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 updateEditorInt(self): c = self.c self.initForm() for attr in self.getAttribs(): class_, name, value, path, type_, readonly = attr if readonly: self.form.addRow(QtWidgets.QLabel(name), QtWidgets.QLabel(str(value))) else: editor = editWatcher(c, c.currentPosition().v, class_, name, value, path, type_) self.editors.append(editor) self.form.addRow(QtWidgets.QLabel(name), editor.widget())
def image(self, pane, fn, center=None, height=None, width=None): '''Put an image in the indicated pane.''' m = self parent = m.pane_widget(pane) if not parent: g.trace('bad pane: %s' % (pane)) return None w = QtWidgets.QLabel('label', parent) fn = m.resolve_icon_fn(fn) if not fn: return None pixmap = QtGui.QPixmap(fn) if not pixmap: return g.trace('Not a pixmap: %s' % (fn)) if height: pixmap = pixmap.scaledToHeight(height) if width: pixmap = pixmap.scaledToWidth(width) w.setPixmap(pixmap) if center: g_w = w.geometry() g_p = parent.geometry() dx = (g_p.width() - g_w.width()) / 2 w.move(g_w.x() + dx, g_w.y() + 10) w.show() m.widgets.append(w) return w
def _build_gui(self): self.w = w = QtWidgets.QWidget() w.setObjectName('show_livecode') w.setLayout(QtWidgets.QVBoxLayout()) self.status = QtWidgets.QLabel() w.layout().addWidget(self.status) self.text = QtWidgets.QTextBrowser() w.layout().addWidget(self.text) h = QtWidgets.QHBoxLayout() w.layout().addLayout(h) self.activate = QtWidgets.QPushButton("Stop") self.activate.setToolTip("Start / stop live code display") h.addWidget(self.activate) self.activate.clicked.connect(lambda checked: self.toggle_active()) b = QtWidgets.QPushButton("Run here") b.setToolTip("Show live code for this node") h.addWidget(b) b.clicked.connect(lambda checked: self.run_here()) b = QtWidgets.QPushButton("Go to node") b.setToolTip("Jump to node where live code is shown") h.addWidget(b) b.clicked.connect(lambda checked: self.goto_node()) b = QtWidgets.QPushButton("Dump") b.setToolTip("AST dump to stdout (devel. option)") h.addWidget(b) b.clicked.connect( lambda checked, self=self: setattr(self, 'dump', True))
def __init__(self, *args, **kwargs): QtWidgets.QWidget.__init__(self, *args, **kwargs) self.textedit = QtWidgets.QTextEdit(*args, **kwargs) # need to call focusin/out set on parent by FocusingPlaintextEdit / mknote self.textedit.focusInEvent = self._call_old_first( self.textedit.focusInEvent, self.focusin) self.textedit.focusOutEvent = self._call_old_first( self.textedit.focusOutEvent, self.focusout) self.searchbox = QtWidgets.QLineEdit() self.searchbox.focusInEvent = self._call_old_first( self.searchbox.focusInEvent, self.focusin) self.searchbox.focusOutEvent = self._call_old_first( self.searchbox.focusOutEvent, self.focusout) # invoke find when return pressed self.searchbox.returnPressed.connect(self.search) layout = QtWidgets.QVBoxLayout() self.setLayout(layout) layout.setSpacing(0) layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self.textedit) hlayout = QtWidgets.QHBoxLayout() hlayout.setContentsMargins(0, 0, 0, 0) hlayout.addWidget(QtWidgets.QLabel("Find:")) hlayout.addWidget(self.searchbox) layout.addLayout(hlayout)
def update_current_tags(self, pos): # clear out the horizontalLayout2 hl2 = self.horizontalLayout2 while hl2.count(): child = hl2.takeAt(0) child.widget().deleteLater() label = QtWidgets.QLabel(self) label.setText('Tags for current node:') hl2.addWidget(label) tags = self.tc.get_tags(pos) # add tags for tag in tags: l = QtWidgets.QLabel(self) l.setText(tag) hl2.addWidget(l) l.mouseReleaseEvent = self.callback_factory(tag)
def make_widgets(self): w = self # Init the window's attributes. w.setStyleSheet(f"background: {self.background_color}") w.setGeometry(0, 0, self._width, self._height) # The non-full-screen sizes. # Create the picture area. w.picture = QtWidgets.QLabel('picture', self) w.picture.keyPressEvent = w.keyPressEvent # Create the scroll area. w.scroll_area = area = QtWidgets.QScrollArea() area.setWidget(self.picture) AlignmentFlag = QtCore.Qt if isQt5 else QtCore.Qt.AlignmentFlag area.setAlignment(AlignmentFlag.AlignHCenter | AlignmentFlag.AlignVCenter) # pylint: disable=no-member # Disable scrollbars. ScrollBarPolicy = QtCore.Qt if isQt5 else QtCore.Qt.ScrollBarPolicy area.setHorizontalScrollBarPolicy( ScrollBarPolicy.ScrollBarAlwaysOff) # pylint: disable=no-member area.setVerticalScrollBarPolicy(ScrollBarPolicy.ScrollBarAlwaysOff) # pylint: disable=no-member # Init the layout. layout = QtWidgets.QVBoxLayout() layout.addWidget(self.scroll_area) w.setLayout(layout)
def update_current_tags(self, p): # # Clear horizontalLayout2 layout = self.horizontalLayout2 while layout.count(): child = layout.takeAt(0) child.widget().deleteLater() label = QtWidgets.QLabel(self) label.setObjectName("nodetags-label2") label.setText('Tags for current node (right click to clear):') layout.addWidget(label) # # add tags tags = self.tc.get_tags(p) for tag in tags: label = QtWidgets.QLabel(self) label.setText(tag) label.setObjectName('nodetags-label3') layout.addWidget(label) label.mouseReleaseEvent = self.callback_factory(tag)
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 __init__(self, canvas, num): '''Ctor for the LeoFigureManagerQt class.''' self.c = c = g.app.log.c # g.trace('LeoFigureManagerQT', c) FigureManagerBase.__init__(self, canvas, num) self.canvas = canvas # New code for Leo: embed the canvas in the viewrendered area. self.vr_controller = vc = vr.controllers.get(c.hash()) self.splitter = c.free_layout.get_top_splitter() self.frame = w = QtWidgets.QFrame() w.setLayout(QtWidgets.QVBoxLayout()) w.layout().addWidget(self.canvas) vc.embed_widget(w) class DummyWindow: def __init__(self, c): self.c = c self._destroying = None def windowTitle(self): return self.c.p.h self.window = DummyWindow(c) # See comments in the base class ctor, in backend_qt5.py. self.canvas.setFocusPolicy(QtCore.Qt.StrongFocus) self.canvas.setFocus() self.canvas._destroying = False self.toolbar = self._get_toolbar(self.canvas, self.frame) if self.toolbar is not None: # The toolbar is a backend_qt5.NavigationToolbar2QT. layout = self.frame.layout() layout.addWidget(self.toolbar) # add text label to status bar self.statusbar_label = QtWidgets.QLabel() layout.addWidget(self.statusbar_label) # pylint: disable=no-member if isQt5: pass # The status bar doesn't work yet. else: self.toolbar.message.connect(self._show_message) self.canvas.draw_idle() def notify_axes_change(fig): # This will be called whenever the current axes is changed if self.toolbar is not None: self.toolbar.update() self.canvas.figure.add_axobserver(notify_axes_change)
def create_input_area(self, layout): # Create the Label label = QtWidgets.QLabel() label.setText('Debugger command:') # Create the editor. self.line_edit = w = QtWidgets.QLineEdit() w.setStyleSheet('background: white; color: black;') w.returnPressed.connect(self.debug_input) # Add the widgets to a new layout. layout2 = QtWidgets.QVBoxLayout() layout2.addWidget(label) layout2.addWidget(w) layout.addLayout(layout2)
def create_output_area(self, layout): # Create the Label label = QtWidgets.QLabel() label.setText('Debugger outpuit:') # Create the output area. self.output_area = w = QtWidgets.QTextEdit() w.setStyleSheet('background: white; color: black;') w.setHorizontalScrollBarPolicy(ScrollBarPolicy.ScrollBarAsNeeded) w.setWordWrapMode(WrapMode.NoWrap) # Add the widgets to a new layout. vlayout = QtWidgets.QVBoxLayout() vlayout.addWidget(label) vlayout.addWidget(w) layout.addLayout(vlayout)
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 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