Package Gnumed :: Package timelinelib :: Package wxgui :: Package components :: Module numtimepicker |
[frames] | no frames]

# Source Code for Module Gnumed.timelinelib.wxgui.components.numtimepicker

     1  # Copyright (C) 2009, 2010, 2011  Rickard Lindberg, Roger Lindberg
     2  #
     3  # This file is part of Timeline.
     4  #
     5  # Timeline is free software: you can redistribute it and/or modify
     6  # it under the terms of the GNU General Public License as published by
     7  # the Free Software Foundation, either version 3 of the License, or
     8  # (at your option) any later version.
     9  #
    10  # Timeline is distributed in the hope that it will be useful,
    11  # but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  # GNU General Public License for more details.
    14  #
    15  # You should have received a copy of the GNU General Public License
    16  # along with Timeline.  If not, see <http://www.gnu.org/licenses/>.
    17
    18
    19  import wx
    20
    21
    22 -class NumTimePicker(wx.Panel):
    23
    24 -    def __init__(self, parent, show_time=False, config=None):
    25          wx.Panel.__init__(self, parent)
    26          self.time_picker = self._create_gui()
    27          self.controller = NumTimePickerController(self, 0)
    28
    29 -    def get_value(self):
    30          return self.time_picker.GetValue()
    31
    32 -    def set_value(self, num_time):
    33          self.time_picker.SetValue(int(round(num_time,0)))
    34
    35 -    def set_range(self, min, max):
    36          self.time_picker.SetRange(min, max)
    37
    38 -    def select_all(self):
    39          self.time_picker.SetSelection(0, len(str(self.get_value())))
    40
    41 -    def _create_gui(self):
    42          time_picker = wx.SpinCtrl(self, -1, "", (30, 50))
    43          self.Bind(wx.EVT_SPINCTRL, self.OnSpin, time_picker)
    44          # Layout
    45          sizer = wx.BoxSizer(wx.HORIZONTAL)
    46          sizer.Add(time_picker, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
    47          self.SetSizerAndFit(sizer)
    48          return time_picker
    49
    50 -    def OnSpin(self, evt):
    51          self.controller.on_spin()
    52
    53
    54 -class NumTimePickerController(object):
    55
    56 -    def __init__(self, time_picker, default_num_time):
    57          self.time_picker = time_picker
    58          self.time_picker.set_range(-10000, 10000)
    59          self.default_num_time = default_num_time
    60
    61 -    def get_value(self):
    62          num_time = self.time_picker.get_value()
    63          return num_time
    64
    65 -    def set_value(self, num_time):
    66          if num_time == None:
    67              num_time = self.default_num_time
    68          self.time_picker.set_value(num_time)
    69
    70 -    def on_spin(self):
    71          pass
    72