def buildfromauto(formconfig, base): widgetsconfig = formconfig['widgets'] outlayout = QFormLayout() outlayout.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow) outwidget = base outwidget.setLayout(outlayout) for config in widgetsconfig: widgettype = config['widget'] field = config['field'] name = config.get('name', field) if not field: utils.warning("Field can't be null for {}".format(name)) utils.warning("Skipping widget") continue label = QLabel(name) label.setObjectName(field + "_label") widget = roam.editorwidgets.core.createwidget(widgettype, parent=base) widget.setObjectName(field) layoutwidget = QWidget() layoutwidget.setLayout(QBoxLayout(QBoxLayout.LeftToRight)) layoutwidget.layout().addWidget(widget) if config.get('rememberlastvalue', False): savebutton = QToolButton() savebutton.setObjectName('{}_save'.format(field)) layoutwidget.layout().addWidget(savebutton) outlayout.addRow(label, layoutwidget) outlayout.addItem(QSpacerItem(10, 10)) installflickcharm(outwidget) return outwidget
def make_layout(): if newstyle: return QVBoxLayout() else: layout = QFormLayout() layout.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow) return layout
def buildfromauto(formconfig, base): widgetsconfig = formconfig['widgets'] outlayout = QFormLayout() outlayout.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow) outwidget = base outwidget.setLayout(outlayout) for config in widgetsconfig: widgettype = config['widget'] field = config['field'] name = config.get('name', field) if not field: utils.warning("Field can't be null for {}".format(name)) utils.warning("Skipping widget") continue label = QLabel(name) label.setObjectName(field + "_label") widget = roam.editorwidgets.core.createwidget(widgettype, parent=base) widget.setObjectName(field) layoutwidget = QWidget() layoutwidget.setLayout(QBoxLayout(QBoxLayout.LeftToRight)) layoutwidget.layout().addWidget(widget) if config.get('rememberlastvalue', False): savebutton = QToolButton() savebutton.setObjectName('{}_save'.format(field)) layoutwidget.layout().addWidget(savebutton) outlayout.addRow(label, layoutwidget) outlayout.addItem(QSpacerItem(10, 10)) installflickcharm(outwidget) return outwidget
def make_layout(): if newstyle: return QVBoxLayout() else: layout = QFormLayout() layout.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow) return layout
def __init__(self, parent=None, **kwargs): super(ApBbaDlg, self).__init__(parent) self.bpms = [] self.quads = [] self.corrs = [] self.quad_dkicks = [] self.cor_dkicks = [] self.bba = ap.bba.BbaBowtie() self.table = QTableWidget(0, 5) self.table.setMinimumHeight(120) self.table.setMinimumWidth(500) self.table.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) hdview = QHeaderView(Qt.Horizontal) self.table.setHorizontalHeaderLabels( ['QUAD', 'BPM.field', 'BPM center', "Corr", "Kick"]) fmbox = QFormLayout() self.subprogress = QProgressBar() self.subprogress.setTextVisible(True) self.subprogress.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed) self.progress = QProgressBar() self.progress.setTextVisible(True) self.progress.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed) fmbox.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow) fmbox.addRow("Current BPM", self.subprogress) fmbox.addRow("All Alignment", self.progress) #self.progress.setMaximum(self.repeatbox.value()) vbox = QVBoxLayout() vbox.addWidget(self.table) vbox.addLayout(fmbox) #hbox.addStretch() self.widtab = QTabWidget() vbox.addWidget(self.widtab) self.setLayout(vbox) self.connect(self.widtab, SIGNAL("currentChanged(int)"), self.activateResult) self.connect(self.table, SIGNAL("cellClicked(int, int)"), self.activateResult)
def __setupUi(self): layout = QFormLayout() layout.setRowWrapPolicy(QFormLayout.WrapAllRows) layout.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow) self.name_edit = LineEdit(self) self.name_edit.setPlaceholderText(self.tr("untitled")) self.name_edit.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.desc_edit = QTextEdit(self) self.desc_edit.setTabChangesFocus(True) layout.addRow(self.tr("Name"), self.name_edit) layout.addRow(self.tr("Description"), self.desc_edit) self.__schemeIsUntitled = True self.setLayout(layout)
def __setupUi(self): layout = QFormLayout() layout.setRowWrapPolicy(QFormLayout.WrapAllRows) layout.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow) self.name_edit = LineEdit(self) self.name_edit.setPlaceholderText(self.tr("untitled")) self.name_edit.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.desc_edit = QTextEdit(self) self.desc_edit.setTabChangesFocus(True) layout.addRow(self.tr("Name"), self.name_edit) layout.addRow(self.tr("Description"), self.desc_edit) self.__schemeIsUntitled = True self.setLayout(layout)
def __init__(self, base): ModalDialog.__init__(self, 290, 110) self.base = base self.setWindowTitle(i18n.get('select_friend_to_send_message')) self.accounts_combo = QComboBox() accounts = self.base.core.get_registered_accounts() for account in accounts: protocol = get_protocol_from(account.id_) icon = QIcon(base.get_image_path('%s.png' % protocol)) self.accounts_combo.addItem(icon, get_username_from(account.id_), account.id_) completer = QCompleter(self.base.load_friends_list()) completer.setCaseSensitivity(Qt.CaseInsensitive) self.friend = QLineEdit() self.friend.setCompleter(completer) select_button = QPushButton(i18n.get('select')) select_button.clicked.connect(self.__validate) friend_caption = "%s (@)" % i18n.get('friend') form = QFormLayout() form.addRow(friend_caption, self.friend) form.addRow(i18n.get('account'), self.accounts_combo) form.setContentsMargins(30, 10, 10, 5) form.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow) button = QPushButton(i18n.get('search')) button_box = QHBoxLayout() button_box.addStretch(0) button_box.addWidget(select_button) button_box.setContentsMargins(0, 0, 15, 15) layout = QVBoxLayout() layout.addLayout(form) layout.addLayout(button_box) layout.setSpacing(5) layout.setContentsMargins(0, 0, 0, 0) self.setLayout(layout) #load_button = ImageButton(base, 'action-status-menu.png', # i18n.get('load_friends_list')) self.exec_()
def __init__(self, base): QDialog.__init__(self) self.base = base self.setWindowTitle(i18n.get('search')) self.setFixedSize(270, 110) self.setWindowFlags(Qt.Window | Qt.WindowTitleHint | Qt.WindowCloseButtonHint | Qt.CustomizeWindowHint) self.setModal(True) self.accounts_combo = QComboBox() accounts = self.base.core.get_registered_accounts() for account in accounts: protocol = get_protocol_from(account.id_) icon = QIcon(base.get_image_path('%s.png' % protocol)) self.accounts_combo.addItem(icon, get_username_from(account.id_), account.id_) self.criteria = QLineEdit() self.criteria.setToolTip(i18n.get('criteria_tooltip')) form = QFormLayout() form.addRow(i18n.get('criteria'), self.criteria) form.addRow(i18n.get('account'), self.accounts_combo) form.setContentsMargins(30, 10, 10, 5) form.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow) button = QPushButton(i18n.get('search')) button_box = QHBoxLayout() button_box.addStretch(0) button_box.addWidget(button) button_box.setContentsMargins(0, 0, 15, 15) button.clicked.connect(self.accept) layout = QVBoxLayout() layout.addLayout(form) layout.addLayout(button_box) layout.setSpacing(5) layout.setContentsMargins(0, 0, 0, 0) self.setLayout(layout) self.criteria.setFocus() self.exec_()
def __init__(self, base): ModalDialog.__init__(self, 290, 110) self.base = base self.setWindowTitle(i18n.get('select_friend_to_send_message')) self.accounts_combo = QComboBox() accounts = self.base.core.get_registered_accounts() for account in accounts: protocol = get_protocol_from(account.id_) icon = QIcon(base.get_image_path('%s.png' % protocol)) self.accounts_combo.addItem(icon, get_username_from(account.id_), account.id_) completer = QCompleter(self.base.load_friends_list()) completer.setCaseSensitivity(Qt.CaseInsensitive) self.friend = QLineEdit() self.friend.setCompleter(completer) select_button = QPushButton(i18n.get('select')) select_button.clicked.connect(self.__validate) friend_caption = "%s (@)" % i18n.get('friend') form = QFormLayout() form.addRow(friend_caption, self.friend) form.addRow(i18n.get('account'), self.accounts_combo) form.setContentsMargins(30, 10, 10, 5) form.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow) button = QPushButton(i18n.get('search')) button_box = QHBoxLayout() button_box.addStretch(0) button_box.addWidget(select_button) button_box.setContentsMargins(0, 0, 15, 15) layout = QVBoxLayout() layout.addLayout(form) layout.addLayout(button_box) layout.setSpacing(5) layout.setContentsMargins(0, 0, 0, 0) self.setLayout(layout) #load_button = ImageButton(base, 'action-status-menu.png', # i18n.get('load_friends_list')) self.exec_()
def __init__(self, parent=None, **kwargs): super(ApBbaDlg, self).__init__(parent) self.bpms = [] self.quads = [] self.corrs = [] self.quad_dkicks = [] self.cor_dkicks = [] self.bba = ap.bba.BbaBowtie() self.table = QTableWidget(0, 5) self.table.setMinimumHeight(120) self.table.setMinimumWidth(500) self.table.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) hdview = QHeaderView(Qt.Horizontal) self.table.setHorizontalHeaderLabels(["QUAD", "BPM.field", "BPM center", "Corr", "Kick"]) fmbox = QFormLayout() self.subprogress = QProgressBar() self.subprogress.setTextVisible(True) self.subprogress.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed) self.progress = QProgressBar() self.progress.setTextVisible(True) self.progress.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed) fmbox.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow) fmbox.addRow("Current BPM", self.subprogress) fmbox.addRow("All Alignment", self.progress) # self.progress.setMaximum(self.repeatbox.value()) vbox = QVBoxLayout() vbox.addWidget(self.table) vbox.addLayout(fmbox) # hbox.addStretch() self.widtab = QTabWidget() vbox.addWidget(self.widtab) self.setLayout(vbox) self.connect(self.widtab, SIGNAL("currentChanged(int)"), self.activateResult) self.connect(self.table, SIGNAL("cellClicked(int, int)"), self.activateResult)
def __init__(self, base): QDialog.__init__(self) self.base = base self.setWindowTitle(i18n.get('search')) self.setFixedSize(270, 110) self.setWindowFlags(Qt.Window | Qt.WindowTitleHint | Qt.WindowCloseButtonHint | Qt.CustomizeWindowHint) self.setModal(True) self.accounts_combo = QComboBox() accounts = self.base.core.get_registered_accounts() for account in accounts: protocol = get_protocol_from(account.id_) icon = QIcon(base.get_image_path('%s.png' % protocol)) self.accounts_combo.addItem(icon, get_username_from(account.id_), account.id_) self.criteria = QLineEdit() self.criteria.setToolTip(i18n.get('criteria_tooltip')) form = QFormLayout() form.addRow(i18n.get('criteria'), self.criteria) form.addRow(i18n.get('account'), self.accounts_combo) form.setContentsMargins(30, 10, 10, 5) form.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow) button = QPushButton(i18n.get('search')) button_box = QHBoxLayout() button_box.addStretch(0) button_box.addWidget(button) button_box.setContentsMargins(0, 0, 15, 15) button.clicked.connect(self.accept) layout = QVBoxLayout() layout.addLayout(form) layout.addLayout(button_box) layout.setSpacing(5) layout.setContentsMargins(0, 0, 0, 0) self.setLayout(layout) self.criteria.setFocus() self.exec_()
def _initInputUI(self, layout): self.setWindowTitle(u"Send Remote Picture") messageLabel = QLabel(u"Send a remote picture to %s" % self._peerName, self) layout.addWidget(messageLabel) layout.addSpacing(5) formLayout = QFormLayout() formLayout.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow) formLayout.setContentsMargins(0, 0, 0, 0) self.urlInput = QLineEdit(self) if hasattr(self.urlInput, "setPlaceholderText"): self.urlInput.setPlaceholderText("Image URL") formLayout.addRow(u"Image URL:", self.urlInput) self.descInput = QLineEdit(self) if hasattr(self.descInput, "setPlaceholderText"): self.descInput.setPlaceholderText("Description text") formLayout.addRow(u"Description:", self.descInput) self.catInput = QLineEdit(self) if hasattr(self.catInput, "setPlaceholderText"): self.catInput.setPlaceholderText("Category (empty = uncategorized)") formLayout.addRow(u"Category:", self.catInput) layout.addLayout(formLayout)
class GUIBuilder(QMainWindow): def __init__(self, instance): super(GUIBuilder, self).__init__() self.setCentralWidget(QWidget()) layout = QVBoxLayout(self.centralWidget()) self.plots_layout = DockArea() layout.addWidget(self.plots_layout) self.form_layout = QFormLayout() self.form_layout.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow) layout.addLayout(self.form_layout) self.buttons_layout = QHBoxLayout() layout.addLayout(self.buttons_layout) self.instance = instance self.plot_widgets = {} self.plot_data_items = {} self.plot_color_generators = {} seen_form_items = [] seen_plot_items = [] for node in ast.walk(ast.parse(getsource(type(instance)))): if isinstance(node, ast.Call) and isinstance(node.func, ast.Name): if node.func.id.startswith('gb_get_') or node.func.id.startswith('gb_set_'): segs = node.func.id.split('_') caster = __builtins__[segs[2]] name = "_".join(segs[3:]) if name in seen_form_items: continue seen_form_items.append(name) if caster is bool: editor = QCheckBox() if node.func.id.startswith('gb_get_') and node.args: editor.setChecked(node.args[0].id == 'True') get_fn = lambda e=editor: e.isChecked() set_fn = lambda v, e=editor: e.setChecked(v) else: editor = QLineEdit() if node.func.id.startswith('gb_get_') and node.args: if isinstance(node.args[0], ast.Num): init = node.args[0].n else: init = node.args[0].s editor.setText(str(caster(init))) get_fn = lambda e=editor, c=caster: c(e.text()) set_fn = lambda val, e=editor: e.setText(str(val)) base_name = "_".join(segs[2:]) get_name = "gb_get_" + base_name set_name = "gb_set_" + base_name __builtins__[get_name] = lambda init=0, get_fn=get_fn: get_fn() __builtins__[set_name] = lambda val, set_fn=set_fn: set_fn(val) self.form_layout.addRow(prettify(name), editor) if node.func.id.startswith('gb_plot_'): segs = node.func.id.split("_") plot_type = segs[2] plot_name = segs[3] if len(segs) >= 5: data_item_name = "_".join(segs[4:]) else: data_item_name = "" if (plot_name, data_item_name) in seen_plot_items: continue seen_plot_items.append((plot_name, data_item_name)) if plot_name not in self.plot_widgets: if plot_type in ['y', 'xy']: pw = PlotWidget() self.plot_widgets[plot_name] = pw self.plot_color_generators[plot_name] = itertools.cycle('rgb') pw.addLegend() else: raise ValueError("Unknown plot type in {}: {}".format(node.func.id, plot_type)) dock = Dock(name=prettify(plot_name), widget=pw) self.plots_layout.addDock(dock, 'above') self.add_plot_item(node.func.id, plot_name, data_item_name) if isinstance(node, ast.FunctionDef): if node.name.endswith("_gb_button"): name = "_".join(node.name.split("_")[:-2]) button = QPushButton(prettify(name)) button.clicked.connect(getattr(instance, node.name)) self.buttons_layout.addWidget(button) def add_plot_item(self, fn_name, plot_name, data_item_name): plot_widget = self.plot_widgets[plot_name] color_generator = self.plot_color_generators[plot_name] plot_type = fn_name.split("_")[2] if plot_type == "xy": def plot_fn(x, y): if data_item_name in self.plot_data_items: self.plot_data_items[data_item_name].setData(x, y) else: self.plot_data_items[data_item_name] = plot_widget.plot( x, y, name=prettify(data_item_name), pen=color_generator.next() ) elif plot_type == "y": def plot_fn(y): if data_item_name in self.plot_data_items: self.plot_data_items[data_item_name].setData(y) else: self.plot_data_items[data_item_name] = plot_widget.plot( y, name=prettify(data_item_name), pen=color_generator.next() ) else: raise ValueError("Unknown plot type in {}: {}".format(fn_name, plot_type)) __builtins__[fn_name] = plot_fn
class CustomDialog(QDialog): INVALID_COLOR = QColor(255, 235, 235) def __init__(self, title="Title", description="Description", parent=None): QDialog.__init__(self, parent) self._option_list = [] """ :type: list of QWidget """ self.setModal(True) self.setWindowTitle(title) self.layout = QFormLayout() self.layout.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow) self.layout.setSizeConstraint(QLayout.SetFixedSize) label = QLabel(description) label.setAlignment(Qt.AlignHCenter) self.layout.addRow(self.createSpace(5)) self.layout.addRow(label) self.layout.addRow(self.createSpace(10)) self.ok_button = None self.setLayout(self.layout) def notValid(self, msg): """Called when the name is not valid.""" self.ok_button.setEnabled(False) def valid(self): """Called when the name is valid.""" self.ok_button.setEnabled(True) def optionValidationChanged(self): valid = True for option in self._option_list: if hasattr(option, "isValid"): if not option.isValid(): valid = False self.notValid("One or more options are incorrectly set!") if valid: self.valid() def showAndTell(self): """ Shows the dialog modally and returns the true or false (accept/reject) @rtype: bool """ self.optionValidationChanged() return self.exec_() def createSpace(self, size=5): """Creates a widget that can be used as spacing on a panel.""" qw = QWidget() qw.setMinimumSize(QSize(size, size)) return qw def addSpace(self, size=10): """ Add some vertical spacing """ space_widget = self.createSpace(size) self.layout.addRow("", space_widget) def addLabeledOption(self, label, option_widget): """ @type option_widget: QWidget """ self._option_list.append(option_widget) if hasattr(option_widget, "validationChanged"): option_widget.validationChanged.connect(self.optionValidationChanged) if hasattr(option_widget, "getValidationSupport"): validation_support = option_widget.getValidationSupport() validation_support.validationChanged.connect(self.optionValidationChanged) self.layout.addRow("%s:" % label, option_widget) def addWidget(self, widget, label=""): if not label.endswith(":"): label = "%s:" % label self.layout.addRow(label, widget) def addButtons(self): buttons = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal, self) self.ok_button = buttons.button(QDialogButtonBox.Ok) self.ok_button.setEnabled(False) self.layout.addRow(self.createSpace(10)) self.layout.addRow(buttons) self.connect(buttons, SIGNAL('accepted()'), self.accept) self.connect(buttons, SIGNAL('rejected()'), self.reject)
class TrackingParamsWindow(QMainWindow): def __init__(self, controller): QMainWindow.__init__(self) # set controller self.controller = controller # set position & size self.setGeometry(550, 100, 10, 10) # set title self.setWindowTitle("Parameters") # create main widget self.main_widget = QWidget(self) # create main layout self.main_layout = QVBoxLayout(self.main_widget) self.main_layout.setAlignment(Qt.AlignTop) self.main_layout.addStretch(1) self.main_layout.setSpacing(5) # initialize list of dicts used for accessing all crop parameter controls self.param_controls = [] # create parameter controls self.create_param_controls_layout() self.create_param_controls(self.controller.tracking_params[self.controller.current_tracking_num], self.controller.current_crop) # set main widget self.setCentralWidget(self.main_widget) # set window buttons self.setWindowFlags(Qt.CustomizeWindowHint | Qt.WindowCloseButtonHint | Qt.WindowMinimizeButtonHint | Qt.WindowMaximizeButtonHint) self.show() def create_param_controls_layout(self): # initialize parameter controls variable self.param_controls = None # create form layout for param controls with textboxes self.form_layout = QFormLayout() self.form_layout.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow) self.main_layout.addLayout(self.form_layout) # create dict for storing all parameter controls self.param_controls = {} def create_param_controls(self, params, current_crop): self.add_parameter_label("type", "Tracking type:", params['type'], self.form_layout) self.add_parameter_label("shrink_factor", "Shrink factor:", params['shrink_factor'], self.form_layout) self.add_parameter_label("invert", "Invert:", params['invert'], self.form_layout) self.add_parameter_label("n_tail_points", "Number of tail points:", params['n_tail_points'], self.form_layout) self.add_parameter_label("subtract_background", "Subtract background:", params['subtract_background'], self.form_layout) self.add_parameter_label("media_types", "Media types:", params['media_types'], self.form_layout) self.add_parameter_label("media_paths", "Media paths:", params['media_paths'], self.form_layout) self.add_parameter_label("use_multiprocessing", "Use multiprocessing:", params['use_multiprocessing'], self.form_layout) if params['type'] == "freeswimming": self.add_parameter_label("adjust_thresholds", "Adjust thresholds:", params['adjust_thresholds'], self.form_layout) self.add_parameter_label("track_tail", "Track tail:", params['track_tail'], self.form_layout) self.add_parameter_label("track_eyes", "Track eyes:", params['track_eyes'], self.form_layout) self.add_parameter_label("min_tail_body_dist", "Body/tail min. dist.:", params['min_tail_body_dist'], self.form_layout) self.add_parameter_label("max_tail_body_dist", "Body/tail max. dist.:", params['max_tail_body_dist'], self.form_layout) self.add_parameter_label("eye_resize_factor", "Eye resize factor:", params['eye_resize_factor'], self.form_layout) self.add_parameter_label("interpolation", "Interpolation:", params['interpolation'], self.form_layout) self.add_parameter_label("tail_crop", "Tail crop:", params['tail_crop'], self.form_layout) else: self.add_parameter_label("tail_direction", "Tail direction:", params['tail_direction'], self.form_layout) self.add_parameter_label("tail_start_coords", "Tail start coords:", params['tail_start_coords'], self.form_layout) def add_parameter_label(self, label, description, value, parent): # make value label & add row to form layout param_label = QLabel() param_label.setText(str(value)) parent.addRow(description, param_label) # add to list of crop or global controls self.param_controls[label] = param_label def fileQuit(self): self.close() def closeEvent(self, ce): self.fileQuit()
def __init__(self, parent, elems=[]): QDockWidget.__init__(self, parent) self.model = None #self.connect(self, SIGNAL('tabCloseRequested(int)'), self.closeTab) #gb = QGroupBox("select") fmbox = QFormLayout() #fmbox.addRow("S-Range", self.lblRange) self.elemBox = QLineEdit() self.elemBox.setToolTip( "list elements within the range of the active plot.<br>" "Examples are '*', 'HCOR', 'BPM', 'QUAD', 'c*c20a', 'q*g2*'") self.elems = elems self.elemCompleter = QCompleter(elems) self.elemBox.setCompleter(self.elemCompleter) #self.elemBox.insertSeparator(len(self.elems)) fmbox.addRow("Filter", self.elemBox) #self.refreshBtn = QPushButton("refresh") #fmbox.addRow(self.elemBox) self.fldGroup = QGroupBox() fmbox2 = QFormLayout() self.lblName = QLabel() self.lblField = QLabel() self.lblStep = QLabel() self.lblRange = QLabel() self.valMeter = Qwt.QwtThermo() self.valMeter.setOrientation(Qt.Horizontal, Qwt.QwtThermo.BottomScale) self.valMeter.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed) self.valMeter.setEnabled(False) #fmbox2.addRow("Name", self.lblName) #fmbox2.addRow("Field", self.lblField) fmbox2.addRow("Step", self.lblStep) #fmbox2.addRow("Range", self.valMeter) fmbox2.addRow("Range", self.lblRange) #fmbox2.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow) fmbox2.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow) self.fldGroup.setLayout(fmbox2) self.model = None self.delegate = None self.tableview = ElementPropertyView() #self.tableview.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.tableview.setWhatsThis("double click cell to enter editing mode") fmbox.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow) vbox = QVBoxLayout() vbox.addLayout(fmbox) vbox.addWidget(self.tableview) vbox.addWidget(self.fldGroup) cw = QWidget(self) cw.setLayout(vbox) self.setWidget(cw) #self.connect(self.elemBox, SIGNAL("editingFinished()"), # self.refreshTable) self.connect(self.elemBox, SIGNAL("returnPressed()"), self.refreshTable) #self.connect(self.elemBox, SIGNAL("currentIndexChanged(QString)"), # self.refreshTable) self.setWindowTitle("Element Editor") self.noTableUpdate = True
class VariableEditor(QWidget): """An editor widget for a variable. Can edit the variable name, and its attributes dictionary. """ variable_changed = Signal() def __init__(self, parent=None): QWidget.__init__(self, parent) self.setup_gui() def setup_gui(self): layout = QVBoxLayout() self.setLayout(layout) self.main_form = QFormLayout() self.main_form.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow) layout.addLayout(self.main_form) self._setup_gui_name() self._setup_gui_labels() def _setup_gui_name(self): self.name_edit = QLineEdit() self.main_form.addRow("Name", self.name_edit) self.name_edit.editingFinished.connect(self.on_name_changed) def _setup_gui_labels(self): vlayout = QVBoxLayout() vlayout.setContentsMargins(0, 0, 0, 0) vlayout.setSpacing(1) self.labels_edit = QTreeView() self.labels_edit.setEditTriggers(QTreeView.CurrentChanged) self.labels_edit.setRootIsDecorated(False) self.labels_model = DictItemsModel() self.labels_edit.setModel(self.labels_model) self.labels_edit.selectionModel().selectionChanged.connect( self.on_label_selection_changed) # Necessary signals to know when the labels change self.labels_model.dataChanged.connect(self.on_labels_changed) self.labels_model.rowsInserted.connect(self.on_labels_changed) self.labels_model.rowsRemoved.connect(self.on_labels_changed) vlayout.addWidget(self.labels_edit) hlayout = QHBoxLayout() hlayout.setContentsMargins(0, 0, 0, 0) hlayout.setSpacing(1) self.add_label_action = QAction( "+", self, toolTip="Add a new label.", triggered=self.on_add_label, enabled=False, shortcut=QKeySequence(QKeySequence.New)) self.remove_label_action = QAction( unicodedata.lookup("MINUS SIGN"), self, toolTip="Remove selected label.", triggered=self.on_remove_label, enabled=False, shortcut=QKeySequence(QKeySequence.Delete)) button_size = gui.toolButtonSizeHint() button_size = QSize(button_size, button_size) button = QToolButton(self) button.setFixedSize(button_size) button.setDefaultAction(self.add_label_action) hlayout.addWidget(button) button = QToolButton(self) button.setFixedSize(button_size) button.setDefaultAction(self.remove_label_action) hlayout.addWidget(button) hlayout.addStretch(10) vlayout.addLayout(hlayout) self.main_form.addRow("Labels", vlayout) def set_data(self, var): """Set the variable to edit. """ self.clear() self.var = var if var is not None: self.name_edit.setText(var.name) self.labels_model.set_dict(dict(var.attributes)) self.add_label_action.setEnabled(True) else: self.add_label_action.setEnabled(False) self.remove_label_action.setEnabled(False) def get_data(self): """Retrieve the modified variable. """ name = str(self.name_edit.text()) labels = self.labels_model.get_dict() # Is the variable actually changed. if not self.is_same(): var = type(self.var)(name) var.attributes.update(labels) self.var = var else: var = self.var return var def is_same(self): """Is the current model state the same as the input. """ name = str(self.name_edit.text()) labels = self.labels_model.get_dict() return self.var and name == self.var.name and labels == self.var.attributes def clear(self): """Clear the editor state. """ self.var = None self.name_edit.setText("") self.labels_model.set_dict({}) def maybe_commit(self): if not self.is_same(): self.commit() def commit(self): """Emit a ``variable_changed()`` signal. """ self.variable_changed.emit() @Slot() def on_name_changed(self): self.maybe_commit() @Slot() def on_labels_changed(self, *args): self.maybe_commit() @Slot() def on_add_label(self): self.labels_model.appendRow([QStandardItem(""), QStandardItem("")]) row = self.labels_model.rowCount() - 1 index = self.labels_model.index(row, 0) self.labels_edit.edit(index) @Slot() def on_remove_label(self): rows = self.labels_edit.selectionModel().selectedRows() if rows: row = rows[0] self.labels_model.removeRow(row.row()) @Slot() def on_label_selection_changed(self): selected = self.labels_edit.selectionModel().selectedRows() self.remove_label_action.setEnabled(bool(len(selected)))
class VariableEditor(QWidget): """An editor widget for a variable. Can edit the variable name, and its attributes dictionary. """ variable_changed = Signal() def __init__(self, parent=None): QWidget.__init__(self, parent) self.setup_gui() def setup_gui(self): layout = QVBoxLayout() self.setLayout(layout) self.main_form = QFormLayout() self.main_form.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow) layout.addLayout(self.main_form) self._setup_gui_name() self._setup_gui_labels() def _setup_gui_name(self): self.name_edit = QLineEdit() self.main_form.addRow("Name", self.name_edit) self.name_edit.editingFinished.connect(self.on_name_changed) def _setup_gui_labels(self): vlayout = QVBoxLayout() vlayout.setContentsMargins(0, 0, 0, 0) vlayout.setSpacing(1) self.labels_edit = QTreeView() self.labels_edit.setEditTriggers(QTreeView.CurrentChanged) self.labels_edit.setRootIsDecorated(False) self.labels_model = DictItemsModel() self.labels_edit.setModel(self.labels_model) self.labels_edit.selectionModel().selectionChanged.connect( self.on_label_selection_changed) # Necessary signals to know when the labels change self.labels_model.dataChanged.connect(self.on_labels_changed) self.labels_model.rowsInserted.connect(self.on_labels_changed) self.labels_model.rowsRemoved.connect(self.on_labels_changed) vlayout.addWidget(self.labels_edit) hlayout = QHBoxLayout() hlayout.setContentsMargins(0, 0, 0, 0) hlayout.setSpacing(1) self.add_label_action = QAction("+", self, toolTip="Add a new label.", triggered=self.on_add_label, enabled=False, shortcut=QKeySequence( QKeySequence.New)) self.remove_label_action = QAction(unicodedata.lookup("MINUS SIGN"), self, toolTip="Remove selected label.", triggered=self.on_remove_label, enabled=False, shortcut=QKeySequence( QKeySequence.Delete)) button_size = gui.toolButtonSizeHint() button_size = QSize(button_size, button_size) button = QToolButton(self) button.setFixedSize(button_size) button.setDefaultAction(self.add_label_action) hlayout.addWidget(button) button = QToolButton(self) button.setFixedSize(button_size) button.setDefaultAction(self.remove_label_action) hlayout.addWidget(button) hlayout.addStretch(10) vlayout.addLayout(hlayout) self.main_form.addRow("Labels", vlayout) def set_data(self, var): """Set the variable to edit. """ self.clear() self.var = var if var is not None: self.name_edit.setText(var.name) self.labels_model.set_dict(dict(var.attributes)) self.add_label_action.setEnabled(True) else: self.add_label_action.setEnabled(False) self.remove_label_action.setEnabled(False) def get_data(self): """Retrieve the modified variable. """ name = str(self.name_edit.text()) labels = self.labels_model.get_dict() # Is the variable actually changed. if not self.is_same(): var = type(self.var)(name) var.attributes.update(labels) self.var = var else: var = self.var return var def is_same(self): """Is the current model state the same as the input. """ name = str(self.name_edit.text()) labels = self.labels_model.get_dict() return self.var and name == self.var.name and labels == self.var.attributes def clear(self): """Clear the editor state. """ self.var = None self.name_edit.setText("") self.labels_model.set_dict({}) def maybe_commit(self): if not self.is_same(): self.commit() def commit(self): """Emit a ``variable_changed()`` signal. """ self.variable_changed.emit() @Slot() def on_name_changed(self): self.maybe_commit() @Slot() def on_labels_changed(self, *args): self.maybe_commit() @Slot() def on_add_label(self): self.labels_model.appendRow([QStandardItem(""), QStandardItem("")]) row = self.labels_model.rowCount() - 1 index = self.labels_model.index(row, 0) self.labels_edit.edit(index) @Slot() def on_remove_label(self): rows = self.labels_edit.selectionModel().selectedRows() if rows: row = rows[0] self.labels_model.removeRow(row.row()) @Slot() def on_label_selection_changed(self): selected = self.labels_edit.selectionModel().selectedRows() self.remove_label_action.setEnabled(bool(len(selected)))
def __init__(self): super().__init__() self.selected_node = None self.root_node = None self.model = None box = gui.vBox(self.controlArea, 'Tree', addSpace=20, sizePolicy=QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)) self.info = gui.widgetLabel(box, 'No tree.') layout = QFormLayout() layout.setVerticalSpacing(20) layout.setFieldGrowthPolicy(layout.ExpandingFieldsGrow) box = self.display_box = \ gui.widgetBox(self.controlArea, "Display", addSpace=True, orientation=layout) layout.addRow( "Zoom: ", gui.hSlider(box, self, 'zoom', minValue=1, maxValue=10, step=1, ticks=False, callback=self.toggle_zoom_slider, createLabel=False, addToLayout=False, addSpace=False)) layout.addRow( "Width: ", gui.hSlider(box, self, 'max_node_width', minValue=50, maxValue=200, step=1, ticks=False, callback=self.toggle_node_size, createLabel=False, addToLayout=False, addSpace=False)) policy = QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed) layout.addRow( "Depth: ", gui.comboBox(box, self, 'max_tree_depth', items=["Unlimited"] + ["{} levels".format(x) for x in range(2, 10)], addToLayout=False, sendSelectedValue=False, callback=self.toggle_tree_depth, sizePolicy=policy)) layout.addRow( "Edge width: ", gui.comboBox( box, self, 'line_width_method', items=['Fixed', 'Relative to root', 'Relative to parent'], addToLayout=False, callback=self.toggle_line_width, sizePolicy=policy)) gui.rubber(self.controlArea) self.resize(800, 500) self.scene = TreeGraphicsScene(self) self.scene_view = TreeGraphicsView(self.scene) self.scene_view.setViewportUpdateMode(QGraphicsView.FullViewportUpdate) self.mainArea.layout().addWidget(self.scene_view) self.toggle_zoom_slider() self.scene.selectionChanged.connect(self.update_selection)
class CropsWindow(QMainWindow): def __init__(self, controller): QMainWindow.__init__(self) # set controller self.controller = controller # set position & size self.setGeometry(750, 200, 500, 10) # set title self.setWindowTitle("Crops") # create main widget self.main_widget = QWidget(self) # create main layout self.main_layout = QVBoxLayout(self.main_widget) self.main_layout.setAlignment(Qt.AlignTop) self.main_layout.addStretch(1) self.main_layout.setSpacing(5) # initialize list of dicts used for accessing all crop parameter controls self.crop_param_controls = [] # create tabs widget self.crop_tabs_widget = QTabWidget() self.crop_tabs_widget.setUsesScrollButtons(True) self.crop_tabs_widget.tabCloseRequested.connect( self.controller.remove_crop) self.crop_tabs_widget.currentChanged.connect( self.controller.change_crop) self.crop_tabs_widget.setElideMode(Qt.ElideLeft) self.crop_tabs_widget.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) self.crop_tabs_widget.setMinimumSize(276, 300) self.main_layout.addWidget(self.crop_tabs_widget) # create tabs layout crop_tabs_layout = QHBoxLayout(self.crop_tabs_widget) # create lists for storing all crop tab widgets & layouts self.crop_tab_layouts = [] self.crop_tab_widgets = [] # add crop button layout crop_button_layout = QHBoxLayout() crop_button_layout.setSpacing(5) crop_button_layout.addStretch(1) self.main_layout.addLayout(crop_button_layout) # add delete crop button self.remove_crop_button = QPushButton(u'\u2717 Remove Crop', self) self.remove_crop_button.setMaximumWidth(120) self.remove_crop_button.clicked.connect( lambda: self.controller.remove_crop(self.controller.current_crop)) self.remove_crop_button.setDisabled(True) crop_button_layout.addWidget(self.remove_crop_button) # add new crop button self.create_crop_button = QPushButton(u'\u270E New Crop', self) self.create_crop_button.setMaximumWidth(100) self.create_crop_button.clicked.connect( lambda: self.controller.create_crop()) crop_button_layout.addWidget(self.create_crop_button) # set main widget self.setCentralWidget(self.main_widget) # set window buttons self.setWindowFlags(Qt.CustomizeWindowHint | Qt.WindowMinimizeButtonHint | Qt.WindowMaximizeButtonHint) self.show() def add_textbox(self, label, description, default_value, parent): # make textbox & add row to form layout param_box = QLineEdit() param_box.setObjectName(label) param_box.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) param_box.returnPressed.connect( self.controller.update_crop_params_from_gui) parent.addRow(description, param_box) # set default text if default_value != None: param_box.setText(str(default_value)) # add to list of crop or global controls self.crop_param_controls[-1][label] = param_box def add_slider(self, label, description, minimum, maximum, value, slider_moved_func, parent, tick_interval=1, single_step=1, slider_scale_factor=1, int_values=False): # make layout to hold slider and textbox control_layout = QHBoxLayout() slider_label = label + "_slider" textbox_label = label + "_textbox" # make slider & add to layout slider = QSlider(Qt.Horizontal) slider.setObjectName(label) slider.setFocusPolicy(Qt.StrongFocus) slider.setTickPosition(QSlider.TicksBothSides) slider.setTickInterval(tick_interval) slider.setSingleStep(single_step) slider.setMinimum(minimum) slider.setMaximum(maximum) slider.setValue(value) control_layout.addWidget(slider) # make textbox & add to layout textbox = QLineEdit() textbox.setObjectName(label) textbox.setFixedWidth(40) textbox.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) textbox.returnPressed.connect( self.controller.update_crop_params_from_gui) self.update_textbox_from_slider(slider, textbox, slider_scale_factor, int_values) control_layout.addWidget(textbox) # connect slider to set textbox text & update params slider.sliderMoved.connect(lambda: self.update_textbox_from_slider( slider, textbox, slider_scale_factor, int_values)) slider.sliderMoved.connect(slider_moved_func) slider.sliderPressed.connect(lambda: self.slider_pressed(slider)) slider.sliderReleased.connect(lambda: self.slider_released(slider)) # connect textbox to textbox.editingFinished.connect( lambda: self.update_slider_from_textbox(slider, textbox, slider_scale_factor)) textbox.editingFinished.connect(slider_moved_func) # add row to form layout parent.addRow(description, control_layout) # add to list of controls self.crop_param_controls[-1][slider_label] = slider self.crop_param_controls[-1][textbox_label] = textbox def slider_pressed(self, slider): label = slider.objectName() if "threshold" in label: # store previously-checked threshold checkbox self.prev_checked_threshold_checkbox = self.controller.get_checked_threshold_checkbox( ) checkbox = self.controller.param_window.param_controls[ "show_{}".format(label)] checkbox.setChecked(True) self.controller.toggle_threshold_image(checkbox) def slider_released(self, slider): label = slider.objectName() if "threshold" in label: checkbox = self.controller.param_window.param_controls[ "show_{}".format(label)] checkbox.setChecked(False) if self.prev_checked_threshold_checkbox != None: self.prev_checked_threshold_checkbox.setChecked(True) self.controller.toggle_threshold_image( self.prev_checked_threshold_checkbox) def update_textbox_from_slider(self, slider, textbox, slider_scale_factor=1.0, int_values=False): if int_values: textbox.setText( str(int(slider.sliderPosition() / slider_scale_factor))) else: textbox.setText(str(slider.sliderPosition() / slider_scale_factor)) def update_slider_from_textbox(self, slider, textbox, slider_scale_factor=1.0): slider.setValue(float(textbox.text()) * slider_scale_factor) def set_slider_value(self, label, value, crop_index, slider_scale_factor=1.0, int_values=False): # change slider value without sending signals slider_label = label + "_slider" textbox_label = label + "_textbox" slider = self.crop_param_controls[crop_index][slider_label] if value == None: value = slider.minimum() slider.blockSignals(True) slider.setValue(value * slider_scale_factor) slider.blockSignals(False) # change textbox value textbox = self.crop_param_controls[crop_index][textbox_label] self.update_textbox_from_slider( slider, textbox, slider_scale_factor=slider_scale_factor, int_values=int_values) def set_gui_disabled(self, disbaled_bool): self.crop_tabs_widget.setDisabled(disbaled_bool) self.remove_crop_button.setDisabled(disbaled_bool) self.create_crop_button.setDisabled(disbaled_bool) def create_crop_tab(self, crop_params): # create crop tab widget & layout crop_tab_widget = QWidget(self.crop_tabs_widget) crop_tab_widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) crop_tab_widget.resize(276, 300) crop_tab_layout = QVBoxLayout(crop_tab_widget) # add to list of crop widgets & layouts self.crop_tab_layouts.append(crop_tab_layout) self.crop_tab_widgets.append(crop_tab_widget) # create form layout self.form_layout = QFormLayout() self.form_layout.setFieldGrowthPolicy( QFormLayout.AllNonFixedFieldsGrow) crop_tab_layout.addLayout(self.form_layout) # add dict for storing param controls for this crop self.crop_param_controls.append({}) # add param controls self.create_param_controls(crop_params) # create crop button layout crop_button_layout = QHBoxLayout() crop_button_layout.setSpacing(5) crop_button_layout.addStretch(1) crop_tab_layout.addLayout(crop_button_layout) # add crop buttons self.reset_crop_button = QPushButton(u'\u25A8 Reset Crop', self) self.reset_crop_button.setMaximumWidth(110) self.reset_crop_button.clicked.connect(self.controller.reset_crop) crop_button_layout.addWidget(self.reset_crop_button) self.select_crop_button = QPushButton(u'\u25A3 Select Crop', self) self.select_crop_button.setMaximumWidth(110) self.select_crop_button.clicked.connect(self.controller.select_crop) crop_button_layout.addWidget(self.select_crop_button) # add crop widget as a tab self.crop_tabs_widget.addTab(crop_tab_widget, str(self.controller.current_crop)) # make this crop the active tab self.crop_tabs_widget.setCurrentIndex(self.controller.current_crop) # update text on all tabs for i in range(len(self.controller.params['crop_params'])): self.crop_tabs_widget.setTabText(i, str(i)) def remove_crop_tab(self, index): # remove the tab self.crop_tabs_widget.removeTab(index) # delete this tab's controls, widget & layout del self.crop_param_controls[index] del self.crop_tab_widgets[index] del self.crop_tab_layouts[index] # update text on all tabs for i in range(len(self.controller.params['crop_params'])): self.crop_tabs_widget.setTabText(i, str(i)) def create_param_controls(self, crop_params): if self.controller.current_frame is not None: # add sliders - (key, description, start, end, initial value, parent layout) self.add_slider('crop_y', 'Crop y:', 1, self.controller.current_frame.shape[0], crop_params['crop'][0], self.controller.update_crop_params_from_gui, self.form_layout, tick_interval=50, int_values=True) self.add_slider('crop_x', 'Crop x:', 1, self.controller.current_frame.shape[1], crop_params['crop'][1], self.controller.update_crop_params_from_gui, self.form_layout, tick_interval=50, int_values=True) self.add_slider('offset_y', 'Offset y:', 0, self.controller.current_frame.shape[0] - 1, crop_params['offset'][0], self.controller.update_crop_params_from_gui, self.form_layout, tick_interval=50, int_values=True) self.add_slider('offset_x', 'Offset x:', 0, self.controller.current_frame.shape[1] - 1, crop_params['offset'][1], self.controller.update_crop_params_from_gui, self.form_layout, tick_interval=50, int_values=True) else: self.add_slider('crop_y', 'Crop y:', 1, 2, 1, self.controller.update_crop_params_from_gui, self.form_layout, tick_interval=50, int_values=True) self.add_slider('crop_x', 'Crop x:', 1, 2, 1, self.controller.update_crop_params_from_gui, self.form_layout, tick_interval=50, int_values=True) self.add_slider('offset_y', 'Offset y:', 0, 1, 0, self.controller.update_crop_params_from_gui, self.form_layout, tick_interval=50, int_values=True) self.add_slider('offset_x', 'Offset x:', 0, 1, 0, self.controller.update_crop_params_from_gui, self.form_layout, tick_interval=50, int_values=True) def update_gui_from_params(self, crop_params): if len(crop_params) == len(self.crop_param_controls): # update crop gui for each crop for c in range(len(crop_params)): self.crop_param_controls[c]['crop_y' + '_slider'].setMaximum( self.controller.current_frame.shape[0]) self.crop_param_controls[c]['crop_x' + '_slider'].setMaximum( self.controller.current_frame.shape[1]) self.crop_param_controls[c]['offset_y' + '_slider'].setMaximum( self.controller.current_frame.shape[0] - 1) self.crop_param_controls[c]['offset_x' + '_slider'].setMaximum( self.controller.current_frame.shape[1] - 1) # update param controls with current parameters self.set_slider_value('crop_y', crop_params[c]['crop'][0], c, int_values=True) self.set_slider_value('crop_x', crop_params[c]['crop'][1], c, int_values=True) self.set_slider_value('offset_y', crop_params[c]['offset'][0], c, int_values=True) self.set_slider_value('offset_x', crop_params[c]['offset'][1], c, int_values=True) def closeEvent(self, ce): if not self.controller.closing: ce.ignore() else: ce.accept()
class AccountPanel(Panel): FIELDS = [ ('nameEdit', 'name'), ('accountNumberEdit', 'account_number'), ('notesEdit', 'notes'), ] def __init__(self, mainwindow): Panel.__init__(self, mainwindow) self._setupUi() self.model = mainwindow.model.account_panel self.model.view = self self.typeComboBox = ComboboxModel(model=self.model.type_list, view=self.typeComboBoxView) self.currencyComboBox = ComboboxModel(model=self.model.currency_list, view=self.currencyComboBoxView) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject) def _setupUi(self): self.setWindowTitle(tr("Account Info")) self.resize(274, 121) self.setModal(True) self.verticalLayout = QVBoxLayout(self) self.formLayout = QFormLayout() self.formLayout.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow) self.label = QLabel(tr("Name")) self.formLayout.setWidget(0, QFormLayout.LabelRole, self.label) self.nameEdit = QLineEdit() self.formLayout.setWidget(0, QFormLayout.FieldRole, self.nameEdit) self.label_2 = QLabel(tr("Type")) self.formLayout.setWidget(1, QFormLayout.LabelRole, self.label_2) self.typeComboBoxView = QComboBox() self.formLayout.setWidget(1, QFormLayout.FieldRole, self.typeComboBoxView) self.label_3 = QLabel(tr("Currency")) self.formLayout.setWidget(2, QFormLayout.LabelRole, self.label_3) self.currencyComboBoxView = QComboBox() sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.currencyComboBoxView.sizePolicy().hasHeightForWidth()) self.currencyComboBoxView.setSizePolicy(sizePolicy) self.currencyComboBoxView.setEditable(True) self.currencyComboBoxView.setInsertPolicy(QComboBox.NoInsert) self.formLayout.setWidget(2, QFormLayout.FieldRole, self.currencyComboBoxView) self.accountNumberLabel = QLabel(tr("Account #")) self.formLayout.setWidget(3, QFormLayout.LabelRole, self.accountNumberLabel) self.accountNumberEdit = QLineEdit() self.accountNumberEdit.setMaximumSize(QSize(80, 16777215)) self.formLayout.setWidget(3, QFormLayout.FieldRole, self.accountNumberEdit) self.notesEdit = QPlainTextEdit() self.formLayout.setWidget(4, QFormLayout.FieldRole, self.notesEdit) self.label1 = QLabel(tr("Notes:")) self.formLayout.setWidget(4, QFormLayout.LabelRole, self.label1) self.verticalLayout.addLayout(self.formLayout) self.buttonBox = QDialogButtonBox() self.buttonBox.setOrientation(Qt.Horizontal) self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel|QDialogButtonBox.Save) self.verticalLayout.addWidget(self.buttonBox) self.label.setBuddy(self.nameEdit) self.label_2.setBuddy(self.typeComboBoxView) self.label_3.setBuddy(self.currencyComboBoxView) def _loadFields(self): Panel._loadFields(self) self.currencyComboBoxView.setEnabled(self.model.can_change_currency)
class TransactionPanel(Panel): FIELDS = [ ("dateEdit", "date"), ("descriptionEdit", "description"), ("payeeEdit", "payee"), ("checkNoEdit", "checkno"), ("notesEdit", "notes"), ] def __init__(self, mainwindow): Panel.__init__(self, mainwindow) self.mainwindow = mainwindow self.model = mainwindow.model.transaction_panel self._setupUi() self.model.view = self self.splitTable = SplitTable(model=self.model.split_table, view=self.splitTableView) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject) self.mctButton.clicked.connect(self.model.mct_balance) self.addSplitButton.clicked.connect(self.splitTable.model.add) self.removeSplitButton.clicked.connect(self.splitTable.model.delete) def _setupUi(self): self.setWindowTitle(tr("Transaction Info")) self.resize(462, 329) self.setModal(True) self.mainLayout = QVBoxLayout(self) self.tabWidget = QTabWidget(self) self.infoTab = QWidget() self.infoLayout = QVBoxLayout(self.infoTab) self.formLayout = QFormLayout() self.formLayout.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow) self.dateEdit = DateEdit(self.infoTab) self.dateEdit.setMaximumSize(QSize(120, 16777215)) self.formLayout.addRow(tr("Date:"), self.dateEdit) self.descriptionEdit = DescriptionEdit(self.model.completable_edit, self.infoTab) self.formLayout.addRow(tr("Description:"), self.descriptionEdit) self.payeeEdit = PayeeEdit(self.model.completable_edit, self.infoTab) self.formLayout.addRow(tr("Payee:"), self.payeeEdit) self.checkNoEdit = QLineEdit(self.infoTab) self.checkNoEdit.setMaximumSize(QSize(120, 16777215)) self.formLayout.addRow(tr("Check #:"), self.checkNoEdit) self.infoLayout.addLayout(self.formLayout) self.amountLabel = QLabel(tr("Transfers:"), self.infoTab) self.infoLayout.addWidget(self.amountLabel) self.splitTableView = TableView(self.infoTab) self.splitTableView.setAcceptDrops(True) self.splitTableView.setEditTriggers(QAbstractItemView.DoubleClicked | QAbstractItemView.EditKeyPressed) self.splitTableView.setDragEnabled(True) self.splitTableView.setDragDropMode(QAbstractItemView.InternalMove) self.splitTableView.setSelectionMode(QAbstractItemView.SingleSelection) self.splitTableView.setSelectionBehavior(QAbstractItemView.SelectRows) self.splitTableView.horizontalHeader().setDefaultSectionSize(40) self.splitTableView.verticalHeader().setVisible(False) self.splitTableView.verticalHeader().setDefaultSectionSize(18) self.infoLayout.addWidget(self.splitTableView) self.mctButtonsLayout = QHBoxLayout() self.mctButtonsLayout.setMargin(0) spacerItem = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.mctButtonsLayout.addItem(spacerItem) self.mctButton = QPushButton(tr("Multi-currency balance"), self.infoTab) self.mctButtonsLayout.addWidget(self.mctButton) self.addSplitButton = QPushButton(self.infoTab) icon = QIcon() icon.addPixmap(QPixmap(":/plus_8"), QIcon.Normal, QIcon.Off) self.addSplitButton.setIcon(icon) self.mctButtonsLayout.addWidget(self.addSplitButton) self.removeSplitButton = QPushButton(self.infoTab) icon1 = QIcon() icon1.addPixmap(QPixmap(":/minus_8"), QIcon.Normal, QIcon.Off) self.removeSplitButton.setIcon(icon1) self.mctButtonsLayout.addWidget(self.removeSplitButton) self.infoLayout.addLayout(self.mctButtonsLayout) self.tabWidget.addTab(self.infoTab, tr("Info")) self.notesTab = QWidget() self.notesLayout = QVBoxLayout(self.notesTab) self.notesEdit = QPlainTextEdit(self.notesTab) self.notesLayout.addWidget(self.notesEdit) self.tabWidget.addTab(self.notesTab, tr("Notes")) self.tabWidget.setCurrentIndex(0) self.mainLayout.addWidget(self.tabWidget) self.buttonBox = QDialogButtonBox(self) self.buttonBox.setOrientation(Qt.Horizontal) self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel | QDialogButtonBox.Save) self.mainLayout.addWidget(self.buttonBox) def _loadFields(self): Panel._loadFields(self) self.tabWidget.setCurrentIndex(0) # --- model --> view def refresh_for_multi_currency(self): self.mctButton.setEnabled(self.model.is_multi_currency)
class RegSubmitDialog(QDialog): def __init__(self, parent, reg): flags = Qt.CustomizeWindowHint | Qt.WindowTitleHint | Qt.WindowSystemMenuHint QDialog.__init__(self, parent, flags) self._setupUi() self.reg = reg self.submitButton.clicked.connect(self.submitClicked) self.contributeButton.clicked.connect(self.contributeClicked) self.cancelButton.clicked.connect(self.reject) def _setupUi(self): self.setWindowTitle(tr("Enter your registration key")) self.resize(365, 126) self.verticalLayout = QVBoxLayout(self) self.promptLabel = QLabel(self) appname = str(QCoreApplication.instance().applicationName()) prompt = tr("Type the key you received when you contributed to $appname, as well as the " "e-mail used as a reference for the purchase.").replace('$appname', appname) self.promptLabel.setText(prompt) self.promptLabel.setAlignment(Qt.AlignLeading|Qt.AlignLeft|Qt.AlignTop) self.promptLabel.setWordWrap(True) self.verticalLayout.addWidget(self.promptLabel) self.formLayout = QFormLayout() self.formLayout.setSizeConstraint(QLayout.SetNoConstraint) self.formLayout.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow) self.formLayout.setLabelAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter) self.formLayout.setFormAlignment(Qt.AlignLeading|Qt.AlignLeft|Qt.AlignTop) self.label2 = QLabel(self) self.label2.setText(tr("Registration key:")) self.formLayout.setWidget(0, QFormLayout.LabelRole, self.label2) self.label3 = QLabel(self) self.label3.setText(tr("Registered e-mail:")) self.formLayout.setWidget(1, QFormLayout.LabelRole, self.label3) self.codeEdit = QLineEdit(self) self.formLayout.setWidget(0, QFormLayout.FieldRole, self.codeEdit) self.emailEdit = QLineEdit(self) self.formLayout.setWidget(1, QFormLayout.FieldRole, self.emailEdit) self.verticalLayout.addLayout(self.formLayout) self.horizontalLayout = QHBoxLayout() self.contributeButton = QPushButton(self) self.contributeButton.setText(tr("Contribute")) self.contributeButton.setAutoDefault(False) self.horizontalLayout.addWidget(self.contributeButton) spacerItem = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout.addItem(spacerItem) self.cancelButton = QPushButton(self) sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.cancelButton.sizePolicy().hasHeightForWidth()) self.cancelButton.setSizePolicy(sizePolicy) self.cancelButton.setText(tr("Cancel")) self.cancelButton.setAutoDefault(False) self.horizontalLayout.addWidget(self.cancelButton) self.submitButton = QPushButton(self) sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.submitButton.sizePolicy().hasHeightForWidth()) self.submitButton.setSizePolicy(sizePolicy) self.submitButton.setText(tr("Submit")) self.submitButton.setAutoDefault(False) self.submitButton.setDefault(True) self.horizontalLayout.addWidget(self.submitButton) self.verticalLayout.addLayout(self.horizontalLayout) #--- Events def contributeClicked(self): self.reg.app.contribute() def submitClicked(self): code = self.codeEdit.text() email = self.emailEdit.text() if self.reg.app.set_registration(code, email, False): self.accept()
def __init__(self, lat, parent = None): super(ElementEditor, self).__init__(parent) #self.cadata = cadata #self.model = None self._lat = lat fmbox = QFormLayout() self.elemName = QLineEdit() self.elemName.setToolTip( "list elements within the range of the active plot.<br>" "Examples are '*', 'HCOR', 'BPM', 'QUAD', 'c*c20a', 'q*g2*'" ) self.elemName.setCompleter(QCompleter([ "*", "BPM", "COR", "HCOR", "VCOR", "QUAD"])) self.elemField = QLineEdit() self.elemField.setToolTip( "Element fields separated by comma, space or both." "e.g. 'x, y'" ) #self.rangeSlider = qrangeslider.QRangeSlider() #self.rangeSlider.setMin(0) #self.rangeSlider.setMax(100) #self.rangeSlider.setRange(10, 70) #self.elemName.insertSeparator(len(self.elems)) #fmbox.addRow("Range", self.rangeSlider) fmbox.addRow("Elements:", self.elemName) fmbox.addRow("Fields:", self.elemField) fmbox.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow) fmbox.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow) #self.refreshBtn = QPushButton("refresh") #fmbox.addRow(self.elemName) self._active_elem = None self._active_idx = None self._active_sp = None self.lblInfo = QLabel() self.gpCellEditor = QtGui.QGroupBox() fmbox2 = QFormLayout() self.lblNameField = QLabel() self.ledStep = QLineEdit(".1") self.ledStep.setValidator(QtGui.QDoubleValidator()) self.spb1 = QtGui.QDoubleSpinBox() self.spb2 = QtGui.QDoubleSpinBox() self.spb5 = QtGui.QDoubleSpinBox() self.connect(self.spb5, SIGNAL("valueChanged(double)"), self.spb2.setValue) self.connect(self.spb2, SIGNAL("valueChanged(double)"), self.spb1.setValue) self.connect(self.spb1, SIGNAL("valueChanged(double)"), self.spb5.setValue) self.connect(self.spb1, SIGNAL("valueChanged(double)"), self.setActiveCell) self.lblPv = QLabel("") self.lblRange = QLabel("") self.valMeter = Qwt.QwtThermo() self.valMeter.setOrientation(Qt.Horizontal, Qwt.QwtThermo.BottomScale) self.valMeter.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed) self.valMeter.setEnabled(False) self.ledSet = QLineEdit("") self.ledSet.setValidator(QtGui.QDoubleValidator()) self.connect(self.ledSet, SIGNAL("returnPressed()"), self.setDirectValue) fmbox2.addRow("Name:", self.lblNameField) #fmbox2.addRow("Range", self.valMeter) fmbox2.addRow("Range:", self.lblRange) fmbox2.addRow("PV Name:", self.lblPv) hbox = QtGui.QHBoxLayout() hbox.addWidget(self.ledSet) btnSet = QtGui.QPushButton("Set") self.connect(btnSet, SIGNAL("clicked()"), self.setDirectValue) hbox.addWidget(btnSet) fmbox2.addRow("Set New Value:", hbox) hbox = QtGui.QHBoxLayout() hbox.addWidget(self.ledStep) # btnu1 = QtGui.QPushButton() btnu1.setIcon(QtGui.QIcon(":/control_up1.png")) btnu1.setIconSize(QtCore.QSize(24, 24)) self.connect(btnu1, SIGNAL("clicked()"), partial(self.stepActiveCell, 1.0)) hbox.addWidget(btnu1) btnd1 = QtGui.QPushButton() btnd1.setIcon(QtGui.QIcon(":/control_dn1.png")) btnd1.setIconSize(QtCore.QSize(24, 24)) self.connect(btnd1, SIGNAL("clicked()"), partial(self.stepActiveCell, -1.0)) hbox.addWidget(btnd1) btnu5 = QtGui.QPushButton() btnu5.setIcon(QtGui.QIcon(":/control_up5.png")) btnu5.setIconSize(QtCore.QSize(24, 24)) self.connect(btnu5, SIGNAL("clicked()"), partial(self.stepActiveCell, 5.0)) hbox.addWidget(btnu5) btnd5 = QtGui.QPushButton() btnd5.setIcon(QtGui.QIcon(":/control_dn5.png")) btnd5.setIconSize(QtCore.QSize(24, 24)) self.connect(btnd5, SIGNAL("clicked()"), partial(self.stepActiveCell, -5.0)) hbox.addWidget(btnd5) fmbox2.addRow("Step Up/Down:", hbox) hbox = QtGui.QHBoxLayout() self.ledMult = QtGui.QLineEdit("1.0") hbox.addWidget(self.ledMult) btnx1 = QtGui.QPushButton() btnx1.setIcon(QtGui.QIcon(":/control_x1.png")) btnx1.setIconSize(QtCore.QSize(24, 24)) self.connect(btnx1, SIGNAL("clicked()"), self.scaleActiveCell) hbox.addWidget(btnx1) btnx1 = QtGui.QPushButton() btnx1.setIcon(QtGui.QIcon(":/control_x1r.png")) btnx1.setIconSize(QtCore.QSize(24, 24)) self.connect(btnx1, SIGNAL("clicked()"), partial(self.scaleActiveCell, True)) hbox.addWidget(btnx1) fmbox2.addRow("Multiply/Divide:", hbox) fmbox2.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow) fmbox2.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow) self.gpCellEditor.setLayout(fmbox2) self.gpCellEditor.setVisible(False) self.model = ElementPropertyTableModel() self.connect(self.model, SIGNAL("toggleElementState(PyQt_PyObject, bool)"), self.elementStateChanged) self.tableview = ElementPropertyView() self.connect(self.tableview, SIGNAL("clicked(QModelIndex)"), self.editingCell) #self.delegate = ElementPropertyDelegate() #self.connect(self.delegate, SIGNAL("editingElement(PyQt_PyObject)"), # self.updateCellInfo) #t2 = time.time() self.tableview.setModel(self.model) #self.tableview.setItemDelegate(self.delegate) #self.tableview.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) #self.tableview.setWhatsThis("double click cell to enter editing mode") #fmbox.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow) #self.model.loadElements(aphla.getElements("*")[:10]) vbox = QVBoxLayout() vbox.addLayout(fmbox) vbox.addWidget(self.tableview) #vbox.addWidget(self.lblInfo) #vbox.addLayout(fmbox2) vbox.addWidget(self.gpCellEditor) self.setLayout(vbox) #self.connect(self.elemName, SIGNAL("editingFinished()"), # self.refreshTable) self.connect(self.elemName, SIGNAL("returnPressed()"), self._reload_elements) self.connect(self.elemField, SIGNAL("returnPressed()"), self._reload_elements) #self.connect(self.elemName, SIGNAL("currentIndexChanged(QString)"), # self.refreshTable) self.setWindowTitle("Element Editor") self.noTableUpdate = True self.resize(800, 600) self.setWindowFlags(Qt.Window)
class SchedulePanel(Panel): FIELDS = [ ('startDateEdit', 'start_date'), ('repeatEverySpinBox', 'repeat_every'), ('stopDateEdit', 'stop_date'), ('descriptionEdit', 'description'), ('payeeEdit', 'payee'), ('checkNoEdit', 'checkno'), ('notesEdit', 'notes'), ] def __init__(self, mainwindow): Panel.__init__(self, mainwindow) self.mainwindow = mainwindow self.model = mainwindow.model.schedule_panel self._setupUi() self.model.view = self self.splitTable = SplitTable(model=self.model.split_table, view=self.splitTableView) self.repeatTypeComboBox = ComboboxModel(model=self.model.repeat_type_list, view=self.repeatTypeComboBoxView) self.addSplitButton.clicked.connect(self.splitTable.model.add) self.removeSplitButton.clicked.connect(self.splitTable.model.delete) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject) def _setupUi(self): self.setWindowTitle(tr("Schedule Info")) self.resize(469, 416) self.setModal(True) self.verticalLayout_2 = QVBoxLayout(self) self.tabWidget = QTabWidget(self) self.tab = QWidget() self.formLayout = QFormLayout(self.tab) self.formLayout.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow) self.label_2 = QLabel(tr("Start Date:")) self.formLayout.setWidget(0, QFormLayout.LabelRole, self.label_2) self.startDateEdit = DateEdit(self.tab) self.startDateEdit.setMaximumSize(QSize(120, 16777215)) self.formLayout.setWidget(0, QFormLayout.FieldRole, self.startDateEdit) self.label_7 = QLabel(tr("Repeat Type:")) self.formLayout.setWidget(1, QFormLayout.LabelRole, self.label_7) self.repeatTypeComboBoxView = QComboBox(self.tab) self.formLayout.setWidget(1, QFormLayout.FieldRole, self.repeatTypeComboBoxView) self.label_8 = QLabel(tr("Every:")) self.formLayout.setWidget(2, QFormLayout.LabelRole, self.label_8) self.horizontalLayout_2 = QHBoxLayout() self.repeatEverySpinBox = QSpinBox(self.tab) self.repeatEverySpinBox.setMinimum(1) self.horizontalLayout_2.addWidget(self.repeatEverySpinBox) self.repeatEveryDescLabel = QLabel(self.tab) self.horizontalLayout_2.addWidget(self.repeatEveryDescLabel) self.formLayout.setLayout(2, QFormLayout.FieldRole, self.horizontalLayout_2) self.label_9 = QLabel(tr("Stop Date:")) self.formLayout.setWidget(3, QFormLayout.LabelRole, self.label_9) self.stopDateEdit = DateEdit(self.tab) self.stopDateEdit.setMaximumSize(QSize(120, 16777215)) self.formLayout.setWidget(3, QFormLayout.FieldRole, self.stopDateEdit) self.label_3 = QLabel(tr("Description:")) self.formLayout.setWidget(4, QFormLayout.LabelRole, self.label_3) self.descriptionEdit = DescriptionEdit(self.model.completable_edit, self.tab) self.formLayout.setWidget(4, QFormLayout.FieldRole, self.descriptionEdit) self.label_4 = QLabel(tr("Payee:")) self.formLayout.setWidget(5, QFormLayout.LabelRole, self.label_4) self.payeeEdit = PayeeEdit(self.model.completable_edit, self.tab) self.formLayout.setWidget(5, QFormLayout.FieldRole, self.payeeEdit) self.label_5 = QLabel(tr("Check #:")) self.formLayout.setWidget(6, QFormLayout.LabelRole, self.label_5) self.checkNoEdit = QLineEdit(self.tab) self.checkNoEdit.setMaximumSize(QSize(120, 16777215)) self.formLayout.setWidget(6, QFormLayout.FieldRole, self.checkNoEdit) self.amountLabel = QLabel(tr("Transfers:")) self.formLayout.setWidget(7, QFormLayout.LabelRole, self.amountLabel) self.splitTableView = TableView(self.tab) self.splitTableView.setMinimumSize(QSize(355, 0)) self.splitTableView.setAcceptDrops(True) self.splitTableView.setDragEnabled(True) self.splitTableView.setDragDropOverwriteMode(False) self.splitTableView.setDragDropMode(QAbstractItemView.InternalMove) self.splitTableView.setSelectionBehavior(QAbstractItemView.SelectRows) self.splitTableView.horizontalHeader().setDefaultSectionSize(40) self.splitTableView.verticalHeader().setVisible(False) self.splitTableView.verticalHeader().setDefaultSectionSize(18) self.formLayout.setWidget(7, QFormLayout.FieldRole, self.splitTableView) self.widget = QWidget(self.tab) sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.widget.sizePolicy().hasHeightForWidth()) self.widget.setSizePolicy(sizePolicy) self.horizontalLayout_6 = QHBoxLayout(self.widget) self.horizontalLayout_6.setMargin(0) spacerItem = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout_6.addItem(spacerItem) self.addSplitButton = QPushButton(self.widget) icon = QIcon() icon.addPixmap(QPixmap(':/plus_8'), QIcon.Normal, QIcon.Off) self.addSplitButton.setIcon(icon) self.horizontalLayout_6.addWidget(self.addSplitButton) self.removeSplitButton = QPushButton(self.widget) icon1 = QIcon() icon1.addPixmap(QPixmap(':/minus_8'), QIcon.Normal, QIcon.Off) self.removeSplitButton.setIcon(icon1) self.horizontalLayout_6.addWidget(self.removeSplitButton) self.formLayout.setWidget(8, QFormLayout.FieldRole, self.widget) self.tabWidget.addTab(self.tab, tr("Info")) self.tab_3 = QWidget() self.horizontalLayout_5 = QHBoxLayout(self.tab_3) self.notesEdit = QPlainTextEdit(self.tab_3) self.horizontalLayout_5.addWidget(self.notesEdit) self.tabWidget.addTab(self.tab_3, tr("Notes")) self.verticalLayout_2.addWidget(self.tabWidget) self.buttonBox = QDialogButtonBox(self) self.buttonBox.setOrientation(Qt.Horizontal) self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel|QDialogButtonBox.Save) self.verticalLayout_2.addWidget(self.buttonBox) self.label_2.setBuddy(self.startDateEdit) self.label_7.setBuddy(self.repeatTypeComboBoxView) self.label_3.setBuddy(self.descriptionEdit) self.label_4.setBuddy(self.payeeEdit) self.label_5.setBuddy(self.checkNoEdit) self.tabWidget.setCurrentIndex(0) def _loadFields(self): Panel._loadFields(self) self.tabWidget.setCurrentIndex(0) #--- model --> view def refresh_for_multi_currency(self): pass def refresh_repeat_every(self): self.repeatEveryDescLabel.setText(self.model.repeat_every_desc)
class BudgetPanel(Panel): FIELDS = [ ('startDateEdit', 'start_date'), ('repeatEverySpinBox', 'repeat_every'), ('stopDateEdit', 'stop_date'), ('amountEdit', 'amount'), ('notesEdit', 'notes'), ] def __init__(self, mainwindow): Panel.__init__(self, mainwindow) self._setupUi() self.model = mainwindow.model.budget_panel self.model.view = self self.repeatTypeComboBox = ComboboxModel(model=self.model.repeat_type_list, view=self.repeatTypeComboBoxView) self.accountComboBox = ComboboxModel(model=self.model.account_list, view=self.accountComboBoxView) self.targetComboBox = ComboboxModel(model=self.model.target_list, view=self.targetComboBoxView) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject) def _setupUi(self): self.setWindowTitle(tr("Budget Info")) self.resize(230, 369) self.setModal(True) self.verticalLayout = QVBoxLayout(self) self.formLayout = QFormLayout() self.formLayout.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow) self.label_2 = QLabel(tr("Start Date:")) self.formLayout.setWidget(0, QFormLayout.LabelRole, self.label_2) self.startDateEdit = DateEdit(self) self.startDateEdit.setMaximumSize(QSize(120, 16777215)) self.formLayout.setWidget(0, QFormLayout.FieldRole, self.startDateEdit) self.label_7 = QLabel(tr("Repeat Type:")) self.formLayout.setWidget(1, QFormLayout.LabelRole, self.label_7) self.repeatTypeComboBoxView = QComboBox(self) self.formLayout.setWidget(1, QFormLayout.FieldRole, self.repeatTypeComboBoxView) self.label_8 = QLabel(tr("Every:")) self.formLayout.setWidget(2, QFormLayout.LabelRole, self.label_8) self.horizontalLayout_2 = QHBoxLayout() self.repeatEverySpinBox = QSpinBox(self) self.repeatEverySpinBox.setMinimum(1) self.horizontalLayout_2.addWidget(self.repeatEverySpinBox) self.repeatEveryDescLabel = QLabel(self) self.horizontalLayout_2.addWidget(self.repeatEveryDescLabel) self.formLayout.setLayout(2, QFormLayout.FieldRole, self.horizontalLayout_2) self.label_9 = QLabel(tr("Stop Date:")) self.formLayout.setWidget(3, QFormLayout.LabelRole, self.label_9) self.stopDateEdit = DateEdit(self) self.stopDateEdit.setMaximumSize(QSize(120, 16777215)) self.formLayout.setWidget(3, QFormLayout.FieldRole, self.stopDateEdit) self.accountComboBoxView = QComboBox(self) self.formLayout.setWidget(4, QFormLayout.FieldRole, self.accountComboBoxView) self.label_3 = QLabel(tr("Account:")) self.formLayout.setWidget(4, QFormLayout.LabelRole, self.label_3) self.targetComboBoxView = QComboBox(self) self.formLayout.setWidget(5, QFormLayout.FieldRole, self.targetComboBoxView) self.label_4 = QLabel(tr("Target:")) self.formLayout.setWidget(5, QFormLayout.LabelRole, self.label_4) self.amountEdit = QLineEdit(self) self.amountEdit.setMaximumSize(QSize(120, 16777215)) self.formLayout.setWidget(6, QFormLayout.FieldRole, self.amountEdit) self.label_5 = QLabel(tr("Amount:")) self.formLayout.setWidget(6, QFormLayout.LabelRole, self.label_5) self.notesEdit = QPlainTextEdit(tr("Notes:")) self.formLayout.setWidget(7, QFormLayout.FieldRole, self.notesEdit) self.label = QLabel(self) self.formLayout.setWidget(7, QFormLayout.LabelRole, self.label) self.verticalLayout.addLayout(self.formLayout) self.buttonBox = QDialogButtonBox(self) self.buttonBox.setOrientation(Qt.Horizontal) self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel|QDialogButtonBox.Save) self.verticalLayout.addWidget(self.buttonBox) self.label_2.setBuddy(self.startDateEdit) self.label_7.setBuddy(self.repeatTypeComboBoxView) self.label_8.setBuddy(self.repeatEverySpinBox) self.label_9.setBuddy(self.stopDateEdit) self.label_3.setBuddy(self.accountComboBoxView) self.label_4.setBuddy(self.targetComboBoxView) self.label_5.setBuddy(self.amountEdit) #--- model --> view def refresh_repeat_every(self): self.repeatEveryDescLabel.setText(self.model.repeat_every_desc)
def __init__(self, parent, elems=[]): QDockWidget.__init__(self, parent) self.model = None #self.connect(self, SIGNAL('tabCloseRequested(int)'), self.closeTab) #gb = QGroupBox("select") fmbox = QFormLayout() #fmbox.addRow("S-Range", self.lblRange) self.elemBox = QLineEdit() self.elemBox.setToolTip( "list elements within the range of the active plot.<br>" "Examples are '*', 'HCOR', 'BPM', 'QUAD', 'c*c20a', 'q*g2*'" ) self.elems = elems self.elemCompleter = QCompleter(elems) self.elemBox.setCompleter(self.elemCompleter) #self.elemBox.insertSeparator(len(self.elems)) fmbox.addRow("Filter", self.elemBox) #self.refreshBtn = QPushButton("refresh") #fmbox.addRow(self.elemBox) self.fldGroup = QGroupBox() fmbox2 = QFormLayout() self.lblName = QLabel() self.lblField = QLabel() self.lblStep = QLabel() self.lblRange = QLabel() self.valMeter = Qwt.QwtThermo() self.valMeter.setOrientation(Qt.Horizontal, Qwt.QwtThermo.BottomScale) self.valMeter.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed) self.valMeter.setEnabled(False) #fmbox2.addRow("Name", self.lblName) #fmbox2.addRow("Field", self.lblField) fmbox2.addRow("Step", self.lblStep) #fmbox2.addRow("Range", self.valMeter) fmbox2.addRow("Range", self.lblRange) #fmbox2.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow) fmbox2.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow) self.fldGroup.setLayout(fmbox2) self.model = None self.delegate = None self.tableview = ElementPropertyView() #self.tableview.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.tableview.setWhatsThis("double click cell to enter editing mode") fmbox.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow) vbox = QVBoxLayout() vbox.addLayout(fmbox) vbox.addWidget(self.tableview) vbox.addWidget(self.fldGroup) cw = QWidget(self) cw.setLayout(vbox) self.setWidget(cw) #self.connect(self.elemBox, SIGNAL("editingFinished()"), # self.refreshTable) self.connect(self.elemBox, SIGNAL("returnPressed()"), self.refreshTable) #self.connect(self.elemBox, SIGNAL("currentIndexChanged(QString)"), # self.refreshTable) self.setWindowTitle("Element Editor") self.noTableUpdate = True
class CustomDialog(QDialog): INVALID_COLOR = QColor(255, 235, 235) def __init__(self, title="Title", description="Description", parent=None): QDialog.__init__(self, parent) self._option_list = [] """ :type: list of QWidget """ self.setModal(True) self.setWindowTitle(title) self.layout = QFormLayout() self.layout.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow) self.layout.setSizeConstraint(QLayout.SetFixedSize) label = QLabel(description) label.setAlignment(Qt.AlignHCenter) self.layout.addRow(self.createSpace(5)) self.layout.addRow(label) self.layout.addRow(self.createSpace(10)) self.ok_button = None self.setLayout(self.layout) def notValid(self, msg): """Called when the name is not valid.""" self.ok_button.setEnabled(False) def valid(self): """Called when the name is valid.""" self.ok_button.setEnabled(True) def optionValidationChanged(self): valid = True for option in self._option_list: if hasattr(option, "isValid"): if not option.isValid(): valid = False self.notValid("One or more options are incorrectly set!") if valid: self.valid() def showAndTell(self): """ Shows the dialog modally and returns the true or false (accept/reject) @rtype: bool """ self.optionValidationChanged() return self.exec_() def createSpace(self, size=5): """Creates a widget that can be used as spacing on a panel.""" qw = QWidget() qw.setMinimumSize(QSize(size, size)) return qw def addSpace(self, size=10): """ Add some vertical spacing """ space_widget = self.createSpace(size) self.layout.addRow("", space_widget) def addLabeledOption(self, label, option_widget): """ @type option_widget: QWidget """ self._option_list.append(option_widget) if hasattr(option_widget, "validationChanged"): option_widget.validationChanged.connect( self.optionValidationChanged) if hasattr(option_widget, "getValidationSupport"): validation_support = option_widget.getValidationSupport() validation_support.validationChanged.connect( self.optionValidationChanged) self.layout.addRow("%s:" % label, option_widget) def addWidget(self, widget, label=""): if not label.endswith(":"): label = "%s:" % label self.layout.addRow(label, widget) def addButtons(self): buttons = QDialogButtonBox( QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal, self) self.ok_button = buttons.button(QDialogButtonBox.Ok) self.ok_button.setEnabled(False) self.layout.addRow(self.createSpace(10)) self.layout.addRow(buttons) self.connect(buttons, SIGNAL('accepted()'), self.accept) self.connect(buttons, SIGNAL('rejected()'), self.reject)
class DiscreteVariableEditor(VariableEditor): """An editor widget for editing a discrete variable. Extends the :class:`VariableEditor` to enable editing of variables values. """ def setup_gui(self): layout = QVBoxLayout() self.setLayout(layout) self.main_form = QFormLayout() self.main_form.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow) layout.addLayout(self.main_form) self._setup_gui_name() self._setup_gui_values() self._setup_gui_labels() def _setup_gui_values(self): self.values_edit = QListView() self.values_edit.setEditTriggers(QTreeView.CurrentChanged) self.values_model = itemmodels.PyListModel(flags=Qt.ItemIsSelectable | \ Qt.ItemIsEnabled | Qt.ItemIsEditable) self.values_edit.setModel(self.values_model) self.values_model.dataChanged.connect(self.on_values_changed) self.main_form.addRow("Values", self.values_edit) def set_data(self, var): """Set the variable to edit """ VariableEditor.set_data(self, var) self.values_model[:] = list(var.values) if var is not None else [] def get_data(self): """Retrieve the modified variable """ name = str(self.name_edit.text()) labels = self.labels_model.get_dict() values = map(str, self.values_model) if not self.is_same(): var = type(self.var)(name, values=values) var.attributes.update(labels) self.var = var else: var = self.var return var def is_same(self): """Is the current model state the same as the input. """ values = map(str, self.values_model) return VariableEditor.is_same(self) and self.var.values == values def clear(self): """Clear the model state. """ VariableEditor.clear(self) self.values_model.wrap([]) @Slot() def on_values_changed(self): self.maybe_commit()
def __init__(self, lat, parent=None): super(ElementEditor, self).__init__(parent) #self.cadata = cadata #self.model = None self._lat = lat fmbox = QFormLayout() self.elemName = QLineEdit() self.elemName.setToolTip( "list elements within the range of the active plot.<br>" "Examples are '*', 'HCOR', 'BPM', 'QUAD', 'c*c20a', 'q*g2*'") self.elemName.setCompleter( QCompleter(["*", "BPM", "COR", "HCOR", "VCOR", "QUAD"])) self.elemField = QLineEdit() self.elemField.setToolTip( "Element fields separated by comma, space or both." "e.g. 'x, y'") #self.rangeSlider = qrangeslider.QRangeSlider() #self.rangeSlider.setMin(0) #self.rangeSlider.setMax(100) #self.rangeSlider.setRange(10, 70) #self.elemName.insertSeparator(len(self.elems)) #fmbox.addRow("Range", self.rangeSlider) fmbox.addRow("Elements:", self.elemName) fmbox.addRow("Fields:", self.elemField) fmbox.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow) fmbox.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow) #self.refreshBtn = QPushButton("refresh") #fmbox.addRow(self.elemName) self._active_elem = None self._active_idx = None self._active_sp = None self.lblInfo = QLabel() self.gpCellEditor = QtGui.QGroupBox() fmbox2 = QFormLayout() self.lblNameField = QLabel() self.ledStep = QLineEdit(".1") self.ledStep.setValidator(QtGui.QDoubleValidator()) self.spb1 = QtGui.QDoubleSpinBox() self.spb2 = QtGui.QDoubleSpinBox() self.spb5 = QtGui.QDoubleSpinBox() self.connect(self.spb5, SIGNAL("valueChanged(double)"), self.spb2.setValue) self.connect(self.spb2, SIGNAL("valueChanged(double)"), self.spb1.setValue) self.connect(self.spb1, SIGNAL("valueChanged(double)"), self.spb5.setValue) self.connect(self.spb1, SIGNAL("valueChanged(double)"), self.setActiveCell) self.lblPv = QLabel("") self.lblRange = QLabel("") self.valMeter = Qwt.QwtThermo() self.valMeter.setOrientation(Qt.Horizontal, Qwt.QwtThermo.BottomScale) self.valMeter.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed) self.valMeter.setEnabled(False) self.ledSet = QLineEdit("") self.ledSet.setValidator(QtGui.QDoubleValidator()) self.connect(self.ledSet, SIGNAL("returnPressed()"), self.setDirectValue) fmbox2.addRow("Name:", self.lblNameField) #fmbox2.addRow("Range", self.valMeter) fmbox2.addRow("Range:", self.lblRange) fmbox2.addRow("PV Name:", self.lblPv) hbox = QtGui.QHBoxLayout() hbox.addWidget(self.ledSet) btnSet = QtGui.QPushButton("Set") self.connect(btnSet, SIGNAL("clicked()"), self.setDirectValue) hbox.addWidget(btnSet) fmbox2.addRow("Set New Value:", hbox) hbox = QtGui.QHBoxLayout() hbox.addWidget(self.ledStep) # btnu1 = QtGui.QPushButton() btnu1.setIcon(QtGui.QIcon(":/control_up1.png")) btnu1.setIconSize(QtCore.QSize(24, 24)) self.connect(btnu1, SIGNAL("clicked()"), partial(self.stepActiveCell, 1.0)) hbox.addWidget(btnu1) btnd1 = QtGui.QPushButton() btnd1.setIcon(QtGui.QIcon(":/control_dn1.png")) btnd1.setIconSize(QtCore.QSize(24, 24)) self.connect(btnd1, SIGNAL("clicked()"), partial(self.stepActiveCell, -1.0)) hbox.addWidget(btnd1) btnu5 = QtGui.QPushButton() btnu5.setIcon(QtGui.QIcon(":/control_up5.png")) btnu5.setIconSize(QtCore.QSize(24, 24)) self.connect(btnu5, SIGNAL("clicked()"), partial(self.stepActiveCell, 5.0)) hbox.addWidget(btnu5) btnd5 = QtGui.QPushButton() btnd5.setIcon(QtGui.QIcon(":/control_dn5.png")) btnd5.setIconSize(QtCore.QSize(24, 24)) self.connect(btnd5, SIGNAL("clicked()"), partial(self.stepActiveCell, -5.0)) hbox.addWidget(btnd5) fmbox2.addRow("Step Up/Down:", hbox) hbox = QtGui.QHBoxLayout() self.ledMult = QtGui.QLineEdit("1.0") hbox.addWidget(self.ledMult) btnx1 = QtGui.QPushButton() btnx1.setIcon(QtGui.QIcon(":/control_x1.png")) btnx1.setIconSize(QtCore.QSize(24, 24)) self.connect(btnx1, SIGNAL("clicked()"), self.scaleActiveCell) hbox.addWidget(btnx1) btnx1 = QtGui.QPushButton() btnx1.setIcon(QtGui.QIcon(":/control_x1r.png")) btnx1.setIconSize(QtCore.QSize(24, 24)) self.connect(btnx1, SIGNAL("clicked()"), partial(self.scaleActiveCell, True)) hbox.addWidget(btnx1) fmbox2.addRow("Multiply/Divide:", hbox) fmbox2.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow) fmbox2.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow) self.gpCellEditor.setLayout(fmbox2) self.gpCellEditor.setVisible(False) self.model = ElementPropertyTableModel() self.connect(self.model, SIGNAL("toggleElementState(PyQt_PyObject, bool)"), self.elementStateChanged) self.tableview = ElementPropertyView() self.connect(self.tableview, SIGNAL("clicked(QModelIndex)"), self.editingCell) #self.delegate = ElementPropertyDelegate() #self.connect(self.delegate, SIGNAL("editingElement(PyQt_PyObject)"), # self.updateCellInfo) #t2 = time.time() self.tableview.setModel(self.model) #self.tableview.setItemDelegate(self.delegate) #self.tableview.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) #self.tableview.setWhatsThis("double click cell to enter editing mode") #fmbox.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow) #self.model.loadElements(aphla.getElements("*")[:10]) vbox = QVBoxLayout() vbox.addLayout(fmbox) vbox.addWidget(self.tableview) #vbox.addWidget(self.lblInfo) #vbox.addLayout(fmbox2) vbox.addWidget(self.gpCellEditor) self.setLayout(vbox) #self.connect(self.elemName, SIGNAL("editingFinished()"), # self.refreshTable) self.connect(self.elemName, SIGNAL("returnPressed()"), self._reload_elements) self.connect(self.elemField, SIGNAL("returnPressed()"), self._reload_elements) #self.connect(self.elemName, SIGNAL("currentIndexChanged(QString)"), # self.refreshTable) self.setWindowTitle("Element Editor") self.noTableUpdate = True self.resize(800, 600) self.setWindowFlags(Qt.Window)
class DiscreteVariableEditor(VariableEditor): """An editor widget for editing a discrete variable. Extends the :class:`VariableEditor` to enable editing of variables values. """ def setup_gui(self): layout = QVBoxLayout() self.setLayout(layout) self.main_form = QFormLayout() self.main_form.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow) layout.addLayout(self.main_form) self._setup_gui_name() self._setup_gui_values() self._setup_gui_labels() def _setup_gui_values(self): self.values_edit = QListView() self.values_edit.setEditTriggers(QTreeView.CurrentChanged) self.values_model = itemmodels.PyListModel(flags=Qt.ItemIsSelectable | \ Qt.ItemIsEnabled | Qt.ItemIsEditable) self.values_edit.setModel(self.values_model) self.values_model.dataChanged.connect(self.on_values_changed) self.main_form.addRow("Values", self.values_edit) def set_data(self, var): """Set the variable to edit """ VariableEditor.set_data(self, var) self.values_model[:] = list(var.values) if var is not None else [] def get_data(self): """Retrieve the modified variable """ name = str(self.name_edit.text()) labels = self.labels_model.get_dict() values = map(str, self.values_model) if not self.is_same(): var = type(self.var)(name, values=values) var.attributes.update(labels) self.var = var else: var = self.var return var def is_same(self): """Is the current model state the same as the input. """ values = map(str, self.values_model) return VariableEditor.is_same(self) and self.var.values == values def clear(self): """Clear the model state. """ VariableEditor.clear(self) self.values_model.wrap([]) @Slot() def on_values_changed(self): self.maybe_commit()
class RegSubmitDialog(QDialog): def __init__(self, parent, reg): flags = Qt.CustomizeWindowHint | Qt.WindowTitleHint | Qt.WindowSystemMenuHint QDialog.__init__(self, parent, flags) self._setupUi() self.reg = reg self.submitButton.clicked.connect(self.submitClicked) self.contributeButton.clicked.connect(self.contributeClicked) self.cancelButton.clicked.connect(self.reject) def _setupUi(self): self.setWindowTitle(tr("Enter your registration key")) self.resize(365, 126) self.verticalLayout = QVBoxLayout(self) self.promptLabel = QLabel(self) appname = str(QCoreApplication.instance().applicationName()) prompt = tr("Type the key you received when you contributed to $appname, as well as the " "e-mail used as a reference for the purchase.").replace('$appname', appname) self.promptLabel.setText(prompt) self.promptLabel.setAlignment(Qt.AlignLeading|Qt.AlignLeft|Qt.AlignTop) self.promptLabel.setWordWrap(True) self.verticalLayout.addWidget(self.promptLabel) self.formLayout = QFormLayout() self.formLayout.setSizeConstraint(QLayout.SetNoConstraint) self.formLayout.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow) self.formLayout.setLabelAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter) self.formLayout.setFormAlignment(Qt.AlignLeading|Qt.AlignLeft|Qt.AlignTop) self.label2 = QLabel(self) self.label2.setText(tr("Registration key:")) self.formLayout.setWidget(0, QFormLayout.LabelRole, self.label2) self.label3 = QLabel(self) self.label3.setText(tr("Registered e-mail:")) self.formLayout.setWidget(1, QFormLayout.LabelRole, self.label3) self.codeEdit = QLineEdit(self) self.formLayout.setWidget(0, QFormLayout.FieldRole, self.codeEdit) self.emailEdit = QLineEdit(self) self.formLayout.setWidget(1, QFormLayout.FieldRole, self.emailEdit) self.verticalLayout.addLayout(self.formLayout) self.horizontalLayout = QHBoxLayout() self.contributeButton = QPushButton(self) self.contributeButton.setText(tr("Contribute")) self.contributeButton.setAutoDefault(False) self.horizontalLayout.addWidget(self.contributeButton) spacerItem = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout.addItem(spacerItem) self.cancelButton = QPushButton(self) sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.cancelButton.sizePolicy().hasHeightForWidth()) self.cancelButton.setSizePolicy(sizePolicy) self.cancelButton.setText(tr("Cancel")) self.cancelButton.setAutoDefault(False) self.horizontalLayout.addWidget(self.cancelButton) self.submitButton = QPushButton(self) sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.submitButton.sizePolicy().hasHeightForWidth()) self.submitButton.setSizePolicy(sizePolicy) self.submitButton.setText(tr("Submit")) self.submitButton.setAutoDefault(False) self.submitButton.setDefault(True) self.horizontalLayout.addWidget(self.submitButton) self.verticalLayout.addLayout(self.horizontalLayout) #--- Events def contributeClicked(self): self.reg.app.contribute() def submitClicked(self): code = self.codeEdit.text() email = self.emailEdit.text() if self.reg.app.set_registration(code, email, False): self.accept()