Beremiz.py
changeset 230 38feaca5f06b
parent 229 8bc65076e290
child 234 aff053bad924
equal deleted inserted replaced
229:8bc65076e290 230:38feaca5f06b
   124 
   124 
   125 wx.lib.imageutils.grayOut = grayOut
   125 wx.lib.imageutils.grayOut = grayOut
   126 
   126 
   127 class GenBitmapTextButton(wx.lib.buttons.GenBitmapTextButton):
   127 class GenBitmapTextButton(wx.lib.buttons.GenBitmapTextButton):
   128     def _GetLabelSize(self):
   128     def _GetLabelSize(self):
   129         return wx.lib.buttons.GenBitmapTextButton._GetLabelSize(self)[:-1] + (False,)
   129         """ used internally """
       
   130         w, h = self.GetTextExtent(self.GetLabel())
       
   131         if not self.bmpLabel:
       
   132             return w, h, False       # if there isn't a bitmap use the size of the text
       
   133 
       
   134         w_bmp = self.bmpLabel.GetWidth()+2
       
   135         h_bmp = self.bmpLabel.GetHeight()+2
       
   136         height = h + h_bmp
       
   137         if w_bmp > w:
       
   138             width = w_bmp
       
   139         else:
       
   140             width = w
       
   141         return width, height, False
       
   142 
       
   143     def DrawLabel(self, dc, width, height, dw=0, dy=0):
       
   144         bmp = self.bmpLabel
       
   145         if bmp != None:     # if the bitmap is used
       
   146             if self.bmpDisabled and not self.IsEnabled():
       
   147                 bmp = self.bmpDisabled
       
   148             if self.bmpFocus and self.hasFocus:
       
   149                 bmp = self.bmpFocus
       
   150             if self.bmpSelected and not self.up:
       
   151                 bmp = self.bmpSelected
       
   152             bw,bh = bmp.GetWidth(), bmp.GetHeight()
       
   153             if not self.up:
       
   154                 dw = dy = self.labelDelta
       
   155             hasMask = bmp.GetMask() != None
       
   156         else:
       
   157             bw = bh = 0     # no bitmap -> size is zero
       
   158 
       
   159         dc.SetFont(self.GetFont())
       
   160         if self.IsEnabled():
       
   161             dc.SetTextForeground(self.GetForegroundColour())
       
   162         else:
       
   163             dc.SetTextForeground(wx.SystemSettings.GetColour(wx.SYS_COLOUR_GRAYTEXT))
       
   164 
       
   165         label = self.GetLabel()
       
   166         tw, th = dc.GetTextExtent(label)        # size of text
       
   167         if not self.up:
       
   168             dw = dy = self.labelDelta
       
   169 
       
   170         pos_x = (width-bw)/2+dw      # adjust for bitmap and text to centre
       
   171         pos_y = (height-bh-th)/2+dy
       
   172         if bmp !=None:
       
   173             dc.DrawBitmap(bmp, pos_x, pos_y, hasMask) # draw bitmap if available
       
   174             pos_x = (width-tw)/2+dw      # adjust for bitmap and text to centre
       
   175             pos_y += bh + 2
       
   176 
       
   177         dc.DrawText(label, pos_x, pos_y)      # draw the text
       
   178 
   130 
   179 
   131 class GenStaticBitmap(wx.lib.statbmp.GenStaticBitmap):
   180 class GenStaticBitmap(wx.lib.statbmp.GenStaticBitmap):
   132     """ Customized GenStaticBitmap, fix transparency redraw bug on wx2.8/win32, 
   181     """ Customized GenStaticBitmap, fix transparency redraw bug on wx2.8/win32, 
   133     and accept image name as __init__ parameter, fail silently if file do not exist"""
   182     and accept image name as __init__ parameter, fail silently if file do not exist"""
   134     def __init__(self, parent, ID, bitmapname,
   183     def __init__(self, parent, ID, bitmapname,
   587 #            addbutton.SetToolTipString("Add a \"%s\" plugin to this one"%name)
   636 #            addbutton.SetToolTipString("Add a \"%s\" plugin to this one"%name)
   588 #            addbutton.Bind(wx.EVT_BUTTON, self._GetAddPluginFunction(name, plugin), id=addbutton_id)
   637 #            addbutton.Bind(wx.EVT_BUTTON, self._GetAddPluginFunction(name, plugin), id=addbutton_id)
   589 #            addsizer.AddWindow(addbutton, 0, border=0, flag=0)
   638 #            addsizer.AddWindow(addbutton, 0, border=0, flag=0)
   590 #        return addsizer
   639 #        return addsizer
   591 
   640 
       
   641     normal_bt_font=wx.Font(faces["size"] / 3, wx.DEFAULT, wx.NORMAL, 0, faceName = faces["helv"])
       
   642     mouseover_bt_font=wx.Font(faces["size"] / 3, wx.DEFAULT, wx.NORMAL, 0, underline=True, faceName = faces["helv"])
   592     def GenerateMethodButtonSizer(self, plugin, parent, horizontal = True):
   643     def GenerateMethodButtonSizer(self, plugin, parent, horizontal = True):
   593         if horizontal:
   644         if horizontal:
   594             msizer = wx.FlexGridSizer(cols=len(plugin.PluginMethods))
   645             msizer = wx.FlexGridSizer(cols=len(plugin.PluginMethods))
   595         else:
   646         else:
   596             msizer = wx.FlexGridSizer(cols=1)
   647             msizer = wx.FlexGridSizer(cols=1)
   597         for plugin_method in plugin.PluginMethods:
   648         for plugin_method in plugin.PluginMethods:
   598             if "method" in plugin_method and plugin_method.get("shown",True):
   649             if "method" in plugin_method and plugin_method.get("shown",True):
   599                 id = wx.NewId()
   650                 id = wx.NewId()
       
   651                 label=plugin_method["name"]
   600                 button = GenBitmapTextButton(id=id, parent=parent,
   652                 button = GenBitmapTextButton(id=id, parent=parent,
   601                     bitmap=wx.Bitmap(Bpath( "%s.png"%plugin_method.get("bitmap", os.path.join("images", "Unknown")))), label=plugin_method["name"], 
   653                     bitmap=wx.Bitmap(Bpath( "%s.png"%plugin_method.get("bitmap", os.path.join("images", "Unknown")))), label=label, 
   602                     name=plugin_method["name"], pos=wx.DefaultPosition, style=wx.NO_BORDER)
   654                     name=label, pos=wx.DefaultPosition, style=wx.NO_BORDER)
       
   655                 button.SetFont(self.normal_bt_font)
   603                 button.SetToolTipString(plugin_method["tooltip"])
   656                 button.SetToolTipString(plugin_method["tooltip"])
   604                 button.Bind(wx.EVT_BUTTON, self.GetButtonCallBackFunction(plugin, plugin_method["method"]), id=id)
   657                 button.Bind(wx.EVT_BUTTON, self.GetButtonCallBackFunction(plugin, plugin_method["method"]), id=id)
       
   658                 # a fancy underline on mouseover
       
   659                 def setFontStyle(b, s):
       
   660                     def fn(event):
       
   661                         b.SetFont(s)
       
   662                         b.Refresh()
       
   663                         event.Skip()
       
   664                     return fn
       
   665                 button.Bind(wx.EVT_ENTER_WINDOW, setFontStyle(button, self.mouseover_bt_font))
       
   666                 button.Bind(wx.EVT_LEAVE_WINDOW, setFontStyle(button, self.normal_bt_font))
   605                 #hack to force size to mini
   667                 #hack to force size to mini
   606                 if not plugin_method.get("enabled",True):
   668                 if not plugin_method.get("enabled",True):
   607                     button.Disable()
   669                     button.Disable()
   608                 msizer.AddWindow(button, 0, border=0, flag=0)
   670                 msizer.AddWindow(button, 0, border=0, flag=wx.ALIGN_CENTER)
   609         return msizer
   671         return msizer
   610 
   672 
   611     def RefreshPluginTree(self):
   673     def RefreshPluginTree(self):
   612         self.Freeze()
   674         self.Freeze()
   613         self.ClearSizer(self.PluginTreeSizer)
   675         self.ClearSizer(self.PluginTreeSizer)