def loadFromFile(file): lockfile = QLockFile(getLockfileName(file)) lockfile.lock() if not QFileInfo(file).exists(): return with open(file) as f: data = json.load(f) return data
def launch_mia(): global imageViewer def my_excepthook(type, value, tback): # log the exception here print("excepthook") clean_up() # then call the default handler sys.__excepthook__(type, value, tback) sys.exit(1) sys.excepthook = my_excepthook # Working from the scripts directory os.chdir(os.path.dirname(os.path.realpath(__file__))) lock_file = QLockFile( QDir.temp().absoluteFilePath('lock_file_populse_mia.lock')) if not lock_file.tryLock(100): # Software already opened in another instance pass else: # No instances of the software is opened, the list of opened projects can be cleared config = Config() config.set_opened_projects([]) app = QApplication(sys.argv) project = Project(None, True) imageViewer = Main_Window(project) imageViewer.show() app.exec()
def writeToJSONFile(fileName, data): pprint(data) filePath = getFilePath(fileName) lockfile = QLockFile(getLockfileName(fileName)) lockfile.lock() with open(filePath, 'w') as f: json.dump(data, f) lockfile.unlock()
def launch_mia(): """Actual launch of the mia software. Overload the sys.excepthook handler with the _my_excepthook private function. Check if the software is already opened in another instance. If not, the list of opened projects is cleared. Checks if saved projects known in the mia software still exist, and updates if necessary. Instantiates a 'project' object that handles projects and their associated database anf finally launch of the mia's GUI. **Contains: Private function:** - *_my_excepthook(etype, evalue, tback)* Log all uncaught exceptions in non-interactive mode. All python exceptions are handled by function, stored in sys.excepthook. By overloading the sys.excepthook handler with _my_excepthook function, this last function is called whenever there is a unhandled exception (so one that exits the interpreter). We take advantage of it to clean up mia software before closing. :Parameters: - :etype: exception class - :evalue: exception instance - :tback: traceback object **Contains: Private function:** - *_clean_up()* Cleans up the mia software during "normal" closing. Make a clean up of the opened projects just before exiting mia. - *_verify_saved_projects()* Verify if the projects saved in saved_projects.yml are still on the disk. :Returns: the list of the deleted projects """ def _my_excepthook(etype, evalue, tback): def _clean_up(): global main_window config = Config() opened_projects = config.get_opened_projects() try: opened_projects.remove(main_window.project.folder) config.set_opened_projects(opened_projects) main_window.remove_raw_files_useless() except AttributeError as e: opened_projects = [] config.set_opened_projects(opened_projects) print("\nClean up before closing mia done ...\n") # log the exception here print("\nException hooking in progress ...") _clean_up() # then call the default handler sys.__excepthook__(etype, evalue, tback) # there was some issue/error/problem, so exiting sys.exit(1) def _verify_saved_projects(): saved_projects_object = SavedProjects() saved_projects_list = copy.deepcopy(saved_projects_object.pathsList) deleted_projects = [] for saved_project in saved_projects_list: if not os.path.isdir(saved_project): deleted_projects.append(saved_project) saved_projects_object.removeSavedProject(saved_project) return deleted_projects global main_window app = QApplication(sys.argv) QApplication.setOverrideCursor(Qt.WaitCursor) sys.excepthook = _my_excepthook # working from the scripts directory os.chdir(os.path.dirname(os.path.realpath(__file__))) lock_file = QLockFile( QDir.temp().absoluteFilePath('lock_file_populse_mia.lock')) if not lock_file.tryLock(100): # software already opened in another instance pass else: # no instances of the software is opened, the list of opened projects # can be cleared config = Config() config.set_opened_projects([]) deleted_projects = _verify_saved_projects() project = Project(None, True) main_window = MainWindow(project, deleted_projects=deleted_projects) main_window.show() app.exec()
try: from PyQt5.QtCore import QLockFile, QDir lockfile = QLockFile(QDir.tempPath() + '/wdg.lock') is_single = lockfile.tryLock(100) except: is_single = True import logging import sys from logging.handlers import RotatingFileHandler from PyQt5.QtGui import QIcon from PyQt5.QtWidgets import QApplication, QMessageBox from dg import ( ICONS_DIR, LOG_DIR ) from dg.contrib import get_style from dg.home import HomeWindow log_file = LOG_DIR / 'app.log' logging.basicConfig( # noqa level=logging.INFO, format="[%(asctime)s]:%(levelname)s %(name)s :%(module)s/%(funcName)s,%(lineno)d: %(message)s", handlers=[ RotatingFileHandler(str(log_file)), logging.StreamHandler() ] )
if self.info['update']['isbeta']: out = 'MDFSetup-beta.exe' else: out = 'MDFSetup-stable.exe' win32api.ShellExecute( None, "open", os.path.dirname(self.download_file_name) + '\\{}'.format(out), param, None, 1) sys.exit() def check_update(self): if self.isnew(): self.download() elif self.insider and self.isbeta(): self.download(True) if __name__ == '__main__': lockfile = QLockFile(os.getenv('TEMP') + '/MDFMSU.lock') if not lockfile.tryLock(): sys.exit() ut = Updater() if len(sys.argv) > 0: if sys.argv[1] == "/cu": ut.check_update() elif sys.argv[1] == "/ru": ut.run_update() elif sys.argv[1] == "/ruwa": ut.run_update(True)