Exemplo n.º 1
0
    def _init_Editor(self, parent):
        self.Editor = wx.Panel(parent, style=wx.SUNKEN_BORDER)
        
        self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
        self.MainSizer.AddGrowableCol(0)
        self.MainSizer.AddGrowableRow(1)
        
        top_sizer = wx.BoxSizer(wx.HORIZONTAL)
        self.MainSizer.AddSizer(top_sizer, border=5, 
              flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
        
        derivation_type_label = wx.StaticText(self.Editor, label=_('Derivation Type:'))
        top_sizer.AddWindow(derivation_type_label, border=5, 
              flag=wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT)
        
        self.DerivationType = wx.ComboBox(self.Editor,
              size=wx.Size(200, -1), style=wx.CB_READONLY)
        self.Bind(wx.EVT_COMBOBOX, self.OnDerivationTypeChanged, self.DerivationType)
        top_sizer.AddWindow(self.DerivationType, border=5, flag=wx.GROW|wx.RIGHT)
        
        typeinfos_staticbox = wx.StaticBox(self.Editor, label=_('Type infos:'))
        typeinfos_sizer = wx.StaticBoxSizer(typeinfos_staticbox, wx.HORIZONTAL)
        self.MainSizer.AddSizer(typeinfos_sizer, border=5, 
              flag=wx.GROW|wx.BOTTOM|wx.LEFT|wx.RIGHT)
        
        # Panel for Directly derived data types

        self.DirectlyPanel = wx.Panel(self.Editor, style=wx.TAB_TRAVERSAL)
        typeinfos_sizer.AddWindow(self.DirectlyPanel, 1)
        
        directly_panel_sizer = wx.BoxSizer(wx.HORIZONTAL)
        
        directly_basetype_label = wx.StaticText(self.DirectlyPanel, 
              label=_('Base Type:'))
        directly_panel_sizer.AddWindow(directly_basetype_label, 1, border=5, 
              flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
        
        self.DirectlyBaseType = wx.ComboBox(self.DirectlyPanel, style=wx.CB_READONLY)
        self.Bind(wx.EVT_COMBOBOX, self.OnInfosChanged, self.DirectlyPanel)
        directly_panel_sizer.AddWindow(self.DirectlyBaseType, 1, border=5, 
              flag=wx.GROW|wx.ALL)
        
        directly_initialvalue_label = wx.StaticText(self.DirectlyPanel,
              label=_('Initial Value:'))
        directly_panel_sizer.AddWindow(directly_initialvalue_label, 1, border=5, 
              flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
        
        self.DirectlyInitialValue = wx.TextCtrl(self.DirectlyPanel, 
              style=wx.TAB_TRAVERSAL|wx.TE_PROCESS_ENTER|wx.TE_RICH)
        self.Bind(wx.EVT_TEXT_ENTER, self.OnReturnKeyPressed, self.DirectlyInitialValue)
        directly_panel_sizer.AddWindow(self.DirectlyInitialValue, 1, border=5, 
              flag=wx.ALL)
        
        self.DirectlyPanel.SetSizer(directly_panel_sizer)
        
        # Panel for Subrange data types

        self.SubrangePanel = wx.Panel(self.Editor, style=wx.TAB_TRAVERSAL)
        typeinfos_sizer.AddWindow(self.SubrangePanel, 1)
        
        subrange_panel_sizer = wx.GridSizer(cols=4, hgap=5, rows=3, vgap=0)
        
        subrange_basetype_label = wx.StaticText(self.SubrangePanel,
              label=_('Base Type:'))
        subrange_panel_sizer.AddWindow(subrange_basetype_label, 1, border=5, 
              flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
        
        self.SubrangeBaseType = wx.ComboBox(self.SubrangePanel, style=wx.CB_READONLY)
        self.Bind(wx.EVT_COMBOBOX, self.OnSubrangeBaseTypeChanged, 
              self.SubrangeBaseType)
        subrange_panel_sizer.AddWindow(self.SubrangeBaseType, 1, border=5, 
              flag=wx.GROW|wx.ALL)
        
        subrange_initialvalue_label = wx.StaticText(self.SubrangePanel,
              label=_('Initial Value:'))
        subrange_panel_sizer.AddWindow(subrange_initialvalue_label, 1, border=5, 
              flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
        
        self.SubrangeInitialValue = wx.SpinCtrl(self.SubrangePanel, 
              style=wx.TAB_TRAVERSAL)
        self.Bind(wx.EVT_SPINCTRL, self.OnInfosChanged, self.SubrangeInitialValue)
        subrange_panel_sizer.AddWindow(self.SubrangeInitialValue, 1, border=5, 
              flag=wx.GROW|wx.ALL)
        
        subrange_minimum_label = wx.StaticText(self.SubrangePanel, label=_('Minimum:'))
        subrange_panel_sizer.AddWindow(subrange_minimum_label, 1, border=5, 
              flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
        
        self.SubrangeMinimum = wx.SpinCtrl(self.SubrangePanel, style=wx.TAB_TRAVERSAL)
        self.Bind(wx.EVT_SPINCTRL, self.OnSubrangeMinimumChanged, self.SubrangeMinimum)
        subrange_panel_sizer.AddWindow(self.SubrangeMinimum, 1, border=5, 
              flag=wx.GROW|wx.ALL)
        
        for i in xrange(2):
            subrange_panel_sizer.AddWindow(wx.Size(0, 0), 1)
        
        subrange_maximum_label = wx.StaticText(self.SubrangePanel,
              label=_('Maximum:'))
        subrange_panel_sizer.AddWindow(subrange_maximum_label, 1, border=5, 
              flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
        
        self.SubrangeMaximum = wx.SpinCtrl(self.SubrangePanel, style=wx.TAB_TRAVERSAL)
        self.Bind(wx.EVT_SPINCTRL, self.OnSubrangeMaximumChanged, self.SubrangeMaximum)
        
        subrange_panel_sizer.AddWindow(self.SubrangeMaximum, 1, border=5, 
              flag=wx.GROW|wx.ALL)
        
        self.SubrangePanel.SetSizer(subrange_panel_sizer)
        
        # Panel for Enumerated data types
        
        self.EnumeratedPanel = wx.Panel(self.Editor, style=wx.TAB_TRAVERSAL)
        typeinfos_sizer.AddWindow(self.EnumeratedPanel, 1)
        
        enumerated_panel_sizer = wx.BoxSizer(wx.HORIZONTAL)
        
        self.EnumeratedValues = CustomEditableListBox(self.EnumeratedPanel, 
              label=_("Values:"), style=wx.gizmos.EL_ALLOW_NEW| 
                                        wx.gizmos.EL_ALLOW_EDIT| 
                                        wx.gizmos.EL_ALLOW_DELETE)
        setattr(self.EnumeratedValues, "_OnLabelEndEdit", self.OnEnumeratedValueEndEdit)
        for func in ["_OnAddButton", "_OnDelButton", "_OnUpButton", "_OnDownButton"]:
            setattr(self.EnumeratedValues, func, self.OnEnumeratedValuesChanged)
        enumerated_panel_sizer.AddWindow(self.EnumeratedValues, 1, border=5, 
              flag=wx.GROW|wx.ALL)
        
        enumerated_panel_rightsizer = wx.BoxSizer(wx.HORIZONTAL)
        enumerated_panel_sizer.AddSizer(enumerated_panel_rightsizer, 1)
        
        enumerated_initialvalue_label = wx.StaticText(self.EnumeratedPanel,
              label=_('Initial Value:'))
        enumerated_panel_rightsizer.AddWindow(enumerated_initialvalue_label, 1, 
              border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
        
        self.EnumeratedInitialValue = wx.ComboBox(self.EnumeratedPanel, 
              style=wx.CB_READONLY)
        self.Bind(wx.EVT_COMBOBOX, self.OnInfosChanged, self.EnumeratedInitialValue)
        enumerated_panel_rightsizer.AddWindow(self.EnumeratedInitialValue, 1, 
              border=5, flag=wx.ALL)
        
        self.EnumeratedPanel.SetSizer(enumerated_panel_sizer)
        
        # Panel for Array data types

        self.ArrayPanel = wx.Panel(self.Editor, style=wx.TAB_TRAVERSAL)
        typeinfos_sizer.AddWindow(self.ArrayPanel, 1)
        
        array_panel_sizer = wx.FlexGridSizer(cols=2, hgap=5, rows=2, vgap=0)
        array_panel_sizer.AddGrowableCol(0)
        array_panel_sizer.AddGrowableCol(1)
        array_panel_sizer.AddGrowableRow(1)
        
        array_panel_leftSizer = wx.BoxSizer(wx.HORIZONTAL)
        array_panel_sizer.AddSizer(array_panel_leftSizer, flag=wx.GROW)
        
        array_basetype_label = wx.StaticText(self.ArrayPanel, label=_('Base Type:'))
        array_panel_leftSizer.AddWindow(array_basetype_label, 1, border=5, 
              flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
        
        self.ArrayBaseType = wx.ComboBox(self.ArrayPanel, style=wx.CB_READONLY)
        self.Bind(wx.EVT_COMBOBOX, self.OnInfosChanged, self.ArrayBaseType)
        array_panel_leftSizer.AddWindow(self.ArrayBaseType, 1, border=5, 
              flag=wx.GROW|wx.ALL)
    
        array_panel_rightsizer = wx.BoxSizer(wx.HORIZONTAL)
        array_panel_sizer.AddSizer(array_panel_rightsizer, flag=wx.GROW)
        
        array_initialvalue_label = wx.StaticText(self.ArrayPanel,
              label=_('Initial Value:'))
        array_panel_rightsizer.AddWindow(array_initialvalue_label, 1, border=5, 
              flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
        
        self.ArrayInitialValue = wx.TextCtrl(self.ArrayPanel,
              style=wx.TAB_TRAVERSAL|wx.TE_PROCESS_ENTER|wx.TE_RICH)
        self.Bind(wx.EVT_TEXT_ENTER, self.OnReturnKeyPressed, self.ArrayInitialValue)
        array_panel_rightsizer.AddWindow(self.ArrayInitialValue, 1, border=5, 
              flag=wx.ALL)        
        
        self.ArrayDimensions = CustomEditableListBox(self.ArrayPanel, 
              label=_("Dimensions:"), style=wx.gizmos.EL_ALLOW_NEW|
                                            wx.gizmos.EL_ALLOW_EDIT|
                                            wx.gizmos.EL_ALLOW_DELETE)
        for func in ["_OnLabelEndEdit", "_OnAddButton", "_OnDelButton", 
                     "_OnUpButton", "_OnDownButton"]:
            setattr(self.ArrayDimensions, func, self.OnDimensionsChanged)
        array_panel_sizer.AddWindow(self.ArrayDimensions, 0, border=5, 
              flag=wx.GROW|wx.ALL)
        
        self.ArrayPanel.SetSizer(array_panel_sizer)
        
        # Panel for Structure data types
        
        self.StructurePanel = wx.Panel(self.Editor, style=wx.TAB_TRAVERSAL)
        typeinfos_sizer.AddWindow(self.StructurePanel, 1)
        
        structure_panel_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
        structure_panel_sizer.AddGrowableCol(0)
        structure_panel_sizer.AddGrowableRow(1)
        
        structure_button_sizer = wx.FlexGridSizer(cols=5, hgap=5, rows=1, vgap=0)
        structure_button_sizer.AddGrowableCol(0)
        structure_button_sizer.AddGrowableRow(0)
        structure_panel_sizer.AddSizer(structure_button_sizer, 0, border=5, 
              flag=wx.ALL|wx.GROW)
        
        structure_elements_label = wx.StaticText(self.StructurePanel,
              label=_('Elements :'))
        structure_button_sizer.AddWindow(structure_elements_label, flag=wx.ALIGN_BOTTOM)
        
        for name, bitmap, help in [
                ("StructureAddButton", "add_element", _("Add element")),
                ("StructureDeleteButton", "remove_element", _("Remove element")),
                ("StructureUpButton", "up", _("Move element up")),
                ("StructureDownButton", "down", _("Move element down"))]:
            button = wx.lib.buttons.GenBitmapButton(self.StructurePanel,
                  bitmap=GetBitmap(bitmap), size=wx.Size(28, 28), style=wx.NO_BORDER)
            button.SetToolTipString(help)
            setattr(self, name, button)
            structure_button_sizer.AddWindow(button)
        
        self.StructureElementsGrid = CustomGrid(self.StructurePanel, 
              size=wx.Size(0, 150), style=wx.VSCROLL)
        self.StructureElementsGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, 
              self.OnStructureElementsGridCellChange)
        self.StructureElementsGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, 
              self.OnStructureElementsGridEditorShown)
        structure_panel_sizer.AddWindow(self.StructureElementsGrid, flag=wx.GROW)
        
        self.StructurePanel.SetSizer(structure_panel_sizer)
        
        self.Editor.SetSizer(self.MainSizer)
Exemplo n.º 2
0
    def __init__(self, parent, window, controler, element_type, debug=False):
        wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL)
        
        self.MainSizer = wx.FlexGridSizer(cols=1, hgap=10, rows=2, vgap=0)
        self.MainSizer.AddGrowableCol(0)
        self.MainSizer.AddGrowableRow(1)
        
        controls_sizer = wx.FlexGridSizer(cols=10, hgap=5, rows=1, vgap=5)
        controls_sizer.AddGrowableCol(5)
        controls_sizer.AddGrowableRow(0)
        self.MainSizer.AddSizer(controls_sizer, border=5, flag=wx.GROW|wx.ALL)
        
        self.ReturnTypeLabel = wx.StaticText(self, label=_('Return Type:'))
        controls_sizer.AddWindow(self.ReturnTypeLabel, flag=wx.ALIGN_CENTER_VERTICAL)
        
        self.ReturnType = wx.ComboBox(self,
              size=wx.Size(145, -1), style=wx.CB_READONLY)
        self.Bind(wx.EVT_COMBOBOX, self.OnReturnTypeChanged, self.ReturnType)
        controls_sizer.AddWindow(self.ReturnType)
        
        self.DescriptionLabel = wx.StaticText(self, label=_('Description:'))
        controls_sizer.AddWindow(self.DescriptionLabel, flag=wx.ALIGN_CENTER_VERTICAL)
        
        self.Description = wx.TextCtrl(self,
              size=wx.Size(250, -1), style=wx.TE_PROCESS_ENTER)
        self.Bind(wx.EVT_TEXT_ENTER, self.OnDescriptionChanged, self.Description)
        self.Description.Bind(wx.EVT_KILL_FOCUS, self.OnDescriptionChanged)
        controls_sizer.AddWindow(self.Description) 
        
        class_filter_label = wx.StaticText(self, label=_('Class Filter:'))
        controls_sizer.AddWindow(class_filter_label, flag=wx.ALIGN_CENTER_VERTICAL)
        
        self.ClassFilter = wx.ComboBox(self, 
              size=wx.Size(145, -1), style=wx.CB_READONLY)
        self.Bind(wx.EVT_COMBOBOX, self.OnClassFilter, self.ClassFilter)
        controls_sizer.AddWindow(self.ClassFilter)
        
        for name, bitmap, help in [
                ("AddButton", "add_element", _("Add variable")),
                ("DeleteButton", "remove_element", _("Remove variable")),
                ("UpButton", "up", _("Move variable up")),
                ("DownButton", "down", _("Move variable down"))]:
            button = wx.lib.buttons.GenBitmapButton(self, bitmap=GetBitmap(bitmap), 
                  size=wx.Size(28, 28), style=wx.NO_BORDER)
            button.SetToolTipString(help)
            setattr(self, name, button)
            controls_sizer.AddWindow(button)
        
        self.VariablesGrid = CustomGrid(self, style=wx.VSCROLL)
        self.VariablesGrid.SetDropTarget(VariableDropTarget(self))
        self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, 
              self.OnVariablesGridCellChange)
        self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, 
              self.OnVariablesGridCellLeftClick)
        self.VariablesGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, 
              self.OnVariablesGridEditorShown)
        self.MainSizer.AddWindow(self.VariablesGrid, flag=wx.GROW)
        
        self.SetSizer(self.MainSizer)
        
        self.ParentWindow = window
        self.Controler = controler
        self.ElementType = element_type
        self.Debug = debug
        
        self.RefreshHighlightsTimer = wx.Timer(self, -1)
        self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, 
              self.RefreshHighlightsTimer)
        
        self.Filter = "All"
        self.FilterChoices = []
        self.FilterChoiceTransfer = GetFilterChoiceTransfer()
        
        self.DefaultValue = {
             "Name" : "", 
             "Class" : "", 
             "Type" : "INT", 
             "Location" : "",
              "Initial Value" : "", 
              "Option" : "",
              "Documentation" : "", 
              "Edit" : True
        }

        if element_type in ["config", "resource"]:
            self.DefaultTypes = {"All" : "Global"}
        else:
            self.DefaultTypes = {"All" : "Local", "Interface" : "Input", "Variables" : "Local"}

        if element_type in ["config", "resource"] \
        or element_type in ["program", "transition", "action"]:
            # this is an element that can have located variables
            self.Table = VariableTable(self, [], GetVariableTableColnames(True))

            if element_type in ["config", "resource"]:
                self.FilterChoices = ["All", "Global"]#,"Access"]
            else:
                self.FilterChoices = ["All",
                                        "Interface", "   Input", "   Output", "   InOut", "   External",
                                        "Variables", "   Local", "   Temp"]#,"Access"]

            # these condense the ColAlignements list
            l = wx.ALIGN_LEFT
            c = wx.ALIGN_CENTER 

            #                      Num  Name    Class   Type    Loc     Init    Option   Doc
            self.ColSizes       = [40,  80,     70,     80,     80,     80,     100,     80]
            self.ColAlignements = [c,   l,      l,      l,      l,      l,      l,       l]

        else:
            # this is an element that cannot have located variables
            self.Table = VariableTable(self, [], GetVariableTableColnames(False))

            if element_type == "function":
                self.FilterChoices = ["All",
                                        "Interface", "   Input", "   Output", "   InOut",
                                        "Variables", "   Local"]
            else:
                self.FilterChoices = ["All",
                                        "Interface", "   Input", "   Output", "   InOut", "   External",
                                        "Variables", "   Local", "   Temp"]

            # these condense the ColAlignements list
            l = wx.ALIGN_LEFT
            c = wx.ALIGN_CENTER 

            #                      Num  Name    Class   Type    Init    Option   Doc
            self.ColSizes       = [40,  80,     70,     80,     80,     100,     160]
            self.ColAlignements = [c,   l,      l,      l,      l,      l,       l]

        for choice in self.FilterChoices:
            self.ClassFilter.Append(_(choice))

        reverse_transfer = {}
        for filter, choice in self.FilterChoiceTransfer.items():
            reverse_transfer[choice] = filter
        self.ClassFilter.SetStringSelection(_(reverse_transfer[self.Filter]))
        self.RefreshTypeList()

        self.VariablesGrid.SetTable(self.Table)
        self.VariablesGrid.SetButtons({"Add": self.AddButton,
                                       "Delete": self.DeleteButton,
                                       "Up": self.UpButton,
                                       "Down": self.DownButton})
        self.VariablesGrid.SetEditable(not self.Debug)
        
        def _AddVariable(new_row):
            if not self.PouIsUsed or self.Filter not in ["Interface", "Input", "Output", "InOut"]:
                row_content = self.DefaultValue.copy()
                if self.Filter in self.DefaultTypes:
                    row_content["Class"] = self.DefaultTypes[self.Filter]
                else:
                    row_content["Class"] = self.Filter
                if self.Filter == "All" and len(self.Values) > 0:
                    self.Values.insert(new_row, row_content)
                else:
                    self.Values.append(row_content)
                    new_row = self.Table.GetNumberRows()
                self.SaveValues()
                self.RefreshValues()
                return new_row
            return self.VariablesGrid.GetGridCursorRow()
        setattr(self.VariablesGrid, "_AddRow", _AddVariable)
        
        def _DeleteVariable(row):
            if (self.Table.GetValueByName(row, "Edit") and 
                (not self.PouIsUsed or self.Table.GetValueByName(row, "Class") not in ["Input", "Output", "InOut"])):
                self.Values.remove(self.Table.GetRow(row))
                self.SaveValues()
                self.RefreshValues()
        setattr(self.VariablesGrid, "_DeleteRow", _DeleteVariable)
            
        def _MoveVariable(row, move):
            if (self.Filter == "All" and 
                (not self.PouIsUsed or self.Table.GetValueByName(row, "Class") not in ["Input", "Output", "InOut"])):
                new_row = max(0, min(row + move, len(self.Values) - 1))
                if new_row != row:
                    self.Values.insert(new_row, self.Values.pop(row))
                    self.SaveValues()
                    self.RefreshValues()
                return new_row
            return row
        setattr(self.VariablesGrid, "_MoveRow", _MoveVariable)
        
        def _RefreshButtons():
            if self:
                table_length = len(self.Table.data)
                row_class = None
                row_edit = True
                row = 0
                if table_length > 0:
                    row = self.VariablesGrid.GetGridCursorRow()
                    row_edit = self.Table.GetValueByName(row, "Edit")
                    if self.PouIsUsed:
                        row_class = self.Table.GetValueByName(row, "Class")
                self.AddButton.Enable(not self.Debug and (not self.PouIsUsed or self.Filter not in ["Interface", "Input", "Output", "InOut"]))
                self.DeleteButton.Enable(not self.Debug and (table_length > 0 and row_edit and row_class not in ["Input", "Output", "InOut"]))
                self.UpButton.Enable(not self.Debug and (table_length > 0 and row > 0 and self.Filter == "All" and row_class not in ["Input", "Output", "InOut"]))
                self.DownButton.Enable(not self.Debug and (table_length > 0 and row < table_length - 1 and self.Filter == "All" and row_class not in ["Input", "Output", "InOut"]))
        setattr(self.VariablesGrid, "RefreshButtons", _RefreshButtons)
        
        self.VariablesGrid.SetRowLabelSize(0)
        for col in range(self.Table.GetNumberCols()):
            attr = wx.grid.GridCellAttr()
            attr.SetAlignment(self.ColAlignements[col], wx.ALIGN_CENTRE)
            self.VariablesGrid.SetColAttr(col, attr)
            self.VariablesGrid.SetColMinimalWidth(col, self.ColSizes[col])
            self.VariablesGrid.AutoSizeColumn(col, False)
 def __init__(self, parent, window, controller, debug):
     wx.Panel.__init__(self, name='PouInstanceTreePanel', 
             parent=parent, pos=wx.Point(0, 0), 
             size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
     
     self.ParentButton = wx.lib.buttons.GenBitmapButton(self,
           bitmap=GetBitmap("top"), size=wx.Size(28, 28), style=wx.NO_BORDER)
     self.ParentButton.SetToolTipString(_("Parent instance"))
     self.Bind(wx.EVT_BUTTON, self.OnParentButtonClick, 
             self.ParentButton)
     
     self.InstanceChoice = wx.ComboBox(self, style=wx.CB_READONLY)
     self.Bind(wx.EVT_COMBOBOX, self.OnInstanceChoiceChanged,
             self.InstanceChoice)
     self.InstanceChoice.Bind(wx.EVT_LEFT_DOWN, self.OnInstanceChoiceLeftDown)
     
     self.DebugButton = wx.lib.buttons.GenBitmapButton(self, 
           bitmap=GetBitmap("debug_instance"), size=wx.Size(28, 28), style=wx.NO_BORDER)
     self.ParentButton.SetToolTipString(_("Debug instance"))
     self.Bind(wx.EVT_BUTTON, self.OnDebugButtonClick, 
             self.DebugButton)
     
     self.VariablesList = CT.CustomTreeCtrl(self,
           style=wx.SUNKEN_BORDER,
           agwStyle=CT.TR_NO_BUTTONS|
                    CT.TR_SINGLE|
                    CT.TR_HAS_VARIABLE_ROW_HEIGHT|
                    CT.TR_HIDE_ROOT|
                    CT.TR_NO_LINES|
                    getattr(CT, "TR_ALIGN_WINDOWS_RIGHT", CT.TR_ALIGN_WINDOWS))
     self.VariablesList.SetIndent(0)
     self.VariablesList.SetSpacing(5)
     self.VariablesList.DoSelectItem = lambda *x,**y:True
     self.VariablesList.Bind(CT.EVT_TREE_ITEM_ACTIVATED,
             self.OnVariablesListItemActivated)
     self.VariablesList.Bind(wx.EVT_LEFT_DOWN, self.OnVariablesListLeftDown)
     
     buttons_sizer = wx.FlexGridSizer(cols=3, hgap=0, rows=1, vgap=0)
     buttons_sizer.AddWindow(self.ParentButton)
     buttons_sizer.AddWindow(self.InstanceChoice, flag=wx.GROW)
     buttons_sizer.AddWindow(self.DebugButton)
     buttons_sizer.AddGrowableCol(1)
     buttons_sizer.AddGrowableRow(0)
     
     main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
     main_sizer.AddSizer(buttons_sizer, flag=wx.GROW)
     main_sizer.AddWindow(self.VariablesList, flag=wx.GROW)
     main_sizer.AddGrowableCol(0)
     main_sizer.AddGrowableRow(1)
     
     self.SetSizer(main_sizer)
     
     self.ParentWindow = window
     self.Controller = controller
     self.Debug = debug
     if not self.Debug:
         self.DebugButton.Hide()
     
     self.PouTagName = None
     self.PouInfos = None
     self.PouInstance = None
 def RefreshView(self):
     self.VariablesList.DeleteAllItems()
     self.InstanceChoice.Clear()
     self.InstanceChoice.SetValue("")
     
     if self.Controller is not None and self.PouTagName is not None:
         self.PouInfos = self.Controller.GetPouVariables(self.PouTagName, self.Debug)
     else:
         self.PouInfos = None
     if self.PouInfos is not None:
         root = self.VariablesList.AddRoot("")
         for var_infos in self.PouInfos["variables"]:
             if var_infos.get("type", None) is not None:
                 text = "%(name)s (%(type)s)" % var_infos
             else:
                 text = var_infos["name"]
             
             panel = wx.Panel(self.VariablesList)
                 
             buttons = []
             if var_infos["class"] in ITEMS_VARIABLE:
                 if (var_infos["debug"] and self.Debug and
                     (self.Controller.IsOfType(var_infos["type"], "ANY_NUM", True) or
                      self.Controller.IsOfType(var_infos["type"], "ANY_BIT", True))):
                     graph_button = wx.lib.buttons.GenBitmapButton(panel, 
                           bitmap=GetBitmap("instance_graph"), 
                           size=wx.Size(28, 28), style=wx.NO_BORDER)
                     self.Bind(wx.EVT_BUTTON, self.GenGraphButtonCallback(var_infos), graph_button)
                     buttons.append(graph_button)
             elif var_infos["edit"]:
                 edit_button = wx.lib.buttons.GenBitmapButton(panel, 
                       bitmap=GetBitmap("edit"), 
                       size=wx.Size(28, 28), style=wx.NO_BORDER)
                 self.Bind(wx.EVT_BUTTON, self.GenEditButtonCallback(var_infos), edit_button)
                 buttons.append(edit_button)
             
             if var_infos["debug"] and self.Debug:
                 debug_button = wx.lib.buttons.GenBitmapButton(panel, 
                       bitmap=GetBitmap("debug_instance"), 
                       size=wx.Size(28, 28), style=wx.NO_BORDER)
                 self.Bind(wx.EVT_BUTTON, self.GenDebugButtonCallback(var_infos), debug_button)
                 buttons.append(debug_button)
             
             button_num = len(buttons)
             if button_num > 0:
                 panel.SetSize(wx.Size(button_num * 32, 28))
                 panel.SetBackgroundColour(self.VariablesList.GetBackgroundColour())
                 panel_sizer = wx.BoxSizer(wx.HORIZONTAL)
                 panel.SetSizer(panel_sizer)
                 
                 for button in buttons:
                     panel_sizer.AddWindow(button, 0, border=4, flag=wx.LEFT)
                 panel_sizer.Layout()
                 
             else:
                 panel.Destroy()
                 panel = None
             
             item = self.VariablesList.AppendItem(root, text, wnd=panel)
             self.VariablesList.SetItemImage(item, self.ParentWindow.GetTreeImage(var_infos["class"]))
             self.VariablesList.SetPyData(item, var_infos)
         
         instances = self.Controller.SearchPouInstances(self.PouTagName, self.Debug)
         for instance in instances:
             self.InstanceChoice.Append(instance)
         if len(instances) == 1:
             self.PouInstance = instances[0]
         if self.PouInfos["class"] in [ITEM_CONFIGURATION, ITEM_RESOURCE]:
             self.PouInstance = None
             self.InstanceChoice.SetSelection(0)
         elif self.PouInstance in instances:
             self.InstanceChoice.SetStringSelection(self.PouInstance)
         else:
             self.PouInstance = None
             self.InstanceChoice.SetValue(_("Select an instance"))
     
     self.RefreshButtons()
Exemplo n.º 5
0
    def __init__(self, parent, producer):
        wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL)
        DebugViewer.__init__(self, producer, True)

        main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
        main_sizer.AddGrowableCol(0)
        main_sizer.AddGrowableRow(1)

        button_sizer = wx.BoxSizer(wx.HORIZONTAL)
        main_sizer.AddSizer(button_sizer,
                            border=5,
                            flag=wx.ALIGN_RIGHT | wx.ALL)

        for name, bitmap, help in [
            ("DeleteButton", "remove_element", _("Remove debug variable")),
            ("UpButton", "up", _("Move debug variable up")),
            ("DownButton", "down", _("Move debug variable down"))
        ]:
            button = wx.lib.buttons.GenBitmapButton(self,
                                                    bitmap=GetBitmap(bitmap),
                                                    size=wx.Size(28, 28),
                                                    style=wx.NO_BORDER)
            button.SetToolTipString(help)
            setattr(self, name, button)
            button_sizer.AddWindow(button, border=5, flag=wx.LEFT)

        self.VariablesGrid = CustomGrid(self,
                                        size=wx.Size(0, 150),
                                        style=wx.VSCROLL)
        self.VariablesGrid.SetDropTarget(DebugVariableDropTarget(self))
        self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK,
                                self.OnVariablesGridCellRightClick)
        main_sizer.AddWindow(self.VariablesGrid, flag=wx.GROW)

        self.SetSizer(main_sizer)

        self.HasNewData = False

        self.Table = DebugVariableTable(self, [],
                                        GetDebugVariablesTableColnames())
        self.VariablesGrid.SetTable(self.Table)
        self.VariablesGrid.SetButtons({
            "Delete": self.DeleteButton,
            "Up": self.UpButton,
            "Down": self.DownButton
        })

        def _AddVariable(new_row):
            return self.VariablesGrid.GetGridCursorRow()

        setattr(self.VariablesGrid, "_AddRow", _AddVariable)

        def _DeleteVariable(row):
            item = self.Table.GetItem(row)
            self.RemoveDataConsumer(item)
            self.Table.RemoveItem(row)
            self.RefreshGrid()

        setattr(self.VariablesGrid, "_DeleteRow", _DeleteVariable)

        def _MoveVariable(row, move):
            new_row = max(0, min(row + move, self.Table.GetNumberRows() - 1))
            if new_row != row:
                self.Table.MoveItem(row, new_row)
                self.RefreshGrid()
            return new_row

        setattr(self.VariablesGrid, "_MoveRow", _MoveVariable)

        self.VariablesGrid.SetRowLabelSize(0)

        for col in range(self.Table.GetNumberCols()):
            attr = wx.grid.GridCellAttr()
            attr.SetAlignment(wx.ALIGN_RIGHT, wx.ALIGN_CENTER)
            self.VariablesGrid.SetColAttr(col, attr)
            self.VariablesGrid.SetColSize(col, 100)

        self.Table.ResetView(self.VariablesGrid)
        self.VariablesGrid.RefreshButtons()
Exemplo n.º 6
0
    def _init_Editor(self, prnt):
        self.Editor = wx.Panel(prnt)

        main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
        main_sizer.AddGrowableCol(0)
        main_sizer.AddGrowableRow(0)

        self.Canvas = plot.PlotCanvas(self.Editor, name='Canvas')

        def _axisInterval(spec, lower, upper):
            if spec == 'border':
                if lower == upper:
                    return lower - 0.5, upper + 0.5
                else:
                    border = (upper - lower) * 0.05
                    return lower - border, upper + border
            else:
                return plot.PlotCanvas._axisInterval(self.Canvas, spec, lower,
                                                     upper)

        self.Canvas._axisInterval = _axisInterval
        self.Canvas.SetYSpec('border')
        self.Canvas.canvas.Bind(wx.EVT_LEFT_DOWN, self.OnCanvasLeftDown)
        self.Canvas.canvas.Bind(wx.EVT_LEFT_UP, self.OnCanvasLeftUp)
        self.Canvas.canvas.Bind(wx.EVT_MIDDLE_DOWN, self.OnCanvasMiddleDown)
        self.Canvas.canvas.Bind(wx.EVT_MIDDLE_UP, self.OnCanvasMiddleUp)
        self.Canvas.canvas.Bind(wx.EVT_MOTION, self.OnCanvasMotion)
        self.Canvas.canvas.Bind(wx.EVT_SIZE, self.OnCanvasResize)
        main_sizer.AddWindow(self.Canvas, 0, border=0, flag=wx.GROW)

        range_sizer = wx.FlexGridSizer(cols=10, hgap=5, rows=1, vgap=0)
        range_sizer.AddGrowableCol(5)
        range_sizer.AddGrowableRow(0)
        main_sizer.AddSizer(range_sizer, 0, border=5, flag=wx.GROW | wx.ALL)

        range_label = wx.StaticText(self.Editor, label=_('Range:'))
        range_sizer.AddWindow(range_label,
                              0,
                              border=0,
                              flag=wx.ALIGN_CENTER_VERTICAL)

        self.CanvasRange = wx.ComboBox(self.Editor,
                                       size=wx.Size(100, 28),
                                       style=wx.CB_READONLY)
        self.Bind(wx.EVT_COMBOBOX, self.OnRangeChanged, self.CanvasRange)
        range_sizer.AddWindow(self.CanvasRange,
                              0,
                              border=0,
                              flag=wx.ALIGN_CENTER_VERTICAL)

        zoom_label = wx.StaticText(self.Editor, label=_('Zoom:'))
        range_sizer.AddWindow(zoom_label,
                              0,
                              border=0,
                              flag=wx.ALIGN_CENTER_VERTICAL)

        self.CanvasZoom = wx.ComboBox(self.Editor,
                                      size=wx.Size(70, 28),
                                      style=wx.CB_READONLY)
        self.Bind(wx.EVT_COMBOBOX, self.OnZoomChanged, self.CanvasZoom)
        range_sizer.AddWindow(self.CanvasZoom,
                              0,
                              border=0,
                              flag=wx.ALIGN_CENTER_VERTICAL)

        position_label = wx.StaticText(self.Editor, label=_('Position:'))
        range_sizer.AddWindow(position_label,
                              0,
                              border=0,
                              flag=wx.ALIGN_CENTER_VERTICAL)

        self.CanvasPosition = wx.ScrollBar(self.Editor,
                                           size=wx.Size(0, 16),
                                           style=wx.SB_HORIZONTAL)
        self.CanvasPosition.SetScrollbar(0, 10, 100, 10)
        self.CanvasPosition.Bind(wx.EVT_SCROLL_THUMBTRACK,
                                 self.OnPositionChanging, self.CanvasPosition)
        self.CanvasPosition.Bind(wx.EVT_SCROLL_LINEUP, self.OnPositionChanging,
                                 self.CanvasPosition)
        self.CanvasPosition.Bind(wx.EVT_SCROLL_LINEDOWN,
                                 self.OnPositionChanging, self.CanvasPosition)
        self.CanvasPosition.Bind(wx.EVT_SCROLL_PAGEUP, self.OnPositionChanging,
                                 self.CanvasPosition)
        self.CanvasPosition.Bind(wx.EVT_SCROLL_PAGEDOWN,
                                 self.OnPositionChanging, self.CanvasPosition)
        range_sizer.AddWindow(self.CanvasPosition,
                              0,
                              border=5,
                              flag=wx.GROW | wx.ALL)

        self.ResetButton = wx.lib.buttons.GenBitmapButton(
            self.Editor,
            bitmap=GetBitmap("reset"),
            size=wx.Size(28, 28),
            style=wx.NO_BORDER)
        self.ResetButton.SetToolTipString(_("Clear the graph values"))
        self.Bind(wx.EVT_BUTTON, self.OnResetButton, self.ResetButton)
        range_sizer.AddWindow(self.ResetButton, 0, border=0, flag=0)

        self.CurrentButton = wx.lib.buttons.GenBitmapButton(
            self.Editor,
            bitmap=GetBitmap("current"),
            size=wx.Size(28, 28),
            style=wx.NO_BORDER)
        self.CurrentButton.SetToolTipString(_("Go to current value"))
        self.Bind(wx.EVT_BUTTON, self.OnCurrentButton, self.CurrentButton)
        range_sizer.AddWindow(self.CurrentButton, 0, border=0, flag=0)

        self.ResetZoomOffsetButton = wx.lib.buttons.GenBitmapButton(
            self.Editor,
            bitmap=GetBitmap("fit"),
            size=wx.Size(28, 28),
            style=wx.NO_BORDER)
        self.ResetZoomOffsetButton.SetToolTipString(_("Reset zoom and offset"))
        self.Bind(wx.EVT_BUTTON, self.OnResetZoomOffsetButton,
                  self.ResetZoomOffsetButton)
        range_sizer.AddWindow(self.ResetZoomOffsetButton, 0, border=0, flag=0)

        self.ExportGraphButton = wx.lib.buttons.GenBitmapButton(
            self.Editor,
            bitmap=GetBitmap("export_graph"),
            size=wx.Size(28, 28),
            style=wx.NO_BORDER)
        self.ExportGraphButton.SetToolTipString(
            _("Export graph values to clipboard"))
        self.Bind(wx.EVT_BUTTON, self.OnExportGraphButtonClick,
                  self.ExportGraphButton)
        range_sizer.AddWindow(self.ExportGraphButton, 0, border=0, flag=0)

        self.Editor.SetSizer(main_sizer)

        self.Editor.Bind(wx.EVT_MOUSEWHEEL, self.OnCanvasMouseWheel)
    def _init_Editor(self, parent):
        self.Editor = wx.Panel(parent,
                               style=wx.SUNKEN_BORDER | wx.TAB_TRAVERSAL)

        main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
        main_sizer.AddGrowableCol(0)
        main_sizer.AddGrowableRow(0)
        main_sizer.AddGrowableRow(1)

        tasks_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
        tasks_sizer.AddGrowableCol(0)
        tasks_sizer.AddGrowableRow(1)
        main_sizer.AddSizer(tasks_sizer,
                            border=5,
                            flag=wx.GROW | wx.TOP | wx.LEFT | wx.RIGHT)

        tasks_buttons_sizer = wx.FlexGridSizer(cols=5, hgap=5, rows=1, vgap=0)
        tasks_buttons_sizer.AddGrowableCol(0)
        tasks_buttons_sizer.AddGrowableRow(0)
        tasks_sizer.AddSizer(tasks_buttons_sizer, flag=wx.GROW)

        tasks_label = wx.StaticText(self.Editor, label=_(u'Tasks:'))
        tasks_buttons_sizer.AddWindow(tasks_label, flag=wx.ALIGN_BOTTOM)

        for name, bitmap, help in [
            ("AddTaskButton", "add_element", _("Add task")),
            ("DeleteTaskButton", "remove_element", _("Remove task")),
            ("UpTaskButton", "up", _("Move task up")),
            ("DownTaskButton", "down", _("Move task down"))
        ]:
            button = wx.lib.buttons.GenBitmapButton(self.Editor,
                                                    bitmap=GetBitmap(bitmap),
                                                    size=wx.Size(28, 28),
                                                    style=wx.NO_BORDER)
            button.SetToolTipString(help)
            setattr(self, name, button)
            tasks_buttons_sizer.AddWindow(button)

        self.TasksGrid = CustomGrid(self.Editor, style=wx.VSCROLL)
        self.TasksGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE,
                            self.OnTasksGridCellChange)
        tasks_sizer.AddWindow(self.TasksGrid, flag=wx.GROW)

        instances_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
        instances_sizer.AddGrowableCol(0)
        instances_sizer.AddGrowableRow(1)
        main_sizer.AddSizer(instances_sizer,
                            border=5,
                            flag=wx.GROW | wx.BOTTOM | wx.LEFT | wx.RIGHT)

        instances_buttons_sizer = wx.FlexGridSizer(cols=5,
                                                   hgap=5,
                                                   rows=1,
                                                   vgap=0)
        instances_buttons_sizer.AddGrowableCol(0)
        instances_buttons_sizer.AddGrowableRow(0)
        instances_sizer.AddSizer(instances_buttons_sizer, flag=wx.GROW)

        instances_label = wx.StaticText(self.Editor, label=_(u'Instances:'))
        instances_buttons_sizer.AddWindow(instances_label,
                                          flag=wx.ALIGN_BOTTOM)

        for name, bitmap, help in [
            ("AddInstanceButton", "add_element", _("Add instance")),
            ("DeleteInstanceButton", "remove_element", _("Remove instance")),
            ("UpInstanceButton", "up", _("Move instance up")),
            ("DownInstanceButton", "down", _("Move instance down"))
        ]:
            button = wx.lib.buttons.GenBitmapButton(self.Editor,
                                                    bitmap=GetBitmap(bitmap),
                                                    size=wx.Size(28, 28),
                                                    style=wx.NO_BORDER)
            button.SetToolTipString(help)
            setattr(self, name, button)
            instances_buttons_sizer.AddWindow(button)

        self.InstancesGrid = CustomGrid(self.Editor, style=wx.VSCROLL)
        self.InstancesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE,
                                self.OnInstancesGridCellChange)
        instances_sizer.AddWindow(self.InstancesGrid, flag=wx.GROW)

        self.Editor.SetSizer(main_sizer)