Ejemplo n.º 1
0
    def __init__(self, parent):
        QtGui.QWidget.__init__(self, parent)

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

        # Create options button
        self._options = QtGui.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 = QtGui.QMenu()
        self._options.setMenu(self._options._menu)

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

        # Create two sizers
        self._sizer1 = QtGui.QVBoxLayout(self)
        self._sizer2 = QtGui.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
Ejemplo n.º 2
0
    def __init__(self, parent=None):
        QtGui.QDialog.__init__(self, parent)
        self.setWindowTitle('Install a conda env?')
        self.setModal(True)

        text = 'Pyzo is only an editor. To execute code, you need a Python environment.\n\n'
        text += 'Do you want Pyzo to install a Python environment (miniconda)?\n'
        text += 'If not, you must arrange for a Python interpreter yourself'
        if not sys.platform.startswith('win'):
            text += ' or use the system Python'
        text += '.'
        text += '\n(You can always launch the installer from the shell menu.)'

        self._label = QtGui.QLabel(text, self)
        self._no = QtGui.QPushButton("No thanks (dont ask again)")
        self._yes = QtGui.QPushButton("Yes, please install Python!")

        self._no.clicked.connect(self.reject)
        self._yes.clicked.connect(self.accept)

        vbox = QtGui.QVBoxLayout(self)
        hbox = QtGui.QHBoxLayout()
        self.setLayout(vbox)
        vbox.addWidget(self._label, 1)
        vbox.addLayout(hbox, 0)
        hbox.addWidget(self._no, 2)
        hbox.addWidget(self._yes, 2)

        self._yes.setDefault(1)
Ejemplo n.º 3
0
    def __init__(self, parent, i):
        QtGui.QWizardPage.__init__(self, parent)
        self._i = i

        # Create label for description
        self._text_label = QtGui.QLabel(self)
        self._text_label.setTextFormat(QtCore.Qt.RichText)
        self._text_label.setWordWrap(True)

        # Create label for image
        self._comicLabel = QtGui.QLabel(self)
        pm = QtGui.QPixmap()
        if 'logo' in self._image_filename:
            pm.load(
                os.path.join(pyzo.pyzoDir, 'resources', 'appicons',
                             self._image_filename))
        elif self._image_filename:
            pm.load(
                os.path.join(pyzo.pyzoDir, 'resources', 'images',
                             self._image_filename))
        self._comicLabel.setPixmap(pm)
        self._comicLabel.setAlignment(QtCore.Qt.AlignHCenter
                                      | QtCore.Qt.AlignVCenter)

        # Layout
        theLayout = QtGui.QVBoxLayout(self)
        self.setLayout(theLayout)
        #
        theLayout.addWidget(self._text_label)
        theLayout.addStretch()
        theLayout.addWidget(self._comicLabel)
        theLayout.addStretch()
Ejemplo n.º 4
0
    def __init__(self, parent, distro=None):
        QtGui.QWidget.__init__(self, parent)
        self.setMinimumSize(360, 256)  # Ensure title fits nicely

        # Create label widget and costumize
        self._label = QtGui.QLabel(self)
        self._label.setTextFormat(QtCore.Qt.RichText)
        self._label.setOpenExternalLinks(True)
        self._label.setWordWrap(True)
        self._label.setMargin(20)

        # Set font size (absolute value)
        font = self._label.font()
        font.setPointSize(11)  #(font.pointSize()+1)
        self._label.setFont(font)

        # Build
        distrotext = ''
        if distro:
            distrotext = '<br />brought to you by %s.' % distro
        text = splash_text.format(distro=distrotext, version=pyzo.__version__)

        # Set text
        self._label.setText(text)

        layout = QtGui.QVBoxLayout(self)
        self.setLayout(layout)
        layout.addStretch(1)
        layout.addWidget(self._label, 0)
        layout.addStretch(1)
