class MainWindow(QMainWindow): def __init__(self, reset=False, start_freq=None, bandwidth=None, numpts=None, max_hold=None, dev='/dev/ttyUSB0'): QMainWindow.__init__(self) self.settings = QSettings("Darkstar007", "networkanalyser") if reset: self.settings.clear() self.file_dir = self.settings.value('spectrum/file_dir', os.getenv('HOME')) print 'File dir', self.file_dir self.dev = dev self.setup(start_freq, bandwidth, numpts, max_hold) def setup(self, start_freq, bandwidth, numpts, max_hold): """Setup window parameters""" self.setWindowIcon(get_icon('python.png')) self.setWindowTitle(APP_NAME + ' ' + VERS + ' Running on ' + self.dev) dt = QDesktopWidget() print dt.numScreens(), dt.screenGeometry() sz = dt.screenGeometry() self.resize(QSize(sz.width() * 9 / 10, sz.height() * 9 / 10)) # Welcome message in statusbar: status = self.statusBar() status.showMessage(_("Welcome to the NetworkAnalyser application!"), 5000) # File menu file_menu = self.menuBar().addMenu(_("File")) open_action = create_action(self, _("Save"), shortcut="Ctrl+S", icon=get_std_icon("DialogSaveButton"), tip=_("Save a Cal File"), triggered=self.saveFileDialog) load_action = create_action(self, _("Load"), shortcut="Ctrl+L", icon=get_std_icon("FileIcon"), tip=_("Load a cal File"), triggered=self.loadFileDialog) quit_action = create_action(self, _("Quit"), shortcut="Ctrl+Q", icon=get_std_icon("DialogCloseButton"), tip=_("Quit application"), triggered=self.close) add_actions(file_menu, (open_action, load_action, None, quit_action)) # Help menu - prolly should just say "you're on your own..."!! help_menu = self.menuBar().addMenu("Help") about_action = create_action( self, _("About..."), icon=get_std_icon('MessageBoxInformation'), triggered=self.about) add_actions(help_menu, (about_action, )) main_toolbar = self.addToolBar("Main") # add_actions(main_toolbar, (new_action, open_action, )) rescan_action = create_action( self, _("Rescan"), shortcut="Ctrl+R", icon=get_std_icon("BrowserReload"), tip=_("Rescan the current frequency selection"), checkable=False, triggered=self.do_scan) max_hold_action = create_action( self, _("Max Hold"), shortcut="Ctrl+M", icon=get_std_icon("ArrowUp"), tip=_("Display the maximum value encountered"), checkable=True, triggered=self.do_max_hold) log_lin_action = create_action(self, _("Log/Lin"), shortcut="Ctrl+L", icon=get_std_icon("ArrowRight"), tip=_("Use linear power receive mode"), checkable=True, triggered=self.do_log_lin) new_plot_action = create_action(self, _("New Plot"), shortcut="Ctrl+N", icon=get_std_icon("ArrowLeft"), tip=_("Creates a new labeled plot"), checkable=False, triggered=self.do_new_plot) if max_hold is None: max_hold = self.settings.value('gui/max_hold', False) print 'Got max_hold', max_hold if type(max_hold) != bool: if max_hold in ['y', 'Y', 'T', 'True', 'true', '1']: max_hold = True else: max_hold = False max_hold_action.setChecked(max_hold) # Calibration action? add_actions(main_toolbar, (open_action, load_action, rescan_action, max_hold_action, log_lin_action, new_plot_action)) # Set central widget: toolbar = self.addToolBar("Image") self.mainwidget = CentralWidget(self, self.settings, toolbar, start_freq, bandwidth, numpts, self.dev) self.setCentralWidget(self.mainwidget) if max_hold: self.do_max_hold() def do_scan(self): self.mainwidget.rescan() def do_new_plot(self): self.mainwidget.do_new_plot() def do_max_hold(self): self.mainwidget.do_max_hold() def do_log_lin(self): self.mainwidget.do_log_lin() def saveFileDialog(self): print 'Save f dialog' fileName = QFileDialog.getSaveFileName(self, _("Save Cal Data"), self.file_dir) print fileName self.mainwidget.save_cal_data(fileName) def loadFileDialog(self): print 'load f dialog' fileName = QFileDialog.getOpenFileName(self, _("Open Cal Data"), self.file_dir) print fileName self.mainwidget.load_cal_data(fileName) def about(self): QMessageBox.about( self, _("About ") + APP_NAME, """<b>%s</b> v%s<p>%s Matt Nottingham <br>Copyright © 2015-2017 Matt Nottingham <p>Python %s, Qt %s, PyQt %s %s %s""" % (APP_NAME, VERS, _("Developped by"), platform.python_version(), QT_VERSION_STR, PYQT_VERSION_STR, _("on"), platform.system()))
class MainWindow(QMainWindow): def __init__(self, reset=False, start_freq=None, bandwidth=None, numpts=None, max_hold=None): QMainWindow.__init__(self) self.settings = QSettings("Darkstar007", "signal_generator") if reset: self.settings.clear() self.setup(start_freq, bandwidth, numpts, max_hold) def setup(self, start_freq, bandwidth, numpts, max_hold): """Setup window parameters""" self.setWindowIcon(get_icon('python.png')) self.setWindowTitle(APP_NAME) #dt = QDesktopWidget() #print dt.numScreens(), dt.screenGeometry() #sz = dt.screenGeometry() #self.resize(QSize(sz.width()*9/10, sz.height()*9/10)) # Welcome message in statusbar: status = self.statusBar() status.showMessage(_("Welcome to the Signal Generator application!"), 5000) # File menu file_menu = self.menuBar().addMenu(_("File")) open_action = create_action(self, _("Save"), shortcut="Ctrl+S", icon=get_std_icon("FileIcon"), tip=_("Save a File"), triggered=self.saveFileDialog) quit_action = create_action(self, _("Quit"), shortcut="Ctrl+Q", icon=get_std_icon("DialogCloseButton"), tip=_("Quit application"), triggered=self.close) add_actions(file_menu, (open_action, None, quit_action)) # Help menu - prolly should just say "you're on your own..."!! help_menu = self.menuBar().addMenu("Help") about_action = create_action(self, _("About..."), icon=get_std_icon('MessageBoxInformation'), triggered=self.about) add_actions(help_menu, (about_action,)) main_toolbar = self.addToolBar("Main") # Calibration action? add_actions(main_toolbar, (open_action, )) # Set central widget: toolbar = self.addToolBar("Image") self.setCentralWidget(self.mainwidget) if max_hold: self.do_max_hold() def about(self): QMessageBox.about( self, _("About ")+APP_NAME, """<b>%s</b> v%s<p>%s Matt Nottingham <br>Copyright © 2015 Matt Nottingham <p>Python %s, Qt %s, PyQt %s %s %s""" % \ (APP_NAME, VERS, _("Developped by"), platform.python_version(), QT_VERSION_STR, PYQT_VERSION_STR, _("on"), platform.system()) )