controls/EnhancedStatusBar.py
changeset 1730 64d8f52bc8c8
parent 1583 d91356480df9
child 1731 6ebd9c40b2be
equal deleted inserted replaced
1726:d51af006fa6b 1730:64d8f52bc8c8
    14 # 1. Some Requests/Features To Add?
    14 # 1. Some Requests/Features To Add?
    15 #
    15 #
    16 #
    16 #
    17 # For All Kind Of Problems, Requests Of Enhancements And Bug Reports, Please
    17 # For All Kind Of Problems, Requests Of Enhancements And Bug Reports, Please
    18 # Write To Me At:
    18 # Write To Me At:
    19 # 
    19 #
    20 #
    20 #
    21 # andrea.gavana@agip.it
    21 # andrea.gavana@agip.it
    22 # andrea_gavan@tin.it
    22 # andrea_gavan@tin.it
    23 #
    23 #
    24 # Or, Obviously, To The wxPython Mailing List!!!
    24 # Or, Obviously, To The wxPython Mailing List!!!
    45      ESB_ALIGN_RIGHT;
    45      ESB_ALIGN_RIGHT;
    46    - varticalalignment: This Specify The Vertical Alignment For Your Widget,
    46    - varticalalignment: This Specify The Vertical Alignment For Your Widget,
    47      And Can Be ESB_EXACT_FIT, ESB_ALIGN_CENTER_VERTICAL, ESB_ALIGN_BOTTOM And
    47      And Can Be ESB_EXACT_FIT, ESB_ALIGN_CENTER_VERTICAL, ESB_ALIGN_BOTTOM And
    48      ESB_ALIGN_LEFT;
    48      ESB_ALIGN_LEFT;
    49 
    49 
    50 EnhancedStatusBar Is Freeware And Distributed Under The wxPython License. 
    50 EnhancedStatusBar Is Freeware And Distributed Under The wxPython License.
    51 
    51 
    52 Latest Revision: 21 September 2005, 19.57.20 GMT+2
    52 Latest Revision: 21 September 2005, 19.57.20 GMT+2
    53 Latest Revision before Latest Revision: 21 September 2005, 18.29.35 GMT+2
    53 Latest Revision before Latest Revision: 21 September 2005, 18.29.35 GMT+2
    54 Latest Revision before Latest Revision before Latest Revision: 31 May 2005, 23.17 CET
    54 Latest Revision before Latest Revision before Latest Revision: 31 May 2005, 23.17 CET
    55 
    55 
    88 
    88 
    89         EnhancedStatusBar.__init__(self, parent, id=wx.ID_ANY,
    89         EnhancedStatusBar.__init__(self, parent, id=wx.ID_ANY,
    90                                    style=wx.ST_SIZEGRIP,
    90                                    style=wx.ST_SIZEGRIP,
    91                                    name="EnhancedStatusBar")
    91                                    name="EnhancedStatusBar")
    92         """
    92         """
    93         
    93 
    94         wx.StatusBar.__init__(self, parent, id, style, name)
    94         wx.StatusBar.__init__(self, parent, id, style, name)
    95         
    95 
    96         self._items = {}
    96         self._items = {}
    97         self._curPos = 0
    97         self._curPos = 0
    98         self._parent = parent
    98         self._parent = parent
    99         
    99 
   100         wx.EVT_SIZE(self, self.OnSize) 
   100         wx.EVT_SIZE(self, self.OnSize)
   101         wx.CallAfter(self.OnSize, None)
   101         wx.CallAfter(self.OnSize, None)
   102 
   102 
   103             
   103 
   104     def OnSize(self, event):
   104     def OnSize(self, event):
   105         """Handles The wx.EVT_SIZE Events For The StatusBar.
   105         """Handles The wx.EVT_SIZE Events For The StatusBar.
   106 
   106 
   107         Actually, All The Calculations Linked To HorizontalAlignment And
   107         Actually, All The Calculations Linked To HorizontalAlignment And
   108         VerticalAlignment Are Done In This Function."""
   108         VerticalAlignment Are Done In This Function."""
   109 
   109 
   110         for pos, item in self._items.items():
   110         for pos, item in self._items.items():
   111             widget, horizontalalignment, verticalalignment = item.widget, item.horizontalalignment, item.verticalalignment
   111             widget, horizontalalignment, verticalalignment = item.widget, item.horizontalalignment, item.verticalalignment
   112            
   112 
   113             rect = self.GetFieldRect(pos)
   113             rect = self.GetFieldRect(pos)
   114             widgetpos = widget.GetPosition()
   114             widgetpos = widget.GetPosition()
   115             widgetsize = widget.GetSize()
   115             widgetsize = widget.GetSize()
   116 
   116 
   117             rect = self.GetFieldRect(pos)
   117             rect = self.GetFieldRect(pos)
   118             
   118 
   119             if horizontalalignment == ESB_EXACT_FIT:
   119             if horizontalalignment == ESB_EXACT_FIT:
   120                 
   120 
   121                 if verticalalignment == ESB_EXACT_FIT:
   121                 if verticalalignment == ESB_EXACT_FIT:
   122                     """ 1 September 2015 Fix fit align """
   122                     """ 1 September 2015 Fix fit align """
   123                     widget.SetSize((rect.width-4, rect.height-4))
   123                     widget.SetSize((rect.width-4, rect.height-4))
   124                     widget.SetPosition((rect.x+2, rect.y+2))
   124                     widget.SetPosition((rect.x+2, rect.y+2))
   125                 elif verticalalignment == ESB_ALIGN_CENTER_VERTICAL:
   125                 elif verticalalignment == ESB_ALIGN_CENTER_VERTICAL:
   136                 elif verticalalignment == ESB_ALIGN_BOTTOM:
   136                 elif verticalalignment == ESB_ALIGN_BOTTOM:
   137                     widget.SetSize((rect.width-2, widgetsize[1]))
   137                     widget.SetSize((rect.width-2, widgetsize[1]))
   138                     widget.SetPosition((rect.x-1, rect.height-widgetsize[1]))
   138                     widget.SetPosition((rect.x-1, rect.height-widgetsize[1]))
   139 
   139 
   140             elif horizontalalignment == ESB_ALIGN_LEFT:
   140             elif horizontalalignment == ESB_ALIGN_LEFT:
   141                 
   141 
   142                 xpos = rect.x - 1
   142                 xpos = rect.x - 1
   143                 if verticalalignment == ESB_EXACT_FIT:
   143                 if verticalalignment == ESB_EXACT_FIT:
   144                     widget.SetSize((widgetsize[0], rect.height-2))
   144                     widget.SetSize((widgetsize[0], rect.height-2))
   145                     widget.SetPosition((xpos, rect.y-1))
   145                     widget.SetPosition((xpos, rect.y-1))
   146                 elif verticalalignment == ESB_ALIGN_CENTER_VERTICAL:
   146                 elif verticalalignment == ESB_ALIGN_CENTER_VERTICAL:
   152                         widget.SetPosition((xpos, rect.y-1))
   152                         widget.SetPosition((xpos, rect.y-1))
   153                 elif verticalalignment == ESB_ALIGN_TOP:
   153                 elif verticalalignment == ESB_ALIGN_TOP:
   154                     widget.SetPosition((xpos, rect.y))
   154                     widget.SetPosition((xpos, rect.y))
   155                 elif verticalalignment == ESB_ALIGN_BOTTOM:
   155                 elif verticalalignment == ESB_ALIGN_BOTTOM:
   156                     widget.SetPosition((xpos, rect.height-widgetsize[1]))
   156                     widget.SetPosition((xpos, rect.height-widgetsize[1]))
   157                 
   157 
   158             elif horizontalalignment == ESB_ALIGN_RIGHT:
   158             elif horizontalalignment == ESB_ALIGN_RIGHT:
   159                 
   159 
   160                 xpos = rect.x + rect.width - widgetsize[0] - 1
   160                 xpos = rect.x + rect.width - widgetsize[0] - 1
   161                 if verticalalignment == ESB_EXACT_FIT:
   161                 if verticalalignment == ESB_EXACT_FIT:
   162                     widget.SetSize((widgetsize[0], rect.height-2))
   162                     widget.SetSize((widgetsize[0], rect.height-2))
   163                     widget.SetPosition((xpos, rect.y-1))
   163                     widget.SetPosition((xpos, rect.y-1))
   164                 elif verticalalignment == ESB_ALIGN_CENTER_VERTICAL:
   164                 elif verticalalignment == ESB_ALIGN_CENTER_VERTICAL:
   172                     widget.SetPosition((xpos, rect.y))
   172                     widget.SetPosition((xpos, rect.y))
   173                 elif verticalalignment == ESB_ALIGN_BOTTOM:
   173                 elif verticalalignment == ESB_ALIGN_BOTTOM:
   174                     widget.SetPosition((xpos, rect.height-widgetsize[1]))
   174                     widget.SetPosition((xpos, rect.height-widgetsize[1]))
   175 
   175 
   176             elif horizontalalignment == ESB_ALIGN_CENTER_HORIZONTAL:
   176             elif horizontalalignment == ESB_ALIGN_CENTER_HORIZONTAL:
   177                 
   177 
   178                 xpos = rect.x + (rect.width - widgetsize[0])/2 - 1
   178                 xpos = rect.x + (rect.width - widgetsize[0])/2 - 1
   179                 if verticalalignment == ESB_EXACT_FIT:
   179                 if verticalalignment == ESB_EXACT_FIT:
   180                     widget.SetSize((widgetsize[0], rect.height))
   180                     widget.SetSize((widgetsize[0], rect.height))
   181                     widget.SetPosition((xpos, rect.y))
   181                     widget.SetPosition((xpos, rect.y))
   182                 elif verticalalignment == ESB_ALIGN_CENTER_VERTICAL:
   182                 elif verticalalignment == ESB_ALIGN_CENTER_VERTICAL:
   189                 elif verticalalignment == ESB_ALIGN_TOP:
   189                 elif verticalalignment == ESB_ALIGN_TOP:
   190                     widget.SetPosition((xpos, rect.y))
   190                     widget.SetPosition((xpos, rect.y))
   191                 elif verticalalignment == ESB_ALIGN_BOTTOM:
   191                 elif verticalalignment == ESB_ALIGN_BOTTOM:
   192                     widget.SetPosition((xpos, rect.height-widgetsize[1]))
   192                     widget.SetPosition((xpos, rect.height-widgetsize[1]))
   193 
   193 
   194                 
   194 
   195         if event is not None:
   195         if event is not None:
   196             event.Skip()
   196             event.Skip()
   197         
   197 
   198         
   198 
   199     def AddWidget(self, widget, horizontalalignment=ESB_ALIGN_CENTER_HORIZONTAL,
   199     def AddWidget(self, widget, horizontalalignment=ESB_ALIGN_CENTER_HORIZONTAL,
   200                   verticalalignment=ESB_ALIGN_CENTER_VERTICAL, pos = -1):
   200                   verticalalignment=ESB_ALIGN_CENTER_VERTICAL, pos = -1):
   201         """Add A Widget To The EnhancedStatusBar.
   201         """Add A Widget To The EnhancedStatusBar.
   202 
   202 
   203         Parameters:
   203         Parameters:
   219         """
   219         """
   220 
   220 
   221         if pos == -1:
   221         if pos == -1:
   222             pos = self._curPos
   222             pos = self._curPos
   223             self._curPos += 1
   223             self._curPos += 1
   224         
   224 
   225         if self.GetFieldsCount() <= pos:
   225         if self.GetFieldsCount() <= pos:
   226             raise "\nERROR: EnhancedStatusBar has a max of %d items, you tried to set item #%d" % (self.GetFieldsCount(), pos)
   226             raise "\nERROR: EnhancedStatusBar has a max of %d items, you tried to set item #%d" % (self.GetFieldsCount(), pos)
   227 
   227 
   228         if horizontalalignment not in [ESB_ALIGN_CENTER_HORIZONTAL, ESB_EXACT_FIT,
   228         if horizontalalignment not in [ESB_ALIGN_CENTER_HORIZONTAL, ESB_EXACT_FIT,
   229                                        ESB_ALIGN_LEFT, ESB_ALIGN_RIGHT]:
   229                                        ESB_ALIGN_LEFT, ESB_ALIGN_RIGHT]:
   234         if verticalalignment not in [ESB_ALIGN_CENTER_VERTICAL, ESB_EXACT_FIT,
   234         if verticalalignment not in [ESB_ALIGN_CENTER_VERTICAL, ESB_EXACT_FIT,
   235                                      ESB_ALIGN_TOP, ESB_ALIGN_BOTTOM]:
   235                                      ESB_ALIGN_TOP, ESB_ALIGN_BOTTOM]:
   236             raise '\nERROR: Parameter "verticalalignment" Should Be One Of '\
   236             raise '\nERROR: Parameter "verticalalignment" Should Be One Of '\
   237                   '"ESB_ALIGN_CENTER_VERTICAL", "ESB_ALIGN_TOP", "ESB_ALIGN_BOTTOM"' \
   237                   '"ESB_ALIGN_CENTER_VERTICAL", "ESB_ALIGN_TOP", "ESB_ALIGN_BOTTOM"' \
   238                   '"ESB_EXACT_FIT"'
   238                   '"ESB_EXACT_FIT"'
   239         
   239 
   240 
   240 
   241         try:
   241         try:
   242             self.RemoveChild(self._items[pos].widget)
   242             self.RemoveChild(self._items[pos].widget)
   243             self._items[pos].widget.Destroy()
   243             self._items[pos].widget.Destroy()
   244         except KeyError: pass
   244         except KeyError: pass
   245         
   245 
   246         self._items[pos] = EnhancedStatusBarItem(widget, pos, horizontalalignment, verticalalignment)
   246         self._items[pos] = EnhancedStatusBarItem(widget, pos, horizontalalignment, verticalalignment)
   247         
   247 
   248         wx.CallAfter(self.OnSize, None)
   248         wx.CallAfter(self.OnSize, None)