def create_ui(self): self.w = w = QtWidgets.QWidget() w.setWindowTitle("Leo search") lay = QtWidgets.QVBoxLayout() self.web = web = QtWebKitWidgets.QWebView(w) self.web.linkClicked.connect(self._lnk_handler) self.led = led = QtWidgets.QLineEdit(w) led.returnPressed.connect(self.docmd) lay.addWidget(led) lay.addWidget(web) self.lc = lc = LeoConnector() web.page().mainFrame().addToJavaScriptWindowObject("leo",lc) web.page().setLinkDelegationPolicy(QtWebKitWidgets.QWebPage.DelegateAllLinks) w.setLayout(lay) #web.load(QUrl("http://google.fi")) self.show_help() # w.show() def help_handler(tgt,qs): if qs == "help": self.show_help() return True return False self.add_cmd_handler(help_handler) self.led.setFocus()
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, c, v=None): self.c = c c._bookmarks = self # self.v - where the bookmarks for c are kept, may not be in c if v is None: v = self.v = c.p.v else: self.v = v self.current = None # current (last used) bookmark self.previous = None # position in outline, for outline / bookmarks switch self.levels = c.config.getInt('bookmarks-levels') or 1 # levels to show in hierarchical display self.second = False # second click of current bookmark? self.upwards = False # moving upwards through hierarchy self.w = QtWidgets.QWidget() self.reloadSettings() # stuff for pane persistence self.w._ns_id = '_leo_bookmarks_show:' # v might not be in this outline c.db['_leo_bookmarks_show'] = v.context.vnode2position(v).get_UNL() # else: # c.frame.log.createTab(c.p.h[:10]) # tabWidget = c.frame.log.tabWidget # self.w = tabWidget.widget(tabWidget.count()-1) self.w.setObjectName('show_bookmarks') self.w.setMinimumSize(10, 10) self.w.setLayout(QtWidgets.QVBoxLayout()) self.w.layout().setContentsMargins(0, 0, 0, 0) self.current_list = self.get_list() self.show_list(self.current_list) g.registerHandler('select1', self.update)
def main(): app = QtWidgets.QApplication(sys.argv) win = QtWidgets.QWidget() l = QtWidgets.QVBoxLayout() win.setLayout(l) w = QtWidgets.QDateEdit() w.setCalendarPopup(True) l.addWidget(w) l.addWidget(QNDateEdit()) l.addWidget(QNDateEdit(n=6)) l.addWidget(QNDateEdit(n=1)) l.addWidget(QNDateEdit(n=2)) l.addWidget(QNDateEdit(n=6, columns=2)) l.addWidget(QNDateEdit(n=6, columns=4)) l.addWidget(QNDateEdit(n=12, columns=4)) l.addWidget(QNDateEdit(columns=1)) last = QNDateEdit() l.addWidget(last) last.calendarWidget().build(5, 4) win.show() if isQt6: sys.exit(app.exec()) else: sys.exit(app.exec_())
def create_widgets(self): '''Create the big-text buttons and text warning area.''' c = self.c self.active_flag = True warning = self.warning_message() self.old_w.setPlainText(self.p.b) # essential. 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 _add_frame(self): """_add_frame - add a widget with a layout as a hiding target. i.e. a container we can hide / show easily""" w = QtWidgets.QWidget(self) self.layout().addWidget(w) w.setSizePolicy(Policy.Expanding, Policy.Maximum) w.setLayout(QtWidgets.QHBoxLayout()) w.layout().setContentsMargins(0, 0, 0, 0) w.layout().setSpacing(0) return w
def create_ui(self): self.w = w = QtWidgets.QWidget() w.setWindowTitle("Leo search") lay = QtWidgets.QVBoxLayout() if (not QtWebKitWidgets # Workaround #1114: https://github.com/leo-editor/leo-editor/issues/1114 or isQt5 and sys.platform.startswith('win') # Workaround #304: https://github.com/leo-editor/leo-editor/issues/304 ): self.web = web = QtWidgets.QTextBrowser(w) else: self.web = web = QtWebKitWidgets.QWebView(w) try: # PyQt4 self.web.linkClicked.connect(self._lnk_handler) # AttributeError: 'QWebEngineView' object has no attribute 'linkClicked' except AttributeError: # PyQt5 pass # Not clear what to do. self.led = led = QtWidgets.QLineEdit(w) led.returnPressed.connect(self.docmd) lay.addWidget(led) lay.addWidget(web) self.lc = lc = LeoConnector() try: web.page().mainFrame().addToJavaScriptWindowObject("leo", lc) web.page().setLinkDelegationPolicy( QtWebKitWidgets.QWebPage.DelegateAllLinks) except AttributeError: # PyQt5 pass # Not clear what to do. w.setLayout(lay) #web.load(QUrl("http://google.fi")) self.show_help() # w.show() def help_handler(tgt, qs): if qs == "help": self.show_help() return True return False self.add_cmd_handler(help_handler) self.led.setFocus()
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 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()