Package Camelot :: Package camelot :: Package view :: Package controls :: Package editors :: Module timeeditor |
[frames] | no frames]

# Source Code for Module Camelot.camelot.view.controls.editors.timeeditor

     1  import datetime
     2

     3  from PyQt4 import QtGui
     4

     5  from customeditor import AbstractCustomEditor
     6  from camelot.core import constants
     7

     8 -class TimeEditor(QtGui.QTimeEdit, AbstractCustomEditor):
     9

    10 -    def __init__(self,

    11                   parent,

    12                   editable=True,

    13                   format=constants.camelot_time_format,

    14                   **kwargs):
    15          QtGui.QTimeEdit.__init__(self, parent)
    16          AbstractCustomEditor.__init__(self)
    17          self.setDisplayFormat(format)
    18          self.setEnabled(editable)
    19

    20 -    def set_value(self, value):
    21          value = AbstractCustomEditor.set_value(self, value)
    22          if value:
    23              self.setTime(value)
    24          else:
    25              self.setTime(self.minimumTime())
    26

    27 -    def get_value(self):
    28          value = self.time()
    29          value = datetime.time(hour=value.hour(),

    30                                minute=value.minute(),

    31                                second=value.second())
    32          return AbstractCustomEditor.get_value(self) or value
    33

    34 -    def set_enabled(self, editable=True):
    35          self.setEnabled(editable)
    36