def __init__(self, spiderName, resumable=False, parent=None): super(SpiderToolButton, self).__init__(parent) self._drag_start = None button_play = QToolButton() button_play.setIcon(QIcon("play.png")) self.triggered.connect( button_play.triggered ) # clicking the outer button run the play functionality button_play.setIconSize(QSize(32, 32)) button_resume = QToolButton() button_resume.setEnabled(resumable) button_resume.setIcon(QIcon("resume.png")) button_resume.setIconSize(QSize(32, 32)) button_pause = QToolButton() button_pause.setIcon(QIcon("pause.png")) button_pause.setIconSize(QSize(32, 32)) self.label_spidername = QLabel(spiderName) self.label_spidername.setStyleSheet(self.stylesheet_label_spidername) layout = QGridLayout() layout.addWidget(self.label_spidername, 0, 0) layout.addWidget(button_pause, 1, 1) layout.addWidget(button_resume, 1, 2) layout.addWidget(button_play, 1, 3) layout.setContentsMargins(10, 8, 10, 8) self.setLayout(layout)
def createWidgets(self): self.backButton = QToolButton() self.backButton.setIcon(QIcon(":/go-back.svg")) self.backButton.setText("&Back") self.backButton.setToolTip("""\ <p><b>Back</b> ({})</p> <p>Navigate to the previous page.</p>""".format( QKeySequence("Alt+Left").toString())) self.forwardButton = QToolButton() self.forwardButton.setIcon(QIcon(":/go-forward.svg")) self.forwardButton.setText("&Forward") self.forwardButton.setToolTip("""\ <p><b>Forward</b> ({})</p> <p>Navigate to the page you've just come back from.</p>""".format( QKeySequence("Alt+Right").toString())) self.contentsButton = QToolButton() self.contentsButton.setIcon(QIcon(":/go-home.svg")) self.contentsButton.setText("&Contents") self.contentsButton.setToolTip("""\ <p><b>Contents</b> ({})</p> <p>Navigate to the contents page.</p>""".format( QKeySequence("Alt+Home").toString())) self.searchLineEdit = Widgets.LegendLineEdit.LineEdit( "Search (F3 or Ctrl+F)") self.searchLineEdit.setToolTip("""\ <p><b>Search editor</p> <p>Type in a word to search for in the online help pages and press <b>Enter</b> or <b>F3</b> to search.</p>""") self.zoomInButton = QToolButton() self.zoomInButton.setIcon(QIcon(":/zoomin.svg")) self.zoomInButton.setText("&Zoom In") self.zoomInButton.setToolTip("""\ <p><b>Zoom In</b> ({})</p> <p>Make the text bigger.</p>""".format( QKeySequence("Alt++").toString())) self.zoomOutButton = QToolButton() self.zoomOutButton.setIcon(QIcon(":/zoomout.svg")) self.zoomOutButton.setText("Zoom &Out") self.zoomOutButton.setToolTip("""\ <p><b>Zoom Out</b> ({})</p> <p>Make the text smaller.</p>""".format( QKeySequence("Alt+-").toString())) width = self.fontMetrics().width(self.zoomOutButton.text() + " ") for button in (self.backButton, self.forwardButton, self.contentsButton, self.zoomInButton, self.zoomOutButton): button.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) button.setMinimumWidth(width) button.setFocusPolicy(Qt.NoFocus) self.browser = QWebView() page = self.browser.page() page.setLinkDelegationPolicy(QWebPage.DelegateAllLinks) if self.debug: self.urlLabel = QLabel()
def _make_tabs_button(self, side_widgets, side_icons): if len(side_widgets) != len(side_icons): raise Exception( "Bad parameters : len(side_widgets) ({}) != len(side_icons) ({})" .format(len(side_widgets), len(side_icons))) layout = QVBoxLayout() self._side_icons = [] ndx = 0 for w in side_widgets: resource_name = side_icons[ndx] pixmap = QPixmap(os.path.join(resource_dir, resource_name)) icon = QIcon(pixmap) self._side_icons.append(icon) b = QToolButton() b.setIcon(icon) b.setIconSize(pixmap.rect().size()) b.setMaximumWidth(pixmap.rect().width() + 6) b.clicked.connect(self.signal_mapper_tab_changed.map) self.signal_mapper_tab_changed.setMapping(b, ndx) layout.addWidget(b) layout.setStretch(ndx, 1) ndx += 1 layout.addStretch() return layout
def show_calorie_calc(self, row_count=0): ''' show calorie calculator :return: ''' if row_count > 0: row_count += 1 self.clear_table(None, None) self.stuff_table.clearContents() self.stuff_table.setColumnCount(3) self.stuff_table.setRowCount(row_count) self.stuff_table.setHorizontalHeaderLabels(['Amount', 'Unit', 'Name']) if row_count > 0: stuff_widget = QWidget() stuff_pixmap = QPixmap('icons/add.png') stuff_icon = QIcon() stuff_add_bt = QToolButton() stuff_icon.addPixmap(stuff_pixmap) stuff_add_bt.setIcon(stuff_icon) stuff_add_bt.setIconSize(QSize(8, 8)) stuff_add_bt.clicked.connect( lambda: self.stuff_table.insertRow(row_count - 1)) stuff_layout = QHBoxLayout() stuff_layout.addWidget(stuff_add_bt) stuff_widget.setLayout(stuff_layout) self.stuff_table.setCellWidget(row_count - 1, 2, stuff_widget)
def __init__(self, filter_updater, parent=None): """ :type filter_updater: (str) -> None :type parent: QWidget """ super().__init__(parent) self._filter_updater = lambda: filter_updater(self.text()) self.setFixedHeight(self.HEIGHT) self.setMaxLength(48) self.setMaximumWidth(200) self._tool_button = QToolButton(self) self._tool_button.setIcon(QIcon(resource_filepath("clear.png"))) self._tool_button.setStyleSheet("QToolButton {" " border: none;" " padding: 0px;" "}") frame_width = self._getFrameWidth() icon_side = self.HEIGHT - 2 * frame_width self._tool_button.setFixedSize(icon_side, icon_side) self._tool_button.clicked.connect(self.onClearButton) self._tool_button.hide() self.textChanged.connect(self.updateFilter) stylesheet = \ "QLineEdit {{" \ " padding-right: {}px;" \ " background-color: #FFFFFF;" \ "}}".format(self._tool_button.sizeHint().width() + frame_width + 1) self.setStyleSheet(stylesheet)
def create_header_bar(self, layout): back_button = QToolButton() back_button.setIconSize(QSize(30, 30)) back_button.setIcon(QIcon(os.path.join("icons", "ic_action_back.png"))) back_button.setStyleSheet("border: 0px;") back_button.setToolTip("Zurück") back_button.clicked.connect(self.back) layout.addWidget(back_button)
def create_header_bar(self, layout): self.sync_button = QToolButton() self.sync_button.setIconSize(QSize(30, 30)) self.sync_button.setIcon(QIcon(os.path.join("icons", "ic_action_sync.png"))) self.sync_button.setStyleSheet("border: 0px;") self.sync_button.setToolTip("Sync") self.sync_button.clicked.connect(self.sync_clicked) self.sync_button.setVisible(False) layout.addWidget(self.sync_button) self.clipboard_button = QToolButton() self.clipboard_button.setIconSize(QSize(30, 30)) self.clipboard_button.setIcon(QIcon(os.path.join("icons", "ic_action_copy.png"))) self.clipboard_button.setStyleSheet("border: 0px;") self.clipboard_button.setToolTip("in die Zwischenablage") self.clipboard_button.clicked.connect(self.copy_to_clipboard) self.clipboard_button.setVisible(False) layout.addWidget(self.clipboard_button)
def createWidgets(self): self.label = QLabel("Gro&ups") self.groupsList = QListWidget() self.tooltips.append((self.groupsList, """ <p><b>Groups</b> (Alt+U)</p> <p>A (possibly empty) list of the current entry's groups.</p>""")) self.label.setBuddy(self.groupsList) self.closeButton = QToolButton() self.closeButton.setIcon(QIcon(":/hide.svg")) self.closeButton.setFocusPolicy(Qt.NoFocus) self.tooltips.append((self.closeButton, """<p><b>Hide</b></p> <p>Hide the Groups panel.</p> <p>Use <b>Spelling→Show Suggestions and Groups</b> to show it again.</p>""")) self.helpButton = QToolButton() self.helpButton.setIcon(QIcon(":/help.svg")) self.helpButton.setFocusPolicy(Qt.NoFocus) self.tooltips.append((self.helpButton, "Help on the Groups panel."))
def __init__(self, parent=None): QLineEdit.__init__(self, parent) self.clear_button = QToolButton(self) self.clear_button.setText("clear") self.clear_button.hide() self.clear_button.clicked.connect(self.clear) # self.clear_button.setIcon(QIcon(":/denied.png")) self.textChanged.connect(self.update_clear_button)
def createWidgets(self): self.label = QLabel("Suggestions") self.spellList = Widgets.List.HtmlListWidget(self.state) self.tooltips.append((self.spellList, """ <p><b>Suggestions</b> (Alt+N,Tab)</p> <p>A (possibly empty) list of completions or replacements for the word being typed in the <b>Term</b> editor.</p>""")) self.label.setBuddy(self.spellList) self.closeButton = QToolButton() self.closeButton.setIcon(QIcon(":/hide.svg")) self.closeButton.setFocusPolicy(Qt.NoFocus) self.tooltips.append((self.closeButton, """<p><b>Hide</b></p> <p>Hide the Suggestions panel.</p> <p>Use <b>Spelling→Show Suggestions and Groups</b> to show it again.</p>""")) self.helpButton = QToolButton() self.helpButton.setIcon(QIcon(":/help.svg")) self.helpButton.setFocusPolicy(Qt.NoFocus) self.tooltips.append( (self.helpButton, "Help on the Suggestions panel."))
def CreateFlatButton(action): """ Create a custom flat button and style it so that it will look good on all platforms. """ toolButton = QToolButton() toolButton.setIcon(action.icon()) toolButton.setText(action.text()) toolButton.setAutoRaise(True) toolButton.setIconSize(QSize(32, 32)) toolButton.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) if sys.platform.startswith('darwin'): # Bug for Mac: QToolButtons do not react to setAutoRaise so # can't be made flat when they are not used inside a toolbar. # Setting a custom style sheet with border to none fixes this. # But then it looses all its highlight and pressed visual cues # so some extra styling needs to be done to provide some nice # visual feedback on hover and pressed states. toolButton.setStyleSheet( "QToolButton {" "border: none;" "} " "QToolButton:hover {" "background-color: qradialgradient(cx: 0.5, cy: 0.5," "fx: 0.5, fy: 0.5," "radius: 0.5, " "stop: 0 rgba(255, 255, 255, 100), " "stop: 1 rgba(0, 0, 0, 0));" "}" "QToolButton:pressed {" "background-color: qradialgradient(cx: 0.5, cy: 0.5," "fx: 0.5, fy: 0.5," "radius: 0.5, " "stop: 0 rgba(255, 255, 255, 200), " "stop: 1 rgba(0, 0, 0, 0));" "}") font = QFont() font.setPixelSize(10) toolButton.setFont(font) # Connect the clicked signal to the action trigger def pushed(): toolButton.action.triggered.emit() setattr(toolButton, "pushed", pushed) toolButton.clicked.connect(toolButton.pushed) setattr(toolButton, "action", action) return toolButton
def _init_toolbar(self): self.basedir = os.path.join(matplotlib.rcParams['datapath'], 'images') layout = QVBoxLayout(self) #a = QToolButton(self._icon('home.png'), u'原状', self.home) a = QToolButton(self) layout.addWidget(a) a.setToolTip(u'恢复初始状态') #a = QToolButton(self._icon('back.png'), u'后退', self.back) a = QToolButton(self) layout.addWidget(a) a.setToolTip(u'前一个视图') #a = QToolButton(self._icon('forward.png'), u'前进', self.forward) a = QToolButton(self) layout.addWidget(a) a.setToolTip(u'下一个视图') #a = QToolButton(self._icon('move.png'), u'平移', self.pan) a = QToolButton(self) layout.addWidget(a) a.setToolTip('Pan axes with left mouse, zoom with right') #a = QToolButton(self._icon('zoom_to_rect.png'), 'Zoom', self.zoom) a = QToolButton(self) layout.addWidget(a) a.setToolTip('Zoom to rectangle')
def createWidgets(self): self.helpButton = QToolButton() self.helpButton.setIcon(QIcon(":/help.svg")) self.helpButton.setFocusPolicy(Qt.NoFocus) self.helpButton.clicked.connect(self.help) self.tooltips.append( (self.helpButton, """Help on the Suggestions or Filtered panel.""")) self.view = Views.Filtered.View(self.state) self.tooltips.append((self.view, """<p><b>Filtered view</b></p> <p>This view shows any entries that match the current <b>Filter</b>.</p> <p>Press <b>F3</b> or click <img src=":/goto-found.svg" width={0} height={0}> or click <b>Goto→Filtered</b> to go to the current filtered entry.</p>""".format(TOOLTIP_IMAGE_SIZE))) self.view.match = "" self.filterLabel = QLabel( "Filter <font color=darkgreen>(Ctrl+F)</font>") self.filterComboBox = QComboBox() self.filterComboBox.setMaxVisibleItems(24) self.tooltips.append((self.filterComboBox, """\ <p><b>Filter combobox</b></p> <p>Use this combobox to choose the filter to use.</p> <p>The <b>Terms Matching</b>, <b>Pages Matching</b>, and <b>Notes Matching</b> filters need a match text.</p>""")) self.filterLabel.setBuddy(self.filterComboBox) for filter in FilterKind: if not filter.isCheck: self.filterComboBox.addItem(filter.text, filter) self.filterComboBox.currentIndexChanged[int].connect(self.query) self.filterTextComboBox = ComboBox() self.filterTextComboBox.setEditable(True) self.filterTextComboBox.setDuplicatesEnabled(False) self.filterTextComboBox.currentIndexChanged[str].connect(self.setMatch) self.tooltips.append((self.filterTextComboBox, """\ <p><b>Filter Match editor</b></p> <p>The text to match when using a <b>Terms Matching</b>, <b>Pages Matching</b>, or <b>Notes Matching</b> filter.</p> <p>For terms and notes, the filtered entries are chosen by case-insensitively comparing with the match word or words.</p> <p>Add a <tt>*</tt> after a word to match any words that begin with the text preceding the <tt>*</tt>.</p> <p>For example, “comp*” will match “compress”, “compulsory”, “computer”, “computed”, etc.</p> <p>For pages, enter them as you would for an entry's pages, e.g., <tt>199,202-5</tt> to match entries whose pages equal or include <tt>199,202,203,204,205</tt>, whether explicitly, or within page ranges.</p>""")) self.view.pane.clickLine.connect(self.state.updateNavigationStatus)
def make_tool_button(filename): res_path = os.path.join(resource_dir, filename) if filename not in resources_cache: if not os.path.exists(res_path): raise Exception("Can't find resource {}".format(res_path)) pixmap = QPixmap(res_path) icon = QIcon(pixmap) resources_cache[filename] = (pixmap, icon) pixmap, icon = resources_cache[filename] b = QToolButton() b.setIcon(icon) b.setIconSize(pixmap.rect().size()) b.setMaximumWidth(pixmap.rect().width() + 6) return b
def setup_ui(self): main_layout = QHBoxLayout(self) edt = QLineEdit(self) edt.setPlaceholderText("Wildcard filter") btn = QToolButton(self) btn.clicked.connect(self.set_icon) layout = QHBoxLayout(self) layout.addWidget(edt) layout.addWidget(btn) layout2 = QVBoxLayout() layout2.addLayout(layout) model = TListModel(self) proxy = QSortFilterProxyModel(self) proxy.setFilterCaseSensitivity(Qt.CaseInsensitive) proxy.setSourceModel(model) edt.textChanged.connect(proxy.setFilterWildcard) list = QListView() list.setModel(proxy) selection_model = list.selectionModel() selection_model.currentChanged.connect(self.currentChanged) layout2.addWidget(list) main_layout.addLayout(layout2) image = QLabel("Select icon", self) image.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter) image.setMinimumWidth(256) main_layout.addWidget(image) self.btn = btn self.edt = edt self.image = image self.list = list self.proxy = proxy self.model = model self.selection_model = selection_model
def createWidgets(self): self.indexLabel = QLabel("&Index ") self.view = Views.All.View(self.state) self.tooltips.append((self.view, """ <p><b>Index view</b> (Alt+I)</p> <p>This view shows all the index's entries.</p> <p>The entries are always shown in the correct order in accordance with the the chosen <b>Index→Options, Rules, Calculate Sort As Rules</b>, so there's never a need to explicitly sort.</p>""")) self.indexLabel.setBuddy(self.view) self.gotoLabel = QLabel("Goto <font color=darkgreen>(Ctrl+T)</font>") self.gotoLineEdit = SelectAllLineEdit() self.gotoLabel.setBuddy(self.gotoLineEdit) self.tooltips.append((self.gotoLineEdit, """ <p><b>Goto (Ctrl+T)</b></p> <p>Enter a few initial letters to goto the first main entry whose term begins with those letters.</p>""")) self.state.editors.add(self.gotoLineEdit) self.helpButton = QToolButton() self.helpButton.setIcon(QIcon(":/help.svg")) self.helpButton.setFocusPolicy(Qt.NoFocus)
def setupUi(self): scene = QGraphicsScene(self) self.view = QGraphicsView(scene, self) self.view.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.view.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.view.setVisible(True) self.view.setInteractive(True) self.createPixmapIcon() self.mapWidget = MapWidget(self.mapManager) scene.addItem(self.mapWidget) self.mapWidget.setCenter(QGeoCoordinate(-8.1, -34.95)) self.mapWidget.setZoomLevel(5) #... self.slider = QSlider(Qt.Vertical, self) self.slider.setTickInterval(1) self.slider.setTickPosition(QSlider.TicksBothSides) self.slider.setMaximum(self.mapManager.maximumZoomLevel()) self.slider.setMinimum(self.mapManager.minimumZoomLevel()) self.slider.valueChanged[int].connect(self.sliderValueChanged) self.mapWidget.zoomLevelChanged[float].connect(self.mapZoomLevelChanged) mapControlLayout = QVBoxLayout() self.mapWidget.mapTypeChanged.connect(self.mapTypeChanged) for mapType in self.mapWidget.supportedMapTypes(): radio = QRadioButton(self) if mapType == QGraphicsGeoMap.StreetMap: radio.setText('Street') elif mapType == QGraphicsGeoMap.SatelliteMapDay: radio.setText('Sattelite') elif mapType == QGraphicsGeoMap.SatelliteMapNight: radio.setText('Sattelite - Night') elif mapType == QGraphicsGeoMap.TerrainMap: radio.setText('Terrain') if mapType == self.mapWidget.mapType(): radio.setChecked(True) radio.toggled[bool].connect(self.mapTypeToggled) self.mapControlButtons.append(radio) self.mapControlTypes.append(mapType) mapControlLayout.addWidget(radio) self.latitudeEdit = QLineEdit() self.longitudeEdit = QLineEdit() formLayout = QFormLayout() formLayout.addRow('Latitude', self.latitudeEdit) formLayout.addRow('Longitude', self.longitudeEdit) self.captureCoordsButton = QToolButton() self.captureCoordsButton.setText('Capture coordinates') self.captureCoordsButton.setCheckable(True) self.captureCoordsButton.toggled[bool].connect( self.mapWidget.setMouseClickCoordQuery) self.mapWidget.coordQueryResult.connect(self.updateCoords) self.setCoordsButton = QPushButton() self.setCoordsButton.setText('Set coordinates') self.setCoordsButton.clicked.connect(self.setCoordsClicked) buttonLayout = QHBoxLayout() buttonLayout.addWidget(self.captureCoordsButton) buttonLayout.addWidget(self.setCoordsButton) coordControlLayout = QVBoxLayout() coordControlLayout.addLayout(formLayout) coordControlLayout.addLayout(buttonLayout) widget = QWidget(self) layout = QGridLayout() layout.setRowStretch(0, 1) layout.setRowStretch(1, 0) topLayout = QGridLayout() bottomLayout = QGridLayout() topLayout.setColumnStretch(0, 0) topLayout.setColumnStretch(1, 1) bottomLayout.setColumnStretch(0, 0) bottomLayout.setColumnStretch(1, 1) topLayout.addWidget(self.slider, 0, 0) topLayout.addWidget(self.view, 0, 1) bottomLayout.addLayout(mapControlLayout, 0, 0) bottomLayout.addLayout(coordControlLayout, 0, 1) layout.addLayout(topLayout, 0, 0) layout.addLayout(bottomLayout, 1, 0) self.layout = layout widget.setLayout(layout) self.setCentralWidget(widget) self.view.setContextMenuPolicy(Qt.CustomContextMenu) self.view.customContextMenuRequested.connect(self.customContextMenuRequest)
def createWidgets(self): self.helpButton = QToolButton() self.helpButton.setIcon(QIcon(":/help.svg")) self.helpButton.setFocusPolicy(Qt.NoFocus) self.tooltips.append((self.helpButton, "Help on the Entry panel.")) self.addingLabel = Widgets.Label.HtmlLabel(CANCEL_ADD) self.addingLabel.hide() self.termLabel = QLabel("&Term") self.termEdit = Widgets.LineEdit.HtmlLineEdit(self.state) self.tooltips.append((self.termEdit, """\ <p><b>Term editor</b> (Alt+T)</p> <p>The entry's term text styled (e.g., <b>bold</b>, <i>italic</i>), as it should appear in the final index.</p>""")) self.spellHighlighter = Widgets.SpellHighlighter.Highlighter( self.state, self.termEdit.document()) self.termLabel.setBuddy(self.termEdit) self.pagesLabel = QLabel("&Pages") self.pagesEdit = Widgets.LineEdit.HtmlPagesLineEdit(self.state, maxLines=3) self.tooltips.append((self.pagesEdit, """\ <p><b>Pages editor</b> (Alt+P)</p> <p>The entry's pages styled (e.g., <b>bold</b>, <i>italic</i>), as they should appear in the final index.</p> <p>The pages are automatically sorted, and exact duplicates are automatically removed.</p> <p>See also <b>Index→Combine Overlapping Pages</b> and <b>Index→Renumber Pages</b>.</p>""")) self.pagesLabel.setBuddy(self.pagesEdit) self.calcSortAsCheckBox = QCheckBox("&Automatically Calculate Sort As") self.tooltips.append((self.calcSortAsCheckBox, """\ <p><b>Automatically Calculate Sort As</b> (Alt+A)</p> <p>This checkbox controls how the Sort As text is created.</p> <p>If checked, {} will either automatically create the sort as text, or will present some choices from which to choose the sort as text, depending on the term text.</p> <p>If unchecked, the sort as text should be entered manually.</p>""".format(QApplication.applicationName()))) self.calcSortAsCheckBox.setChecked(True) self.sortAsHelpButton = QToolButton() self.sortAsHelpButton.setIcon(QIcon(":/help.svg")) self.sortAsHelpButton.setFocusPolicy(Qt.NoFocus) self.tooltips.append( (self.sortAsHelpButton, "Help on the Sort As text.")) self.sortAsEdit = Widgets.LineEdit.LineEdit(self.state) self.tooltips.append((self.sortAsEdit, """\ <p><b>Sort As editor</b> (Alt+S)</p> <p>The entry's sort as text.</p> <p>If the <b>Automatically Calculate Sort As</b> checkbox is unchecked, manually enter the sort as text to use for sorting the entry.</p> <p>Main entry's are sorted using the sort as text, so it is easy to force a non-standard ordering by entering a custom sort as text.</p> <p>Subentries are also sorted using the sort as text, but the first word of a subentry will be ignored for sorting purposes if it is in the Ignore Subentry Function words list (see <b>Index→Ignore Subentry Function words</b>) <i>and</i> the <b>Index→Options, Rules, Ignore Subenty Function Words</b> checkbox is checked for this index.</p>""")) self.sortAsEdit.setEnabled(False) self.sortAsLabel = QLabel("&Sort As") self.sortAsLabel.setBuddy(self.sortAsEdit) self.sortAsLabel.setEnabled(False) self.xrefLabel = QLabel("&Cross-references") self.xrefList = Widgets.List.HtmlListWidget(self.state, minLines=4) self.tooltips.append((self.xrefList, """\ <p><b>Cross-references list</b> (Alt+C)</p> <p>The list of the entry's see and see also cross-references, both generic and to other entries.</p> <p>To add a cross-reference to an entry, circle the <i>to</i> entry (<b>Entry→Circle</b>), then go to the <i>from</i> entry and click <img src=":/xref-add.svg" width={0} height={0}> or press <b>Entry→Add Cross-reference</b> (See also the <b>Entry</b> menu.)</p>""".format(TOOLTIP_IMAGE_SIZE))) self.xrefLabel.setBuddy(self.xrefList) self.notesLabel = QLabel("&Notes") self.notesEdit = Widgets.LineEdit.MultilineHtmlEdit(self.state) self.tooltips.append((self.notesEdit, """\ <p><b>Notes editor</b> (Alt+N)</p> <p>The entry's notes.</p> <p>The notes shown here are never output as part of the index so may be freely used for any purpose.</p> <p>If the notes facility isn't wanted, the notes can be hidden by unchecking the <b>Index→Options, General, Show Notes</b> checkbox.</p>""")) self.notesLabel.setBuddy(self.notesEdit)
def createWidgets(self): settings = QSettings() self.searchLabel = QLabel("Search For") self.searchLineEdit = QLineEdit() self.tooltips.append((self.searchLineEdit, """\ <p><b>Search For editor</b></p> <p>The text or regular expression to search for.</p>""")) self.searchLabel.setBuddy(self.searchLineEdit) self.replaceLabel = QLabel("Replace With") self.replaceLineEdit = QLineEdit() self.tooltips.append((self.replaceLineEdit, """\ <p><b>Replace With editor</b></p> <p>The replacement text (which may include backreferences, \\1, \\2, etc., if a regular expression search is being made).</p>""")) self.replaceLabel.setBuddy(self.replaceLineEdit) self.allEntriesRadioButton = QRadioButton("All Entries") self.allEntriesRadioButton.setChecked( bool(int(settings.value("RP/All", 1)))) self.tooltips.append((self.allEntriesRadioButton, """\ <p><b>All Entries</b></p> <p>If checked, the search will consider every entry in the index.</p>""")) self.filteredEntriesRadioButton = QRadioButton("Filtered Entries") self.filteredEntriesRadioButton.setChecked( bool(int(settings.value("RP/Filtered", 0)))) self.tooltips.append((self.filteredEntriesRadioButton, """\ <p><b>Filtered Entries</b></p> <p>If checked, the search will consider only those entries that are in the current filtered view.</p>""")) self.considerLabel = QLabel("Consider") self.scopeGroup = QButtonGroup() self.scopeGroup.addButton(self.allEntriesRadioButton) self.scopeGroup.addButton(self.filteredEntriesRadioButton) self.literalRadioButton = QRadioButton("Literal") self.literalRadioButton.setChecked( bool(int(settings.value("RP/Literal", 1)))) self.tooltips.append((self.literalRadioButton, """<p><b>Literal</b></p> <p>If checked, the <b>Search For</b> text will be searched for literally.</p>""")) self.regexRadioButton = QRadioButton("Regex") self.regexRadioButton.setChecked( bool(int(settings.value("RP/Regex", 0)))) self.tooltips.append((self.regexRadioButton, """<p><b>Regex</b></p> <p>If checked, the <b>Search For</b> text will be searched for as a regular expression pattern.</p>""")) self.matchAsGroup = QButtonGroup() self.matchAsGroup.addButton(self.literalRadioButton) self.matchAsGroup.addButton(self.regexRadioButton) self.ignoreCaseCheckBox = QCheckBox("Ignore Case") self.ignoreCaseCheckBox.setChecked( bool(int(settings.value("RP/ICase", 0)))) self.tooltips.append((self.ignoreCaseCheckBox, """\ <p><b>Ignore Case</b></p> <p>If checked, the <b>Search For</b> text will be searched for case-insensitively.</p>""")) self.wholeWordsCheckBox = QCheckBox("Whole Words") self.wholeWordsCheckBox.setChecked( bool(int(settings.value("RP/WW", 0)))) self.tooltips.append((self.wholeWordsCheckBox, """\ <p><b>Whole Words</b></p> <p>If checked—and when <b>Literal</b> is checked—the <b>Search For</b> text will be matched as whole words.</p> <p>For example, “habit” will not match “habitat” when whole words is checked.</p> <p>(For regular expressions use \\b before and after each word to get whole word matches.)</p>""")) self.replaceInLabel = QLabel("Look In") self.replaceInTermsCheckBox = QCheckBox("Terms") self.replaceInTermsCheckBox.setChecked( bool(int(settings.value("RP/Terms", 1)))) self.tooltips.append((self.replaceInTermsCheckBox, """\ <p><b>Terms</b></p> <p>If checked, the search will look in term texts.</p>""")) self.replaceInPagesCheckBox = QCheckBox("Pages") self.replaceInPagesCheckBox.setChecked( bool(int(settings.value("RP/Pages", 0)))) self.tooltips.append((self.replaceInPagesCheckBox, """\ <p><b>Pages</b></p> <p>If checked, the search will look in pages texts.</p>""")) self.replaceInNotesCheckBox = QCheckBox("Notes") self.replaceInNotesCheckBox.setChecked( bool(int(settings.value("RP/Notes", 0)))) self.tooltips.append((self.replaceInNotesCheckBox, """\ <p><b>Notes</b></p> <p>If checked, the search will look in notes texts.</p>""")) self.startButton = QPushButton(QIcon(":/edit-find.svg"), "Start Search") self.tooltips.append((self.startButton, """<p><b>Start Search</b></p> <p>Start the search from the first entry in the index or the first entry in the filtered view's entries.</p>""")) self.replaceButton = QPushButton(QIcon(":/edit-find-replace.svg"), "Replace") self.tooltips.append((self.replaceButton, """<p><b>Replace</b></p> <p>Replace the highlighted text with the <b>Replace With</b> text (using backreferences if they are in the replacement text and a <b>Regex</b> search is underway), and then try to find the next matching text.</p>""")) self.skipButton = QPushButton(QIcon(":/skip.svg"), "S&kip") self.tooltips.append((self.skipButton, """<p><b>Skip</b></p> <p>Skip the highlighted text and try to find the next matching text.</p>""")) self.stopButton = QPushButton(QIcon(":/process-stop.svg"), "Stop Search") self.tooltips.append((self.stopButton, """<p><b>Stop Search</b></p> <p>Stop the current search. This allows the search options to be changed.</p>""")) self.closeButton = QToolButton() self.closeButton.setIcon(QIcon(":/hide.svg")) self.closeButton.setFocusPolicy(Qt.NoFocus) self.tooltips.append((self.closeButton, """<p><b>Hide</b></p> <p>Hide the Search and Replace panel.</p> <p>Press <b>Ctrl+H</b> or click <img src=":/edit-find-replace.svg" width={0} height={0}> or click <b>Edit→Search and Replace</b> to show it again.</p>""".format(TOOLTIP_IMAGE_SIZE))) self.helpButton = QToolButton() self.helpButton.setIcon(QIcon(":/help.svg")) self.helpButton.setFocusPolicy(Qt.NoFocus) self.tooltips.append( (self.helpButton, "Help on the Search and Replace panel."))
def createActions(self): self.fileActions = Actions.File.Actions(self) self.fileMenu = self.menuBar().addMenu("&File") Lib.addActions(self.fileMenu, self.fileActions.forMenu()) self.fileToolBar = self.addToolBar("File") self.fileToolBar.setObjectName("File") Lib.addActions(self.fileToolBar, self.fileActions.forToolbar()) self.editActions = Actions.Edit.Actions(self) self.editMenu = self.menuBar().addMenu("&Edit") Lib.addActions(self.editMenu, self.editActions.forMenu()) self.editToolBar = self.addToolBar("Edit") self.editToolBar.setObjectName("Edit") Lib.addActions(self.editToolBar, self.editActions.forToolbar()) self.insertActions = Actions.Insert.Actions(self) self.insertMenu = self.menuBar().addMenu("Inse&rt") Lib.addActions(self.insertMenu, self.insertActions.forMenu()) self.spellingActions = Actions.Spelling.Actions(self) self.spellingMenu = self.menuBar().addMenu("Spe&lling") Lib.addActions(self.spellingMenu, self.spellingActions.forMenu()) self.spellingToolBar = self.addToolBar("Spelling") self.spellingToolBar.setObjectName("Spelling") Lib.addActions(self.spellingToolBar, self.spellingActions.forToolbar()) self.formatActions = Actions.Format.Actions(self) self.formatMenu = self.menuBar().addMenu("F&ormat") Lib.addActions(self.formatMenu, self.formatActions.forMenu()) self.formatToolBar = self.addToolBar("Format") self.formatToolBar.setObjectName("Format") Lib.addActions(self.formatToolBar, self.formatActions.forToolbar()) self.addToolBarBreak() # Actions created earlier self.indexActions = Actions.Index.Actions(self) # Menu added later self.indexToolBar = self.addToolBar("Index") self.indexToolBar.setObjectName("Index") Lib.addActions(self.indexToolBar, self.indexActions.forToolbar()) self.gotoActions = Actions.Goto.Actions(self) self.gotoMenu = self.menuBar().addMenu("&Goto") Lib.addActions(self.gotoMenu, self.gotoActions.forMenu()) # Goto toolbar is last # These actions are created in createWidgets() because two are # needed by the groups panel self.entryMenu = self.menuBar().addMenu("Entr&y") Lib.addActions(self.entryMenu, self.entryActions.forMenu()) self.entryToolBar1 = self.addToolBar("Entry Add and Copy") self.entryToolBar1.setObjectName("Entry1") Lib.addActions(self.entryToolBar1, self.entryActions.forToolbar1()) self.entryToolBar2 = self.addToolBar("Entry Cross-references") self.entryToolBar2.setObjectName("Entry2") Lib.addActions(self.entryToolBar2, self.entryActions.forToolbar2()) self.entryToolBar3 = self.addToolBar("Entry Groups") self.entryToolBar3.setObjectName("Entry3") Lib.addActions(self.entryToolBar3, self.entryActions.forToolbar3()) self.modifyActions = Actions.Modify.Actions(self) self.modifyMenu = self.menuBar().addMenu("&Modify") Lib.addActions(self.modifyMenu, self.modifyActions.forMenu()) self.modifyToolBar = self.addToolBar("Modify") self.modifyToolBar.setObjectName("Modify") Lib.addActions(self.modifyToolBar, self.modifyActions.forToolbar()) self.indexMenu = self.menuBar().addMenu("Inde&x") Lib.addActions(self.indexMenu, self.indexActions.forMenu()) self.helpActions = Actions.Help.Actions(self) self.helpMenu = self.menuBar().addMenu("&Help") Lib.addActions(self.helpMenu, self.helpActions.forMenu()) self.addToolBarBreak() self.gotoToolBar1 = self.addToolBar("Goto Filtered etc.") self.gotoToolBar1.setObjectName("Goto1") Lib.addActions(self.gotoToolBar1, self.gotoActions.forToolbar1()) self.gotoToolBar2 = self.addToolBar("Goto First, Next, etc.") self.gotoToolBar2.setObjectName("Goto2") Lib.addActions(self.gotoToolBar2, self.gotoActions.forToolbar2()) self.gotoToolBar4 = Widgets.AlphaBar.Bar() self.gotoToolBar4.setWindowTitle("Goto Letter") self.gotoToolBar4.setObjectName("Goto4") self.addToolBar(self.gotoToolBar4) self.gotoToolBar3 = self.addToolBar("Goto Bookmarks") self.gotoToolBar3.setObjectName("Goto3") Lib.addActions(self.gotoToolBar3, self.gotoActions.forToolbar3()) self.bookmarksToolButton = QToolButton() self.bookmarksToolButton.setIcon(QIcon(":/bookmark.svg")) self.bookmarksToolButton.setPopupMode(QToolButton.InstantPopup) self.bookmarksToolButton.setToolTip("""\ <p><b>Goto→Bookmarks</b></p><p>Goto the bookmarked entry.""") self.gotoToolBar3.addWidget(self.bookmarksToolButton) for toolbar in (self.fileToolBar, self.editToolBar, self.spellingToolBar, self.formatToolBar, self.indexToolBar, self.entryToolBar1, self.entryToolBar2, self.modifyToolBar, self.gotoToolBar1, self.gotoToolBar2, self.gotoToolBar4, self.gotoToolBar3): toolbar.setFloatable(False)
def __init__(self, parent=None, filePath=''): """Default class constructor.""" super(MDISubWindow_TextEdit, self).__init__(parent) print(filePath) self.filePath = filePath self.fileName = os.path.basename(os.path.abspath(filePath)) self.fileExt = os.path.splitext(self.fileName)[1] if not filePath: self.setWindowTitle('Untitled[*]') parent.setWindowIcon(QIcon(gIconDir + os.sep + 'new.png')) else: f = open(filePath, 'r') txt = f.read() f.close() self.setText(txt) self.setWindowTitle('%s[*]' % self.fileName) # TODO: This is changing all the subwindows icons. We want individual icons based on filetype...? if self.fileExt in ('.py', '.pyw'): parent.setWindowIcon(QIcon(gIconDir + os.sep + 'pyscript.png')) else: parent.setWindowIcon(QIcon(gIconDir + os.sep + 'new.png')) monoFont = QFont('Courier New') monoFont.setFixedPitch(True) self.setFont(monoFont) self.setWordWrapMode(QTextOption.NoWrap) ## self.setTextBackgroundColor(QColor('#000000')) ## self.setTextColor(QColor('#FFFFFF')) self.setCursorWidth(2) self.CreateActions() self.zoomLevel = 0 gMainWin.action_Edit_Cut.setEnabled(False) gMainWin.action_Edit_Copy.setEnabled(False) self.copyAvailable.connect(gMainWin.action_Edit_Cut.setEnabled) self.copyAvailable.connect(gMainWin.action_Edit_Copy.setEnabled) # Handle the Context Menu Entries Also. self.action_Edit_Undo.setEnabled(False) self.action_Edit_Redo.setEnabled(False) self.action_Edit_Cut.setEnabled(False) self.action_Edit_Copy.setEnabled(False) self.undoAvailable.connect(self.action_Edit_Undo.setEnabled) self.redoAvailable.connect(self.action_Edit_Redo.setEnabled) self.copyAvailable.connect(self.action_Edit_Cut.setEnabled) self.copyAvailable.connect(self.action_Edit_Copy.setEnabled) self.document().contentsChanged.connect(self.TheDocumentWasModified) # self.show() # self.showMaximized() # self.setFocusPolicy(Qt.WheelFocus) ##### self.setFocus() # This makes the MDIArea go into SubWindowView...? self.gCornerWidget = QToolButton(self) # self.gCornerWidgetToolTip = QToolTip() QToolTip.setFont(QFont('SansSerif', 10)) br = QBrush(QPixmap(gImgDir + os.sep + 'texture-spirals.png')) pal = QPalette() # pal.setBrush(QPalette.Active, QPalette.Base, br) # pal.setColor(QPalette.Background, QColor('#FF8000')) pal.setColor(QPalette.ColorGroup.Inactive, QPalette.ColorRole.ToolTipBase, QColor(EMBROIDERBLUE2)) QToolTip.setPalette(QPalette(pal)) self.action_Edit_SelectAll.setToolTip( 'This is a <b>QWidget</b> widget') self.gCornerWidget.setDefaultAction(self.action_Edit_SelectAll) self.setCornerWidget(self.gCornerWidget) # We want to show the corner widget no matter what so... self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn) self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)