Beispiel #1
0
 def on_menu_edit_load_default(self):
     if confirm_dialog('Load default configuration ?'):
         self.controller.load_default_configuration()
Beispiel #2
0
 def on_menu_file_quit(self):
     if confirm_dialog('Quit ?'):
         self.controller.quit()
Beispiel #3
0
 def on_menu_edit_reload(self):
     if confirm_dialog('Reload configuration ?'):
         self.controller.load_configuration()
Beispiel #4
0
    def start_tool(self, tool):

        name = self.tools.keys()[self.tools.values().index(tool)]

        cfg = self.get_configuration()

        self.info('start tool %r %r', name, tool)
        self.debug('cfg: %s', pprint.pformat(cfg.dict()))

        if 'type' not in tool:
            tool['func']()
            return

        if 'thread' in tool:
            warning_dialog('This tool is already running')
            return
        tool['thread'] = RunThread(name, tool, cfg)

        progress = QtGui.QProgressDialog()
        progress.setWindowTitle(tool['title'])
        progress.setLabelText(tool['title'])
        progress.setMinimum(0)
        progress.setMaximum(0)
        progress.setCancelButton(None)

        if tool['type'] == 'generate_and_check_file':

            check_file = find_config(cfg.dict(), *tool['check_file_cfgpath'])
            check_file = os.path.join(cfg['session']['workdir'], check_file)

            if os.path.isfile(check_file):
                if not confirm_dialog(
                        'File %r already exists, regenerate file ?' %
                    (check_file, ),
                        title=tool['title']):
                    return
                os.remove(check_file)

            progress.setLabelText('Generating %s' % (check_file, ))

            def finished():
                if not os.path.isfile(check_file):
                    msg = 'Error while generating file %r' % check_file
                    self.error(msg)
                    error_dialog(msg, title=tool['title'])
                else:
                    msg = 'File %r generated' % check_file
                    self.info(msg)
                    info_dialog(msg, title=tool['title'])

        elif tool['type'] == 'generate_and_open_html':

            html_file = find_config(cfg.dict(), *tool['open_html_cfgpath'])
            html_file = os.path.join(cfg['session']['workdir'], html_file)

            if os.path.isfile(html_file):
                if not confirm_dialog(
                        'File %r already exists, regenerate file ?' %
                    (html_file, ),
                        title=tool['title']):
                    self.add_html_tab(tool['title'], html_file)
                    return
                os.remove(html_file)

            progress.setLabelText('Generating %s' % (html_file, ))

            def finished():
                if not os.path.isfile(html_file):
                    msg = 'Error while generating file %r' % html_file
                    self.error(msg)
                    error_dialog(msg, title=tool['title'])
                else:
                    msg = 'File %r generated' % html_file
                    self.info(msg)
                    self.add_html_tab(tool['title'], html_file)
                    info_dialog(msg, title=tool['title'])

        def wrap_finished(self, name, tool, finished):
            def wrapped_finished(res, exc, tb):
                self.verbose('tool thread finised %r', name)
                progress.hide()
                thread = tool['thread']
                if exc:
                    detail = tb
                    error_dialog('Error running tool %r: %s' %
                                 (tool['title'], exc),
                                 title=tool['title'],
                                 detail=detail)
                else:
                    finished()
                thread.deleteLater()
                tool.pop('thread')

            return wrapped_finished

        tool['thread'].finished.connect(
            wrap_finished(self, name, tool, finished))

        progress.open()
        self.verbose('start tool thread %r', name)
        tool['thread'].start()