--- a/dialogs/ConnectionDialog.py Fri Jun 15 18:03:25 2012 +0200
+++ b/dialogs/ConnectionDialog.py Mon Jun 25 20:03:53 2012 +0200
@@ -30,137 +30,77 @@
# Create New Connection Dialog
#-------------------------------------------------------------------------------
-[ID_CONNECTIONDIALOG, ID_CONNECTIONDIALOGSPACER,
- ID_CONNECTIONDIALOGNAME, ID_CONNECTIONDIALOGRADIOBUTTON1,
- ID_CONNECTIONDIALOGRADIOBUTTON2, ID_CONNECTIONDIALOGPREVIEW,
- ID_CONNECTIONDIALOGSTATICTEXT1, ID_CONNECTIONDIALOGSTATICTEXT2,
- ID_CONNECTIONDIALOGSTATICTEXT3,
-] = [wx.NewId() for _init_ctrls in range(9)]
-
class ConnectionDialog(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__(self, parent, controller):
+ wx.Dialog.__init__(self, parent,
+ size=wx.Size(350, 220), title=_('Connection Properties'))
- def _init_coll_flexGridSizer1_Growables(self, parent):
- parent.AddGrowableCol(0)
- parent.AddGrowableRow(0)
-
- def _init_coll_MainSizer_Items(self, parent):
- parent.AddSizer(self.LeftGridSizer, 1, border=5, flag=wx.GROW|wx.RIGHT)
- parent.AddSizer(self.RightGridSizer, 1, border=5, flag=wx.GROW|wx.LEFT)
-
- def _init_coll_LeftGridSizer_Items(self, parent):
- parent.AddWindow(self.staticText1, 0, border=0, flag=wx.GROW)
- parent.AddWindow(self.radioButton1, 0, border=0, flag=wx.GROW)
- parent.AddWindow(self.radioButton2, 0, border=0, flag=wx.GROW)
- parent.AddWindow(self.staticText2, 0, border=0, flag=wx.GROW)
- parent.AddWindow(self.ConnectionName, 0, border=0, flag=wx.GROW)
- parent.AddWindow(self.Spacer, 0, border=0, flag=wx.GROW)
-
- def _init_coll_LeftGridSizer_Growables(self, parent):
- parent.AddGrowableCol(0)
- parent.AddGrowableRow(5)
-
- def _init_coll_RightGridSizer_Items(self, parent):
- parent.AddWindow(self.staticText3, 0, border=0, flag=wx.GROW)
- parent.AddWindow(self.Preview, 0, border=0, flag=wx.GROW)
+ main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
+ main_sizer.AddGrowableCol(0)
+ main_sizer.AddGrowableRow(0)
- def _init_coll_RightGridSizer_Growables(self, parent):
- parent.AddGrowableCol(0)
- parent.AddGrowableRow(1)
-
- def _init_sizers(self):
- self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
- self.MainSizer = wx.BoxSizer(wx.HORIZONTAL)
- self.LeftGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=6, vgap=5)
- self.RightGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, 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_LeftGridSizer_Items(self.LeftGridSizer)
- self._init_coll_LeftGridSizer_Growables(self.LeftGridSizer)
- self._init_coll_RightGridSizer_Items(self.RightGridSizer)
- self._init_coll_RightGridSizer_Growables(self.RightGridSizer)
-
- self.SetSizer(self.flexGridSizer1)
-
- def _init_ctrls(self, prnt, ctrler):
- wx.Dialog.__init__(self, id=ID_CONNECTIONDIALOG,
- name='ConnectionDialog', parent=prnt,
- size=wx.Size(350, 220), style=wx.DEFAULT_DIALOG_STYLE,
- title=_('Connection Properties'))
- self.SetClientSize(wx.Size(350, 220))
-
- self.staticText1 = wx.StaticText(id=ID_CONNECTIONDIALOGSTATICTEXT1,
- label=_('Type:'), name='staticText1', parent=self,
- pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
-
- self.staticText2 = wx.StaticText(id=ID_CONNECTIONDIALOGSTATICTEXT2,
- label=_('Name:'), name='staticText2', parent=self,
- pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
-
- self.staticText3 = wx.StaticText(id=ID_CONNECTIONDIALOGSTATICTEXT3,
- label=_('Preview:'), name='staticText3', parent=self,
- pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
-
- self.radioButton1 = wx.RadioButton(id=ID_CONNECTIONDIALOGRADIOBUTTON1,
- label=_('Connector'), name='radioButton1', parent=self,
- pos=wx.Point(0, 0), size=wx.Size(0, 24), style=wx.RB_GROUP)
- self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, id=ID_CONNECTIONDIALOGRADIOBUTTON1)
- self.radioButton1.SetValue(True)
-
- self.radioButton2 = wx.RadioButton(id=ID_CONNECTIONDIALOGRADIOBUTTON2,
- label=_('Continuation'), name='radioButton2', parent=self,
- pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0)
- self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, id=ID_CONNECTIONDIALOGRADIOBUTTON2)
- self.radioButton2.SetValue(False)
+ column_sizer = wx.BoxSizer(wx.HORIZONTAL)
+ main_sizer.AddSizer(column_sizer, border=20,
+ flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
- self.ConnectionName = wx.TextCtrl(id=ID_CONNECTIONDIALOGNAME,
- name='Name', parent=self, pos=wx.Point(0, 0),
- size=wx.Size(0, 24), style=0)
- self.Bind(wx.EVT_TEXT, self.OnNameChanged, id=ID_CONNECTIONDIALOGNAME)
-
- self.Preview = wx.Panel(id=ID_CONNECTIONDIALOGPREVIEW,
- name='Preview', parent=self, pos=wx.Point(0, 0),
- size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER)
+ left_gridsizer = wx.FlexGridSizer(cols=1, hgap=0, rows=5, vgap=5)
+ left_gridsizer.AddGrowableCol(0)
+ column_sizer.AddSizer(left_gridsizer, 1, border=5,
+ flag=wx.GROW|wx.RIGHT)
+
+ type_label = wx.StaticText(self, label=_('Type:'))
+ left_gridsizer.AddWindow(type_label, flag=wx.GROW)
+
+ self.ConnectorRadioButton = wx.RadioButton(self,
+ label=_('Connector'), style=wx.RB_GROUP)
+ self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, self.ConnectorRadioButton)
+ self.ConnectorRadioButton.SetValue(True)
+ left_gridsizer.AddWindow(self.ConnectorRadioButton, flag=wx.GROW)
+
+ self.ConnectionRadioButton = wx.RadioButton(self, label=_('Continuation'))
+ self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, self.ConnectionRadioButton)
+ left_gridsizer.AddWindow(self.ConnectionRadioButton, flag=wx.GROW)
+
+ name_label = wx.StaticText(self, label=_('Name:'))
+ left_gridsizer.AddWindow(name_label, flag=wx.GROW)
+
+ self.ConnectionName = wx.TextCtrl(self)
+ self.Bind(wx.EVT_TEXT, self.OnNameChanged, self.ConnectionName)
+ left_gridsizer.AddWindow(self.ConnectionName, flag=wx.GROW)
+
+ right_gridsizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
+ right_gridsizer.AddGrowableCol(0)
+ right_gridsizer.AddGrowableRow(1)
+ column_sizer.AddSizer(right_gridsizer, 1, border=5,
+ flag=wx.GROW|wx.LEFT)
+
+ 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, "IsOfType", ctrler.IsOfType)
+ setattr(self.Preview, "IsOfType", controller.IsOfType)
+ self.Preview.Bind(wx.EVT_PAINT, self.OnPaint)
+ right_gridsizer.AddWindow(self.Preview, flag=wx.GROW)
- self.Spacer = wx.Panel(id=ID_CONNECTIONDIALOGSPACER,
- name='Spacer', parent=self, pos=wx.Point(0, 0),
- size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
+ 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.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.SetSizer(main_sizer)
- self._init_sizers()
-
- def __init__(self, parent, controler):
- self._init_ctrls(parent, controler)
self.Connection = None
self.MinConnectionSize = None
self.PouNames = []
self.PouElementNames = []
- self.radioButton1.SetFocus()
+ self.ConnectorRadioButton.SetFocus()
def SetPreviewFont(self, font):
self.Preview.SetFont(font)
@@ -172,16 +112,16 @@
for name, value in values.items():
if name == "type":
if value == CONNECTOR:
- self.radioButton1.SetValue(True)
+ self.ConnectorRadioButton.SetValue(True)
elif value == CONTINUATION:
- self.radioButton2.SetValue(True)
+ self.ConnectionRadioButton.SetValue(True)
elif name == "name":
self.ConnectionName.SetValue(value)
self.RefreshPreview()
def GetValues(self):
values = {}
- if self.radioButton1.GetValue():
+ if self.ConnectorRadioButton.GetValue():
values["type"] = CONNECTOR
else:
values["type"] = CONTINUATION
@@ -196,27 +136,22 @@
self.PouElementNames = [element_name.upper() for element_name in element_names]
def OnOK(self, event):
+ message = None
connection_name = self.ConnectionName.GetValue()
if connection_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 not TestIdentifier(connection_name):
- message = wx.MessageDialog(self, _("\"%s\" is not a valid identifier!")%connection_name, _("Error"), wx.OK|wx.ICON_ERROR)
- message.ShowModal()
- message.Destroy()
+ message = _("\"%s\" is not a valid identifier!") % connection_name
elif connection_name.upper() in IEC_KEYWORDS:
- message = wx.MessageDialog(self, _("\"%s\" is a keyword. It can't be used!")%connection_name, _("Error"), wx.OK|wx.ICON_ERROR)
- message.ShowModal()
- message.Destroy()
+ message = _("\"%s\" is a keyword. It can't be used!") % connection_name
elif connection_name.upper() in self.PouNames:
- message = wx.MessageDialog(self, _("\"%s\" pou already exists!")%connection_name, _("Error"), wx.OK|wx.ICON_ERROR)
- message.ShowModal()
- message.Destroy()
+ message = _("\"%s\" pou already exists!") % connection_name
elif connection_name.upper() in self.PouElementNames:
- message = wx.MessageDialog(self, _("\"%s\" element for this pou already exists!")%connection_name, _("Error"), wx.OK|wx.ICON_ERROR)
- message.ShowModal()
- message.Destroy()
+ message = _("\"%s\" element for this pou already exists!") % connection_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)
@@ -232,7 +167,7 @@
dc = wx.ClientDC(self.Preview)
dc.SetFont(self.Preview.GetFont())
dc.Clear()
- if self.radioButton1.GetValue():
+ if self.ConnectorRadioButton.GetValue():
self.Connection = FBD_Connector(self.Preview, CONNECTOR, self.ConnectionName.GetValue())
else:
self.Connection = FBD_Connector(self.Preview, CONTINUATION, self.ConnectionName.GetValue())
@@ -248,4 +183,4 @@
def OnPaint(self, event):
self.RefreshPreview()
- event.Skip()
\ No newline at end of file
+ event.Skip()