Ejemplo n.º 5
0
 def __init__(self, parent):
     QtGui.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 = QtGui.QToolButton(self)
     style = QtGui.qApp.style()
     self._up.setIcon( style.standardIcon(style.SP_ArrowLeft) )
     self._up.setIconSize(QtCore.QSize(16,16))
     
     # Create "path" line edit
     self._line = QtGui.QLineEdit(self)
     self._line.setReadOnly(True)
     self._line.setStyleSheet("QLineEdit { background:#ddd; }")
     self._line.setFocusPolicy(QtCore.Qt.NoFocus)
     
     # Create options menu
     self._options = QtGui.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 = QtGui.QMenu()
     self._options.setMenu(self._options._menu)
     self.onOptionsPress()  # create menu now
     
     # Create tree
     self._tree = WorkspaceTree(self)
     
     # Set layout
     layout = QtGui.QHBoxLayout()
     layout.addWidget(self._up, 0)
     layout.addWidget(self._line, 1)
     layout.addWidget(self._options, 0)
     #
     mainLayout = QtGui.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)
Ejemplo n.º 6
0
    def __init__(self, parent):
        QtGui.QWidget.__init__(self, parent)

        # Get config
        toolId = self.__class__.__name__.lower(
        ) + '2'  # This is v2 of the file browser
        if toolId not in pyzo.config.tools:
            pyzo.config.tools[toolId] = ssdf.new()
        self.config = pyzo.config.tools[toolId]

        # Ensure three main attributes in config
        for name in ['expandedDirs', 'starredDirs']:
            if name not in self.config:
                self.config[name] = []

        # Ensure path in config
        if 'path' not in self.config or not isdir(self.config.path):
            self.config.path = op.expanduser('~')

        # Check expandedDirs and starredDirs.
        # Make path objects and remove invalid dirs. Also normalize case,
        # should not be necessary, but maybe the config was manually edited.
        expandedDirs, starredDirs = [], []
        for d in self.config.starredDirs:
            if 'path' in d and 'name' in d and 'addToPythonpath' in d:
                if isdir(d.path):
                    d.path = op.normcase(cleanpath(d.path))
                    starredDirs.append(d)
        for p in set([str(p) for p in self.config.expandedDirs]):
            if isdir(p):
                p = op.normcase(cleanpath(p))
                # Add if it is a subdir of a starred dir
                for d in starredDirs:
                    if p.startswith(d.path):
                        expandedDirs.append(p)
                        break
        self.config.expandedDirs, self.config.starredDirs = expandedDirs, starredDirs

        # Create browser(s).
        self._browsers = []
        for i in [0]:
            self._browsers.append(Browser(self, self.config))

        # Layout
        layout = QtGui.QVBoxLayout(self)
        self.setLayout(layout)
        layout.addWidget(self._browsers[0])
        layout.setSpacing(0)
        layout.setContentsMargins(4, 4, 4, 4)
Ejemplo n.º 7
0
    def __init__(self, parent):
        super().__init__(parent)

        self._label = QtGui.QLabel('hello world')
        self._label.setTextFormat(QtCore.Qt.RichText)
        self._label.setWordWrap(True)
        # self._label.setOpenExternalLinks(True)
        self._label.linkActivated.connect(self.handle_link)
        font = self._label.font()
        font.setPointSize(font.pointSize() + 1)
        self._label.setFont(font)

        layout = QtGui.QVBoxLayout()
        self.setLayout(layout)
        layout.addWidget(self._label, 1)
Ejemplo n.º 8
0
    def __init__(self, engine):
        super().__init__()
        self._engine = engine
        layout = QtGui.QVBoxLayout(self)
        add_button = QtGui.QPushButton("Add")
        del_button = QtGui.QPushButton("Delete")
        self._view = QtGui.QListView()
        layout.addWidget(self._view)
        layout2 = QtGui.QHBoxLayout()
        layout2.addWidget(add_button)
        layout2.addWidget(del_button)
        layout.addLayout(layout2)
        self._model = QtGui.QStringListModel()
        self._view.setModel(self._model)

        self._model.setStringList(self._engine.registeredDocumentations())

        add_button.clicked.connect(self.add_doc)
        del_button.clicked.connect(self.del_doc)
