From 955638cbe2ae7fd60a5d296ea16948e522700d43 Mon Sep 17 00:00:00 2001 From: Capocchi L Date: Tue, 12 May 2020 16:00:12 +0200 Subject: [PATCH] bug fix --- Components.py | 16 ++++++++-------- LibraryTree.py | 2 +- SimulationGUI.py | 8 ++++---- Utilities.py | 4 +++- ZipManager.py | 25 +++++++++++++------------ 5 files changed, 29 insertions(+), 26 deletions(-) diff --git a/Components.py b/Components.py index 67dc5fd1..1c9ea03f 100644 --- a/Components.py +++ b/Components.py @@ -742,19 +742,19 @@ def GetModule(filename): module_name = os.path.basename(filename).split('.py')[0] # find and load module - try: + #try: #name, ext = os.path.splitext(module_name) #pkg = '.'.join(modulename.split('.')[0:-1]) #module = importlib.import_module(name, package=pkg) - f, fn, description = imp.find_module(module_name, [dir_name]) - module = imp.load_module(module_name, f, fn, description) - f.close() - return module + f, fn, description = imp.find_module(module_name, [dir_name]) + module = imp.load_module(module_name, f, fn, description) + f.close() + return module - except Exception as info: - sys.stderr.write(_("Module %s not imported from %s!\n"%(module_name,dir_name))) - return sys.exc_info() + #except Exception as info: + # sys.stderr.write(_("Module %s not imported from %s!\n"%(module_name,dir_name))) + # return sys.exc_info() @staticmethod def GetBlock(filename, label): diff --git a/LibraryTree.py b/LibraryTree.py index 4e7a21a0..3c2b0913 100644 --- a/LibraryTree.py +++ b/LibraryTree.py @@ -1059,7 +1059,7 @@ def OnItemRefresh(self, evt): finally: if self.GetItemImage(item) != 1: - NotificationMessage(_('Information'), _("Model %s has been succeffully updated!")%self.GetItemText(item), self, flag=wx.ICON_ERROR, timeout=5) + NotificationMessage(_('Information'), _("Model %s has been succeffully updated!")%self.GetItemText(item), self, timeout=5) ### def OnItemEdit(self, evt): diff --git a/SimulationGUI.py b/SimulationGUI.py index 1b6c862a..8dcf3dd2 100644 --- a/SimulationGUI.py +++ b/SimulationGUI.py @@ -636,14 +636,14 @@ def GetClock(self): ### def MsgBoxEmptyModel(self): - """ Pop-up alert for empty model + """ Pop-up alert for empty model. """ dial = wx.MessageDialog(self, _('You want to simulate an empty master model!'), _('Simulation Manager'), wx.OK|wx.ICON_EXCLAMATION) - if (dial.ShowModal() == wx.ID_OK) and (isinstance(self.parent, wx.Frame)): + if (dial.ShowModal() == wx.ID_OK) and isinstance(self.parent, wx.Frame): self.PrepareDestroyWin() ### destroy the frame self.Destroy() @@ -659,7 +659,7 @@ def SetFields(self): printOnStatusBar(self.statusbar, {i:'' for i in range(self.statusbar.GetFieldsCount())}) def PrepareDestroyWin(self): - """ To destroy the simulation frame + """ To destroy the simulation frame. """ ### clean status bar @@ -694,7 +694,7 @@ def PrepareDestroyWin(self): pass def OnQuit(self, event): - """ When the simulation are stopping + """ When the simulation are stopping. """ # if the simulation is running diff --git a/Utilities.py b/Utilities.py index 7e304245..21e38efe 100644 --- a/Utilities.py +++ b/Utilities.py @@ -872,9 +872,11 @@ def listf(data): def RGBToHEX(rgb_tuple): """ convert an (R, G, B) tuple to #RRGGBB """ - hexcolor = '#%02x%02x%02x' % rgb_tuple + + hexcolor = f'#%02x%02x%02x'%rgb_tuple[:-1] # that's it! '%02x' means zero-padded, 2-digit hex values return hexcolor + def HEXToRGB(colorstring): """ convert #RRGGBB to an (R, G, B) tuple """ diff --git a/ZipManager.py b/ZipManager.py index e271926c..18a3fe60 100644 --- a/ZipManager.py +++ b/ZipManager.py @@ -82,7 +82,7 @@ def getPythonModelFileName(fn:str)->str: class Zip: - def __init__(self, fn, files = []): + def __init__(self, fn:str, files:[str]=[]): """ Constructor """ ### local copy @@ -100,7 +100,7 @@ def __init__(self, fn, files = []): if files != []: self.Create(files) - def Create(self, add_files = []): + def Create(self, add_files:[str]=[])->None: dir_name, base_name = os.path.split(self.fn) name, ext = os.path.splitext(base_name) @@ -126,7 +126,7 @@ def Create(self, add_files = []): zout.close() - def Update(self, replace_files=[]): + def Update(self, replace_files:[str]=[])->None: """ Update zip archive with the new replace file names """ @@ -190,7 +190,7 @@ def Update(self, replace_files=[]): ### remove and rename the zip file self.ClearFiles() - def Delete(self, delete_files=[]): + def Delete(self, delete_files:[str]=[])->None: """ Remove file in zip archive """ @@ -218,7 +218,7 @@ def Delete(self, delete_files=[]): ### remove and rename the zip file self.ClearFiles() - def GetImage(self, scaleW=16, scaleH=16): + def GetImage(self, scaleW:int=16, scaleH:int=16): """ Get image object from image file stored in zip file. scaleH and scaleW are used to rescale image """ @@ -285,7 +285,7 @@ def HasTests(fn:str)->bool: return any([re.search("^(BDD/[\w*/]*\.py|BDD/[\w*/]*\.feature)$", s) for s in nl]) @staticmethod - def GetTests(fn): + def GetTests(fn:str)->[str]: """ Return feature, steps and environment files from .amd """ zf = zipfile.ZipFile(fn, 'r') @@ -299,7 +299,7 @@ def GetTests(fn): return tests_files # ------------------------------------------------------------------------------ - def GetModule(self, rcp=False): + def GetModule(self, rcp: bool=False)->types.ModuleType: """ Return module from zip file corresponding to the amd or cmd model. It used when the tree library is created. If the module refered by self.fn is already imported, its returned else its imported using zipimport @@ -312,7 +312,7 @@ def GetModule(self, rcp=False): return self.ImportModule() if self.fullname not in sys.modules else sys.modules[self.fullname] - def ImportModule(self): + def ImportModule(self)->types.ModuleType: """ Import module from zip file corresponding to the amd or cmd model. """ ### allows to import the lib from its name (like import MyModel.amd). Dangerous because confuse! @@ -366,7 +366,7 @@ def ReImport(self): return module @staticmethod - def ClearCache(fn): + def ClearCache(fn:str)->None: """Clear out cached entries from _zip_directory_cache""" if fn in zipimport._zip_directory_cache: @@ -375,12 +375,13 @@ def ClearCache(fn): if fn not in sys.path: sys.path.append(fn) - def ClearFiles(self): - """ remove and rename the zip file + def ClearFiles(self)->None: + """ remove and rename the zip file. """ try: os.remove(self.fn) - except info: + except Exception as info: + #sys.exc_info() sys.stderr.write(_('File has not been deleted: %s'%info)) try: