# 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/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


import gi
import fstimer.gui
import os
import re
from gi.repository import Gtk
from fstimer.gui.util_classes import MsgDialog
from fstimer.gui.util_classes import GtkStockButton
                    timePattern = r'((?P<days>-?\d+) day(s)?, )?((?P<hours>\d+):)?'r'(?P<minutes>\d+):(?P<seconds>\d+)'
                    re.match(timePattern, sduration).groupdict(0)
                except AttributeError:
                    label_hd.set_markup('<span color="red">hh:mm:ss</span>')
                    return
        # If that was OK, we go through each field and grab the new value.
        new_vals = {}
        for field in self.fields:
            #Entrybox
            if self.fieldsdic[field]['type'] in ['entrybox', 'entrybox_int']:
                new_vals[field] = self.editregfields[field].get_text()
            #Combobox
            elif self.fieldsdic[field]['type'] == 'combobox':
                indx = self.editregfields[field].get_active()
                if indx == 0:
                    new_vals[field] = ''
                else:
                    new_vals[field] = self.fieldsdic[field]['options'][indx-1]
        # Make sure we don't have a duplicate ID, unless we are editing and leave it the same.
        if treeiter and new_vals['ID'] == self.prereg[preregiter]['ID']:
            pass  # No need for an ID check, it was already done.
        elif new_vals['ID'] in self.ids:
            label_id.set_markup('<span color="red">{} has already been used</span>'.format(new_vals['ID']))
            return
        # Now we replace or append in the treemodel and in prereg
        if treeiter:
            # Remove the old ID from the id store, and add the new value
            if self.prereg[preregiter]['ID']:
                self.ids.remove(self.prereg[preregiter]['ID'])
            # Update the tree and prereg

# 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/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/register.py
import gi
import fstimer.gui
import os
import re
from gi.repository import Gtk
from fstimer.gui.util_classes import MsgDialog
from fstimer.gui.util_classes import GtkStockButton

                    timePattern = r'((?P<days>-?\d+) day(s)?, )?((?P<hours>\d+):)?'r'(?P<minutes>\d+):(?P<seconds>\d+)'
                    re.match(timePattern, sduration).groupdict(0)
                except AttributeError:
                    label_hd.set_markup('<span color="red">hh:mm:ss</span>')
                    return
        # If that was OK, we go through each field and grab the new value.
        new_vals = {}
        for field in self.fields:
            #Entrybox
            if self.fieldsdic[field]['type'] in ['entrybox', 'entrybox_int']:
                new_vals[field] = self.editregfields[field].get_text()
            #Combobox
            elif self.fieldsdic[field]['type'] == 'combobox':
                indx = self.editregfields[field].get_active()
                if indx == 0:
                    new_vals[field] = ''
                else:
                    new_vals[field] = self.fieldsdic[field]['options'][indx-1]
        # Make sure we don't have a duplicate ID, unless we are editing and leave it the same.
        if treeiter and new_vals['ID'] == self.prereg[preregiter]['ID']:
            pass  # No need for an ID check, it was already done.
        elif new_vals['ID'] in self.ids:
            label_id.set_markup('<span color="red">{} has already been used</span>'.format(new_vals['ID']))
            return
        # Now we replace or append in the treemodel and in prereg
        if treeiter:
            # Remove the old ID from the id store, and add the new value
            if self.prereg[preregiter]['ID']:
                self.ids.remove(self.prereg[preregiter]['ID'])
            # Update the tree and prereg

            for (colid, field) in enumerate(self.fields):