def setup_ui(self): """Initialize widgets.""" info_label = QLabel() info_label.setText("Hit enter to capture your image!") self.image_label = QLabel() self.image_label.setMinimumSize(320, 240) self.image_label.setScaledContents(True) button_layout = QVBoxLayout() button_layout.setAlignment(Qt.AlignLeft) self.style_buttons = [ QRadioButton(settings.STYLE_SHORTCUTS[i] + ". " + style.name if i < len(settings.STYLE_SHORTCUTS) else style.name) for i, style in enumerate(self.styles) ] self.style_buttons[self.styles.index( self.selected_style)].setChecked(True) self.style_button_group = QButtonGroup() for i, btn in enumerate(self.style_buttons): button_layout.addWidget(btn) self.style_button_group.addButton(btn, i) btn.clicked.connect( partial(lambda style: self.style_button_clicked(style), self.styles[i])) button_layout.addStretch(1) ctrl_layout = QHBoxLayout() if not settings.KIOSK: fullscreen_button = QPushButton('[ ]') fullscreen_button.setMaximumWidth( fullscreen_button.fontMetrics().boundingRect('[ ]').width() + 10) fullscreen_button.clicked.connect(self.toggle_fullscreen) ctrl_layout.addWidget(fullscreen_button) ctrl_layout.addStretch(1) self.size_combo = QComboBox() for s in settings.SIZES: self.size_combo.addItem(s) self.size_combo.setCurrentIndex(settings.SIZES.index(self.quality)) ctrl_layout.addWidget(self.size_combo) self.size_combo.activated[str].connect(self.quality_choice) button_layout.addLayout(ctrl_layout) sub_layout = QHBoxLayout() sub_layout.addLayout(button_layout) sub_layout.addWidget(self.image_label, 1) main_layout = QVBoxLayout() main_layout.addWidget(info_label) main_layout.addLayout(sub_layout) self.setLayout(main_layout)
def setup_monitors(self): ui = self.ui.monitors # Grab a fresh copy, may have been updated self.monitors_region_dict = self.ui.regions.get_region_dict() # Mark regions which are in use (this gets reset each time we get here) #for (i, data) in self.monitors.items(): # region = data['region'] # if region in self.monitors_region_dict: # self.monitors_region_dict[region]['available'] = False self.fixup_monitors_table() row = get_selected_row(ui.tablewidget_regions) # Autoselect if only 1 row if row is None and ui.tablewidget_regions.rowCount() == 1: row = 0 ui.tablewidget_regions.setCurrentCell(row, COLUMN_REGION) enabled = (row is not None) for item in (ui.toolbutton_delete, ui.bottom_frame): item.setEnabled(enabled) mon = self.monitors_current_index enable_phase = self.monitor_requires_phase(mon) #**Fluid phase tab** b = ui.pushbutton_fluid b.setText(self.fluid_phase_name) font = b.font() font.setBold(self.monitors_current_tab == FLUID_TAB) b.setFont(font) w = b.fontMetrics().boundingRect(b.text()).width() + 20 b.setMaximumWidth(w) b.setEnabled(not enable_phase) #**Solids Phase Tab** *(Requires TFM Solids)* #Each solid phase will have its own tab. The tab name should be the name of the solid solids_names = list(self.solids.keys()) if self.monitors_saved_solids_names != solids_names: # Clear out the old ones n_cols = ui.tab_layout.columnCount() for i in range(n_cols - 1, 0, -1): item = ui.tab_layout.itemAtPosition(0, i) if not item: continue widget = item.widget() if not widget: continue if widget in (ui.pushbutton_fluid, ui.pushbutton_scalar, ui.pushbutton_reactions, ui.pushbutton_phase): continue ui.tab_layout.removeWidget(widget) widget.setParent(None) widget.deleteLater() # And make new ones for (i, solid_name) in enumerate(solids_names, 1): b = QPushButton(text=solid_name) w = b.fontMetrics().boundingRect(solid_name).width() + 20 b.setMaximumWidth(w) b.setFlat(True) font = b.font() font.setBold(self.monitors_current_tab == SOLIDS_TAB and i == self.monitors_current_solid) b.setFont(font) b.pressed.connect( lambda i=i: self.monitors_change_tab(SOLIDS_TAB, i)) ui.tab_layout.addWidget(b, 0, i) # Only TFM solids for i in range(1, 1 + len(self.solids)): enabled = self.project.get_value( 'solids_model', args=[i]) == 'TFM' and not enable_phase item = ui.tab_layout.itemAtPosition(0, i) if item: widget = item.widget() if widget: widget.setEnabled(enabled) #Scalar (tab) - Tab only available if scalar equations are solved # Move the 'Scalar' button to the right of all solids, if needed b = ui.pushbutton_scalar font = b.font() font.setBold(self.monitors_current_tab == SCALAR_TAB) b.setFont(font) nscalar = self.project.get_value('nscalar', default=0) enabled = (nscalar > 0) and not enable_phase b.setEnabled(enabled) if len(self.solids) != len(self.monitors_saved_solids_names): ui.tab_layout.removeWidget(b) ui.tab_layout.addWidget(b, 0, 1 + len(self.solids)) #Reactions (tab) - Tab only available if nrr > 0 # Move the 'Reactions' button to the right of all solids, if needed b = ui.pushbutton_reactions font = b.font() font.setBold(self.monitors_current_tab == REACTIONS_TAB) b.setFont(font) nrr = self.project.get_value('nrr', default=0) enabled = (nrr > 0) and not enable_phase if nrr == 0 and not enable_phase: b.setToolTip("Requires nrr > 0") else: b.setToolTip('') b.setEnabled(enabled) if len(self.solids) != len(self.monitors_saved_solids_names): ui.tab_layout.removeWidget(b) ui.tab_layout.addWidget(b, 0, 2 + len(self.solids)) # Move the 'Phase' button to the right of all solids, if needed b = ui.pushbutton_phase font = b.font() font.setBold(self.monitors_current_tab == PHASE_TAB) b.setFont(font) b.setEnabled(enable_phase) if len(self.solids) != len(self.monitors_saved_solids_names): ui.tab_layout.removeWidget(b) ui.tab_layout.addWidget(b, 0, 3 + len(self.solids)) self.monitors_saved_solids_names = solids_names self.P = self.monitors_current_solid if mon is None: #Construct the GUI, even though disabled (species checkboxes, etc) self.monitors_setup_current_tab() return key = 'monitor_name' le = ui.lineedit_keyword_monitor_name_args_MONITOR val = self.project.get_value(key, args=[mon]) if val is None: # Construct from region name val = self.monitor_default_name(self.monitors_current_region) self.update_keyword(key, val, args=[mon]) le.updateValue(key, val) # Update table too tw = ui.tablewidget_regions for i in range(tw.rowCount()): data = tw.item(i, 0).data(UserRole) index, name = data if index == mon: tw.item(i, COLUMN_FILENAME).setText(val) #Specify write interval key = 'monitor_dt' default = 0.05 le = ui.lineedit_keyword_monitor_dt_args_MONITOR val = self.project.get_value(key, args=[mon]) if val is None: val = default self.update_keyword(key, val, args=[mon]) le.updateValue(key, val) # Don't stay on a disabled tab index = self.monitors_tab_to_index(self.monitors_current_tab, self.monitors_current_solid) item = None if index is None else ui.tab_layout.itemAtPosition( 0, index) b = item.widget() if item else None if ui.isEnabled() and not (b and b.isEnabled()): self.monitors_change_tab(*self.monitors_find_valid_tab()) else: self.monitors_setup_current_tab() # make sure underline is in the right place, as # of solids may # have changed (lifted from animate_stacked_widget, which we # don't want to call here) tab = self.monitors_current_tab line_to = self.monitors_tab_to_index(tab, self.monitors_current_solid) line = ui.tab_underline btn_layout = ui.tab_layout if line_to is not None: btn_layout.addItem(btn_layout.takeAt(btn_layout.indexOf(line)), 1, line_to)
def setup_pss(self): ui = self.ui.point_sources # Grab a fresh copy, may have been updated self.pss_region_dict = self.ui.regions.get_region_dict() # Mark regions which are in use (this gets reset each time we get here) for (i, data) in self.pss.items(): region = data['region'] if region in self.pss_region_dict: self.pss_region_dict[region]['available'] = False self.fixup_pss_table(ui.tablewidget_regions) row = get_selected_row(ui.tablewidget_regions) # Autoselect if only 1 row if row is None and ui.tablewidget_regions.rowCount() == 1: row = 0 ui.tablewidget_regions.setCurrentCell(row, 0) enabled = (row is not None) for item in (ui.toolbutton_delete, ui.bottom_frame): item.setEnabled(enabled) #Tabs group point source parameters for phases. Tabs are unavailable if no input #is required from the user. # Fluid tab - Unavailable if the fluid phase was disabled. b = ui.pushbutton_fluid b.setText(self.fluid_phase_name) b.setEnabled(not self.fluid_solver_disabled) font = b.font() font.setBold(self.pss_current_tab == 0) b.setFont(font) # Each solid phase will have its own tab. The tab name should be the name of the solid solids_names = list(self.solids.keys()) if self.pss_saved_solids_names != solids_names: # Clear out the old ones n_cols = ui.tab_layout.columnCount() for i in range(n_cols - 1, 0, -1): item = ui.tab_layout.itemAtPosition(0, i) if not item: continue widget = item.widget() if not widget: continue if widget == ui.pushbutton_fluid: continue ui.tab_layout.removeWidget(widget) widget.setParent(None) widget.deleteLater() # And make new ones for (i, solid_name) in enumerate(solids_names, 1): b = QPushButton(text=solid_name) w = b.fontMetrics().boundingRect(solid_name).width() + 20 b.setMaximumWidth(w) b.setFlat(True) font = b.font() font.setBold(self.pss_current_tab == SOLIDS_TAB and i == self.pss_current_solid) b.setFont(font) ui.tab_layout.addWidget(b, 0, i) b.pressed.connect( lambda i=i: self.pss_change_tab(SOLIDS_TAB, i)) for (i, solid_name) in enumerate(self.solids.keys(), 1): model = self.project.get_value('solids_model', args=[i]) #At this time, only TFM solids can be defined with point sources. #At some point in the future, this could be extended to PIC solids, but never DEM. b = ui.tab_layout.itemAtPosition(0, i).widget() if model == 'TFM': b.setEnabled(True) b.setToolTip(None) else: b.setEnabled(False) b.setToolTip("Only TFM solids can be defined as point sources" "") self.pss_saved_solids_names = solids_names self.P = self.pss_current_solid # Don't stay on a disabled tab index = self.pss_tab_to_index(self.pss_current_tab, self.pss_current_solid) item = None if index is None else ui.tab_layout.itemAtPosition( 0, index) b = item.widget() if item else None if ui.isEnabled() and not (b and b.isEnabled()): self.pss_change_tab(*self.pss_find_valid_tab()) else: self.pss_setup_current_tab() # make sure underline is in the right place, as # of solids may # have changed (lifted from animate_stacked_widget, which we # don't want to call here) tab = self.pss_current_tab line_to = self.pss_tab_to_index(tab, self.pss_current_solid) line = ui.tab_underline btn_layout = ui.tab_layout if line_to is not None: btn_layout.addItem(btn_layout.takeAt(btn_layout.indexOf(line)), 1, line_to)