Exemplo n.º 1
0
    def __init__(self, parent):
        QtWidgets.QWidget.__init__(self, parent)

        # Create text field, checkbox, and button
        self._text = QtWidgets.QLineEdit(self)
        self._printBut = QtWidgets.QPushButton("Print", self)

        # Create options button
        self._options = QtWidgets.QToolButton(self)
        self._options.setIcon(pyzo.icons.wrench)
        self._options.setIconSize(QtCore.QSize(16, 16))
        self._options.setPopupMode(self._options.InstantPopup)
        self._options.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)

        # Create options menu
        self._options._menu = QtWidgets.QMenu()
        self._options.setMenu(self._options._menu)

        # Create browser
        self._browser = QtWidgets.QTextBrowser(self)
        self._browser_text = initText

        # Create two sizers
        self._sizer1 = QtWidgets.QVBoxLayout(self)
        self._sizer2 = QtWidgets.QHBoxLayout()

        # Put the elements together
        self._sizer2.addWidget(self._text, 4)
        self._sizer2.addWidget(self._printBut, 0)
        self._sizer2.addWidget(self._options, 2)
        #
        self._sizer1.addLayout(self._sizer2, 0)
        self._sizer1.addWidget(self._browser, 1)
        #
        self._sizer1.setSpacing(2)
        self._sizer1.setContentsMargins(4, 4, 4, 4)
        self.setLayout(self._sizer1)

        # Set config
        toolId = self.__class__.__name__.lower()
        self._config = config = pyzo.config.tools[toolId]
        #
        if not hasattr(config, 'smartNewlines'):
            config.smartNewlines = True
        if not hasattr(config, 'fontSize'):
            if sys.platform == 'darwin':
                config.fontSize = 12
            else:
                config.fontSize = 10

        # Create callbacks
        self._text.returnPressed.connect(self.queryDoc)
        self._printBut.clicked.connect(self.printDoc)
        #
        self._options.pressed.connect(self.onOptionsPress)
        self._options._menu.triggered.connect(self.onOptionMenuTiggered)

        # Start
        self.setText()  # Set default text
        self.onOptionsPress()  # Fill menu
Exemplo n.º 2
0
 def __init__(self, parent = None):
     super().__init__(parent)
     
     # Widgets
     self._search = QtWidgets.QLineEdit(self)
     self._list = QtWidgets.QListWidget(self)
     
     # Set monospace
     font = self._list.font()
     font.setFamily(pyzo.config.view.fontname)
     self._list.setFont(font)
     
     # Layout
     layout = QtWidgets.QVBoxLayout(self)
     self.setLayout(layout)
     layout.addWidget(self._search, 0)
     layout.addWidget(self._list, 1)
     # set margins
     margin = pyzo.config.view.widgetMargin
     layout.setContentsMargins(margin, margin, margin, margin)
     
     # Customize line edit
     self._search.setPlaceholderText(translate('menu', 'Search'))
     self._search.textChanged.connect(self._on_search)
     
     # Drag/drop
     self._list.setSelectionMode(self._list.ExtendedSelection)
     self._list.setDragEnabled(True)
     self._list.doubleClicked.connect(self._onDoubleClicked)
     
     # Context menu
     self._menu = Menu(self, translate("menu", "History"))
     self._menu.addItem(translate("menu", "Copy ::: Copy selected lines"),
         pyzo.icons.page_white_copy, self.copy, "copy")
     self._menu.addItem(translate("menu", "Run ::: Run selected lines in current shell"),
         pyzo.icons.run_lines, self.runSelection, "run")
     self._menu.addItem(translate("menu", "Remove ::: Remove selected history items(s)"),
         pyzo.icons.delete, self.removeSelection, "remove")
     
     self._list.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
     self._list.customContextMenuRequested.connect(self._onCustomContextMenuRequested)
     
     # Populate
     for command in pyzo.command_history.get_commands():
         self._list.addItem(command)
     
     # Scroll to end of list on start up
     self._list.setCurrentRow(self._list.count()-1)
     item = self._list.currentItem()
     self._list.scrollToItem(item)
     
     # Keep up to date ...
     pyzo.command_history.command_added.connect(self._on_command_added)
     pyzo.command_history.command_removed.connect(self._on_command_removed)
     pyzo.command_history.commands_reset.connect(self._on_commands_reset)
