# Path: fstimer/printer/formatter.py
# def print_startsheets(pytimer, use_csv):
#     '''print startsheets to files'''
#     cols = get_startsheet_columns(pytimer)
#     col_fns = get_col_fns(pytimer, cols)
#     ranking_keys = set(['ID'])
#     rankings = defaultdict(lambda: 'ID')
#     printer = get_printer(pytimer, cols, use_csv, False)
#     # Build the results
#     ranked_results = {}
#     for ranking_key in ranking_keys:
#         ranked_results[ranking_key] = get_sorted_startsheet(
#                 pytimer.timedict, ranking_key, cols, col_fns)
#     fname_overall = '_'.join([os.path.basename(pytimer.path),
#                               'all_startsheet'])
#     fname_cat = '_'.join([os.path.basename(pytimer.path),
#                           'divisions_startsheet'])
#     gen_printouts(pytimer.timedict, pytimer.fieldsdic, pytimer.divisions, rankings,
#                   pytimer.path, printer, ranked_results, fname_overall, fname_cat)
# 
# Path: fstimer/gui/util_classes.py
# class MsgDialog(Gtk.Dialog):
#     
#     def __init__(self, parent, icon_name, buttons, title, text):
#         super(MsgDialog, self).__init__(title, parent, Gtk.DialogFlags.MODAL)
#         btn_list = []
#         for i, btn_name in enumerate(buttons):
#             icon, label, signal = dialog_buttons[btn_name]
#             btn = GtkStockButton(icon, label)
#             btn.connect('clicked', self.click_response, signal)
#             btn_list.append(btn)
#         self.set_border_width(5)
#         self.set_default_size(400, 50)
#         #Load in the icon
#         fname = os.path.join(icon_path, icon_files[icon_name])
#         msg_icon = Gtk.Image.new_from_file(fname)
#         label = Gtk.Label(label=text)
#         #And pack
#         hbox = Gtk.HBox(False, 0)
#         hbox.pack_start(msg_icon, False, False,10)
#         hbox.pack_start(label, False, False,10)
#         vbox = Gtk.VBox(False, 0)
#         vbox.pack_start(hbox, True, True, 15)
#         # Pack in all of the buttons
#         hbox_btns = Gtk.HBox(False, 0)
#         align = Gtk.Alignment.new(1, 0, 1, 0)
#         hbox_btns.pack_start(align, True, True, 0)
#         for btn in btn_list:
#             hbox_btns.pack_start(btn, False, False, 5)
#         vbox.pack_start(hbox_btns, False, False, 0)
#         self.get_content_area().add(vbox)
#         self.show_all()
#     
#     def click_response(self, w, signal):
#         self.response(signal)


import logging
import gi
import os, json, csv, re, datetime
import fstimer.gui.intro
import fstimer.gui.newproject
import fstimer.gui.projecttype
import fstimer.gui.definefields
import fstimer.gui.definedivisions
import fstimer.gui.printfields
import fstimer.gui.definerankings
import fstimer.gui.root
import fstimer.gui.about
import fstimer.gui.importprereg
import fstimer.gui.preregister
import fstimer.gui.register
import fstimer.gui.compile
import fstimer.gui.compileerrors
import fstimer.gui.pretime
import fstimer.gui.timing
from gi.repository import Gtk
from os.path import normpath, join, dirname, abspath, basename
from fstimer.printer.formatter import print_startsheets
from collections import defaultdict
from fstimer.gui.util_classes import MsgDialog
        self.rankingswin = fstimer.gui.definerankings.RankingsWin(
            self.rankings, self.divisions, self.printfields, self.back_to_printfields, self.store_new_project, parent_win, edit)

    def back_to_printfields(self, jnk_unused):
        '''Goes back to define fields window from the family reset one'''
        self.rankingswin.hide()
        self.printfieldswin.show_all()

    def store_new_project(self, jnk_unused, edit):
        '''Stores a new project to file and goes to root window'''
        logger = logging.getLogger('fstimer')
        logger.debug(self.path)
        if not edit:
            os.system('mkdir '+ self.path)
        regdata = {}
        regdata['projecttype'] = self.projecttype
        regdata['numlaps'] = self.numlaps
        regdata['variablelaps'] = self.variablelaps
        regdata['fields'] = self.fields
        regdata['fieldsdic'] = self.fieldsdic
        regdata['printfields'] = self.printfields
        regdata['divisions'] = self.divisions
        regdata['rankings'] = self.rankings
        logger.debug(regdata)
        os.makedirs(self.path, exist_ok=True)
        with open(join(self.path, basename(self.path)+'.reg'), 'w', encoding='utf-8') as fout:
            json.dump(regdata, fout)
        if edit:
            md = MsgDialog(self.rankingswin, 'information', ['ok'], 'Edited!', 'Project '+basename(self.path)+' successfully edited!')
        else:

