LPCManager.py
changeset 53 d92a0c3040a4
parent 52 7fc0928030b6
child 55 0be064739434
equal deleted inserted replaced
52:7fc0928030b6 53:d92a0c3040a4
   134               'helv' : 'Helvetica',
   134               'helv' : 'Helvetica',
   135               'other': 'new century schoolbook',
   135               'other': 'new century schoolbook',
   136               'size' : 18,
   136               'size' : 18,
   137              }
   137              }
   138 
   138 
   139 # Some helpers to tweak GenBitmapTextButtons
   139 from editors.ConfTreeNodeEditor import GenBitmapTextButton
   140 # TODO: declare customized classes instead.
       
   141 gen_mini_GetBackgroundBrush = lambda obj:lambda dc: wx.Brush(obj.GetParent().GetBackgroundColour(), wx.SOLID)
       
   142 gen_textbutton_GetLabelSize = lambda obj:lambda:(wx.lib.buttons.GenButton._GetLabelSize(obj)[:-1] + (False,))
       
   143 
       
   144 def make_genbitmaptogglebutton_flat(button):
       
   145     button.GetBackgroundBrush = gen_mini_GetBackgroundBrush(button)
       
   146     button.labelDelta = 0
       
   147     button.SetBezelWidth(0)
       
   148     button.SetUseFocusIndicator(False)
       
   149 
       
   150 # Patch wx.lib.imageutils so that gray is supported on alpha images
       
   151 import wx.lib.imageutils
       
   152 from wx.lib.imageutils import grayOut as old_grayOut
       
   153 def grayOut(anImage):
       
   154     if anImage.HasAlpha():
       
   155         AlphaData = anImage.GetAlphaData()
       
   156     else :
       
   157         AlphaData = None
       
   158 
       
   159     old_grayOut(anImage)
       
   160 
       
   161     if AlphaData is not None:
       
   162         anImage.SetAlphaData(AlphaData)
       
   163 
       
   164 wx.lib.imageutils.grayOut = grayOut
       
   165 
       
   166 class GenBitmapTextButton(wx.lib.buttons.GenBitmapTextButton):
       
   167     def _GetLabelSize(self):
       
   168         """ used internally """
       
   169         w, h = self.GetTextExtent(self.GetLabel())
       
   170         if not self.bmpLabel:
       
   171             return w, h, False       # if there isn't a bitmap use the size of the text
       
   172 
       
   173         w_bmp = self.bmpLabel.GetWidth()+2
       
   174         h_bmp = self.bmpLabel.GetHeight()+2
       
   175         height = h + h_bmp
       
   176         if w_bmp > w:
       
   177             width = w_bmp
       
   178         else:
       
   179             width = w
       
   180         return width, height, False
       
   181 
       
   182     def DrawLabel(self, dc, width, height, dw=0, dy=0):
       
   183         bmp = self.bmpLabel
       
   184         if bmp != None:     # if the bitmap is used
       
   185             if self.bmpDisabled and not self.IsEnabled():
       
   186                 bmp = self.bmpDisabled
       
   187             if self.bmpFocus and self.hasFocus:
       
   188                 bmp = self.bmpFocus
       
   189             if self.bmpSelected and not self.up:
       
   190                 bmp = self.bmpSelected
       
   191             bw,bh = bmp.GetWidth(), bmp.GetHeight()
       
   192             if not self.up:
       
   193                 dw = dy = self.labelDelta
       
   194             hasMask = bmp.GetMask() != None
       
   195         else:
       
   196             bw = bh = 0     # no bitmap -> size is zero
       
   197 
       
   198         dc.SetFont(self.GetFont())
       
   199         if self.IsEnabled():
       
   200             dc.SetTextForeground(self.GetForegroundColour())
       
   201         else:
       
   202             dc.SetTextForeground(wx.SystemSettings.GetColour(wx.SYS_COLOUR_GRAYTEXT))
       
   203 
       
   204         label = self.GetLabel()
       
   205         tw, th = dc.GetTextExtent(label)        # size of text
       
   206         if not self.up:
       
   207             dw = dy = self.labelDelta
       
   208 
       
   209         pos_x = (width-bw)/2+dw      # adjust for bitmap and text to centre
       
   210         pos_y = (height-bh-th)/2+dy
       
   211         if bmp !=None:
       
   212             dc.DrawBitmap(bmp, pos_x, pos_y, hasMask) # draw bitmap if available
       
   213             pos_x = (width-tw)/2+dw      # adjust for bitmap and text to centre
       
   214             pos_y += bh + 2
       
   215 
       
   216         dc.DrawText(label, pos_x, pos_y)      # draw the text
       
   217 
       
   218 
   140 
   219 #-------------------------------------------------------------------------------
   141 #-------------------------------------------------------------------------------
   220 #                          CANFESTIVAL CONFNODE HACK
   142 #                          CANFESTIVAL CONFNODE HACK
   221 #-------------------------------------------------------------------------------
   143 #-------------------------------------------------------------------------------
   222 # from canfestival import canfestival
   144 # from canfestival import canfestival
   727             return "LPC"
   649             return "LPC"
   728 
   650 
   729     def GetTarget(self):
   651     def GetTarget(self):
   730         target = ProjectController.GetTarget(self)
   652         target = ProjectController.GetTarget(self)
   731         if self.CurrentMode != SIMULATION_MODE:
   653         if self.CurrentMode != SIMULATION_MODE:
   732             target.getcontent()["value"].setBuildPath(self.BuildPath)
   654             target.getcontent().setBuildPath(self.BuildPath)
   733         return target
   655         return target
   734     
   656     
   735     def _getBuildPath(self):
   657     def _getBuildPath(self):
   736         if self.CurrentMode == SIMULATION_MODE:
   658         if self.CurrentMode == SIMULATION_MODE:
   737             if self.SimulationBuildPath is None:
   659             if self.SimulationBuildPath is None:
  1329         self.Bind(wx.EVT_MENU, self.AddResourceMenu, id=new_id)
  1251         self.Bind(wx.EVT_MENU, self.AddResourceMenu, id=new_id)
  1330     
  1252     
  1331     def _init_ctrls(self, prnt):
  1253     def _init_ctrls(self, prnt):
  1332         Beremiz._init_ctrls(self, prnt)
  1254         Beremiz._init_ctrls(self, prnt)
  1333         
  1255         
  1334         self.PLCConfig = wx.ScrolledWindow(id=ID_BEREMIZPLCCONFIG,
  1256         self.PLCConfig = wx.ScrolledWindow(
  1335               name='PLCConfig', parent=self.LeftNoteBook, pos=wx.Point(0, 0),
  1257               name='PLCConfig', parent=self.LeftNoteBook, pos=wx.Point(0, 0),
  1336               size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER|wx.HSCROLL|wx.VSCROLL)
  1258               size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER|wx.HSCROLL|wx.VSCROLL)
  1337         self.PLCConfig.SetBackgroundColour(wx.WHITE)
  1259         self.PLCConfig.SetBackgroundColour(wx.WHITE)
  1338         self.PLCConfig.Bind(wx.EVT_LEFT_DOWN, self.OnPanelLeftDown)
  1260         self.PLCConfig.Bind(wx.EVT_LEFT_DOWN, self.OnPanelLeftDown)
  1339         self.PLCConfig.Bind(wx.EVT_SIZE, self.OnMoveWindow)
  1261         self.PLCConfig.Bind(wx.EVT_SIZE, self.OnMoveWindow)
  2234     Log = StdoutPseudoFile(port)
  2156     Log = StdoutPseudoFile(port)
  2235 
  2157 
  2236     if projectOpen is not None:
  2158     if projectOpen is not None:
  2237         projectOpen = DecodeFileSystemPath(projectOpen, False)
  2159         projectOpen = DecodeFileSystemPath(projectOpen, False)
  2238     
  2160     
  2239     CTR = LPCProjectController(None, Log, buildpath)
  2161     CTR = LPCProjectController(None, Log, DecodeFileSystemPath(buildpath))
  2240     if projectOpen is not None and os.path.isdir(projectOpen):
  2162     if projectOpen is not None and os.path.isdir(projectOpen):
  2241         result = CTR.LoadProject(projectOpen)
  2163         result = CTR.LoadProject(projectOpen)
  2242         if result:
  2164         if result:
  2243             Log.write("Error: Invalid project directory", result)
  2165             Log.write("Error: Invalid project directory", result)
  2244     else:
  2166     else: