def __add_checkBox(self, key, name): """this is a helper method to create a QCheckBox it adds the created widget (as a TitledWidget) to the layout and register a setter and listen to changes """ checkBox = QtWidgets.QCheckBox() self.setters[key] = ( lambda val, check=checkBox: check.setCheckState(val == "yes")) checkBox.stateChanged.connect(lambda state, key=key: self.__update( key, "yes" if state else "no")) self.layout.addWidget(TitledWidget(name, checkBox))
def __init__(self, parent=None): QtWidgets.QDialog.__init__(self, parent) self.setWindowTitle("Install miniconda") self.setModal(True) self.resize(500, 500) text = translate( "bootstrapconda", "This will download and install miniconda on your computer.", ) self._label = QtWidgets.QLabel(text, self) self._scipystack = QtWidgets.QCheckBox( translate("bootstrapconda", "Also install scientific packages"), self ) self._scipystack.setChecked(True) self._path = QtWidgets.QLineEdit(default_conda_dir, self) self._progress = QtWidgets.QProgressBar(self) self._outputLine = QtWidgets.QLabel(self) self._output = QtWidgets.QPlainTextEdit(self) self._output.setReadOnly(True) self._button = QtWidgets.QPushButton("Install", self) self._outputLine.setSizePolicy( QtWidgets.QSizePolicy.Ignored, QtWidgets.QSizePolicy.Fixed ) vbox = QtWidgets.QVBoxLayout(self) self.setLayout(vbox) vbox.addWidget(self._label, 0) vbox.addWidget(self._path, 0) vbox.addWidget(self._scipystack, 0) vbox.addWidget(self._progress, 0) vbox.addWidget(self._outputLine, 0) vbox.addWidget(self._output, 1) vbox.addWidget(self._button, 0) self._button.clicked.connect(self.go) self.addOutput(translate("bootstrapconda", "Waiting to start installation.\n")) self._progress.setVisible(False) self.lineFromStdOut.connect(self.setStatus)
def __init__(self, parent, widget): # Do not pass parent, because is a sublayout QtWidgets.QVBoxLayout.__init__(self) # Layout self.setSpacing(1) self.addWidget(widget) # Create checkbox widget if not self.DISABLE_SYSTEM_DEFAULT: t = translate('shell', 'Use system default') self._check = QtWidgets.QCheckBox(t, parent) self._check.stateChanged.connect(self.onCheckChanged) self.addWidget(self._check) # The actual value of this shell config attribute self._value = '' # A buffered version, so that clicking the text box does not # remove the value at once self._bufferedValue = ''
def __init__(self): super().__init__() from pyzo.util.qt import QtPrintSupport self.printer = QtPrintSupport.QPrinter( QtPrintSupport.QPrinter.HighResolution, ) # To allow pdf export with color self.printer.setColorMode(QtPrintSupport.QPrinter.Color) # Default settings self.show_line_number = True self._enable_syntax_highlighting = True m = QtWidgets.QMessageBox(self) # Set title self.setWindowTitle(translate("menu dialog", 'Pdf Export')) # Set dialog size size = 1000, 600 offset = 0 size2 = size[0], size[1] + offset self.resize(*size2) # self.setMinimumSize(*size2) # Button to export to pdf self.validation_button = QtWidgets.QPushButton("Export") self.validation_button.clicked.connect(self._export_pdf) # Button to update the preview self.button_update_preview = QtWidgets.QPushButton( 'Update preview', self) self.button_update_preview.clicked.connect(self._update_preview) # Previw widget self.preview = QtPrintSupport.QPrintPreviewWidget(self.printer) # Lines numbers option self.checkbox_line_number = QtWidgets.QCheckBox( "Print line number", self, checked=self.show_line_number) self.checkbox_line_number.stateChanged.connect( self._get_show_line_number) # Make of copy of the editor self.current_editor = pyzo.editors.getCurrentEditor() self.editor_name = self.current_editor.name self.editor_filename = self.current_editor.filename self.editor = pyzo.core.editor.PyzoEditor( pyzo.editors.getCurrentEditor().toPlainText()) # Zoom # The default zoom is the current zoom used by the editor self.original_zoom = pyzo.config.view.zoom self.zoom_slider = QtWidgets.QSlider(QtCore.Qt.Horizontal) self.zoom_slider.setMinimum(-10) # Maybe too much ? self.zoom_slider.setMaximum(10) self.zoom_slider.setTickInterval(1) self.zoom_selected = self.original_zoom self.zoom_slider.setValue(self.zoom_selected) self.zoom_value_label = QtWidgets.QLabel() self._zoom_value_changed() self.zoom_slider.valueChanged.connect(self._zoom_value_changed) # Option for syntax highlighting self.checkbox_syntax_highlighting = QtWidgets.QCheckBox( "Enable syntax highlighting", self, checked=self._enable_syntax_highlighting) self.checkbox_syntax_highlighting.stateChanged.connect( self._change_syntax_highlighting_option) self.combobox_file_name = QtWidgets.QComboBox(self) self.combobox_file_name.addItem("Do not print the file name", 0) self.combobox_file_name.addItem("Print with file name", 1) self.combobox_file_name.addItem( "Print with file name and absolute path", 2) self.combobox_file_name.setCurrentIndex(1) self.combobox_file_name.setToolTip( "The title at the top of the document") # Orientation self.combobox_orientation = QtWidgets.QComboBox(self) self.combobox_orientation.addItem("Portrait", QtPrintSupport.QPrinter.Portrait) self.combobox_orientation.addItem("Landscape", QtPrintSupport.QPrinter.Landscape) self.combobox_orientation.setToolTip("Orientation of the document") # Layout self.main_layout = QtWidgets.QHBoxLayout() self.setLayout(self.main_layout) self.preview.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) self.right_layout = QtWidgets.QVBoxLayout() self.option_layout = QtWidgets.QFormLayout() self.main_layout.addWidget(self.preview) self.main_layout.addLayout(self.right_layout) self.right_layout.addLayout(self.option_layout) self.option_layout.addRow(self.combobox_file_name) self.option_layout.addRow(self.checkbox_line_number) self.option_layout.addRow(self.checkbox_syntax_highlighting) self.option_layout.addRow(self.zoom_value_label, self.zoom_slider) self.option_layout.addRow(self.combobox_orientation) self.bottom_layout = QtWidgets.QHBoxLayout() self.right_layout.addLayout(self.bottom_layout) self.bottom_layout.addStretch() self.bottom_layout.addWidget(self.button_update_preview) self.bottom_layout.addWidget(self.validation_button) self._update_preview()
def __init__(self, parent): QtWidgets.QWidget.__init__(self, parent) # Make sure there is a configuration entry for this tool # The pyzo tool manager makes sure that there is an entry in # config.tools before the tool is instantiated. toolId = self.__class__.__name__.lower() self._config = pyzo.config.tools[toolId] # Set config if not hasattr(self._config, "hideTypes"): self._config.hideTypes = [] # if not hasattr(self._config, "fontSizeTree"): if sys.platform == "darwin": self._config.fontSizeTree = 12 else: self._config.fontSizeTree = 10 if not hasattr(self._config, "fontSizeHelp"): if sys.platform == "darwin": self._config.fontSizeHelp = 12 else: self._config.fontSizeHelp = 10 # if not hasattr(self._config, "historyMaximum"): self._config.historyMaximum = 10 # if not hasattr(self._config, "historyFreeze"): # self._config.historyFreeze = 0 if not hasattr(self._config, "historyClearOnStartup"): self._config.historyClearOnStartup = 1 style = QtWidgets.qApp.style() # self.initText = "<p>{}</p>".format( "Click an item in the list for Help information.") # Create empty label self._empty = QtWidgets.QLabel(self) self._empty.setText("") # ----- Layout 1 ----- # Create Home tool button self._home = QtWidgets.QToolButton(self) self._home.setIcon(style.standardIcon(style.SP_ArrowUp)) self._home.setIconSize(QtCore.QSize(16, 16)) self._home.setToolTip("Home - return to the beginninig.") # Create Refresh tool button self._refresh = QtWidgets.QToolButton(self) self._refresh.setIcon(style.standardIcon(style.SP_BrowserReload)) self._refresh.setIconSize(QtCore.QSize(16, 16)) self._refresh.setToolTip("Reload the current command.") # Create Go back tool button self.back = QtWidgets.QToolButton(self) self.back.setIcon(style.standardIcon(style.SP_ArrowLeft)) self.back.setIconSize(QtCore.QSize(16, 16)) self.back.setToolTip("Go back to the previous command.") # Create "path" line edit self._line = QtWidgets.QLineEdit(self) self._line.setReadOnly(True) self._line.setStyleSheet("QLineEdit { background:#ddd; }") self._line.setFocusPolicy(QtCore.Qt.NoFocus) # Create selection tool button self._selection = QtWidgets.QToolButton(self) self._selection.setIcon(pyzo.icons.layout) self._selection.setIconSize(QtCore.QSize(16, 16)) self._selection.setToolTip("Get selected objects in the document.") self._selection.setEnabled(False) # Create "insert_code" button self._insert_code = QtWidgets.QToolButton(self) self._insert_code.setIcon( style.standardIcon(style.SP_FileDialogDetailedView)) self._insert_code.setToolTip( "Insert code in the script at the cursor position") # ----- Layout 2 ----- # Create element_index combo box self._element_index = QtWidgets.QComboBox(self) self._element_index.setToolTip( "Set the argument for getByIndex method.") self._element_index.setEnabled(False) # Create element_names combo box self._element_names = QtWidgets.QComboBox(self) self._element_names.setToolTip("Get by name") self._element_names.setEnabled(False) # Create enumerate combo box self._enumerate_index = QtWidgets.QComboBox(self) self._enumerate_index.setToolTip( "Objects enumerated by createEnumeration method") self._enumerate_index.setEnabled(False) # Create history combo box self._history = QtWidgets.QComboBox(self) self._history.setToolTip("Show the command history") self._history.setEnabled(True) # Create options menu self._options = QtWidgets.QToolButton(self) self._options.setToolTip("Tool configuration.") self._options.setIcon(pyzo.icons.filter) self._options.setIconSize(QtCore.QSize(16, 16)) self._options.setPopupMode(self._options.InstantPopup) self._options.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon) # main menu self._options._menu = pyzo.core.menu.Menu( self, "Main menu") # QtWidgets.QMenu() # submenus self._show_hide_menu = pyzo.core.menu.Menu(None, "Show/Hide") # self._font_size_menu = pyzo.core.menu.Menu(None, "Font size") self._font_size_tree_menu = pyzo.core.menu.Menu(None, "Workspace") self._font_size_help_menu = pyzo.core.menu.Menu(None, "Help") # self._history_menu = pyzo.core.menu.Menu(None, "History") # create menu self._options.setMenu(self._options._menu) self.onOptionsPress() # Show/hide Help button self._btn_toggle = QtWidgets.QToolButton(self) self._btn_toggle.setToolTip("Show/hide help") self._btn_toggle.setIcon(style.standardIcon(style.SP_DialogHelpButton)) self._btn_toggle.setIconSize(QtCore.QSize(16, 16)) self._btn_toggle.setCheckable(True) self._btn_toggle.setChecked(False) # ----- Layout 3 ----- # Create tree self._tree = PyUNOWorkspaceTree(self) # Create message for when tree is empty self._initText = QtWidgets.QLabel( pyzo.translate( "pyzoWorkspace", """Lists the variables in the current shell's namespace. Currently, there are none. Some of them may be hidden because of the filters you configured.""", ), self, ) self._initText.setVisible(False) self._initText.setWordWrap(True) # ----- Layout 4 ----- # Create description widget self._description = QtWidgets.QTextBrowser(self) self._description.setText(self.initText) # ----- Layout 5 ----- # Create counter self._desc_counter = QtWidgets.QLabel(self) self._desc_counter.setText("0") # Label self._desc_of = QtWidgets.QLabel(self) self._desc_of.setText(" of ") # Create all items counter self._desc_all_items = QtWidgets.QLabel(self) self._desc_all_items.setText("0") # self._search_line = QtWidgets.QLineEdit(self) self._search_line.setReadOnly(False) self._search_line.setToolTip("Search") self._search_line.setPlaceholderText("UNO API Search...") # self._match = QtWidgets.QCheckBox(self) self._match.setText("Match") self._match.setChecked(True) self._match.setToolTip("Match") # self._search = QtWidgets.QToolButton(self) self._search.setIconSize(QtCore.QSize(16, 16)) self._search.setText("Search") self._search.setToolTip("Search") # self._clear = QtWidgets.QToolButton(self) self._clear.setIconSize(QtCore.QSize(16, 16)) self._clear.setText("Clear") self._clear.setToolTip("Clear") # ------ Set layouts # Layout 1: Object and insert code layout layout_1 = QtWidgets.QHBoxLayout() layout_1.addWidget(self._home, 0) layout_1.addWidget(self._refresh, 0) layout_1.addWidget(self.back, 0) layout_1.addWidget(self._line, 1) layout_1.addWidget(self._selection, 0) layout_1.addWidget(self._insert_code, 0) # Layout 2: Display, arguments, history and option layout layout_2 = QtWidgets.QHBoxLayout() layout_2.addWidget(self._element_index, 0) layout_2.addWidget(self._element_names, 0) layout_2.addWidget(self._enumerate_index, 0) layout_2.addWidget(self._history, 1) layout_2.addWidget(self._options, 0) layout_2.addWidget(self._btn_toggle, 0) # Layout 3: Tree layout layout_3 = QtWidgets.QVBoxLayout() layout_3.addWidget(self._tree, 0) # Layout 5: Hidden help layout self._description_widget = QtWidgets.QWidget(self) self._description_widget.setVisible(False) layout_5 = QtWidgets.QVBoxLayout() layout_5.setSpacing(0) layout_5.setContentsMargins(0, 0, 0, 0) # Layout 6: Search layout layout_6 = QtWidgets.QHBoxLayout() layout_6.addWidget(self._desc_counter, 0) layout_6.addWidget(self._desc_of, 0) layout_6.addWidget(self._desc_all_items, 0) layout_6.addWidget(self._empty, 0) layout_6.addWidget(self._search_line, 0) layout_6.addWidget(self._empty, 0) layout_6.addWidget(self._match, 0) layout_6.addWidget(self._search, 0) layout_6.addWidget(self._clear, 0) # Layout 7: Help description layout layout_7 = QtWidgets.QVBoxLayout() layout_7.addWidget(self._description, 0) layout_5.addLayout(layout_7, 0) layout_5.addLayout(layout_6, 0) layout_7.setSpacing(0) layout_7.setContentsMargins(0, 0, 0, 0) # Main Layout mainLayout = QtWidgets.QVBoxLayout(self) mainLayout.addLayout(layout_1, 0) mainLayout.addLayout(layout_2, 0) mainLayout.addLayout(layout_3, 0) # add hidden widget mainLayout.addWidget(self._description_widget) self._description_widget.setLayout(layout_5) # set margins mainLayout.setContentsMargins(0, 0, 0, 0) self.setLayout(mainLayout) # ------ Bind events self._home.pressed.connect(self.onHomePress) self._refresh.pressed.connect(self.onRefreshPress) self.back.pressed.connect(self.onBackPress) # self._selection.pressed.connect(self.onCurrentSelectionPress) self._insert_code.pressed.connect(self.onInsertCodeInEditorPress) # self._element_names.activated[str].connect(self.onElementNamesPress) self._element_index.activated[str].connect(self.onElementIndexPress) self._enumerate_index.activated[str].connect( self.onEnumerateIndexPress) self._history.activated[str].connect(self.onHistoryPress) # self._options.pressed.connect(self.onOptionsPress) # self._show_hide_menu.triggered.connect(self.onShowHideMenuTiggered) self._font_size_help_menu.triggered.connect( self.onFontHelpOptionMenuTiggered) self._font_size_tree_menu.triggered.connect( self.onFontTreeOptionMenuTiggered) self._history_menu.triggered.connect(self.onHistoryOptionMenuTiggered) # self._btn_toggle.toggled.connect(self.onHelpTogglePress) # self._search.pressed.connect(self.onSearchPress) self._clear.pressed.connect(self.onClearHelpPress) # Create json result file createResultFile(), # Load History if self._config.historyClearOnStartup: #self._config.historyFreeze = 0 createHistoryFile() self.loadHistory()
def __init__(self, *args): QtWidgets.QFrame.__init__(self, *args) self.setFocusPolicy(QtCore.Qt.ClickFocus) # init layout layout = QtWidgets.QHBoxLayout(self) layout.setSpacing(0) self.setLayout(layout) # Create some widgets first to realize a correct tab order self._hidebut = QtWidgets.QToolButton(self) self._findText = QtWidgets.QLineEdit(self) self._replaceText = QtWidgets.QLineEdit(self) if True: # Create sub layouts vsubLayout = QtWidgets.QVBoxLayout() vsubLayout.setSpacing(0) layout.addLayout(vsubLayout, 0) # Add button self._hidebut.setFont(QtGui.QFont('helvetica', 7)) self._hidebut.setToolTip( translate('search', 'Hide search widget (Escape)')) self._hidebut.setIcon(pyzo.icons.cancel) self._hidebut.setIconSize(QtCore.QSize(16, 16)) vsubLayout.addWidget(self._hidebut, 0) vsubLayout.addStretch(1) layout.addSpacing(10) if True: # Create sub layouts vsubLayout = QtWidgets.QVBoxLayout() hsubLayout = QtWidgets.QHBoxLayout() vsubLayout.setSpacing(0) hsubLayout.setSpacing(0) layout.addLayout(vsubLayout, 0) # Add find text self._findText.setToolTip(translate('search', 'Find pattern')) vsubLayout.addWidget(self._findText, 0) vsubLayout.addLayout(hsubLayout) # Add previous button self._findPrev = QtWidgets.QToolButton(self) t = translate( 'search', 'Previous ::: Find previous occurrence of the pattern.') self._findPrev.setText(t) self._findPrev.setToolTip(t.tt) hsubLayout.addWidget(self._findPrev, 0) hsubLayout.addStretch(1) # Add next button self._findNext = QtWidgets.QToolButton(self) t = translate('search', 'Next ::: Find next occurrence of the pattern.') self._findNext.setText(t) self._findNext.setToolTip(t.tt) #self._findNext.setDefault(True) # Not possible with tool buttons hsubLayout.addWidget(self._findNext, 0) layout.addSpacing(10) if True: # Create sub layouts vsubLayout = QtWidgets.QVBoxLayout() hsubLayout = QtWidgets.QHBoxLayout() vsubLayout.setSpacing(0) hsubLayout.setSpacing(0) layout.addLayout(vsubLayout, 0) # Add replace text self._replaceText.setToolTip(translate('search', 'Replace pattern')) vsubLayout.addWidget(self._replaceText, 0) vsubLayout.addLayout(hsubLayout) # Add replace-all button self._replaceAll = QtWidgets.QToolButton(self) t = translate( 'search', 'Repl. all ::: Replace all matches in current document.') self._replaceAll.setText(t) self._replaceAll.setToolTip(t.tt) hsubLayout.addWidget(self._replaceAll, 0) hsubLayout.addStretch(1) # Add replace button self._replace = QtWidgets.QToolButton(self) t = translate('search', 'Replace ::: Replace this match.') self._replace.setText(t) self._replace.setToolTip(t.tt) hsubLayout.addWidget(self._replace, 0) layout.addSpacing(10) if True: # Create sub layouts vsubLayout = QtWidgets.QVBoxLayout() vsubLayout.setSpacing(0) layout.addLayout(vsubLayout, 0) # Add match-case checkbox t = translate('search', 'Match case ::: Find words that match case.') self._caseCheck = QtWidgets.QCheckBox(t, self) self._caseCheck.setToolTip(t.tt) vsubLayout.addWidget(self._caseCheck, 0) # Add regexp checkbox t = translate('search', 'RegExp ::: Find using regular expressions.') self._regExp = QtWidgets.QCheckBox(t, self) self._regExp.setToolTip(t.tt) vsubLayout.addWidget(self._regExp, 0) if True: # Create sub layouts vsubLayout = QtWidgets.QVBoxLayout() vsubLayout.setSpacing(0) layout.addLayout(vsubLayout, 0) # Add whole-word checkbox t = translate('search', 'Whole words ::: Find only whole words.') self._wholeWord = QtWidgets.QCheckBox(t, self) self._wholeWord.setToolTip(t.tt) self._wholeWord.resize(60, 16) vsubLayout.addWidget(self._wholeWord, 0) # Add autohide dropbox t = translate( 'search', 'Auto hide ::: Hide search/replace when unused for 10 s.') self._autoHide = QtWidgets.QCheckBox(t, self) self._autoHide.setToolTip(t.tt) self._autoHide.resize(60, 16) vsubLayout.addWidget(self._autoHide, 0) layout.addStretch(1) # Set placeholder texts for lineEdit in [self._findText, self._replaceText]: if hasattr(lineEdit, 'setPlaceholderText'): lineEdit.setPlaceholderText(lineEdit.toolTip()) lineEdit.textChanged.connect(self.autoHideTimerReset) # Set focus policy for but in [ self._findPrev, self._findNext, self._replaceAll, self._replace, self._caseCheck, self._wholeWord, self._regExp ]: #but.setFocusPolicy(QtCore.Qt.ClickFocus) but.clicked.connect(self.autoHideTimerReset) # create timer objects self._timerBeginEnd = QtCore.QTimer(self) self._timerBeginEnd.setSingleShot(True) self._timerBeginEnd.timeout.connect(self.resetAppearance) # self._timerAutoHide = QtCore.QTimer(self) self._timerAutoHide.setSingleShot(False) self._timerAutoHide.setInterval(500) # ms self._timerAutoHide.timeout.connect(self.autoHideTimerCallback) self._timerAutoHide_t0 = time.time() self._timerAutoHide.start() # create callbacks self._findText.returnPressed.connect(self.findNext) self._hidebut.clicked.connect(self.hideMe) self._findNext.clicked.connect(self.findNext) self._findPrev.clicked.connect(self.findPrevious) self._replace.clicked.connect(self.replaceOne) self._replaceAll.clicked.connect(self.replaceAll) # self._regExp.stateChanged.connect(self.handleReplacePossible) # init case and regexp self._caseCheck.setChecked(bool(pyzo.config.state.find_matchCase)) self._regExp.setChecked(bool(pyzo.config.state.find_regExp)) self._wholeWord.setChecked(bool(pyzo.config.state.find_wholeWord)) self._autoHide.setChecked(bool(pyzo.config.state.find_autoHide)) # show or hide? if bool(pyzo.config.state.find_show): self.show() else: self.hide()