def helpClicked(self): dialog = displayobject.AnObject( QtWidgets.QDialog(), self.help, title='Help for SIREN Preferences file', section='prefs') dialog.exec_()
def helpClicked(self): dialog = displayobject.AnObject(QtWidgets.QDialog(), self.help, title='Help for getmap (' + fileVersion() + ')', section='map') dialog.exec_()
def addtotbl(self): if self.message.text() != ' ' and self.message.text()[0] != '(': return addproperty = {} for field in self.fields: addproperty[field] = '' if len(self.fields) == 2: duplicate = [] for entry in self.entry: duplicate.append(entry[self.fields[0]]) else: duplicate = None dialog = displayobject.AnObject(QDialog(), addproperty, readonly=False, textedit=True, title='Add ' + self.fields[0].title() + ' value', duplicate=duplicate) try: dialog.edit[0].setFocus() except: pass dialog.exec_() if dialog.getValues()[self.fields[0]] != '': self.recur = True self.entry.append(addproperty) self.table.setRowCount(self.table.rowCount() + 1) self.sort_col = 1 self.order(0) del dialog self.recur = False
def item_selected(self, row, col): for thing in self.objects: try: attr = getattr(thing, self.name) if attr == self.entry[row][self.name]: dialog = displayobject.AnObject(QtWidgets.QDialog(), thing) dialog.exec_() break except: pass
def item_selected(self, row, col): self.selection = self.entry[row][self.fields[0]] self.close() return for thing in self.e: try: attr = getattr(thing, self.fields[0]) if attr == self.entry[row][self.fields[0]]: self.selection = attr self.close() return dialog = displayobject.AnObject(QDialog(), thing) dialog.exec_() break except: pass
def addtotbl(self): addproperty = {} for field in self.fields: addproperty[field] = '' if self.fields[0] == 'name': textedit = False else: textedit = True dialog = displayobject.AnObject(QtWidgets.QDialog(), addproperty, readonly=False, textedit=textedit, title='Add ' + self.fields[0].title()) dialog.exec_() if dialog.getValues()[self.fields[0]] != '' or 1 == 1: self.entry.append(addproperty) if self.fields[0] == 'property': self.objects.append(FakeObject([dialog.getValues()[self.fields[0]], dialog.getValues()[self.fields[1]]], self.fields)) else: fakes = [] for field in self.fields: if self.labels[field] == 'int': try: fakes.append(int(dialog.getValues()[field])) except: fakes.append(0) elif self.labels[field] == 'float': try: fakes.append(float(dialog.getValues()[field])) except: fakes.append(0.) else: fakes.append(dialog.getValues()[field]) self.objects.append(FakeObject(fakes, self.fields)) self.populate() self.table.setRowCount(self.table.rowCount() + 1) self.sort_col = 1 self.order(0) del dialog
def helpClicked(self): dialog = displayobject.AnObject(QtWidgets.QDialog(), self.help, title='Help for getting MERRA-2 data (' + fileVersion() + ')', section='getmerra2') dialog.exec_()
def helpClicked(self): dialog = displayobject.AnObject(QtWidgets.QDialog(), self.help, title='Help for makerainfall2 (' + fileVersion() + ')', section='merrar') dialog.exec_()
def __init__(self, parent=None): QtWidgets.QDialog.__init__(self, parent) self.siren_dir = '.' if len(sys.argv) > 1: if sys.argv[1][-4:] == '.ini': self.invoke('sirenm', sys.argv[1]) sys.exit() elif os.path.isdir(sys.argv[1]): self.siren_dir = sys.argv[1] if sys.platform == 'win32' or sys.platform == 'cygwin': if self.siren_dir[-1] != '\\' and self.siren_dir[-1] != '/': self.siren_dir += '\\' elif self.siren_dir[-1] != '/': self.siren_dir += '/' else: self.siren_dir = getModelFile() self.entries = [] fils = os.listdir(self.siren_dir) self.help = 'help.html' self.about = 'about.html' self.config = configparser.RawConfigParser() ignore = [ 'flexiplot.ini', 'getfiles.ini', 'powerplot.ini', 'siren_default.ini', 'siren_windows_default.ini' ] errors = '' for fil in sorted(fils): if fil[-4:] == '.ini': if fil in ignore: continue mod_time = time.strftime( '%Y-%m-%d %H:%M:%S', time.localtime(os.path.getmtime(self.siren_dir + fil))) ok, model_name, errors = self.check_file(fil, errors) self.entries.append([fil, model_name, mod_time, ok]) if len(errors) > 0: dialog = displayobject.AnObject(QtWidgets.QDialog(), errors, title='SIREN (' + fileVersion() + ') - Preferences file errors') dialog.exec_() if len(self.entries) == 0: self.new() self.setWindowTitle('SIREN (' + fileVersion() + ') - Select SIREN Model') self.setWindowIcon(QtGui.QIcon('sen_icon32.ico')) buttonLayout = QtWidgets.QHBoxLayout() self.quitButton = QtWidgets.QPushButton(self.tr('&Quit')) buttonLayout.addWidget(self.quitButton) self.quitButton.clicked.connect(self.quit) QtWidgets.QShortcut(QtGui.QKeySequence('q'), self, self.quit) self.newButton = QtWidgets.QPushButton(self.tr('&New Model')) buttonLayout.addWidget(self.newButton) self.newButton.clicked.connect(self.new) buttons = QtWidgets.QFrame() buttons.setLayout(buttonLayout) layout = QtWidgets.QGridLayout() self.table = QtWidgets.QTableWidget() self.table.setRowCount(len(self.entries)) self.table.setColumnCount(3) hdr_labels = ['Preference File', 'SIREN Model', 'Date modified'] self.table.setHorizontalHeaderLabels(hdr_labels) self.headers = self.table.horizontalHeader() self.headers.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.headers.customContextMenuRequested.connect(self.header_click) self.headers.setSelectionMode( QtWidgets.QAbstractItemView.SingleSelection) self.table.verticalHeader().setVisible(False) self.table.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers) self.table.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows) max_row = 30 for rw in range(len(self.entries)): ln = 0 for cl in range(3): self.table.setItem( rw, cl, QtWidgets.QTableWidgetItem(self.entries[rw][cl])) ln += len(self.entries[rw][cl]) if ln > max_row: max_row = ln self.sort_desc = False # start in date descending order self.sort_col = 2 self.order(2) self.table.resizeColumnsToContents() self.table.viewport().installEventFilter(self) fnt = self.table.fontMetrics() ln = max_row * max(9, fnt.averageCharWidth()) ln2 = (len(self.entries) + 8) * (fnt.xHeight() + fnt.lineSpacing()) screen = QtWidgets.QDesktopWidget().screenGeometry() if ln > screen.width() * .9: ln = int(screen.width() * .9) if ln2 > screen.height() * .9: ln2 = int(screen.height() * .9) layout.addWidget( QtWidgets.QLabel( 'Left click on row for Desired Model or right click for Tools; Right click column header to sort' ), 0, 0) layout.addWidget(self.table, 1, 0) layout.addWidget(buttons, 2, 0) menubar = QtWidgets.QMenuBar() utilities = [ 'flexiplot', 'getmap', 'getmerra2', 'makeweatherfiles', 'powerplot', 'sirenupd' ] utilicon = [ 'line.png', 'map.png', 'download.png', 'weather.png', 'line.png', 'download.png' ] spawns = [] icons = [] if sys.platform == 'win32' or sys.platform == 'cygwin': for i in range(len(utilities)): if os.path.exists(utilities[i] + '.exe'): spawns.append(utilities[i] + '.exe') icons.append(utilicon[i]) else: if os.path.exists(utilities[i] + '.py'): spawns.append(utilities[i] + '.py') icons.append(utilicon[i]) else: for i in range(len(utilities)): if os.path.exists(utilities[i] + '.py'): spawns.append(utilities[i] + '.py') icons.append(utilicon[i]) if len(spawns) > 0: spawnitem = [] spawnMenu = menubar.addMenu('&Tools') for i in range(len(spawns)): if type(spawns[i]) is list: who = spawns[i][0][:spawns[i][0].find('.')] else: who = spawns[i][:spawns[i].find('.')] spawnitem.append( QtWidgets.QAction(QtGui.QIcon(icons[i]), who, self)) spawnitem[-1].triggered.connect(partial(self.spawn, spawns[i])) spawnMenu.addAction(spawnitem[-1]) layout.setMenuBar(menubar) self.model_tool = [ 'flexiplot', 'getmap', 'indexweather', 'makegrid', 'powermatch', 'powerplot', 'sirenm', 'updateswis' ] self.model_icon = [ 'line.png', 'map.png', 'list.png', 'grid.png', 'power.png', 'line.png', 'sen_icon32.png', 'list.png' ] help = QtWidgets.QAction(QtGui.QIcon('help.png'), 'Help', self) help.setShortcut('F1') help.setStatusTip('Help') help.triggered.connect(self.showHelp) about = QtWidgets.QAction(QtGui.QIcon('about.png'), 'About', self) about.setShortcut('Ctrl+I') about.setStatusTip('About') about.triggered.connect(self.showAbout) helpMenu = menubar.addMenu('&Help') helpMenu.addAction(help) helpMenu.addAction(about) self.setLayout(layout) size = QtCore.QSize(ln, ln2) self.resize(size)
def showAbout(self): dialog = displayobject.AnObject(QtWidgets.QDialog(), self.about, title='About SENs SAM Model') dialog.exec_()
def eventFilter(self, source, event): if self.table.selectedIndexes() != []: if event.type() == QtCore.QEvent.MouseButtonRelease and \ event.button() == QtCore.Qt.LeftButton: ent = self.table.item(self.table.currentRow(), 0).text() self.table.viewport().removeEventFilter(self) self.invoke('sirenm', self.siren_dir + ent) self.quit() if (event.type() == QtCore.QEvent.MouseButtonPress or event.type() == QtCore.QEvent.MouseButtonRelease) and \ event.button() == QtCore.Qt.RightButton: ent = self.table.item(self.table.currentRow(), 0).text() index = self.table.indexAt(event.pos()) selectionModel = self.table.selectionModel() selectionModel.select( self.table.model().index(self.table.currentRow(), 0), selectionModel.Deselect | selectionModel.Rows) selectionModel.select(self.table.model().index(index.row(), 0), selectionModel.Rows) menu = QtWidgets.QMenu() actions = [] for i in range(len(self.model_tool)): if self.model_tool[i] == 'updateswis': mdl = self.table.item(self.table.currentRow(), 1).text() if mdl.find('SWIS') < 0: continue actions.append( menu.addAction(QtGui.QIcon(self.model_icon[i]), 'Execute ' + self.model_tool[i])) actions[-1].setIconVisibleInMenu(True) actions.append( menu.addAction(QtGui.QIcon('edit.png'), 'Edit Preferences')) actions[-1].setIconVisibleInMenu(True) actions.append( menu.addAction(QtGui.QIcon('edit.png'), 'Edit File Preferences')) actions[-1].setIconVisibleInMenu(True) action = menu.exec_(self.mapToGlobal(event.pos())) if action is not None: if action.text()[:8] == 'Execute ': if not self.entries[self.table.currentRow()][3]: ok, model_name, errors = self.check_file(ent) if len(errors) > 0: dialog = displayobject.AnObject( QtWidgets.QDialog(), errors, title='SIREN (' + fileVersion() + ') - Preferences file errors') dialog.exec_() return QtCore.QObject.event(source, event) self.invoke(action.text()[8:], self.siren_dir + ent) elif action.text()[-11:] == 'Preferences': i = self.table.item(self.table.currentRow(), 1).text().find('[line ') if i >= 0: j = self.table.item(self.table.currentRow(), 1).text().find(']', i) line = int( self.table.item(self.table.currentRow(), 1).text()[i + 5:j].strip()) - 1 else: line = None if action.text()[-16:] == 'File Preferences': self.editIniFileSects(self.siren_dir + ent) else: self.editIniFile(self.siren_dir + ent, line=line) ok, model_name, errors = self.check_file(ent) if model_name != self.entries[ self.table.currentRow()][1]: self.entries[ self.table.currentRow()][1] = model_name self.table.setItem( self.table.currentRow(), 1, QtWidgets.QTableWidgetItem(model_name)) if len(errors) > 0: self.entries[self.table.currentRow()][3] = False dialog = displayobject.AnObject( QtWidgets.QDialog(), errors, title='SIREN (' + fileVersion() + ') - Preferences file errors') dialog.exec_() return QtCore.QObject.event(source, event) else: self.entries[self.table.currentRow()][3] = True return QtCore.QObject.event(source, event)
def helpClicked(self): dialog = displayobject.AnObject(QtWidgets.QDialog(), self.helpfile, title='Resource Help', section='resource') dialog.exec_()