# Path: fstimer/printer/formatter.py
# def print_startsheets(pytimer, use_csv):
#     '''print startsheets to files'''
#     cols = get_startsheet_columns(pytimer)
#     col_fns = get_col_fns(pytimer, cols)
#     ranking_keys = set(['ID'])
#     rankings = defaultdict(lambda: 'ID')
#     printer = get_printer(pytimer, cols, use_csv, False)
#     # Build the results
#     ranked_results = {}
#     for ranking_key in ranking_keys:
#         ranked_results[ranking_key] = get_sorted_startsheet(
#                 pytimer.timedict, ranking_key, cols, col_fns)
#     fname_overall = '_'.join([os.path.basename(pytimer.path),
#                               'all_startsheet'])
#     fname_cat = '_'.join([os.path.basename(pytimer.path),
#                           'divisions_startsheet'])
#     gen_printouts(pytimer.timedict, pytimer.fieldsdic, pytimer.divisions, rankings,
#                   pytimer.path, printer, ranked_results, fname_overall, fname_cat)
# 
# Path: fstimer/gui/util_classes.py
# class MsgDialog(Gtk.Dialog):
#     
#     def __init__(self, parent, icon_name, buttons, title, text):
#         super(MsgDialog, self).__init__(title, parent, Gtk.DialogFlags.MODAL)
#         btn_list = []
#         for i, btn_name in enumerate(buttons):
#             icon, label, signal = dialog_buttons[btn_name]
#             btn = GtkStockButton(icon, label)
#             btn.connect('clicked', self.click_response, signal)
#             btn_list.append(btn)
#         self.set_border_width(5)
#         self.set_default_size(400, 50)
#         #Load in the icon
#         fname = os.path.join(icon_path, icon_files[icon_name])
#         msg_icon = Gtk.Image.new_from_file(fname)
#         label = Gtk.Label(label=text)
#         #And pack
#         hbox = Gtk.HBox(False, 0)
#         hbox.pack_start(msg_icon, False, False,10)
#         hbox.pack_start(label, False, False,10)
#         vbox = Gtk.VBox(False, 0)
#         vbox.pack_start(hbox, True, True, 15)
#         # Pack in all of the buttons
#         hbox_btns = Gtk.HBox(False, 0)
#         align = Gtk.Alignment.new(1, 0, 1, 0)
#         hbox_btns.pack_start(align, True, True, 0)
#         for btn in btn_list:
#             hbox_btns.pack_start(btn, False, False, 5)
#         vbox.pack_start(hbox_btns, False, False, 0)
#         self.get_content_area().add(vbox)
#         self.show_all()
#     
#     def click_response(self, w, signal):
#         self.response(signal)


# Path: fstimer/timer.py
import logging
import gi
import os, json, csv, re, datetime
import fstimer.gui.intro
import fstimer.gui.newproject
import fstimer.gui.projecttype
import fstimer.gui.definefields
import fstimer.gui.definedivisions
import fstimer.gui.printfields
import fstimer.gui.definerankings
import fstimer.gui.root
import fstimer.gui.about
import fstimer.gui.importprereg
import fstimer.gui.preregister
import fstimer.gui.register
import fstimer.gui.compile
import fstimer.gui.compileerrors
import fstimer.gui.pretime
import fstimer.gui.timing
from gi.repository import Gtk
from os.path import normpath, join, dirname, abspath, basename
from fstimer.printer.formatter import print_startsheets
from collections import defaultdict
from fstimer.gui.util_classes import MsgDialog

        self.rankingswin = fstimer.gui.definerankings.RankingsWin(
            self.rankings, self.divisions, self.printfields, self.back_to_printfields, self.store_new_project, parent_win, edit)

    def back_to_printfields(self, jnk_unused):
        '''Goes back to define fields window from the family reset one'''
        self.rankingswin.hide()
        self.printfieldswin.show_all()

    def store_new_project(self, jnk_unused, edit):
        '''Stores a new project to file and goes to root window'''
        logger = logging.getLogger('fstimer')
        logger.debug(self.path)
        if not edit:
            os.system('mkdir '+ self.path)
        regdata = {}
        regdata['projecttype'] = self.projecttype
        regdata['numlaps'] = self.numlaps
        regdata['variablelaps'] = self.variablelaps
        regdata['fields'] = self.fields
        regdata['fieldsdic'] = self.fieldsdic
        regdata['printfields'] = self.printfields
        regdata['divisions'] = self.divisions
        regdata['rankings'] = self.rankings
        logger.debug(regdata)
        os.makedirs(self.path, exist_ok=True)
        with open(join(self.path, basename(self.path)+'.reg'), 'w', encoding='utf-8') as fout:
            json.dump(regdata, fout)
        if edit:
            md = MsgDialog(self.rankingswin, 'information', ['ok'], 'Edited!', 'Project '+basename(self.path)+' successfully edited!')
        else:

            md = MsgDialog(self.rankingswin, 'information', ['ok'], 'Created!', 'Project '+basename(self.path)+' successfully created!')