Ejemplo n.º 9
0
    def __init__(self, parent=None):
        QtGui.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 = QtGui.QLabel(text, self)

        self._scipystack = QtGui.QCheckBox(
            translate('bootstrapconda', 'Also install scientific packages',
                      self))
        self._scipystack.setChecked(True)
        self._path = QtGui.QLineEdit(default_conda_dir, self)
        self._progress = QtGui.QProgressBar(self)
        self._outputLine = QtGui.QLabel(self)
        self._output = QtGui.QPlainTextEdit(self)
        self._output.setReadOnly(True)
        self._button = QtGui.QPushButton('Install', self)

        self._outputLine.setSizePolicy(QtGui.QSizePolicy.Ignored,
                                       QtGui.QSizePolicy.Fixed)

        vbox = QtGui.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)
Ejemplo n.º 10
0
    def __init__(self, parent):
        QtGui.QWidget.__init__(self, parent)

        # create toolbar
        self._toolbar = QtGui.QToolBar(self)
        self._toolbar.setMaximumHeight(25)
        self._toolbar.setIconSize(QtCore.QSize(16, 16))

        # create stack
        self._stack = QtGui.QStackedWidget(self)

        # Populate toolbar
        self._shellButton = ShellControl(self._toolbar, self._stack)
        self._debugmode = 0
        self._dbs = DebugStack(self._toolbar)
        #
        self._toolbar.addWidget(self._shellButton)
        self._toolbar.addSeparator()
        # self._toolbar.addWidget(self._dbc) -> delayed, see addContextMenu()

        self._condahelp = CondaHelper(self)

        # widget layout
        layout = QtGui.QVBoxLayout()
        layout.setSpacing(0)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(self._toolbar)
        layout.addWidget(self._stack, 0)
        layout.addWidget(self._condahelp, 0)
        self.setLayout(layout)

        # make callbacks
        self._stack.currentChanged.connect(self.onCurrentChanged)

        # Make shared history (shared among shells)
        if PythonHistory is None:
            self.sharedHistory = None
        else:
            self.sharedHistory = PythonHistory('shellhistory.py')

        self.showCondaHelper()
Ejemplo n.º 11
0
 def __init__(self, parent):
     QtGui.QDialog.__init__(self, parent)
     self.setWindowTitle(pyzo.translate("menu dialog", "About Pyzo"))
     self.resize(600,500)
     
     # Layout
     layout = QtGui.QVBoxLayout(self)
     self.setLayout(layout)
     
     # Create image and title
     im = QtGui.QPixmap( os.path.join(pyzo.pyzoDir, 
                         'resources', 'appicons', 'pyzologo64.png') )
     imlabel = QtGui.QLabel(self)
     imlabel.setPixmap(im)
     textlabel = QtGui.QLabel(self)
     textlabel.setText('<h3>Pyzo: the Interactive Editor for Python</h3>')
     #
     titleLayout = QtGui.QHBoxLayout()
     titleLayout.addWidget(imlabel, 0)
     titleLayout.addWidget(textlabel, 1)
     #
     layout.addLayout(titleLayout, 0)
     
     # Create tab bar
     self._tabs = QtGui.QTabWidget(self)
     self._tabs.setDocumentMode(True)
     layout.addWidget(self._tabs, 1)
     
     # Create button box
     self._butBox = QtGui.QDialogButtonBox(self)
     self._butBox.setOrientation(QtCore.Qt.Horizontal)
     self._butBox.setStandardButtons(self._butBox.Close)
     layout.addWidget(self._butBox, 0)
     
     # Signals
     self._butBox.rejected.connect(self.close)
     
     # Create tabs
     self.createGeneralTab()
     self.createContributorsTab()
     self.createLicenseTab()
