Changeset 4232

Show
Ignore:
Timestamp:
07/04/08 10:13:10 (3 months ago)
Author:
ed
Message:

Re-write the way that the calendar is displayed. It now is contained by the FloatingPanel? of the form, and thus is not bound by panels or other container.

Also added the ExtendedCalendar? property. When True, the larger version of the calendar control is used. This version has additional controls for quickly moving to any date.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/dabo/ui/uiwx/dDateTextBox.py

    r4186 r4232  
    1515 
    1616class CalPanel(dPanel): 
    17     def __init__(self, parent, pos=None, dt=None, ctrl=None ): 
     17    def __init__(self, parent, pos=None, dt=None, ctrl=None,  
     18            extended=False): 
    1819        if isinstance(dt, (datetime.datetime, datetime.date)): 
    1920            self.date = dt 
     
    2122            self.date = datetime.date.today() 
    2223        self.ctrl = ctrl 
     24        self.extended = extended 
    2325        super(CalPanel, self).__init__(parent, pos=pos) 
    2426         
     
    2830        to the calendar's size. 
    2931        """ 
    30         self.cal = dabo.ui.dCalendar(self, Position=(5, 5)) 
     32        calClass = {True: dabo.ui.dExtendedCalendar, False: dabo.ui.dCalendar}[self.extended] 
     33        self.cal = calClass(self, Position=(5, 5)) 
    3134        self.cal.Date = self.date 
    3235        self.cal.bindEvent(dEvents.Hit, self.onCalSelection) 
     
    4245            self.ctrl.setDate(self.cal.Date) 
    4346            self.ctrl.setFocus() 
    44         self.Visible = False 
     47        self.Form.hide() 
    4548     
    4649     
     
    5053            if self.ctrl is not None: 
    5154                self.ctrl.setFocus() 
    52             self.Visible = False 
     55            self.Form.hide() 
    5356         
    5457         
     
    7679        # Do we display datetimes in 24-hour clock, or with AM/PM? 
    7780        self.ampm = False 
    78      
     81        # Do we use the extended format for the calendar display? 
     82        self._extendedCalendar = False 
     83 
    7984     
    8085    def afterInit(self): 
    8186        self._baseClass = dDateTextBox 
    8287        self.Value = datetime.date.today() 
     88        self._calendarPanel = None 
    8389        if self.showCalButton: 
    8490            # Create a button that will display the calendar 
     
    102108C: Popup Calendar to Select 
    103109""") 
    104         self.DynamicToolTipText = lambda: {True: self._defaultToolTipText,  
    105                 False: None}[self.Enabled and not self.ReadOnly] 
    106  
     110#       self.DynamicToolTipText = lambda: {True: self._defaultToolTipText,  
     111#               False: None}[self.Enabled and not self.ReadOnly] 
     112 
     113        self.DynamicToolTipText = lambda: "%s, %s" % self.formCoordinates() 
    107114 
    108115    def initEvents(self): 
     
    122129            # ignore 
    123130            return 
    124         availHt = self.Parent.Bottom - self.Bottom 
    125         try: 
    126             self.calPanel.cal.Date = self.Value 
    127         except AttributeError: 
    128             self.calPanel = CalPanel(self.Parent, dt=self.Value, ctrl=self) 
    129         cp = self.calPanel 
    130         cp.Position = (self.Left, self.Bottom) 
    131         if self.Bottom + cp.Height > self.Parent.Bottom: 
    132             # Maybe we should move it above 
    133             if cp.Height <= self.Top: 
    134                 cp.Bottom = self.Top 
    135             else: 
    136                 # We can't fit it cleanly, so try to fit as much as possible 
    137                 cp.Top = max(0, (self.Parent.Height - cp.Height) ) 
    138         if self.Left + cp.Width > self.Parent.Right: 
    139             # Try moving it to the left 
    140             cp.Left = max(0, (self.Parent.Width - cp.Width) ) 
    141         cp.Visible = True 
    142         cp.bringToFront() 
    143         cp.setFocus() 
     131        cp = self._CalendarPanel 
     132        cp.cal.Date = self.Value 
     133        fp = self.Form.FloatingPanel 
     134        fp.Owner = self 
     135        fp.show() 
    144136         
    145137     
     
    397389            self.Value = dt 
    398390 
    399              
     391    def _getCalendarPanel(self): 
     392        fp = self.Form.FloatingPanel 
     393        if not isinstance(self._calendarPanel, CalPanel) or not (self._calendarPanel.Parent is fp): 
     394            fp.clear() 
     395            self._calendarPanel = CalPanel(fp, dt=self.Value, ctrl=self,  
     396                    extended=self.ExtendedCalendar) 
     397            fp.Sizer.append(self._calendarPanel) 
     398            fp.fitToSizer() 
     399        return self._calendarPanel 
     400 
     401 
     402    def _getExtendedCalendar(self): 
     403        return self._extendedCalendar 
     404 
     405    def _setExtendedCalendar(self, val): 
     406        if self._constructed(): 
     407            self._extendedCalendar = val 
     408        else: 
     409            self._properties["ExtendedCalendar"] = val 
     410 
     411 
     412    _CalendarPanel = property(_getCalendarPanel, None, None, 
     413            _("Reference to the displayed calendar  (read-only) (CalPanel)")) 
     414 
     415    ExtendedCalendar = property(_getExtendedCalendar, _setExtendedCalendar, None, 
     416            _("""When True, the calendar is displayed in a larger format with more controls  
     417            for quickly moving to any date. Default=False  (bool)""")) 
     418 
     419 
    400420 
    401421if __name__ == "__main__":