def saveConfig(self): """ Actions to take when the 'save config' menu item is selected """ # Call dialog box to select the configuration file self.loader = FileSelector("saveConfig") # Save the raob request into the configuration file self.raob.request.set_config(self.loader.get_file()) configfile = config(self.log) configfile.write(self.raob.request)
def loadRSL(self): """ Call dialog box to load a station list """ # Call dialog box to select a raob station list (rsl) file # Once selected, code will loop through contents self.loader = FileSelector("loadRsl") self.request.set_rsl(self.loader.get_file()) if (self.request.get_rsl() == ""): printmsg(self.log, "WARNING: Station list not loaded. Please " + "select a station/station list.") else: self.load.setText(self.request.get_rsl()) logging.info("RAOB station list set to " + self.request.get_rsl()) # When load an RSL file, set stnm to empty in request and reset display # text to empty. self.request.set_stnm('') self.stnm.setText('')
def loadConfig(self): """ Actions to take when the 'Load config' menu item is selected """ # This has to be self.editor (not just editor) to avoid garbage # collection or the GUIconfig window won't appear. configfile = config(self.log) # Call dialog box to select the configuration file self.loader = FileSelector("loadConfig") # Clear the previously loaded config so don't get conflicts configfile.clear(self.raob.request) # Load the configuration into the raob request self.raob.request.set_config(self.loader.get_file()) configfile.read(self.raob.request) # Update the displayed selections in the configedit portion # of the GUI self.update_displayed_config()
def saveRSL(self): """ Save the list of values out of the GUI (rslbox) """ # Call dialog box to select the file to save the RSL list to self.loader = FileSelector("saveRsl") self.outfile = self.loader.get_file() # Write the RSL list to the open file fp = open(os.path.relpath(self.outfile, start=os.getcwd()), 'w') for item in range(self.rslbox.count()): # Only save the beginning of the file until the first space. This # will get the id, or if blank, the number. fp.write( str(self.rslbox.item(item).data(0)).strip().split(' ', 1)[0] + "\n") fp.close() # close window self.signal.emit() self.close()
class LoadRSL(): def __init__(self, request, log=""): """ This class creates a button which launches a FileSelector """ self.log = log self.request = request self.label = "Load RSL station list" def create(self, box, row, stnm): """ Create the Load station list button """ self.stnm = stnm lbl = QLabel("-or-") box.addWidget(lbl, row, 0) self.load = QPushButton(self.label) self.load.clicked.connect(self.loadRSL) self.load.setToolTip('Load a list of stations from a file') box.addWidget(self.load, row, 1, 1, 2) def loadRSL(self): """ Call dialog box to load a station list """ # Call dialog box to select a raob station list (rsl) file # Once selected, code will loop through contents self.loader = FileSelector("loadRsl") self.request.set_rsl(self.loader.get_file()) if (self.request.get_rsl() == ""): printmsg(self.log, "WARNING: Station list not loaded. Please " + "select a station/station list.") else: self.load.setText(self.request.get_rsl()) logging.info("RAOB station list set to " + self.request.get_rsl()) # When load an RSL file, set stnm to empty in request and reset display # text to empty. self.request.set_stnm('') self.stnm.setText('') def get_default_label(self): """ Return the default label for the load RSL button """ return(self.label) def get_button(self): """ This is used to pass a reference to load RSL button to the stnm class so it can reset the RSL button label to the default when a station is chosen to override a previous RSL file selection. """ return(self.load)
class RSLWidget(QWidget): # Need a signal to send back to RSLCreator when RSLWidget is closed to tell # it to close the parent window. signal = pyqtSignal() def __init__(self, station_list): """ Initialize the RSLCreator widget inside the creator main window """ super().__init__() layout = QGridLayout(self) # Create a QListWidget to hold the source station list self.textbox = QListWidget(self) self.textbox.show() self.textbox.setDragEnabled(True) layout.addWidget(self.textbox, 1, 0, 12, 1) # Add a title above the source station list lbl = QLabel("Master Station List") lbl.setAlignment(Qt.AlignCenter | Qt.AlignCenter) layout.addWidget(lbl, 0, 0) # If the user cancelled out of selecting a source station list, or # requested a non-existent one, capture the error here and warn them. # Otherwise, display stations in textbox error = re.compile("^ERROR:") if isinstance(station_list, str) and error.match(station_list): self.textbox.addItem(station_list) else: self.display_station(station_list) # Create a QListWidget to hold the selected stations to be saved to # the RSL file. self.rslbox = QListWidget(self) self.rslbox.setAcceptDrops(True) layout.addWidget(self.rslbox, 1, 2, 12, 1) # Add a title above the RSL file lbl = QLabel("RSL file") lbl.setAlignment(Qt.AlignCenter | Qt.AlignCenter) layout.addWidget(lbl, 0, 2) # Add arrows that move stuff back and forth between boxes select = QPushButton('->', self) layout.addWidget(select, 1, 1) select.clicked.connect(self.select_station) remove = QPushButton('<-', self) layout.addWidget(remove, 2, 1) remove.clicked.connect(self.remove_station) # Add a Save button to save RSL save = QPushButton('Save', self) layout.addWidget(save, 11, 1) save.clicked.connect(self.saveRSL) def display_station(self, station_list): """ Load stations from station_list into textbox """ for stn in station_list: self.textbox.addItem(stn['id'] + "\t" + stn['number'] + " " + stn['description'] + "\t" + stn['state'] + " " + stn['country'] + " " + stn['lat'] + " " + stn['lon'] + " " + stn['elev']) def select_station(self): """ Transfer a station from the master list to the RSL list """ for line in self.textbox.selectedItems(): self.rslbox.addItem(line.text()) def remove_station(self): """ Remove station from RSL list """ self.rslbox.takeItem(self.rslbox.currentRow()) def saveRSL(self): """ Save the list of values out of the GUI (rslbox) """ # Call dialog box to select the file to save the RSL list to self.loader = FileSelector("saveRsl") self.outfile = self.loader.get_file() # Write the RSL list to the open file fp = open(os.path.relpath(self.outfile, start=os.getcwd()), 'w') for item in range(self.rslbox.count()): # Only save the beginning of the file until the first space. This # will get the id, or if blank, the number. fp.write( str(self.rslbox.item(item).data(0)).strip().split(' ', 1)[0] + "\n") fp.close() # close window self.signal.emit() self.close() def get_rsl_filename(self): return (self.outfile)
class RAOBview(QMainWindow): def __init__(self, raob, app): """ Set the initial GUI window size here """ self.raob = raob # RAOBget instance # The QMainWindow class provides a main application window QMainWindow.__init__(self) # Set the initial size of the window created. It is user resizeable self.left = 100 # Pixel distance from left of screen to open window self.top = 50 # Pixel distance from top of screen to open window self.width = 1200 # Pixel width of window self.height = 800 # Pixel height of window # Create the GUI self.initUI(app) def initUI(self, app): """ Create the GUI """ # Set window title self.setWindowTitle('RAOBget - a utility to download soundings from ' + 'the University of Wyoming sounding archive') # Set where GUI will appear on screen (x locn, y locn, width, ht) self.setGeometry(self.left, self.top, self.width, self.height) # Set central widget. A QMainWindow must have a central widget. It can # also have a menu bar, status bar, toolbars, and dock widgets which # appear in a standard layout self.widget = Widget(self.raob, app) self.setCentralWidget(self.widget) # Get a pointer to the log message window self.log = self.widget.get_log() # Configure the menu bar self.createMenuBar() def createMenuBar(self): """ Create the menu bar and add options and dropdowns """ # A Menu bar will show menus at the top of the QMainWindow menubar = self.menuBar() # Mac OS treats menubars differently. To get a similar outcome, we can # add the following line: menubar.setNativeMenuBar(False). menubar.setNativeMenuBar(False) # Add a menu option to access config files fileMenu = menubar.addMenu("File") # In order for tooltips of actions to display, need to # setToolTipsVisible to True (is False by default) fileMenu.setToolTipsVisible(True) # Add a submenu option to load a config file loadConfig = QAction("Load config", self) loadConfig.setToolTip('Load a previously saved configuration file') loadConfig.triggered.connect(self.loadConfig) fileMenu.addAction(loadConfig) # Add a submenu option to save the current configuration saveConfig = QAction("Save config", self) saveConfig.setToolTip('Save the current configuration to a file') saveConfig.triggered.connect(self.saveConfig) fileMenu.addAction(saveConfig) # Add a menu/submenu? option to quit quitButton = QAction('Quit', self) quitButton.setShortcut('Ctrl+Q') quitButton.setToolTip('Exit application') quitButton.triggered.connect(self.close) menubar.addAction(quitButton) def loadConfig(self): """ Actions to take when the 'Load config' menu item is selected """ # This has to be self.editor (not just editor) to avoid garbage # collection or the GUIconfig window won't appear. configfile = config(self.log) # Call dialog box to select the configuration file self.loader = FileSelector("loadConfig") # Clear the previously loaded config so don't get conflicts configfile.clear(self.raob.request) # Load the configuration into the raob request self.raob.request.set_config(self.loader.get_file()) configfile.read(self.raob.request) # Update the displayed selections in the configedit portion # of the GUI self.update_displayed_config() def update_displayed_config(self): """ Update the displayed selections in the configedit portion of the GUI """ newconfig = self.widget.configGUI() # Update mode if self.raob.request.get_mtp() is True: newconfig.updateMode("MTP") if self.raob.request.get_catalog() is True: newconfig.updateMode("CATALOG") if self.raob.request.get_mtp() is True and \ self.raob.request.get_catalog() is True: printmsg(self.log, "ERROR: Both mtp and catalog set to true" + " in config file. Setting to default mode.") self.raob.request.set_mtp(False) self.raob.request.set_catalog(False) newconfig.updateMode("Default") # update Freq (hours) newconfig.updateFreq(self.raob.request.get_freq()) # update Type of RAOB data to download newconfig.updateType(self.raob.request.get_type()) # update displayed station number / id newconfig.updateStnm(self.raob.request.get_stnm()) # update displayed begin time newconfig.updateBtime(self.raob.request.get_year() + self.raob.request.get_month() + self.raob.request.get_begin()) # update displayed end time newconfig.updateEtime(self.raob.request.get_year() + self.raob.request.get_month() + self.raob.request.get_end()) # update displayed RSL file if self.raob.request.get_rsl() != '': newconfig.updateRSL(self.raob.request.get_rsl()) # update displayed time if now if self.raob.request.get_now() is True: newconfig.updatenow("Time set to now") def saveConfig(self): """ Actions to take when the 'save config' menu item is selected """ # Call dialog box to select the configuration file self.loader = FileSelector("saveConfig") # Save the raob request into the configuration file self.raob.request.set_config(self.loader.get_file()) configfile = config(self.log) configfile.write(self.raob.request)