screenlets.options.time_option

Package screenlets :: Package options :: Module time_option |
[hide private]
[frames] | no frames]

# Source Code for Module screenlets.options.time_option

     1  #
     2  # Copyright (C) 2009 Martin Owens (DoctorMO) <doctormo@gmail.com>
     3  #
     4  # This program is free software: you can redistribute it and/or modify
     5  # it under the terms of the GNU General Public License as published by
     6  # the Free Software Foundation, either version 3 of the License, or
     7  # (at your option) any later version.
     8  #
     9  # This program is distributed in the hope that it will be useful,
    10  # but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  # GNU General Public License for more details.
    13  #
    14  # You should have received a copy of the GNU General Public License
    15  # along with this program.  If not, see <http://www.gnu.org/licenses/>.
    16  #
    17  """
    18  Time options, these classes will display a text box.
    19  """
    20
    21  import gtk
    22
    23  from screenlets.options import _
    24  from colour_option import ColorOption
    25
    26 -class TimeOption(ColorOption):
    27      """An class for time options."""
    28
    29 -    def generate_widget(self, value):
    30          """Generate a textbox for a time options"""
    31          self.widget = gtk.HBox()
    32          input_hour = gtk.SpinButton()
    33          input_minute = gtk.SpinButton()
    34          input_second = gtk.SpinButton()
    35          input_hour.set_range(0, 23)
    36          input_hour.set_max_length(2)
    37          input_hour.set_increments(1, 1)
    38          input_hour.set_numeric(True)
    39          input_hour.set_value(value[0])
    40          input_minute.set_range(0, 59)
    41          input_minute.set_max_length(2)
    42          input_minute.set_increments(1, 1)
    43          input_minute.set_numeric(True)
    44          input_minute.set_value(value[1])
    45          input_second.set_range(0, 59)
    46          input_second.set_max_length(2)
    47          input_second.set_increments(1, 1)
    48          input_second.set_numeric(True)
    49          input_second.set_value(value[2])
    50          input_hour.connect('value-changed', self.has_changed)
    51          input_minute.connect('value-changed', self.has_changed)
    52          input_second.connect('value-changed', self.has_changed)
    53          input_hour.set_tooltip_text(self.desc)
    54          input_minute.set_tooltip_text(self.desc)
    55          input_second.set_tooltip_text(self.desc)
    56          self.widget.add(input_hour)
    57          self.widget.add(gtk.Label(':'))
    58          self.widget.add(input_minute)
    59          self.widget.add(gtk.Label(':'))
    60          self.widget.add(input_second)
    61          self.widget.add(gtk.Label('h'))
    62          self.widget.show_all()
    63          return self.widget
    64
    65 -    def set_value(self, value):
    66          """Set the time value as required."""
    67          self.value = value
    68
    69 -    def has_changed(self, widget):
    70          """Executed when the widget event kicks off."""
    71          box = widget.get_parent()
    72          inputs = box.get_children()
    73          self.value = (
    74              int(inputs[0].get_value()),
    75              int(inputs[2].get_value()),
    76              int(inputs[4].get_value()),
    77          )
    78          super(ColorOption, self).has_changed()
    79