Exemple #1
0
 def data(self, index, role):
     fld = self.fields[index.column()]
     obj = index.internalPointer()
     rslt = None
     if type(obj) is Project:
         if role == QtCore.Qt.DisplayRole or role == QtCore.Qt.EditRole:
             if fld == 'name':
                 rslt = obj.name
         elif role == QtCore.Qt.DecorationRole and index.column() == 0:
             #TODO: icon for projects
             pass
     elif type(obj) is Run:
         if fld == 'sel' and role == QtCore.Qt.CheckStateRole:
             if self.master_window.pal_tab.has_run(obj, enabled=True):
                 rslt = QtCore.Qt.Checked
             else:
                 rslt = QtCore.Qt.Unchecked
         elif role == QtCore.Qt.DisplayRole or role == QtCore.Qt.EditRole:
             if fld == 'name':
                 rslt = obj.name
             else:
                 rslt = obj.info.get(fld, '')
         elif role == QtCore.Qt.DecorationRole and index.column() == 0:
             loc = resfile('aston/qtgui', 'icons/file.png')
             rslt = QtGui.QIcon(loc)
     elif type(obj) is Analysis:
         if role == QtCore.Qt.DisplayRole:
             if fld == 'name':
                 return obj.name
     #elif role == QtCore.Qt.DisplayRole or role == QtCore.Qt.EditRole:
     #    if fld == 'p-model' and f.db_type == 'peak':
     #        rpeakmodels = {peak_models[k]: k for k in peak_models}
     #        rslt = rpeakmodels.get(f.info[fld], 'None')
     #    else:
     #        rslt = f.info[fld]
     #elif role == QtCore.Qt.DecorationRole and index.column() == 0:
     #    #TODO: icon for method, compound
     #    fname = {'file': 'file.png', 'peak': 'peak.png', \
     #            'spectrum': 'spectrum.png'}
     #    loc = resfile('aston/ui', 'icons/' + fname.get(f.db_type, ''))
     #    rslt = QtGui.QIcon(loc)
     return rslt
Exemple #2
0
    def __init__(self, canvas, parent=None):
        NavigationToolbar2QTAgg.__init__(self, canvas, parent, False)
        self.parent = parent
        self.ev_time = 0
        self._xypress = []

        #quick function to return icon locs
        icon = lambda l: resfile('aston/qtgui', 'icons/' + l + '.png')

        #remove the plot adjustment buttons
        self.removeAction(self.actions()[-1])
        self.removeAction(self.actions()[-1])
        self.removeAction(self.actions()[-1])

        #add the alignment tool
        if not hasattr(self, '_actions'):
            self._actions = {}
        self._actions['align'] = QtGui.QAction(QtGui.QIcon(icon('align')), \
          self.parent.tr('Align Chromatogram'), self)
        self._actions['align'].setCheckable(True)
        self.addAction(self._actions['align'])
        self._actions['align'].triggered.connect(self.align)

        self.addSeparator()

        #add the peak tool
        self._actions['peak'] = QtGui.QAction(QtGui.QIcon(icon('peak')), \
          self.parent.tr('Add/Delete Peak'), self)
        self._actions['peak'].setCheckable(True)
        self.addAction(self._actions['peak'])
        self._actions['peak'].triggered.connect(self.peak)

        #add the spectra tool
        self._actions['spectrum'] = QtGui.QAction( \
          QtGui.QIcon(icon('spectrum')), self.parent.tr('Get Spectrum'), self)
        self._actions['spectrum'].setCheckable(True)
        self.addAction(self._actions['spectrum'])
        self._actions['spectrum'].triggered.connect(self.spec)
