etisserant@0: #Boa:Frame:objdictedit etisserant@0: #!/usr/bin/env python etisserant@0: # -*- coding: utf-8 -*- etisserant@0: etisserant@0: #This file is part of CanFestival, a library implementing CanOpen Stack. etisserant@0: # etisserant@0: #Copyright (C): Edouard TISSERANT, Francis DUPIN and Laurent BESSARD etisserant@0: # etisserant@0: #See COPYING file for copyrights details. etisserant@0: # etisserant@0: #This library is free software; you can redistribute it and/or etisserant@0: #modify it under the terms of the GNU Lesser General Public etisserant@0: #License as published by the Free Software Foundation; either etisserant@0: #version 2.1 of the License, or (at your option) any later version. etisserant@0: # etisserant@0: #This library is distributed in the hope that it will be useful, etisserant@0: #but WITHOUT ANY WARRANTY; without even the implied warranty of etisserant@0: #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU etisserant@0: #Lesser General Public License for more details. etisserant@0: # etisserant@0: #You should have received a copy of the GNU Lesser General Public etisserant@0: #License along with this library; if not, write to the Free Software etisserant@0: #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA etisserant@0: etisserant@0: from wxPython.wx import * etisserant@0: from wxPython.grid import * etisserant@0: import wx etisserant@0: from wx.lib.anchors import LayoutAnchors etisserant@0: import wx.grid etisserant@0: etisserant@0: from types import * etisserant@0: import os, re, platform, sys, time, traceback, getopt etisserant@0: etisserant@0: __version__ = "$Revision$" etisserant@0: etisserant@0: from nodemanager import * etisserant@0: from node import OD_Subindex,OD_MultipleSubindexes,OD_IdenticalSubindexes,OD_IdenticalIndexes etisserant@0: from doc_index.DS301_index import * etisserant@0: lbessard@72: try: lbessard@72: from wxPython.html import * lbessard@72: lbessard@72: wxEVT_HTML_URL_CLICK = wxNewId() lbessard@72: lbessard@72: def EVT_HTML_URL_CLICK(win, func): lbessard@72: win.Connect(-1, -1, wxEVT_HTML_URL_CLICK, func) lbessard@72: lbessard@72: class wxHtmlWindowUrlClick(wxPyEvent): lbessard@72: def __init__(self, linkinfo): lbessard@72: wxPyEvent.__init__(self) lbessard@72: self.SetEventType(wxEVT_HTML_URL_CLICK) lbessard@72: self.linkinfo = (linkinfo.GetHref(), linkinfo.GetTarget()) lbessard@72: lbessard@72: class wxUrlClickHtmlWindow(wxHtmlWindow): lbessard@72: """ HTML window that generates and OnLinkClicked event. lbessard@72: lbessard@72: Use this to avoid having to override HTMLWindow lbessard@72: """ lbessard@72: def OnLinkClicked(self, linkinfo): lbessard@72: wxPostEvent(self, wxHtmlWindowUrlClick(linkinfo)) lbessard@72: lbessard@72: #------------------------------------------------------------------------------- lbessard@72: # Html Frame lbessard@72: #------------------------------------------------------------------------------- lbessard@72: lbessard@72: [wxID_HTMLFRAME, wxID_HTMLFRAMEHTMLCONTENT] = [wx.NewId() for _init_ctrls in range(2)] lbessard@72: lbessard@72: class HtmlFrame(wx.Frame): lbessard@72: def _init_ctrls(self, prnt): lbessard@72: # generated method, don't edit lbessard@72: wx.Frame.__init__(self, id=wxID_HTMLFRAME, name='HtmlFrame', lbessard@72: parent=prnt, pos=wx.Point(320, 231), size=wx.Size(853, 616), lbessard@72: style=wx.DEFAULT_FRAME_STYLE, title='') lbessard@72: self.Bind(wx.EVT_CLOSE, self.OnCloseFrame, id=wxID_HTMLFRAME) lbessard@72: lbessard@72: self.HtmlContent = wxUrlClickHtmlWindow(id=wxID_HTMLFRAMEHTMLCONTENT, lbessard@72: name='HtmlContent', parent=self, pos=wx.Point(0, 0), lbessard@72: size=wx.Size(-1, -1), style=wxHW_SCROLLBAR_AUTO|wxHW_NO_SELECTION) lbessard@72: EVT_HTML_URL_CLICK(self.HtmlContent, self.OnLinkClick) lbessard@72: lbessard@72: def __init__(self, parent, opened): lbessard@72: self._init_ctrls(parent) lbessard@72: self.HtmlFrameOpened = opened lbessard@72: lbessard@72: def SetHtmlCode(self, htmlcode): lbessard@72: self.HtmlContent.SetPage(htmlcode) lbessard@72: lbessard@72: def SetHtmlPage(self, htmlpage): lbessard@72: self.HtmlContent.LoadPage(htmlpage) lbessard@72: lbessard@72: def OnCloseFrame(self, event): lbessard@72: self.HtmlFrameOpened.remove(self.GetTitle()) lbessard@72: event.Skip() lbessard@72: lbessard@72: def OnLinkClick(self, event): lbessard@72: url = event.linkinfo[0] lbessard@72: try: lbessard@72: import webbrowser lbessard@72: except ImportError: lbessard@72: wxMessageBox('Please point your browser at: %s' % url) lbessard@72: else: lbessard@72: webbrowser.open(url) lbessard@72: lbessard@72: Html_Window = True lbessard@72: except: lbessard@72: Html_Window = False etisserant@0: etisserant@0: def create(parent): etisserant@0: return objdictedit(parent) etisserant@0: etisserant@0: def usage(): etisserant@0: print "\nUsage of objectdict.py :" etisserant@0: print "\n %s [Filepath, ...]\n"%sys.argv[0] etisserant@0: etisserant@0: try: etisserant@0: opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) etisserant@0: except getopt.GetoptError: etisserant@0: # print help information and exit: etisserant@0: usage() etisserant@0: sys.exit(2) etisserant@0: etisserant@0: for o, a in opts: etisserant@0: if o in ("-h", "--help"): etisserant@0: usage() etisserant@0: sys.exit() etisserant@0: etisserant@0: filesOpen = args etisserant@0: etisserant@0: ColSizes = [75, 250, 150, 125, 100, 60, 250] etisserant@0: ColAlignements = [wxALIGN_CENTER, wxALIGN_LEFT, wxALIGN_CENTER, wxALIGN_RIGHT, wxALIGN_CENTER, wxALIGN_CENTER, wxALIGN_LEFT] etisserant@0: AccessList = "Read Only,Write Only,Read/Write" lbessard@68: RAccessList = "Read Only,Read/Write" etisserant@0: BoolList = "True,False" etisserant@0: OptionList = "Yes,No" etisserant@0: etisserant@0: DictionaryOrganisation = [ etisserant@0: {"minIndex" : 0x0001, "maxIndex" : 0x0FFF, "name" : "Data Type Definitions"}, etisserant@0: {"minIndex" : 0x1000, "maxIndex" : 0x1029, "name" : "Communication Parameters"}, etisserant@0: {"minIndex" : 0x1200, "maxIndex" : 0x12FF, "name" : "SDO Parameters"}, etisserant@0: {"minIndex" : 0x1400, "maxIndex" : 0x15FF, "name" : "Receive PDO Parameters"}, etisserant@0: {"minIndex" : 0x1600, "maxIndex" : 0x17FF, "name" : "Receive PDO Mapping"}, etisserant@0: {"minIndex" : 0x1800, "maxIndex" : 0x19FF, "name" : "Transmit PDO Parameters"}, etisserant@0: {"minIndex" : 0x1A00, "maxIndex" : 0x1BFF, "name" : "Transmit PDO Mapping"}, etisserant@0: {"minIndex" : 0x1C00, "maxIndex" : 0x1FFF, "name" : "Other Communication Parameters"}, etisserant@0: {"minIndex" : 0x2000, "maxIndex" : 0x5FFF, "name" : "Manufacturer Specific"}, etisserant@0: {"minIndex" : 0x6000, "maxIndex" : 0x9FFF, "name" : "Standardized Device Profile"}, etisserant@0: {"minIndex" : 0xA000, "maxIndex" : 0xBFFF, "name" : "Standardized Interface Profile"}] etisserant@0: etisserant@0: class SubindexTable(wxPyGridTableBase): etisserant@0: etisserant@0: """ etisserant@0: A custom wxGrid Table using user supplied data etisserant@0: """ etisserant@0: def __init__(self, parent, data, editors, colnames): etisserant@0: # The base class must be initialized *first* etisserant@0: wxPyGridTableBase.__init__(self) etisserant@0: self.data = data etisserant@0: self.editors = editors etisserant@0: self.CurrentIndex = 0 etisserant@0: self.colnames = colnames etisserant@0: self.Parent = parent etisserant@0: # XXX etisserant@0: # we need to store the row length and collength to etisserant@0: # see if the table has changed size etisserant@0: self._rows = self.GetNumberRows() etisserant@0: self._cols = self.GetNumberCols() etisserant@0: etisserant@0: def GetNumberCols(self): etisserant@0: return len(self.colnames) etisserant@0: etisserant@0: def GetNumberRows(self): etisserant@0: return len(self.data) etisserant@0: etisserant@0: def GetColLabelValue(self, col): etisserant@0: if col < len(self.colnames): etisserant@0: return self.colnames[col] etisserant@0: etisserant@0: def GetRowLabelValues(self, row): etisserant@0: return row etisserant@0: etisserant@0: def GetValue(self, row, col): etisserant@0: if row < self.GetNumberRows(): lbessard@63: value = self.data[row].get(self.GetColLabelValue(col), "") lbessard@63: if (type(value) == UnicodeType): lbessard@63: return value lbessard@63: else: lbessard@63: return str(value) etisserant@0: etisserant@0: def GetEditor(self, row, col): etisserant@0: if row < self.GetNumberRows(): etisserant@0: return self.editors[row].get(self.GetColLabelValue(col), "") etisserant@0: etisserant@0: def GetValueByName(self, row, colname): etisserant@0: return self.data[row].get(colname) etisserant@0: etisserant@0: def SetValue(self, row, col, value): etisserant@0: if col < len(self.colnames): etisserant@0: self.data[row][self.GetColLabelValue(col)] = value etisserant@0: etisserant@0: def ResetView(self, grid): etisserant@0: """ etisserant@0: (wxGrid) -> Reset the grid view. Call this to etisserant@0: update the grid if rows and columns have been added or deleted etisserant@0: """ etisserant@0: grid.BeginBatch() etisserant@0: for current, new, delmsg, addmsg in [ etisserant@0: (self._rows, self.GetNumberRows(), wxGRIDTABLE_NOTIFY_ROWS_DELETED, wxGRIDTABLE_NOTIFY_ROWS_APPENDED), etisserant@0: (self._cols, self.GetNumberCols(), wxGRIDTABLE_NOTIFY_COLS_DELETED, wxGRIDTABLE_NOTIFY_COLS_APPENDED), etisserant@0: ]: etisserant@0: if new < current: etisserant@0: msg = wxGridTableMessage(self,delmsg,new,current-new) etisserant@0: grid.ProcessTableMessage(msg) etisserant@0: elif new > current: etisserant@0: msg = wxGridTableMessage(self,addmsg,new-current) etisserant@0: grid.ProcessTableMessage(msg) etisserant@0: self.UpdateValues(grid) etisserant@0: grid.EndBatch() etisserant@0: etisserant@0: self._rows = self.GetNumberRows() etisserant@0: self._cols = self.GetNumberCols() etisserant@0: # update the column rendering scheme etisserant@0: self._updateColAttrs(grid) etisserant@0: etisserant@0: # update the scrollbars and the displayed part of the grid etisserant@0: grid.AdjustScrollbars() etisserant@0: grid.ForceRefresh() etisserant@0: etisserant@0: etisserant@0: def UpdateValues(self, grid): etisserant@0: """Update all displayed values""" etisserant@0: # This sends an event to the grid table to update all of the values etisserant@0: msg = wxGridTableMessage(self, wxGRIDTABLE_REQUEST_VIEW_GET_VALUES) etisserant@0: grid.ProcessTableMessage(msg) etisserant@0: etisserant@0: def _updateColAttrs(self, grid): etisserant@0: """ etisserant@0: wxGrid -> update the column attributes to add the etisserant@0: appropriate renderer given the column name. etisserant@0: etisserant@0: Otherwise default to the default renderer. etisserant@0: """ etisserant@0: etisserant@0: for col in range(self.GetNumberCols()): etisserant@0: attr = wxGridCellAttr() etisserant@0: attr.SetAlignment(ColAlignements[col], wxALIGN_CENTRE) etisserant@0: grid.SetColAttr(col, attr) etisserant@0: grid.SetColSize(col, ColSizes[col]) etisserant@0: etisserant@0: typelist = None etisserant@0: accesslist = None etisserant@0: for row in range(self.GetNumberRows()): etisserant@0: editors = self.editors[row] etisserant@0: for col in range(self.GetNumberCols()): etisserant@0: editor = None etisserant@0: renderer = None etisserant@0: etisserant@0: colname = self.GetColLabelValue(col) etisserant@0: editortype = editors[colname] etisserant@0: if editortype: etisserant@0: grid.SetReadOnly(row, col, False) etisserant@0: if editortype == "string": etisserant@0: editor = wxGridCellTextEditor() etisserant@0: renderer = wxGridCellStringRenderer() etisserant@0: if colname == "value" and "length" in editors: etisserant@0: editor.SetParameters(editors["length"]) etisserant@0: elif editortype == "number": etisserant@0: editor = wxGridCellNumberEditor() etisserant@0: renderer = wxGridCellNumberRenderer() etisserant@0: if colname == "value" and "min" in editors and "max" in editors: etisserant@0: editor.SetParameters("%s,%s"%(editors["min"],editors["max"])) etisserant@0: elif editortype == "real": etisserant@0: editor = wxGridCellFloatEditor() etisserant@0: renderer = wxGridCellFloatRenderer() etisserant@0: if colname == "value" and "min" in editors and "max" in editors: etisserant@0: editor.SetParameters("%s,%s"%(editors["min"],editors["max"])) etisserant@0: elif editortype == "bool": etisserant@0: editor = wxGridCellChoiceEditor() etisserant@0: editor.SetParameters(BoolList) etisserant@0: elif editortype == "access": etisserant@0: editor = wxGridCellChoiceEditor() etisserant@0: editor.SetParameters(AccessList) lbessard@68: elif editortype == "raccess": lbessard@68: editor = wxGridCellChoiceEditor() lbessard@68: editor.SetParameters(RAccessList) etisserant@0: elif editortype == "option": etisserant@0: editor = wxGridCellChoiceEditor() etisserant@0: editor.SetParameters(OptionList) etisserant@0: elif editortype == "type": etisserant@0: editor = wxGridCellChoiceEditor() etisserant@0: editor.SetParameters(self.Parent.Manager.GetCurrentTypeList()) etisserant@0: elif editortype == "map": etisserant@0: editor = wxGridCellChoiceEditor() etisserant@0: editor.SetParameters(self.Parent.Manager.GetCurrentMapList()) lbessard@68: elif editortype == "time": lbessard@68: editor = wxGridCellTextEditor() lbessard@68: renderer = wxGridCellStringRenderer() etisserant@0: else: etisserant@0: grid.SetReadOnly(row, col, True) etisserant@0: etisserant@0: grid.SetCellEditor(row, col, editor) etisserant@0: grid.SetCellRenderer(row, col, renderer) etisserant@0: etisserant@0: grid.SetCellBackgroundColour(row, col, wxWHITE) etisserant@0: etisserant@0: def SetData(self, data): etisserant@0: self.data = data etisserant@0: etisserant@0: def SetEditors(self, editors): etisserant@0: self.editors = editors etisserant@0: etisserant@0: def GetCurrentIndex(self): etisserant@0: return self.CurrentIndex etisserant@0: etisserant@0: def SetCurrentIndex(self, index): etisserant@0: self.CurrentIndex = index etisserant@0: etisserant@0: def AppendRow(self, row_content): etisserant@0: self.data.append(row_content) etisserant@0: etisserant@0: def Empty(self): etisserant@0: self.data = [] etisserant@0: self.editors = [] etisserant@0: etisserant@0: [wxID_EDITINGPANEL, wxID_EDITINGPANELADDBUTTON, wxID_EDITINGPANELINDEXCHOICE, etisserant@0: wxID_EDITINGPANELINDEXLIST, wxID_EDITINGPANELINDEXLISTPANEL, wxID_EDITINGPANELPARTLIST, etisserant@0: wxID_EDITINGPANELSECONDSPLITTER, wxID_EDITINGPANELSUBINDEXGRID, etisserant@0: wxID_EDITINGPANELSUBINDEXGRIDPANEL, wxID_EDITINGPANELCALLBACKCHECK, etisserant@0: ] = [wx.NewId() for _init_ctrls in range(10)] etisserant@0: etisserant@0: [wxID_EDITINGPANELINDEXLISTMENUITEMS0, wxID_EDITINGPANELINDEXLISTMENUITEMS1, etisserant@0: wxID_EDITINGPANELINDEXLISTMENUITEMS2, etisserant@0: ] = [wx.NewId() for _init_coll_IndexListMenu_Items in range(3)] etisserant@0: etisserant@0: [wxID_EDITINGPANELMENU1ITEMS0, wxID_EDITINGPANELMENU1ITEMS1, etisserant@0: ] = [wx.NewId() for _init_coll_SubindexGridMenu_Items in range(2)] etisserant@0: etisserant@0: class EditingPanel(wx.SplitterWindow): etisserant@0: def _init_coll_AddToListSizer_Items(self, parent): etisserant@0: # generated method, don't edit etisserant@0: etisserant@0: parent.AddWindow(self.AddButton, 0, border=0, flag=0) etisserant@0: parent.AddWindow(self.IndexChoice, 0, border=0, flag=wxGROW) etisserant@0: etisserant@0: def _init_coll_SubindexGridSizer_Items(self, parent): etisserant@0: # generated method, don't edit etisserant@0: etisserant@0: parent.AddWindow(self.CallbackCheck, 0, border=0, flag=0) etisserant@0: parent.AddWindow(self.SubindexGrid, 0, border=0, flag=wxGROW) etisserant@0: etisserant@0: def _init_coll_IndexListSizer_Items(self, parent): etisserant@0: # generated method, don't edit etisserant@0: etisserant@0: parent.AddWindow(self.IndexList, 0, border=0, flag=wxGROW) etisserant@0: parent.AddSizer(self.AddToListSizer, 0, border=0, flag=wxGROW) etisserant@0: etisserant@0: def _init_coll_AddToListSizer_Growables(self, parent): etisserant@0: # generated method, don't edit etisserant@0: etisserant@0: parent.AddGrowableCol(1) etisserant@0: etisserant@0: def _init_coll_SubindexGridSizer_Growables(self, parent): etisserant@0: # generated method, don't edit etisserant@0: etisserant@0: parent.AddGrowableCol(0) etisserant@0: parent.AddGrowableRow(1) etisserant@0: etisserant@0: def _init_coll_IndexListSizer_Growables(self, parent): etisserant@0: # generated method, don't edit etisserant@0: etisserant@0: parent.AddGrowableCol(0) etisserant@0: parent.AddGrowableRow(0) etisserant@0: etisserant@0: def _init_coll_SubindexGridMenu_Items(self, parent): etisserant@0: # generated method, don't edit etisserant@0: etisserant@0: parent.Append(help='', id=wxID_EDITINGPANELMENU1ITEMS0, etisserant@0: kind=wx.ITEM_NORMAL, text='Add') etisserant@0: parent.Append(help='', id=wxID_EDITINGPANELMENU1ITEMS1, etisserant@0: kind=wx.ITEM_NORMAL, text='Delete') etisserant@0: self.Bind(wx.EVT_MENU, self.OnAddSubindexMenu, etisserant@0: id=wxID_EDITINGPANELMENU1ITEMS0) etisserant@0: self.Bind(wx.EVT_MENU, self.OnDeleteSubindexMenu, etisserant@0: id=wxID_EDITINGPANELMENU1ITEMS1) etisserant@0: etisserant@0: def _init_coll_IndexListMenu_Items(self, parent): etisserant@0: # generated method, don't edit etisserant@0: etisserant@0: parent.Append(help='', id=wxID_EDITINGPANELINDEXLISTMENUITEMS0, etisserant@0: kind=wx.ITEM_NORMAL, text='Rename') etisserant@0: parent.Append(help='', id=wxID_EDITINGPANELINDEXLISTMENUITEMS2, etisserant@0: kind=wx.ITEM_NORMAL, text='Modify') etisserant@0: parent.Append(help='', id=wxID_EDITINGPANELINDEXLISTMENUITEMS1, etisserant@0: kind=wx.ITEM_NORMAL, text='Delete') etisserant@0: self.Bind(wx.EVT_MENU, self.OnRenameIndexMenu, etisserant@0: id=wxID_EDITINGPANELINDEXLISTMENUITEMS0) etisserant@0: self.Bind(wx.EVT_MENU, self.OnDeleteIndexMenu, etisserant@0: id=wxID_EDITINGPANELINDEXLISTMENUITEMS1) etisserant@0: self.Bind(wx.EVT_MENU, self.OnModifyIndexMenu, etisserant@0: id=wxID_EDITINGPANELINDEXLISTMENUITEMS2) etisserant@0: etisserant@0: def _init_utils(self): etisserant@0: # generated method, don't edit etisserant@0: self.IndexListMenu = wx.Menu(title='') etisserant@0: etisserant@0: self.SubindexGridMenu = wx.Menu(title='') etisserant@0: etisserant@0: self._init_coll_IndexListMenu_Items(self.IndexListMenu) etisserant@0: self._init_coll_SubindexGridMenu_Items(self.SubindexGridMenu) etisserant@0: etisserant@0: def _init_sizers(self): etisserant@0: # generated method, don't edit etisserant@0: self.IndexListSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) etisserant@0: etisserant@0: self.SubindexGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) etisserant@0: etisserant@0: self.AddToListSizer = wx.FlexGridSizer(cols=2, hgap=0, rows=1, vgap=0) etisserant@0: etisserant@0: self._init_coll_IndexListSizer_Growables(self.IndexListSizer) etisserant@0: self._init_coll_IndexListSizer_Items(self.IndexListSizer) etisserant@0: self._init_coll_SubindexGridSizer_Growables(self.SubindexGridSizer) etisserant@0: self._init_coll_SubindexGridSizer_Items(self.SubindexGridSizer) etisserant@0: self._init_coll_AddToListSizer_Growables(self.AddToListSizer) etisserant@0: self._init_coll_AddToListSizer_Items(self.AddToListSizer) etisserant@0: etisserant@0: self.SubindexGridPanel.SetSizer(self.SubindexGridSizer) etisserant@0: self.IndexListPanel.SetSizer(self.IndexListSizer) etisserant@0: etisserant@0: def _init_ctrls(self, prnt): etisserant@0: wx.SplitterWindow.__init__(self, id=wxID_EDITINGPANEL, etisserant@0: name='MainSplitter', parent=prnt, point=wx.Point(0, 0), etisserant@0: size=wx.Size(-1, -1), style=wx.SP_3D) etisserant@0: self._init_utils() etisserant@0: self.SetNeedUpdating(True) etisserant@0: self.SetMinimumPaneSize(1) etisserant@0: etisserant@0: self.PartList = wx.ListBox(choices=[], id=wxID_EDITINGPANELPARTLIST, etisserant@0: name='PartList', parent=self, pos=wx.Point(0, 0), etisserant@0: size=wx.Size(-1, -1), style=0) etisserant@0: self.PartList.Bind(wx.EVT_LISTBOX, self.OnPartListBoxClick, etisserant@0: id=wxID_EDITINGPANELPARTLIST) etisserant@0: etisserant@0: self.SecondSplitter = wx.SplitterWindow(id=wxID_EDITINGPANELSECONDSPLITTER, etisserant@0: name='SecondSplitter', parent=self, point=wx.Point(0, etisserant@0: 0), size=wx.Size(-1, -1), style=wx.SP_3D) etisserant@0: self.SecondSplitter.SetMinimumPaneSize(1) etisserant@0: self.SplitHorizontally(self.PartList, self.SecondSplitter, etisserant@0: 110) etisserant@0: etisserant@0: self.SubindexGridPanel = wx.Panel(id=wxID_EDITINGPANELSUBINDEXGRIDPANEL, etisserant@0: name='SubindexGridPanel', parent=self.SecondSplitter, pos=wx.Point(0, etisserant@0: 0), size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL) etisserant@0: etisserant@0: self.IndexListPanel = wx.Panel(id=wxID_EDITINGPANELINDEXLISTPANEL, etisserant@0: name='IndexListPanel', parent=self.SecondSplitter, pos=wx.Point(0, etisserant@0: 0), size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL) etisserant@0: self.SecondSplitter.SplitVertically(self.IndexListPanel, etisserant@0: self.SubindexGridPanel, 280) etisserant@0: etisserant@0: self.SubindexGrid = wx.grid.Grid(id=wxID_EDITINGPANELSUBINDEXGRID, etisserant@0: name='SubindexGrid', parent=self.SubindexGridPanel, pos=wx.Point(0, etisserant@0: 0), size=wx.Size(-1, -1), style=0) etisserant@0: self.SubindexGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False, etisserant@0: 'Sans')) etisserant@0: self.SubindexGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL, etisserant@0: False, 'Sans')) etisserant@0: self.SubindexGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, etisserant@0: self.OnSubindexGridCellChange) etisserant@0: self.SubindexGrid.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK, etisserant@0: self.OnSubindexGridRightClick) etisserant@0: self.SubindexGrid.Bind(wx.grid.EVT_GRID_SELECT_CELL, etisserant@0: self.OnSubindexGridSelectCell) etisserant@0: etisserant@0: self.CallbackCheck = wx.CheckBox(id=wxID_EDITINGPANELCALLBACKCHECK, etisserant@0: label='Have Callbacks', name='CallbackCheck', etisserant@0: parent=self.SubindexGridPanel, pos=wx.Point(0, 0), size=wx.Size(152, etisserant@0: 24), style=0) etisserant@0: self.CallbackCheck.Bind(wx.EVT_CHECKBOX, self.OnCallbackCheck, etisserant@0: id=wxID_EDITINGPANELCALLBACKCHECK) etisserant@0: etisserant@0: self.IndexList = wx.ListBox(choices=[], id=wxID_EDITINGPANELINDEXLIST, etisserant@0: name='IndexList', parent=self.IndexListPanel, pos=wx.Point(0, 0), etisserant@0: size=wx.Size(-1, -1), style=0) etisserant@0: self.IndexList.Bind(wx.EVT_LISTBOX, self.OnIndexListClick, etisserant@0: id=wxID_EDITINGPANELINDEXLIST) etisserant@0: self.IndexList.Bind(wx.EVT_RIGHT_UP, self.OnIndexListRightUp) etisserant@0: etisserant@0: self.AddButton = wx.Button(id=wxID_EDITINGPANELADDBUTTON, label='Add', etisserant@0: name='AddButton', parent=self.IndexListPanel, pos=wx.Point(0, 0), etisserant@0: size=wx.Size(50, 30), style=0) etisserant@0: self.AddButton.Bind(wx.EVT_BUTTON, self.OnAddButtonClick, etisserant@0: id=wxID_EDITINGPANELADDBUTTON) etisserant@0: etisserant@0: self.IndexChoice = wx.Choice(choices=[], id=wxID_EDITINGPANELINDEXCHOICE, etisserant@0: name='IndexChoice', parent=self.IndexListPanel, pos=wx.Point(50, etisserant@0: 0), size=wx.Size(-1, 30), style=0) etisserant@0: etisserant@0: self._init_sizers() etisserant@0: etisserant@0: def __init__(self, parent, manager): etisserant@0: self._init_ctrls(parent.GetNoteBook()) etisserant@0: self.Parent = parent etisserant@0: self.Manager = manager etisserant@0: self.ListIndex = [] etisserant@0: self.ChoiceIndex = [] etisserant@0: self.FirstCall = False etisserant@0: etisserant@0: for values in DictionaryOrganisation: etisserant@37: text = " 0x%04X-0x%04X %s"%(values["minIndex"],values["maxIndex"],values["name"]) etisserant@0: self.PartList.Append(text) etisserant@0: self.Table = SubindexTable(self, [], [], ["subindex", "name", "type", "value", "access", "save", "comment"]) etisserant@0: self.SubindexGrid.SetTable(self.Table) etisserant@0: self.SubindexGrid.SetRowLabelSize(0) etisserant@0: self.CallbackCheck.Disable() etisserant@0: self.Table.ResetView(self.SubindexGrid) etisserant@0: etisserant@0: def GetSelection(self): etisserant@0: selected = self.IndexList.GetSelection() etisserant@0: if selected != wxNOT_FOUND: etisserant@0: index = self.ListIndex[selected] etisserant@0: subIndex = self.SubindexGrid.GetGridCursorRow() etisserant@0: return index, subIndex etisserant@0: return None etisserant@0: etisserant@0: def OnAddButtonClick(self, event): lbessard@59: self.SubindexGrid.SetGridCursor(0, 0) etisserant@0: selected = self.IndexChoice.GetStringSelection() etisserant@0: if selected != "": etisserant@0: if selected == "User Type": etisserant@0: self.Parent.AddUserType() etisserant@0: elif selected == "SDO Server": etisserant@0: self.Manager.AddSDOServerToCurrent() etisserant@0: elif selected == "SDO Client": etisserant@0: self.Manager.AddSDOClientToCurrent() etisserant@0: elif selected == "PDO Receive": etisserant@0: self.Manager.AddPDOReceiveToCurrent() etisserant@0: elif selected == "PDO Transmit": etisserant@0: self.Manager.AddPDOTransmitToCurrent() etisserant@0: elif selected == "Map Variable": etisserant@0: self.Parent.AddMapVariable() etisserant@0: elif selected in [menu for menu, indexes in self.Manager.GetCurrentSpecificMenu()]: etisserant@0: self.Manager.AddSpecificEntryToCurrent(selected) etisserant@0: else: etisserant@0: index = self.ChoiceIndex[self.IndexChoice.GetSelection()] etisserant@0: self.Manager.ManageEntriesOfCurrent([index], []) etisserant@0: self.Parent.RefreshBufferState() etisserant@0: self.RefreshIndexList() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnPartListBoxClick(self, event): etisserant@0: self.SubindexGrid.SetGridCursor(0, 0) etisserant@0: self.RefreshIndexList() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnIndexListClick(self, event): etisserant@0: self.SubindexGrid.SetGridCursor(0, 0) etisserant@0: self.RefreshTable() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnSubindexGridSelectCell(self, event): etisserant@0: wxCallAfter(self.Parent.RefreshStatusBar) etisserant@0: event.Skip() etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Refresh Functions etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: def RefreshIndexList(self): etisserant@0: selected = self.IndexList.GetSelection() etisserant@0: choice = self.IndexChoice.GetStringSelection() etisserant@0: choiceindex = self.IndexChoice.GetSelection() etisserant@0: if selected != wxNOT_FOUND: etisserant@0: selectedindex = self.ListIndex[selected] etisserant@0: self.IndexList.Clear() etisserant@0: self.IndexChoice.Clear() etisserant@0: i = self.PartList.GetSelection() etisserant@0: if i < len(DictionaryOrganisation): etisserant@0: values = DictionaryOrganisation[i] etisserant@0: self.ListIndex = [] etisserant@0: for name, index in self.Manager.GetCurrentValidIndexes(values["minIndex"], values["maxIndex"]): etisserant@37: self.IndexList.Append("0x%04X %s"%(index, name)) etisserant@0: self.ListIndex.append(index) etisserant@0: self.ChoiceIndex = [] etisserant@0: if i == 0: etisserant@0: self.IndexChoice.Append("User Type") etisserant@0: self.IndexChoice.SetStringSelection("User Type") etisserant@0: elif i == 2: etisserant@0: self.IndexChoice.Append("SDO Server") etisserant@0: self.IndexChoice.Append("SDO Client") etisserant@0: if choiceindex != wxNOT_FOUND and choice == self.IndexChoice.GetString(choiceindex): etisserant@0: self.IndexChoice.SetStringSelection(choice) etisserant@0: elif i in (3, 4): etisserant@0: self.IndexChoice.Append("PDO Receive") etisserant@0: self.IndexChoice.SetStringSelection("PDO Receive") etisserant@0: elif i in (5, 6): etisserant@0: self.IndexChoice.Append("PDO Transmit") etisserant@0: self.IndexChoice.SetStringSelection("PDO Transmit") etisserant@0: elif i == 8: etisserant@0: self.IndexChoice.Append("Map Variable") etisserant@0: self.IndexChoice.SetStringSelection("Map Variable") etisserant@0: else: etisserant@0: for name, index in self.Manager.GetCurrentValidChoices(values["minIndex"], values["maxIndex"]): etisserant@0: if index: etisserant@37: self.IndexChoice.Append("0x%04X %s"%(index, name)) etisserant@0: else: etisserant@0: self.IndexChoice.Append(name) etisserant@0: self.ChoiceIndex.append(index) etisserant@0: if choiceindex != wxNOT_FOUND and choice == self.IndexChoice.GetString(choiceindex): etisserant@0: self.IndexChoice.SetStringSelection(choice) etisserant@0: self.IndexChoice.Enable(self.IndexChoice.GetCount() != 0) etisserant@0: self.AddButton.Enable(self.IndexChoice.GetCount() != 0) etisserant@0: if selected == wxNOT_FOUND or selected >= len(self.ListIndex) or selectedindex != self.ListIndex[selected]: etisserant@0: self.Table.Empty() etisserant@0: self.CallbackCheck.SetValue(False) etisserant@0: self.CallbackCheck.Disable() etisserant@0: self.Table.ResetView(self.SubindexGrid) etisserant@0: self.Parent.RefreshStatusBar() etisserant@0: else: etisserant@0: self.IndexList.SetSelection(selected) etisserant@0: self.RefreshTable() etisserant@0: etisserant@0: def RefreshTable(self): etisserant@0: selected = self.IndexList.GetSelection() etisserant@0: if selected != wxNOT_FOUND: etisserant@0: index = self.ListIndex[selected] etisserant@0: if index > 0x260: etisserant@0: self.CallbackCheck.Enable() etisserant@0: self.CallbackCheck.SetValue(self.Manager.HasCurrentEntryCallbacks(index)) etisserant@0: result = self.Manager.GetCurrentEntryValues(index) etisserant@0: if result != None: etisserant@0: self.Table.SetCurrentIndex(index) etisserant@0: data, editors = result etisserant@0: self.Table.SetData(data) etisserant@0: self.Table.SetEditors(editors) etisserant@0: self.Table.ResetView(self.SubindexGrid) etisserant@0: self.Parent.RefreshStatusBar() etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Editing Table value function etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: def OnSubindexGridCellChange(self, event): etisserant@0: index = self.Table.GetCurrentIndex() etisserant@0: subIndex = event.GetRow() etisserant@0: col = event.GetCol() etisserant@0: name = self.Table.GetColLabelValue(col) etisserant@0: value = self.Table.GetValue(subIndex, col) etisserant@0: editor = self.Table.GetEditor(subIndex, col) etisserant@0: self.Manager.SetCurrentEntry(index, subIndex, value, name, editor) etisserant@0: self.Parent.RefreshBufferState() etisserant@0: wxCallAfter(self.RefreshTable) etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnCallbackCheck(self, event): etisserant@0: index = self.Table.GetCurrentIndex() etisserant@0: self.Manager.SetCurrentEntryCallbacks(index, self.CallbackCheck.GetValue()) etisserant@0: self.Parent.RefreshBufferState() etisserant@0: wxCallAfter(self.RefreshTable) etisserant@0: event.Skip() etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Contextual Menu functions etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: def OnIndexListRightUp(self, event): etisserant@0: if not self.FirstCall: etisserant@0: self.FirstCall = True etisserant@0: selected = self.IndexList.GetSelection() etisserant@0: if selected != wxNOT_FOUND: etisserant@0: index = self.ListIndex[selected] etisserant@0: if index < 0x260: etisserant@0: self.IndexListMenu.FindItemByPosition(0).Enable(False) etisserant@0: self.IndexListMenu.FindItemByPosition(1).Enable(True) etisserant@0: self.PopupMenu(self.IndexListMenu) etisserant@0: elif 0x1000 <= index <= 0x1BFF: etisserant@0: self.IndexListMenu.FindItemByPosition(0).Enable(False) etisserant@0: self.IndexListMenu.FindItemByPosition(1).Enable(False) etisserant@0: self.PopupMenu(self.IndexListMenu) etisserant@0: elif 0x2000 <= index <= 0x5FFF: etisserant@0: self.IndexListMenu.FindItemByPosition(0).Enable(True) etisserant@0: self.IndexListMenu.FindItemByPosition(1).Enable(False) etisserant@0: self.PopupMenu(self.IndexListMenu) etisserant@0: elif index >= 0x6000: etisserant@0: self.IndexListMenu.FindItemByPosition(0).Enable(False) etisserant@0: self.IndexListMenu.FindItemByPosition(1).Enable(False) etisserant@0: self.PopupMenu(self.IndexListMenu) etisserant@0: else: etisserant@0: self.FirstCall = False etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnSubindexGridRightClick(self, event): etisserant@0: selected = self.IndexList.GetSelection() etisserant@0: if selected != wxNOT_FOUND: etisserant@0: index = self.ListIndex[selected] etisserant@0: if self.Manager.IsCurrentEntry(index): etisserant@0: infos = self.Manager.GetEntryInfos(index) etisserant@0: if index >= 0x2000 and infos["struct"] & OD_MultipleSubindexes or infos["struct"] & OD_IdenticalSubindexes: etisserant@0: self.PopupMenu(self.SubindexGridMenu) etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnRenameIndexMenu(self, event): etisserant@0: selected = self.IndexList.GetSelection() etisserant@0: if selected != wxNOT_FOUND: etisserant@0: index = self.ListIndex[selected] etisserant@0: if self.Manager.IsCurrentEntry(index): etisserant@0: infos = self.Manager.GetEntryInfos(index) etisserant@0: dialog = wxTextEntryDialog(self, "Give a new name for index 0x%04X"%index, etisserant@0: "Rename an index", infos["name"], wxOK|wxCANCEL) etisserant@0: if dialog.ShowModal() == wxID_OK: etisserant@0: self.Manager.SetCurrentEntryName(index, dialog.GetValue()) etisserant@0: self.Parent.RefreshBufferState() etisserant@0: self.RefreshIndexList() etisserant@0: dialog.Destroy() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnModifyIndexMenu(self, event): etisserant@0: selected = self.IndexList.GetSelection() etisserant@0: if selected != wxNOT_FOUND: etisserant@0: index = self.ListIndex[selected] etisserant@0: if self.Manager.IsCurrentEntry(index) and index < 0x260: etisserant@0: values, valuetype = self.Manager.GetCustomisedTypeValues(index) etisserant@0: dialog = UserTypeDialog(self) etisserant@0: dialog.SetTypeList(self.Manager.GetCustomisableTypes(), values[1]) etisserant@0: if valuetype == 0: etisserant@0: dialog.SetValues(min = values[2], max = values[3]) etisserant@0: elif valuetype == 1: etisserant@0: dialog.SetValues(length = values[2]) etisserant@0: if dialog.ShowModal() == wxID_OK: etisserant@0: type, min, max, length = dialog.GetValues() etisserant@0: self.Manager.SetCurrentUserType(index, type, min, max, length) etisserant@0: self.Parent.RefreshBufferState() etisserant@0: self.RefreshIndexList() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnDeleteIndexMenu(self, event): etisserant@0: selected = self.IndexList.GetSelection() etisserant@0: if selected != wxNOT_FOUND: etisserant@0: index = self.ListIndex[selected] etisserant@0: if self.Manager.IsCurrentEntry(index): etisserant@0: self.Manager.ManageEntriesOfCurrent([],[index]) etisserant@0: self.Parent.RefreshBufferState() etisserant@0: self.RefreshIndexList() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnAddSubindexMenu(self, event): etisserant@0: selected = self.IndexList.GetSelection() etisserant@0: if selected != wxNOT_FOUND: etisserant@0: index = self.ListIndex[selected] etisserant@0: if self.Manager.IsCurrentEntry(index): etisserant@0: dialog = wxTextEntryDialog(self, "Number of subindexes to add:", etisserant@0: "Add subindexes", "1", wxOK|wxCANCEL) etisserant@0: if dialog.ShowModal() == wxID_OK: etisserant@0: number = eval(dialog.GetValue()) etisserant@0: if type(number) == IntType: etisserant@0: self.Manager.AddSubentriesToCurrent(index, number) etisserant@0: self.Parent.RefreshBufferState() etisserant@0: self.RefreshIndexList() etisserant@0: else: etisserant@0: message = wxMessageDialog(self, "An integer is required!", "ERROR", wxOK|wxICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() etisserant@0: dialog.Destroy() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnDeleteSubindexMenu(self, event): etisserant@0: selected = self.IndexList.GetSelection() etisserant@0: if selected != wxNOT_FOUND: etisserant@0: index = self.ListIndex[selected] etisserant@0: if self.Manager.IsCurrentEntry(index): etisserant@0: dialog = wxTextEntryDialog(self, "Number of subindexes to delete:", etisserant@0: "Delete subindexes", "1", wxOK|wxCANCEL) etisserant@0: if dialog.ShowModal() == wxID_OK: etisserant@0: number = eval(dialog.GetValue()) etisserant@0: if type(number) == IntType: etisserant@0: self.Manager.RemoveSubentriesFromCurrent(index, number) etisserant@0: self.Parent.RefreshBufferState() etisserant@0: self.RefreshIndexList() etisserant@0: else: etisserant@0: message = wxMessageDialog(self, "An integer is required!", "ERROR", wxOK|wxICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() etisserant@0: dialog.Destroy() etisserant@0: event.Skip() etisserant@0: etisserant@0: [wxID_OBJDICTEDIT, wxID_OBJDICTEDITFILEOPENED, etisserant@0: wxID_OBJDICTEDITHELPBAR, etisserant@0: ] = [wx.NewId() for _init_ctrls in range(3)] etisserant@0: etisserant@0: [wxID_OBJDICTEDITADDMENUITEMS0, wxID_OBJDICTEDITADDMENUITEMS1, etisserant@0: wxID_OBJDICTEDITADDMENUITEMS2, wxID_OBJDICTEDITADDMENUITEMS3, etisserant@0: wxID_OBJDICTEDITADDMENUITEMS4, wxID_OBJDICTEDITADDMENUITEMS5, etisserant@0: ] = [wx.NewId() for _init_coll_AddMenu_Items in range(6)] etisserant@0: etisserant@0: [wxID_OBJDICTEDITFILEMENUITEMS0, wxID_OBJDICTEDITFILEMENUITEMS1, etisserant@0: wxID_OBJDICTEDITFILEMENUITEMS2, wxID_OBJDICTEDITFILEMENUITEMS4, etisserant@0: wxID_OBJDICTEDITFILEMENUITEMS5, wxID_OBJDICTEDITFILEMENUITEMS6, etisserant@0: wxID_OBJDICTEDITFILEMENUITEMS7, wxID_OBJDICTEDITFILEMENUITEMS8, etisserant@0: ] = [wx.NewId() for _init_coll_FileMenu_Items in range(8)] etisserant@0: etisserant@0: [wxID_OBJDICTEDITEDITMENUITEMS0, wxID_OBJDICTEDITEDITMENUITEMS1, etisserant@0: wxID_OBJDICTEDITEDITMENUITEMS2, wxID_OBJDICTEDITEDITMENUITEMS4, etisserant@0: wxID_OBJDICTEDITEDITMENUITEMS6, wxID_OBJDICTEDITEDITMENUITEMS7, etisserant@0: wxID_OBJDICTEDITEDITMENUITEMS8, etisserant@0: ] = [wx.NewId() for _init_coll_EditMenu_Items in range(7)] etisserant@0: etisserant@0: [wxID_OBJDICTEDITHELPMENUITEMS0, wxID_OBJDICTEDITHELPMENUITEMS1, etisserant@0: wxID_OBJDICTEDITHELPMENUITEMS2, etisserant@0: ] = [wx.NewId() for _init_coll_HelpMenu_Items in range(3)] etisserant@0: etisserant@0: class objdictedit(wx.Frame): etisserant@0: def _init_coll_menuBar1_Menus(self, parent): etisserant@0: # generated method, don't edit etisserant@0: etisserant@0: parent.Append(menu=self.FileMenu, title='File') etisserant@0: parent.Append(menu=self.EditMenu, title='Edit') etisserant@0: parent.Append(menu=self.AddMenu, title='Add') etisserant@0: parent.Append(menu=self.HelpMenu, title='Help') etisserant@0: etisserant@0: def _init_coll_EditMenu_Items(self, parent): etisserant@0: # generated method, don't edit etisserant@0: etisserant@0: parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS4, etisserant@0: kind=wx.ITEM_NORMAL, text='Refresh\tCTRL+R') etisserant@0: parent.AppendSeparator() etisserant@0: parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS1, etisserant@0: kind=wx.ITEM_NORMAL, text='Undo\tCTRL+Z') etisserant@0: parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS0, etisserant@0: kind=wx.ITEM_NORMAL, text='Redo\tCTRL+Y') etisserant@0: parent.AppendSeparator() etisserant@0: parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS6, etisserant@0: kind=wx.ITEM_NORMAL, text='Node infos') etisserant@0: parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS2, etisserant@0: kind=wx.ITEM_NORMAL, text='DS-301 Profile') etisserant@0: parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS8, etisserant@0: kind=wx.ITEM_NORMAL, text='DS-302 Profile') etisserant@0: parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS7, etisserant@0: kind=wx.ITEM_NORMAL, text='Other Profile') etisserant@0: self.Bind(wx.EVT_MENU, self.OnUndoMenu, etisserant@0: id=wxID_OBJDICTEDITEDITMENUITEMS1) etisserant@0: self.Bind(wx.EVT_MENU, self.OnRedoMenu, etisserant@0: id=wxID_OBJDICTEDITEDITMENUITEMS0) etisserant@0: self.Bind(wx.EVT_MENU, self.OnCommunicationMenu, etisserant@0: id=wxID_OBJDICTEDITEDITMENUITEMS2) etisserant@0: self.Bind(wx.EVT_MENU, self.OnRefreshMenu, etisserant@0: id=wxID_OBJDICTEDITEDITMENUITEMS4) etisserant@0: self.Bind(wx.EVT_MENU, self.OnNodeInfosMenu, etisserant@0: id=wxID_OBJDICTEDITEDITMENUITEMS6) etisserant@0: self.Bind(wx.EVT_MENU, self.OnEditProfileMenu, etisserant@0: id=wxID_OBJDICTEDITEDITMENUITEMS7) etisserant@0: self.Bind(wx.EVT_MENU, self.OnOtherCommunicationMenu, etisserant@0: id=wxID_OBJDICTEDITEDITMENUITEMS8) etisserant@0: etisserant@0: def _init_coll_HelpMenu_Items(self, parent): etisserant@0: # generated method, don't edit etisserant@0: etisserant@0: parent.Append(help='', id=wxID_OBJDICTEDITHELPMENUITEMS0, etisserant@0: kind=wx.ITEM_NORMAL, text='DS-301 Standard\tF1') etisserant@0: self.Bind(wx.EVT_MENU, self.OnHelpDS301Menu, etisserant@0: id=wxID_OBJDICTEDITHELPMENUITEMS0) lbessard@72: if Html_Window: lbessard@72: parent.Append(help='', id=wxID_OBJDICTEDITHELPMENUITEMS1, lbessard@72: kind=wx.ITEM_NORMAL, text='CAN Festival Docs\tF2') lbessard@72: parent.Append(help='', id=wxID_OBJDICTEDITHELPMENUITEMS2, lbessard@72: kind=wx.ITEM_NORMAL, text='About') lbessard@72: self.Bind(wx.EVT_MENU, self.OnHelpCANFestivalMenu, lbessard@72: id=wxID_OBJDICTEDITHELPMENUITEMS1) lbessard@72: self.Bind(wx.EVT_MENU, self.OnAboutMenu, lbessard@72: id=wxID_OBJDICTEDITHELPMENUITEMS2) etisserant@0: etisserant@0: def _init_coll_FileMenu_Items(self, parent): etisserant@0: # generated method, don't edit etisserant@0: etisserant@0: parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS5, etisserant@0: kind=wx.ITEM_NORMAL, text='New\tCTRL+N') etisserant@0: parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS0, etisserant@0: kind=wx.ITEM_NORMAL, text='Open\tCTRL+O') etisserant@0: parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS1, etisserant@0: kind=wx.ITEM_NORMAL, text='Save\tCTRL+S') etisserant@0: parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS6, etisserant@0: kind=wx.ITEM_NORMAL, text='Save As...\tALT+S') etisserant@0: parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS2, etisserant@0: kind=wx.ITEM_NORMAL, text='Close\tCTRL+W') etisserant@0: parent.AppendSeparator() lbessard@59: # parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS7, lbessard@59: # kind=wx.ITEM_NORMAL, text='Import XML file') etisserant@0: parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS8, etisserant@0: kind=wx.ITEM_NORMAL, text='Build Dictionary\tCTRL+B') etisserant@0: parent.AppendSeparator() etisserant@0: parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS4, etisserant@0: kind=wx.ITEM_NORMAL, text='Exit') etisserant@0: self.Bind(wx.EVT_MENU, self.OnOpenMenu, etisserant@0: id=wxID_OBJDICTEDITFILEMENUITEMS0) etisserant@0: self.Bind(wx.EVT_MENU, self.OnSaveMenu, etisserant@0: id=wxID_OBJDICTEDITFILEMENUITEMS1) etisserant@0: self.Bind(wx.EVT_MENU, self.OnCloseMenu, etisserant@0: id=wxID_OBJDICTEDITFILEMENUITEMS2) etisserant@0: self.Bind(wx.EVT_MENU, self.OnQuitMenu, etisserant@0: id=wxID_OBJDICTEDITFILEMENUITEMS4) etisserant@0: self.Bind(wx.EVT_MENU, self.OnNewMenu, etisserant@0: id=wxID_OBJDICTEDITFILEMENUITEMS5) etisserant@0: self.Bind(wx.EVT_MENU, self.OnSaveAsMenu, etisserant@0: id=wxID_OBJDICTEDITFILEMENUITEMS6) lbessard@59: # self.Bind(wx.EVT_MENU, self.OnImportMenu, lbessard@59: # id=wxID_OBJDICTEDITFILEMENUITEMS7) etisserant@0: self.Bind(wx.EVT_MENU, self.OnExportMenu, etisserant@0: id=wxID_OBJDICTEDITFILEMENUITEMS8) etisserant@0: etisserant@0: def _init_coll_AddMenu_Items(self, parent): etisserant@0: # generated method, don't edit etisserant@0: etisserant@0: parent.Append(help='', id=wxID_OBJDICTEDITADDMENUITEMS0, etisserant@0: kind=wx.ITEM_NORMAL, text='SDO Server') etisserant@0: parent.Append(help='', id=wxID_OBJDICTEDITADDMENUITEMS1, etisserant@0: kind=wx.ITEM_NORMAL, text='SDO Client') etisserant@0: parent.Append(help='', id=wxID_OBJDICTEDITADDMENUITEMS2, etisserant@0: kind=wx.ITEM_NORMAL, text='PDO Transmit') etisserant@0: parent.Append(help='', id=wxID_OBJDICTEDITADDMENUITEMS3, etisserant@0: kind=wx.ITEM_NORMAL, text='PDO Receive') etisserant@0: parent.Append(help='', id=wxID_OBJDICTEDITADDMENUITEMS4, etisserant@0: kind=wx.ITEM_NORMAL, text='Map Variable') etisserant@0: parent.Append(help='', id=wxID_OBJDICTEDITADDMENUITEMS5, etisserant@0: kind=wx.ITEM_NORMAL, text='User Type') etisserant@0: self.Bind(wx.EVT_MENU, self.OnAddSDOServerMenu, etisserant@0: id=wxID_OBJDICTEDITADDMENUITEMS0) etisserant@0: self.Bind(wx.EVT_MENU, self.OnAddSDOClientMenu, etisserant@0: id=wxID_OBJDICTEDITADDMENUITEMS1) etisserant@0: self.Bind(wx.EVT_MENU, self.OnAddPDOTransmitMenu, etisserant@0: id=wxID_OBJDICTEDITADDMENUITEMS2) etisserant@0: self.Bind(wx.EVT_MENU, self.OnAddPDOReceiveMenu, etisserant@0: id=wxID_OBJDICTEDITADDMENUITEMS3) etisserant@0: self.Bind(wx.EVT_MENU, self.OnAddMapVariableMenu, etisserant@0: id=wxID_OBJDICTEDITADDMENUITEMS4) etisserant@0: self.Bind(wx.EVT_MENU, self.OnAddUserTypeMenu, etisserant@0: id=wxID_OBJDICTEDITADDMENUITEMS5) etisserant@0: etisserant@0: def _init_coll_HelpBar_Fields(self, parent): etisserant@0: # generated method, don't edit etisserant@0: parent.SetFieldsCount(3) etisserant@0: etisserant@0: parent.SetStatusText(number=0, text='') etisserant@0: parent.SetStatusText(number=1, text='') etisserant@0: parent.SetStatusText(number=2, text='') etisserant@0: etisserant@0: parent.SetStatusWidths([100, 110, -1]) etisserant@0: etisserant@0: def _init_utils(self): etisserant@0: # generated method, don't edit etisserant@0: self.menuBar1 = wx.MenuBar() etisserant@0: self.menuBar1.SetEvtHandlerEnabled(True) etisserant@0: etisserant@0: self.FileMenu = wx.Menu(title='') etisserant@0: etisserant@0: self.EditMenu = wx.Menu(title='') etisserant@0: etisserant@0: self.AddMenu = wx.Menu(title='') etisserant@0: etisserant@0: self.HelpMenu = wx.Menu(title='') etisserant@0: etisserant@0: self._init_coll_menuBar1_Menus(self.menuBar1) etisserant@0: self._init_coll_FileMenu_Items(self.FileMenu) etisserant@0: self._init_coll_EditMenu_Items(self.EditMenu) etisserant@0: self._init_coll_AddMenu_Items(self.AddMenu) etisserant@0: self._init_coll_HelpMenu_Items(self.HelpMenu) etisserant@0: etisserant@0: def _init_ctrls(self, prnt): etisserant@0: # generated method, don't edit etisserant@0: wx.Frame.__init__(self, id=wxID_OBJDICTEDIT, name='objdictedit', etisserant@0: parent=prnt, pos=wx.Point(149, 178), size=wx.Size(1000, 700), etisserant@0: style=wx.DEFAULT_FRAME_STYLE, title='Objdictedit') etisserant@0: self._init_utils() etisserant@0: self.SetClientSize(wx.Size(1000, 700)) etisserant@0: self.SetMenuBar(self.menuBar1) etisserant@0: self.Bind(wx.EVT_CLOSE, self.OnCloseFrame, id=wxID_OBJDICTEDIT) etisserant@0: etisserant@0: self.FileOpened = wx.Notebook(id=wxID_OBJDICTEDITFILEOPENED, etisserant@0: name='FileOpened', parent=self, pos=wx.Point(0, 0), etisserant@0: size=wx.Size(0, 0), style=0) etisserant@0: self.FileOpened.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, etisserant@0: self.OnFileSelectedChanged, id=wxID_OBJDICTEDITFILEOPENED) etisserant@0: etisserant@0: self.HelpBar = wx.StatusBar(id=wxID_OBJDICTEDITHELPBAR, name='HelpBar', etisserant@0: parent=self, style=wxST_SIZEGRIP) etisserant@0: self._init_coll_HelpBar_Fields(self.HelpBar) etisserant@0: self.SetStatusBar(self.HelpBar) etisserant@0: etisserant@0: def __init__(self, parent): etisserant@0: self._init_ctrls(parent) etisserant@0: self.HtmlFrameOpened = [] etisserant@0: etisserant@0: self.Manager = NodeManager() etisserant@0: for filepath in filesOpen: etisserant@0: self.Manager.OpenFileInCurrent(filepath) etisserant@0: new_editingpanel = EditingPanel(self, self.Manager) etisserant@0: self.FileOpened.AddPage(new_editingpanel, "") etisserant@0: self.FileOpened.SetSelection(self.Manager.GetCurrentNodeIndex()) etisserant@0: if self.Manager.CurrentDS302Defined(): etisserant@0: self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS8, True) etisserant@0: else: etisserant@0: self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS8, False) etisserant@0: self.RefreshEditMenu() etisserant@0: self.RefreshBufferState() etisserant@0: self.RefreshProfileMenu() etisserant@0: self.RefreshMainMenu() etisserant@0: etisserant@0: self.RefreshBufferState() etisserant@0: self.RefreshTitle() etisserant@0: self.RefreshMainMenu() etisserant@0: etisserant@0: def GetNoteBook(self): etisserant@0: return self.FileOpened etisserant@0: etisserant@0: def OnAddSDOServerMenu(self, event): etisserant@0: self.Manager.AddSDOServerToCurrent() etisserant@0: self.RefreshBufferState() etisserant@0: self.RefreshCurrentIndexList() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnAddSDOClientMenu(self, event): etisserant@0: self.Manager.AddSDOClientToCurrent() etisserant@0: self.RefreshBufferState() etisserant@0: self.RefreshCurrentIndexList() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnAddPDOTransmitMenu(self, event): etisserant@0: self.Manager.AddPDOTransmitToCurrent() etisserant@0: self.RefreshBufferState() etisserant@0: self.RefreshCurrentIndexList() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnAddPDOReceiveMenu(self, event): etisserant@0: self.Manager.AddPDOReceiveToCurrent() etisserant@0: self.RefreshBufferState() etisserant@0: self.RefreshCurrentIndexList() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnAddMapVariableMenu(self, event): etisserant@0: self.AddMapVariable() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnAddUserTypeMenu(self, event): etisserant@0: self.AddUserType() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnFileSelectedChanged(self, event): lbessard@43: selected = event.GetSelection() etisserant@37: # At init selected = -1 etisserant@37: if selected >= 0: etisserant@37: self.Manager.ChangeCurrentNode(selected) etisserant@37: self.RefreshBufferState() etisserant@37: self.RefreshProfileMenu() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnHelpDS301Menu(self, event): lbessard@72: find_index = False etisserant@0: selected = self.FileOpened.GetSelection() etisserant@0: if selected >= 0: etisserant@0: window = self.FileOpened.GetPage(selected) etisserant@0: result = window.GetSelection() etisserant@0: if result: lbessard@72: find_index = True etisserant@0: index, subIndex = result etisserant@0: result = OpenPDFDocIndex(index) etisserant@0: if type(result) == StringType: etisserant@0: message = wxMessageDialog(self, result, "ERROR", wxOK|wxICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() lbessard@72: if not find_index: lbessard@72: result = OpenPDFDocIndex(None) lbessard@72: if type(result) == StringType: lbessard@72: message = wxMessageDialog(self, result, "ERROR", wxOK|wxICON_ERROR) lbessard@72: message.ShowModal() lbessard@72: message.Destroy() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnHelpCANFestivalMenu(self, event): etisserant@0: self.OpenHtmlFrame("CAN Festival Reference", "../doc/canfestival.html", wx.Size(1000, 600)) etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnAboutMenu(self, event): etisserant@0: self.OpenHtmlFrame("About CAN Festival", "../doc/about.html", wx.Size(500, 450)) etisserant@0: event.Skip() etisserant@0: etisserant@0: def OpenHtmlFrame(self, title, file, size): etisserant@0: if title not in self.HtmlFrameOpened: etisserant@0: self.HtmlFrameOpened.append(title) etisserant@0: window = HtmlFrame(self, self.HtmlFrameOpened) etisserant@0: window.SetTitle(title) etisserant@0: window.SetHtmlPage(file) etisserant@0: window.SetClientSize(size) etisserant@0: window.Show() etisserant@0: etisserant@0: def OnQuitMenu(self, event): etisserant@0: self.Close() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnCloseFrame(self, event): etisserant@0: if self.Manager.OneFileHasChanged(): etisserant@0: dialog = wxMessageDialog(self, "There are changes, do you want to save?", "Close Application", wxYES_NO|wxCANCEL|wxICON_QUESTION) etisserant@0: answer = dialog.ShowModal() etisserant@0: dialog.Destroy() etisserant@0: if answer == wxID_YES: etisserant@0: self.Manager.ChangeCurrentNode(0) etisserant@0: for i in xrange(self.FileOpened.GetPageCount()): etisserant@0: if self.Manager.CurrentIsSaved(): etisserant@0: self.Manager.CloseCurrent() etisserant@0: else: etisserant@0: self.Save() etisserant@0: self.Manager.CloseCurrent(True) etisserant@0: event.Skip() etisserant@0: elif answer == wxID_NO: etisserant@0: for i in xrange(self.FileOpened.GetPageCount()): etisserant@0: self.Manager.CloseCurrent(True) etisserant@0: wxCallAfter(self.Close) etisserant@0: event.Skip() etisserant@0: else: etisserant@0: event.Skip() etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Refresh Functions etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: def RefreshTitle(self): etisserant@0: if self.FileOpened.GetPageCount() > 0: etisserant@0: self.SetTitle("Objdictedit - %s"%self.Manager.GetCurrentFilename()) etisserant@0: else: etisserant@0: self.SetTitle("Objdictedit") etisserant@0: etisserant@0: def OnRefreshMenu(self, event): etisserant@0: self.RefreshCurrentIndexList() etisserant@0: event.Skip() etisserant@0: etisserant@0: def RefreshCurrentIndexList(self): etisserant@0: selected = self.FileOpened.GetSelection() etisserant@0: window = self.FileOpened.GetPage(selected) etisserant@0: window.RefreshIndexList() etisserant@0: etisserant@0: def RefreshStatusBar(self): etisserant@0: window = self.FileOpened.GetPage(self.FileOpened.GetSelection()) etisserant@0: selection = window.GetSelection() etisserant@0: if selection: etisserant@0: index, subIndex = selection etisserant@0: if self.Manager.IsCurrentEntry(index): etisserant@0: self.HelpBar.SetStatusText("Index: 0x%04X"%index, 0) etisserant@0: self.HelpBar.SetStatusText("Subindex: 0x%02X"%subIndex, 1) etisserant@0: entryinfos = self.Manager.GetEntryInfos(index) etisserant@0: name = entryinfos["name"] etisserant@0: category = "Optional" etisserant@0: if entryinfos["need"]: etisserant@0: category = "Mandatory" etisserant@0: struct = "VAR" etisserant@0: number = "" etisserant@0: if entryinfos["struct"] & OD_IdenticalIndexes: etisserant@0: number = " possibly defined %d times"%entryinfos["nbmax"] etisserant@0: if entryinfos["struct"] & OD_IdenticalSubindexes: etisserant@0: struct = "REC" etisserant@0: elif entryinfos["struct"] & OD_MultipleSubindexes: etisserant@0: struct = "ARRAY" etisserant@0: text = "%s: %s entry of struct %s%s."%(name,category,struct,number) etisserant@0: self.HelpBar.SetStatusText(text, 2) etisserant@0: else: etisserant@0: for i in xrange(3): etisserant@0: self.HelpBar.SetStatusText("", i) etisserant@0: else: etisserant@0: for i in xrange(3): etisserant@0: self.HelpBar.SetStatusText("", i) etisserant@0: etisserant@0: def RefreshMainMenu(self): etisserant@0: if self.FileOpened.GetPageCount() > 0: etisserant@0: self.menuBar1.EnableTop(1, True) etisserant@0: self.menuBar1.EnableTop(2, True) etisserant@0: self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS1, True) etisserant@0: self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS2, True) etisserant@0: self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS6, True) etisserant@0: self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS8, True) etisserant@0: else: etisserant@0: self.menuBar1.EnableTop(1, False) etisserant@0: self.menuBar1.EnableTop(2, False) etisserant@0: self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS1, False) etisserant@0: self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS2, False) etisserant@0: self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS6, False) etisserant@0: self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS8, False) etisserant@0: etisserant@0: def RefreshEditMenu(self): etisserant@0: if self.FileOpened.GetPageCount() > 0: etisserant@0: undo, redo = self.Manager.GetCurrentBufferState() etisserant@0: self.EditMenu.FindItemByPosition(2).Enable(undo) etisserant@0: self.EditMenu.FindItemByPosition(3).Enable(redo) etisserant@0: else: etisserant@0: self.EditMenu.FindItemByPosition(2).Enable(False) etisserant@0: self.EditMenu.FindItemByPosition(3).Enable(False) etisserant@0: etisserant@0: def RefreshProfileMenu(self): etisserant@0: profile = self.Manager.GetCurrentProfileName() etisserant@0: edititem = self.EditMenu.FindItemByPosition(8) etisserant@0: length = self.AddMenu.GetMenuItemCount() etisserant@0: for i in xrange(length-6): etisserant@0: additem = self.AddMenu.FindItemByPosition(6) etisserant@0: self.AddMenu.Delete(additem.GetId()) etisserant@0: if profile not in ("None", "DS-301"): etisserant@0: edititem.SetText("%s Profile"%profile) etisserant@0: edititem.Enable(True) etisserant@0: self.AddMenu.AppendSeparator() etisserant@0: for text, indexes in self.Manager.GetCurrentSpecificMenu(): etisserant@0: new_id = wx.NewId() etisserant@0: self.AddMenu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=text) etisserant@0: self.Bind(wx.EVT_MENU, self.GetProfileCallBack(text), id=new_id) etisserant@0: else: etisserant@0: edititem.SetText("Other Profile") etisserant@0: edititem.Enable(False) etisserant@0: etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Buffer Functions etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: def RefreshBufferState(self): etisserant@0: fileopened = self.Manager.GetAllFilenames() etisserant@0: for idx, filename in enumerate(fileopened): etisserant@0: self.FileOpened.SetPageText(idx, filename) etisserant@0: self.RefreshEditMenu() etisserant@0: self.RefreshTitle() etisserant@0: etisserant@0: def OnUndoMenu(self, event): etisserant@0: self.Manager.LoadCurrentPrevious() etisserant@0: self.RefreshCurrentIndexList() etisserant@0: self.RefreshBufferState() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnRedoMenu(self, event): etisserant@0: self.Manager.LoadCurrentNext() etisserant@0: self.RefreshCurrentIndexList() etisserant@0: self.RefreshBufferState() etisserant@0: event.Skip() etisserant@0: etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Load and Save Funtions etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: def OnNewMenu(self, event): etisserant@0: self.FilePath = "" etisserant@0: dialog = CreateNodeDialog(self) etisserant@0: if dialog.ShowModal() == wxID_OK: etisserant@0: name, id, type = dialog.GetValues() lbessard@59: profile, filepath = dialog.GetProfile() lbessard@59: NMT = dialog.GetNMTManagement() lbessard@59: options = dialog.GetOptions() lbessard@59: result = self.Manager.CreateNewNode(name, id, type, profile, filepath, NMT, options) lbessard@59: if not IsOfType(result, StringType): lbessard@59: new_editingpanel = EditingPanel(self, self.Manager) lbessard@59: self.FileOpened.AddPage(new_editingpanel, "") lbessard@59: self.FileOpened.SetSelection(self.Manager.GetCurrentNodeIndex()) lbessard@59: self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS8, False) lbessard@59: if "DS302" in options: lbessard@59: self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS8, True) lbessard@59: self.RefreshBufferState() lbessard@59: self.RefreshProfileMenu() lbessard@59: self.RefreshMainMenu() etisserant@0: else: lbessard@59: message = wxMessageDialog(self, result, "ERROR", wxOK|wxICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnOpenMenu(self, event): etisserant@0: filepath = self.Manager.GetCurrentFilePath() etisserant@0: if filepath != "": etisserant@0: directory = os.path.dirname(filepath) etisserant@0: else: etisserant@0: directory = os.getcwd() lbessard@59: dialog = wxFileDialog(self, "Choose a file", directory, "", "OD files (*.od)|*.od|All files|*.*", wxOPEN|wxCHANGE_DIR) etisserant@0: if dialog.ShowModal() == wxID_OK: etisserant@0: filepath = dialog.GetPath() etisserant@0: if os.path.isfile(filepath): etisserant@0: result = self.Manager.OpenFileInCurrent(filepath) etisserant@0: if type(result) != StringType: etisserant@0: new_editingpanel = EditingPanel(self, self.Manager) etisserant@0: self.FileOpened.AddPage(new_editingpanel, "") etisserant@0: self.FileOpened.SetSelection(self.Manager.GetCurrentNodeIndex()) etisserant@0: if self.Manager.CurrentDS302Defined(): etisserant@0: self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS8, True) etisserant@0: else: etisserant@0: self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS8, False) etisserant@0: self.RefreshEditMenu() etisserant@0: self.RefreshBufferState() etisserant@0: self.RefreshProfileMenu() etisserant@0: self.RefreshMainMenu() etisserant@0: else: etisserant@0: message = wxMessageDialog(self, e.args[0], "Error", wxOK|wxICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() etisserant@0: dialog.Destroy() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnSaveMenu(self, event): etisserant@0: self.Save() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnSaveAsMenu(self, event): etisserant@0: self.SaveAs() lbessard@30: event.Skip() etisserant@0: etisserant@0: def Save(self): etisserant@0: result = self.Manager.SaveCurrentInFile() etisserant@0: if not result: etisserant@0: self.SaveAs() etisserant@0: elif type(result) != StringType: etisserant@0: self.RefreshBufferState() etisserant@0: else: etisserant@0: message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() etisserant@0: etisserant@0: def SaveAs(self): etisserant@0: filepath = self.Manager.GetCurrentFilePath() etisserant@0: if filepath != "": etisserant@0: directory, filename = os.path.split(filepath) etisserant@0: else: etisserant@0: directory, filename = os.getcwd(), "%s.od"%self.Manager.GetCurrentNodeInfos()[0] lbessard@59: dialog = wxFileDialog(self, "Choose a file", directory, filename, "OD files (*.od)|*.od|All files|*.*", wxSAVE|wxOVERWRITE_PROMPT|wxCHANGE_DIR) etisserant@0: if dialog.ShowModal() == wxID_OK: etisserant@0: filepath = dialog.GetPath() etisserant@0: if os.path.isdir(os.path.dirname(filepath)): etisserant@0: result = self.Manager.SaveCurrentInFile(filepath) etisserant@0: if type(result) != StringType: etisserant@0: self.RefreshBufferState() etisserant@0: else: etisserant@0: message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() etisserant@0: else: etisserant@0: message = wxMessageDialog(self, "%s is not a valid folder!"%os.path.dirname(filepath), "Error", wxOK|wxICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() etisserant@0: dialog.Destroy() etisserant@0: etisserant@0: def OnCloseMenu(self, event): etisserant@0: answer = wxID_YES etisserant@0: result = self.Manager.CloseCurrent() etisserant@0: if not result: etisserant@0: dialog = wxMessageDialog(self, "There are changes, do you want to save?", "Close File", wxYES_NO|wxCANCEL|wxICON_QUESTION) etisserant@0: answer = dialog.ShowModal() etisserant@0: dialog.Destroy() etisserant@0: if answer == wxID_YES: etisserant@0: self.OnSaveMenu(event) etisserant@0: if self.Manager.CurrentIsSaved(): etisserant@0: self.Manager.CloseCurrent() etisserant@0: elif answer == wxID_NO: etisserant@0: self.Manager.CloseCurrent(True) etisserant@0: if self.FileOpened.GetPageCount() > self.Manager.GetBufferNumber(): etisserant@0: current = self.FileOpened.GetSelection() etisserant@0: self.FileOpened.DeletePage(current) etisserant@0: if self.FileOpened.GetPageCount() > 0: etisserant@0: self.FileOpened.SetSelection(min(current, self.FileOpened.GetPageCount() - 1)) etisserant@0: self.RefreshBufferState() etisserant@0: self.RefreshMainMenu() etisserant@0: event.Skip() etisserant@0: etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Import and Export Functions etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: def OnImportMenu(self, event): lbessard@59: dialog = wxFileDialog(self, "Choose a file", os.getcwd(), "", "XML OD files (*.xml)|*.xml|All files|*.*", wxOPEN|wxCHANGE_DIR) etisserant@0: if dialog.ShowModal() == wxID_OK: etisserant@0: filepath = dialog.GetPath() etisserant@0: if os.path.isfile(filepath): etisserant@0: result = self.Manager.ImportCurrentFromFile(filepath) etisserant@0: if result: etisserant@0: if self.FileOpened.GetPageCount() == 0: etisserant@0: new_editingpanel = EditingPanel(self, self.Manager) etisserant@0: self.FileOpened.AddPage(new_editingpanel, "") etisserant@0: self.FileOpened.SetSelection(self.Manager.GetCurrentNodeIndex()) etisserant@0: self.RefreshBufferState() etisserant@0: self.RefreshCurrentIndexList() etisserant@0: self.RefreshProfileMenu() etisserant@0: self.RefreshMainMenu() etisserant@0: message = wxMessageDialog(self, "Import successful", "Information", wxOK|wxICON_INFORMATION) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() etisserant@0: dialog.Destroy() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnExportMenu(self, event): lbessard@59: dialog = wxFileDialog(self, "Choose a file", os.getcwd(), self.Manager.GetCurrentNodeInfos()[0], "CANFestival OD files (*.c)|*.c|All files|*.*", wxSAVE|wxOVERWRITE_PROMPT|wxCHANGE_DIR) etisserant@0: if dialog.ShowModal() == wxID_OK: etisserant@0: filepath = dialog.GetPath() etisserant@0: if os.path.isdir(os.path.dirname(filepath)): etisserant@0: path, extend = os.path.splitext(filepath) etisserant@0: if extend in ("", "."): etisserant@0: filepath = path + ".c" etisserant@0: result = self.Manager.ExportCurrentToFile(filepath) etisserant@0: if result: etisserant@0: message = wxMessageDialog(self, "Export successful", "Information", wxOK|wxICON_INFORMATION) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() etisserant@0: else: etisserant@0: message = wxMessageDialog(self, "%s is not a valid folder!"%os.path.dirname(filepath), "Error", wxOK|wxICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() etisserant@0: dialog.Destroy() etisserant@0: event.Skip() etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Editing Profiles functions etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: def OnCommunicationMenu(self, event): etisserant@0: dictionary,current = self.Manager.GetCurrentCommunicationLists() etisserant@0: self.EditProfile("Edit DS-301 Profile", dictionary, current) etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnOtherCommunicationMenu(self, event): etisserant@0: dictionary,current = self.Manager.GetCurrentDS302Lists() etisserant@0: self.EditProfile("Edit DS-301 Profile", dictionary, current) etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnEditProfileMenu(self, event): etisserant@0: title = "Edit %s Profile"%self.Manager.GetCurrentProfileName() etisserant@0: dictionary,current = self.Manager.GetCurrentProfileLists() etisserant@0: self.EditProfile(title, dictionary, current) etisserant@0: event.Skip() etisserant@0: etisserant@0: def EditProfile(self, title, dictionary, current): etisserant@0: dialog = CommunicationDialog(self) etisserant@0: dialog.SetTitle(title) etisserant@0: dialog.SetIndexDictionary(dictionary) etisserant@0: dialog.SetCurrentList(current) etisserant@0: dialog.RefreshLists() etisserant@0: if dialog.ShowModal() == wxID_OK: etisserant@0: new_profile = dialog.GetCurrentList() etisserant@0: addinglist = [] etisserant@0: removinglist = [] etisserant@0: for index in new_profile: etisserant@0: if index not in current: etisserant@0: addinglist.append(index) etisserant@0: for index in current: etisserant@0: if index not in new_profile: etisserant@0: removinglist.append(index) etisserant@0: self.Manager.ManageEntriesOfCurrent(addinglist, removinglist) etisserant@0: self.Manager.GenerateMapList() etisserant@0: self.Manager.BufferCurrentNode() etisserant@0: self.RefreshBufferState() etisserant@0: self.RefreshCurrentIndexList() etisserant@0: dialog.Destroy() etisserant@0: etisserant@0: def GetProfileCallBack(self, text): etisserant@0: def ProfileCallBack(event): etisserant@0: self.Manager.AddSpecificEntryToCurrent(text) etisserant@0: self.RefreshBufferState() etisserant@0: self.RefreshCurrentIndexList() etisserant@0: event.Skip() etisserant@0: return ProfileCallBack etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Edit Node informations function etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: def OnNodeInfosMenu(self, event): etisserant@0: dialog = NodeInfosDialog(self) etisserant@0: name,id,type = self.Manager.GetCurrentNodeInfos() etisserant@0: profile = self.Manager.GetCurrentProfileName() etisserant@0: dialog.SetProfiles([profile]) etisserant@0: dialog.SetValues(name, id, type, profile) etisserant@0: if dialog.ShowModal() == wxID_OK: etisserant@0: name,id,type,profile = dialog.GetValues() etisserant@0: self.Manager.SetCurrentNodeInfos(name, id, type) etisserant@0: self.RefreshBufferState() etisserant@0: self.RefreshProfileMenu() etisserant@0: event.Skip() etisserant@0: etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Add User Types and Variables etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: def AddMapVariable(self): lbessard@39: index = self.Manager.GetCurrentNextMapIndex() lbessard@39: if index: lbessard@39: dialog = MapVariableDialog(self) lbessard@39: dialog.SetIndex(index) lbessard@39: if dialog.ShowModal() == wxID_OK: lbessard@39: index, name, struct, number = dialog.GetValues() lbessard@39: result = self.Manager.AddMapVariableToCurrent(index, name, struct, number) lbessard@39: if type(result) != StringType: lbessard@39: self.RefreshBufferState() lbessard@39: self.RefreshCurrentIndexList() lbessard@39: else: lbessard@39: message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR) lbessard@39: message.ShowModal() lbessard@39: message.Destroy() lbessard@39: dialog.Destroy() lbessard@39: else: lbessard@39: message = wxMessageDialog(self, result, "No map variable index left!", wxOK|wxICON_ERROR) lbessard@39: message.ShowModal() lbessard@39: message.Destroy() etisserant@0: etisserant@0: def AddUserType(self): etisserant@0: dialog = UserTypeDialog(self) etisserant@0: dialog.SetTypeList(self.Manager.GetCustomisableTypes()) etisserant@0: if dialog.ShowModal() == wxID_OK: etisserant@0: type, min, max, length = dialog.GetValues() etisserant@0: result = self.Manager.AddUserTypeToCurrent(type, min, max, length) etisserant@0: if not IsOfType(result, StringType): etisserant@0: self.RefreshBufferState() etisserant@0: self.RefreshCurrentIndexList() etisserant@0: else: etisserant@0: message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() etisserant@0: dialog.Destroy() etisserant@0: etisserant@0: etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Editing Communication Dialog etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: etisserant@0: [wxID_COMMUNICATIONDIALOG, wxID_COMMUNICATIONDIALOGMAINPANEL, etisserant@0: wxID_COMMUNICATIONDIALOGPOSSIBLEINDEXES, wxID_COMMUNICATIONDIALOGCURRENTINDEXES, etisserant@0: wxID_COMMUNICATIONDIALOGSELECT, wxID_COMMUNICATIONDIALOGUNSELECT, etisserant@0: wxID_COMMUNICATIONDIALOGSTATICTEXT1, wxID_COMMUNICATIONDIALOGSTATICTEXT2 etisserant@0: ] = [wx.NewId() for _init_ctrls in range(8)] etisserant@0: etisserant@0: class CommunicationDialog(wx.Dialog): etisserant@0: def _init_coll_flexGridSizer1_Items(self, parent): etisserant@0: # generated method, don't edit etisserant@0: etisserant@0: parent.AddWindow(self.MainPanel, 0, border=0, flag=0) etisserant@0: etisserant@0: def _init_sizers(self): etisserant@0: # generated method, don't edit etisserant@0: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) etisserant@0: etisserant@0: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) etisserant@0: etisserant@0: self.SetSizer(self.flexGridSizer1) etisserant@0: etisserant@0: def _init_ctrls(self, prnt): etisserant@0: # generated method, don't edit etisserant@0: wx.Dialog.__init__(self, id=wxID_COMMUNICATIONDIALOG, etisserant@0: name='CommunicationDialog', parent=prnt, pos=wx.Point(234, 216), etisserant@0: size=wx.Size(726, 437), style=wx.DEFAULT_DIALOG_STYLE, etisserant@0: title='Edit Communication Profile') etisserant@0: self.SetClientSize(wx.Size(726, 437)) etisserant@0: etisserant@0: self.MainPanel = wx.Panel(id=wxID_COMMUNICATIONDIALOGMAINPANEL, etisserant@0: name='MainPanel', parent=self, pos=wx.Point(0, 0), etisserant@0: size=wx.Size(688, 382), style=wx.TAB_TRAVERSAL) etisserant@0: self.MainPanel.SetAutoLayout(True) etisserant@0: etisserant@0: self.PossibleIndexes = wx.ListBox(choices=[], etisserant@0: id=wxID_COMMUNICATIONDIALOGPOSSIBLEINDEXES, etisserant@0: name='PossibleIndexes', parent=self.MainPanel, pos=wx.Point(40, etisserant@0: 48), size=wx.Size(280, 320), style=wxLB_EXTENDED) etisserant@0: self.PossibleIndexes.Bind(wx.EVT_LEFT_DCLICK, self.OnPossibleIndexesDClick, etisserant@0: id=wxID_COMMUNICATIONDIALOGPOSSIBLEINDEXES) etisserant@0: etisserant@0: self.CurrentIndexes = wx.ListBox(choices=[], etisserant@0: id=wxID_COMMUNICATIONDIALOGCURRENTINDEXES, name='CurrentIndexes', etisserant@0: parent=self.MainPanel, pos=wx.Point(400, 48), size=wx.Size(280, etisserant@0: 320), style=wxLB_EXTENDED) etisserant@0: self.CurrentIndexes.Bind(wx.EVT_LEFT_DCLICK, self.OnCurrentIndexesDClick, etisserant@0: id=wxID_COMMUNICATIONDIALOGCURRENTINDEXES) etisserant@0: etisserant@0: self.Select = wx.Button(id=wxID_COMMUNICATIONDIALOGSELECT, label='>>', etisserant@0: name='Select', parent=self.MainPanel, pos=wx.Point(345, 136), etisserant@0: size=wx.Size(32, 32), style=0) etisserant@0: self.Select.Bind(wx.EVT_BUTTON, self.OnSelectButton, etisserant@0: id=wxID_COMMUNICATIONDIALOGSELECT) etisserant@0: etisserant@0: self.Unselect = wx.Button(id=wxID_COMMUNICATIONDIALOGUNSELECT, etisserant@0: label='<<', name='Unselect', parent=self.MainPanel, etisserant@0: pos=wx.Point(345, 216), size=wx.Size(32, 30), style=0) etisserant@0: self.Unselect.Bind(wx.EVT_BUTTON, self.OnUnselectButton, etisserant@0: id=wxID_COMMUNICATIONDIALOGUNSELECT) etisserant@0: etisserant@0: self.staticText1 = wx.StaticText(id=wxID_COMMUNICATIONDIALOGSTATICTEXT1, lbessard@59: label='Possible Profile Indexes:', name='staticText1', etisserant@0: parent=self.MainPanel, pos=wx.Point(40, 24), size=wx.Size(156, etisserant@0: 17), style=0) etisserant@0: etisserant@0: self.staticText2 = wx.StaticText(id=wxID_COMMUNICATIONDIALOGSTATICTEXT2, lbessard@59: label='Current Profile Indexes:', name='staticText2', etisserant@0: parent=self.MainPanel, pos=wx.Point(400, 24), size=wx.Size(152, etisserant@0: 17), style=0) etisserant@0: etisserant@0: self._init_sizers() etisserant@0: etisserant@0: def __init__(self, parent): etisserant@0: self._init_ctrls(parent) etisserant@0: self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL) etisserant@0: self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_CENTER) etisserant@0: self.AllList = [] etisserant@0: self.CurrentList = [] etisserant@0: self.IndexDictionary = {} etisserant@0: etisserant@0: def SetIndexDictionary(self, dictionary): etisserant@0: self.IndexDictionary = dictionary etisserant@0: etisserant@0: def SetCurrentList(self, list): etisserant@0: self.CurrentList = [] etisserant@0: self.CurrentList.extend(list) etisserant@0: self.CurrentList.sort() etisserant@0: etisserant@0: def GetCurrentList(self): etisserant@0: return self.CurrentList etisserant@0: etisserant@0: def RefreshLists(self): etisserant@0: self.PossibleIndexes.Clear() etisserant@0: self.CurrentIndexes.Clear() etisserant@0: self.AllList = [] etisserant@0: for index in self.IndexDictionary.iterkeys(): etisserant@0: if index not in self.CurrentList: etisserant@0: self.AllList.append(index) etisserant@0: self.AllList.sort() etisserant@0: for index in self.AllList: etisserant@37: self.PossibleIndexes.Append("0x%04X %s"%(index, self.IndexDictionary[index][0])) etisserant@0: for index in self.CurrentList: etisserant@0: if index in self.IndexDictionary: etisserant@37: self.CurrentIndexes.Append("0x%04X %s"%(index, self.IndexDictionary[index][0])) etisserant@0: etisserant@0: def OnPossibleIndexesDClick(self, event): etisserant@0: self.SelectPossible() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnCurrentIndexesDClick(self, event): etisserant@0: self.UnselectCurrent() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnSelectButton(self, event): etisserant@0: self.SelectPossible() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnUnselectButton(self, event): etisserant@0: self.UnselectCurrent() etisserant@0: event.Skip() etisserant@0: etisserant@0: def SelectPossible(self): etisserant@0: selected = self.PossibleIndexes.GetSelections() etisserant@0: for i in selected: etisserant@0: self.CurrentList.append(self.AllList[i]) etisserant@0: self.CurrentList.sort() etisserant@0: self.RefreshLists() etisserant@0: etisserant@0: def UnselectCurrent(self): etisserant@0: selected = self.CurrentIndexes.GetSelections() etisserant@0: for i in selected: etisserant@0: if not self.IndexDictionary[self.CurrentList[i]][1]: etisserant@0: self.CurrentList.pop(i) etisserant@0: self.CurrentList.sort() etisserant@0: self.RefreshLists() etisserant@0: etisserant@0: etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Create Map Variable Dialog etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: etisserant@0: [wxID_MAPVARIABLEDIALOG, wxID_MAPVARIABLEDIALOGINDEX, etisserant@0: wxID_MAPVARIABLEDIALOGINDEXNAME, wxID_MAPVARIABLEDIALOGMAINPANEL, etisserant@0: wxID_MAPVARIABLEDIALOGNUMBER, wxID_MAPVARIABLEDIALOGRADIOBUTTON1, etisserant@0: wxID_MAPVARIABLEDIALOGRADIOBUTTON2, wxID_MAPVARIABLEDIALOGRADIOBUTTON3, etisserant@0: wxID_MAPVARIABLEDIALOGSTATICTEXT1, wxID_MAPVARIABLEDIALOGSTATICTEXT2, etisserant@0: wxID_MAPVARIABLEDIALOGSTATICTEXT3, wxID_MAPVARIABLEDIALOGSTATICTEXT4, etisserant@0: ] = [wx.NewId() for _init_ctrls in range(12)] etisserant@0: etisserant@0: class MapVariableDialog(wx.Dialog): etisserant@0: def _init_coll_flexGridSizer1_Items(self, parent): etisserant@0: # generated method, don't edit etisserant@0: etisserant@0: parent.AddWindow(self.MainPanel, 0, border=0, flag=0) etisserant@0: etisserant@0: def _init_sizers(self): etisserant@0: # generated method, don't edit etisserant@0: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) etisserant@0: etisserant@0: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) etisserant@0: etisserant@0: self.SetSizer(self.flexGridSizer1) etisserant@0: etisserant@0: def _init_ctrls(self, prnt): etisserant@0: # generated method, don't edit etisserant@0: wx.Dialog.__init__(self, id=wxID_MAPVARIABLEDIALOG, etisserant@0: name='CommunicationDialog', parent=prnt, pos=wx.Point(376, 223), etisserant@0: size=wx.Size(444, 186), style=wx.DEFAULT_DIALOG_STYLE, etisserant@0: title='Add Map Variable') etisserant@0: self.SetClientSize(wx.Size(444, 186)) etisserant@0: etisserant@0: self.MainPanel = wx.Panel(id=wxID_MAPVARIABLEDIALOGMAINPANEL, etisserant@0: name='MainPanel', parent=self, pos=wx.Point(0, 0), etisserant@0: size=wx.Size(431, 142), style=wx.TAB_TRAVERSAL) etisserant@0: self.MainPanel.SetAutoLayout(True) etisserant@0: etisserant@0: self.staticText1 = wx.StaticText(id=wxID_MAPVARIABLEDIALOGSTATICTEXT1, lbessard@59: label='Index:', name='staticText1', parent=self.MainPanel, etisserant@0: pos=wx.Point(24, 24), size=wx.Size(156, 17), style=0) etisserant@0: lbessard@39: self.Index = wx.TextCtrl(id=wxID_MAPVARIABLEDIALOGINDEX, name='Index', lbessard@39: parent=self.MainPanel, pos=wx.Point(24, 48), size=wx.Size(152, lbessard@39: 25), style=0, value='0x2000') lbessard@39: lbessard@39: self.staticText3 = wx.StaticText(id=wxID_MAPVARIABLEDIALOGSTATICTEXT3, lbessard@59: label='Name:', name='staticText3', parent=self.MainPanel, lbessard@39: pos=wx.Point(24, 80), size=wx.Size(47, 17), style=0) lbessard@39: lbessard@39: self.IndexName = wx.TextCtrl(id=wxID_MAPVARIABLEDIALOGINDEXNAME, lbessard@39: name='IndexName', parent=self.MainPanel, pos=wx.Point(24, 104), lbessard@39: size=wx.Size(152, 24), style=0, value='Undefined') lbessard@39: lbessard@39: self.staticText2 = wx.StaticText(id=wxID_MAPVARIABLEDIALOGSTATICTEXT2, lbessard@59: label='Type:', name='staticText2', parent=self.MainPanel, lbessard@39: pos=wx.Point(208, 24), size=wx.Size(38, 17), style=0) lbessard@39: etisserant@0: self.radioButton1 = wx.RadioButton(id=wxID_MAPVARIABLEDIALOGRADIOBUTTON1, etisserant@0: label='VAR', name='radioButton1', parent=self.MainPanel, lbessard@39: pos=wx.Point(208, 48), size=wx.Size(72, 24), style=wxRB_GROUP) etisserant@0: self.radioButton1.SetValue(True) etisserant@0: self.radioButton1.Bind(wx.EVT_RADIOBUTTON, self.OnRadioButton1Click, etisserant@0: id=wxID_MAPVARIABLEDIALOGRADIOBUTTON1) etisserant@0: etisserant@0: self.radioButton2 = wx.RadioButton(id=wxID_MAPVARIABLEDIALOGRADIOBUTTON2, lbessard@39: label='ARRAY', name='radioButton2', parent=self.MainPanel, lbessard@39: pos=wx.Point(208, 72), size=wx.Size(80, 24), style=wxRB_SINGLE) etisserant@0: self.radioButton2.SetValue(False) etisserant@0: self.radioButton2.Bind(wx.EVT_RADIOBUTTON, self.OnRadioButton2Click, etisserant@0: id=wxID_MAPVARIABLEDIALOGRADIOBUTTON2) etisserant@0: etisserant@0: self.radioButton3 = wx.RadioButton(id=wxID_MAPVARIABLEDIALOGRADIOBUTTON3, lbessard@39: label='REC', name='radioButton3', parent=self.MainPanel, lbessard@39: pos=wx.Point(208, 96), size=wx.Size(96, 24), style=wxRB_SINGLE) etisserant@0: self.radioButton3.SetValue(False) etisserant@0: self.radioButton3.Bind(wx.EVT_RADIOBUTTON, self.OnRadioButton3Click, etisserant@0: id=wxID_MAPVARIABLEDIALOGRADIOBUTTON3) etisserant@0: etisserant@0: self.staticText4 = wx.StaticText(id=wxID_MAPVARIABLEDIALOGSTATICTEXT4, lbessard@59: label='Number:', name='staticText4', parent=self.MainPanel, etisserant@0: pos=wx.Point(312, 80), size=wx.Size(88, 16), style=0) etisserant@0: etisserant@0: self.Number = wx.TextCtrl(id=wxID_MAPVARIABLEDIALOGNUMBER, etisserant@0: name='Number', parent=self.MainPanel, pos=wx.Point(312, 104), etisserant@0: size=wx.Size(112, 24), style=wx.TE_RIGHT, value='0') etisserant@0: etisserant@0: self._init_sizers() etisserant@0: etisserant@0: def __init__(self, parent): etisserant@0: self._init_ctrls(parent) etisserant@0: self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL) etisserant@0: self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_CENTER) etisserant@0: self.staticText4.Enable(False) etisserant@0: self.Number.Enable(False) etisserant@0: lbessard@39: def SetIndex(self, index): lbessard@39: self.Index.SetValue("0x%04X"%index) lbessard@39: etisserant@0: def GetValues(self): etisserant@0: if self.radioButton1.GetValue(): etisserant@0: struct = 1 lbessard@43: elif self.radioButton2.GetValue(): lbessard@43: struct = 3 etisserant@0: elif self.radioButton3.GetValue(): etisserant@0: struct = 7 etisserant@0: name = self.IndexName.GetValue() etisserant@0: index = eval(self.Index.GetValue()) etisserant@0: number = eval(self.Number.GetValue()) etisserant@0: return index, name, struct, number etisserant@0: etisserant@0: def OnRadioButton1Click(self, event): lbessard@39: self.EnableNumberTyping(False) etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnRadioButton2Click(self, event): lbessard@39: self.EnableNumberTyping(True) etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnRadioButton3Click(self, event): lbessard@39: self.EnableNumberTyping(True) lbessard@39: event.Skip() lbessard@39: lbessard@39: def EnableNumberTyping(self, enable): lbessard@39: self.staticText4.Enable(enable) lbessard@39: self.Number.Enable(enable) etisserant@0: etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Create User Type Dialog etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: etisserant@0: [wxID_USERTYPEDIALOG, wxID_USERTYPEDIALOGLENGTH, wxID_USERTYPEDIALOGMAINPANEL, etisserant@0: wxID_USERTYPEDIALOGMAX, wxID_USERTYPEDIALOGMIN, etisserant@0: wxID_USERTYPEDIALOGSTATICBOX1, wxID_USERTYPEDIALOGSTATICTEXT1, etisserant@0: wxID_USERTYPEDIALOGSTATICTEXT2, wxID_USERTYPEDIALOGSTATICTEXT3, etisserant@0: wxID_USERTYPEDIALOGSTATICTEXT4, wxID_USERTYPEDIALOGTYPE, etisserant@0: ] = [wx.NewId() for _init_ctrls in range(11)] etisserant@0: etisserant@0: class UserTypeDialog(wx.Dialog): etisserant@0: def _init_coll_flexGridSizer1_Items(self, parent): etisserant@0: # generated method, don't edit etisserant@0: etisserant@0: parent.AddWindow(self.MainPanel, 0, border=0, flag=0) etisserant@0: etisserant@0: def _init_sizers(self): etisserant@0: # generated method, don't edit etisserant@0: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) etisserant@0: etisserant@0: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) etisserant@0: etisserant@0: self.SetSizer(self.flexGridSizer1) etisserant@0: etisserant@0: def _init_ctrls(self, prnt): etisserant@0: # generated method, don't edit etisserant@0: wx.Dialog.__init__(self, id=wxID_USERTYPEDIALOG, name='UserTypeDialog', etisserant@0: parent=prnt, pos=wx.Point(376, 223), size=wx.Size(444, 228), etisserant@0: style=wx.DEFAULT_DIALOG_STYLE, title='Add User Type') etisserant@0: self.SetClientSize(wx.Size(444, 228)) etisserant@0: etisserant@0: self.MainPanel = wx.Panel(id=wxID_USERTYPEDIALOGMAINPANEL, etisserant@0: name='MainPanel', parent=self, pos=wx.Point(0, 0), etisserant@0: size=wx.Size(431, 182), style=wx.TAB_TRAVERSAL) etisserant@0: self.MainPanel.SetAutoLayout(True) etisserant@0: etisserant@0: self.staticText1 = wx.StaticText(id=wxID_USERTYPEDIALOGSTATICTEXT1, lbessard@59: label='Type:', name='staticText1', parent=self.MainPanel, etisserant@0: pos=wx.Point(24, 24), size=wx.Size(156, 17), style=0) etisserant@0: etisserant@0: self.Type = wx.Choice(choices=[], id=wxID_USERTYPEDIALOGTYPE, etisserant@0: name='Type', parent=self.MainPanel, pos=wx.Point(24, 48), etisserant@0: size=wx.Size(160, 24), style=0) etisserant@0: self.Type.Bind(wx.EVT_CHOICE, self.OnTypeChoice, etisserant@0: id=wxID_USERTYPEDIALOGTYPE) etisserant@0: lbessard@39: self.staticBox1 = wx.StaticBox(id=wxID_USERTYPEDIALOGSTATICBOX1, lbessard@39: label='Values', name='staticBox1', parent=self.MainPanel, lbessard@39: pos=wx.Point(200, 24), size=wx.Size(224, 144), style=0) lbessard@39: lbessard@39: self.staticText2 = wx.StaticText(id=wxID_USERTYPEDIALOGSTATICTEXT2, lbessard@59: label='Minimum:', name='staticText2', parent=self.MainPanel, lbessard@39: pos=wx.Point(216, 48), size=wx.Size(67, 17), style=0) lbessard@39: lbessard@39: self.Min = wx.TextCtrl(id=wxID_USERTYPEDIALOGMIN, name='Min', lbessard@39: parent=self.MainPanel, pos=wx.Point(296, 48), size=wx.Size(112, lbessard@39: 24), style=wx.TE_RIGHT, value='0') lbessard@39: lbessard@39: self.staticText3 = wx.StaticText(id=wxID_USERTYPEDIALOGSTATICTEXT3, lbessard@59: label='Maximum:', name='staticText3', parent=self.MainPanel, lbessard@39: pos=wx.Point(216, 88), size=wx.Size(71, 17), style=0) lbessard@39: lbessard@39: self.Max = wx.TextCtrl(id=wxID_USERTYPEDIALOGMAX, name='Max', lbessard@39: parent=self.MainPanel, pos=wx.Point(296, 88), size=wx.Size(112, lbessard@39: 25), style=wx.TE_RIGHT, value='0') lbessard@39: lbessard@39: self.staticText4 = wx.StaticText(id=wxID_USERTYPEDIALOGSTATICTEXT4, lbessard@59: label='Length:', name='staticText4', parent=self.MainPanel, lbessard@39: pos=wx.Point(216, 128), size=wx.Size(52, 17), style=0) lbessard@39: lbessard@39: self.Length = wx.TextCtrl(id=wxID_USERTYPEDIALOGLENGTH, name='Length', lbessard@39: parent=self.MainPanel, pos=wx.Point(296, 128), size=wx.Size(112, lbessard@39: 25), style=wx.TE_RIGHT, value='0') lbessard@39: etisserant@0: self._init_sizers() etisserant@0: etisserant@0: def __init__(self, parent): etisserant@0: self._init_ctrls(parent) etisserant@0: self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL) etisserant@0: self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_CENTER) etisserant@0: self.TypeDictionary = {} etisserant@0: etisserant@0: def SetValues(self, min = None, max = None, length = None): etisserant@0: if min != None: etisserant@0: self.Min.SetValue(str(min)) etisserant@0: if max != None: etisserant@0: self.Max.SetValue(str(max)) etisserant@0: if length != None: etisserant@0: self.Length.SetValue(str(length)) etisserant@0: etisserant@0: def SetTypeList(self, typedic, type = None): etisserant@0: self.Type.Clear() etisserant@0: list = [] etisserant@0: for index, (name, valuetype) in typedic.iteritems(): etisserant@0: self.TypeDictionary[name] = (index, valuetype) etisserant@0: list.append((index, name)) etisserant@0: list.sort() etisserant@0: for index, name in list: etisserant@0: self.Type.Append(name) etisserant@0: if type != None: etisserant@0: self.Type.SetStringSelection(typedic[type][0]) etisserant@0: self.RefreshValues() etisserant@0: etisserant@0: def OnTypeChoice(self, event): etisserant@0: self.RefreshValues() etisserant@0: event.Skip() etisserant@0: etisserant@0: def RefreshValues(self): etisserant@0: name = self.Type.GetStringSelection() etisserant@0: if name != "": etisserant@0: valuetype = self.TypeDictionary[name][1] etisserant@0: if valuetype == 0: etisserant@0: self.staticText2.Enable(True) etisserant@0: self.staticText3.Enable(True) etisserant@0: self.staticText4.Enable(False) etisserant@0: self.Min.Enable(True) etisserant@0: self.Max.Enable(True) etisserant@0: self.Length.Enable(False) etisserant@0: elif valuetype == 1: etisserant@0: self.staticText2.Enable(False) etisserant@0: self.staticText3.Enable(False) etisserant@0: self.staticText4.Enable(True) etisserant@0: self.Min.Enable(False) etisserant@0: self.Max.Enable(False) etisserant@0: self.Length.Enable(True) etisserant@0: else: etisserant@0: self.staticText2.Enable(False) etisserant@0: self.staticText3.Enable(False) etisserant@0: self.staticText4.Enable(False) etisserant@0: self.Min.Enable(False) etisserant@0: self.Max.Enable(False) etisserant@0: self.Length.Enable(False) etisserant@0: etisserant@0: def GetValues(self): etisserant@0: name = self.Type.GetStringSelection() etisserant@0: type = self.TypeDictionary[name][0] etisserant@0: min = eval(self.Min.GetValue()) etisserant@0: max = eval(self.Max.GetValue()) etisserant@0: length = eval(self.Length.GetValue()) etisserant@0: return type, min, max, length etisserant@0: etisserant@0: etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Editing Node Infos Dialog etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: etisserant@0: [wxID_NODEINFOSDIALOG, wxID_NODEINFOSDIALOGMAINPANEL, etisserant@0: wxID_NODEINFOSDIALOGNAME, wxID_NODEINFOSDIALOGNODEID, etisserant@0: wxID_NODEINFOSDIALOGPROFILE, wxID_NODEINFOSDIALOGSTATICTEXT1, etisserant@0: wxID_NODEINFOSDIALOGSTATICTEXT2, wxID_NODEINFOSDIALOGSTATICTEXT3, etisserant@0: wxID_NODEINFOSDIALOGSTATICTEXT4, wxID_NODEINFOSDIALOGTYPE, etisserant@0: ] = [wx.NewId() for _init_ctrls in range(10)] etisserant@0: etisserant@0: class NodeInfosDialog(wx.Dialog): etisserant@0: def _init_coll_flexGridSizer1_Items(self, parent): etisserant@0: # generated method, don't edit etisserant@0: etisserant@0: parent.AddWindow(self.MainPanel, 0, border=0, flag=0) etisserant@0: etisserant@0: def _init_sizers(self): etisserant@0: # generated method, don't edit etisserant@0: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) etisserant@0: etisserant@0: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) etisserant@0: etisserant@0: self.SetSizer(self.flexGridSizer1) etisserant@0: etisserant@0: def _init_ctrls(self, prnt): etisserant@0: # generated method, don't edit etisserant@0: wx.Dialog.__init__(self, id=wxID_NODEINFOSDIALOG, etisserant@0: name='NodeInfosDialog', parent=prnt, pos=wx.Point(376, 223), etisserant@0: size=wx.Size(249, 250), style=wx.DEFAULT_DIALOG_STYLE, etisserant@0: title='Node Infos') etisserant@0: self.SetClientSize(wx.Size(249, 250)) etisserant@0: etisserant@0: self.MainPanel = wx.Panel(id=wxID_NODEINFOSDIALOGMAINPANEL, etisserant@0: name='MainPanel', parent=self, pos=wx.Point(0, 0), etisserant@0: size=wx.Size(231, 264), style=wx.TAB_TRAVERSAL) etisserant@0: self.MainPanel.SetAutoLayout(True) etisserant@0: etisserant@0: self.staticText1 = wx.StaticText(id=wxID_NODEINFOSDIALOGSTATICTEXT1, lbessard@59: label='Name:', lbessard@59: name='staticText1', parent=self.MainPanel, etisserant@0: pos=wx.Point(24, 24), size=wx.Size(156, 17), style=0) etisserant@0: lbessard@39: self.Name = wx.TextCtrl(id=wxID_NODEINFOSDIALOGNAME, name='Name', lbessard@39: parent=self.MainPanel, pos=wx.Point(24, 48), size=wx.Size(200, lbessard@39: 25), style=0, value='') lbessard@39: etisserant@0: self.staticText2 = wx.StaticText(id=wxID_NODEINFOSDIALOGSTATICTEXT2, lbessard@59: label='Node ID:', name='staticText2', parent=self.MainPanel, etisserant@0: pos=wx.Point(24, 80), size=wx.Size(67, 17), style=0) etisserant@0: lbessard@39: self.NodeID = wx.TextCtrl(id=wxID_NODEINFOSDIALOGNODEID, name='NodeID', lbessard@39: parent=self.MainPanel, pos=wx.Point(24, 104), size=wx.Size(200, lbessard@39: 25), style=wx.TE_RIGHT, value='') lbessard@39: etisserant@0: self.staticText3 = wx.StaticText(id=wxID_NODEINFOSDIALOGSTATICTEXT3, lbessard@59: label='Type:', name='staticText3', parent=self.MainPanel, etisserant@0: pos=wx.Point(24, 136), size=wx.Size(71, 17), style=0) etisserant@0: etisserant@0: self.Type = wx.Choice(choices=[], id=wxID_NODEINFOSDIALOGTYPE, etisserant@0: name='Type', parent=self.MainPanel, pos=wx.Point(24, 160), lbessard@39: size=wx.Size(200, 25), style=0) etisserant@0: etisserant@0: self.staticText4 = wx.StaticText(id=wxID_NODEINFOSDIALOGSTATICTEXT4, lbessard@59: label='Profile:', name='staticText4', parent=self.MainPanel, etisserant@0: pos=wx.Point(24, 192), size=wx.Size(47, 17), style=0) etisserant@0: etisserant@0: self.Profile = wx.Choice(choices=[], id=wxID_NODEINFOSDIALOGPROFILE, etisserant@0: name='Profile', parent=self.MainPanel, pos=wx.Point(24, 216), lbessard@39: size=wx.Size(200, 25), style=0) etisserant@0: etisserant@0: self._init_sizers() etisserant@0: etisserant@0: def __init__(self, parent): etisserant@0: self._init_ctrls(parent) etisserant@0: self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL) etisserant@0: self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_CENTER) etisserant@0: self.Type.Append("master") etisserant@0: self.Type.Append("slave") etisserant@0: self.staticText4.Hide() etisserant@0: self.Profile.Hide() lbessard@59: lbessard@59: EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK) lbessard@59: lbessard@59: def OnOK(self, event): lbessard@59: name = self.Name.GetValue() lbessard@59: if name != "": lbessard@59: good = not name[0].isdigit() lbessard@59: for item in name.split("_"): lbessard@59: good &= item.isalnum() lbessard@59: else: lbessard@59: good = False lbessard@59: if not good: lbessard@59: message = wxMessageDialog(self, "Node name can't be undefined or start with a digit and must be composed of alphanumerical characters or underscore!", "ERROR", wxOK|wxICON_ERROR) lbessard@59: message.ShowModal() lbessard@59: message.Destroy() lbessard@59: self.Name.SetFocus() lbessard@59: else: lbessard@59: self.EndModal(wxID_OK) etisserant@0: etisserant@0: def SetProfiles(self, profiles): etisserant@0: for profile in profiles: etisserant@0: self.Profile.Append(profile) etisserant@0: etisserant@0: def SetValues(self, name, id, type, profile): etisserant@0: self.Name.SetValue(name) etisserant@0: self.NodeID.SetValue("0x%02X"%id) etisserant@0: self.Type.SetStringSelection(type) etisserant@0: self.Profile.SetStringSelection(profile) etisserant@0: etisserant@0: def GetValues(self): etisserant@0: name = self.Name.GetValue() etisserant@0: nodeid = eval(self.NodeID.GetValue()) etisserant@0: type = self.Type.GetStringSelection() etisserant@0: profile = self.Profile.GetStringSelection() etisserant@0: return name, nodeid, type, profile etisserant@0: etisserant@0: etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Create New Node Dialog etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: etisserant@0: [wxID_CREATENODEDIALOG, wxID_CREATENODEDIALOGEMERGENCY, etisserant@0: wxID_CREATENODEDIALOGGENSYNC, wxID_CREATENODEDIALOGMAINPANEL, etisserant@0: wxID_CREATENODEDIALOGNAME, wxID_CREATENODEDIALOGNMT_HEARTBEAT, etisserant@0: wxID_CREATENODEDIALOGNMT_NODEGUARDING, wxID_CREATENODEDIALOGNMT_NONE, etisserant@0: wxID_CREATENODEDIALOGNODEID, wxID_CREATENODEDIALOGPROFILE, etisserant@0: wxID_CREATENODEDIALOGSAVECONFIG, wxID_CREATENODEDIALOGSTATICTEXT1, etisserant@0: wxID_CREATENODEDIALOGSTATICTEXT2, wxID_CREATENODEDIALOGSTATICTEXT3, etisserant@0: wxID_CREATENODEDIALOGSTATICTEXT4, wxID_CREATENODEDIALOGSTATICTEXT5, etisserant@0: wxID_CREATENODEDIALOGSTATICTEXT6, wxID_CREATENODEDIALOGSTOREEDS, etisserant@0: wxID_CREATENODEDIALOGTYPE, etisserant@0: ] = [wx.NewId() for _init_ctrls in range(19)] etisserant@0: etisserant@0: class CreateNodeDialog(wx.Dialog): etisserant@0: def _init_coll_flexGridSizer1_Items(self, parent): etisserant@0: # generated method, don't edit etisserant@0: etisserant@0: parent.AddWindow(self.MainPanel, 0, border=0, flag=0) etisserant@0: etisserant@0: def _init_sizers(self): etisserant@0: # generated method, don't edit etisserant@0: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) etisserant@0: etisserant@0: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) etisserant@0: etisserant@0: self.SetSizer(self.flexGridSizer1) etisserant@0: etisserant@0: def _init_ctrls(self, prnt): etisserant@0: # generated method, don't edit etisserant@0: wx.Dialog.__init__(self, id=wxID_CREATENODEDIALOG, etisserant@0: name='CreateNodeDialog', parent=prnt, pos=wx.Point(376, 223), etisserant@0: size=wx.Size(451, 316), style=wx.DEFAULT_DIALOG_STYLE, etisserant@0: title='Create a new Node') etisserant@0: self.SetClientSize(wx.Size(451, 316)) etisserant@0: etisserant@0: self.MainPanel = wx.Panel(id=wxID_CREATENODEDIALOGMAINPANEL, etisserant@0: name='MainPanel', parent=self, pos=wx.Point(0, 0), etisserant@0: size=wx.Size(440, 278), style=wx.TAB_TRAVERSAL) etisserant@0: self.MainPanel.SetAutoLayout(True) etisserant@0: etisserant@0: self.staticText1 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT1, lbessard@59: label='Name:', name='staticText1', parent=self.MainPanel, etisserant@0: pos=wx.Point(24, 24), size=wx.Size(156, 17), style=0) etisserant@0: etisserant@0: self.staticText2 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT2, lbessard@59: label='Node ID:', name='staticText2', parent=self.MainPanel, etisserant@0: pos=wx.Point(24, 80), size=wx.Size(67, 17), style=0) etisserant@0: etisserant@0: self.staticText3 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT3, lbessard@59: label='Type:', name='staticText3', parent=self.MainPanel, etisserant@0: pos=wx.Point(24, 136), size=wx.Size(71, 17), style=0) etisserant@0: etisserant@0: self.Type = wx.Choice(choices=[], id=wxID_CREATENODEDIALOGTYPE, etisserant@0: name='Type', parent=self.MainPanel, pos=wx.Point(24, 160), etisserant@0: size=wx.Size(200, 24), style=0) etisserant@0: etisserant@0: self.Name = wx.TextCtrl(id=wxID_CREATENODEDIALOGNAME, name='Name', etisserant@0: parent=self.MainPanel, pos=wx.Point(24, 48), size=wx.Size(200, etisserant@0: 25), style=0, value='') etisserant@0: etisserant@0: self.NodeID = wx.TextCtrl(id=wxID_CREATENODEDIALOGNODEID, name='NodeID', etisserant@0: parent=self.MainPanel, pos=wx.Point(24, 104), size=wx.Size(200, etisserant@0: 25), style=wx.TE_RIGHT, value='') etisserant@0: etisserant@0: self.staticText4 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT4, lbessard@59: label='Profile:', name='staticText4', parent=self.MainPanel, etisserant@0: pos=wx.Point(24, 192), size=wx.Size(47, 17), style=0) etisserant@0: etisserant@0: self.Profile = wx.Choice(choices=[], id=wxID_CREATENODEDIALOGPROFILE, etisserant@0: name='Profile', parent=self.MainPanel, pos=wx.Point(24, 216), etisserant@0: size=wx.Size(200, 24), style=0) etisserant@0: self.Profile.Bind(wx.EVT_CHOICE, self.OnProfileChoice, etisserant@0: id=wxID_CREATENODEDIALOGPROFILE) etisserant@0: etisserant@0: self.staticText5 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT5, lbessard@59: label='Network Management:', name='staticText5', etisserant@0: parent=self.MainPanel, pos=wx.Point(256, 24), size=wx.Size(152, etisserant@0: 16), style=0) etisserant@0: etisserant@0: self.NMT_None = wx.RadioButton(id=wxID_CREATENODEDIALOGNMT_NONE, etisserant@0: label='None', name='NMT_None', parent=self.MainPanel, etisserant@0: pos=wx.Point(256, 40), size=wx.Size(114, 24), style=0) etisserant@0: self.NMT_None.SetValue(True) etisserant@0: etisserant@0: self.NMT_NodeGuarding = wx.RadioButton(id=wxID_CREATENODEDIALOGNMT_NODEGUARDING, etisserant@0: label='Node Guarding', name='NMT_NodeGuarding', etisserant@0: parent=self.MainPanel, pos=wx.Point(256, 64), size=wx.Size(128, etisserant@0: 24), style=0) etisserant@0: self.NMT_NodeGuarding.SetValue(False) etisserant@0: etisserant@0: self.NMT_Heartbeat = wx.RadioButton(id=wxID_CREATENODEDIALOGNMT_HEARTBEAT, etisserant@0: label='Heartbeat', name='NMT_Heartbeat', parent=self.MainPanel, etisserant@0: pos=wx.Point(256, 88), size=wx.Size(114, 24), style=0) etisserant@0: self.NMT_Heartbeat.SetValue(False) etisserant@0: etisserant@0: self.staticText6 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT6, lbessard@59: label='Options:', name='staticText6', parent=self.MainPanel, etisserant@0: pos=wx.Point(256, 128), size=wx.Size(72, 17), style=0) etisserant@0: etisserant@0: self.DS302 = wx.CheckBox(id=wxID_CREATENODEDIALOGGENSYNC, etisserant@0: label='DS-302 Profile', name='DS302', parent=self.MainPanel, etisserant@0: pos=wx.Point(256, 144), size=wx.Size(128, 24), style=0) etisserant@0: self.DS302.SetValue(False) lbessard@59: self.DS302.Enable(False) etisserant@0: etisserant@0: self.GenSYNC = wx.CheckBox(id=wxID_CREATENODEDIALOGGENSYNC, etisserant@0: label='Generate SYNC', name='GenSYNC', parent=self.MainPanel, etisserant@0: pos=wx.Point(256, 168), size=wx.Size(128, 24), style=0) etisserant@0: self.GenSYNC.SetValue(False) etisserant@0: etisserant@0: self.Emergency = wx.CheckBox(id=wxID_CREATENODEDIALOGEMERGENCY, etisserant@0: label='Emergency support', name='Emergency', etisserant@0: parent=self.MainPanel, pos=wx.Point(256, 192), size=wx.Size(152, etisserant@0: 24), style=0) etisserant@0: self.Emergency.SetValue(False) lbessard@59: self.Emergency.Enable(False) etisserant@0: etisserant@0: self.SaveConfig = wx.CheckBox(id=wxID_CREATENODEDIALOGSAVECONFIG, etisserant@0: label='Save Configuration', name='SaveConfig', etisserant@0: parent=self.MainPanel, pos=wx.Point(256, 216), size=wx.Size(152, etisserant@0: 24), style=0) etisserant@0: self.SaveConfig.SetValue(False) lbessard@59: self.SaveConfig.Enable(False) lbessard@59: lbessard@59: # self.StoreEDS = wx.CheckBox(id=wxID_CREATENODEDIALOGSTOREEDS, lbessard@59: # label='Store EDS', name='StoreEDS', parent=self.MainPanel, lbessard@59: # pos=wx.Point(256, 240), size=wx.Size(144, 24), style=0) lbessard@59: # self.StoreEDS.SetValue(False) lbessard@59: etisserant@0: self._init_sizers() etisserant@0: etisserant@0: def __init__(self, parent): etisserant@0: self._init_ctrls(parent) etisserant@0: self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL) etisserant@0: self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_CENTER) lbessard@59: self.NodeID.SetValue("0x00") etisserant@0: self.Type.Append("master") etisserant@0: self.Type.Append("slave") etisserant@0: self.Type.SetStringSelection("slave") etisserant@0: self.ListProfile = {"None" : ""} etisserant@0: self.Profile.Append("None") etisserant@0: self.Directory = os.path.join(os.getcwd(), "config") etisserant@0: listfiles = os.listdir(self.Directory) etisserant@0: listfiles.sort() etisserant@0: for item in listfiles: etisserant@0: name, extend = os.path.splitext(item) etisserant@0: if os.path.isfile(os.path.join(self.Directory, item)) and extend == ".prf" and name != "DS-302": etisserant@0: self.ListProfile[name] = os.path.join(self.Directory, item) etisserant@0: self.Profile.Append(name) etisserant@0: self.Profile.Append("Other") etisserant@0: self.Profile.SetStringSelection("None") lbessard@59: self.Name.SetFocus() lbessard@59: lbessard@59: EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK) lbessard@59: lbessard@59: def OnOK(self, event): lbessard@59: name = self.Name.GetValue() lbessard@59: if name != "": lbessard@59: good = not name[0].isdigit() lbessard@59: for item in name.split("_"): lbessard@59: good &= item.isalnum() lbessard@59: else: lbessard@59: good = False lbessard@59: if not good: lbessard@59: message = wxMessageDialog(self, "Node name can't be undefined or start with a digit and must be composed of alphanumerical characters or underscore!", "ERROR", wxOK|wxICON_ERROR) lbessard@59: message.ShowModal() lbessard@59: message.Destroy() lbessard@59: self.Name.SetFocus() lbessard@59: else: lbessard@59: self.EndModal(wxID_OK) etisserant@0: etisserant@0: def GetValues(self): etisserant@0: name = self.Name.GetValue() etisserant@0: nodeid = 0 etisserant@0: if self.NodeID.GetValue() != "": etisserant@0: nodeid = eval(self.NodeID.GetValue()) etisserant@0: type = self.Type.GetStringSelection() etisserant@0: return name, nodeid, type etisserant@0: etisserant@0: def GetProfile(self): etisserant@0: name = self.Profile.GetStringSelection() etisserant@0: return name, self.ListProfile[name] etisserant@0: etisserant@0: def GetNMTManagement(self): etisserant@0: if self.NMT_None.GetValue(): etisserant@0: return "None" etisserant@0: elif self.NMT_NodeGuarding.GetValue(): etisserant@0: return "NodeGuarding" etisserant@0: elif self.NMT_Heartbeat.GetValue(): etisserant@0: return "Heartbeat" etisserant@0: return None etisserant@0: etisserant@0: def GetOptions(self): etisserant@0: options = [] etisserant@0: if self.DS302.GetValue(): etisserant@0: options.append("DS302") etisserant@0: if self.GenSYNC.GetValue(): etisserant@0: options.append("GenSYNC") etisserant@0: if self.Emergency.GetValue(): etisserant@0: options.append("Emergency") etisserant@0: if self.SaveConfig.GetValue(): etisserant@0: options.append("SaveConfig") lbessard@59: # if self.StoreEDS.GetValue(): lbessard@59: # options.append("StoreEDS") etisserant@0: return options etisserant@0: etisserant@0: def OnProfileChoice(self, event): etisserant@0: if self.Profile.GetStringSelection() == "Other": lbessard@59: dialog = wxFileDialog(self, "Choose a file", self.Directory, "", "OD Profile files (*.prf)|*.prf|All files|*.*", wxOPEN|wxCHANGE_DIR) etisserant@0: dialog.ShowModal() etisserant@0: filepath = dialog.GetPath() etisserant@0: dialog.Destroy() etisserant@0: if os.path.isfile(filepath): etisserant@0: name = os.path.splitext(os.path.basename(filepath))[0] etisserant@0: self.ListProfile[name] = filepath etisserant@0: length = self.Profile.GetCount() etisserant@0: self.Profile.Insert(name, length - 2) etisserant@0: self.Profile.SetStringSelection(name) etisserant@0: else: etisserant@0: self.Profile.SetStringSelection("None") etisserant@0: event.Skip() etisserant@0: etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Exception Handler etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: Max_Traceback_List_Size = 20 etisserant@0: etisserant@0: def Display_Exception_Dialog(e_type,e_value,e_tb): etisserant@0: trcbck_lst = [] etisserant@0: for i,line in enumerate(traceback.extract_tb(e_tb)): etisserant@0: trcbck = " " + str(i+1) + ". " etisserant@0: if line[0].find(os.getcwd()) == -1: etisserant@0: trcbck += "file : " + str(line[0]) + ", " etisserant@0: else: etisserant@0: trcbck += "file : " + str(line[0][len(os.getcwd()):]) + ", " etisserant@0: trcbck += "line : " + str(line[1]) + ", " + "function : " + str(line[2]) etisserant@0: trcbck_lst.append(trcbck) etisserant@0: etisserant@0: # Allow clicking.... etisserant@0: cap = wx.Window_GetCapture() etisserant@0: if cap: etisserant@0: cap.ReleaseMouse() etisserant@0: etisserant@0: dlg = wx.SingleChoiceDialog(None, etisserant@0: """ etisserant@0: An error happens. etisserant@0: etisserant@0: Click on OK for saving an error report. etisserant@0: etisserant@0: Please contact LOLITech at: etisserant@0: +33 (0)3 29 52 95 67 etisserant@0: bugs_objdictedit@lolitech.fr etisserant@0: etisserant@0: etisserant@0: Error: etisserant@0: """ + etisserant@0: str(e_type) + " : " + str(e_value), etisserant@0: "Error", etisserant@0: trcbck_lst) etisserant@0: try: etisserant@0: res = (dlg.ShowModal() == wx.ID_OK) etisserant@0: finally: etisserant@0: dlg.Destroy() etisserant@0: etisserant@0: return res etisserant@0: etisserant@0: def Display_Error_Dialog(e_value): etisserant@0: message = wxMessageDialog(None, str(e_value), "Error", wxOK|wxICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() etisserant@0: etisserant@0: def get_last_traceback(tb): etisserant@0: while tb.tb_next: etisserant@0: tb = tb.tb_next etisserant@0: return tb etisserant@0: etisserant@0: etisserant@0: def format_namespace(d, indent=' '): etisserant@0: return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()]) etisserant@0: etisserant@0: etisserant@0: ignored_exceptions = [] # a problem with a line in a module is only reported once per session etisserant@0: etisserant@0: def wxAddExceptHook(path, app_version='[No version]'):#, ignored_exceptions=[]): etisserant@0: etisserant@0: def handle_exception(e_type, e_value, e_traceback): etisserant@0: traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func etisserant@0: last_tb = get_last_traceback(e_traceback) etisserant@0: ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno) etisserant@0: if str(e_value).startswith("!!!"): etisserant@0: Display_Error_Dialog(e_value) etisserant@0: elif ex not in ignored_exceptions: etisserant@0: ignored_exceptions.append(ex) etisserant@0: result = Display_Exception_Dialog(e_type,e_value,e_traceback) etisserant@0: if result: etisserant@0: info = { etisserant@0: 'app-title' : wx.GetApp().GetAppName(), # app_title etisserant@0: 'app-version' : app_version, etisserant@0: 'wx-version' : wx.VERSION_STRING, etisserant@0: 'wx-platform' : wx.Platform, etisserant@0: 'python-version' : platform.python_version(), #sys.version.split()[0], etisserant@0: 'platform' : platform.platform(), etisserant@0: 'e-type' : e_type, etisserant@0: 'e-value' : e_value, etisserant@0: 'date' : time.ctime(), etisserant@0: 'cwd' : os.getcwd(), etisserant@0: } etisserant@0: if e_traceback: etisserant@0: info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value) etisserant@0: last_tb = get_last_traceback(e_traceback) etisserant@0: exception_locals = last_tb.tb_frame.f_locals # the locals at the level of the stack trace where the exception actually occurred etisserant@0: info['locals'] = format_namespace(exception_locals) etisserant@0: if 'self' in exception_locals: etisserant@0: info['self'] = format_namespace(exception_locals['self'].__dict__) etisserant@0: etisserant@0: output = open(path+os.sep+"bug_report_"+info['date'].replace(':','-').replace(' ','_')+".txt",'w') etisserant@0: lst = info.keys() etisserant@0: lst.sort() etisserant@0: for a in lst: etisserant@0: output.write(a+":\n"+str(info[a])+"\n\n") etisserant@0: etisserant@0: #sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args) etisserant@0: sys.excepthook = handle_exception etisserant@0: etisserant@0: if __name__ == '__main__': etisserant@0: app = wxPySimpleApp() etisserant@0: wxInitAllImageHandlers() etisserant@0: etisserant@0: # Install a exception handle for bug reports etisserant@0: wxAddExceptHook(os.getcwd(),__version__) etisserant@0: etisserant@0: frame = objdictedit(None) etisserant@0: etisserant@0: frame.Show() etisserant@0: app.MainLoop()