Exemplo n.º 3
0
 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]
     if not hasattr(self._config, 'hideTypes'):
         self._config.hideTypes = []
     
     # Create tool button
     self._up = QtWidgets.QToolButton(self)
     style = QtWidgets.qApp.style()
     self._up.setIcon( style.standardIcon(style.SP_ArrowLeft) )
     self._up.setIconSize(QtCore.QSize(16,16))
     
     # 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 options menu
     self._options = QtWidgets.QToolButton(self)
     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)
     #
     self._options._menu = QtWidgets.QMenu()
     self._options.setMenu(self._options._menu)
     self.onOptionsPress()  # create menu now
     
     # Create tree
     self._tree = WorkspaceTree(self)
     
     # Set layout
     layout = QtWidgets.QHBoxLayout()
     layout.addWidget(self._up, 0)
     layout.addWidget(self._line, 1)
     layout.addWidget(self._options, 0)
     #
     mainLayout = QtWidgets.QVBoxLayout(self)
     mainLayout.addLayout(layout, 0)
     mainLayout.addWidget(self._tree, 1)
     mainLayout.setSpacing(2)
     mainLayout.setContentsMargins(4,4,4,4)
     self.setLayout(mainLayout)
     
     # Bind events
     self._up.pressed.connect(self._tree._proxy.goUp)
     self._options.pressed.connect(self.onOptionsPress)
     self._options._menu.triggered.connect(self.onOptionMenuTiggered)
Exemplo n.º 4
0
    def __init__(self, parent):
        # Do not pass parent, because is a sublayout
        QtWidgets.QVBoxLayout.__init__(self)

        # Create sub-widget
        self._edit1 = QtWidgets.QLineEdit(parent)
        self._edit1.textEdited.connect(self.onEditChanged)
        if sys.platform.startswith('win'):
            self._edit1.setPlaceholderText('C:\\path\\to\\script.py')
        else:
            self._edit1.setPlaceholderText('/path/to/script.py')
        #
        self._edit2 = QtWidgets.QTextEdit(parent)
        self._edit2.zoomOut(1)
        self._edit2.setMaximumHeight(80)
        self._edit2.setMinimumWidth(200)
        self._edit2.textChanged.connect(self.onEditChanged)

        # Layout
        self.setSpacing(1)
        self.addWidget(self._edit1)
        self.addWidget(self._edit2)

        # Create radio widget for system default
        t = translate('shell', 'Use system default')
        self._radio_system = QtWidgets.QRadioButton(t, parent)
        self._radio_system.toggled.connect(self.onCheckChanged)
        self.addWidget(self._radio_system)
        if self.DISABLE_SYSTEM_DEFAULT:
            self._radio_system.hide()

        # Create radio widget for file
        t = translate('shell', 'File to run at startup')
        self._radio_file = QtWidgets.QRadioButton(t, parent)
        self._radio_file.toggled.connect(self.onCheckChanged)
        self.addWidget(self._radio_file)

        # Create radio widget for code
        t = translate('shell', 'Code to run at startup')
        self._radio_code = QtWidgets.QRadioButton(t, parent)
        self._radio_code.toggled.connect(self.onCheckChanged)
        self.addWidget(self._radio_code)

        # 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._valueFile = ''
        self._valueCode = '\n'
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
    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]
        if not hasattr(self._config, 'hideTypes'):
            self._config.hideTypes = []
        # <kludge 2>
        # configuring the typeTranslation dictionary
        if not hasattr(self._config, 'typeTranslation'):
            # to prevent the exception to be raised, one could init to :
            # {"method": "function", "function": "function", "type": "type", "private": "private", "module": "module"}
            self._config.typeTranslation = {}
        # Defaults
        self._config.typeTranslation['method'] = 'function'
        self._config.typeTranslation['builtin_function_or_method'] = 'function'
        # <kludge 2>

        # Create tool button
        self._up = QtWidgets.QToolButton(self)
        style = QtWidgets.qApp.style()
        self._up.setIcon(style.standardIcon(style.SP_ArrowLeft))
        self._up.setIconSize(QtCore.QSize(16, 16))

        # 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 options menu
        self._options = QtWidgets.QToolButton(self)
        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)
        #
        self._options._menu = QtWidgets.QMenu()
        self._options.setMenu(self._options._menu)
        self.onOptionsPress()  # create menu now

        # Create tree
        self._tree = WorkspaceTree(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)

        # Set layout
        layout = QtWidgets.QHBoxLayout()
        layout.addWidget(self._up, 0)
        layout.addWidget(self._line, 1)
        layout.addWidget(self._options, 0)
        #
        mainLayout = QtWidgets.QVBoxLayout(self)
        mainLayout.addLayout(layout, 0)
        mainLayout.addWidget(self._initText, 1)
        mainLayout.addWidget(self._tree, 2)
        mainLayout.setSpacing(2)
        # set margins
        margin = pyzo.config.view.widgetMargin
        mainLayout.setContentsMargins(margin, margin, margin, margin)
        self.setLayout(mainLayout)

        # Bind events
        self._up.pressed.connect(self._tree._proxy.goUp)
        self._options.pressed.connect(self.onOptionsPress)
        self._options._menu.triggered.connect(self.onOptionMenuTiggered)
Exemplo n.º 7
0
    def __init__(self, parent):
        QtWidgets.QWidget.__init__(self, parent)

        # Create text field, checkbox, and button
        self._text = QtWidgets.QLineEdit(self)
        self._printBut = QtWidgets.QPushButton("Print", self)

        style = QtWidgets.qApp.style()

        self._backBut = QtWidgets.QToolButton(self)
        self._backBut.setIcon(style.standardIcon(style.SP_ArrowLeft))
        self._backBut.setIconSize(QtCore.QSize(16, 16))
        self._backBut.setPopupMode(self._backBut.DelayedPopup)
        self._backBut.setMenu(
            PyzoInteractiveHelpHistoryMenu("Backward menu", self, False))

        self._forwBut = QtWidgets.QToolButton(self)
        self._forwBut.setIcon(style.standardIcon(style.SP_ArrowRight))
        self._forwBut.setIconSize(QtCore.QSize(16, 16))
        self._forwBut.setPopupMode(self._forwBut.DelayedPopup)
        self._forwBut.setMenu(
            PyzoInteractiveHelpHistoryMenu("Forward menu", self, True))

        # Create options button
        self._options = QtWidgets.QToolButton(self)
        self._options.setIcon(pyzo.icons.wrench)
        self._options.setIconSize(QtCore.QSize(16, 16))
        self._options.setPopupMode(self._options.InstantPopup)
        self._options.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)

        # Create options menu
        self._options._menu = QtWidgets.QMenu()
        self._options.setMenu(self._options._menu)

        # Create browser
        self._browser = QtWidgets.QTextBrowser(self)
        self._browser_text = initText
        self._browser.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self._browser.customContextMenuRequested.connect(self.showMenu)

        # Create two sizers
        self._sizer1 = QtWidgets.QVBoxLayout(self)
        self._sizer2 = QtWidgets.QHBoxLayout()

        # Put the elements together
        self._sizer2.addWidget(self._backBut, 1)
        self._sizer2.addWidget(self._forwBut, 2)
        self._sizer2.addWidget(self._text, 4)
        self._sizer2.addWidget(self._printBut, 0)
        self._sizer2.addWidget(self._options, 3)
        #
        self._sizer1.addLayout(self._sizer2, 0)
        self._sizer1.addWidget(self._browser, 1)
        #
        self._sizer1.setSpacing(2)
        # set margins
        margin = pyzo.config.view.widgetMargin
        self._sizer1.setContentsMargins(margin, margin, margin, margin)

        self.setLayout(self._sizer1)

        # Set config
        toolId = self.__class__.__name__.lower()
        self._config = config = pyzo.config.tools[toolId]
        #
        if not hasattr(config, "smartNewlines"):
            config.smartNewlines = True
        if not hasattr(config, "fontSize"):
            if sys.platform == "darwin":
                config.fontSize = 12
            else:
                config.fontSize = 10

        # Create callbacks
        self._text.returnPressed.connect(self.queryDoc)
        self._printBut.clicked.connect(self.printDoc)
        self._backBut.clicked.connect(self.goBack)
        self._forwBut.clicked.connect(self.goForward)
        #
        self._options.pressed.connect(self.onOptionsPress)
        self._options._menu.triggered.connect(self.onOptionMenuTiggered)

        # Start
        self._history = []
        self._histindex = 0
        self.setText()  # Set default text
        self.onOptionsPress()  # Fill menu
