def __init__(self, ini_file=None, parent=None): QtWidgets.QDialog.__init__(self, parent) file_sects = ['Parents', 'Files', 'SAM Modules'] dir_props = [ 'pow_files', 'sam_sdk', 'scenarios', 'solar_files', 'variable_files', 'wind_files' ] field_props = ['check', 'scenario_prefix'] config = configparser.RawConfigParser() if ini_file is not None: self.config_file = ini_file elif len(sys.argv) > 1: self.config_file = sys.argv[1] else: self.config_file = getModelFile('SIREN.ini') config.read(self.config_file) sections = {} for section in file_sects: props = [] try: items = config.items(section) except: continue for key, value in items: props.append([key, value]) if len(props) > 0: sections[section] = props bgd = 'rgba({}, {}, {}, {})'.format( *self.palette().color(QtGui.QPalette.Window).getRgb()) bgd_style = 'background-color: ' + bgd + '; border: 1px inset grey; min-height: 22px; border-radius: 4px;' bold = QtGui.QFont() bold.setBold(True) width0 = 0 width1 = 0 width2 = 0 row = 0 self.fields = [] self.fields.append( ['section', 'typ', 'name', 'value', QtWidgets.QLineEdit()]) self.grid = QtWidgets.QGridLayout() label = QtWidgets.QLabel('Working directory') label.setFont(bold) width0 = label.fontMetrics().boundingRect(label.text()).width() * 1.1 self.grid.addWidget(label, row, 0) self.fields[row][4].setText(os.getcwd()) self.fields[row][4].setReadOnly(True) self.fields[row][4].setStyleSheet(bgd_style) width2 = self.fields[row][4].fontMetrics().boundingRect( self.fields[row][4].text()).width() * 1.1 self.grid.addWidget(self.fields[row][4], row, 2, 1, 3) self.parents = {} sections['Parents'].append(['$USER$', getUser()]) now = datetime.datetime.now() sections['Parents'].append(['$YEAR$', str(now.year - 1)]) if 'Parents' in list(sections.keys()): for key, value in sections['Parents']: self.parents[key] = value row += 1 self.fields.append(['Parents', '?', key, value, '?']) if self.fields[row][0] != self.fields[row - 1][0]: label = QtWidgets.QLabel(self.fields[row][0]) label.setFont(bold) width0 = max( width0, label.fontMetrics().boundingRect(label.text()).width() * 1.1) self.grid.addWidget(label, row, 0) label = QtWidgets.QLabel(self.fields[row][2]) width1 = max( width1, label.fontMetrics().boundingRect(label.text()).width() * 1.1) self.grid.addWidget(label, row, 1) if key == '$USER$' or key == '$YEAR$': self.fields[row][1] = 'txt' self.fields[row][4] = QtWidgets.QLineEdit() self.fields[row][4].setText(self.fields[row][3]) width2 = max( width2, self.fields[row][4].fontMetrics().boundingRect( self.fields[row][4].text()).width() * 1.1) self.fields[row][4].setReadOnly(True) self.fields[row][4].setStyleSheet(bgd_style) self.grid.addWidget(self.fields[row][4], row, 2, 1, 3) else: self.fields[row][1] = 'dir' self.fields[row][4] = ClickableQLabel() self.fields[row][4].setText(self.fields[row][3]) width2 = max( width2, self.fields[row][4].fontMetrics().boundingRect( self.fields[row][4].text()).width() * 1.1) self.fields[row][4].setStyleSheet( "background-color: white; border: 1px inset grey; min-height: 22px; border-radius: 4px;" ) self.grid.addWidget(self.fields[row][4], row, 2, 1, 3) self.fields[row][4].clicked.connect(self.itemClicked) for section, props in sections.items(): if section == 'Parents': continue for prop in props: row += 1 self.fields.append([section, '?', prop[0], prop[1], '?']) if self.fields[row][0] != self.fields[row - 1][0]: label = QtWidgets.QLabel(self.fields[row][0]) label.setFont(bold) width0 = max( width0, label.fontMetrics().boundingRect(label.text()).width() * 1.1) self.grid.addWidget(label, row, 0) label = QtWidgets.QLabel(self.fields[row][2]) width1 = max( width1, label.fontMetrics().boundingRect(label.text()).width() * 1.1) self.grid.addWidget(label, row, 1) self.fields[row][3] = prop[1] if prop[0] in field_props: self.fields[row][1] = 'txt' self.fields[row][4] = QtWidgets.QLineEdit() self.fields[row][4].setText(self.fields[row][3]) width2 = max( width2, self.fields[row][4].fontMetrics().boundingRect( self.fields[row][4].text()).width() * 1.1) else: if prop[0] in dir_props: self.fields[row][1] = 'dir' else: self.fields[row][1] = 'fil' self.fields[row][4] = ClickableQLabel() self.fields[row][4].setText(self.fields[row][3]) width2 = max( width2, self.fields[row][4].fontMetrics().boundingRect( self.fields[row][4].text()).width() * 1.1) self.fields[row][4].setStyleSheet( "background-color: white; border: 1px inset grey; min-height: 22px; border-radius: 4px;" ) self.fields[row][4].clicked.connect(self.itemClicked) self.grid.addWidget(self.fields[row][4], row, 2, 1, 3) row += 1 quit = QtWidgets.QPushButton('Quit', self) self.grid.addWidget(quit, row, 0) quit.clicked.connect(self.quitClicked) QtWidgets.QShortcut(QtGui.QKeySequence('q'), self, self.quitClicked) save = QtWidgets.QPushButton('Save & Exit', self) self.grid.addWidget(save, row, 1) save.clicked.connect(self.saveClicked) self.grid.setColumnStretch(2, 5) frame = QtWidgets.QFrame() frame.setLayout(self.grid) self.scroll = QtWidgets.QScrollArea() self.scroll.setWidgetResizable(True) self.scroll.setWidget(frame) self.layout = QtWidgets.QVBoxLayout(self) self.layout.addWidget(self.scroll) self.setWindowTitle('SIREN - Edit File Sections - ' + ini_file[ini_file.rfind('/') + 1:]) self.setWindowIcon(QtGui.QIcon('sen_icon32.ico')) self.resize(int(width0 + width1 + width2), int(self.sizeHint().height() * 1.1)) self.show()