コード例 #1
0
    def __init__(self, parent):
        QMainWindow.__init__(self, parent)
        loadUi(self, 'browse.ui')
        self.logger = logger.getChild('browse')

        self.dataloader = parent
        self.rootdir = ''
        self.loader = Loader()
        self._data = {}
        self.yaxis = None
        self.canvas = MPLCanvas(self)
        self.canvas.plotter.lines = True
        self.toolbar = MPLToolbar(self.canvas, self)
        self.toolbar.setObjectName('browsetoolbar')
        self.addToolBar(self.toolbar)
        layout = QVBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(self.canvas)
        self.plotframe.setLayout(layout)
        self.sgroup = SettingGroup('browse')

        with self.sgroup as settings:
            geometry = settings.value('geometry', QByteArray())
            self.restoreGeometry(geometry)
            windowstate = settings.value('windowstate', QByteArray())
            self.restoreState(windowstate)
            splitstate = settings.value('splitstate', QByteArray())
            self.splitter.restoreState(splitstate)
            self.monScaleEdit.setText(settings.value('fixedmonval'))
コード例 #2
0
ファイル: coverage.py プロジェクト: McStasMcXtrace/ufit
    def __init__(self, parent):
        """ Constructing a basic QApplication
        """
        QMainWindow.__init__(self, parent)
        self.sgroup = SettingGroup('main')
        self.ui = uic.loadUi(path.join(path.dirname(__file__), 'ui', 'qexplorer.ui'), self)
        self.addWidgets()
        self.ui.show()
        self.dir = path.dirname(__file__)
        self.pts = []
        self.canvas = MPLCanvas(self)
        self.canvas.plotter.lines = True
        self.toolbar = MPLToolbar(self.canvas, self)
        self.toolbar.setObjectName('browsetoolbar')
        self.addToolBar(self.toolbar)
        self.v1 = [1, 0, 0]
        self.v2 = [0, 0, 1]
        layout = QVBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(self.canvas)
        self.frmPlot.setLayout(layout)
        self.Reader = None

        # restore settings
        with self.sgroup as settings:
            data_template_path = settings.value('last_data_template', '')
            print(settings.value('test', ''))
            if data_template_path:
                dtempl, numor = extract_template(data_template_path)
                self.dir = dtempl
                self.ui.txtNumors.setText(str(numor))
                print("directory set to", self.dir)
コード例 #3
0
 def on_arbBtn_clicked(self):
     dlg = QDialog(self)
     loadUi(dlg, 'change.ui')
     with SettingGroup('main') as settings:
         dlg.xEdit.setText(settings.value('changex', 'x'))
         dlg.yEdit.setText(settings.value('changey', 'y'))
         dlg.dyEdit.setText(settings.value('changedy', 'dy'))
         if dlg.exec_() != QDialog.Accepted:
             return
         settings.setValue('changex', dlg.xEdit.text())
         settings.setValue('changey', dlg.yEdit.text())
         settings.setValue('changedy', dlg.dyEdit.text())
     xfml = dlg.xEdit.text()
     yfml = dlg.yEdit.text()
     dyfml = dlg.dyEdit.text()
     new_x = []
     new_y = []
     new_dy = []
     ns = {}
     for dpoint in zip(self.data.x, self.data.y_raw, self.data.dy_raw):
         ns.update(x=dpoint[0], y=dpoint[1], dy=dpoint[2])
         new_x.append(eval(xfml, ns))
         new_y.append(eval(yfml, ns))
         new_dy.append(eval(dyfml, ns))
     self.data.x[:] = new_x
     self.data.y_raw[:] = new_y
     self.data.dy_raw[:] = new_dy
     self.data.y = self.data.y_raw / self.data.norm
     self.data.dy = self.data.dy_raw / self.data.norm
     self.replotRequest.emit(None)
     session.set_dirty()
コード例 #4
0
ファイル: inspector.py プロジェクト: McStasMcXtrace/ufit
    def __init__(self, parent):
        self._updating = False
        self._data = None
        QMainWindow.__init__(self, parent)
        loadUi(self, 'inspector.ui')
        # layout = QVBoxLayout()
        # layout.setContentsMargins(0, 0, 0, 0)
        # layout.addWidget(self.canvas)
        self.sgroup = SettingGroup('inspector')
        self.tbl.verticalHeader().setDefaultSectionSize(
            self.tbl.verticalHeader().minimumSectionSize() + 2)

        with self.sgroup as settings:
            geometry = settings.value('geometry', QByteArray())
            self.restoreGeometry(geometry)
            windowstate = settings.value('windowstate', QByteArray())
            self.restoreState(windowstate)