Exemplo n.º 8
0
    def __init__(self, parent=None, collection_filename=None):
        """
        Initializes an assistance instance.
        When collection_file is none, it is determined from the
        appDataDir.
        """
        from pyzo.util.qt import QtHelp

        super().__init__(parent)
        self.setWindowTitle("Help")
        pyzoDir, appDataDir, appConfigDir = getResourceDirs()
        if collection_filename is None:
            # Collection file is stored in pyzo data dir:
            collection_filename = os.path.join(appDataDir, "tools", "docs.qhc")
        self._engine = QtHelp.QHelpEngine(collection_filename)

        # Important, call setup data to load the files:
        self._engine.setupData()

        # If no files are loaded, register at least the pyzo docs:
        if len(self._engine.registeredDocumentations()) == 0:
            doc_file = os.path.join(pyzoDir, "resources", "pyzo.qch")
            self._engine.registerDocumentation(doc_file)

        # The main players:
        self._content = self._engine.contentWidget()
        self._index = self._engine.indexWidget()
        self._indexTab = QtWidgets.QWidget()
        il = QtWidgets.QVBoxLayout(self._indexTab)
        filter_text = QtWidgets.QLineEdit()
        il.addWidget(filter_text)
        il.addWidget(self._index)

        self._helpBrowser = HelpBrowser(self._engine)
        self._searchEngine = self._engine.searchEngine()
        self._settings = Settings(self._engine)

        self._progress = QtWidgets.QWidget()
        pl = QtWidgets.QHBoxLayout(self._progress)
        bar = QtWidgets.QProgressBar()
        bar.setMaximum(0)
        pl.addWidget(QtWidgets.QLabel("Indexing"))
        pl.addWidget(bar)

        self._searchResultWidget = self._searchEngine.resultWidget()
        self._searchQueryWidget = self._searchEngine.queryWidget()
        self._searchTab = QtWidgets.QWidget()
        search_layout = QtWidgets.QVBoxLayout(self._searchTab)
        search_layout.addWidget(self._searchQueryWidget)
        search_layout.addWidget(self._searchResultWidget)

        tab = QtWidgets.QTabWidget()
        tab.addTab(self._content, "Contents")
        tab.addTab(self._indexTab, "Index")
        tab.addTab(self._searchTab, "Search")
        tab.addTab(self._settings, "Settings")

        splitter = QtWidgets.QSplitter(self)
        splitter.addWidget(tab)
        splitter.addWidget(self._helpBrowser)

        layout = QtWidgets.QVBoxLayout(self)
        layout.addWidget(splitter)
        layout.addWidget(self._progress)

        # Connect clicks:
        self._content.linkActivated.connect(self._helpBrowser.setSource)
        self._index.linkActivated.connect(self._helpBrowser.setSource)
        self._searchEngine.searchingFinished.connect(self.onSearchFinish)
        self._searchEngine.indexingStarted.connect(self.onIndexingStarted)
        self._searchEngine.indexingFinished.connect(self.onIndexingFinished)
        filter_text.textChanged.connect(self._index.filterIndices)
        self._searchResultWidget.requestShowLink.connect(self._helpBrowser.setSource)
        self._searchQueryWidget.search.connect(self.goSearch)

        # Always re-index on startup:
        self._searchEngine.reindexDocumentation()

        self._search_term = None

        # Show initial page:
        # self.showHelpForTerm('welcome to pyzo')
        self._helpBrowser.setHtml(help_help)
Exemplo n.º 9
0
    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()
Exemplo n.º 10
0
    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()
Exemplo n.º 11
0
    def __init__(self, *args):

        QtWidgets.QDialog.__init__(self, *args)

        self.input = DIALOG_INPUT

        self.placeholders = """
        Placeholders:\n
        %b \n                Gets replaced by the selected text in the File Browser
        %d \n                Gets replaced by the path to the directory of the active document
        %e \n                Gets replaced by the name of the active document, including its extension
        %f \n                Gets replaced by the local filepath to the active document
        %n \n                Gets replaced by the name of the active document without its extension
        %s \n                Gets replaced by the selected text in the active document
        """
        # Set size
        size = 650, 190
        offset = 0
        size2 = size[0], size[1] + offset
        self.resize(*size2)
        self.setMaximumSize(*size2)
        self.setMinimumSize(*size2)
        self.item = ""

        note = "NOTE: It is your responsibility to prevent running hazardous commands"
        self._note_label = QtWidgets.QLabel(self)
        self._note_label.setText(note)

        layout_1 = QtWidgets.QHBoxLayout()
        layout_1.addWidget(self._note_label, 0)
        # Name
        self._name_label = QtWidgets.QLabel(self)
        self._name_label.setText("Name")
        self._name = QtWidgets.QLineEdit(self)
        self._name.setReadOnly(False)
        # Command
        self._command_label = QtWidgets.QLabel(self)
        self._command_label.setText("Command")
        self._command = QtWidgets.QLineEdit(self)
        self._command.setReadOnly(False)
        self._command.setToolTip(str(self.placeholders))
        # Grid
        self.horizontalGroupBox = QtWidgets.QGroupBox()
        layout_grid = QtWidgets.QGridLayout()
        layout_grid.setColumnStretch(1, 2)
        layout_grid.addWidget(self._name_label, 0, 0)
        layout_grid.addWidget(self._name, 0, 1)
        layout_grid.addWidget(self._command_label, 1, 0)
        layout_grid.addWidget(self._command, 1, 1)
        self.horizontalGroupBox.setLayout(layout_grid)

        self.button_box = QtWidgets.QDialogButtonBox(
            QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel)
        self.button_box.accepted.connect(self.accept)
        self.button_box.rejected.connect(self.reject)

        layout_2 = QtWidgets.QHBoxLayout()
        layout_2.addWidget(self.button_box, 0)
        # Layouts
        mainLayout = QtWidgets.QVBoxLayout(self)
        mainLayout.addLayout(layout_1, 0)
        mainLayout.addWidget(self.horizontalGroupBox)
        mainLayout.addLayout(layout_2, 0)
        self.setLayout(mainLayout)