--- a/PLCOpenEditor.py Wed Oct 24 16:00:00 2007 +0200
+++ b/PLCOpenEditor.py Wed Oct 24 16:01:06 2007 +0200
@@ -131,32 +131,45 @@
"IL" : []
}
+def AppendMenu(parent, help, id, kind, text):
+ if wx.VERSION >= (2, 6, 0):
+ parent.Append(help=help, id=id, kind=kind, text=text)
+ else:
+ parent.Append(helpString=help, id=id, kind=kind, item=text)
+
class PLCOpenEditor(wx.Frame):
_custom_classes = {'wx.SashWindow' : ['Viewer']}
+ if wx.VERSION < (2, 6, 0):
+ def Bind(self, event, function, id = None):
+ if id is not None:
+ event(self, id, function)
+ else:
+ event(self, function)
+
def _init_coll_EditMenu_Items(self, parent):
- parent.Append(help='', id=ID_PLCOPENEDITOREDITMENUITEMS0,
+ AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUITEMS0,
kind=wx.ITEM_NORMAL, text=u'Refresh\tCTRL+R')
- parent.Append(help='', id=ID_PLCOPENEDITOREDITMENUITEMS1,
+ AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUITEMS1,
kind=wx.ITEM_NORMAL, text=u'Undo\tCTRL+Z')
- parent.Append(help='', id=ID_PLCOPENEDITOREDITMENUITEMS2,
+ AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUITEMS2,
kind=wx.ITEM_NORMAL, text=u'Redo\tCTRL+Y')
parent.AppendSeparator()
- parent.Append(help='', id=ID_PLCOPENEDITOREDITMENUITEMS4,
+ AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUITEMS4,
kind=wx.ITEM_NORMAL, text=u'Cut\tCTRL+X')
- parent.Append(help='', id=ID_PLCOPENEDITOREDITMENUITEMS5,
+ AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUITEMS5,
kind=wx.ITEM_NORMAL, text=u'Copy\tCTRL+C')
- parent.Append(help='', id=ID_PLCOPENEDITOREDITMENUITEMS6,
+ AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUITEMS6,
kind=wx.ITEM_NORMAL, text=u'Paste\tCTRL+V')
parent.AppendSeparator()
- parent.Append(help='', id=ID_PLCOPENEDITOREDITMENUITEMS8,
+ AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUITEMS8,
kind=wx.ITEM_NORMAL, text=u'Add POU')
- parent.Append(help='', id=ID_PLCOPENEDITOREDITMENUITEMS9,
+ AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUITEMS9,
kind=wx.ITEM_NORMAL, text=u'Remove POU')
parent.AppendSeparator()
- parent.Append(help='', id=ID_PLCOPENEDITOREDITMENUITEMS11,
+ AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUITEMS11,
kind=wx.ITEM_NORMAL, text=u'Add Configuration')
- parent.Append(help='', id=ID_PLCOPENEDITOREDITMENUITEMS12,
+ AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUITEMS12,
kind=wx.ITEM_NORMAL, text=u'Remove Configuration')
self.Bind(wx.EVT_MENU, self.OnRefreshMenu,
id=ID_PLCOPENEDITOREDITMENUITEMS0)
@@ -186,9 +199,9 @@
parent.Append(menu=self.HelpMenu, title=u'Help')
def _init_coll_ConfigMenu_Items(self, parent):
- parent.Append(help='', id=ID_PLCOPENEDITORCONFIGMENUITEMS0,
+ AppendMenu(parent, help='', id=ID_PLCOPENEDITORCONFIGMENUITEMS0,
kind=wx.ITEM_NORMAL, text=u'Add Resource')
- parent.Append(help='', id=ID_PLCOPENEDITORCONFIGMENUITEMS1,
+ AppendMenu(parent, help='', id=ID_PLCOPENEDITORCONFIGMENUITEMS1,
kind=wx.ITEM_NORMAL, text=u'Remove Resource')
self.Bind(wx.EVT_MENU, self.OnAddResourceMenu,
id=ID_PLCOPENEDITORCONFIGMENUITEMS0)
@@ -196,39 +209,39 @@
id=ID_PLCOPENEDITORCONFIGMENUITEMS1)
def _init_coll_HelpMenu_Items(self, parent):
- parent.Append(help='', id=ID_PLCOPENEDITORHELPMENUITEMS0,
- kind=wx.ITEM_NORMAL, text=u'PLCOpenEditor\tF1')
- parent.Append(help='', id=ID_PLCOPENEDITORHELPMENUITEMS1,
+ AppendMenu(parent, help='', id=ID_PLCOPENEDITORHELPMENUITEMS0,
+ kind=wx.ITEM_NORMAL, text=u'PLCOpenEditor\tF1')
+ AppendMenu(parent, help='', id=ID_PLCOPENEDITORHELPMENUITEMS1,
kind=wx.ITEM_NORMAL, text=u'PLCOpen\tF2')
- parent.Append(help='', id=ID_PLCOPENEDITORHELPMENUITEMS2,
+ AppendMenu(parent, help='', id=ID_PLCOPENEDITORHELPMENUITEMS2,
kind=wx.ITEM_NORMAL, text=u'IEC 61131-3\tF3')
if self.ModeSolo:
- parent.Append(help='', id=ID_PLCOPENEDITORHELPMENUITEMS3,
+ AppendMenu(parent, help='', id=ID_PLCOPENEDITORHELPMENUITEMS3,
kind=wx.ITEM_NORMAL, text=u'About')
self.Bind(wx.EVT_MENU, self.OnPLCOpenMenu,
id=ID_PLCOPENEDITORHELPMENUITEMS1)
-
+
def _init_coll_FileMenu_Items(self, parent):
- parent.Append(help='', id=ID_PLCOPENEDITORFILEMENUITEMS0,
+ AppendMenu(parent, help='', id=ID_PLCOPENEDITORFILEMENUITEMS0,
kind=wx.ITEM_NORMAL, text=u'New\tCTRL+N')
- parent.Append(help='', id=ID_PLCOPENEDITORFILEMENUITEMS1,
+ AppendMenu(parent, help='', id=ID_PLCOPENEDITORFILEMENUITEMS1,
kind=wx.ITEM_NORMAL, text=u'Open\tCTRL+O')
- parent.Append(help='', id=ID_PLCOPENEDITORFILEMENUITEMS2,
+ AppendMenu(parent, help='', id=ID_PLCOPENEDITORFILEMENUITEMS2,
kind=wx.ITEM_NORMAL, text=u'Close Tab\tCTRL+W')
- parent.Append(help='', id=ID_PLCOPENEDITORFILEMENUITEMS3,
+ AppendMenu(parent, help='', id=ID_PLCOPENEDITORFILEMENUITEMS3,
kind=wx.ITEM_NORMAL, text=u'Close Project')
parent.AppendSeparator()
- parent.Append(help='', id=ID_PLCOPENEDITORFILEMENUITEMS5,
+ AppendMenu(parent, help='', id=ID_PLCOPENEDITORFILEMENUITEMS5,
kind=wx.ITEM_NORMAL, text=u'Save\tCTRL+S')
- parent.Append(help='', id=ID_PLCOPENEDITORFILEMENUITEMS6,
+ AppendMenu(parent, help='', id=ID_PLCOPENEDITORFILEMENUITEMS6,
kind=wx.ITEM_NORMAL, text=u'Save As...\tCTRL+SHIFT+S')
- parent.Append(help='', id=ID_PLCOPENEDITORFILEMENUITEMS7,
+ AppendMenu(parent, help='', id=ID_PLCOPENEDITORFILEMENUITEMS7,
kind=wx.ITEM_NORMAL, text=u'Generate Program\tCTRL+G')
parent.AppendSeparator()
- parent.Append(help='', id=ID_PLCOPENEDITORFILEMENUITEMS9,
+ AppendMenu(parent, help='', id=ID_PLCOPENEDITORFILEMENUITEMS9,
kind=wx.ITEM_NORMAL, text=u'Properties')
parent.AppendSeparator()
- parent.Append(help='', id=ID_PLCOPENEDITORFILEMENUITEMS11,
+ AppendMenu(parent, help='', id=ID_PLCOPENEDITORFILEMENUITEMS11,
kind=wx.ITEM_NORMAL, text=u'Quit\tCTRL+Q')
self.Bind(wx.EVT_MENU, self.OnNewProjectMenu,
id=ID_PLCOPENEDITORFILEMENUITEMS0)
@@ -250,13 +263,13 @@
id=ID_PLCOPENEDITORFILEMENUITEMS11)
def _init_coll_SFCMenu_Items(self, parent):
- parent.Append(help='', id=ID_PLCOPENEDITORSFCMENUITEMS0,
+ AppendMenu(parent, help='', id=ID_PLCOPENEDITORSFCMENUITEMS0,
kind=wx.ITEM_NORMAL, text=u'Add Transition')
- parent.Append(help='', id=ID_PLCOPENEDITORSFCMENUITEMS1,
+ AppendMenu(parent, help='', id=ID_PLCOPENEDITORSFCMENUITEMS1,
kind=wx.ITEM_NORMAL, text=u'Add Action')
- parent.Append(help='', id=ID_PLCOPENEDITORSFCMENUITEMS2,
+ AppendMenu(parent, help='', id=ID_PLCOPENEDITORSFCMENUITEMS2,
kind=wx.ITEM_NORMAL, text=u'Remove Transition')
- parent.Append(help='', id=ID_PLCOPENEDITORSFCMENUITEMS3,
+ AppendMenu(parent, help='', id=ID_PLCOPENEDITORSFCMENUITEMS3,
kind=wx.ITEM_NORMAL, text=u'Remove Action')
self.Bind(wx.EVT_MENU, self.OnAddPouTransitionMenu,
id=ID_PLCOPENEDITORSFCMENUITEMS0)
@@ -271,10 +284,10 @@
self.menuBar1 = wx.MenuBar()
if self.ModeSolo:
- self.FileMenu = wx.Menu(title=u'')
+ self.FileMenu = wx.Menu(title='')
else:
self.FileMenu = None
- self.EditMenu = wx.Menu(title=u'')
+ self.EditMenu = wx.Menu(title='')
self.HelpMenu = wx.Menu(title='')
self.SFCMenu = wx.Menu(title='')
self.ConfigMenu = wx.Menu(title='')
@@ -310,7 +323,10 @@
name='treeCtrl1', parent=self.MainSplitter, pos=wx.Point(0, 0),
size=wx.Size(-1, -1),
style=wx.TR_HAS_BUTTONS|wx.TR_EDIT_LABELS|wx.TR_SINGLE|wx.SUNKEN_BORDER)
- self.ProjectTree.Bind(wx.EVT_RIGHT_UP, self.OnProjectTreeRightUp)
+ if wx.VERSION >= (2, 6, 0):
+ self.ProjectTree.Bind(wx.EVT_RIGHT_UP, self.OnProjectTreeRightUp)
+ else:
+ wx.EVT_RIGHT_UP(self.ProjectTree, self.OnProjectTreeRightUp)
self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.OnProjectTreeBeginDrag,
id=ID_PLCOPENEDITORPROJECTTREE)
self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.OnProjectTreeItemBeginEdit,
@@ -334,9 +350,12 @@
self.TabsOpened = wx.Notebook(id=ID_PLCOPENEDITORTABSOPENED,
name='TabsOpened', parent=self.MainSplitter, pos=wx.Point(0,
0), size=wx.Size(0, 0), style=0)
- self.TabsOpened.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED,
- self.OnPouSelectedChanged, id=ID_PLCOPENEDITORTABSOPENED)
-
+ if wx.VERSION >= (2, 6, 0):
+ self.TabsOpened.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED,
+ self.OnPouSelectedChanged, id=ID_PLCOPENEDITORTABSOPENED)
+ else:
+ wx.EVT_NOTEBOOK_PAGE_CHANGED(self.TabsOpened, ID_PLCOPENEDITORTABSOPENED,
+ self.OnPouSelectedChanged)
self.MainSplitter.SplitVertically(self.ProjectTree, self.TabsOpened, 200)
def __init__(self, parent, controler = None, fileOpen = None):
@@ -360,6 +379,7 @@
self.CurrentToolBar = []
self.CurrentLanguage = ""
+ self.CopyBuffer = None
self.DrawingMode = FREEDRAWING_MODE
#self.DrawingMode = DRIVENDRAWING_MODE
@@ -368,6 +388,13 @@
self.RefreshTitle()
self.RefreshToolBar()
+ def GetCopyBuffer(self):
+ return self.CopyBuffer
+
+ def SetCopyBuffer(self, element):
+ self.CopyBuffer = element
+ self.RefreshEditMenu()
+
def GetDrawingMode(self):
return self.DrawingMode
@@ -381,21 +408,21 @@
if self.FileMenu:
if self.Controler.HasOpenedProject():
if self.TabsOpened.GetPageCount() > 0:
- self.FileMenu.FindItemByPosition(2).Enable(True)
+ self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS2, True)
else:
- self.FileMenu.FindItemByPosition(2).Enable(False)
- self.FileMenu.FindItemByPosition(3).Enable(True)
- self.FileMenu.FindItemByPosition(5).Enable(True)
- self.FileMenu.FindItemByPosition(6).Enable(True)
- self.FileMenu.FindItemByPosition(7).Enable(True)
- self.FileMenu.FindItemByPosition(9).Enable(True)
- else:
- self.FileMenu.FindItemByPosition(2).Enable(False)
- self.FileMenu.FindItemByPosition(3).Enable(False)
- self.FileMenu.FindItemByPosition(5).Enable(False)
- self.FileMenu.FindItemByPosition(6).Enable(False)
- self.FileMenu.FindItemByPosition(7).Enable(False)
- self.FileMenu.FindItemByPosition(9).Enable(False)
+ self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS2, False)
+ self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS3, True)
+ self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS5, True)
+ self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS6, True)
+ self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS7, True)
+ self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS9, True)
+ else:
+ self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS2, False)
+ self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS3, False)
+ self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS5, False)
+ self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS6, False)
+ self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS7, False)
+ self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUITEMS9, False)
def RefreshEditMenu(self):
if self.EditMenu:
@@ -408,24 +435,22 @@
self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS2, False)
if self.Controler.HasOpenedProject():
if self.TabsOpened.GetPageCount() > 0:
- self.EditMenu.FindItemByPosition(0).Enable(True)
+ self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS0, True)
else:
- self.EditMenu.FindItemByPosition(0).Enable(False)
- self.EditMenu.FindItemByPosition(8).Enable(True)
- self.EditMenu.FindItemByPosition(9).Enable(True)
- else:
- self.EditMenu.FindItemByPosition(0).Enable(False)
- self.EditMenu.FindItemByPosition(8).Enable(False)
- self.EditMenu.FindItemByPosition(9).Enable(False)
+ self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS0, False)
+ self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS8, True)
+ self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS9, True)
+ else:
+ self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS0, False)
+ self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS8, False)
+ self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS9, False)
bodytype = self.Controler.GetCurrentElementEditingBodyType()
- if bodytype in ["IL","ST"]:
- self.EditMenu.FindItemByPosition(4).Enable(True)
- self.EditMenu.FindItemByPosition(5).Enable(True)
- self.EditMenu.FindItemByPosition(6).Enable(True)
- else:
- self.EditMenu.FindItemByPosition(4).Enable(False)
- self.EditMenu.FindItemByPosition(5).Enable(False)
- self.EditMenu.FindItemByPosition(6).Enable(False)
+ self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS4, True)
+ self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS5, True)
+ if self.CopyBuffer is not None:
+ self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS6, True)
+ else:
+ self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUITEMS6, False)
def RefreshEditor(self):
selected = self.TabsOpened.GetSelection()
@@ -748,7 +773,10 @@
name = self.TabsOpened.GetPageText(selected)
if self.ProjectTree:
root = self.ProjectTree.GetRootItem()
- item, root_cookie = self.ProjectTree.GetFirstChild(root)
+ if wx.VERSION >= (2, 6, 0):
+ item, root_cookie = self.ProjectTree.GetFirstChild(root)
+ else:
+ item, root_cookie = self.ProjectTree.GetFirstChild(root, 0)
while item.IsOk() and not found:
if self.ProjectTree.GetItemText(item) == name:
self.ProjectTree.SelectItem(item)
@@ -961,6 +989,7 @@
idx = self.Controler.OpenConfigurationEditing(*names)
if idx is not None:
new_window = PouEditorPanel(self.TabsOpened, self, self.Controler, "config", config_name = names[0])
+ new_window.SetIndex(idx)
self.TabsOpened.AddPage(new_window, "")
if idx is None:
idx = self.Controler.ChangeConfigurationEditing(*names)
@@ -969,6 +998,7 @@
idx = self.Controler.OpenConfigurationResourceEditing(*names)
if idx is not None:
new_window = PouEditorPanel(self.TabsOpened, self, self.Controler, "resource", config_name = names[0], resource_name = names[1])
+ new_window.SetIndex(idx)
self.TabsOpened.AddPage(new_window, "")
if idx is None:
idx = self.Controler.ChangeConfigurationResourceEditing(*names)
@@ -977,6 +1007,7 @@
idx = self.Controler.OpenPouEditing(*names)
if idx != None:
new_window = PouEditorPanel(self.TabsOpened, self, self.Controler, self.Controler.GetPouType(names[0]), pou_name = names[0])
+ new_window.SetIndex(idx)
self.TabsOpened.AddPage(new_window, "")
if idx is None:
idx = self.Controler.ChangePouEditing(*names)
@@ -985,6 +1016,7 @@
idx = self.Controler.OpenPouTransitionEditing(*names)
if idx is not None:
new_window = PouEditorPanel(self.TabsOpened, self, self.Controler, "transition", pou_name = names[0], transition_name = names[1])
+ new_window.SetIndex(idx)
self.TabsOpened.AddPage(new_window, "")
if idx is None:
idx = self.Controler.ChangePouTransitionEditing(*names)
@@ -993,6 +1025,7 @@
idx = self.Controler.OpenPouActionEditing(*names)
if idx is not None:
new_window = PouEditorPanel(self.TabsOpened, self, self.Controler, "action", pou_name = names[0], action_name = names[1])
+ new_window.SetIndex(idx)
self.TabsOpened.AddPage(new_window, "")
if idx is None:
idx = self.Controler.ChangePouActionEditing(*names)
@@ -1000,20 +1033,24 @@
old_selected = self.TabsOpened.GetSelection()
if old_selected >= 0:
self.TabsOpened.GetPage(old_selected).ResetBuffer()
- self.TabsOpened.SetSelection(idx)
- window = self.TabsOpened.GetPage(idx)
- window.RefreshView()
- self.RefreshTabsOpenedTitles()
- self.RefreshFileMenu()
- self.RefreshEditMenu()
- self.RefreshToolBar()
+ for i in xrange(self.TabsOpened.GetPageCount()):
+ window = self.TabsOpened.GetPage(i)
+ if window.GetIndex() == idx:
+ self.TabsOpened.SetSelection(i)
+ window.RefreshView()
+ self.RefreshTabsOpenedTitles()
+ self.RefreshFileMenu()
+ self.RefreshEditMenu()
+ self.RefreshToolBar()
+ return
def OnProjectTreeRightUp(self, event):
+ cursor_pos = event.GetPosition()
selected = self.ProjectTree.GetSelection()
if self.ProjectTree.GetPyData(selected) == ITEM_POU:
name = self.ProjectTree.GetItemText(selected)
if self.Controler.GetPouBodyType(name) == "SFC":
- self.PopupMenu(self.SFCMenu)
+ self.PopupMenuXY(self.SFCMenu, cursor_pos.x, cursor_pos.y)
elif self.ProjectTree.GetPyData(selected) == ITEM_CONFIGURATION:
self.PopupMenu(self.ConfigMenu)
event.Skip()
@@ -1032,7 +1069,10 @@
self.ProjectTree.SetPyData(root, infos["type"])
if infos["type"] == ITEM_POU and wx.Platform != '__WXMSW__':
self.ProjectTree.SetItemImage(root, LANGUAGES.index(self.Controler.GetPouBodyType(infos["name"])))
- item, root_cookie = self.ProjectTree.GetFirstChild(root)
+ if wx.VERSION >= (2, 5, 0):
+ item, root_cookie = self.ProjectTree.GetFirstChild(root)
+ else:
+ item, root_cookie = self.ProjectTree.GetFirstChild(root, 0)
for values in infos["values"]:
if not item.IsOk():
item = self.ProjectTree.AppendItem(root, "")
@@ -1048,7 +1088,10 @@
def ResetToolBar(self):
for item in self.CurrentToolBar:
- self.Unbind(wx.EVT_MENU, id=item)
+ if wx.VERSION >= (2, 6, 0):
+ self.Unbind(wx.EVT_MENU, id=item)
+ else:
+ self.Disconnect(id=item, eventType=wx.wxEVT_COMMAND_MENU_SELECTED)
self.ToolBar.DeleteTool(item)
def RefreshToolBar(self):
@@ -1322,6 +1365,13 @@
] = [wx.NewId() for _init_ctrls in range(15)]
class ProjectDialog(wx.Dialog):
+ if wx.VERSION < (2, 6, 0):
+ def Bind(self, event, function, id = None):
+ if id is not None:
+ event(self, id, function)
+ else:
+ event(self, function)
+
def _init_coll_flexGridSizer1_Items(self, parent):
parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
@@ -1498,6 +1548,13 @@
] = [wx.NewId() for _init_ctrls in range(7)]
class PouDialog(wx.Dialog):
+ if wx.VERSION < (2, 6, 0):
+ def Bind(self, event, function, id = None):
+ if id is not None:
+ event(self, id, function)
+ else:
+ event(self, function)
+
def _init_coll_flexGridSizer1_Items(self, parent):
parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
@@ -1663,6 +1720,13 @@
] = [wx.NewId() for _init_ctrls in range(5)]
class PouTransitionDialog(wx.Dialog):
+ if wx.VERSION < (2, 6, 0):
+ def Bind(self, event, function, id = None):
+ if id is not None:
+ event(self, id, function)
+ else:
+ event(self, function)
+
def _init_coll_flexGridSizer1_Items(self, parent):
parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
@@ -1795,6 +1859,13 @@
] = [wx.NewId() for _init_ctrls in range(5)]
class PouActionDialog(wx.Dialog):
+ if wx.VERSION < (2, 6, 0):
+ def Bind(self, event, function, id = None):
+ if id is not None:
+ event(self, id, function)
+ else:
+ event(self, function)
+
def _init_coll_flexGridSizer1_Items(self, parent):
parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
@@ -1923,6 +1994,13 @@
class ConfigurationNameDialog(wx.TextEntryDialog):
+ if wx.VERSION < (2, 6, 0):
+ def Bind(self, event, function, id = None):
+ if id is not None:
+ event(self, id, function)
+ else:
+ event(self, function)
+
def __init__(self, parent, message, caption = "Please enter configuration name", defaultValue = "",
style = wx.OK|wx.CANCEL|wx.CENTRE, pos = wx.DefaultPosition):
wx.TextEntryDialog.__init__(self, parent, message, caption, defaultValue, style, pos)
@@ -1974,6 +2052,13 @@
class ResourceNameDialog(wx.TextEntryDialog):
+ if wx.VERSION < (2, 6, 0):
+ def Bind(self, event, function, id = None):
+ if id is not None:
+ event(self, id, function)
+ else:
+ event(self, function)
+
def __init__(self, parent, message, caption = "Please enter resource name", defaultValue = "",
style = wx.OK|wx.CANCEL|wx.CENTRE, pos = wx.DefaultPosition):
wx.TextEntryDialog.__init__(self, parent, message, caption, defaultValue, style, pos)
@@ -2252,6 +2337,14 @@
] = [wx.NewId() for _init_ctrls in range(12)]
class PouEditorPanel(wx.SplitterWindow):
+
+ if wx.VERSION < (2, 6, 0):
+ def Bind(self, event, function, id = None):
+ if id is not None:
+ event(self, id, function)
+ else:
+ event(self, function)
+
def _init_coll_VariablePanelSizer_Items(self, parent):
parent.AddWindow(self.VariablesGrid, 0, border=0, flag=wx.GROW)
parent.AddSizer(self.ControlPanelSizer, 0, border=0, flag=wx.GROW)
@@ -2306,7 +2399,7 @@
def _init_ctrls(self, prnt, element_type):
wx.SplitterWindow.__init__(self, id=ID_POUEDITORPANEL,
- name='EditVariablePanel', parent=prnt, pos=wx.Point(0, 0),
+ name='EditVariablePanel', parent=prnt, point=wx.Point(0, 0),
size=wx.Size(0, 0), style=wx.SP_3D)
self.SetNeedUpdating(True)
self.SetMinimumPaneSize(1)
@@ -2365,10 +2458,16 @@
False, 'Sans'))
self.VariablesGrid.SetSelectionBackground(wx.WHITE)
self.VariablesGrid.SetSelectionForeground(wx.BLACK)
- self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnVariablesGridCellChange)
- self.VariablesGrid.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.OnVariablesGridSelectCell)
- self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnVariablesGridCellLeftClick)
- self.VariablesGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, self.OnVariablesGridEditorShown)
+ if wx.VERSION >= (2, 6, 0):
+ self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnVariablesGridCellChange)
+ self.VariablesGrid.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.OnVariablesGridSelectCell)
+ self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnVariablesGridCellLeftClick)
+ self.VariablesGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, self.OnVariablesGridEditorShown)
+ else:
+ wx.grid.EVT_GRID_CELL_CHANGE(self.VariablesGrid, self.OnVariablesGridCellChange)
+ wx.grid.EVT_GRID_SELECT_CELL(self.VariablesGrid, self.OnVariablesGridSelectCell)
+ wx.grid.EVT_GRID_CELL_LEFT_CLICK(self.VariablesGrid, self.OnVariablesGridCellLeftClick)
+ wx.grid.EVT_GRID_EDITOR_SHOWN(self.VariablesGrid, self.OnVariablesGridEditorShown)
self.VariablesGrid.SetDropTarget(VariableDropTarget(self))
self.AddButton = wx.Button(id=ID_POUEDITORPANELADDBUTTON, label='Add',
@@ -2475,6 +2574,12 @@
self.VariablesGrid.SetColAttr(col, attr)
self.VariablesGrid.SetColSize(col, self.ColSizes[col])
+ def SetIndex(self, index):
+ self.ControlerIndex = index
+
+ def GetIndex(self):
+ return self.ControlerIndex
+
def RefreshName(self, name_type, old_name, new_name):
if name_type == ITEM_POU and self.PouName == old_name:
self.PouName = new_name
@@ -2668,15 +2773,15 @@
base_menu = wx.Menu(title='')
for base_type in self.TypeList:
new_id = wx.NewId()
- base_menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=base_type)
+ AppendMenu(base_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=base_type)
self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(base_type), id=new_id)
- type_menu.AppendMenu(-1, "Base Types", base_menu, '')
+ type_menu.AppendMenu(wx.NewId(), "Base Types", base_menu)
functionblock_menu = wx.Menu(title='')
for functionblock_type in self.Controler.GetFunctionBlockTypes():
new_id = wx.NewId()
- functionblock_menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=functionblock_type)
+ AppendMenu(functionblock_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=functionblock_type)
self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(functionblock_type), id=new_id)
- type_menu.AppendMenu(-1, "Function Block Types", functionblock_menu, '')
+ type_menu.AppendMenu(wx.NewId(), "Function Block Types", functionblock_menu)
rect = self.VariablesGrid.BlockToDeviceRect((row, col), (row, col))
self.VariablesGrid.PopupMenuXY(type_menu, rect.x + rect.width, rect.y + self.VariablesGrid.GetColLabelSize())
event.Veto()
--- a/Viewer.py Wed Oct 24 16:00:00 2007 +0200
+++ b/Viewer.py Wed Oct 24 16:01:06 2007 +0200
@@ -33,6 +33,12 @@
WINDOW_BORDER = 10
SCROLL_ZONE = 10
+def AppendMenu(parent, help, id, kind, text):
+ if wx.VERSION >= (2, 6, 0):
+ parent.Append(help=help, id=id, kind=kind, text=text)
+ else:
+ parent.Append(helpString=help, id=id, kind=kind, item=text)
+
#-------------------------------------------------------------------------------
# Graphic elements Viewer base class
#-------------------------------------------------------------------------------
@@ -119,31 +125,38 @@
class Viewer(wx.ScrolledWindow):
+ if wx.VERSION < (2, 6, 0):
+ def Bind(self, event, function, id = None):
+ if id is not None:
+ event(self, id, function)
+ else:
+ event(self, function)
+
# Create Contextual Menu items
def _init_coll_ContextualMenu_Items(self, parent):
# Create menu items
- parent.Append(help='', id=ID_FBDVIEWERCONTEXTUALMENUITEMS0,
+ AppendMenu(parent, help='', id=ID_FBDVIEWERCONTEXTUALMENUITEMS0,
kind=wx.ITEM_RADIO, text=u'No Modifier')
- parent.Append(help='', id=ID_FBDVIEWERCONTEXTUALMENUITEMS1,
+ AppendMenu(parent, help='', id=ID_FBDVIEWERCONTEXTUALMENUITEMS1,
kind=wx.ITEM_RADIO, text=u'Negated')
- parent.Append(help='', id=ID_FBDVIEWERCONTEXTUALMENUITEMS2,
+ AppendMenu(parent, help='', id=ID_FBDVIEWERCONTEXTUALMENUITEMS2,
kind=wx.ITEM_RADIO, text=u'Rising Edge')
- parent.Append(help='', id=ID_FBDVIEWERCONTEXTUALMENUITEMS3,
+ AppendMenu(parent, help='', id=ID_FBDVIEWERCONTEXTUALMENUITEMS3,
kind=wx.ITEM_RADIO, text=u'Falling Edge')
parent.AppendSeparator()
- parent.Append(help='', id=ID_FBDVIEWERCONTEXTUALMENUITEMS5,
+ AppendMenu(parent, help='', id=ID_FBDVIEWERCONTEXTUALMENUITEMS5,
kind=wx.ITEM_NORMAL, text=u'Add Wire Segment')
- parent.Append(help='', id=ID_FBDVIEWERCONTEXTUALMENUITEMS6,
+ AppendMenu(parent, help='', id=ID_FBDVIEWERCONTEXTUALMENUITEMS6,
kind=wx.ITEM_NORMAL, text=u'Delete Wire Segment')
parent.AppendSeparator()
- parent.Append(help='', id=ID_FBDVIEWERCONTEXTUALMENUITEMS8,
+ AppendMenu(parent, help='', id=ID_FBDVIEWERCONTEXTUALMENUITEMS8,
kind=wx.ITEM_NORMAL, text=u'Add Divergence Branch')
- parent.Append(help='', id=ID_FBDVIEWERCONTEXTUALMENUITEMS9,
+ AppendMenu(parent, help='', id=ID_FBDVIEWERCONTEXTUALMENUITEMS9,
kind=wx.ITEM_NORMAL, text=u'Delete Divergence Branch')
parent.AppendSeparator()
- parent.Append(help='', id=ID_FBDVIEWERCONTEXTUALMENUITEMS11,
+ AppendMenu(parent, help='', id=ID_FBDVIEWERCONTEXTUALMENUITEMS11,
kind=wx.ITEM_NORMAL, text=u'Edit Block')
- parent.Append(help='', id=ID_FBDVIEWERCONTEXTUALMENUITEMS12,
+ AppendMenu(parent, help='', id=ID_FBDVIEWERCONTEXTUALMENUITEMS12,
kind=wx.ITEM_NORMAL, text=u'Delete')
# Link menu event to corresponding called functions
self.Bind(wx.EVT_MENU, self.OnNoModifierMenu,
@@ -185,7 +198,7 @@
self.Scaling = None
#self.Scaling = (8, 8)
self.DrawGrid = True
- self.current_id = 0
+ self.current_id = 0
# Initialize Block, Wire and Comment numbers
self.block_id = self.wire_id = self.comment_id = 0
@@ -193,6 +206,7 @@
# Initialize Viewer mode to Selection mode
self.Mode = MODE_SELECTION
self.SavedMode = False
+ self.CurrentLanguage = "FBD"
self.ParentWindow = window
self.Controler = controler
@@ -227,7 +241,10 @@
dc = wx.ClientDC(self)
if wx.Platform != '__WXMSW__':
dc.SetFont(wx.NORMAL_FONT)
- self.DoPrepareDC(dc)
+ if wx.VERSION >= (2, 6, 0):
+ self.DoPrepareDC(dc)
+ else:
+ self.PrepareDC(dc)
return dc
#-------------------------------------------------------------------------------
@@ -1056,6 +1073,11 @@
self.RefreshBuffer()
self.RefreshScrollBars()
self.Refresh(False)
+ elif keycode == wx.WXK_SPACE and self.SelectedElement is not None and self.SelectedElement.Dragging:
+ self.CopyBlock(self.SelectedElement, self.SelectedElement.Pos)
+ self.RefreshBuffer()
+ self.RefreshScrollBars()
+ self.Refresh()
else:
event.Skip()
@@ -1132,7 +1154,10 @@
dialog.Destroy()
def AddNewComment(self, bbox):
- dialog = wx.TextEntryDialog(self.ParentWindow, "Add a new comment", "Please enter comment text", "", wx.OK|wx.CANCEL|wx.TE_MULTILINE)
+ if wx.VERSION >= (2, 5, 0):
+ dialog = wx.TextEntryDialog(self.ParentWindow, "Edit comment", "Please enter comment text", "", wx.OK|wx.CANCEL|wx.TE_MULTILINE)
+ else:
+ dialog = wx.TextEntryDialog(self.ParentWindow, "Edit comment", "Please enter comment text", "", wx.OK|wx.CANCEL)
if dialog.ShowModal() == wx.ID_OK:
value = dialog.GetValue()
id = self.GetNewId()
@@ -1553,7 +1578,10 @@
dialog.Destroy()
def EditCommentContent(self, comment):
- dialog = wx.TextEntryDialog(self.ParentWindow, "Edit comment", "Please enter comment text", comment.GetContent(), wx.OK|wx.CANCEL|wx.TE_MULTILINE)
+ if wx.VERSION >= (2, 5, 0):
+ dialog = wx.TextEntryDialog(self.ParentWindow, "Edit comment", "Please enter comment text", comment.GetContent(), wx.OK|wx.CANCEL|wx.TE_MULTILINE)
+ else:
+ dialog = wx.TextEntryDialog(self.ParentWindow, "Edit comment", "Please enter comment text", comment.GetContent(), wx.OK|wx.CANCEL)
if dialog.ShowModal() == wx.ID_OK:
value = dialog.GetValue()
comment.SetContent(value)
@@ -1822,13 +1850,80 @@
#-------------------------------------------------------------------------------
def Cut(self):
- pass
+ if self.IsBlock(self.SelectedElement):
+ self.ParentWindow.SetCopyBuffer(self.SelectedElement.Clone())
+ self.SelectedElement.Delete()
+ self.RefreshBuffer()
+ self.RefreshScrollBars()
+ self.Refresh()
def Copy(self):
- pass
+ if self.IsBlock(self.SelectedElement):
+ self.ParentWindow.SetCopyBuffer(self.SelectedElement.Clone())
def Paste(self):
- pass
+ element = self.ParentWindow.GetCopyBuffer()
+ if element is not None and self.CanAddBlock(element):
+ block = self.CopyBlock(element, wx.Point(*self.CalcUnscrolledPosition(30, 30)))
+ if self.SelectedElement is not None:
+ self.SelectedElement.SetSelected(False)
+ self.SelectedElement = block
+ self.SelectedElement.SetSelected(True)
+ self.RefreshBuffer()
+ self.RefreshScrollBars()
+ self.Refresh()
+
+ def CanAddBlock(self, block):
+ if self.CurrentLanguage == "SFC":
+ return True
+ elif self.CurrentLanguage == "LD" and not isinstance(block, (SFC_Step, SFC_Transition, SFC_Divergence, SFC_Jump, SFC_ActionBlock)):
+ return True
+ elif self.CurrentLanguage == "FBD" and isinstance(block, (FBD_Block, FBD_Variable, FBD_Connector, Comment)):
+ return True
+ return False
+
+ def CopyBlock(self, element, pos):
+ id = self.GetNewId()
+ block = element.Clone(id, pos)
+ self.AddBlock(block)
+ if isinstance(block, Comment):
+ self.Controler.AddCurrentElementEditingComment(id)
+ self.RefreshCommentModel(comment)
+ elif isinstance(block, FBD_Block):
+ self.Controler.AddCurrentElementEditingBlock(id, block.GetType(), None)
+ self.RefreshBlockModel(block)
+ elif isinstance(block, FBD_Variable):
+ self.Controler.AddCurrentElementEditingVariable(id, block.GetType())
+ self.RefreshVariableModel(block)
+ elif isinstance(block, FBD_Connector):
+ self.Controler.AddCurrentElementEditingConnection(id, block.GetType())
+ self.RefreshConnectionModel(block)
+ elif isinstance(block, LD_Contact):
+ self.Controler.AddCurrentElementEditingContact(id)
+ self.RefreshContactModel(block)
+ elif isinstance(block, LD_Coil):
+ self.Controler.AddCurrentElementEditingCoil(id)
+ self.RefreshCoilModel(block)
+ elif isinstance(block, LD_PowerRail):
+ self.Controler.AddCurrentElementEditingPowerRail(id, block.GetType())
+ self.RefreshPowerRailModel(block)
+ elif isinstance(block, SFC_Step):
+ self.Controler.AddCurrentElementEditingStep(id)
+ self.RefreshStepModel(block)
+ elif isinstance(block, SFC_Transition):
+ self.Controler.AddCurrentElementEditingTransition(id)
+ self.RefreshTransitionModel(block)
+ elif isinstance(block, SFC_Divergence):
+ self.Controler.AddCurrentElementEditingDivergence(id, block.GetType())
+ self.RefreshActionDivergenceModel(block)
+ elif isinstance(block, SFC_Jump):
+ self.Controler.AddCurrentElementEditingJump(id)
+ self.RefreshJumpModel(block)
+ elif isinstance(block, SFC_ActionBlock):
+ self.Controler.AddCurrentElementEditingActionBlock(id)
+ self.RefreshActionBlockModel(block)
+ return block
+
#-------------------------------------------------------------------------------
# Drawing functions