コード例 #5
0
ファイル: annotations.py プロジェクト: McStasMcXtrace/ufit
    def __init__(self, parent):
        self._updating = False
        self._data = None
        QMainWindow.__init__(self, parent)
        loadUi(self, 'annotations.ui')
        self.sgroup = SettingGroup('annotations')

        session.propsRequested.connect(self.on_session_propsRequested)
        session.propsUpdated.connect(self.on_session_propsUpdated)

        with self.sgroup as settings:
            geometry = settings.value('geometry', QByteArray())
            self.restoreGeometry(geometry)
            windowstate = settings.value('windowstate', QByteArray())
            self.restoreState(windowstate)

        self._editing = True
        self.on_session_propsUpdated()
コード例 #6
0
ファイル: dataloader.py プロジェクト: McStasMcXtrace/ufit
    def __init__(self, parent, plotter, standalone=False):
        QWidget.__init__(self, parent)
        self.logger = logger.getChild('loader')
        self.plotter = plotter
        self.last_data = []
        self.loader = Loader()
        self.createUI(standalone)

        self.sgroup = SettingGroup('main')

        # These will not do anything in standalone mode, but do not hurt.
        session.propsRequested.connect(self.on_session_propsRequested)
        session.propsUpdated.connect(self.on_session_propsUpdated)
        session.itemsUpdated.connect(self.on_session_itemsUpdated)
        session.groupAdded.connect(self.on_session_itemsUpdated)

        with self.sgroup as settings:
            data_template_path = settings.value('last_data_template', '')
            if data_template_path:
                self.templateEdit.setText(data_template_path)
                self.set_template(data_template_path, 0, silent=True)
コード例 #7
0
ファイル: __init__.py プロジェクト: McStasMcXtrace/ufit
def main():
    app = QApplication([])
    app.setOrganizationName('ufit')
    app.setApplicationName('gui')

    pixmap = QPixmap(':/splash.png')
    splash = QSplashScreen(pixmap, Qt.WindowStaysOnTopHint)
    splash.showMessage(u'Loading...' + u'\xa0' * 10 + '\n\n',
                       Qt.AlignRight | Qt.AlignBottom)
    splash.show()
    time.sleep(0.1)
    with SettingGroup('main') as settings:
        if settings.value('current_version', '') != __version__:
            settings.setValue('current_version', __version__)
            # Execute here the actions to be performed only once after
            # each update (there is nothing there for now, but it could
            # be useful some day...)
            logger.info('Upgrade to version %s finished' % __version__)
    app.processEvents()

    def log_unhandled(*exc_info):
        logger.error('Unhandled exception in Qt callback', exc_info=exc_info)

    sys.excepthook = log_unhandled

    t1 = time.time()
    logger.info('Startup: import finished (%.3f s), starting GUI...' %
                (t1 - t0))

    mainwindow = UFitMain()

    parser = optparse.OptionParser(usage='''\
    Usage: %prog [-b directory] [.ufit file | data file]
    ''')
    parser.add_option('-b',
                      '--browse',
                      action='store',
                      metavar='DIR',
                      help='open browse window in specified directory')

    opts, args = parser.parse_args()

    if len(args) >= 1:
        datafile = path.abspath(args[0])
        if path.isdir(datafile):
            # directory given, treat it as -b argument (browse)
            opts.browse = datafile
        elif datafile.endswith('.ufit'):
            try:
                mainwindow.filename = datafile
                mainwindow.load_session(datafile)
            except Exception as err:
                QMessageBox.warning(mainwindow, 'Error',
                                    'Loading failed: %s' % err)
                mainwindow.filename = None
        else:
            dtempl, numor = extract_template(datafile)
            mainwindow.dloader.set_template(dtempl, numor, silent=False)
    mainwindow.show()
    if opts.browse:
        mainwindow.dloader.open_browser(opts.browse)

    t2 = time.time()
    logger.info('Startup: loading finished (%.3f s), main window opened' %
                (t2 - t1))
    splash.deleteLater()
    app.exec_()
