111 from TextViewer import * |
111 from TextViewer import * |
112 from GraphicViewer import * |
112 from GraphicViewer import * |
113 from RessourceEditor import * |
113 from RessourceEditor import * |
114 from DataTypeEditor import * |
114 from DataTypeEditor import * |
115 from PLCControler import * |
115 from PLCControler import * |
116 from controls.VariablePanel import VariablePanel |
|
117 from SearchResultPanel import SearchResultPanel |
116 from SearchResultPanel import SearchResultPanel |
118 from controls import CustomGrid |
117 from controls import CustomGrid, CustomTable |
119 |
118 |
120 # Define PLCOpenEditor controls id |
119 # Define PLCOpenEditor controls id |
121 [ID_PLCOPENEDITOR, ID_PLCOPENEDITORLEFTNOTEBOOK, |
120 [ID_PLCOPENEDITOR, ID_PLCOPENEDITORLEFTNOTEBOOK, |
122 ID_PLCOPENEDITORBOTTOMNOTEBOOK, ID_PLCOPENEDITORRIGHTNOTEBOOK, |
121 ID_PLCOPENEDITORBOTTOMNOTEBOOK, ID_PLCOPENEDITORRIGHTNOTEBOOK, |
123 ID_PLCOPENEDITORTYPESTREE, ID_PLCOPENEDITORINSTANCESTREE, |
122 ID_PLCOPENEDITORTYPESTREE, ID_PLCOPENEDITORINSTANCESTREE, |
3843 self.Parent.HasNewData = True |
3842 self.Parent.HasNewData = True |
3844 |
3843 |
3845 def GetValue(self): |
3844 def GetValue(self): |
3846 return self.Value |
3845 return self.Value |
3847 |
3846 |
3848 class DebugVariableTable(wx.grid.PyGridTableBase): |
3847 class DebugVariableTable(CustomTable): |
3849 |
3848 |
3850 """ |
|
3851 A custom wx.grid.Grid Table using user supplied data |
|
3852 """ |
|
3853 def __init__(self, parent, data, colnames): |
|
3854 # The base class must be initialized *first* |
|
3855 wx.grid.PyGridTableBase.__init__(self) |
|
3856 self.data = data |
|
3857 self.colnames = colnames |
|
3858 self.Parent = parent |
|
3859 # XXX |
|
3860 # we need to store the row length and collength to |
|
3861 # see if the table has changed size |
|
3862 self._rows = self.GetNumberRows() |
|
3863 self._cols = self.GetNumberCols() |
|
3864 |
|
3865 def GetNumberCols(self): |
|
3866 return len(self.colnames) |
|
3867 |
|
3868 def GetNumberRows(self): |
|
3869 return len(self.data) |
|
3870 |
|
3871 def GetColLabelValue(self, col, translate=True): |
|
3872 if col < len(self.colnames): |
|
3873 if translate: |
|
3874 return _(self.colnames[col]) |
|
3875 return self.colnames[col] |
|
3876 |
|
3877 def GetRowLabelValues(self, row, translate=True): |
|
3878 return row |
|
3879 |
|
3880 def GetValue(self, row, col): |
3849 def GetValue(self, row, col): |
3881 if row < self.GetNumberRows(): |
3850 if row < self.GetNumberRows(): |
3882 return self.GetValueByName(row, self.GetColLabelValue(col, False)) |
3851 return self.GetValueByName(row, self.GetColLabelValue(col, False)) |
3883 return "" |
3852 return "" |
3884 |
3853 |
3904 def IsForced(self, row): |
3873 def IsForced(self, row): |
3905 if row < self.GetNumberRows(): |
3874 if row < self.GetNumberRows(): |
3906 return self.data[row].IsForced() |
3875 return self.data[row].IsForced() |
3907 return False |
3876 return False |
3908 |
3877 |
3909 def ResetView(self, grid): |
|
3910 """ |
|
3911 (wx.grid.Grid) -> Reset the grid view. Call this to |
|
3912 update the grid if rows and columns have been added or deleted |
|
3913 """ |
|
3914 grid.BeginBatch() |
|
3915 for current, new, delmsg, addmsg in [ |
|
3916 (self._rows, self.GetNumberRows(), wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED), |
|
3917 (self._cols, self.GetNumberCols(), wx.grid.GRIDTABLE_NOTIFY_COLS_DELETED, wx.grid.GRIDTABLE_NOTIFY_COLS_APPENDED), |
|
3918 ]: |
|
3919 if new < current: |
|
3920 msg = wx.grid.GridTableMessage(self,delmsg,new,current-new) |
|
3921 grid.ProcessTableMessage(msg) |
|
3922 elif new > current: |
|
3923 msg = wx.grid.GridTableMessage(self,addmsg,new-current) |
|
3924 grid.ProcessTableMessage(msg) |
|
3925 self.UpdateValues(grid) |
|
3926 grid.EndBatch() |
|
3927 |
|
3928 self._rows = self.GetNumberRows() |
|
3929 self._cols = self.GetNumberCols() |
|
3930 # update the column rendering scheme |
|
3931 self._updateColAttrs(grid) |
|
3932 |
|
3933 # update the scrollbars and the displayed part of the grid |
|
3934 grid.AdjustScrollbars() |
|
3935 grid.ForceRefresh() |
|
3936 |
|
3937 def UpdateValues(self, grid): |
|
3938 """Update all displayed values""" |
|
3939 # This sends an event to the grid table to update all of the values |
|
3940 msg = wx.grid.GridTableMessage(self, wx.grid.GRIDTABLE_REQUEST_VIEW_GET_VALUES) |
|
3941 grid.ProcessTableMessage(msg) |
|
3942 |
|
3943 def _updateColAttrs(self, grid): |
3878 def _updateColAttrs(self, grid): |
3944 """ |
3879 """ |
3945 wx.grid.Grid -> update the column attributes to add the |
3880 wx.grid.Grid -> update the column attributes to add the |
3946 appropriate renderer given the column name. |
3881 appropriate renderer given the column name. |
3947 |
3882 |
3954 if self.IsForced(row): |
3889 if self.IsForced(row): |
3955 grid.SetCellTextColour(row, col, wx.BLUE) |
3890 grid.SetCellTextColour(row, col, wx.BLUE) |
3956 else: |
3891 else: |
3957 grid.SetCellTextColour(row, col, wx.BLACK) |
3892 grid.SetCellTextColour(row, col, wx.BLACK) |
3958 grid.SetReadOnly(row, col, True) |
3893 grid.SetReadOnly(row, col, True) |
|
3894 self.ResizeRow(grid, row) |
3959 |
3895 |
3960 def SetData(self, data): |
|
3961 self.data = data |
|
3962 |
|
3963 def GetData(self): |
|
3964 return self.data |
|
3965 |
|
3966 def AppendItem(self, data): |
3896 def AppendItem(self, data): |
3967 self.data.append(data) |
3897 self.data.append(data) |
3968 |
3898 |
3969 def InsertItem(self, idx, data): |
3899 def InsertItem(self, idx, data): |
3970 self.data.insert(idx, data) |
3900 self.data.insert(idx, data) |
3976 self.data.insert(new_idx, self.data.pop(idx)) |
3906 self.data.insert(new_idx, self.data.pop(idx)) |
3977 |
3907 |
3978 def GetItem(self, idx): |
3908 def GetItem(self, idx): |
3979 return self.data[idx] |
3909 return self.data[idx] |
3980 |
3910 |
3981 def Empty(self): |
3911 |
3982 self.data = [] |
|
3983 |
|
3984 class DebugVariableDropTarget(wx.TextDropTarget): |
3912 class DebugVariableDropTarget(wx.TextDropTarget): |
3985 |
3913 |
3986 def __init__(self, parent): |
3914 def __init__(self, parent): |
3987 wx.TextDropTarget.__init__(self) |
3915 wx.TextDropTarget.__init__(self) |
3988 self.ParentWindow = parent |
3916 self.ParentWindow = parent |