def property_changed(self, pwidget): """Get information from a possibly changed parameter. Parameters ---------- pwidget : QWidget The parameter widget that has possibly changed. """ pos = self.layout.indexOf(pwidget) if pos == -1: for i in range(3, self.layout.count() - 1): group_box = self.layout.itemAtPosition(i, 0).widget() glayout = group_box.layout() pos = glayout.indexOf(pwidget) if pos != -1: qualifier = "{}/{}".format(self.name, group_box.objectName()) ConfigurationTab.property_changed(self, pwidget, layout=glayout, qualifier=qualifier, position=i) break else: ConfigurationTab.property_changed(self, pwidget)
def __init__(self, name, parent=None): """Initialize the class. Parameters ---------- name : str The name for the tab title. parent : QWidget The parent widget of this one. """ ConfigurationTab.__init__(self, name, parent=parent)
def reset_all(self, layout=None, qualifier=None, positions=None): """Reset all of the changed parameters. """ for i in xrange(self.layout.rowCount()): widget = self.layout.itemAtPosition(i, 0).widget() if isinstance(widget, QtWidgets.QGroupBox): glayout = widget.layout() qualifier = "{}/{}".format(self.name, widget.title()) ConfigurationTab.reset_all(self, layout=glayout, qualifier=qualifier, position=i) else: property_name = str(widget.text()) if property_name.endswith(self.CHANGED_PARAMETER): self.getProperty.emit(property_name.strip(self.CHANGED_PARAMETER), [i])
def reset_all(self, layout=None, qualifier=None, positions=None): """Reset all of the changed parameters. """ for i in range(self.layout.rowCount()): widget = self.layout.itemAtPosition(i, 0).widget() if isinstance(widget, QtWidgets.QGroupBox): glayout = widget.layout() qualifier = "{}/{}".format(self.name, widget.title()) ConfigurationTab.reset_all(self, layout=glayout, qualifier=qualifier, position=i) else: property_name = str(widget.text()) if property_name != "name": property_name = self.name + "/" + property_name if property_name.endswith(self.CHANGED_PARAMETER): self.getProperty.emit(property_name.strip(self.CHANGED_PARAMETER), [i])
def __init__(self, name, proposals, parent=None): """Initialize the class. Parameters ---------- name : str The name for the tab title. proposals : dict The default set of proposals. parent : QWidget The parent widget of this one. """ self.proposals = proposals self.GEN_PROP_GB_POS = 3 ConfigurationTab.__init__(self, name, parent=parent)
def reset_field(self, position, param_value): """Mark a parameter widget as changed. Parameters ---------- position : list(int) The position (usually row) of the widget. param_value : str The string representation of the parameter value. """ if len(position) > 1: group_box = self.layout.itemAtPosition(position[0], 0).widget() glayout = group_box.layout() ConfigurationTab.reset_field(self, position, param_value, layout=glayout) else: ConfigurationTab.reset_field(self, position, param_value)
def is_changed(self, position, is_changed): """Mark a parameter widget as changed. Parameters ---------- position : int The position (usually row) of the widget. is_changed : bool Flag set to True if the parameter has changed from baseline, false if not. """ if len(position) > 1: group_box = self.layout.itemAtPosition(position[0], 0).widget() glayout = group_box.layout() ConfigurationTab.is_changed(self, position, is_changed, layout=glayout) else: ConfigurationTab.is_changed(self, position, is_changed)
def get_diff(self, layout=None, parent_name=None): """Get the changed parameters. Parameters ---------- layout : QLayout, optional An alternative layout to check. parent_name : str, optional The name of a parent tab. Returns ------- dict{str: str} The set of changed parameters. """ if layout is None: diff = ConfigurationTab.get_diff(self, layout=layout, parent_name=parent_name) else: self.diff_props.append(parent_name) # Parent class calls this function with another layout, so just return the results. return ConfigurationTab.get_diff(self, layout=layout, parent_name=parent_name) for name in self.diff_props: props_changed = False for key in diff: if name in key: props_changed = True if props_changed: del diff["survey/{}".format(name)] prop_gb_loc = self.prop_loc_map[name] prop_gb = self.layout.itemAtPosition(prop_gb_loc, 0).widget() prop_gb_layout = prop_gb.layout() proposals = [] for i in range(prop_gb_layout.rowCount()): cb = prop_gb_layout.itemAtPosition(i, 1).widget() if cb.isChecked(): proposals.append( str( prop_gb_layout.itemAtPosition( i, 0).widget().text())) diff["survey"][name] = [",".join(proposals)] self.diff_props = [] return diff
def set_information(self, params): """Set the information for the configuration. Parameters ---------- params : dict The configuration information. """ for key, value in params.items(): if "proposals" in key: if "general" in key: gen_prop_gb = self.layout.itemAtPosition(self.GEN_PROP_GB_POS, 0).widget() for proposal in value["value"].split(','): cb = gen_prop_gb.findChild(QtWidgets.QCheckBox, proposal) cb.setChecked(True) else: ConfigurationTab.set_information(self, key, value)
def reset_active_field(self): """Reset the active (has focus) parameter widget. """ for i in range(self.layout.rowCount()): widget = self.layout.itemAtPosition(i, 0).widget() if isinstance(widget, QtWidgets.QGroupBox): glayout = widget.layout() qualifier = "{}/{}".format(self.name, widget.title()) ConfigurationTab.reset_active_field(self, layout=glayout, qualifier=qualifier, position=i) else: property_name = str(widget.text()) if property_name.endswith(self.CHANGED_PARAMETER): self.getProperty.emit( property_name.strip(self.CHANGED_PARAMETER), [i])
def __init__(self, name, params, parent=None): """Initialize the class. Parameters ---------- name : str The name for the tab title. params : dict A set of parameters to help dynamically create the widgets. parent : QWidget The parent widget of this one. """ self.group_box_rows = [] self.num_group_boxes = 0 self.setup = params ConfigurationTab.__init__(self, name, self.property_changed, parent) del self.setup
def __init__(self, name, params, parent=None): """Initialize the class. Parameters ---------- name : str The name for the tab title. params : dict A set of parameters to help dynamically create the widgets. parent : QWidget The parent widget of this one. """ self.group_box_rows = [] self.num_group_boxes = 0 self.setup = params self.full_check = False ConfigurationTab.__init__(self, name, self.property_changed, parent) del self.setup
def __init__(self, name, proposals, parent=None): """Initialize the class. Parameters ---------- name : str The name for the tab title. proposals : dict The default set of proposals. parent : QWidget The parent widget of this one. """ self.proposals = proposals self.GEN_PROP_GB_POS = 3 self.SEQ_PROP_GB_POS = 4 self.prop_loc_map = { "general_proposals": self.GEN_PROP_GB_POS, "sequence_proposals": self.SEQ_PROP_GB_POS } self.diff_props = [] ConfigurationTab.__init__(self, name, parent=parent)
def property_changed(self, pwidget): """Get information from a possibly changed parameter. Parameters ---------- pwidget : QWidget The parameter widget that has possibly changed. """ pos = self.layout.indexOf(pwidget) if pos == -1: for i in xrange(1, self.layout.count() - 1): group_box = self.layout.itemAtPosition(i, 0).widget() glayout = group_box.layout() pos = glayout.indexOf(pwidget) if pos != -1: qualifier = "{}/{}".format(self.name, group_box.title()) ConfigurationTab.property_changed(self, pwidget, layout=glayout, qualifier=qualifier, position=i) break else: ConfigurationTab.property_changed(self, pwidget)
def set_information(self, params, full_check=False): """Set the information for the configuration. Parameters ---------- params : dict The configuration information. full_check : bool Flag to run through all proposals in group boxes. """ for key, value in list(params.items()): if "proposals" in key: prop_gb = None if "general" in key: prop_gb = self.layout.itemAtPosition( self.GEN_PROP_GB_POS, 0).widget() if "sequence" in key: prop_gb = self.layout.itemAtPosition( self.SEQ_PROP_GB_POS, 0).widget() if not full_check: for proposal in value["value"].split(','): cb = prop_gb.findChild(QtWidgets.QCheckBox, proposal) if cb is not None: cb.setChecked(True) else: glayout = prop_gb.layout() proposals = value["value"].split(',') for i in range(glayout.rowCount()): lwidget = glayout.itemAtPosition(i, 0).widget() prop_label = str(lwidget.text()) if prop_label not in proposals: cb = glayout.itemAtPosition(i, 1).widget() cb.setChecked(False) else: ConfigurationTab.set_information(self, key, value, full_check=full_check)
def get_diff(self, layout=None, parent_name=None): """Get the changed parameters. Parameters ---------- layout : QLayout, optional An alternative layout to check. parent_name : str, optional The name of a parent tab. Returns ------- dict{str: str} The set of changed parameters. """ if layout is None: diff = ConfigurationTab.get_diff(self, layout=layout, parent_name=parent_name) else: # Parent class calls this function with another layout, so just return the results. return ConfigurationTab.get_diff(self, layout=layout, parent_name=parent_name) general_props_changed = False for key in diff: if "general_proposals" in key: general_props_changed = True if general_props_changed: del diff["survey/general_proposals"] general_prop_gb = self.layout.itemAtPosition(self.GEN_PROP_GB_POS, 0).widget() general_prop_gb_layout = general_prop_gb.layout() general_proposals = [] for i in xrange(general_prop_gb_layout.rowCount()): cb = general_prop_gb_layout.itemAtPosition(i, 1).widget() if cb.isChecked(): general_proposals.append(str(general_prop_gb_layout.itemAtPosition(i, 0).widget().text())) diff["survey"]["general_proposals"] = [",".join(general_proposals)] return diff
def get_changed_parameters(self, layout=None, parent_name=None): """Find the changed parameters. Parameters ---------- layout : QLayout, optional An alternative layout to check. parent_name : str, optional The name of a parent tab. Returns ------- list((str, str)) A list of 2-tuples of the changed property name and the property value. """ changed_values = ConfigurationTab.get_changed_parameters( self, layout=layout, parent_name=parent_name) props_changed = False for changed_value in changed_values: if parent_name in changed_value[0]: props_changed = True corrected_changed_values = [] if props_changed: for changed_value in changed_values: if parent_name not in changed_value[0]: corrected_changed_values.append(changed_value) prop_gb_loc = self.prop_loc_map[parent_name] prop_gb = self.layout.itemAtPosition(prop_gb_loc, 0).widget() prop_gb_layout = prop_gb.layout() props = [] for i in range(prop_gb_layout.rowCount()): cb = prop_gb_layout.itemAtPosition(i, 1).widget() if cb.isChecked(): props.append( str( prop_gb_layout.itemAtPosition(i, 0).widget().text())) corrected_changed_values.append((parent_name, props)) else: corrected_changed_values = changed_values return corrected_changed_values
def get_changed_parameters(self, layout=None, parent_name=None): """Find the changed parameters. Parameters ---------- layout : QLayout, optional An alternative layout to check. parent_name : str, optional The name of a parent tab. Returns ------- list((str, str)) A list of 2-tuples of the changed property name and the property value. """ changed_values = ConfigurationTab.get_changed_parameters(self, layout=layout, parent_name=parent_name) general_props_changed = False for changed_value in changed_values: if "general_proposals" in changed_value[0]: general_props_changed = True corrected_changed_values = [] if general_props_changed: for changed_value in changed_values: if "general_proposals" not in changed_value[0]: corrected_changed_values.append(changed_value) general_prop_gb = self.layout.itemAtPosition(self.GEN_PROP_GB_POS, 0).widget() general_prop_gb_layout = general_prop_gb.layout() general_proposals = [] for i in xrange(general_prop_gb_layout.rowCount()): cb = general_prop_gb_layout.itemAtPosition(i, 1).widget() if cb.isChecked(): general_proposals.append(str(general_prop_gb_layout.itemAtPosition(i, 0).widget().text())) corrected_changed_values.append(("general_proposals", general_proposals)) else: corrected_changed_values = changed_values return corrected_changed_values