コード例 #8
0
ファイル: main.py プロジェクト: McStasMcXtrace/ufit
    def __init__(self):
        QMainWindow.__init__(self)

        self.itempanels = {}
        self.multipanels = {}
        self.current_panel = None
        self.inspector_window = None
        self.annotation_window = None

        self.sgroup = SettingGroup('main')
        loadUi(self, 'main.ui')

        self.menuRecent.aboutToShow.connect(self.on_menuRecent_aboutToShow)
        self.menuMoveToGroup = QMenu('Move selected to group', self)
        self.menuMoveToGroup.setIcon(QIcon(':/drawer-open.png'))
        self.menuMoveToGroup.aboutToShow.connect(
            self.on_menuMoveToGroup_aboutToShow)
        self.menuCopyToGroup = QMenu('Copy selected to group', self)
        self.menuCopyToGroup.setIcon(QIcon(':/drawer-double-open.png'))
        self.menuCopyToGroup.aboutToShow.connect(
            self.on_menuCopyToGroup_aboutToShow)
        self.menuRemoveGroup = QMenu('Remove group', self)
        self.menuRemoveGroup.setIcon(QIcon(':/drawer--minus.png'))
        self.menuRemoveGroup.aboutToShow.connect(
            self.on_menuRemoveGroup_aboutToShow)
        self.menuRenameGroup = QMenu('Rename group', self)
        self.menuRenameGroup.aboutToShow.connect(
            self.on_menuRenameGroup_aboutToShow)

        # populate plot view
        layout2 = QVBoxLayout()
        layout2.setContentsMargins(0, 0, 0, 0)
        self.canvas = MPLCanvas(self, maincanvas=True)
        self.canvas.replotRequest.connect(
            lambda: self.current_panel.plot(True))
        self.canvas.mpl_connect('button_press_event', self.on_canvas_pick)
        self.canvas.mpl_connect('pick_event', self.on_canvas_pick)
        self.canvas.mpl_connect('button_release_event', self.on_canvas_click)
        self.toolbar = MPLToolbar(self.canvas, self)
        self.toolbar.setObjectName('mainplottoolbar')
        self.toolbar.popoutRequested.connect(self.on_actionPopOut_triggered)
        self.addToolBar(self.toolbar)
        layout2.addWidget(self.canvas)
        self.plotframe.setLayout(layout2)

        # session events
        session.itemsUpdated.connect(self.on_session_itemsUpdated)
        session.itemAdded.connect(self.on_session_itemAdded)
        session.filenameChanged.connect(self.on_session_filenameChanged)
        session.dirtyChanged.connect(self.on_session_dirtyChanged)

        # create data loader
        self.dloader = DataLoader(self, self.canvas.plotter)
        self.dloader.newDatas.connect(self.on_dloader_newDatas)
        self.stacker.addWidget(self.dloader)
        self.current_panel = self.dloader

        # create item model
        self.itemlistmodel = ItemListModel()
        self.itemTree.setModel(self.itemlistmodel)
        self.itemlistmodel.reset()
        self.itemTree.addAction(self.actionMergeData)
        self.itemTree.addAction(self.actionRemoveData)
        self.itemTree.addAction(self.menuMoveToGroup.menuAction())
        self.itemTree.addAction(self.menuCopyToGroup.menuAction())
        self.itemTree.newSelection.connect(self.on_itemTree_newSelection)

        # backend selector
        self.backend_group = QActionGroup(self)
        for backend in backends.available:
            action = QAction(backend.backend_name, self)
            action.setCheckable(True)
            if backends.backend.backend_name == backend.backend_name:
                action.setChecked(True)
            self.backend_group.addAction(action)
            self.menuBackend.addAction(action)
            action.triggered.connect(self.on_backend_action_triggered)

        # manage button
        menu = QMenu(self)
        menu.addAction(self.actionMergeData)
        menu.addAction(self.actionRemoveData)
        menu.addMenu(self.menuMoveToGroup)
        menu.addMenu(self.menuCopyToGroup)
        menu.addAction(self.actionReorder)
        menu.addSeparator()
        menu.addAction(self.actionNewGroup)
        menu.addMenu(self.menuRenameGroup)
        menu.addMenu(self.menuRemoveGroup)
        self.manageBtn.setMenu(menu)

        # right-mouse-button menu for canvas
        menu = self.canvasMenu = QMenu(self)
        menu.addAction(self.actionUnzoom)
        menu.addAction(self.actionHideFit)
        menu.addSeparator()
        menu.addAction(self.actionDrawSymbols)
        menu.addAction(self.actionConnectData)
        menu.addAction(self.actionSmoothImages)
        menu.addSeparator()
        menu.addAction(self.actionDrawGrid)
        menu.addAction(self.actionShowLegend)

        # restore window state
        with self.sgroup as settings:
            geometry = settings.value('geometry', QByteArray())
            self.restoreGeometry(geometry)
            windowstate = settings.value('windowstate', QByteArray())
            self.restoreState(windowstate)
            splitstate = settings.value('splitstate', QByteArray())
            self.splitter.restoreState(splitstate)
            vsplitstate = settings.value('vsplitstate', QByteArray())
            self.vsplitter.restoreState(vsplitstate)
            self.recent_files = settings.value('recentfiles', []) or []