# Path: pytrainer/core/equipment.py
# class Equipment(DeclarativeBase):
#    """An equipment item that can be used during an activity, such as a pair of running shoes."""
# 
#    __tablename__ = 'equipment'
#    active = Column(Boolean)
#    description = Column(Unicode(length=100), unique=True, index=True)
#    id = Column(Integer, primary_key=True)
#    life_expectancy = Column(ForcedInteger)
#    notes = Column(UnicodeText)
#    prior_usage = Column(ForcedInteger)
# 
#    def __init__(self, **kwargs):
#        self.description = u""
#        self.active = True
#        self.life_expectancy = 0
#        self.prior_usage = 0
#        self.notes = u""
#        super(Equipment, self).__init__(**kwargs)
# 
#    def __eq__(self, o):
#        if isinstance(o, Equipment):
#            if self.id is not None and o.id is not None:
#                return self.id == o.id
#        return False
#        
#    def __hash__(self):
#        if self.id is not None:
#            return self.id
#        else:
#            return object.__hash__(self)
# 
# Path: pytrainer/lib/localization.py
# def gtk_str(string):
#     """On Python 2 GTK returns all strings as UTF-8 encoded str. See
# https://python-gtk-3-tutorial.readthedocs.io/en/latest/unicode.html for
# more details."""
#     if sys.version_info[0] == 2:
#         if string is None:
#             return None
#         else:
#             return string.decode('utf-8')
#     else:
#         return string


from gi.repository import Gtk
from pytrainer.core.equipment import Equipment
from pytrainer.lib.localization import gtk_str
    
    def clear_add_equipment_fields(self):
        self._builder.get_object("entryEquipmentAddDescription").set_text("") 
        self._builder.get_object("entryEquipmentAddLifeExpectancy").set_text("0")
        self._builder.get_object("entryEquipmentAddPriorUsage").set_text("0")
        self._builder.get_object("checkbuttonEquipmentAddActive").set_active(True)
        self._builder.get_object("textviewEquipmentAddNotes").get_buffer().set_text("")
        
    def show_page_equipment_list(self):
        self._get_notebook().set_current_page(0)
        
    def show_page_equipment_add(self):
        self._get_notebook().set_current_page(1)
        self._builder.get_object("entryEquipmentAddDescription").grab_focus()
        
    def show_page_equipment_edit(self):
        self._get_notebook().set_current_page(2)
        
    def show_page_equipment_delete(self):
        self._get_notebook().set_current_page(3)
    
    def _add_equipment_clicked(self, widget):
        self.clear_add_equipment_fields()
        self.show_page_equipment_add()
    
    def _cancel_add_equipment_clicked(self, widget):
        self.show_page_equipment_list()
    
    def _confirm_add_equipment_clicked(self, widget):
        #FIXME input validation for numeric fields

# Path: pytrainer/core/equipment.py
# class Equipment(DeclarativeBase):
#    """An equipment item that can be used during an activity, such as a pair of running shoes."""
# 
#    __tablename__ = 'equipment'
#    active = Column(Boolean)
#    description = Column(Unicode(length=100), unique=True, index=True)
#    id = Column(Integer, primary_key=True)
#    life_expectancy = Column(ForcedInteger)
#    notes = Column(UnicodeText)
#    prior_usage = Column(ForcedInteger)
# 
#    def __init__(self, **kwargs):
#        self.description = u""
#        self.active = True
#        self.life_expectancy = 0
#        self.prior_usage = 0
#        self.notes = u""
#        super(Equipment, self).__init__(**kwargs)
# 
#    def __eq__(self, o):
#        if isinstance(o, Equipment):
#            if self.id is not None and o.id is not None:
#                return self.id == o.id
#        return False
#        
#    def __hash__(self):
#        if self.id is not None:
#            return self.id
#        else:
#            return object.__hash__(self)
# 
# Path: pytrainer/lib/localization.py
# def gtk_str(string):
#     """On Python 2 GTK returns all strings as UTF-8 encoded str. See
# https://python-gtk-3-tutorial.readthedocs.io/en/latest/unicode.html for
# more details."""
#     if sys.version_info[0] == 2:
#         if string is None:
#             return None
#         else:
#             return string.decode('utf-8')
#     else:
#         return string


# Path: pytrainer/gui/equipment.py
from gi.repository import Gtk
from pytrainer.core.equipment import Equipment
from pytrainer.lib.localization import gtk_str

    
    def clear_add_equipment_fields(self):
        self._builder.get_object("entryEquipmentAddDescription").set_text("") 
        self._builder.get_object("entryEquipmentAddLifeExpectancy").set_text("0")
        self._builder.get_object("entryEquipmentAddPriorUsage").set_text("0")
        self._builder.get_object("checkbuttonEquipmentAddActive").set_active(True)
        self._builder.get_object("textviewEquipmentAddNotes").get_buffer().set_text("")
        
    def show_page_equipment_list(self):
        self._get_notebook().set_current_page(0)
        
    def show_page_equipment_add(self):
        self._get_notebook().set_current_page(1)
        self._builder.get_object("entryEquipmentAddDescription").grab_focus()
        
    def show_page_equipment_edit(self):
        self._get_notebook().set_current_page(2)
        
    def show_page_equipment_delete(self):
        self._get_notebook().set_current_page(3)
    
    def _add_equipment_clicked(self, widget):
        self.clear_add_equipment_fields()
        self.show_page_equipment_add()
    
    def _cancel_add_equipment_clicked(self, widget):
        self.show_page_equipment_list()
    
    def _confirm_add_equipment_clicked(self, widget):
        #FIXME input validation for numeric fields

        description = gtk_str(self._builder.get_object("entryEquipmentAddDescription").get_text())