lbessard@0: #!/usr/bin/env python lbessard@0: # -*- coding: utf-8 -*- lbessard@0: lbessard@3: #This file is part of Beremiz, a Integrated Development Environment for lbessard@3: #programming IEC 61131-3 automates supporting plcopen standard and CanFestival. lbessard@0: # lbessard@3: #Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD lbessard@0: # lbessard@0: #See COPYING file for copyrights details. lbessard@0: # lbessard@0: #This library is free software; you can redistribute it and/or lbessard@0: #modify it under the terms of the GNU General Public lbessard@0: #License as published by the Free Software Foundation; either lbessard@0: #version 2.1 of the License, or (at your option) any later version. lbessard@0: # lbessard@0: #This library is distributed in the hope that it will be useful, lbessard@0: #but WITHOUT ANY WARRANTY; without even the implied warranty of lbessard@0: #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU lbessard@3: #General Public License for more details. lbessard@0: # lbessard@0: #You should have received a copy of the GNU General Public lbessard@0: #License along with this library; if not, write to the Free Software lbessard@0: #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA lbessard@0: etisserant@13: __version__ = "$Revision$" etisserant@13: etisserant@117: import os, sys, getopt, wx etisserant@217: import tempfile etisserant@217: import shutil etisserant@227: import random etisserant@217: etisserant@217: _local_path = os.path.split(os.path.realpath(__file__))[0] etisserant@217: def Bpath(*args): etisserant@217: return os.path.join(_local_path,*args) etisserant@117: etisserant@117: if __name__ == '__main__': etisserant@117: def usage(): etisserant@117: print "\nUsage of Beremiz.py :" greg@256: print "\n %s [Projectpath] [Buildpath]\n"%sys.argv[0] etisserant@117: etisserant@117: try: etisserant@117: opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) etisserant@117: except getopt.GetoptError: etisserant@117: # print help information and exit: etisserant@117: usage() etisserant@117: sys.exit(2) etisserant@117: etisserant@117: for o, a in opts: etisserant@117: if o in ("-h", "--help"): etisserant@117: usage() etisserant@117: sys.exit() etisserant@117: greg@256: if len(args) > 2: etisserant@117: usage() etisserant@117: sys.exit() etisserant@117: elif len(args) == 1: etisserant@117: projectOpen = args[0] greg@260: buildpath = None greg@256: elif len(args) == 2: greg@256: projectOpen = args[0] greg@256: buildpath = args[1] etisserant@117: else: etisserant@117: projectOpen = None greg@256: buildpath = None etisserant@117: etisserant@117: app = wx.PySimpleApp() greg@257: app.SetAppName('beremiz') greg@257: config = wx.ConfigBase.Get() etisserant@117: wx.InitAllImageHandlers() etisserant@117: etisserant@217: bmp = wx.Image(Bpath("images","splash.png")).ConvertToBitmap() etisserant@117: splash=wx.SplashScreen(bmp,wx.SPLASH_CENTRE_ON_SCREEN, 1000, None) etisserant@117: wx.Yield() etisserant@117: greg@134: import wx.lib.buttons, wx.lib.statbmp greg@268: import TextCtrlAutoComplete, cPickle etisserant@117: import types, time, re, platform, time, traceback, commands lbessard@356: from plugger import PluginsRoot, MATIEC_ERROR_MODEL etisserant@217: from wxPopen import ProcessLogger greg@122: greg@120: base_folder = os.path.split(sys.path[0])[0] greg@136: sys.path.append(base_folder) greg@136: from docutils import * lbessard@0: lbessard@97: SCROLLBAR_UNIT = 10 lbessard@97: WINDOW_COLOUR = wx.Colour(240,240,240) etisserant@106: TITLE_COLOUR = wx.Colour(200,200,220) etisserant@118: CHANGED_TITLE_COLOUR = wx.Colour(220,200,220) etisserant@118: CHANGED_WINDOW_COLOUR = wx.Colour(255,240,240) lbessard@97: lbessard@97: if wx.Platform == '__WXMSW__': lbessard@97: faces = { 'times': 'Times New Roman', lbessard@97: 'mono' : 'Courier New', lbessard@97: 'helv' : 'Arial', lbessard@97: 'other': 'Comic Sans MS', lbessard@98: 'size' : 16, lbessard@97: } lbessard@97: else: lbessard@97: faces = { 'times': 'Times', lbessard@97: 'mono' : 'Courier', lbessard@97: 'helv' : 'Helvetica', lbessard@97: 'other': 'new century schoolbook', lbessard@97: 'size' : 18, lbessard@97: } lbessard@97: etisserant@109: # Some helpers to tweak GenBitmapTextButtons etisserant@109: # TODO: declare customized classes instead. etisserant@106: gen_mini_GetBackgroundBrush = lambda obj:lambda dc: wx.Brush(obj.GetParent().GetBackgroundColour(), wx.SOLID) lbessard@98: gen_textbutton_GetLabelSize = lambda obj:lambda:(wx.lib.buttons.GenButton._GetLabelSize(obj)[:-1] + (False,)) lbessard@98: etisserant@106: def make_genbitmaptogglebutton_flat(button): etisserant@106: button.GetBackgroundBrush = gen_mini_GetBackgroundBrush(button) etisserant@106: button.labelDelta = 0 etisserant@106: button.SetBezelWidth(0) etisserant@106: button.SetUseFocusIndicator(False) etisserant@106: etisserant@109: # Patch wx.lib.imageutils so that gray is supported on alpha images etisserant@109: import wx.lib.imageutils etisserant@110: from wx.lib.imageutils import grayOut as old_grayOut etisserant@109: def grayOut(anImage): etisserant@109: if anImage.HasAlpha(): etisserant@109: AlphaData = anImage.GetAlphaData() etisserant@109: else : etisserant@109: AlphaData = None etisserant@109: etisserant@110: old_grayOut(anImage) etisserant@109: etisserant@109: if AlphaData is not None: etisserant@109: anImage.SetAlphaData(AlphaData) etisserant@109: etisserant@109: wx.lib.imageutils.grayOut = grayOut etisserant@109: etisserant@109: class GenBitmapTextButton(wx.lib.buttons.GenBitmapTextButton): etisserant@109: def _GetLabelSize(self): etisserant@230: """ used internally """ etisserant@230: w, h = self.GetTextExtent(self.GetLabel()) etisserant@230: if not self.bmpLabel: etisserant@230: return w, h, False # if there isn't a bitmap use the size of the text etisserant@230: etisserant@230: w_bmp = self.bmpLabel.GetWidth()+2 etisserant@230: h_bmp = self.bmpLabel.GetHeight()+2 etisserant@230: height = h + h_bmp etisserant@230: if w_bmp > w: etisserant@230: width = w_bmp etisserant@230: else: etisserant@230: width = w etisserant@230: return width, height, False etisserant@230: etisserant@230: def DrawLabel(self, dc, width, height, dw=0, dy=0): etisserant@230: bmp = self.bmpLabel etisserant@230: if bmp != None: # if the bitmap is used etisserant@230: if self.bmpDisabled and not self.IsEnabled(): etisserant@230: bmp = self.bmpDisabled etisserant@230: if self.bmpFocus and self.hasFocus: etisserant@230: bmp = self.bmpFocus etisserant@230: if self.bmpSelected and not self.up: etisserant@230: bmp = self.bmpSelected etisserant@230: bw,bh = bmp.GetWidth(), bmp.GetHeight() etisserant@230: if not self.up: etisserant@230: dw = dy = self.labelDelta etisserant@230: hasMask = bmp.GetMask() != None etisserant@230: else: etisserant@230: bw = bh = 0 # no bitmap -> size is zero etisserant@230: etisserant@230: dc.SetFont(self.GetFont()) etisserant@230: if self.IsEnabled(): etisserant@230: dc.SetTextForeground(self.GetForegroundColour()) etisserant@230: else: etisserant@230: dc.SetTextForeground(wx.SystemSettings.GetColour(wx.SYS_COLOUR_GRAYTEXT)) etisserant@230: etisserant@230: label = self.GetLabel() etisserant@230: tw, th = dc.GetTextExtent(label) # size of text etisserant@230: if not self.up: etisserant@230: dw = dy = self.labelDelta etisserant@230: etisserant@230: pos_x = (width-bw)/2+dw # adjust for bitmap and text to centre etisserant@230: pos_y = (height-bh-th)/2+dy etisserant@230: if bmp !=None: etisserant@230: dc.DrawBitmap(bmp, pos_x, pos_y, hasMask) # draw bitmap if available etisserant@230: pos_x = (width-tw)/2+dw # adjust for bitmap and text to centre etisserant@230: pos_y += bh + 2 etisserant@230: etisserant@230: dc.DrawText(label, pos_x, pos_y) # draw the text etisserant@230: etisserant@106: etisserant@106: class GenStaticBitmap(wx.lib.statbmp.GenStaticBitmap): etisserant@109: """ Customized GenStaticBitmap, fix transparency redraw bug on wx2.8/win32, etisserant@109: and accept image name as __init__ parameter, fail silently if file do not exist""" etisserant@106: def __init__(self, parent, ID, bitmapname, etisserant@106: pos = wx.DefaultPosition, size = wx.DefaultSize, etisserant@106: style = 0, etisserant@106: name = "genstatbmp"): etisserant@106: etisserant@217: bitmappath = Bpath( "images", bitmapname) etisserant@106: if os.path.isfile(bitmappath): etisserant@106: bitmap = wx.Bitmap(bitmappath) etisserant@106: else: etisserant@106: bitmap = None etisserant@106: wx.lib.statbmp.GenStaticBitmap.__init__(self, parent, ID, bitmap, etisserant@106: pos, size, etisserant@106: style, etisserant@106: name) etisserant@106: etisserant@106: def OnPaint(self, event): etisserant@106: dc = wx.PaintDC(self) etisserant@106: colour = self.GetParent().GetBackgroundColour() etisserant@106: dc.SetPen(wx.Pen(colour)) etisserant@106: dc.SetBrush(wx.Brush(colour )) etisserant@106: dc.DrawRectangle(0, 0, *dc.GetSizeTuple()) etisserant@106: if self._bitmap: etisserant@106: dc.DrawBitmap(self._bitmap, 0, 0, True) etisserant@106: lbessard@97: lbessard@1: class LogPseudoFile: lbessard@1: """ Base class for file like objects to facilitate StdOut for the Shell.""" etisserant@110: def __init__(self, output): etisserant@7: self.red_white = wx.TextAttr("RED", "WHITE") etisserant@7: self.red_yellow = wx.TextAttr("RED", "YELLOW") etisserant@7: self.black_white = wx.TextAttr("BLACK", "WHITE") etisserant@7: self.default_style = None lbessard@1: self.output = output lbessard@1: etisserant@22: def write(self, s, style = None): etisserant@110: if style is None : style=self.black_white etisserant@110: self.output.Freeze(); etisserant@22: if self.default_style != style: etisserant@22: self.output.SetDefaultStyle(style) etisserant@22: self.default_style = style etisserant@110: self.output.AppendText(s) etisserant@110: self.output.ScrollLines(s.count('\n')+1) etisserant@110: self.output.ShowPosition(self.output.GetLastPosition()) etisserant@110: self.output.Thaw() etisserant@7: etisserant@7: def write_warning(self, s): etisserant@22: self.write(s,self.red_white) etisserant@7: etisserant@7: def write_error(self, s): etisserant@22: self.write(s,self.red_yellow) lbessard@1: lbessard@1: def flush(self): lbessard@1: self.output.SetValue("") lbessard@1: lbessard@1: def isatty(self): lbessard@1: return false lbessard@1: lbessard@17: [ID_BEREMIZ, ID_BEREMIZMAINSPLITTER, lbessard@97: ID_BEREMIZPLCCONFIG, ID_BEREMIZLOGCONSOLE, etisserant@121: ID_BEREMIZINSPECTOR] = [wx.NewId() for _init_ctrls in range(5)] lbessard@0: lbessard@127: [ID_BEREMIZRUNMENUBUILD, ID_BEREMIZRUNMENUSIMULATE, lbessard@127: ID_BEREMIZRUNMENURUN, ID_BEREMIZRUNMENUSAVELOG, lbessard@0: ] = [wx.NewId() for _init_coll_EditMenu_Items in range(4)] lbessard@0: lbessard@0: class Beremiz(wx.Frame): greg@120: lbessard@0: def _init_coll_FileMenu_Items(self, parent): lbessard@127: parent.Append(help='', id=wx.ID_NEW, lbessard@0: kind=wx.ITEM_NORMAL, text=u'New\tCTRL+N') lbessard@127: parent.Append(help='', id=wx.ID_OPEN, lbessard@0: kind=wx.ITEM_NORMAL, text=u'Open\tCTRL+O') lbessard@127: parent.Append(help='', id=wx.ID_SAVE, lbessard@0: kind=wx.ITEM_NORMAL, text=u'Save\tCTRL+S') lbessard@248: parent.Append(help='', id=wx.ID_CLOSE_ALL, lbessard@0: kind=wx.ITEM_NORMAL, text=u'Close Project') lbessard@0: parent.AppendSeparator() lbessard@127: parent.Append(help='', id=wx.ID_PROPERTIES, lbessard@0: kind=wx.ITEM_NORMAL, text=u'Properties') lbessard@0: parent.AppendSeparator() lbessard@127: parent.Append(help='', id=wx.ID_EXIT, lbessard@0: kind=wx.ITEM_NORMAL, text=u'Quit\tCTRL+Q') lbessard@127: self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, id=wx.ID_NEW) lbessard@127: self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, id=wx.ID_OPEN) lbessard@127: self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE) lbessard@242: self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, id=wx.ID_CLOSE_ALL) lbessard@127: self.Bind(wx.EVT_MENU, self.OnPropertiesMenu, id=wx.ID_PROPERTIES) lbessard@127: self.Bind(wx.EVT_MENU, self.OnQuitMenu, id=wx.ID_EXIT) lbessard@0: lbessard@0: def _init_coll_EditMenu_Items(self, parent): lbessard@127: parent.Append(help='', id=wx.ID_EDIT, lbessard@0: kind=wx.ITEM_NORMAL, text=u'Edit PLC\tCTRL+R') lbessard@0: parent.AppendSeparator() lbessard@127: parent.Append(help='', id=wx.ID_ADD, lbessard@17: kind=wx.ITEM_NORMAL, text=u'Add Plugin') lbessard@127: parent.Append(help='', id=wx.ID_DELETE, lbessard@17: kind=wx.ITEM_NORMAL, text=u'Delete Plugin') lbessard@127: self.Bind(wx.EVT_MENU, self.OnEditPLCMenu, id=wx.ID_EDIT) lbessard@127: self.Bind(wx.EVT_MENU, self.OnAddMenu, id=wx.ID_ADD) lbessard@127: self.Bind(wx.EVT_MENU, self.OnDeleteMenu, id=wx.ID_DELETE) lbessard@0: lbessard@0: def _init_coll_RunMenu_Items(self, parent): lbessard@127: parent.Append(help='', id=ID_BEREMIZRUNMENUBUILD, lbessard@0: kind=wx.ITEM_NORMAL, text=u'Build\tCTRL+R') lbessard@0: parent.AppendSeparator() lbessard@127: parent.Append(help='', id=ID_BEREMIZRUNMENUSIMULATE, lbessard@0: kind=wx.ITEM_NORMAL, text=u'Simulate') lbessard@127: parent.Append(help='', id=ID_BEREMIZRUNMENURUN, lbessard@0: kind=wx.ITEM_NORMAL, text=u'Run') lbessard@0: parent.AppendSeparator() lbessard@127: parent.Append(help='', id=ID_BEREMIZRUNMENUSAVELOG, lbessard@0: kind=wx.ITEM_NORMAL, text=u'Save Log') lbessard@1: self.Bind(wx.EVT_MENU, self.OnBuildMenu, lbessard@127: id=ID_BEREMIZRUNMENUBUILD) lbessard@0: self.Bind(wx.EVT_MENU, self.OnSimulateMenu, lbessard@127: id=ID_BEREMIZRUNMENUSIMULATE) lbessard@0: self.Bind(wx.EVT_MENU, self.OnRunMenu, lbessard@127: id=ID_BEREMIZRUNMENURUN) lbessard@0: self.Bind(wx.EVT_MENU, self.OnSaveLogMenu, lbessard@127: id=ID_BEREMIZRUNMENUSAVELOG) lbessard@0: lbessard@0: def _init_coll_HelpMenu_Items(self, parent): lbessard@127: parent.Append(help='', id=wx.ID_HELP, lbessard@0: kind=wx.ITEM_NORMAL, text=u'Beremiz\tF1') lbessard@127: parent.Append(help='', id=wx.ID_ABOUT, lbessard@0: kind=wx.ITEM_NORMAL, text=u'About') lbessard@127: self.Bind(wx.EVT_MENU, self.OnBeremizMenu, id=wx.ID_HELP) lbessard@127: self.Bind(wx.EVT_MENU, self.OnAboutMenu, id=wx.ID_ABOUT) lbessard@127: lbessard@127: def _init_coll_MenuBar_Menus(self, parent): lbessard@0: parent.Append(menu=self.FileMenu, title=u'File') etisserant@28: #parent.Append(menu=self.EditMenu, title=u'Edit') etisserant@28: #parent.Append(menu=self.RunMenu, title=u'Run') lbessard@0: parent.Append(menu=self.HelpMenu, title=u'Help') lbessard@0: lbessard@0: def _init_utils(self): lbessard@127: self.MenuBar = wx.MenuBar() lbessard@0: self.FileMenu = wx.Menu(title=u'') etisserant@28: #self.EditMenu = wx.Menu(title=u'') etisserant@28: #self.RunMenu = wx.Menu(title=u'') lbessard@0: self.HelpMenu = wx.Menu(title=u'') lbessard@0: lbessard@127: self._init_coll_MenuBar_Menus(self.MenuBar) lbessard@0: self._init_coll_FileMenu_Items(self.FileMenu) etisserant@28: #self._init_coll_EditMenu_Items(self.EditMenu) etisserant@28: #self._init_coll_RunMenu_Items(self.RunMenu) lbessard@0: self._init_coll_HelpMenu_Items(self.HelpMenu) lbessard@0: lbessard@97: def _init_coll_PLCConfigMainSizer_Items(self, parent): lbessard@97: parent.AddSizer(self.PLCParamsSizer, 0, border=10, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) lbessard@97: parent.AddSizer(self.PluginTreeSizer, 0, border=10, flag=wx.BOTTOM|wx.LEFT|wx.RIGHT) lbessard@97: lbessard@97: def _init_coll_PLCConfigMainSizer_Growables(self, parent): lbessard@67: parent.AddGrowableCol(0) lbessard@67: parent.AddGrowableRow(1) lbessard@67: lbessard@97: def _init_coll_PluginTreeSizer_Growables(self, parent): lbessard@17: parent.AddGrowableCol(0) lbessard@97: parent.AddGrowableCol(1) lbessard@0: lbessard@0: def _init_sizers(self): lbessard@97: self.PLCConfigMainSizer = wx.FlexGridSizer(cols=1, hgap=2, rows=2, vgap=2) lbessard@97: self.PLCParamsSizer = wx.BoxSizer(wx.VERTICAL) etisserant@106: #self.PluginTreeSizer = wx.FlexGridSizer(cols=3, hgap=0, rows=0, vgap=2) etisserant@106: self.PluginTreeSizer = wx.FlexGridSizer(cols=2, hgap=0, rows=0, vgap=2) lbessard@97: lbessard@97: self._init_coll_PLCConfigMainSizer_Items(self.PLCConfigMainSizer) lbessard@97: self._init_coll_PLCConfigMainSizer_Growables(self.PLCConfigMainSizer) lbessard@97: self._init_coll_PluginTreeSizer_Growables(self.PluginTreeSizer) lbessard@97: lbessard@97: self.PLCConfig.SetSizer(self.PLCConfigMainSizer) lbessard@97: lbessard@0: def _init_ctrls(self, prnt): lbessard@4: wx.Frame.__init__(self, id=ID_BEREMIZ, name=u'Beremiz', lbessard@17: parent=prnt, pos=wx.Point(0, 0), size=wx.Size(1000, 600), lbessard@25: style=wx.DEFAULT_FRAME_STYLE|wx.CLIP_CHILDREN, title=u'Beremiz') lbessard@0: self._init_utils() lbessard@17: self.SetClientSize(wx.Size(1000, 600)) lbessard@127: self.SetMenuBar(self.MenuBar) lbessard@62: self.Bind(wx.EVT_ACTIVATE, self.OnFrameActivated) etisserant@118: self.Bind(wx.EVT_CLOSE, self.OnCloseFrame) etisserant@121: etisserant@121: self.Bind(wx.EVT_MENU, self.OnOpenWidgetInspector, id=ID_BEREMIZINSPECTOR) etisserant@200: accel = wx.AcceleratorTable([wx.AcceleratorEntry(wx.ACCEL_CTRL|wx.ACCEL_ALT, ord('I'), ID_BEREMIZINSPECTOR)]) etisserant@121: self.SetAcceleratorTable(accel) lbessard@0: lbessard@71: if wx.VERSION < (2, 8, 0): lbessard@71: self.MainSplitter = wx.SplitterWindow(id=ID_BEREMIZMAINSPLITTER, lbessard@71: name='MainSplitter', parent=self, point=wx.Point(0, 0), lbessard@71: size=wx.Size(0, 0), style=wx.SP_3D) lbessard@71: self.MainSplitter.SetNeedUpdating(True) lbessard@71: self.MainSplitter.SetMinimumPaneSize(1) lbessard@71: lbessard@97: parent = self.MainSplitter lbessard@97: else: lbessard@97: parent = self lbessard@97: lbessard@97: self.PLCConfig = wx.ScrolledWindow(id=ID_BEREMIZPLCCONFIG, lbessard@97: name='PLCConfig', parent=parent, pos=wx.Point(0, 0), lbessard@97: size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER|wx.HSCROLL|wx.VSCROLL) lbessard@97: self.PLCConfig.SetBackgroundColour(wx.WHITE) lbessard@296: self.PLCConfig.Bind(wx.EVT_LEFT_DOWN, self.OnPanelLeftDown) lbessard@97: self.PLCConfig.Bind(wx.EVT_SIZE, self.OnMoveWindow) lbessard@97: lbessard@97: self.LogConsole = wx.TextCtrl(id=ID_BEREMIZLOGCONSOLE, value='', lbessard@97: name='LogConsole', parent=parent, pos=wx.Point(0, 0), lbessard@71: size=wx.Size(0, 0), style=wx.TE_MULTILINE|wx.TE_RICH2) lbessard@201: self.LogConsole.Bind(wx.EVT_LEFT_DCLICK, self.OnLogConsoleDClick) lbessard@97: lbessard@97: if wx.VERSION < (2, 8, 0): lbessard@97: self.MainSplitter.SplitHorizontally(self.PLCConfig, self.LogConsole, -250) lbessard@71: else: lbessard@82: self.AUIManager = wx.aui.AuiManager(self) lbessard@82: self.AUIManager.SetDockSizeConstraint(0.5, 0.5) lbessard@97: lbessard@97: self.AUIManager.AddPane(self.PLCConfig, wx.aui.AuiPaneInfo().CenterPane()) lbessard@97: lbessard@97: self.AUIManager.AddPane(self.LogConsole, wx.aui.AuiPaneInfo(). lbessard@97: Caption("Log Console").Bottom().Layer(1). lbessard@97: BestSize(wx.Size(800, 200)).CloseButton(False)) lbessard@82: lbessard@71: self.AUIManager.Update() etisserant@13: lbessard@97: self._init_sizers() lbessard@97: greg@256: def __init__(self, parent, projectOpen, buildpath): lbessard@0: self._init_ctrls(parent) lbessard@0: lbessard@17: self.Log = LogPseudoFile(self.LogConsole) etisserant@290: etisserant@290: self.local_runtime = None etisserant@290: self.runtime_port = None etisserant@290: self.local_runtime_tmpdir = None etisserant@217: greg@116: # Add beremiz's icon in top left corner of the frame etisserant@217: self.SetIcon(wx.Icon(Bpath( "images", "brz.ico"), wx.BITMAP_TYPE_ICO)) greg@116: lbessard@82: self.DisableEvents = False lbessard@17: lbessard@97: self.PluginInfos = {} lbessard@97: lbessard@17: if projectOpen: etisserant@290: self.PluginRoot = PluginsRoot(self, self.Log) greg@256: self.PluginRoot.LoadProject(projectOpen, buildpath) greg@268: self.RefreshAll() lbessard@248: else: lbessard@248: self.PluginRoot = None lbessard@82: lbessard@0: self.RefreshMainMenu() etisserant@118: etisserant@290: def StartLocalRuntime(self, taskbaricon = True): etisserant@290: if self.local_runtime is None or self.local_runtime.finished: etisserant@290: # create temporary directory for runtime working directory etisserant@290: self.local_runtime_tmpdir = tempfile.mkdtemp() etisserant@290: # choose an arbitrary random port for runtime etisserant@290: self.runtime_port = int(random.random() * 1000) + 61131 etisserant@290: # launch local runtime etisserant@290: self.local_runtime = ProcessLogger(self.Log, etisserant@290: "\"%s\" \"%s\" -p %s -i localhost %s %s"%(sys.executable, etisserant@290: Bpath("Beremiz_service.py"), etisserant@290: self.runtime_port, etisserant@290: {False : "-x 0", True :"-x 1"}[taskbaricon], etisserant@290: self.local_runtime_tmpdir), etisserant@290: no_gui=False) etisserant@290: self.local_runtime.spin(timeout=500, keyword = "working", kill_it = False) etisserant@290: return self.runtime_port etisserant@290: etisserant@290: def KillLocalRuntime(self): etisserant@290: if self.local_runtime is not None: etisserant@290: # shutdown local runtime etisserant@290: self.local_runtime.kill(gently=False) etisserant@290: # clear temp dir etisserant@290: shutil.rmtree(self.local_runtime_tmpdir) etisserant@290: etisserant@121: def OnOpenWidgetInspector(self, evt): etisserant@121: # Activate the widget inspection tool etisserant@121: from wx.lib.inspection import InspectionTool etisserant@121: if not InspectionTool().initialized: etisserant@121: InspectionTool().Init() etisserant@121: etisserant@121: # Find a widget to be selected in the tree. Use either the etisserant@121: # one under the cursor, if any, or this frame. etisserant@121: wnd = wx.FindWindowAtPointer() etisserant@121: if not wnd: etisserant@121: wnd = self etisserant@121: InspectionTool().Show(wnd, True) etisserant@121: lbessard@201: def OnLogConsoleDClick(self, event): lbessard@201: wx.CallAfter(self.SearchLineForError) lbessard@201: event.Skip() lbessard@201: lbessard@201: def SearchLineForError(self): lbessard@248: if self.PluginRoot is not None: lbessard@248: text = self.LogConsole.GetRange(0, self.LogConsole.GetInsertionPoint()) lbessard@248: line = self.LogConsole.GetLineText(len(text.splitlines()) - 1) lbessard@248: result = MATIEC_ERROR_MODEL.match(line) lbessard@248: if result is not None: lbessard@248: first_line, first_column, last_line, last_column, error = result.groups() lbessard@248: infos = self.PluginRoot.ShowError(self.Log, lbessard@248: (int(first_line), int(first_column)), lbessard@248: (int(last_line), int(last_column))) lbessard@201: etisserant@118: def OnCloseFrame(self, event): lbessard@248: if self.PluginRoot is not None: etisserant@118: if self.PluginRoot.ProjectTestModified(): etisserant@217: dialog = wx.MessageDialog(self, etisserant@217: "Save changes ?", etisserant@217: "Close Application", etisserant@217: wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION) etisserant@119: answer = dialog.ShowModal() etisserant@119: dialog.Destroy() etisserant@119: if answer == wx.ID_YES: etisserant@119: self.PluginRoot.SaveProject() etisserant@119: event.Skip() etisserant@119: elif answer == wx.ID_NO: etisserant@119: event.Skip() etisserant@119: return etisserant@119: else: etisserant@119: event.Veto() etisserant@119: return etisserant@220: etisserant@290: self.KillLocalRuntime() etisserant@290: etisserant@118: event.Skip() lbessard@62: lbessard@97: def OnMoveWindow(self, event): lbessard@97: self.GetBestSize() lbessard@97: self.RefreshScrollBars() lbessard@97: event.Skip() lbessard@97: lbessard@62: def OnFrameActivated(self, event): lbessard@248: if not event.GetActive() and self.PluginRoot is not None: lbessard@62: self.PluginRoot.RefreshPluginsBlockLists() lbessard@62: lbessard@296: def OnPanelLeftDown(self, event): lbessard@296: focused = self.FindFocus() lbessard@296: if isinstance(focused, TextCtrlAutoComplete.TextCtrlAutoComplete): lbessard@296: focused._showDropDown(False) lbessard@296: event.Skip() lbessard@296: lbessard@0: def RefreshMainMenu(self): lbessard@248: if self.PluginRoot is not None: lbessard@248: ## self.MenuBar.EnableTop(1, True) lbessard@248: ## self.MenuBar.EnableTop(2, True) lbessard@248: self.FileMenu.Enable(wx.ID_SAVE, True) lbessard@249: self.FileMenu.Enable(wx.ID_CLOSE_ALL, True) lbessard@248: self.FileMenu.Enable(wx.ID_PROPERTIES, True) lbessard@248: else: lbessard@248: ## self.MenuBar.EnableTop(1, False) lbessard@248: ## self.MenuBar.EnableTop(2, False) lbessard@248: self.FileMenu.Enable(wx.ID_SAVE, False) lbessard@249: self.FileMenu.Enable(wx.ID_CLOSE_ALL, False) lbessard@248: self.FileMenu.Enable(wx.ID_PROPERTIES, False) lbessard@17: lbessard@97: def RefreshScrollBars(self): lbessard@97: xstart, ystart = self.PLCConfig.GetViewStart() lbessard@97: window_size = self.PLCConfig.GetClientSize() lbessard@97: sizer = self.PLCConfig.GetSizer() lbessard@97: if sizer: lbessard@97: maxx, maxy = sizer.GetMinSize() lbessard@97: self.PLCConfig.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, lbessard@188: maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, lbessard@188: max(0, min(xstart, (maxx - window_size[0]) / SCROLLBAR_UNIT)), lbessard@188: max(0, min(ystart, (maxy - window_size[1]) / SCROLLBAR_UNIT))) lbessard@97: lbessard@97: def RefreshPLCParams(self): etisserant@109: self.Freeze() lbessard@97: self.ClearSizer(self.PLCParamsSizer) lbessard@97: lbessard@248: if self.PluginRoot is not None: lbessard@97: plcwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1)) etisserant@118: if self.PluginRoot.PlugTestModified(): etisserant@118: bkgdclr = CHANGED_TITLE_COLOUR etisserant@118: else: etisserant@118: bkgdclr = TITLE_COLOUR lbessard@129: lbessard@129: if self.PluginRoot not in self.PluginInfos: lbessard@129: self.PluginInfos[self.PluginRoot] = {"middle_visible" : False} lbessard@129: etisserant@106: plcwindow.SetBackgroundColour(TITLE_COLOUR) lbessard@296: plcwindow.Bind(wx.EVT_LEFT_DOWN, self.OnPanelLeftDown) lbessard@97: self.PLCParamsSizer.AddWindow(plcwindow, 0, border=0, flag=wx.GROW) lbessard@97: lbessard@98: plcwindowsizer = wx.BoxSizer(wx.HORIZONTAL) lbessard@97: plcwindow.SetSizer(plcwindowsizer) lbessard@97: lbessard@97: st = wx.StaticText(plcwindow, -1) lbessard@98: st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) lbessard@98: st.SetLabel(self.PluginRoot.GetProjectName()) lbessard@98: plcwindowsizer.AddWindow(st, 0, border=5, flag=wx.ALL|wx.ALIGN_CENTER) lbessard@98: etisserant@106: addbutton_id = wx.NewId() etisserant@217: addbutton = wx.lib.buttons.GenBitmapButton(id=addbutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Add.png')), etisserant@197: name='AddPluginButton', parent=plcwindow, pos=wx.Point(0, 0), etisserant@106: size=wx.Size(16, 16), style=wx.NO_BORDER) etisserant@106: addbutton.SetToolTipString("Add a sub plugin") etisserant@106: addbutton.Bind(wx.EVT_BUTTON, self.Gen_AddPluginMenu(self.PluginRoot), id=addbutton_id) etisserant@106: plcwindowsizer.AddWindow(addbutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER) etisserant@106: lbessard@98: plcwindowmainsizer = wx.BoxSizer(wx.VERTICAL) lbessard@98: plcwindowsizer.AddSizer(plcwindowmainsizer, 0, border=5, flag=wx.ALL) lbessard@98: lbessard@98: plcwindowbuttonsizer = wx.BoxSizer(wx.HORIZONTAL) lbessard@98: plcwindowmainsizer.AddSizer(plcwindowbuttonsizer, 0, border=0, flag=wx.ALIGN_CENTER) lbessard@98: lbessard@129: msizer = self.GenerateMethodButtonSizer(self.PluginRoot, plcwindow, not self.PluginInfos[self.PluginRoot]["middle_visible"]) lbessard@98: plcwindowbuttonsizer.AddSizer(msizer, 0, border=0, flag=wx.GROW) lbessard@97: lbessard@296: paramswindow = wx.Panel(plcwindow, -1, size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL) etisserant@106: paramswindow.SetBackgroundColour(TITLE_COLOUR) lbessard@296: paramswindow.Bind(wx.EVT_LEFT_DOWN, self.OnPanelLeftDown) lbessard@98: plcwindowbuttonsizer.AddWindow(paramswindow, 0, border=0, flag=0) lbessard@97: lbessard@97: psizer = wx.BoxSizer(wx.HORIZONTAL) lbessard@97: paramswindow.SetSizer(psizer) lbessard@97: lbessard@97: plugin_infos = self.PluginRoot.GetParamsAttributes() lbessard@97: self.RefreshSizerElement(paramswindow, psizer, self.PluginRoot, plugin_infos, None, False) lbessard@97: lbessard@129: if not self.PluginInfos[self.PluginRoot]["middle_visible"]: lbessard@129: paramswindow.Hide() lbessard@97: lbessard@97: minimizebutton_id = wx.NewId() etisserant@217: minimizebutton = wx.lib.buttons.GenBitmapToggleButton(id=minimizebutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Maximize.png')), lbessard@97: name='MinimizeButton', parent=plcwindow, pos=wx.Point(0, 0), lbessard@97: size=wx.Size(24, 24), style=wx.NO_BORDER) etisserant@106: make_genbitmaptogglebutton_flat(minimizebutton) etisserant@217: minimizebutton.SetBitmapSelected(wx.Bitmap(Bpath( 'images', 'Minimize.png'))) lbessard@324: minimizebutton.SetToggle(self.PluginInfos[self.PluginRoot]["middle_visible"]) lbessard@99: plcwindowbuttonsizer.AddWindow(minimizebutton, 0, border=5, flag=wx.ALL) lbessard@99: etisserant@106: # if len(self.PluginRoot.PlugChildsTypes) > 0: etisserant@106: # addsizer = self.GenerateAddButtonSizer(self.PluginRoot, plcwindow) etisserant@106: # plcwindowbuttonsizer.AddSizer(addsizer, 0, border=0, flag=0) etisserant@106: # else: etisserant@106: # addsizer = None lbessard@99: lbessard@97: def togglewindow(event): lbessard@97: if minimizebutton.GetToggle(): lbessard@97: paramswindow.Show() lbessard@97: msizer.SetCols(1) etisserant@106: # if addsizer is not None: etisserant@106: # addsizer.SetCols(1) lbessard@97: else: lbessard@97: paramswindow.Hide() lbessard@97: msizer.SetCols(len(self.PluginRoot.PluginMethods)) etisserant@106: # if addsizer is not None: etisserant@106: # addsizer.SetCols(len(self.PluginRoot.PlugChildsTypes)) lbessard@129: self.PluginInfos[self.PluginRoot]["middle_visible"] = minimizebutton.GetToggle() lbessard@97: self.PLCConfigMainSizer.Layout() lbessard@97: self.RefreshScrollBars() lbessard@97: event.Skip() lbessard@97: minimizebutton.Bind(wx.EVT_BUTTON, togglewindow, id=minimizebutton_id) lbessard@101: lbessard@129: self.PluginInfos[self.PluginRoot]["main"] = plcwindow lbessard@129: self.PluginInfos[self.PluginRoot]["params"] = paramswindow etisserant@118: lbessard@101: self.PLCConfigMainSizer.Layout() lbessard@101: self.RefreshScrollBars() etisserant@109: self.Thaw() lbessard@99: etisserant@106: # def GenerateAddButtonSizer(self, plugin, parent, horizontal = True): etisserant@106: # if horizontal: etisserant@106: # addsizer = wx.FlexGridSizer(cols=len(plugin.PluginMethods)) etisserant@106: # else: etisserant@106: # addsizer = wx.FlexGridSizer(cols=1) etisserant@106: # for name, XSDClass, help in plugin.PlugChildsTypes: etisserant@106: # addbutton_id = wx.NewId() etisserant@106: # addbutton = wx.lib.buttons.GenButton(id=addbutton_id, label="Add %s"%help, etisserant@197: # name='AddPluginButton', parent=parent, pos=wx.Point(0, 0), etisserant@106: # style=wx.NO_BORDER) etisserant@106: # font = addbutton.GetFont() etisserant@106: # font.SetUnderlined(True) etisserant@106: # addbutton.SetFont(font) etisserant@106: # addbutton._GetLabelSize = gen_textbutton_GetLabelSize(addbutton) etisserant@106: # addbutton.SetForegroundColour(wx.BLUE) etisserant@106: # addbutton.SetToolTipString("Add a \"%s\" plugin to this one"%name) etisserant@106: # addbutton.Bind(wx.EVT_BUTTON, self._GetAddPluginFunction(name, plugin), id=addbutton_id) etisserant@106: # addsizer.AddWindow(addbutton, 0, border=0, flag=0) etisserant@106: # return addsizer lbessard@98: lbessard@314: normal_bt_font=wx.Font(faces["size"] / 3, wx.DEFAULT, wx.NORMAL, wx.NORMAL, faceName = faces["helv"]) lbessard@314: mouseover_bt_font=wx.Font(faces["size"] / 3, wx.DEFAULT, wx.NORMAL, wx.NORMAL, underline=True, faceName = faces["helv"]) lbessard@98: def GenerateMethodButtonSizer(self, plugin, parent, horizontal = True): lbessard@98: if horizontal: lbessard@98: msizer = wx.FlexGridSizer(cols=len(plugin.PluginMethods)) lbessard@98: else: lbessard@98: msizer = wx.FlexGridSizer(cols=1) lbessard@98: for plugin_method in plugin.PluginMethods: etisserant@203: if "method" in plugin_method and plugin_method.get("shown",True): lbessard@98: id = wx.NewId() etisserant@230: label=plugin_method["name"] etisserant@109: button = GenBitmapTextButton(id=id, parent=parent, etisserant@230: bitmap=wx.Bitmap(Bpath( "%s.png"%plugin_method.get("bitmap", os.path.join("images", "Unknown")))), label=label, etisserant@230: name=label, pos=wx.DefaultPosition, style=wx.NO_BORDER) etisserant@230: button.SetFont(self.normal_bt_font) lbessard@98: button.SetToolTipString(plugin_method["tooltip"]) lbessard@98: button.Bind(wx.EVT_BUTTON, self.GetButtonCallBackFunction(plugin, plugin_method["method"]), id=id) etisserant@230: # a fancy underline on mouseover etisserant@230: def setFontStyle(b, s): etisserant@230: def fn(event): etisserant@230: b.SetFont(s) etisserant@230: b.Refresh() etisserant@230: event.Skip() etisserant@230: return fn etisserant@230: button.Bind(wx.EVT_ENTER_WINDOW, setFontStyle(button, self.mouseover_bt_font)) etisserant@230: button.Bind(wx.EVT_LEAVE_WINDOW, setFontStyle(button, self.normal_bt_font)) lbessard@98: #hack to force size to mini etisserant@109: if not plugin_method.get("enabled",True): etisserant@109: button.Disable() etisserant@230: msizer.AddWindow(button, 0, border=0, flag=wx.ALIGN_CENTER) lbessard@98: return msizer lbessard@97: lbessard@17: def RefreshPluginTree(self): etisserant@109: self.Freeze() lbessard@97: self.ClearSizer(self.PluginTreeSizer) lbessard@248: if self.PluginRoot is not None: lbessard@97: for child in self.PluginRoot.IECSortedChilds(): etisserant@118: self.GenerateTreeBranch(child) lbessard@97: if not self.PluginInfos[child]["expanded"]: lbessard@97: self.CollapsePlugin(child) lbessard@97: self.PLCConfigMainSizer.Layout() lbessard@97: self.RefreshScrollBars() etisserant@109: self.Thaw() lbessard@97: etisserant@118: def SetPluginParamsAttribute(self, plugin, *args, **kwargs): etisserant@118: res, StructChanged = plugin.SetParamsAttribute(*args, **kwargs) etisserant@118: if StructChanged: etisserant@118: wx.CallAfter(self.RefreshPluginTree) etisserant@118: else: etisserant@118: if plugin == self.PluginRoot: etisserant@118: bkgdclr = CHANGED_TITLE_COLOUR etisserant@118: items = ["main", "params"] etisserant@118: else: etisserant@118: bkgdclr = CHANGED_WINDOW_COLOUR etisserant@118: items = ["left", "middle", "params"] etisserant@118: for i in items: etisserant@118: self.PluginInfos[plugin][i].SetBackgroundColour(bkgdclr) etisserant@118: self.PluginInfos[plugin][i].Refresh() etisserant@118: return res etisserant@118: lbessard@97: def ExpandPlugin(self, plugin, force = False): lbessard@97: for child in self.PluginInfos[plugin]["children"]: etisserant@118: self.PluginInfos[child]["left"].Show() etisserant@118: self.PluginInfos[child]["middle"].Show() etisserant@106: # self.PluginTreeSizer.Show(self.PluginInfos[child]["right"]) lbessard@97: if force or not self.PluginInfos[child]["expanded"]: lbessard@97: self.ExpandPlugin(child, force) lbessard@97: if force: lbessard@97: self.PluginInfos[child]["expanded"] = True lbessard@97: lbessard@97: def CollapsePlugin(self, plugin, force = False): lbessard@97: for child in self.PluginInfos[plugin]["children"]: etisserant@118: self.PluginInfos[child]["left"].Hide() etisserant@118: self.PluginInfos[child]["middle"].Hide() etisserant@106: # self.PluginTreeSizer.Hide(self.PluginInfos[child]["right"]) lbessard@97: if force or self.PluginInfos[child]["expanded"]: lbessard@97: self.CollapsePlugin(child, force) lbessard@97: if force: lbessard@97: self.PluginInfos[child]["expanded"] = False lbessard@97: etisserant@118: def GenerateTreeBranch(self, plugin): lbessard@97: leftwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1)) etisserant@118: if plugin.PlugTestModified(): etisserant@118: bkgdclr=CHANGED_WINDOW_COLOUR etisserant@118: else: etisserant@118: bkgdclr=WINDOW_COLOUR etisserant@118: etisserant@118: leftwindow.SetBackgroundColour(bkgdclr) lbessard@97: lbessard@97: if plugin not in self.PluginInfos: lbessard@99: self.PluginInfos[plugin] = {"expanded" : False, "left_visible" : False, "middle_visible" : False} lbessard@97: lbessard@97: self.PluginInfos[plugin]["children"] = plugin.IECSortedChilds() lbessard@97: lbessard@97: self.PluginTreeSizer.AddWindow(leftwindow, 0, border=0, flag=wx.GROW) lbessard@97: etisserant@106: leftwindowsizer = wx.FlexGridSizer(cols=1, rows=3) lbessard@97: leftwindowsizer.AddGrowableCol(0) etisserant@106: leftwindowsizer.AddGrowableRow(2) lbessard@97: leftwindow.SetSizer(leftwindowsizer) lbessard@97: lbessard@97: leftbuttonmainsizer = wx.FlexGridSizer(cols=3, rows=1) lbessard@97: leftbuttonmainsizer.AddGrowableCol(0) etisserant@106: leftwindowsizer.AddSizer(leftbuttonmainsizer, 0, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT) #|wx.TOP lbessard@97: lbessard@97: leftbuttonsizer = wx.BoxSizer(wx.HORIZONTAL) etisserant@106: leftbuttonmainsizer.AddSizer(leftbuttonsizer, 0, border=5, flag=wx.GROW|wx.RIGHT) etisserant@106: etisserant@106: leftsizer = wx.BoxSizer(wx.VERTICAL) etisserant@106: leftbuttonsizer.AddSizer(leftsizer, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) etisserant@106: etisserant@106: rolesizer = wx.BoxSizer(wx.HORIZONTAL) etisserant@106: leftsizer.AddSizer(rolesizer, 0, border=0, flag=wx.GROW|wx.RIGHT) etisserant@106: etisserant@106: enablebutton_id = wx.NewId() etisserant@217: enablebutton = wx.lib.buttons.GenBitmapToggleButton(id=enablebutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Disabled.png')), etisserant@106: name='EnableButton', parent=leftwindow, size=wx.Size(16, 16), pos=wx.Point(0, 0), style=0)#wx.NO_BORDER) etisserant@106: enablebutton.SetToolTipString("Enable/Disable this plugin") etisserant@106: make_genbitmaptogglebutton_flat(enablebutton) etisserant@217: enablebutton.SetBitmapSelected(wx.Bitmap(Bpath( 'images', 'Enabled.png'))) etisserant@106: enablebutton.SetToggle(plugin.MandatoryParams[1].getEnabled()) etisserant@106: def toggleenablebutton(event): etisserant@203: res = self.SetPluginParamsAttribute(plugin, "BaseParams.Enabled", enablebutton.GetToggle()) etisserant@106: enablebutton.SetToggle(res) etisserant@106: event.Skip() etisserant@106: enablebutton.Bind(wx.EVT_BUTTON, toggleenablebutton, id=enablebutton_id) etisserant@106: rolesizer.AddWindow(enablebutton, 0, border=0, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) etisserant@106: etisserant@109: roletext = wx.StaticText(leftwindow, -1) etisserant@109: roletext.SetLabel(plugin.PlugHelp) etisserant@109: rolesizer.AddWindow(roletext, 0, border=5, flag=wx.RIGHT|wx.ALIGN_LEFT) lbessard@97: lbessard@97: plugin_IECChannel = plugin.BaseParams.getIEC_Channel() lbessard@97: etisserant@106: iecsizer = wx.BoxSizer(wx.HORIZONTAL) etisserant@106: leftsizer.AddSizer(iecsizer, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) etisserant@106: etisserant@106: st = wx.StaticText(leftwindow, -1) etisserant@106: st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) etisserant@106: st.SetLabel(plugin.GetFullIEC_Channel()) etisserant@106: iecsizer.AddWindow(st, 0, border=0, flag=0) etisserant@106: etisserant@106: updownsizer = wx.BoxSizer(wx.VERTICAL) etisserant@106: iecsizer.AddSizer(updownsizer, 0, border=5, flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL) etisserant@106: lbessard@97: if plugin_IECChannel > 0: lbessard@98: ieccdownbutton_id = wx.NewId() etisserant@217: ieccdownbutton = wx.lib.buttons.GenBitmapButton(id=ieccdownbutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'IECCDown.png')), lbessard@98: name='IECCDownButton', parent=leftwindow, pos=wx.Point(0, 0), lbessard@98: size=wx.Size(16, 16), style=wx.NO_BORDER) lbessard@97: ieccdownbutton.Bind(wx.EVT_BUTTON, self.GetItemChannelChangedFunction(plugin, plugin_IECChannel - 1), id=ieccdownbutton_id) etisserant@106: updownsizer.AddWindow(ieccdownbutton, 0, border=0, flag=wx.ALIGN_LEFT) etisserant@106: lbessard@97: ieccupbutton_id = wx.NewId() etisserant@217: ieccupbutton = wx.lib.buttons.GenBitmapTextButton(id=ieccupbutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'IECCUp.png')), lbessard@97: name='IECCUpButton', parent=leftwindow, pos=wx.Point(0, 0), lbessard@97: size=wx.Size(16, 16), style=wx.NO_BORDER) lbessard@97: ieccupbutton.Bind(wx.EVT_BUTTON, self.GetItemChannelChangedFunction(plugin, plugin_IECChannel + 1), id=ieccupbutton_id) etisserant@106: updownsizer.AddWindow(ieccupbutton, 0, border=0, flag=wx.ALIGN_LEFT) etisserant@106: etisserant@106: adddeletesizer = wx.BoxSizer(wx.VERTICAL) etisserant@106: iecsizer.AddSizer(adddeletesizer, 0, border=5, flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL) etisserant@106: etisserant@106: deletebutton_id = wx.NewId() etisserant@217: deletebutton = wx.lib.buttons.GenBitmapButton(id=deletebutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Delete.png')), etisserant@197: name='DeletePluginButton', parent=leftwindow, pos=wx.Point(0, 0), etisserant@106: size=wx.Size(16, 16), style=wx.NO_BORDER) etisserant@106: deletebutton.SetToolTipString("Delete this plugin") etisserant@106: deletebutton.Bind(wx.EVT_BUTTON, self.GetDeleteButtonFunction(plugin), id=deletebutton_id) etisserant@106: adddeletesizer.AddWindow(deletebutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER) etisserant@106: etisserant@106: if len(plugin.PlugChildsTypes) > 0: etisserant@106: addbutton_id = wx.NewId() etisserant@217: addbutton = wx.lib.buttons.GenBitmapButton(id=addbutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Add.png')), etisserant@197: name='AddPluginButton', parent=leftwindow, pos=wx.Point(0, 0), etisserant@106: size=wx.Size(16, 16), style=wx.NO_BORDER) etisserant@106: addbutton.SetToolTipString("Add a sub plugin") etisserant@106: addbutton.Bind(wx.EVT_BUTTON, self.Gen_AddPluginMenu(plugin), id=addbutton_id) etisserant@106: adddeletesizer.AddWindow(addbutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER) lbessard@97: etisserant@199: expandbutton_id = wx.NewId() etisserant@217: expandbutton = wx.lib.buttons.GenBitmapToggleButton(id=expandbutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'plus.png')), etisserant@199: name='ExpandButton', parent=leftwindow, pos=wx.Point(0, 0), etisserant@199: size=wx.Size(13, 13), style=wx.NO_BORDER) etisserant@199: expandbutton.labelDelta = 0 etisserant@199: expandbutton.SetBezelWidth(0) etisserant@199: expandbutton.SetUseFocusIndicator(False) etisserant@217: expandbutton.SetBitmapSelected(wx.Bitmap(Bpath( 'images', 'minus.png'))) etisserant@199: expandbutton.SetToggle(self.PluginInfos[plugin]["expanded"]) etisserant@199: lbessard@97: if len(self.PluginInfos[plugin]["children"]) > 0: lbessard@97: def togglebutton(event): lbessard@97: if expandbutton.GetToggle(): lbessard@97: self.ExpandPlugin(plugin) etisserant@89: else: lbessard@97: self.CollapsePlugin(plugin) lbessard@97: self.PluginInfos[plugin]["expanded"] = expandbutton.GetToggle() lbessard@97: self.PLCConfigMainSizer.Layout() lbessard@97: self.RefreshScrollBars() lbessard@97: event.Skip() lbessard@97: expandbutton.Bind(wx.EVT_BUTTON, togglebutton, id=expandbutton_id) etisserant@199: else: etisserant@199: expandbutton.Enable(False) etisserant@199: iecsizer.AddWindow(expandbutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) lbessard@97: lbessard@97: tc_id = wx.NewId() etisserant@199: tc = wx.TextCtrl(leftwindow, tc_id, size=wx.Size(150, 25), style=wx.NO_BORDER) lbessard@97: tc.SetFont(wx.Font(faces["size"] * 0.75, wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) lbessard@214: tc.ChangeValue(plugin.MandatoryParams[1].getName()) lbessard@214: tc.Bind(wx.EVT_TEXT, self.GetTextCtrlCallBackFunction(tc, plugin, "BaseParams.Name"), id=tc_id) etisserant@199: iecsizer.AddWindow(tc, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) etisserant@106: lbessard@97: lbessard@97: leftminimizebutton_id = wx.NewId() etisserant@217: leftminimizebutton = wx.lib.buttons.GenBitmapToggleButton(id=leftminimizebutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'ShowVars.png')), lbessard@97: name='MinimizeButton', parent=leftwindow, pos=wx.Point(0, 0), lbessard@97: size=wx.Size(24, 24), style=wx.NO_BORDER) etisserant@106: make_genbitmaptogglebutton_flat(leftminimizebutton) etisserant@217: leftminimizebutton.SetBitmapSelected(wx.Bitmap(Bpath( 'images', 'HideVars.png'))) lbessard@97: leftminimizebutton.SetToggle(self.PluginInfos[plugin]["left_visible"]) lbessard@97: def toggleleftwindow(event): lbessard@97: if leftminimizebutton.GetToggle(): lbessard@97: leftwindowsizer.Show(1) lbessard@97: else: lbessard@97: leftwindowsizer.Hide(1) lbessard@97: self.PluginInfos[plugin]["left_visible"] = leftminimizebutton.GetToggle() lbessard@97: self.PLCConfigMainSizer.Layout() lbessard@97: self.RefreshScrollBars() lbessard@97: event.Skip() lbessard@97: leftminimizebutton.Bind(wx.EVT_BUTTON, toggleleftwindow, id=leftminimizebutton_id) lbessard@97: leftbuttonmainsizer.AddWindow(leftminimizebutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER) lbessard@97: lbessard@98: locations = plugin.GetLocations() lbessard@98: lb = wx.ListBox(leftwindow, -1, size=wx.Size(-1, max(1, min(len(locations), 4)) * 25), style=wx.NO_BORDER) lbessard@98: for location in locations: lbessard@97: lb.Append(location["NAME"].replace("__", "%").replace("_", ".")) lbessard@97: if not self.PluginInfos[plugin]["left_visible"]: lbessard@97: lb.Hide() lbessard@98: self.PluginInfos[plugin]["variable_list"] = lb lbessard@99: leftwindowsizer.AddWindow(lb, 0, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM) lbessard@99: lbessard@99: middlewindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1)) etisserant@118: middlewindow.SetBackgroundColour(bkgdclr) lbessard@99: lbessard@99: self.PluginTreeSizer.AddWindow(middlewindow, 0, border=0, flag=wx.GROW) lbessard@99: lbessard@99: middlewindowmainsizer = wx.BoxSizer(wx.VERTICAL) lbessard@99: middlewindow.SetSizer(middlewindowmainsizer) lbessard@99: lbessard@99: middlewindowsizer = wx.FlexGridSizer(cols=2, rows=1) lbessard@99: middlewindowsizer.AddGrowableCol(1) lbessard@99: middlewindowsizer.AddGrowableRow(0) etisserant@106: middlewindowmainsizer.AddSizer(middlewindowsizer, 0, border=8, flag=wx.TOP|wx.GROW) lbessard@99: lbessard@99: msizer = self.GenerateMethodButtonSizer(plugin, middlewindow, not self.PluginInfos[plugin]["middle_visible"]) lbessard@99: middlewindowsizer.AddSizer(msizer, 0, border=0, flag=wx.GROW) lbessard@99: lbessard@99: middleparamssizer = wx.BoxSizer(wx.HORIZONTAL) lbessard@99: middlewindowsizer.AddSizer(middleparamssizer, 0, border=0, flag=wx.ALIGN_RIGHT) lbessard@99: lbessard@99: paramswindow = wx.Panel(middlewindow, -1, size=wx.Size(-1, -1)) etisserant@118: paramswindow.SetBackgroundColour(bkgdclr) lbessard@99: lbessard@99: psizer = wx.BoxSizer(wx.HORIZONTAL) lbessard@99: paramswindow.SetSizer(psizer) etisserant@118: self.PluginInfos[plugin]["params"] = paramswindow lbessard@99: lbessard@99: middleparamssizer.AddWindow(paramswindow, 0, border=5, flag=wx.ALL) lbessard@99: lbessard@99: plugin_infos = plugin.GetParamsAttributes() lbessard@99: self.RefreshSizerElement(paramswindow, psizer, plugin, plugin_infos, None, False) lbessard@99: lbessard@99: if not self.PluginInfos[plugin]["middle_visible"]: lbessard@99: paramswindow.Hide() lbessard@99: lbessard@99: middleminimizebutton_id = wx.NewId() etisserant@217: middleminimizebutton = wx.lib.buttons.GenBitmapToggleButton(id=middleminimizebutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Maximize.png')), lbessard@99: name='MinimizeButton', parent=middlewindow, pos=wx.Point(0, 0), lbessard@99: size=wx.Size(24, 24), style=wx.NO_BORDER) etisserant@106: make_genbitmaptogglebutton_flat(middleminimizebutton) etisserant@217: middleminimizebutton.SetBitmapSelected(wx.Bitmap(Bpath( 'images', 'Minimize.png'))) lbessard@99: middleminimizebutton.SetToggle(self.PluginInfos[plugin]["middle_visible"]) lbessard@99: middleparamssizer.AddWindow(middleminimizebutton, 0, border=5, flag=wx.ALL) lbessard@99: etisserant@106: # rightwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1)) etisserant@106: # rightwindow.SetBackgroundColour(wx.Colour(240,240,240)) etisserant@106: # etisserant@106: # self.PluginTreeSizer.AddWindow(rightwindow, 0, border=0, flag=wx.GROW) etisserant@106: # etisserant@106: # rightsizer = wx.BoxSizer(wx.VERTICAL) etisserant@106: # rightwindow.SetSizer(rightsizer) etisserant@106: # etisserant@106: # rightmainsizer = wx.BoxSizer(wx.VERTICAL) etisserant@106: # rightsizer.AddSizer(rightmainsizer, 0, border=5, flag=wx.ALL) etisserant@106: # etisserant@106: # if len(plugin.PlugChildsTypes) > 0: etisserant@106: # addsizer = self.GenerateAddButtonSizer(plugin, rightwindow) etisserant@106: # rightmainsizer.AddSizer(addsizer, 0, border=4, flag=wx.TOP) etisserant@106: # else: etisserant@106: # addsizer = None lbessard@99: lbessard@99: def togglemiddlerightwindow(event): lbessard@99: if middleminimizebutton.GetToggle(): lbessard@99: middleparamssizer.Show(0) lbessard@97: msizer.SetCols(1) etisserant@106: # if addsizer is not None: etisserant@106: # addsizer.SetCols(1) lbessard@97: else: lbessard@99: middleparamssizer.Hide(0) lbessard@97: msizer.SetCols(len(plugin.PluginMethods)) etisserant@106: # if addsizer is not None: etisserant@106: # addsizer.SetCols(len(plugin.PlugChildsTypes)) lbessard@99: self.PluginInfos[plugin]["middle_visible"] = middleminimizebutton.GetToggle() lbessard@97: self.PLCConfigMainSizer.Layout() lbessard@97: self.RefreshScrollBars() lbessard@84: event.Skip() lbessard@99: middleminimizebutton.Bind(wx.EVT_BUTTON, togglemiddlerightwindow, id=middleminimizebutton_id) lbessard@99: etisserant@118: self.PluginInfos[plugin]["left"] = leftwindow etisserant@118: self.PluginInfos[plugin]["middle"] = middlewindow etisserant@118: # self.PluginInfos[plugin]["right"] = rightwindow lbessard@97: for child in self.PluginInfos[plugin]["children"]: etisserant@118: self.GenerateTreeBranch(child) lbessard@97: if not self.PluginInfos[child]["expanded"]: lbessard@97: self.CollapsePlugin(child) lbessard@97: lbessard@98: def RefreshVariableLists(self): lbessard@98: for plugin, infos in self.PluginInfos.items(): lbessard@98: locations = plugin.GetLocations() lbessard@98: infos["variable_list"].SetSize(wx.Size(-1, max(1, min(len(locations), 4)) * 25)) lbessard@98: infos["variable_list"].Clear() lbessard@98: for location in locations: lbessard@98: infos["variable_list"].Append(location["NAME"].replace("__", "%").replace("_", ".")) lbessard@98: self.PLCConfigMainSizer.Layout() lbessard@98: self.RefreshScrollBars() etisserant@109: etisserant@109: def RefreshAll(self): etisserant@109: self.RefreshPLCParams() etisserant@109: self.RefreshPluginTree() etisserant@109: lbessard@97: def GetItemChannelChangedFunction(self, plugin, value): lbessard@82: def OnPluginTreeItemChannelChanged(event): etisserant@203: res = self.SetPluginParamsAttribute(plugin, "BaseParams.IEC_Channel", value) lbessard@82: event.Skip() lbessard@82: return OnPluginTreeItemChannelChanged lbessard@82: lbessard@97: def _GetAddPluginFunction(self, name, plugin): lbessard@17: def OnPluginMenu(event): lbessard@98: wx.CallAfter(self.AddPlugin, name, plugin) lbessard@17: event.Skip() lbessard@17: return OnPluginMenu lbessard@17: etisserant@106: def Gen_AddPluginMenu(self, plugin): etisserant@106: def AddPluginMenu(event): lbessard@17: main_menu = wx.Menu(title='') lbessard@17: if len(plugin.PlugChildsTypes) > 0: etisserant@106: for name, XSDClass, help in plugin.PlugChildsTypes: lbessard@17: new_id = wx.NewId() etisserant@106: main_menu.Append(help=help, id=new_id, kind=wx.ITEM_NORMAL, text="Append "+help) etisserant@106: self.Bind(wx.EVT_MENU, self._GetAddPluginFunction(name, plugin), id=new_id) etisserant@106: self.PopupMenuXY(main_menu) etisserant@106: event.Skip() etisserant@106: return AddPluginMenu lbessard@82: lbessard@21: def GetButtonCallBackFunction(self, plugin, method): etisserant@110: """ Generate the callbackfunc for a given plugin method""" lbessard@21: def OnButtonClick(event): etisserant@110: # Disable button to prevent re-entrant call etisserant@110: event.GetEventObject().Disable() etisserant@110: # Call etisserant@203: getattr(plugin,method)() etisserant@110: # Re-enable button etisserant@110: event.GetEventObject().Enable() etisserant@110: # Trigger refresh on Idle etisserant@109: wx.CallAfter(self.RefreshAll) lbessard@21: event.Skip() lbessard@21: return OnButtonClick lbessard@21: lbessard@97: def GetChoiceCallBackFunction(self, choicectrl, plugin, path): lbessard@19: def OnChoiceChanged(event): etisserant@203: res = self.SetPluginParamsAttribute(plugin, path, choicectrl.GetStringSelection()) lbessard@97: choicectrl.SetStringSelection(res) lbessard@19: event.Skip() lbessard@19: return OnChoiceChanged lbessard@19: lbessard@97: def GetChoiceContentCallBackFunction(self, choicectrl, staticboxsizer, plugin, path): lbessard@19: def OnChoiceContentChanged(event): etisserant@203: res = self.SetPluginParamsAttribute(plugin, path, choicectrl.GetStringSelection()) lbessard@97: if wx.VERSION < (2, 8, 0): lbessard@97: self.ParamsPanel.Freeze() lbessard@129: choicectrl.SetStringSelection(res) lbessard@129: infos = self.PluginRoot.GetParamsAttributes(path) lbessard@129: staticbox = staticboxsizer.GetStaticBox() lbessard@129: staticbox.SetLabel("%(name)s - %(value)s"%infos) lbessard@97: self.RefreshSizerElement(self.ParamsPanel, staticboxsizer, infos["children"], "%s.%s"%(path, infos["name"]), selected=selected) lbessard@97: self.ParamsPanelMainSizer.Layout() lbessard@97: self.ParamsPanel.Thaw() lbessard@97: self.ParamsPanel.Refresh() lbessard@97: else: lbessard@129: wx.CallAfter(self.RefreshAll) lbessard@19: event.Skip() lbessard@19: return OnChoiceContentChanged lbessard@19: lbessard@97: def GetTextCtrlCallBackFunction(self, textctrl, plugin, path): lbessard@19: def OnTextCtrlChanged(event): etisserant@203: res = self.SetPluginParamsAttribute(plugin, path, textctrl.GetValue()) lbessard@214: if res != textctrl.GetValue(): lbessard@214: textctrl.ChangeValue(res) lbessard@19: event.Skip() lbessard@19: return OnTextCtrlChanged lbessard@19: lbessard@97: def GetCheckBoxCallBackFunction(self, chkbx, plugin, path): lbessard@19: def OnCheckBoxChanged(event): etisserant@203: res = self.SetPluginParamsAttribute(plugin, path, chkbx.IsChecked()) lbessard@97: chkbx.SetValue(res) lbessard@19: event.Skip() lbessard@19: return OnCheckBoxChanged lbessard@19: lbessard@19: def ClearSizer(self, sizer): lbessard@19: staticboxes = [] lbessard@19: for item in sizer.GetChildren(): lbessard@19: if item.IsSizer(): lbessard@19: item_sizer = item.GetSizer() lbessard@19: self.ClearSizer(item_sizer) lbessard@19: if isinstance(item_sizer, wx.StaticBoxSizer): lbessard@19: staticboxes.append(item_sizer.GetStaticBox()) lbessard@19: sizer.Clear(True) lbessard@19: for staticbox in staticboxes: lbessard@19: staticbox.Destroy() lbessard@19: lbessard@97: def RefreshSizerElement(self, parent, sizer, plugin, elements, path, clean = True): lbessard@25: if clean: lbessard@97: if wx.VERSION < (2, 8, 0): lbessard@97: self.ClearSizer(sizer) lbessard@97: else: lbessard@97: sizer.Clear(True) lbessard@19: first = True lbessard@19: for element_infos in elements: lbessard@19: if path: lbessard@19: element_path = "%s.%s"%(path, element_infos["name"]) lbessard@19: else: lbessard@19: element_path = element_infos["name"] lbessard@188: if element_infos["type"] == "element": lbessard@188: staticbox = wx.StaticBox(id=-1, label=element_infos["name"], lbessard@188: name='%s_staticbox'%element_infos["name"], parent=parent, lbessard@193: pos=wx.Point(0, 0), size=wx.Size(10, 0), style=0) lbessard@188: staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL) lbessard@188: if first: lbessard@188: sizer.AddSizer(staticboxsizer, 0, border=0, flag=wx.GROW|wx.TOP) lbessard@188: else: lbessard@188: sizer.AddSizer(staticboxsizer, 0, border=0, flag=wx.GROW) lbessard@188: self.RefreshSizerElement(parent, staticboxsizer, plugin, element_infos["children"], element_path) lbessard@188: else: lbessard@188: boxsizer = wx.FlexGridSizer(cols=3, rows=1) lbessard@188: boxsizer.AddGrowableCol(1) lbessard@19: if first: lbessard@19: sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.ALL) lbessard@19: else: lbessard@19: sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM) etisserant@106: staticbitmap = GenStaticBitmap(ID=-1, bitmapname="%s.png"%element_infos["name"], etisserant@106: name="%s_bitmap"%element_infos["name"], parent=parent, etisserant@106: pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0) etisserant@106: boxsizer.AddWindow(staticbitmap, 0, border=5, flag=wx.RIGHT) lbessard@19: statictext = wx.StaticText(id=-1, label="%s:"%element_infos["name"], lbessard@82: name="%s_label"%element_infos["name"], parent=parent, lbessard@19: pos=wx.Point(0, 0), size=wx.Size(100, 17), style=0) lbessard@67: boxsizer.AddWindow(statictext, 0, border=4, flag=wx.TOP) lbessard@19: id = wx.NewId() lbessard@188: if isinstance(element_infos["type"], types.ListType): lbessard@296: combobox = wx.ComboBox(id=id, name=element_infos["name"], parent=parent, lbessard@317: pos=wx.Point(0, 0), size=wx.Size(150, 28), style=wx.CB_READONLY) lbessard@296: boxsizer.AddWindow(combobox, 0, border=0, flag=0) lbessard@188: if element_infos["use"] == "optional": lbessard@296: combobox.Append("") lbessard@188: if len(element_infos["type"]) > 0 and isinstance(element_infos["type"][0], types.TupleType): lbessard@188: for choice, xsdclass in element_infos["type"]: lbessard@296: combobox.Append(choice) lbessard@188: staticbox = wx.StaticBox(id=-1, label="%(name)s - %(value)s"%element_infos, lbessard@188: name='%s_staticbox'%element_infos["name"], parent=parent, lbessard@193: pos=wx.Point(0, 0), size=wx.Size(10, 0), style=0) lbessard@188: staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL) lbessard@188: sizer.AddSizer(staticboxsizer, 0, border=5, flag=wx.GROW|wx.BOTTOM) lbessard@188: self.RefreshSizerElement(parent, staticboxsizer, plugin, element_infos["children"], element_path) lbessard@296: callback = self.GetChoiceContentCallBackFunction(combobox, staticboxsizer, plugin, element_path) etisserant@23: else: lbessard@188: for choice in element_infos["type"]: lbessard@296: combobox.Append(choice) lbessard@296: callback = self.GetChoiceCallBackFunction(combobox, plugin, element_path) lbessard@188: if element_infos["value"] is None: lbessard@296: combobox.SetStringSelection("") lbessard@188: else: lbessard@296: combobox.SetStringSelection(element_infos["value"]) lbessard@296: combobox.Bind(wx.EVT_COMBOBOX, callback, id=id) lbessard@188: elif isinstance(element_infos["type"], types.DictType): lbessard@188: scmin = -(2**31) etisserant@23: scmax = 2**31-1 lbessard@188: if "min" in element_infos["type"]: lbessard@188: scmin = element_infos["type"]["min"] lbessard@188: if "max" in element_infos["type"]: lbessard@188: scmax = element_infos["type"]["max"] lbessard@82: spinctrl = wx.SpinCtrl(id=id, name=element_infos["name"], parent=parent, lbessard@19: pos=wx.Point(0, 0), size=wx.Size(150, 25), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT) lbessard@188: spinctrl.SetRange(scmin,scmax) lbessard@19: boxsizer.AddWindow(spinctrl, 0, border=0, flag=0) etisserant@28: spinctrl.SetValue(element_infos["value"]) lbessard@97: spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, plugin, element_path), id=id) lbessard@19: else: lbessard@188: if element_infos["type"] == "boolean": lbessard@188: checkbox = wx.CheckBox(id=id, name=element_infos["name"], parent=parent, lbessard@188: pos=wx.Point(0, 0), size=wx.Size(17, 25), style=0) lbessard@188: boxsizer.AddWindow(checkbox, 0, border=0, flag=0) lbessard@188: checkbox.SetValue(element_infos["value"]) lbessard@188: checkbox.Bind(wx.EVT_CHECKBOX, self.GetCheckBoxCallBackFunction(checkbox, plugin, element_path), id=id) lbessard@188: elif element_infos["type"] in ["unsignedLong", "long","integer"]: lbessard@188: if element_infos["type"].startswith("unsigned"): lbessard@188: scmin = 0 lbessard@188: else: lbessard@188: scmin = -(2**31) lbessard@188: scmax = 2**31-1 lbessard@188: spinctrl = wx.SpinCtrl(id=id, name=element_infos["name"], parent=parent, lbessard@188: pos=wx.Point(0, 0), size=wx.Size(150, 25), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT) lbessard@188: spinctrl.SetRange(scmin, scmax) lbessard@188: boxsizer.AddWindow(spinctrl, 0, border=0, flag=0) lbessard@188: spinctrl.SetValue(element_infos["value"]) lbessard@188: spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, plugin, element_path), id=id) lbessard@188: else: greg@268: choices = cPickle.loads(str(config.Read(element_path, cPickle.dumps([""])))) greg@268: textctrl = TextCtrlAutoComplete.TextCtrlAutoComplete(id=id, greg@268: name=element_infos["name"], greg@268: parent=parent, greg@268: choices=choices, greg@268: element_path=element_path, greg@268: pos=wx.Point(0, 0), greg@268: size=wx.Size(150, 25), greg@268: style=0) greg@268: lbessard@188: boxsizer.AddWindow(textctrl, 0, border=0, flag=0) lbessard@214: textctrl.ChangeValue(str(element_infos["value"])) lbessard@214: textctrl.Bind(wx.EVT_TEXT, self.GetTextCtrlCallBackFunction(textctrl, plugin, element_path)) lbessard@19: first = False lbessard@19: lbessard@0: def OnNewProjectMenu(self, event): greg@257: if not config.HasEntry("lastopenedfolder"): greg@257: defaultpath = os.path.expanduser("~") greg@257: else: greg@257: defaultpath = config.Read("lastopenedfolder") greg@256: lbessard@4: dialog = wx.DirDialog(self , "Choose a project", defaultpath, wx.DD_NEW_DIR_BUTTON) lbessard@4: if dialog.ShowModal() == wx.ID_OK: greg@258: projectpath = dialog.GetPath() greg@258: dialog.Destroy() greg@257: config.Write("lastopenedfolder", os.path.dirname(projectpath)) greg@257: config.Flush() greg@308: self.PluginRoot = PluginsRoot(self, self.Log) etisserant@20: res = self.PluginRoot.NewProject(projectpath) etisserant@20: if not res : greg@268: self.RefreshAll() etisserant@20: self.RefreshMainMenu() lbessard@0: else: etisserant@20: message = wx.MessageDialog(self, res, "ERROR", wx.OK|wx.ICON_ERROR) lbessard@0: message.ShowModal() lbessard@0: message.Destroy() lbessard@0: event.Skip() lbessard@0: lbessard@0: def OnOpenProjectMenu(self, event): greg@257: if not config.HasEntry("lastopenedfolder"): greg@257: defaultpath = os.path.expanduser("~") greg@257: else: greg@257: defaultpath = config.Read("lastopenedfolder") greg@256: lbessard@4: dialog = wx.DirDialog(self , "Choose a project", defaultpath, wx.DD_NEW_DIR_BUTTON) lbessard@4: if dialog.ShowModal() == wx.ID_OK: lbessard@17: projectpath = dialog.GetPath() lbessard@17: if os.path.isdir(projectpath): greg@257: config.Write("lastopenedfolder", os.path.dirname(projectpath)) greg@257: config.Flush() greg@308: self.PluginRoot = PluginsRoot(self, self.Log) etisserant@203: result = self.PluginRoot.LoadProject(projectpath) lbessard@17: if not result: greg@268: self.RefreshAll() lbessard@17: self.RefreshMainMenu() lbessard@17: else: lbessard@17: message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR) lbessard@17: message.ShowModal() lbessard@17: message.Destroy() lbessard@17: else: lbessard@17: message = wx.MessageDialog(self, "\"%s\" folder is not a valid Beremiz project\n"%projectpath, "Error", wx.OK|wx.ICON_ERROR) lbessard@17: message.ShowModal() lbessard@17: message.Destroy() lbessard@0: dialog.Destroy() lbessard@0: event.Skip() lbessard@0: lbessard@0: def OnCloseProjectMenu(self, event): lbessard@248: if self.PluginRoot is not None: lbessard@248: if self.PluginRoot.ProjectTestModified(): lbessard@248: dialog = wx.MessageDialog(self, lbessard@248: "Save changes ?", lbessard@248: "Close Application", lbessard@248: wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION) lbessard@248: answer = dialog.ShowModal() lbessard@248: dialog.Destroy() lbessard@248: if answer == wx.ID_YES: lbessard@248: self.PluginRoot.SaveProject() lbessard@248: elif answer == wx.ID_CANCEL: lbessard@248: return lbessard@248: self.PluginInfos = {} lbessard@248: self.PluginRoot = None lbessard@248: self.Log.flush() greg@268: self.RefreshAll() lbessard@248: self.RefreshMainMenu() lbessard@0: event.Skip() lbessard@0: lbessard@0: def OnSaveProjectMenu(self, event): lbessard@248: if self.PluginRoot is not None: lbessard@17: self.PluginRoot.SaveProject() etisserant@118: self.RefreshAll() lbessard@0: event.Skip() lbessard@0: lbessard@0: def OnPropertiesMenu(self, event): lbessard@0: event.Skip() lbessard@0: lbessard@0: def OnQuitMenu(self, event): lbessard@0: self.Close() lbessard@0: event.Skip() lbessard@0: lbessard@0: def OnEditPLCMenu(self, event): lbessard@0: self.EditPLC() lbessard@0: event.Skip() lbessard@0: lbessard@17: def OnAddMenu(self, event): lbessard@17: self.AddPlugin() lbessard@17: event.Skip() lbessard@17: lbessard@17: def OnDeleteMenu(self, event): lbessard@17: self.DeletePlugin() lbessard@0: event.Skip() lbessard@0: lbessard@1: def OnBuildMenu(self, event): etisserant@20: #self.BuildAutom() lbessard@1: event.Skip() lbessard@1: lbessard@0: def OnSimulateMenu(self, event): lbessard@0: event.Skip() lbessard@0: lbessard@0: def OnRunMenu(self, event): lbessard@0: event.Skip() lbessard@0: lbessard@0: def OnSaveLogMenu(self, event): lbessard@0: event.Skip() lbessard@0: lbessard@0: def OnBeremizMenu(self, event): etisserant@217: open_pdf(Bpath( "doc", "manual_beremiz.pdf")) lbessard@0: event.Skip() lbessard@0: lbessard@0: def OnAboutMenu(self, event): etisserant@217: OpenHtmlFrame(self,"About Beremiz", Bpath("doc","about.html"), wx.Size(550, 500)) lbessard@0: event.Skip() lbessard@17: lbessard@17: def OnAddButton(self, event): lbessard@17: PluginType = self.PluginChilds.GetStringSelection() lbessard@17: if PluginType != "": lbessard@17: self.AddPlugin(PluginType) lbessard@17: event.Skip() lbessard@17: lbessard@17: def OnDeleteButton(self, event): lbessard@17: self.DeletePlugin() lbessard@0: event.Skip() lbessard@0: lbessard@97: def GetAddButtonFunction(self, plugin, window): lbessard@82: def AddButtonFunction(event): lbessard@82: if plugin and len(plugin.PlugChildsTypes) > 0: lbessard@82: plugin_menu = wx.Menu(title='') etisserant@106: for name, XSDClass, help in plugin.PlugChildsTypes: lbessard@82: new_id = wx.NewId() etisserant@106: plugin_menu.Append(help=help, id=new_id, kind=wx.ITEM_NORMAL, text=name) lbessard@97: self.Bind(wx.EVT_MENU, self._GetAddPluginFunction(name, plugin), id=new_id) lbessard@87: window_pos = window.GetPosition() lbessard@97: wx.CallAfter(self.PLCConfig.PopupMenu, plugin_menu) lbessard@82: event.Skip() lbessard@82: return AddButtonFunction lbessard@82: lbessard@97: def GetDeleteButtonFunction(self, plugin): lbessard@82: def DeleteButtonFunction(event): lbessard@97: wx.CallAfter(self.DeletePlugin, plugin) lbessard@82: event.Skip() lbessard@82: return DeleteButtonFunction lbessard@82: lbessard@97: def AddPlugin(self, PluginType, plugin): lbessard@17: dialog = wx.TextEntryDialog(self, "Please enter a name for plugin:", "Add Plugin", "", wx.OK|wx.CANCEL) lbessard@4: if dialog.ShowModal() == wx.ID_OK: lbessard@17: PluginName = dialog.GetValue() etisserant@203: plugin.PlugAddChild(PluginName, PluginType) lbessard@17: self.RefreshPluginTree() lbessard@0: dialog.Destroy() lbessard@0: lbessard@97: def DeletePlugin(self, plugin): lbessard@72: dialog = wx.MessageDialog(self, "Really delete plugin ?", "Remove plugin", wx.YES_NO|wx.NO_DEFAULT) etisserant@50: if dialog.ShowModal() == wx.ID_YES: lbessard@97: self.PluginInfos.pop(plugin) etisserant@50: plugin.PlugRemove() etisserant@50: del plugin etisserant@50: self.RefreshPluginTree() etisserant@50: dialog.Destroy() etisserant@7: lbessard@0: #------------------------------------------------------------------------------- lbessard@0: # Exception Handler lbessard@0: #------------------------------------------------------------------------------- lbessard@0: lbessard@0: Max_Traceback_List_Size = 20 lbessard@0: etisserant@109: def Display_Exception_Dialog(e_type, e_value, e_tb, bug_report_path): lbessard@0: trcbck_lst = [] lbessard@0: for i,line in enumerate(traceback.extract_tb(e_tb)): lbessard@0: trcbck = " " + str(i+1) + ". " lbessard@0: if line[0].find(os.getcwd()) == -1: lbessard@0: trcbck += "file : " + str(line[0]) + ", " lbessard@0: else: lbessard@0: trcbck += "file : " + str(line[0][len(os.getcwd()):]) + ", " lbessard@0: trcbck += "line : " + str(line[1]) + ", " + "function : " + str(line[2]) lbessard@0: trcbck_lst.append(trcbck) lbessard@0: lbessard@0: # Allow clicking.... lbessard@0: cap = wx.Window_GetCapture() lbessard@0: if cap: lbessard@0: cap.ReleaseMouse() lbessard@0: lbessard@0: dlg = wx.SingleChoiceDialog(None, lbessard@0: """ etisserant@109: An unhandled exception (bug) occured. Bug report saved at : etisserant@109: (%s) etisserant@109: greg@337: Please contact LOLITech at: greg@337: +33 (0)3 29 57 60 42 greg@337: or please be kind enough to send this file to: etisserant@109: bugs_beremiz@lolitech.fr etisserant@109: etisserant@109: You should now restart Beremiz. etisserant@109: etisserant@109: Traceback: etisserant@109: """ % bug_report_path + lbessard@0: str(e_type) + " : " + str(e_value), lbessard@0: "Error", lbessard@0: trcbck_lst) lbessard@0: try: lbessard@0: res = (dlg.ShowModal() == wx.ID_OK) lbessard@0: finally: lbessard@0: dlg.Destroy() lbessard@0: lbessard@0: return res lbessard@0: lbessard@0: def Display_Error_Dialog(e_value): lbessard@0: message = wxMessageDialog(None, str(e_value), "Error", wxOK|wxICON_ERROR) lbessard@0: message.ShowModal() lbessard@0: message.Destroy() lbessard@0: lbessard@0: def get_last_traceback(tb): lbessard@0: while tb.tb_next: lbessard@0: tb = tb.tb_next lbessard@0: return tb lbessard@0: lbessard@0: lbessard@0: def format_namespace(d, indent=' '): lbessard@0: return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()]) lbessard@0: lbessard@0: lbessard@0: ignored_exceptions = [] # a problem with a line in a module is only reported once per session lbessard@0: lbessard@5: def AddExceptHook(path, app_version='[No version]'):#, ignored_exceptions=[]): lbessard@0: lbessard@0: def handle_exception(e_type, e_value, e_traceback): lbessard@0: traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func lbessard@0: last_tb = get_last_traceback(e_traceback) lbessard@0: ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno) lbessard@0: if str(e_value).startswith("!!!"): lbessard@0: Display_Error_Dialog(e_value) lbessard@0: elif ex not in ignored_exceptions: etisserant@109: date = time.ctime() etisserant@109: bug_report_path = path+os.sep+"bug_report_"+date.replace(':','-').replace(' ','_')+".txt" etisserant@109: result = Display_Exception_Dialog(e_type,e_value,e_traceback,bug_report_path) lbessard@0: if result: lbessard@0: ignored_exceptions.append(ex) lbessard@0: info = { lbessard@0: 'app-title' : wx.GetApp().GetAppName(), # app_title lbessard@0: 'app-version' : app_version, lbessard@0: 'wx-version' : wx.VERSION_STRING, lbessard@0: 'wx-platform' : wx.Platform, lbessard@0: 'python-version' : platform.python_version(), #sys.version.split()[0], lbessard@0: 'platform' : platform.platform(), lbessard@0: 'e-type' : e_type, lbessard@0: 'e-value' : e_value, etisserant@109: 'date' : date, lbessard@0: 'cwd' : os.getcwd(), lbessard@0: } lbessard@0: if e_traceback: lbessard@0: info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value) lbessard@0: last_tb = get_last_traceback(e_traceback) lbessard@0: exception_locals = last_tb.tb_frame.f_locals # the locals at the level of the stack trace where the exception actually occurred lbessard@0: info['locals'] = format_namespace(exception_locals) lbessard@0: if 'self' in exception_locals: lbessard@0: info['self'] = format_namespace(exception_locals['self'].__dict__) lbessard@0: etisserant@109: output = open(bug_report_path,'w') lbessard@0: lst = info.keys() lbessard@0: lst.sort() lbessard@0: for a in lst: lbessard@0: output.write(a+":\n"+str(info[a])+"\n\n") lbessard@0: lbessard@0: #sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args) lbessard@0: sys.excepthook = handle_exception lbessard@0: lbessard@0: if __name__ == '__main__': lbessard@0: # Install a exception handle for bug reports lbessard@5: AddExceptHook(os.getcwd(),__version__) lbessard@0: greg@256: frame = Beremiz(None, projectOpen, buildpath) greg@103: frame.Show() greg@133: splash.Close() lbessard@0: app.MainLoop()