25 import wx |
25 import wx |
26 import wx.lib.buttons |
26 import wx.lib.buttons |
27 import wx.lib.agw.customtreectrl as CT |
27 import wx.lib.agw.customtreectrl as CT |
28 |
28 |
29 from PLCControler import ITEMS_VARIABLE, ITEM_CONFIGURATION, ITEM_RESOURCE, ITEM_POU |
29 from PLCControler import ITEMS_VARIABLE, ITEM_CONFIGURATION, ITEM_RESOURCE, ITEM_POU |
|
30 from utils.BitmapLibrary import GetBitmap |
30 |
31 |
31 class PouInstanceVariablesPanel(wx.Panel): |
32 class PouInstanceVariablesPanel(wx.Panel): |
32 |
33 |
33 def __init__(self, parent, window, controller, debug): |
34 def __init__(self, parent, window, controller, debug): |
34 wx.Panel.__init__(self, name='PouInstanceTreePanel', |
35 wx.Panel.__init__(self, name='PouInstanceTreePanel', |
35 parent=parent, pos=wx.Point(0, 0), |
36 parent=parent, pos=wx.Point(0, 0), |
36 size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) |
37 size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) |
37 |
38 |
38 self.ParentButton = wx.lib.buttons.GenBitmapButton( |
39 self.ParentButton = wx.lib.buttons.GenBitmapButton(self, |
39 name='ParentButton', parent=self, |
40 bitmap=GetBitmap("top"), size=wx.Size(28, 28), style=wx.NO_BORDER) |
40 bitmap=window.GenerateBitmap("up"), |
41 self.ParentButton.SetToolTipString(_("Parent instance")) |
41 pos=wx.Point(0, 0), size=wx.Size(28, 28), |
|
42 style=wx.NO_BORDER) |
|
43 self.Bind(wx.EVT_BUTTON, self.OnParentButtonClick, |
42 self.Bind(wx.EVT_BUTTON, self.OnParentButtonClick, |
44 self.ParentButton) |
43 self.ParentButton) |
45 |
44 |
46 self.InstanceChoice = wx.ComboBox(name='InstanceChoice', |
45 self.InstanceChoice = wx.ComboBox(self, style=wx.CB_READONLY) |
47 parent=self, pos=wx.Point(0, 0), |
|
48 size=wx.Size(0, 28), style=wx.CB_READONLY) |
|
49 self.Bind(wx.EVT_COMBOBOX, self.OnInstanceChoiceChanged, |
46 self.Bind(wx.EVT_COMBOBOX, self.OnInstanceChoiceChanged, |
50 self.InstanceChoice) |
47 self.InstanceChoice) |
51 self.InstanceChoice.Bind(wx.EVT_LEFT_DOWN, self.OnInstanceChoiceLeftDown) |
48 self.InstanceChoice.Bind(wx.EVT_LEFT_DOWN, self.OnInstanceChoiceLeftDown) |
52 |
49 |
53 self.DebugButton = wx.lib.buttons.GenBitmapButton( |
50 self.DebugButton = wx.lib.buttons.GenBitmapButton(self, |
54 name='DebugButton', parent=self, |
51 bitmap=GetBitmap("debug_instance"), size=wx.Size(28, 28), style=wx.NO_BORDER) |
55 bitmap=window.GenerateBitmap("debug"), |
52 self.ParentButton.SetToolTipString(_("Debug instance")) |
56 pos=wx.Point(0, 0), size=wx.Size(28, 28), |
|
57 style=wx.NO_BORDER) |
|
58 self.Bind(wx.EVT_BUTTON, self.OnDebugButtonClick, |
53 self.Bind(wx.EVT_BUTTON, self.OnDebugButtonClick, |
59 self.DebugButton) |
54 self.DebugButton) |
60 |
55 |
61 self.VariablesList = CT.CustomTreeCtrl( |
56 self.VariablesList = CT.CustomTreeCtrl(self, |
62 name='VariablesList', parent=self, |
|
63 pos=wx.Point(0, 0), size=wx.Size(0, 0), |
|
64 style=wx.SUNKEN_BORDER, |
57 style=wx.SUNKEN_BORDER, |
65 agwStyle=CT.TR_NO_BUTTONS| |
58 agwStyle=CT.TR_NO_BUTTONS| |
66 CT.TR_SINGLE| |
59 CT.TR_SINGLE| |
67 CT.TR_HAS_VARIABLE_ROW_HEIGHT| |
60 CT.TR_HAS_VARIABLE_ROW_HEIGHT| |
68 CT.TR_HIDE_ROOT| |
61 CT.TR_HIDE_ROOT| |
74 self.VariablesList.Bind(CT.EVT_TREE_ITEM_ACTIVATED, |
67 self.VariablesList.Bind(CT.EVT_TREE_ITEM_ACTIVATED, |
75 self.OnVariablesListItemActivated) |
68 self.OnVariablesListItemActivated) |
76 self.VariablesList.Bind(wx.EVT_LEFT_DOWN, self.OnVariablesListLeftDown) |
69 self.VariablesList.Bind(wx.EVT_LEFT_DOWN, self.OnVariablesListLeftDown) |
77 |
70 |
78 buttons_sizer = wx.FlexGridSizer(cols=3, hgap=0, rows=1, vgap=0) |
71 buttons_sizer = wx.FlexGridSizer(cols=3, hgap=0, rows=1, vgap=0) |
79 buttons_sizer.AddWindow(self.ParentButton, 0, border=0, flag=0) |
72 buttons_sizer.AddWindow(self.ParentButton) |
80 buttons_sizer.AddWindow(self.InstanceChoice, 0, border=0, flag=wx.GROW) |
73 buttons_sizer.AddWindow(self.InstanceChoice, flag=wx.GROW) |
81 buttons_sizer.AddWindow(self.DebugButton, 0, border=0, flag=0) |
74 buttons_sizer.AddWindow(self.DebugButton) |
82 buttons_sizer.AddGrowableCol(1) |
75 buttons_sizer.AddGrowableCol(1) |
83 buttons_sizer.AddGrowableRow(0) |
76 buttons_sizer.AddGrowableRow(0) |
84 |
77 |
85 main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
78 main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
86 main_sizer.AddSizer(buttons_sizer, 0, border=0, flag=wx.GROW) |
79 main_sizer.AddSizer(buttons_sizer, flag=wx.GROW) |
87 main_sizer.AddWindow(self.VariablesList, 0, border=0, flag=wx.GROW) |
80 main_sizer.AddWindow(self.VariablesList, flag=wx.GROW) |
88 main_sizer.AddGrowableCol(0) |
81 main_sizer.AddGrowableCol(0) |
89 main_sizer.AddGrowableRow(1) |
82 main_sizer.AddGrowableRow(1) |
90 |
83 |
91 self.SetSizer(main_sizer) |
84 self.SetSizer(main_sizer) |
92 |
85 |
149 buttons = [] |
142 buttons = [] |
150 if var_infos["class"] in ITEMS_VARIABLE: |
143 if var_infos["class"] in ITEMS_VARIABLE: |
151 if (var_infos["debug"] and self.Debug and |
144 if (var_infos["debug"] and self.Debug and |
152 (self.Controller.IsOfType(var_infos["type"], "ANY_NUM", True) or |
145 (self.Controller.IsOfType(var_infos["type"], "ANY_NUM", True) or |
153 self.Controller.IsOfType(var_infos["type"], "ANY_BIT", True))): |
146 self.Controller.IsOfType(var_infos["type"], "ANY_BIT", True))): |
154 graph_button = wx.lib.buttons.GenBitmapButton(name="graph", |
147 graph_button = wx.lib.buttons.GenBitmapButton(panel, |
155 parent=panel, bitmap=self.ParentWindow.GenerateBitmap("graph"), |
148 bitmap=GetBitmap("instance_graph"), |
156 pos=wx.Point(0, 0), size=wx.Size(28, 28), style=wx.NO_BORDER) |
149 size=wx.Size(28, 28), style=wx.NO_BORDER) |
157 self.Bind(wx.EVT_BUTTON, self.GenGraphButtonCallback(var_infos), graph_button) |
150 self.Bind(wx.EVT_BUTTON, self.GenGraphButtonCallback(var_infos), graph_button) |
158 buttons.append(graph_button) |
151 buttons.append(graph_button) |
159 elif var_infos["edit"]: |
152 elif var_infos["edit"]: |
160 edit_button = wx.lib.buttons.GenBitmapButton(name="edit", |
153 edit_button = wx.lib.buttons.GenBitmapButton(panel, |
161 parent=panel, bitmap=self.ParentWindow.GenerateBitmap("edit"), |
154 bitmap=GetBitmap("edit"), |
162 pos=wx.Point(0, 0), size=wx.Size(28, 28), style=wx.NO_BORDER) |
155 size=wx.Size(28, 28), style=wx.NO_BORDER) |
163 self.Bind(wx.EVT_BUTTON, self.GenEditButtonCallback(var_infos), edit_button) |
156 self.Bind(wx.EVT_BUTTON, self.GenEditButtonCallback(var_infos), edit_button) |
164 buttons.append(edit_button) |
157 buttons.append(edit_button) |
165 |
158 |
166 if var_infos["debug"] and self.Debug: |
159 if var_infos["debug"] and self.Debug: |
167 debug_button = wx.lib.buttons.GenBitmapButton(name="debug", |
160 debug_button = wx.lib.buttons.GenBitmapButton(panel, |
168 parent=panel, bitmap=self.ParentWindow.GenerateBitmap("debug"), |
161 bitmap=GetBitmap("debug_instance"), |
169 pos=wx.Point(0, 0), size=wx.Size(28, 28), style=wx.NO_BORDER) |
162 size=wx.Size(28, 28), style=wx.NO_BORDER) |
170 self.Bind(wx.EVT_BUTTON, self.GenDebugButtonCallback(var_infos), debug_button) |
163 self.Bind(wx.EVT_BUTTON, self.GenDebugButtonCallback(var_infos), debug_button) |
171 buttons.append(debug_button) |
164 buttons.append(debug_button) |
172 |
165 |
173 button_num = len(buttons) |
166 button_num = len(buttons) |
174 if button_num > 0: |
167 if button_num > 0: |