def __init__(self, parent, controller, tagname): """ Constructor @param parent: Parent wx.Window of dialog for modal @param controller: Reference to project controller @param tagname: Tagname of project POU edited """ BlockPreviewDialog.__init__(self, parent, controller, tagname, title=_('Power Rail Properties')) # Init common sizers self._init_sizers(2, 0, 5, None, 2, 1) # Create label for connection type type_label = wx.StaticText(self, label=_('Type:')) self.LeftGridSizer.AddWindow(type_label, flag=wx.GROW) # Create radio buttons for selecting power rail type self.TypeRadioButtons = {} first = True for type, label in [(LEFTRAIL, _('Left PowerRail')), (RIGHTRAIL, _('Right PowerRail'))]: radio_button = wx.RadioButton(self, label=label, style=(wx.RB_GROUP if first else 0)) radio_button.SetValue(first) self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, radio_button) self.LeftGridSizer.AddWindow(radio_button, flag=wx.GROW) self.TypeRadioButtons[type] = radio_button first = False # Create label for power rail pin number pin_number_label = wx.StaticText(self, label=_('Pin number:')) self.LeftGridSizer.AddWindow(pin_number_label, flag=wx.GROW) # Create spin control for defining power rail pin number self.PinNumber = wx.SpinCtrl(self, min=1, max=50, style=wx.SP_ARROW_KEYS) self.PinNumber.SetValue(1) self.Bind(wx.EVT_SPINCTRL, self.OnPinNumberChanged, self.PinNumber) self.LeftGridSizer.AddWindow(self.PinNumber, flag=wx.GROW) # Add preview panel and associated label to sizers self.RightGridSizer.AddWindow(self.PreviewLabel, flag=wx.GROW) self.RightGridSizer.AddWindow(self.Preview, flag=wx.GROW) # Add buttons sizer to sizers self.MainSizer.AddSizer(self.ButtonSizer, border=20, flag=wx.ALIGN_RIGHT | wx.BOTTOM | wx.LEFT | wx.RIGHT) self.Fit() # Left Power Rail radio button is default control having keyboard focus self.TypeRadioButtons[LEFTRAIL].SetFocus()
def __init__(self, parent, controller, tagname): """ Constructor @param parent: Parent wx.Window of dialog for modal @param controller: Reference to project controller @param tagname: Tagname of project POU edited """ BlockPreviewDialog.__init__(self, parent, controller, tagname, title=_('Block Properties')) # Init common sizers self._init_sizers(2, 0, 1, 0, 3, 2) # Create static box around library panel type_staticbox = wx.StaticBox(self, label=_('Type:')) left_staticboxsizer = wx.StaticBoxSizer(type_staticbox, wx.VERTICAL) self.LeftGridSizer.AddSizer(left_staticboxsizer, border=5, flag=wx.GROW) # Create Library panel and add it to static box self.LibraryPanel = LibraryPanel(self) self.LibraryPanel.SetInitialSize(wx.Size(-1, 400)) # Set function to call when selection in Library panel changed setattr(self.LibraryPanel, "_OnTreeItemSelected", self.OnLibraryTreeItemSelected) left_staticboxsizer.AddWindow(self.LibraryPanel, 1, border=5, flag=wx.GROW | wx.TOP) # Create sizer for other block parameters top_right_gridsizer = wx.FlexGridSizer(cols=2, hgap=0, rows=4, vgap=5) top_right_gridsizer.AddGrowableCol(1) self.RightGridSizer.AddSizer(top_right_gridsizer, flag=wx.GROW) # Create label for block name name_label = wx.StaticText(self, label=_('Name:')) top_right_gridsizer.AddWindow(name_label, flag=wx.ALIGN_CENTER_VERTICAL) # Create text control for defining block name self.BlockName = wx.TextCtrl(self) self.Bind(wx.EVT_TEXT, self.OnNameChanged, self.BlockName) top_right_gridsizer.AddWindow(self.BlockName, flag=wx.GROW) # Create label for extended block input number inputs_label = wx.StaticText(self, label=_('Inputs:')) top_right_gridsizer.AddWindow(inputs_label, flag=wx.ALIGN_CENTER_VERTICAL) # Create spin control for defining extended block input number 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) # Create label for block execution order execution_order_label = wx.StaticText(self, label=_('Execution Order:')) top_right_gridsizer.AddWindow(execution_order_label, flag=wx.ALIGN_CENTER_VERTICAL) # Create spin control for defining block execution order 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) # Create label for block execution control execution_control_label = wx.StaticText(self, label=_('Execution Control:')) top_right_gridsizer.AddWindow(execution_control_label, flag=wx.ALIGN_CENTER_VERTICAL) # Create check box to enable block execution control self.ExecutionControl = wx.CheckBox(self) self.Bind(wx.EVT_CHECKBOX, self.OnExecutionOrderChanged, self.ExecutionControl) top_right_gridsizer.AddWindow(self.ExecutionControl, flag=wx.GROW) # Add preview panel and associated label to sizers self.RightGridSizer.AddWindow(self.PreviewLabel, flag=wx.GROW) self.RightGridSizer.AddWindow(self.Preview, flag=wx.GROW) # Add buttons sizer to sizers self.MainSizer.AddSizer(self.ButtonSizer, border=20, flag=wx.ALIGN_RIGHT | wx.BOTTOM | wx.LEFT | wx.RIGHT) # Dictionary containing correspondence between parameter exchanged and # control to fill with parameter value self.ParamsControl = { "extension": self.Inputs, "executionOrder": self.ExecutionOrder, "executionControl": self.ExecutionControl } # Init controls value and sensibility self.BlockName.SetValue("") self.BlockName.Enable(False) self.Inputs.Enable(False) # Variable containing last name typed self.CurrentBlockName = None # Refresh Library panel values self.LibraryPanel.SetBlockList(controller.GetBlockTypes(tagname)) self.Fit() self.LibraryPanel.SetFocus()
def __init__(self, parent, controller, tagname, type): """ Constructor @param parent: Parent wx.Window of dialog for modal @param controller: Reference to project controller @param tagname: Tagname of project POU edited @param type: Type of LD element ('contact or 'coil') """ BlockPreviewDialog.__init__( self, parent, controller, tagname, title=(_("Edit Contact Values") if type == "contact" else _("Edit Coil Values"))) # Init common sizers self._init_sizers(2, 0, (7 if type == "contact" else 9), None, 2, 1) # Create label for LD element modifier modifier_label = wx.StaticText(self, label=_('Modifier:')) self.LeftGridSizer.AddWindow(modifier_label, border=5, flag=wx.GROW | wx.BOTTOM) # Create radio buttons for selecting LD element modifier self.ModifierRadioButtons = {} first = True element_modifiers = ([ CONTACT_NORMAL, CONTACT_REVERSE, CONTACT_RISING, CONTACT_FALLING ] if type == "contact" else [ COIL_NORMAL, COIL_REVERSE, COIL_SET, COIL_RESET, COIL_RISING, COIL_FALLING ]) modifiers_label = \ [_("Normal"), _("Negated")] + \ ([_("Set"), _("Reset")] if type == "coil" else []) + \ [_("Rising Edge"), _("Falling Edge")] for modifier, label in zip(element_modifiers, modifiers_label): radio_button = wx.RadioButton(self, label=label, style=(wx.RB_GROUP if first else 0)) radio_button.SetValue(first) self.Bind(wx.EVT_RADIOBUTTON, self.OnModifierChanged, radio_button) self.LeftGridSizer.AddWindow(radio_button, flag=wx.GROW) self.ModifierRadioButtons[modifier] = radio_button first = False # Create label for LD element variable element_variable_label = wx.StaticText(self, label=_('Variable:')) self.LeftGridSizer.AddWindow(element_variable_label, border=5, flag=wx.GROW | wx.TOP) # Create a combo box for defining LD element variable self.ElementVariable = wx.ComboBox(self, style=wx.CB_SORT) self.Bind(wx.EVT_COMBOBOX, self.OnVariableChanged, self.ElementVariable) self.Bind(wx.EVT_TEXT, self.OnVariableChanged, self.ElementVariable) self.LeftGridSizer.AddWindow(self.ElementVariable, border=5, flag=wx.GROW | wx.TOP) # Add preview panel and associated label to sizers self.RightGridSizer.AddWindow(self.PreviewLabel, flag=wx.GROW) self.RightGridSizer.AddWindow(self.Preview, flag=wx.GROW) # Add buttons sizer to sizers self.MainSizer.AddSizer(self.ButtonSizer, border=20, flag=wx.ALIGN_RIGHT | wx.BOTTOM | wx.LEFT | wx.RIGHT) # Save LD element class self.ElementClass = (LD_Contact if type == "contact" else LD_Coil) # Extract list of variables defined in POU self.RefreshVariableList() # Set values in ElementVariable for name, (var_type, value_type) in self.VariableList.iteritems(): # Only select BOOL variable and avoid input for coil if (type == "contact" or var_type != "Input") and \ value_type == "BOOL": self.ElementVariable.Append(name) self.Fit() # Normal radio button is default control having keyboard focus self.ModifierRadioButtons[element_modifiers[0]].SetFocus()
def __init__(self, parent, controller, tagname, poss_div_types=None): """ Constructor @param parent: Parent wx.Window of dialog for modal @param controller: Reference to project controller @param tagname: Tagname of project POU edited @param poss_div_types: Types of divergence that will be available in the dialog window """ BlockPreviewDialog.__init__( self, parent, controller, tagname, title=_('Create a new divergence or convergence')) # Init common sizers self._init_sizers(2, 0, 7, None, 2, 1) # Create label for divergence type type_label = wx.StaticText(self, label=_('Type:')) self.LeftGridSizer.AddWindow(type_label, flag=wx.GROW) # Create radio buttons for selecting divergence type divergence_buttons = [ (SELECTION_DIVERGENCE, _('Selection Divergence')), (SELECTION_CONVERGENCE, _('Selection Convergence')), (SIMULTANEOUS_DIVERGENCE, _('Simultaneous Divergence')), (SIMULTANEOUS_CONVERGENCE, _('Simultaneous Convergence')) ] poss_div_btns = [] if poss_div_types is not None: for val in poss_div_types: poss_div_btns.append(divergence_buttons[val]) else: poss_div_btns = divergence_buttons self.TypeRadioButtons = {} first = True focusbtn = None for type, label in poss_div_btns: radio_button = wx.RadioButton(self, label=label, style=(wx.RB_GROUP if first else 0)) radio_button.SetValue(first) self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, radio_button) self.LeftGridSizer.AddWindow(radio_button, flag=wx.GROW) self.TypeRadioButtons[type] = radio_button if first: focusbtn = type first = False # Create label for number of divergence sequences sequences_label = wx.StaticText(self, label=_('Number of sequences:')) self.LeftGridSizer.AddWindow(sequences_label, flag=wx.GROW) # Create spin control for defining number of divergence sequences self.Sequences = wx.SpinCtrl(self, min=2, max=20, initial=2) self.Bind(wx.EVT_SPINCTRL, self.OnSequencesChanged, self.Sequences) self.LeftGridSizer.AddWindow(self.Sequences, flag=wx.GROW) # Add preview panel and associated label to sizers self.RightGridSizer.AddWindow(self.PreviewLabel, flag=wx.GROW) self.RightGridSizer.AddWindow(self.Preview, flag=wx.GROW) # Add buttons sizer to sizers self.MainSizer.AddSizer(self.ButtonSizer, border=20, flag=wx.ALIGN_RIGHT | wx.BOTTOM | wx.LEFT | wx.RIGHT) self.Fit() # Selection divergence radio button is default control having keyboard # focus self.TypeRadioButtons[focusbtn].SetFocus()
def __init__(self, parent, controller, tagname, initial=False): """ Constructor @param parent: Parent wx.Window of dialog for modal @param controller: Reference to project controller @param tagname: Tagname of project POU edited @param initial: True if step is initial (default: False) """ BlockPreviewDialog.__init__(self, parent, controller, tagname, title=_('Edit Step')) # Init common sizers self._init_sizers(2, 0, 6, None, 2, 1) # Create label for SFC step name name_label = wx.StaticText(self, label=_('Name:')) self.LeftGridSizer.AddWindow(name_label, flag=wx.GROW) # Create text control for defining SFC step name self.StepName = wx.TextCtrl(self) self.Bind(wx.EVT_TEXT, self.OnNameChanged, self.StepName) self.LeftGridSizer.AddWindow(self.StepName, flag=wx.GROW) # Create label for SFC step connectors connectors_label = wx.StaticText(self, label=_('Connectors:')) self.LeftGridSizer.AddWindow(connectors_label, flag=wx.GROW) # Create check boxes for defining connectors available on SFC step self.ConnectorsCheckBox = {} for name, label in [("input", _("Input")), ("output", _("Output")), ("action", _("Action"))]: check_box = wx.CheckBox(self, label=label) if name == "output" or (name == "input" and not initial): check_box.SetValue(True) self.Bind(wx.EVT_CHECKBOX, self.OnConnectorsChanged, check_box) self.LeftGridSizer.AddWindow(check_box, flag=wx.GROW) self.ConnectorsCheckBox[name] = check_box # Add preview panel and associated label to sizers self.RightGridSizer.AddWindow(self.PreviewLabel, flag=wx.GROW) self.RightGridSizer.AddWindow(self.Preview, flag=wx.GROW) # Add buttons sizer to sizers self.MainSizer.AddSizer(self.ButtonSizer, border=20, flag=wx.ALIGN_RIGHT | wx.BOTTOM | wx.LEFT | wx.RIGHT) # Save flag that indicates that step is initial self.Initial = initial # Set default name for step self.StepName.ChangeValue( controller.GenerateNewName(tagname, None, "Step%d", 0)) self.Fit() # Step name text control is default control having keyboard focus self.StepName.SetFocus()
def __init__(self, parent, controller, tagname, connection=True): """ Constructor @param parent: Parent wx.Window of dialog for modal @param controller: Reference to project controller @param tagname: Tagname of project POU edited @param connection: True if transition value can be defined by a connection (default: True) """ BlockPreviewDialog.__init__(self, parent, controller, tagname, title=_('Edit transition')) # Init common sizers self._init_sizers(2, 0, 8, None, 2, 1) # Create label for transition type type_label = wx.StaticText(self, label=_('Type:')) self.LeftGridSizer.AddWindow(type_label, flag=wx.GROW) # Create combo box for selecting reference value reference = wx.ComboBox(self, style=wx.CB_READONLY) reference.Append("") for transition in controller.GetEditedElementTransitions(tagname): reference.Append(transition) self.Bind(wx.EVT_COMBOBOX, self.OnReferenceChanged, reference) # Create Text control for defining inline value inline = wx.TextCtrl(self) self.Bind(wx.EVT_TEXT, self.OnInlineChanged, inline) # Create radio buttons for selecting power rail type self.TypeRadioButtons = {} first = True for type, label, control in [('reference', _('Reference'), reference), ('inline', _('Inline'), inline), ('connection', _('Connection'), None)]: radio_button = wx.RadioButton(self, label=label, style=(wx.RB_GROUP if first else 0)) radio_button.SetValue(first) self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, radio_button) self.LeftGridSizer.AddWindow(radio_button, flag=wx.GROW) if control is not None: control.Enable(first) self.LeftGridSizer.AddWindow(control, flag=wx.GROW) self.TypeRadioButtons[type] = (radio_button, control) first = False # Create label for transition priority priority_label = wx.StaticText(self, label=_('Priority:')) self.LeftGridSizer.AddWindow(priority_label, flag=wx.GROW) # Create spin control for defining priority value self.Priority = wx.SpinCtrl(self, min=0, style=wx.SP_ARROW_KEYS) self.Bind(wx.EVT_TEXT, self.OnPriorityChanged, self.Priority) self.LeftGridSizer.AddWindow(self.Priority, flag=wx.GROW) # Add preview panel and associated label to sizers self.RightGridSizer.AddWindow(self.PreviewLabel, flag=wx.GROW) self.RightGridSizer.AddWindow(self.Preview, flag=wx.GROW) # Add buttons sizer to sizers self.MainSizer.AddSizer(self.ButtonSizer, border=20, flag=wx.ALIGN_RIGHT | wx.BOTTOM | wx.LEFT | wx.RIGHT) self.Fit() # Reference radio button is default control having keyboard focus self.TypeRadioButtons["reference"][0].SetFocus()
def __init__(self, parent, controller, tagname, exclude_input=False): """ Constructor @param parent: Parent wx.Window of dialog for modal @param controller: Reference to project controller @param tagname: Tagname of project POU edited @param exclude_input: Exclude input from variable class selection """ BlockPreviewDialog.__init__(self, parent, controller, tagname, title=_('Variable Properties')) # Dictionaries containing correspondence between variable block class and string # to be shown in Class combo box in both sense self.VARIABLE_CLASSES_DICT = { INPUT: _("Input"), INOUT: _("InOut"), OUTPUT: _("Output") } self.VARIABLE_CLASSES_DICT_REVERSE = dict([ (value, key) for key, value in self.VARIABLE_CLASSES_DICT.items() ]) # Init common sizers self._init_sizers(4, 2, 4, None, 3, 2) # Create label for variable class class_label = wx.StaticText(self, label=_('Class:')) self.LeftGridSizer.Add(class_label, flag=wx.GROW) # Create a combo box for defining variable class self.Class = wx.ComboBox(self, style=wx.CB_READONLY) self.Bind(wx.EVT_COMBOBOX, self.OnClassChanged, self.Class) self.LeftGridSizer.Add(self.Class, flag=wx.GROW) # Create label for variable execution order execution_order_label = wx.StaticText(self, label=_('Execution Order:')) self.LeftGridSizer.Add(execution_order_label, flag=wx.GROW) # Create spin control for defining variable execution order self.ExecutionOrder = wx.SpinCtrl(self, min=0, style=wx.SP_ARROW_KEYS) self.Bind(wx.EVT_SPINCTRL, self.OnExecutionOrderChanged, self.ExecutionOrder) self.LeftGridSizer.Add(self.ExecutionOrder, flag=wx.GROW) # Create label for variable expression name_label = wx.StaticText(self, label=_('Expression:')) self.RightGridSizer.Add(name_label, border=5, flag=wx.GROW | wx.BOTTOM) # Create text control for defining variable expression self.Expression = wx.TextCtrl(self) self.Bind(wx.EVT_TEXT, self.OnExpressionChanged, self.Expression) self.RightGridSizer.Add(self.Expression, flag=wx.GROW) # Create a list box to selected variable expression in the list of # variables defined in POU self.VariableName = wx.ListBox(self, size=wx.Size(-1, 120), style=wx.LB_SINGLE | wx.LB_SORT) self.Bind(wx.EVT_LISTBOX, self.OnNameChanged, self.VariableName) self.RightGridSizer.Add(self.VariableName, border=4, flag=wx.GROW | wx.TOP) # Add preview panel and associated label to sizers self.MainSizer.Add(self.PreviewLabel, border=20, flag=wx.GROW | wx.LEFT | wx.RIGHT) self.MainSizer.Add(self.Preview, border=20, flag=wx.GROW | wx.LEFT | wx.RIGHT) # Add buttons sizer to sizers self.MainSizer.Add(self.ButtonSizer, border=20, flag=wx.ALIGN_RIGHT | wx.BOTTOM | wx.LEFT | wx.RIGHT) # Set options that can be selected in class combo box for var_class, choice in self.VARIABLE_CLASSES_DICT.items(): if not exclude_input or var_class != INPUT: self.Class.Append(choice) self.Class.SetSelection(0) # Extract list of variables defined in POU self.RefreshVariableList() # Refresh values in name list box self.RefreshNameList() self.Preview.SetInitialSize(wx.Size(-1, 60)) self.Fit() # Class combo box is default control having keyboard focus self.Class.SetFocus()
def __init__(self, parent, controller, tagname, apply_button=False): """ Constructor @param parent: Parent wx.Window of dialog for modal @param controller: Reference to project controller @param tagname: Tagname of project POU edited @param apply_button: Enable button for applying connector modification to all connector having the same name in POU (default: False) """ BlockPreviewDialog.__init__(self, parent, controller, tagname, title=_('Connection Properties')) # Init common sizers self._init_sizers(2, 0, 7, 1, 0, None) # Create label for connection type type_label = wx.StaticText(self, label=_('Type:')) self.LeftGridSizer.AddWindow(type_label, flag=wx.GROW) # Create radio buttons for selecting connection type self.TypeRadioButtons = {} first = True for type, label in [(CONNECTOR, _('Connector')), (CONTINUATION, _('Continuation'))]: radio_button = wx.RadioButton(self, label=label, style=(wx.RB_GROUP if first else 0)) radio_button.SetValue(first) self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, radio_button) self.LeftGridSizer.AddWindow(radio_button, flag=wx.GROW) self.TypeRadioButtons[type] = radio_button first = False # Create label for connection name name_label = wx.StaticText(self, label=_('Name:')) self.LeftGridSizer.AddWindow(name_label, flag=wx.GROW) # Create text control for defining connection name self.ConnectionName = wx.TextCtrl(self) self.ConnectionName.SetMinSize(wx.Size(200, -1)) self.Bind(wx.EVT_TEXT, self.OnNameChanged, self.ConnectionName) self.LeftGridSizer.AddWindow(self.ConnectionName, flag=wx.GROW) # Add preview panel and associated label to sizers self.Preview.SetMinSize(wx.Size(-1, 100)) self.LeftGridSizer.AddWindow(self.PreviewLabel, flag=wx.GROW) self.LeftGridSizer.AddWindow(self.Preview, flag=wx.GROW) # Add buttons sizer to sizers self.MainSizer.AddSizer(self.ButtonSizer, border=20, flag=wx.ALIGN_RIGHT | wx.BOTTOM | wx.LEFT | wx.RIGHT) self.ColumnSizer.RemoveSizer(self.RightGridSizer) # Add button for applying connection name modification to all connection # of POU if apply_button: self.ApplyToAllButton = wx.Button(self, label=_("Propagate Name")) self.ApplyToAllButton.SetToolTipString( _("Apply name modification to all continuations with the same name" )) self.Bind(wx.EVT_BUTTON, self.OnApplyToAll, self.ApplyToAllButton) self.ButtonSizer.AddWindow(self.ApplyToAllButton, flag=wx.LEFT) else: self.ConnectionName.ChangeValue( controller.GenerateNewName(tagname, None, "Connection%d", 0)) self.Fit() # Connector radio button is default control having keyboard focus self.TypeRadioButtons[CONNECTOR].SetFocus()