Ejemplo n.º 12
0
    def __init__(self, parent):
        QtGui.QWidget.__init__(self, parent)

        # keep a booking of opened directories
        self._lastpath = ''

        # keep track of all breakpoints
        self._breakPoints = {}

        # create tab widget
        self._tabs = FileTabWidget(self)
        self._tabs.tabCloseRequested.connect(self.closeFile)
        self._tabs.currentChanged.connect(self.onCurrentChanged)

        # Double clicking a tab saves the file, clicking on the bar opens a new file
        self._tabs.tabBar().tabDoubleClicked.connect(self.saveFile)
        self._tabs.tabBar().barDoubleClicked.connect(self.newFile)

        # Create find/replace widget
        self._findReplace = FindReplaceWidget(self)

        # create box layout control and add widgets
        self._boxLayout = QtGui.QVBoxLayout(self)
        self._boxLayout.addWidget(self._tabs, 1)
        self._boxLayout.addWidget(self._findReplace, 0)
        # spacing of widgets
        self._boxLayout.setSpacing(0)
        # apply
        self.setLayout(self._boxLayout)

        #self.setAttribute(QtCore.Qt.WA_AlwaysShowToolTips,True)

        # accept drops
        self.setAcceptDrops(True)

        # restore state (call later so that the menu module can bind to the
        # currentChanged signal first, in order to set tab/indentation
        # checkmarks appropriately)
        # todo: Resetting the scrolling would work better if set after
        # the widgets are properly sized.
        pyzo.callLater(self.restoreEditorState)
Ejemplo n.º 13
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 = 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')
            ok = self._engine.registerDocumentation(doc_file)

        # The main players:
        self._content = self._engine.contentWidget()
        self._index = self._engine.indexWidget()
        self._indexTab = QtGui.QWidget()
        il = QtGui.QVBoxLayout(self._indexTab)
        filter_text = QtGui.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 = QtGui.QWidget()
        pl = QtGui.QHBoxLayout(self._progress)
        bar = QtGui.QProgressBar()
        bar.setMaximum(0)
        pl.addWidget(QtGui.QLabel('Indexing'))
        pl.addWidget(bar)

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

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

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

        layout = QtGui.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)
Ejemplo n.º 14
0
    def __init__(self, *args):
        QtGui.QFrame.__init__(self, *args)

        self.setFocusPolicy(QtCore.Qt.ClickFocus)

        # init layout
        layout = QtGui.QHBoxLayout(self)
        layout.setSpacing(0)
        self.setLayout(layout)

        # Create some widgets first to realize a correct tab order
        self._hidebut = QtGui.QToolButton(self)
        self._findText = QtGui.QLineEdit(self)
        self._replaceText = QtGui.QLineEdit(self)

        if True:
            # Create sub layouts
            vsubLayout = QtGui.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 = QtGui.QVBoxLayout()
            hsubLayout = QtGui.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 = QtGui.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 = QtGui.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 = QtGui.QVBoxLayout()
            hsubLayout = QtGui.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 = QtGui.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 = QtGui.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 = QtGui.QVBoxLayout()
            vsubLayout.setSpacing(0)
            layout.addLayout(vsubLayout, 0)

            # Add match-case checkbox
            t = translate('search',
                          'Match case ::: Find words that match case.')
            self._caseCheck = QtGui.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 = QtGui.QCheckBox(t, self)
            self._regExp.setToolTip(t.tt)
            vsubLayout.addWidget(self._regExp, 0)

        if True:

            # Create sub layouts
            vsubLayout = QtGui.QVBoxLayout()
            vsubLayout.setSpacing(0)
            layout.addLayout(vsubLayout, 0)

            # Add whole-word checkbox
            t = translate('search', 'Whole words ::: Find only whole words.')
            self._wholeWord = QtGui.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 = QtGui.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()
