--- a/dialogs/FBDBlockDialog.py Fri Jun 15 18:03:25 2012 +0200
+++ b/dialogs/FBDBlockDialog.py Mon Jun 25 20:03:53 2012 +0200
@@ -31,156 +31,97 @@
# Create New Block Dialog
#-------------------------------------------------------------------------------
-[ID_FBDBLOCKDIALOG, ID_FBDBLOCKDIALOGNAME,
- ID_FBDBLOCKDIALOGTYPETREE, ID_FBDBLOCKDIALOGTYPEDESC,
- ID_FBDBLOCKDIALOGINPUTS, ID_FBDBLOCKDIALOGPREVIEW,
- ID_FBDBLOCKDIALOGEXECUTIONORDER, ID_FBDBLOCKDIALOGEXECUTIONCONTROL,
- ID_FBDBLOCKDIALOGSTATICTEXT1, ID_FBDBLOCKDIALOGSTATICTEXT2,
- ID_FBDBLOCKDIALOGSTATICTEXT3, ID_FBDBLOCKDIALOGSTATICTEXT4,
- ID_FBDBLOCKDIALOGSTATICTEXT5, ID_FBDBLOCKDIALOGSTATICTEXT6,
-] = [wx.NewId() for _init_ctrls in range(14)]
-
-[CATEGORY, BLOCK] = range(2)
-
class FBDBlockDialog(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)
-
- def _init_coll_flexGridSizer1_Growables(self, parent):
- parent.AddGrowableCol(0)
- parent.AddGrowableRow(0)
-
- def _init_coll_MainSizer_Items(self, parent):
- parent.AddSizer(self.LeftBoxSizer, 1, border=5, flag=wx.GROW|wx.RIGHT)
- parent.AddSizer(self.RightGridSizer, 1, border=5, flag=wx.GROW|wx.LEFT)
-
- def _init_coll_LeftBoxSizer_Items(self, parent):
- parent.AddWindow(self.LibraryPanel, 1, border=5, flag=wx.GROW|wx.TOP)
-
- def _init_coll_RightGridSizer_Items(self, parent):
- parent.AddSizer(self.RightUpGridSizer, 0, border=0, flag=wx.GROW)
- parent.AddWindow(self.staticText6, 0, border=0, flag=wx.GROW)
- parent.AddWindow(self.Preview, 0, border=0, flag=wx.GROW)
-
- def _init_coll_RightGridSizer_Growables(self, parent):
- parent.AddGrowableCol(0)
- parent.AddGrowableRow(2)
-
- def _init_coll_RightUpGridSizer_Items(self, parent):
- parent.AddWindow(self.staticText2, 0, border=4, flag=wx.ALIGN_CENTER_VERTICAL|wx.TOP)
- parent.AddWindow(self.BlockName, 0, border=0, flag=wx.GROW)
- parent.AddWindow(self.staticText3, 0, border=4, flag=wx.ALIGN_CENTER_VERTICAL|wx.TOP)
- parent.AddWindow(self.Inputs, 0, border=0, flag=wx.GROW)
- parent.AddWindow(self.staticText4, 0, border=4, flag=wx.ALIGN_CENTER_VERTICAL|wx.TOP)
- parent.AddWindow(self.ExecutionOrder, 0, border=0, flag=wx.GROW)
- parent.AddWindow(self.staticText5, 0, border=4, flag=wx.ALIGN_CENTER_VERTICAL|wx.TOP)
- parent.AddWindow(self.ExecutionControl, 0, border=0, flag=wx.GROW)
-
- def _init_coll_RightUpGridSizer_Growables(self, parent):
- parent.AddGrowableCol(1)
-
- def _init_sizers(self):
- self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
- self.MainSizer = wx.BoxSizer(wx.HORIZONTAL)
- self.LeftBoxSizer = wx.StaticBoxSizer(self.staticbox1, wx.VERTICAL)
- self.RightGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=5)
- self.RightUpGridSizer = wx.FlexGridSizer(cols=2, hgap=5, rows=4, vgap=5)
-
- self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
- self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1)
- self._init_coll_MainSizer_Items(self.MainSizer)
- self._init_coll_LeftBoxSizer_Items(self.LeftBoxSizer)
- self._init_coll_RightGridSizer_Items(self.RightGridSizer)
- self._init_coll_RightGridSizer_Growables(self.RightGridSizer)
- self._init_coll_RightUpGridSizer_Items(self.RightUpGridSizer)
- self._init_coll_RightUpGridSizer_Growables(self.RightUpGridSizer)
-
- self.SetSizer(self.flexGridSizer1)
-
- def _init_ctrls(self, prnt):
- wx.Dialog.__init__(self, id=ID_FBDBLOCKDIALOG,
- name='FBDBlockDialog', parent=prnt,
- size=wx.Size(600, 400), style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER,
- title=_('Block Properties'))
- self.SetClientSize(wx.Size(600, 400))
-
- self.staticbox1 = wx.StaticBox(id=ID_FBDBLOCKDIALOGSTATICTEXT1,
- label=_('Type:'), name='staticBox1', parent=self,
- pos=wx.Point(0, 0), size=wx.Size(0, 0), style=0)
-
- self.staticText2 = wx.StaticText(id=ID_FBDBLOCKDIALOGSTATICTEXT2,
- label=_('Name:'), name='staticText2', parent=self,
- pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
-
- self.staticText3 = wx.StaticText(id=ID_FBDBLOCKDIALOGSTATICTEXT2,
- label=_('Inputs:'), name='staticText4', parent=self,
- pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
-
- self.staticText4 = wx.StaticText(id=ID_FBDBLOCKDIALOGSTATICTEXT4,
- label=_('Execution Order:'), name='staticText4', parent=self,
- pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
-
- self.staticText5 = wx.StaticText(id=ID_FBDBLOCKDIALOGSTATICTEXT5,
- label=_('Execution Control:'), name='staticText5', parent=self,
- pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
-
- self.staticText6 = wx.StaticText(id=ID_FBDBLOCKDIALOGSTATICTEXT6,
- label=_('Preview:'), name='staticText6', parent=self,
- pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
-
+ def __init__(self, parent, controller):
+ wx.Dialog.__init__(self, parent,
+ size=wx.Size(600, 400), title=_('Block Properties'))
+
+ main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=4, vgap=10)
+ main_sizer.AddGrowableCol(0)
+ main_sizer.AddGrowableRow(0)
+
+ column_sizer = wx.BoxSizer(wx.HORIZONTAL)
+ main_sizer.AddSizer(column_sizer, border=20,
+ flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
+
+ type_staticbox = wx.StaticBox(self, label=_('Type:'))
+ left_staticboxsizer = wx.StaticBoxSizer(type_staticbox, wx.VERTICAL)
+ column_sizer.AddSizer(left_staticboxsizer, 1, border=5,
+ flag=wx.GROW|wx.RIGHT)
+
self.LibraryPanel = LibraryPanel(self)
-
- self.BlockName = wx.TextCtrl(id=ID_FBDBLOCKDIALOGNAME, value='',
- name='BlockName', parent=self, pos=wx.Point(0, 0),
- size=wx.Size(0, 24), style=0)
- self.Bind(wx.EVT_TEXT, self.OnNameChanged, id=ID_FBDBLOCKDIALOGNAME)
-
- self.Inputs = wx.SpinCtrl(id=ID_FBDBLOCKDIALOGINPUTS,
- name='Inputs', parent=self, pos=wx.Point(0, 0),
- size=wx.Size(0, 24), style=wx.SP_ARROW_KEYS, min=2, max=20)
- self.Bind(wx.EVT_SPINCTRL, self.OnInputsChanged, id=ID_FBDBLOCKDIALOGINPUTS)
-
- self.ExecutionOrder = wx.SpinCtrl(id=ID_FBDBLOCKDIALOGEXECUTIONORDER,
- name='ExecutionOrder', parent=self, pos=wx.Point(0, 0),
- size=wx.Size(0, 24), style=wx.SP_ARROW_KEYS, min=0)
- self.Bind(wx.EVT_SPINCTRL, self.OnExecutionOrderChanged, id=ID_FBDBLOCKDIALOGEXECUTIONORDER)
-
- self.ExecutionControl = wx.CheckBox(id=ID_FBDBLOCKDIALOGEXECUTIONCONTROL,
- name='ExecutionControl', parent=self, pos=wx.Point(0, 0),
- size=wx.Size(0, 24), style=0)
- self.Bind(wx.EVT_CHECKBOX, self.OnExecutionOrderChanged, id=ID_FBDBLOCKDIALOGEXECUTIONCONTROL)
-
- self.Preview = wx.Panel(id=ID_FBDBLOCKDIALOGPREVIEW,
- name='Preview', parent=self, pos=wx.Point(0, 0),
- size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER)
+ self.LibraryPanel.SetController(controller)
+ setattr(self.LibraryPanel, "_OnTreeItemSelected",
+ self.OnLibraryTreeItemSelected)
+ left_staticboxsizer.AddWindow(self.LibraryPanel, 1, border=5,
+ flag=wx.GROW|wx.TOP)
+
+ right_gridsizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=5)
+ right_gridsizer.AddGrowableCol(0)
+ right_gridsizer.AddGrowableRow(2)
+ column_sizer.AddSizer(right_gridsizer, 1, border=5,
+ flag=wx.GROW|wx.LEFT)
+
+ top_right_gridsizer = wx.FlexGridSizer(cols=2, hgap=0, rows=4, vgap=5)
+ top_right_gridsizer.AddGrowableCol(1)
+ right_gridsizer.AddSizer(top_right_gridsizer, flag=wx.GROW)
+
+ name_label = wx.StaticText(self, label=_('Name:'))
+ top_right_gridsizer.AddWindow(name_label,
+ flag=wx.ALIGN_CENTER_VERTICAL)
+
+ self.BlockName = wx.TextCtrl(self)
+ self.Bind(wx.EVT_TEXT, self.OnNameChanged, self.BlockName)
+ top_right_gridsizer.AddWindow(self.BlockName, flag=wx.GROW)
+
+ inputs_label = wx.StaticText(self, label=_('Inputs:'))
+ top_right_gridsizer.AddWindow(inputs_label,
+ flag=wx.ALIGN_CENTER_VERTICAL)
+
+ self.Inputs = wx.SpinCtrl(self, min=2, max=20,
+ style=wx.SP_ARROW_KEYS)
+ self.Bind(wx.EVT_SPINCTRL, self.OnInputsChanged, self.Inputs)
+ top_right_gridsizer.AddWindow(self.Inputs, flag=wx.GROW)
+
+ execution_order_label = wx.StaticText(self, label=_('Execution Order:'))
+ top_right_gridsizer.AddWindow(execution_order_label,
+ flag=wx.ALIGN_CENTER_VERTICAL)
+
+ self.ExecutionOrder = wx.SpinCtrl(self, min=0, style=wx.SP_ARROW_KEYS)
+ self.Bind(wx.EVT_SPINCTRL, self.OnExecutionOrderChanged, self.ExecutionOrder)
+ top_right_gridsizer.AddWindow(self.ExecutionOrder, flag=wx.GROW)
+
+ execution_control_label = wx.StaticText(self, label=_('Execution Control:'))
+ top_right_gridsizer.AddWindow(execution_control_label,
+ flag=wx.ALIGN_CENTER_VERTICAL)
+
+ self.ExecutionControl = wx.CheckBox(self)
+ self.Bind(wx.EVT_CHECKBOX, self.OnExecutionOrderChanged, self.ExecutionControl)
+ top_right_gridsizer.AddWindow(self.ExecutionControl, flag=wx.GROW)
+
+ preview_label = wx.StaticText(self, label=_('Preview:'))
+ right_gridsizer.AddWindow(preview_label, flag=wx.GROW)
+
+ self.Preview = wx.Panel(self,
+ style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER)
self.Preview.SetBackgroundColour(wx.Colour(255,255,255))
setattr(self.Preview, "GetDrawingMode", lambda:FREEDRAWING_MODE)
setattr(self.Preview, "GetScaling", lambda:None)
- setattr(self.Preview, "GetBlockType", self.Controler.GetBlockType)
- setattr(self.Preview, "IsOfType", self.Controler.IsOfType)
-
- self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)
- if wx.VERSION >= (2, 5, 0):
- self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId())
- self.Preview.Bind(wx.EVT_PAINT, self.OnPaint)
- else:
- self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId())
- wx.EVT_PAINT(self.Preview, self.OnPaint)
-
- self._init_sizers()
-
- def __init__(self, parent, controler):
- self.Controler = controler
- self._init_ctrls(parent)
+ setattr(self.Preview, "GetBlockType", controller.GetBlockType)
+ setattr(self.Preview, "IsOfType", controller.IsOfType)
+ self.Preview.Bind(wx.EVT_PAINT, self.OnPaint)
+ right_gridsizer.AddWindow(self.Preview, flag=wx.GROW)
+
+ button_sizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)
+ self.Bind(wx.EVT_BUTTON, self.OnOK, button_sizer.GetAffirmativeButton())
+ main_sizer.AddSizer(button_sizer, border=20,
+ flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
+
+ self.SetSizer(main_sizer)
+
+ self.Controller = controller
+
self.BlockName.SetValue("")
self.BlockName.Enable(False)
self.Inputs.Enable(False)
@@ -191,8 +132,6 @@
self.PouNames = []
self.PouElementNames = []
- self.LibraryPanel.SetControler(controler)
- setattr(self.LibraryPanel, "_OnTreeItemSelected", self.OnLibraryTreeItemSelected)
self.LibraryPanel.SetFocus()
def SetBlockList(self, blocklist):
@@ -202,33 +141,26 @@
self.Preview.SetFont(font)
def OnOK(self, event):
+ message = None
selected = self.LibraryPanel.GetSelectedBlock()
block_name = self.BlockName.GetValue()
name_enabled = self.BlockName.IsEnabled()
if selected is None:
- message = wx.MessageDialog(self, _("Form isn't complete. Valid block type must be selected!"), _("Error"), wx.OK|wx.ICON_ERROR)
- message.ShowModal()
- message.Destroy()
+ message = _("Form isn't complete. Valid block type must be selected!")
elif name_enabled and block_name == "":
- message = wx.MessageDialog(self, _("Form isn't complete. Name must be filled!"), _("Error"), wx.OK|wx.ICON_ERROR)
- message.ShowModal()
- message.Destroy()
+ message = _("Form isn't complete. Name must be filled!")
elif name_enabled and not TestIdentifier(block_name):
- message = wx.MessageDialog(self, _("\"%s\" is not a valid identifier!")%block_name, _("Error"), wx.OK|wx.ICON_ERROR)
- message.ShowModal()
- message.Destroy()
+ message = _("\"%s\" is not a valid identifier!") % block_name
elif name_enabled and block_name.upper() in IEC_KEYWORDS:
- message = wx.MessageDialog(self, _("\"%s\" is a keyword. It can't be used!")%block_name, _("Error"), wx.OK|wx.ICON_ERROR)
- message.ShowModal()
- message.Destroy()
+ message = _("\"%s\" is a keyword. It can't be used!") % block_name
elif name_enabled and block_name.upper() in self.PouNames:
- message = wx.MessageDialog(self, _("\"%s\" pou already exists!")%block_name, _("Error"), wx.OK|wx.ICON_ERROR)
- message.ShowModal()
- message.Destroy()
+ message = _("\"%s\" pou already exists!") % block_name
elif name_enabled and block_name.upper() in self.PouElementNames:
- message = wx.MessageDialog(self, _("\"%s\" element for this pou already exists!")%block_name, _("Error"), wx.OK|wx.ICON_ERROR)
- message.ShowModal()
- message.Destroy()
+ message = _("\"%s\" element for this pou already exists!") % block_name
+ if message is not None:
+ dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR)
+ dialog.ShowModal()
+ dialog.Destroy()
else:
self.EndModal(wx.ID_OK)
@@ -269,7 +201,7 @@
def OnLibraryTreeItemSelected(self, event):
values = self.LibraryPanel.GetSelectedBlock()
if values is not None:
- blocktype = self.Controler.GetBlockType(values["type"], values["inputs"])
+ blocktype = self.Controller.GetBlockType(values["type"], values["inputs"])
else:
blocktype = None
if blocktype is not None: