def DoLabelDialog(self, canvas): """ """ ### only for Block and Port when control is down if isinstance(self, Attributable): ### here for no-gui mode import LabelGUI import AttributeEditor diagram = canvas.GetDiagram() ### store old label before change it old_label = self.label ### ask new label d = LabelGUI.LabelDialog(canvas, self) d.ShowModal() ### update priority list if label is different and update panel properties only if is active if old_label in diagram.priority_list and old_label != self.label: ### find index of label priority list and replace it i = diagram.priority_list.index(old_label) diagram.priority_list[i] = self.label ### update of panel properties import wx mainW = wx.GetApp().GetTopWindow() nb1 = mainW.GetControlNotebook() if nb1.GetSelection() == 1: newContent = AttributeEditor(nb1.propPanel, wx.NewIdRef(), self, canvas) nb1.UpdatePropertiesPage(newContent)
def ShowAttributes(self, event): """ """ canvas = event.GetEventObject() diagram = canvas.GetDiagram() ### only for Block and Port when ctrl is down if isinstance(self, Attributable) and event.ControlDown(): ### store old label before change it old_label = self.label ### ask new label d = LabelGUI.LabelDialog(canvas, self) d.ShowModal() ### update priority list if label is different and update panel properties only if is active if old_label in diagram.priority_list and old_label != self.label: ### find index of label priority list and replace it i = diagram.priority_list.index(old_label) diagram.priority_list[i] = self.label ### update of panel properties mainW = wx.GetApp().GetTopWindow() nb1 = mainW.GetControlNotebook() if nb1.GetSelection() == 1: newContent = AttributeEditor(nb1.propPanel, wx.ID_ANY, self, canvas) nb1.UpdatePropertiesPage(newContent) ### update of code editor panel #print mainW._mgr.GetPane("editor").IsOk() event.Skip()
def SelectProp(self, evt): """ """ row, col = evt.GetRow(), evt.GetCol() table = self.GetTable() typ = table.dataTypes[row][1] prop = self.GetCellValue(row, 0) if prop == 'fill' or re.findall( "[.]*color[.]*", prop, flags=re.IGNORECASE): val = self.GetCellValue(row, 1) dlg = wx.ColourDialog(self.parent) dlg.GetColourData().SetChooseFull(True) if dlg.ShowModal() == wx.ID_OK: data = dlg.GetColourData() val = str([RGBToHEX(data.GetColour().Get())]) self.SetCellValue(row, 1, val) else: dlg.Destroy() return False dlg.Destroy() self.AcceptProp(row, col) elif prop == 'font': val = eval(self.GetCellValue(row, 1)) default_font = wx.Font(val[0], val[1], val[2], val[3], False, val[4]) data = wx.FontData() if sys.platform == 'win32': data.EnableEffects(True) data.SetAllowSymbols(False) data.SetInitialFont(default_font) data.SetRange(10, 30) dlg = wx.FontDialog(self.parent, data) if dlg.ShowModal() == wx.ID_OK: data = dlg.GetFontData() font = data.GetChosenFont() color = data.GetColour() val = [ font.GetPointSize(), font.GetFamily(), font.GetStyle(), font.GetWeight(), font.GetFaceName() ] self.SetCellValue(row, 1, str(val)) else: dlg.Destroy() return False dlg.Destroy() self.AcceptProp(row, col) elif prop == 'label': d = LabelGUI.LabelDialog(self.parent, self.parent.model) d.ShowModal() self.SetCellValue(row, 1, str(self.parent.model.label)) self.AcceptProp(row, col) elif prop == 'image_path': dlg = ib.ImageDialog(self, os.path.join(HOME_PATH)) dlg.Centre() if dlg.ShowModal() == wx.ID_OK: val = os.path.normpath(dlg.GetFile()) if val != self.GetCellValue(row, 1): self.SetCellValue(row, 1, val) self.canvas.UpdateShapes([self.parent.model]) else: dlg.Destroy() return False dlg.Destroy() self.AcceptProp(row, col) elif 'filename' in str(prop).lower(): wcd = _('Data files All files (*)|*') val = self.GetCellValue(row, 1) default_dir = os.path.dirname(val) if os.path.exists( os.path.dirname(val)) else HOME_PATH dlg = wx.FileDialog(self, message=_("Select file ..."), defaultDir=default_dir, defaultFile="", wildcard=wcd, style=wx.OPEN | wx.CHANGE_DIR) if dlg.ShowModal() == wx.ID_OK: val = os.path.normpath(dlg.GetPath()) if val != self.GetCellValue(row, 1): self.SetCellValue(row, 1, val) self.canvas.UpdateShapes([self.parent.model]) else: dlg.Destroy() return False dlg.Destroy() self.AcceptProp(row, col) elif prop == 'python_path': model = self.parent.model ### for .amd or .cmd if model.model_path != '': wcd = _( 'Atomic DEVSimPy model (*.amd)|*.amd|Coupled DEVSimPy model (*.cmd)|*.cmd|All files (*)|*' ) else: wcd = _('Python files (*.py)|*.py|All files (*)|*') default_dir = os.path.dirname(model.python_path) if os.path.exists( os.path.dirname(model.python_path)) else DOMAIN_PATH dlg = wx.FileDialog(self, message=_("Select file ..."), defaultDir=default_dir, defaultFile="", wildcard=wcd, style=wx.OPEN | wx.CHANGE_DIR) if dlg.ShowModal() == wx.ID_OK: new_python_path = os.path.normpath(dlg.GetPath()) ### if the user would like to load a compressed python file, he just give the name of compressed file that contain the python file if zipfile.is_zipfile(new_python_path): zf = zipfile.ZipFile(new_python_path, 'r') new_python_path = os.path.join( new_python_path, filter( lambda f: f.endswith('.py') and f != 'plugins.py', zf.namelist())[0]) ### update model path model.model_path = os.path.dirname(new_python_path) self.SetCellValue(row, 1, new_python_path) # behavioral args update (because depends of the new class coming from new python file) new_cls = Components.GetClass(new_python_path) if inspect.isclass(new_cls): ### update attributes (behavioral ang graphic) model.args = Components.GetArgs(new_cls) model.SetAttributes(Attributable.GRAPHICAL_ATTR) ### TODO: when ScopeGUI and DiskGUI will be amd models, delete this line) ### delete xlabel and ylabel attributes if exist model.RemoveAttribute('xlabel') model.RemoveAttribute('ylabel') ### Update of DEVSimPy model from new python behavioral file (ContainerBlock is not considered because he did not behavioral) if new_cls.__name__ in ('To_Disk', 'MessagesCollector'): model.__class__ = Container.DiskGUI elif new_cls.__name__ == 'QuickScope': model.__class__ = Container.ScopeGUI model.AddAttribute("xlabel") model.AddAttribute("ylabel") elif True in map(lambda a: 'DomainStructure' in str(a), new_cls.__bases__): model.__class__ = Container.ContainerBlock else: model.__class__ = Container.CodeBlock ### if we change the python file from zipfile we compresse the new python file and we update the python_path value if zipfile.is_zipfile(model.model_path): zf = ZipManager.Zip(model.model_path) zf.Update([new_python_path]) #model.model_path = ### update flag and color if bad filename if model.bad_filename_path_flag: model.bad_filename_path_flag = False else: Container.MsgBoxError(evt, self, new_cls) dlg.Destroy() return False else: dlg.Destroy() return False dlg.Destroy() self.AcceptProp(row, col) elif typ == "list": frame = ListEditor(self, wx.ID_ANY, _('List editor'), values=self.GetCellValue(row, 1)) if frame.ShowModal() == wx.ID_CANCEL: self.SetCellValue(row, 1, frame.GetValueAsString()) else: frame.Destroy() self.AcceptProp(row, col) elif typ == 'dict': frame = DictionaryEditor(self, wx.ID_ANY, _('List editor'), values=self.GetCellValue(row, 1)) if frame.ShowModal() == wx.ID_CANCEL: self.SetCellValue(row, 1, frame.GetValueAsString()) else: frame.Destroy() self.AcceptProp(row, col) elif 'choice' in typ: self.AcceptProp(row, col) else: pass ### all properties grid update (because the python classe has been changed) ### here, because OnAcceptProp should be executed before if prop == 'python_path': ### Update table from new model table.UpdateRowBehavioralData(model) self.SetTable(table, False) self.ForceRefresh() self.AutoSizeColumns() # code updating if isinstance(model, Achievable): new_code = CodeCB(self.parent, wx.ID_ANY, model) #self.parent.boxH.Remove(0) if hasattr(self.parent, '_boxH'): # DeleteWindows work better in vista if wx.VERSION_STRING < '4.0': self.parent._boxH.DeleteWindows() self.parent._boxH.AddWindow(new_code, 1, wx.EXPAND, userData='code') else: self.parent._boxH.Clear() self.parent._boxH.Add(new_code, 1, wx.EXPAND, userData='code') self.parent._boxH.Layout() else: sys.stdout.write("_boxH is unknown!")