Ejemplo n.º 15
0
    def __init__(self, parent):
        QtGui.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, 'showTypes'):
            self._config.showTypes = ['class', 'def', 'cell', 'todo']
        if not hasattr(self._config, 'level'):
            self._config.level = 2

        # Create icon for slider
        self._sliderIcon = QtGui.QToolButton(self)
        self._sliderIcon.setIcon(pyzo.icons.text_align_right)
        self._sliderIcon.setIconSize(QtCore.QSize(16, 16))
        self._sliderIcon.setStyleSheet(
            "QToolButton { border: none; padding: 0px; }")

        # Create slider
        self._slider = QtGui.QSlider(QtCore.Qt.Horizontal, self)
        self._slider.setTickPosition(QtGui.QSlider.TicksBelow)
        self._slider.setSingleStep(1)
        self._slider.setPageStep(1)
        self._slider.setRange(1, 9)
        self._slider.setValue(self._config.level)
        self._slider.valueChanged.connect(self.updateStructure)

        # Create options button
        #self._options = QtGui.QPushButton(self)
        #self._options.setText('Options'))
        #self._options.setToolTip("What elements to show.")
        self._options = QtGui.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)

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

        # Create tree widget
        self._tree = QtGui.QTreeWidget(self)
        self._tree.setHeaderHidden(True)
        self._tree.itemCollapsed.connect(self.updateStructure)  # keep expanded
        self._tree.itemClicked.connect(self.onItemClick)

        # Create two sizers
        self._sizer1 = QtGui.QVBoxLayout(self)
        self._sizer2 = QtGui.QHBoxLayout()
        self._sizer1.setSpacing(2)
        self._sizer1.setContentsMargins(4, 4, 4, 4)

        # Set layout
        self._sizer1.addLayout(self._sizer2, 0)
        self._sizer1.addWidget(self._tree, 1)
        self._sizer2.addWidget(self._sliderIcon, 0)
        self._sizer2.addWidget(self._slider, 4)
        self._sizer2.addStretch(1)
        self._sizer2.addWidget(self._options, 2)
        #
        self.setLayout(self._sizer1)

        # Init current-file name
        self._currentEditorId = 0

        # Bind to events
        pyzo.editors.currentChanged.connect(self.onEditorsCurrentChanged)
        pyzo.editors.parserDone.connect(self.updateStructure)

        self._options.pressed.connect(self.onOptionsPress)
        self._options._menu.triggered.connect(self.onOptionMenuTiggered)

        # Start
        # When the tool is loaded, the editorStack is already done loading
        # all previous files and selected the appropriate file.
        self.onOptionsPress()  # Create menu now
        self.onEditorsCurrentChanged()
Ejemplo n.º 16
0
    def __init__(self, *args):
        QtGui.QDialog.__init__(self, *args)
        self.setModal(True)

        # Set title
        self.setWindowTitle(pyzo.translate('shell', 'Shell configurations'))
        # Create tab widget
        self._tabs = QtGui.QTabWidget(self)
        #self._tabs = CompactTabWidget(self, padding=(4,4,5,5))
        #self._tabs.setDocumentMode(False)
        self._tabs.setMovable(True)

        # Get known interpreters (sorted them by version)
        # Do this here so we only need to do it once ...
        from pyzo.util.interpreters import get_interpreters
        self.interpreters = list(reversed(get_interpreters('2.4')))

        # Introduce an entry if there's none
        if not pyzo.config.shellConfigs2:
            w = ShellInfoTab(self._tabs)
            self._tabs.addTab(w, '---')
            w.setInfo()

        # Fill tabs
        for item in pyzo.config.shellConfigs2:
            w = ShellInfoTab(self._tabs)
            self._tabs.addTab(w, '---')
            w.setInfo(item)

        # Enable making new tabs and closing tabs
        self._add = QtGui.QToolButton(self)
        self._tabs.setCornerWidget(self._add)
        self._add.clicked.connect(self.onAdd)
        self._add.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)
        self._add.setIcon(pyzo.icons.add)
        self._add.setText(translate('shell', 'Add config'))
        #
        #self._tabs.setTabsClosable(True)
        self._tabs.tabCloseRequested.connect(self.onTabClose)

        # Create buttons
        cancelBut = QtGui.QPushButton("Cancel", self)
        okBut = QtGui.QPushButton("Done", self)
        cancelBut.clicked.connect(self.close)
        okBut.clicked.connect(self.applyAndClose)
        # Layout for buttons
        buttonLayout = QtGui.QHBoxLayout()
        buttonLayout.addStretch(1)
        buttonLayout.addWidget(cancelBut)
        buttonLayout.addSpacing(10)
        buttonLayout.addWidget(okBut)

        # Layout the widgets
        mainLayout = QtGui.QVBoxLayout(self)
        mainLayout.addSpacing(8)
        mainLayout.addWidget(self._tabs, 0)
        mainLayout.addLayout(buttonLayout, 0)
        self.setLayout(mainLayout)

        # Prevent resizing
        self.show()
        self.setMinimumSize(500, 400)
        self.resize(640, 500)