def CheckItem(self, path): """ """ item = self.ItemDico[path] file_path = "%s.py" % path info = Container.CheckClass(file_path) ### there is error in file if isinstance(info, tuple): ### Until it has parent, we redifine icon to inform user while item: ### change image self.SetItemImage(item, self.not_importedidx, wx.TreeItemIcon_Normal) ### next parent item item = self.GetItemParent(item) else: ### recompile if no error info = ReloadModule.recompile(Utilities.path_to_module(file_path)) ### if not error if not isinstance(info, (Exception, str)): ### change image self.SetItemImage(item, self.pythonfileidx, wx.TreeItemIcon_Normal)
def OnMotion(self, evt): """ Motion engine over item. """ item, flags = self.HitTest(evt.GetPosition()) if item and self.IsSelected(item) and ( flags & wx.TREE_HITTEST_ONITEMLABEL) and not evt.LeftIsDown(): path = self.GetItemPyData(item) if os.path.isdir(path): model_list = self.GetModelList(path) domain_list = self.GetDomainList(path) if domain_list: tip = '\n'.join(domain_list) elif model_list: tip = '\n'.join(model_list) else: tip = "" ### is last item else: module = Components.BlockFactory.GetModule(path) info = Container.CheckClass(path) if isinstance(info, tuple): doc = str(info) elif isinstance(module, tuple): doc = str(module) else: doc = inspect.getdoc(module) tip = doc if doc is not None else _( "No documentation for selected model.") self.SetToolTipString(tip.decode('utf-8')) else: self.SetToolTip(None) ### else the drag and drop dont run evt.Skip()
def OnItemDocumentation(self, evt): """ Display the item's documentation on miniFrame. """ item = self.GetSelection() path = self.GetItemPyData(item) name = self.GetItemText(item) module = Components.BlockFactory.GetModule(path) info = Container.CheckClass(path) if isinstance(info, tuple): doc = str(info) elif isinstance(module, tuple): doc = str(module) else: doc = inspect.getdoc(module) if doc: dlg = wx.lib.dialogs.ScrolledMessageDialog(self, doc, name) dlg.CenterOnParent(wx.BOTH) dlg.ShowModal() else: wx.MessageBox(_('No documentation for %s') % name, 'Info', wx.OK)
def InsertNewDomain(self, dName, parent, L=None): """ Recurcive function that insert new Domain on library panel. """ if not L: L = [] ### au depard seulement pour le parent de plus haut niveau (comme PowerSystem) if dName not in self.ItemDico.keys(): label = os.path.basename( dName) if not dName.startswith('http') else filter( lambda a: a != '', dName.split('/'))[-1] id = self.InsertItemBefore(parent, 0, label) self.SetItemImage(id, self.fldridx, wx.TreeItemIcon_Normal) self.SetItemImage(id, self.fldropenidx, wx.TreeItemIcon_Expanded) self.SetItemBold(id) self.ItemDico.update({dName: id}) self.SetPyData(id, dName) ### fin de la recursion if not L: return else: item = L.pop(0) assert not isinstance(item, unicode), _("Warning unicode item !") ### element a faire remonter dans la liste D = [] ### si le fils est un modele construit dans DEVSimPy if isinstance(item, str): ### le parent est recupere dans le Dico parent = self.ItemDico[dName] assert parent is not None ### path correspondant au parent parentPath = self.GetPyData(parent) ### remplacement des espaces item = item.strip() come_from_net = parentPath.startswith('http') ### suppression de l'extention su .cmd (model atomic lue a partir de __init__ donc pas d'extention) if item.endswith('.cmd'): ### gestion de l'importation de module (.py) associe au .cmd si le fichier .py n'a jamais ete decompressse (pour edition par exemple) if not come_from_net: path = os.path.join(parentPath, item) zf = ZipManager.Zip(path) module = zf.GetModule() image_file = zf.GetImage() else: path = parentPath + '/' + item + '.py' module = load_module_from_net(path) ### check error error = isinstance(module, Exception) ### change icon depending on the error and the presence of image in amd if error: img = self.not_importedidx elif image_file is not None: img = self.il.Add(image_file.ConvertToBitmap()) else: img = self.coupledidx ### insertion dans le tree id = self.InsertItemBefore(parent, 0, os.path.splitext(item)[0], img, img) self.SetPyData(id, path) elif item.endswith('.amd'): ### gestion de l'importation de module (.py) associe au .amd si le fichier .py n'a jamais ete decompressse (pour edition par exemple) if not come_from_net: path = os.path.join(parentPath, item) zf = ZipManager.Zip(path) module = zf.GetModule() image_file = zf.GetImage() else: path = parentPath + '/' + item + '.py' module = load_module_from_net(path) ### check error error = isinstance(module, Exception) ### change icon depending on the error and the presence of image in amd if error: img = self.not_importedidx elif image_file is not None: img = self.il.Add(image_file.ConvertToBitmap()) else: img = self.atomicidx ### insertion dans le tree id = self.InsertItemBefore(parent, 0, os.path.splitext(item)[0], img, img) self.SetPyData(id, path) else: path = os.path.join( parentPath, item + '.py') if not parentPath.startswith( 'http') else parentPath + '/' + item + '.py' info = Container.CheckClass(path) error = isinstance(info, tuple) img = self.not_importedidx if error else self.pythonfileidx ### insertion dans le tree id = self.InsertItemBefore(parent, 0, item, img, img) self.SetPyData(id, path) ### error info back propagation if error: while parent: self.SetItemImage(parent, self.not_importedidx, wx.TreeItemIcon_Normal) ### next parent item parent = self.GetItemParent(parent) ### insertion des donnees dans l'item et gestion du ItemDico self.ItemDico.update({os.path.join( parentPath, item, ): id}) ### si le fils est un sous repertoire contenant au moins un fichier (all dans __init__.py different de []) elif isinstance(item, dict) and item.values() != [[]]: ### nom a inserer dans l'arbe dName = os.path.basename(item.keys()[0]) ### nouveau parent parent = self.ItemDico[os.path.dirname( item.keys()[0])] if not dName.startswith( 'http') else self.ItemDico[item.keys()[0].replace( '/' + dName, '')] assert (parent is not None) ### insertion de fName sous parent id = self.InsertItemBefore(parent, 0, dName) self.SetItemImage(id, self.fldridx, wx.TreeItemIcon_Normal) self.SetItemImage(id, self.fldropenidx, wx.TreeItemIcon_Expanded) ### stockage du parent avec pour cle le chemin complet avec extention (pour l'import du moule dans le Dnd) self.ItemDico.update({item.keys()[0]: id}) self.SetPyData(id, item.keys()[0]) ### pour les fils du sous domain for elem in item.values()[0]: # si elem simple (modele couple ou atomic) if isinstance(elem, str): ### remplacement des espaces elem = elem.strip() #replace(' ','') ### parent provisoir p = self.ItemDico[item.keys()[0]] assert (p is not None) come_from_net = item.keys()[0].startswith('http') ### si model atomic if elem.endswith('.cmd'): ### gestion de l'importation de module (.py) associe au .amd si le fichier .py n'a jamais ete decompressse (pour edition par exemple) if not come_from_net: path = os.path.join(item.keys()[0], elem) zf = ZipManager.Zip(path) module = zf.GetModule() image_file = zf.GetImage() else: path = item.keys()[0] + '/' + elem + '.py' moduel = load_module_from_net(path) ### check error error = isinstance(module, Exception) ### change icon depending on the error and the presence of image in amd if error: img = self.not_importedidx elif image_file is not None: img = self.il.Add(image_file.ConvertToBitmap()) else: img = self.coupledidx ### insertion dans le tree id = self.InsertItemBefore( p, 0, os.path.splitext(elem)[0], img, img) self.SetPyData(id, path) elif elem.endswith('.amd'): ### gestion de l'importation de module (.py) associe au .amd si le fichier .py n'a jamais ete decompressse (pour edition par exemple) if not come_from_net: path = os.path.join(item.keys()[0], elem) zf = ZipManager.Zip(path) module = zf.GetModule() image_file = zf.GetImage() else: path = item.keys()[0] + '/' + elem + '.py' moduel = load_module_from_net(path) ### check error error = isinstance(module, Exception) ### change icon depending on the error and the presence of image in amd if error: img = self.not_importedidx elif image_file is not None: img = self.il.Add(image_file.ConvertToBitmap()) else: img = self.atomicidx ### insertion dans le tree id = self.InsertItemBefore( p, 0, os.path.splitext(elem)[0], img, img) self.SetPyData(id, path) else: path = os.path.join( item.keys()[0], elem + '.py') if not item.keys()[0].startswith( 'http' ) else item.keys()[0] + '/' + elem + '.py' info = Container.CheckClass(path) error = isinstance(info, tuple) img = self.not_importedidx if error else self.pythonfileidx ### insertion dans le tree id = self.InsertItemBefore(p, 0, elem, img, img) self.SetPyData(id, path) ### error info back propagation if error: ### insert error to the doc field while p: self.SetItemImage(p, self.not_importedidx, wx.TreeItemIcon_Normal) ### next parent item p = self.GetItemParent(p) self.ItemDico.update({ os.path.join(item.keys()[0], os.path.splitext(elem)[0]): id }) else: ### pour faire remonter l'info dans la liste D.append(elem) ### mise a jour avec le nom complet dName = item.keys()[0] ### for spash screen try: ### format the string depending the nature of the item if isinstance(item, dict): item = "%s from %s" % ( os.path.basename(item.keys()[0]), os.path.basename(os.path.dirname(item.keys()[0]))) else: item = "%s from %s" % (item, os.path.basename(dName)) pub.sendMessage('object.added', 'Loading %s domain...' % item) except: pass ### gestion de la recursion if D: return self.InsertNewDomain(dName, parent, L + D) else: return self.InsertNewDomain(dName, parent, L)