# Path: fstimer/gui/util_classes.py
# class GtkStockButton(Gtk.Button):
#     
#     def __init__(self, icon_name, label_text):
#         #Init a regular Gtk.Button
#         Gtk.Button.__init__(self)
#         #Add the icon and the label.
#         fname = os.path.join(icon_path, icon_files[icon_name])
#         btnIcon = Gtk.Image.new_from_file(fname)
#         btnLabel = Gtk.Label(label_text+' ')
#         #pack 'em into an HBox
#         btnHbox = Gtk.HBox(False, 0)
#         btnHbox.pack_start(btnIcon, False, False, 0)
#         btnHbox.pack_start(btnLabel, True, True, 0)
#         self.add(btnHbox)
#         return
# 
# 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 gi
import re
import fstimer.gui
from gi.repository import Gtk
from fstimer.gui.util_classes import GtkStockButton
from fstimer.gui.util_classes import MsgDialog
        return

    def custom_new(self, jnk_unused, selection):
        '''handles a click on NEW button'''
        # create new name
        name = 'Custom field'
        i = 1
        while name in self.printfields:
            name = 'Custom field%d' % i
            i = i + 1
        # append new line with default content
        self.printfields[name] = '{Time}'
        self.custommodel.append((name, '{Time}'))
        return

    def name_edit(self, widget, path, text):
        '''handles a change of a ranking name'''
        treeiter = self.custommodel.get_iter(path)
        old_name = self.custommodel.get_value(treeiter, 0)
        # Check if it was changed
        if text != old_name:
            if text in ['Time', 'Pace']:
                md = MsgDialog(self, 'error', ['ok'], 'Error!', 'Names "Time" and "Pace" are reserved.')
                md.run()
                md.destroy()
            elif text not in self.printfields and text not in self.fields:
                self.custommodel[path][0] = text
                self.printfields[text] = self.printfields[old_name]
                self.printfields.pop(old_name)
            else:

# Path: fstimer/gui/util_classes.py
# class GtkStockButton(Gtk.Button):
#     
#     def __init__(self, icon_name, label_text):
#         #Init a regular Gtk.Button
#         Gtk.Button.__init__(self)
#         #Add the icon and the label.
#         fname = os.path.join(icon_path, icon_files[icon_name])
#         btnIcon = Gtk.Image.new_from_file(fname)
#         btnLabel = Gtk.Label(label_text+' ')
#         #pack 'em into an HBox
#         btnHbox = Gtk.HBox(False, 0)
#         btnHbox.pack_start(btnIcon, False, False, 0)
#         btnHbox.pack_start(btnLabel, True, True, 0)
#         self.add(btnHbox)
#         return
# 
# 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/gui/printfields.py
import gi
import re
import fstimer.gui
from gi.repository import Gtk
from fstimer.gui.util_classes import GtkStockButton
from fstimer.gui.util_classes import MsgDialog

        return

    def custom_new(self, jnk_unused, selection):
        '''handles a click on NEW button'''
        # create new name
        name = 'Custom field'
        i = 1
        while name in self.printfields:
            name = 'Custom field%d' % i
            i = i + 1
        # append new line with default content
        self.printfields[name] = '{Time}'
        self.custommodel.append((name, '{Time}'))
        return

    def name_edit(self, widget, path, text):
        '''handles a change of a ranking name'''
        treeiter = self.custommodel.get_iter(path)
        old_name = self.custommodel.get_value(treeiter, 0)
        # Check if it was changed
        if text != old_name:
            if text in ['Time', 'Pace']:
                md = MsgDialog(self, 'error', ['ok'], 'Error!', 'Names "Time" and "Pace" are reserved.')
                md.run()
                md.destroy()
            elif text not in self.printfields and text not in self.fields:
                self.custommodel[path][0] = text
                self.printfields[text] = self.printfields[old_name]
                self.printfields.pop(old_name)
            else:

                md = MsgDialog(self, 'error', ['ok'], 'Error!', 'Field name "%s" is already used!' % text)