Exemple #3
0
    def __init__(self, parent=None):
        QtWidgets.QWidget.__init__(self, parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        # my icon!
        icn_path = resfile('aston/qtgui', 'icons/logo.png')
        self.setWindowIcon(QtGui.QIcon(icn_path))

        # quick fix for Mac OS menus
        self.ui.actionSettings.setMenuRole(QtWidgets.QAction.NoRole)

        # set up the list of files in the current directory
        fdir = get_pref('Default.FILE_DIRECTORY')
        self.load_new_file_db(fdir)

        # connect the menu logic
        self.ui.actionOpen.triggered.connect(self.open_folder)
        self.ui.actionExportChromatogram.triggered.connect(
            self.exportChromatogram
        )
        self.ui.actionExportSpectra.triggered.connect(self.exportSpectrum)
        self.ui.actionExportSelectedItems.triggered.connect(self.exportItems)
        self.ui.actionIntegrate.triggered.connect(self.integrate)
        self.ui.actionEditFilters.triggered.connect(self.showFilterWindow)
        self.ui.actionRevert.triggered.connect(self.revertChromChange)
        self.ui.actionQuit.triggered.connect(QtWidgets.qApp.quit)
        self.ui.loadPeakList.triggered.connect(self.load_peaks)

        # hook up the windows to the menu
        for ac in [self.ui.actionFiles, self.ui.actionSettings,
                   self.ui.actionSpectra, self.ui.actionMethods,
                   self.ui.actionCompounds, self.ui.actionPalette]:
            ac.triggered.connect(self.updateWindows)

        # set up the grouping for the dock widgets and
        # hook the menus up to the windows
        for ac in [self.ui.filesDockWidget, self.ui.paletteDockWidget,
                   self.ui.spectraDockWidget, self.ui.settingsDockWidget,
                   self.ui.methodDockWidget, self.ui.compoundDockWidget]:
            if ac is not self.ui.filesDockWidget:
                self.tabifyDockWidget(self.ui.filesDockWidget, ac)
            ac.visibilityChanged.connect(self.updateWindowsMenu)
        self.ui.filesDockWidget.raise_()
        self.ui.settingsDockWidget.setVisible(False)
        self.ui.compoundDockWidget.setVisible(False)
        self.ui.methodDockWidget.setVisible(False)

        # create the things that keep track of how the plots should look
        self.plotter = Plotter(self)
        self.specplotter = SpecPlotter(self)

        # FIXME
        # hook up the search box
        # self.ui.lineEdit.textChanged.connect(self.updateSearch)

        # make integrator options
        def set_peak_find(x):
            self.state['peak_finder'] = x
        peak_find_menu = QtWidgets.QMenu(self.ui.menuChromatogram)
        v = list(aston.qtgui.MenuOptions.peak_finders.keys())[0]
        set_peak_find(v)
        add_opts_to_menu(peak_find_menu,
                         aston.qtgui.MenuOptions.peak_finders.keys(),
                         set_peak_find, v)
        self.ui.actionPeak_Finder.setMenu(peak_find_menu)

        def set_integrator(x):
            self.state['integrator'] = x
        integrator_menu = QtWidgets.QMenu(self.ui.menuChromatogram)
        v = list(aston.qtgui.MenuOptions.integrators.keys())[0]
        set_integrator(v)
        add_opts_to_menu(integrator_menu,
                         aston.qtgui.MenuOptions.integrators.keys(),
                         set_integrator, v)
        self.ui.actionIntegrator.setMenu(integrator_menu)

        menu_gp = QtWidgets.QActionGroup(self)
        for ac in self.ui.menuIntegrand.actions():
            menu_gp.addAction(ac)

        ## hook up spectrum menu
        #for m in [self.ui.actionSpecLibDisp, self.ui.actionSpecLibLabel,\
        #          self.ui.actionSpecMainDisp, self.ui.actionSpecMainLabel, \
        #          self.ui.actionSpecPrevDisp, self.ui.actionSpecPrevLabel]:
        #    m.triggered.connect(self.specplotter.plot)
        #self.ui.actionSpecMainSave.triggered.connect( \
        #  self.specplotter.save_main_spec)
        #self.ui.actionSpecPrevSave.triggered.connect( \
        #  self.specplotter.save_prev_spec)

        #flesh out the settings menu
        color_menu = QtWidgets.QMenu(self.ui.menuSettings)
        v_cs = self.settings.get_key('color_scheme', dflt='Spectral')
        v = aston_field_opts['color-2d'][v_cs]
        c_opts = list(aston_field_opts['color-2d'].values())
        add_opts_to_menu(color_menu, c_opts, self.set_color_scheme, v)
        self.ui.actionColor_Scheme.setMenu(color_menu)

        self.ui.actionLegend.triggered.connect(self.set_legend)
        self.ui.actionGraphGrid.triggered.connect(self.set_legend)
        self.ui.actionGraphLogYAxis.triggered.connect(self.set_legend)
        #self.ui.actionGraphFxnCollection.triggered.connect(self.set_legend)
        #self.ui.actionGraphFIA.triggered.connect(self.set_legend)
        #self.ui.actionGraphIRMS.triggered.connect(self.set_legend)
        #self.ui.actionGraph_Peaks_Found.triggered.connect(self.set_legend)

        #style_menu = QtWidgets.QMenu(self.ui.menuSettings)
        #v_gs = self.settings.get_key('graph_style', dflt='default')
        #v = self.plotter._styles[v_gs]
        #self.plotter.setStyle(v)
        #add_opts_to_menu(style_menu, \
        #  self.plotter.availStyles(), self.set_graph_style, v)
        #self.ui.actionGraph_Style.setMenu(style_menu)

        # plot data
        self.plot_data()
Exemple #4
0
 def data(self, index, role):
     fld = self.fields[index.column()]
     obj = index.internalPointer()
     rslt = None
     if type(obj) is PaletteRun:
         if role == QtCore.Qt.DisplayRole or role == QtCore.Qt.EditRole:
             if fld == 'name':
                 rslt = obj.run.name
         elif role == QtCore.Qt.DecorationRole and fld == 'name':
             loc = resfile('aston/qtgui', 'icons/file.png')
             rslt = QtGui.QIcon(loc)
     elif type(obj) is Plot:
         if fld == 'vis' and role == QtCore.Qt.CheckStateRole:
             #TODO: allow vis to be a plot number instead?
             if obj.vis > 0:
                 rslt = QtCore.Qt.Checked
             else:
                 rslt = QtCore.Qt.Unchecked
         elif role == QtCore.Qt.DisplayRole or role == QtCore.Qt.EditRole:
             if fld == 'name':
                 rslt = obj.name
             elif fld == 'style':
                 rslt = aston_field_opts[fld][obj.style]
             elif fld == 'color':
                 if obj.style in {'heatmap', 'colors'}:
                     rslt = aston_field_opts['color-2d'][obj.color]
                 else:
                     rslt = aston_field_opts['color-1d'][obj.color]
         elif role == QtCore.Qt.FontRole and fld == 'name':
             # strike out invalid plot names
             if not obj.is_valid:
                 rslt = QtGui.QFont()
                 rslt.setStrikeOut(True)
         #elif role == QtCore.Qt.DecorationRole and index.column() == 0:
         #    if not obj.is_valid:
         #        loc = resfile('aston/qtgui', 'icons/x.png')
         #        rslt = QtGui.QIcon(loc)
     elif type(obj) is Peak:
         if fld == 'vis' and role == QtCore.Qt.CheckStateRole:
             if obj.vis:
                 rslt = QtCore.Qt.Checked
             else:
                 rslt = QtCore.Qt.Unchecked
         elif role == QtCore.Qt.DisplayRole or role == QtCore.Qt.EditRole:
             if fld == 'name':
                 rslt = obj.name
             elif fld == 'color':
                 rslt = aston_field_opts['color-1d'][obj.color]
             elif fld in {'p-model'}:
                 v = obj.components[0].info.get(fld, None)
                 if v is not None:
                     rslt = aston_field_opts[fld][v]
             elif fld in {'p-model-fit'}:
                 fmt = lambda x: '{:.3f}'.format(x)
                 rslt = ','.join(fmt(c.info.get('p-model-fit', '')) \
                                 for c in obj.components \
                                 if c.info.get('p-model') is not None)
             elif fld in {'p-type'}:
                 rslt = aston_field_opts[fld][obj.info.get(fld, '')]
             elif fld in {'p-d13c'}:
                 rslt = str(obj.info.get(fld, ''))
             elif fld in {'s-mz-names'}:
                 rslt = ','.join(str(c._trace.name) for c in obj.components)
             elif fld in {'p-area', 'p-length', 'p-height', 'p-width', \
                          'p-pwhm', 'p-time'}:
                 rslt = str(getattr(obj, fld[2:])())
     #elif role == QtCore.Qt.DisplayRole or role == QtCore.Qt.EditRole:
     #    if fld == 'p-model' and f.db_type == 'peak':
     #        rpeakmodels = {peak_models[k]: k for k in peak_models}
     #        rslt = rpeakmodels.get(f.info[fld], 'None')
     #    else:
     #        rslt = f.info[fld]
     #elif role == QtCore.Qt.DecorationRole and index.column() == 0:
     #    #TODO: icon for method, compound
     #    fname = {'file': 'file.png', 'peak': 'peak.png', \
     #            'spectrum': 'spectrum.png'}
     #    loc = resfile('aston/ui', 'icons/' + fname.get(f.db_type, ''))
     #    rslt = QtGui.QIcon(loc)
     return rslt
Exemple #5
0
    warnings.simplefilter('ignore', sqlalchemy.exc.SAWarning)

    # for multiprocessing to work on Windows
    import multiprocessing
    multiprocessing.freeze_support()

    #all the other imports
    import sys
    import PyQt4
    from aston.qtgui.MainWindow import AstonWindow
    qt = PyQt4.QtGui.QApplication(sys.argv)

    # translation stuff
    import locale
    import pkg_resources
    from aston.resources import resfile
    try:
        locale.setlocale(locale.LC_ALL, '')
        if locale.getlocale()[0] is not None:
            lang = locale.getlocale()[0]
            tlate = PyQt4.QtCore.QTranslator(qt)
            tlate.load('aston_' + lang + '.qm', resfile('aston/qtgui', 'i18n'))
            qt.installTranslator(tlate)
    except locale.Error:
        pass

    # set up the main window and start
    aston = AstonWindow()
    aston.show()
    sys.exit(qt.exec_())