def create_buttons(self, layout): '''Create two rows of buttons.''' vlayout = QtWidgets.QVBoxLayout() table1 = ( ('start', self.debug_xdb), ('quit', self.debug_quit), ('help', self.debug_help), ('list', self.debug_list), ('where', self.debug_where), ) table2 = ( ('break', self.debug_break), ('continue', self.debug_continue), ('next', self.debug_next), ('step', self.debug_step), ('return', self.debug_return), ) for table in (table1, table2): hlayout = QtWidgets.QHBoxLayout() for name, func in table: w = QtWidgets.QPushButton() w.setText(name) w.clicked.connect(func) hlayout.addWidget(w) vlayout.addLayout(hlayout) layout.addLayout(vlayout)
def _add_checkbox(self, text, state_changed, tooltip, checked=True, enabled=True, button_label=True): """ _add_checkbox - helper to add a checkbox :param str text: Text for label :param function state_changed: callback for state_changed signal :param bool checked: initially checked? :param bool enabled: initially enabled? :param bool button_label: label should be a button for single shot use :return: QCheckBox """ cbox = QtWidgets.QCheckBox('' if button_label else text, self) self.control.layout().addWidget(cbox) btn = None if button_label: btn = QtWidgets.QPushButton(text, self) self.control.layout().addWidget(btn) def cb(checked, cbox=cbox, state_changed=state_changed): state_changed(cbox.isChecked(), one_shot=True) btn.clicked.connect(cb) btn.setToolTip(tooltip) cbox.setChecked(checked) cbox.setEnabled(enabled) cbox.stateChanged.connect(state_changed) cbox.setToolTip(tooltip) self.control.layout().addItem(QtWidgets.QSpacerItem(20, 0)) return cbox
def initUI(self): # create GUI components ## this code is atrocious... don't look too closely self.setObjectName("LeoTagWidget") # verticalLayout_2: contains # verticalLayout self.verticalLayout_2 = QtWidgets.QVBoxLayout(self) self.verticalLayout_2.setContentsMargins(0, 1, 0, 1) self.verticalLayout_2.setObjectName("nodetags-verticalLayout_2") # horizontalLayout: contains # "Refresh" button # comboBox self.horizontalLayout = QtWidgets.QHBoxLayout() self.horizontalLayout.setContentsMargins(0, 0, 0, 0) self.horizontalLayout.setObjectName("nodetags-horizontalLayout") # horizontalLayout2: contains # label2 # not much by default -- it's a place to add buttons for current tags self.horizontalLayout2 = QtWidgets.QHBoxLayout() self.horizontalLayout2.setContentsMargins(0, 0, 0, 0) self.horizontalLayout2.setObjectName("nodetags-horizontalLayout2") label2 = QtWidgets.QLabel(self) label2.setObjectName("nodetags-label2") label2.setText("Tags for current node:") self.horizontalLayout2.addWidget(label2) # verticalLayout: contains # horizontalLayout # listWidget # horizontalLayout2 # label self.verticalLayout = QtWidgets.QVBoxLayout() self.verticalLayout.setObjectName("nodetags-verticalLayout") self.comboBox = QtWidgets.QComboBox(self) self.comboBox.setObjectName("nodetags-comboBox") self.comboBox.setEditable(True) self.horizontalLayout.addWidget(self.comboBox) self.pushButton = QtWidgets.QPushButton("+", self) self.pushButton.setObjectName("nodetags-pushButton") self.pushButton.setMinimumSize(24, 24) self.pushButton.setMaximumSize(24, 24) self.horizontalLayout.addWidget(self.pushButton) self.verticalLayout.addLayout(self.horizontalLayout) self.listWidget = QtWidgets.QListWidget(self) self.listWidget.setObjectName("nodetags-listWidget") self.verticalLayout.addWidget(self.listWidget) self.verticalLayout.addLayout(self.horizontalLayout2) self.label = QtWidgets.QLabel(self) self.label.setObjectName("nodetags-label") self.label.setText("Total: 0 items") self.verticalLayout.addWidget(self.label) self.verticalLayout_2.addLayout(self.verticalLayout) QtCore.QMetaObject.connectSlotsByName(self)
def main(): # stupid test a = QtWidgets.QApplication([]) b = QtWidgets.QPushButton("Say hello", None) g.procs.add(['ls', '/tmp']) g.procs.add(['ls', '-la']) #a.setMainWidget(b) b.show() a.exec_()
def create_window(self, filenames): # Create the widget. global gWindow gWindow = window = QtWidgets.QWidget() window.setWindowTitle(f"{len(filenames)} duplicates of {filenames[0]}") window.setMinimumHeight(self.window_height) # Move the window. window.move(50, 50) # Init the layouts. outer_layout = QtWidgets.QVBoxLayout() window.setLayout(outer_layout) button_layout = QtWidgets.QHBoxLayout() frame_layout = QtWidgets.QHBoxLayout() outer_layout.addLayout(button_layout) outer_layout.addLayout(frame_layout) # Set the font. font = QtGui.QFont() font.setBold(True) font.setPointSize(12) # Create the common buttons, left aligned. next_button = QtWidgets.QPushButton(text='Next', parent=window) quit_button = QtWidgets.QPushButton(text='Quit', parent=window) next_button.setFont(font) quit_button.setFont(font) button_layout.addWidget(next_button) button_layout.addWidget(quit_button) button_layout.addStretch() # Create the actions. next_button.clicked.connect(window.close) quit_button.clicked.connect(self.quit) # Create the subframes and add them to the frame_layout. for filename in filenames: frame = self.create_frame(filename, filenames[:], window) if frame: frame_layout.addWidget(frame) # Handle close events. def closeEvent(*args, **kwargs): window.close() self.next_window() window.closeEvent = closeEvent # Show the window. window.show()
def __init__(self, parent=None): """ctor for NestedSplitterChoice class.""" super().__init__(parent) self.setLayout(QtWidgets.QVBoxLayout()) button = QtWidgets.QPushButton("Action", self) # EKR: 2011/03/15 self.layout().addWidget(button) button.setContextMenuPolicy(QtConst.CustomContextMenu) button.customContextMenuRequested.connect(lambda pnt: self.parent( ).choice_menu(self, button.mapToParent(pnt))) button.clicked.connect( lambda: self.parent().choice_menu(self, button.pos()))
def create_frame(self, filename, filenames, window): QLabel = QtWidgets.QLabel # Create the frame. frame = QtWidgets.QFrame(parent=window) # Create the vertical layout. layout = QtWidgets.QVBoxLayout() frame.setLayout(layout) # Set the font. font = QtGui.QFont() font.setBold(True) font.setPointSize(12) # Create the labels.. ctime = time.ctime(os.path.getctime(filename)) struct_time = time.strptime(ctime) creation_time = time.strftime('%Y %m %d', struct_time) file_label = QLabel(text=filename, parent=frame) file_label.setFont(font) layout.addWidget(file_label) size = os.path.getsize(filename) / 1000 info_label = QLabel(text=f"size: {size} KB date: {creation_time}") info_label.setFont(font) layout.addWidget(info_label) # Create the delete button, centered. button_layout = QtWidgets.QHBoxLayout() button_layout.addStretch() delete_button = QtWidgets.QPushButton(text='Delete', parent=frame) button_layout.addWidget(delete_button) button_layout.addStretch() layout.addLayout(button_layout) # Set the button action. def delete_action(arg): self.delete_file(filename) delete_button.clicked.connect(delete_action) # Create the picture area. picture = QtWidgets.QLabel('picture', parent=frame) layout.addWidget(picture) # Display the picture. pixmap = QtGui.QPixmap(filename) try: TransformationMode = QtCore.Qt if isQt5 else QtCore.Qt.TransformationMode image = pixmap.scaledToHeight( self.window_height, TransformationMode.SmoothTransformation) # pylint: disable=no-member picture.setPixmap(image) picture.adjustSize() return frame except Exception: g.trace('Bad image') g.es_exception() return None
def make_ui(self): """make_ui - build up UI""" ui = type('CSVEditUI', (), {}) self.setLayout(QtWidgets.QVBoxLayout()) buttons = QtWidgets.QHBoxLayout() self.layout().addLayout(buttons) def mkbuttons(what, function): list_ = [ ('go-first', "%s column left", QtWidgets.QStyle.SP_ArrowLeft), ('go-last', "%s column right", QtWidgets.QStyle.SP_ArrowRight), ('go-top', "%s row above", QtWidgets.QStyle.SP_ArrowUp), ('go-bottom', "%s row below", QtWidgets.QStyle.SP_ArrowDown), ] buttons.addWidget(QtWidgets.QLabel(what+": ")) for name, tip, fallback in list_: button = QtWidgets.QPushButton() button.setIcon(QtGui.QIcon.fromTheme(name, QtWidgets.QApplication.style().standardIcon(fallback))) button.setToolTip(tip % what) button.clicked.connect(lambda checked, name=name: function(name)) buttons.addWidget(button) mkbuttons("Move", self.move) mkbuttons("Insert", self.insert) for text, function in [ ("Del row", lambda clicked: self.delete_col(row=True)), ("Del col.", lambda clicked: self.delete_col()), ("Prev", lambda clicked: self.prev_tbl()), ("Next", lambda clicked: self.prev_tbl(next=True)), ]: btn = QtWidgets.QPushButton(text) buttons.addWidget(btn) btn.clicked.connect(function) ui.min_rows = QtWidgets.QSpinBox() buttons.addWidget(ui.min_rows) ui.min_rows.setMinimum(1) ui.min_rows.setPrefix("tbl with ") ui.min_rows.setSuffix(" rows") ui.min_rows.setValue(4) buttons.addStretch(1) ui.table = QtWidgets.QTableView() self.layout().addWidget(ui.table) return ui
def mkbuttons(what, function): list_ = [ ('go-first', "%s column left", QtWidgets.QStyle.SP_ArrowLeft), ('go-last', "%s column right", QtWidgets.QStyle.SP_ArrowRight), ('go-top', "%s row above", QtWidgets.QStyle.SP_ArrowUp), ('go-bottom', "%s row below", QtWidgets.QStyle.SP_ArrowDown), ] buttons.addWidget(QtWidgets.QLabel(what+": ")) for name, tip, fallback in list_: button = QtWidgets.QPushButton() button.setIcon(QtGui.QIcon.fromTheme(name, QtWidgets.QApplication.style().standardIcon(fallback))) button.setToolTip(tip % what) button.clicked.connect(lambda checked, name=name: function(name)) buttons.addWidget(button)
def initUI(self): # create GUI components ## this code is atrocious... don't look too closely self.setObjectName("LeoNodewatchWidget") # verticalLayout_2: contains # verticalLayout self.verticalLayout_2 = QtWidgets.QVBoxLayout(self) self.verticalLayout_2.setContentsMargins(0, 1, 0, 1) self.verticalLayout_2.setObjectName("verticalLayout_2") # horizontalLayout: contains # "Refresh" button # comboBox self.horizontalLayout = QtWidgets.QHBoxLayout() self.horizontalLayout.setContentsMargins(0, 0, 0, 0) self.horizontalLayout.setObjectName("horizontalLayout") # verticalLayout: contains # horizontalLayout # listWidget # label self.verticalLayout = QtWidgets.QVBoxLayout() self.verticalLayout.setObjectName("verticalLayout") self.comboBox = QtWidgets.QComboBox(self) self.comboBox.setObjectName("comboBox") self.horizontalLayout.addWidget(self.comboBox) self.pushButton = QtWidgets.QPushButton("Refresh", self) self.pushButton.setObjectName("pushButton") self.pushButton.setMinimumSize(50, 24) self.pushButton.setMaximumSize(50, 24) self.horizontalLayout.addWidget(self.pushButton) self.verticalLayout.addLayout(self.horizontalLayout) self.listWidget = QtWidgets.QListWidget(self) self.listWidget.setObjectName("listWidget") self.verticalLayout.addWidget(self.listWidget) self.label = QtWidgets.QLabel(self) self.label.setObjectName("label") self.label.setText("Total: 0 items") self.verticalLayout.addWidget(self.label) self.verticalLayout_2.addLayout(self.verticalLayout) QtCore.QMetaObject.connectSlotsByName(self)
def create_widgets(self): '''Create the big-text buttons and text warning area.''' c = self.c self.active_flag = True warning = self.warning_message() if 1: # essential self.old_w.setPlainText(self.p.b) else: # can lose data. self.old_w.setPlainText( '@nocolor-node\n\nBig text not loaded: %s characters. Limit is %s' % (len(self.p.b), c.max_pre_loaded_body_chars)) self.w = w = QtWidgets.QWidget() # No parent needed. layout = QtWidgets.QVBoxLayout() # No parent needed. w.setLayout(layout) w.text = tw = QtWidgets.QTextBrowser() tw.setText(warning) tw.setObjectName('bigtextwarning') self.widgets['bigtextwarning'] = tw layout.addWidget(tw) table = [ ('remove', 'Remove These Buttons', self.remove), ('load_nc', 'Load Text With @killcolor', self.load_nc), ('more', 'Double limit for this session', self.more), ('copy', 'Copy body to clipboard', self.copy), ] if self.s.startswith('@killcolor'): del table[1] for key, label, func in table: self.widgets[key] = button = QtWidgets.QPushButton(label) layout.addWidget(button) def button_callback(checked, func=func): func() button.clicked.connect(button_callback) # layout.addItem(QtWidgets.QSpacerItem( # 10, 10, vPolicy=QtWidgets.QSizePolicy.Expanding)) self.layout.addWidget(w) w.show()
def _build_layout(self, show_head=True, show_control=True, update=True, recurse=False): """build_layout - build layout """ DBG("build layout") self.setLayout(QtWidgets.QVBoxLayout()) self.layout().setContentsMargins(0, 0, 0, 0) self.layout().setSpacing(0) # header self.header = self._add_frame() self.toggle_ctrl = QtWidgets.QPushButton("-", self) self.header.layout().addWidget(self.toggle_ctrl) self.line_edit = QtWidgets.QLineEdit(self) self.header.layout().addWidget(self.line_edit) self.header.layout().addStretch(1) self.btn_close = QtWidgets.QPushButton("X", self) self.btn_close.clicked.connect(lambda checked: self.close()) self.header.layout().addWidget(self.btn_close) # controls self.control = self._add_frame() # checkboxes txt = ",\ncheck to do this always" self.cb_track = self._add_checkbox( "Track", self.change_track, "Track the node selected in the tree" + txt) self.cb_goto = self._add_checkbox( "Goto", self.change_goto, "Make the tree go to this node" + txt) self.cb_update = self._add_checkbox( "Update", self.change_update, "Update view to match changed node" + txt) self.cb_recurse = self._add_checkbox("Recurse", self.change_recurse, "Recursive view" + txt, checked=recurse) # mode menu btn = self.btn_mode = QtWidgets.QPushButton("Mode", self) self.control.layout().addWidget(btn) btn.setContextMenuPolicy(QtConst.CustomContextMenu) btn.customContextMenuRequested.connect( # right click lambda pnt: self.mode_menu()) btn.clicked.connect( # or left click lambda checked: self.mode_menu()) # misc. menu btn = self.control_menu_button = QtWidgets.QPushButton( "More\u25BE", self) self.control.layout().addWidget(btn) btn.setContextMenuPolicy(QtConst.CustomContextMenu) btn.customContextMenuRequested.connect( # right click lambda pnt: self.misc_menu()) btn.clicked.connect( # or left click lambda checked: self.misc_menu()) # padding self.control.layout().addItem( QtWidgets.QSpacerItem(0, 0, hPolicy=QtWidgets.QSizePolicy.Expanding)) # content self.splitter = ClickySplitter(self) self.splitter.setOrientation(QtCore.Qt.Vertical) self.layout().addWidget(self.splitter) self.edit_frame = self._add_frame() self.splitter.addWidget(self.edit_frame) self.view_frame = self._add_frame() self.splitter.addWidget(self.view_frame) self.control_visible = show_control self.header_visible = show_head self.show() # debug self.line_edit.setText("test") # toggle control visibility self.toggle_ctrl.clicked.connect( lambda checked: self.control.setVisible(not self.control.isVisible( )))
def show_list(self, links, up=False): """show_list - update pane with buttons :Parameters: - `links`: Bookmarks to show """ p = self.v.context.vnode2position(self.v) if not p: return w = self.w cull = w.layout().takeAt(0) while cull: if cull.widget(): cull.widget().deleteLater() cull = w.layout().takeAt(0) todo = [links or [] ] # empty list to create container to click in to add first current_level = 1 current_url = None showing_chain = [] row_parent = self.v while todo: links = todo.pop(0) if todo else [] top = QtWidgets.QWidget() # pylint: disable=undefined-loop-variable # pylint bug, fix released: http://www.logilab.org/ticket/89092 # pylint: disable=undefined-variable top.mouseReleaseEvent = ( lambda event, links=links, row_parent=row_parent: self. background_clicked(event, links, row_parent)) top.setMinimumSize(10, 10) # so there's something to click when empty size_policy = QtWidgets.QSizePolicy( QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) size_policy.setHorizontalStretch(1) size_policy.setVerticalStretch(1) top.setSizePolicy(size_policy) w.layout().addWidget(top) layout = FlowLayout() layout.setSpacing(5) top.setLayout(layout) if not links: layout.addWidget(QtWidgets.QLabel("(empty bookmarks folder)")) for bm in links: bm.v.u.setdefault('__bookmarks', { 'is_dupe': False, }) but = QtWidgets.QPushButton(bm.head) if bm.url: but.setToolTip(bm.url) # pylint: disable=undefined-variable # 'but' *is* defined. but.mouseReleaseEvent = (lambda event, bm=bm, but=but: self. button_clicked(event, bm, but)) layout.addWidget(but) showing = False if self.current and (bm.children or not bm.url): nd = self.current while nd != bm.v and nd.parents: nd = nd.parents[0] if nd == bm.v: showing = True todo.append(bm.children) row_parent = bm.v if bm.v.u['__bookmarks']['is_dupe']: style_sheet = "background: red; color: white;" else: style_sheet = ("background: #%s;" % self.color(bm.head, dark=self.dark)) but.setStyleSheet(style_sheet) bm.v.u['__bookmarks']['is_dupe'] = False classes = [] if bm.v == self.current: classes += ['bookmark_current'] current_level = self.w.layout().count() current_url = bm.url if showing: classes += ['bookmark_expanded'] showing_chain += [bm] if bm.children or not bm.url: classes += ['bookmark_children'] but.setProperty('style_class', ' '.join(classes)) if self.levels: # drop excess levels if ((not self.second and current_url and current_url.strip() and self.levels == 1 or up or self.upwards) and current_level < self.w.layout().count() and self.levels < self.w.layout().count()): # hide last line, of children, if none are current self.w.layout().takeAt(self.w.layout().count() - 1).widget().deleteLater() while self.w.layout().count() > self.levels: # add an up button to the second row... next_row = self.w.layout().itemAt(1).widget().layout() but = QtWidgets.QPushButton('^') bm = showing_chain.pop(0) def mouseReleaseHandler2(event, bm=bm, but=but): self.button_clicked(event, bm, but, up=True) but.mouseReleaseEvent = mouseReleaseHandler2 next_row.addWidget(but) # rotate to start of layout, FlowLayout() has no insertWidget() next_row.itemList[:] = next_row.itemList[ -1:] + next_row.itemList[:-1] # ...then delete the first self.w.layout().takeAt(0).widget().deleteLater() w.layout().addStretch()
def make_ui(self): """make_ui - build up UI""" ui = type('CSVEditUI', (), {}) # a QVBox containing two QHBoxes self.setLayout(QtWidgets.QVBoxLayout()) buttons = QtWidgets.QHBoxLayout() self.layout().addLayout(buttons) buttons2 = QtWidgets.QHBoxLayout() self.layout().addLayout(buttons2) # make 4 directional buttons def mkbuttons(what, function): list_ = [ ('go-first', "%s column left", QtWidgets.QStyle.SP_ArrowLeft), ('go-last', "%s column right", QtWidgets.QStyle.SP_ArrowRight), ('go-top', "%s row above", QtWidgets.QStyle.SP_ArrowUp), ('go-bottom', "%s row below", QtWidgets.QStyle.SP_ArrowDown), ] buttons.addWidget(QtWidgets.QLabel(what + ": ")) for name, tip, fallback in list_: button = QtWidgets.QPushButton() button.setIcon( QtGui.QIcon.fromTheme( name, QtWidgets.QApplication.style().standardIcon(fallback))) button.setToolTip(tip % what) button.clicked.connect( lambda checked, name=name: function(name)) buttons.addWidget(button) # add buttons to move rows / columns mkbuttons("Move", self.move) # add buttons to insert rows / columns mkbuttons("Insert", self.insert) for text, function, layout in [ ("Del row", lambda clicked: self.delete_col(row=True), buttons), ("Del col.", lambda clicked: self.delete_col(), buttons), ("Prev", lambda clicked: self.prev_tbl(), buttons2), ("Next", lambda clicked: self.prev_tbl(next=True), buttons2), ]: btn = QtWidgets.QPushButton(text) layout.addWidget(btn) btn.clicked.connect(function) # input for minimum rows to count as a table ui.min_rows = QtWidgets.QSpinBox() buttons2.addWidget(ui.min_rows) ui.min_rows.setMinimum(1) ui.min_rows.setPrefix("tbl with ") ui.min_rows.setSuffix(" rows") ui.min_rows.setValue(self.state['rows']) # separator text and line start / end text for attr in 'sep', 'start', 'end': buttons2.addWidget(QtWidgets.QLabel(attr.title() + ':')) w = QtWidgets.QLineEdit() w.setText(self.state[attr]) setattr(ui, attr + '_txt', w) # w.textEdited.connect(self.delim_changed) buttons2.addWidget(w) ui.sep_txt.setToolTip("Use Prev/Next to rescan table with new sep") w = QtWidgets.QPushButton('Change') w.setToolTip("Change separator in text") w.clicked.connect(lambda checked: self.delim_changed()) buttons2.addWidget(w) buttons.addStretch(1) buttons2.addStretch(1) ui.table = QtWidgets.QTableView() self.layout().addWidget(ui.table) return ui