Esempio n. 1
0
    def __init__(self, *args, padding=(4, 4, 6, 6), preventEqualTexts=True):
        QtGui.QTabBar.__init__(self, *args)

        # Put tab widget in document mode
        self.setDocumentMode(True)

        # Widget needs to draw its background (otherwise Mac has a dark bg)
        self.setDrawBase(False)
        if sys.platform == 'darwin':
            self.setAutoFillBackground(True)

        # Set whether we want to prevent eliding for names that start the same.
        self._preventEqualTexts = preventEqualTexts

        # Allow moving tabs around
        self.setMovable(True)

        # Get padding
        if isinstance(padding, (int, float)):
            padding = padding, padding, padding, padding
        elif isinstance(padding, (tuple, list)):
            pass
        else:
            raise ValueError('Invalid value for padding.')

        # Set style sheet
        stylesheet = STYLESHEET
        stylesheet = stylesheet.replace('PADDING_TOP', str(padding[0]))
        stylesheet = stylesheet.replace('PADDING_BOTTOM', str(padding[1]))
        stylesheet = stylesheet.replace('PADDING_LEFT', str(padding[2]))
        stylesheet = stylesheet.replace('PADDING_RIGHT', str(padding[3]))
        self.setStyleSheet(stylesheet)

        # We do our own eliding
        self.setElideMode(QtCore.Qt.ElideNone)

        # Make tabs wider if there's plenty space?
        self.setExpanding(False)

        # If there's not enough space, use scroll buttons
        self.setUsesScrollButtons(True)

        # When a tab is removed, select previous
        self.setSelectionBehaviorOnRemove(self.SelectPreviousTab)

        # Init alignment parameters
        self._alignWidth = MIN_NAME_WIDTH  # Width in characters
        self._alignWidthIsReducing = False  # Whether in process of reducing

        # Create timer for aligning
        self._alignTimer = QtCore.QTimer(self)
        self._alignTimer.setInterval(10)
        self._alignTimer.setSingleShot(True)
        self._alignTimer.timeout.connect(self._alignRecursive)
Esempio n. 2
0
    def __init__(self, objectWithIcon):

        self._objectWithIcon = objectWithIcon

        # Motion properties
        self._index = 0
        self._level = 0
        self._count = 0  #  to count number of iters in level 1

        # Prepare blob pixmap
        self._blob = self._createBlobPixmap()
        self._legs = self._createLegsPixmap()

        # Create timer
        self._timer = QtCore.QTimer(None)
        self._timer.setInterval(150)
        self._timer.setSingleShot(False)
        self._timer.timeout.connect(self.onTimer)
Esempio n. 3
0
 def __init__(self, *args, **kwds):
     super().__init__(*args, **kwds)
     
     # Set font and zooming
     self.setFont(iep.config.view.fontname)
     self.setZoom(iep.config.view.zoom)
     
     # Create timer for autocompletion delay
     self._delayTimer = QtCore.QTimer(self)
     self._delayTimer.setSingleShot(True)
     self._delayTimer.timeout.connect(self._introspectNow)
     
     # For buffering autocompletion and calltip info
     self._callTipBuffer_name = ''
     self._callTipBuffer_time = 0
     self._callTipBuffer_result = ''
     self._autoCompBuffer_name = ''
     self._autoCompBuffer_time = 0
     self._autoCompBuffer_result = []
     
     # The string with names given to SCI_AUTOCSHOW
     self._autoCompNameString = ''
     
     # Set autocomp accept key to default if necessary.
     # We force it to be string (see issue 134)
     if not isinstance(iep.config.settings.autoComplete_acceptKeys, str):
         iep.config.settings.autoComplete_acceptKeys = 'Tab'
     
     # Set autocomp accept keys
     qtKeys = []
     for key in iep.config.settings.autoComplete_acceptKeys.split(' '):
         if len(key) > 1:
             key = 'Key_' + key[0].upper() + key[1:].lower()
             qtkey = getattr(QtCore.Qt, key, None)
         else:
             qtkey = ord(key)
         if qtkey:
             qtKeys.append(qtkey)
     self.setAutoCompletionAcceptKeys(*qtKeys)
     
     self.completer().highlighted.connect(self.updateHelp)
     self.setIndentUsingSpaces(iep.config.settings.defaultIndentUsingSpaces)
     self.setIndentWidth(iep.config.settings.defaultIndentWidth) 
     self.setAutocompletPopupSize(*iep.config.view.autoComplete_popupSize) 
Esempio n. 4
0
    def __init__(self, parent, info):
        BaseShell.__init__(self, parent)

        # Get standard info if not given.
        if info is None and iep.config.shellConfigs2:
            info = iep.config.shellConfigs2[0]
        if not info:
            info = KernelInfo(None)

        # Store info so we can reuse it on a restart
        self._info = info

        # For the editor to keep track of attempted imports
        self._importAttempts = []

        # To keep track of the response for introspection
        self._currentCTO = None
        self._currentACO = None

        # Write buffer to store messages in for writing
        self._write_buffer = None

        # Create timer to keep polling any results
        # todo: Maybe use yoton events to process messages as they arrive.
        # I tried this briefly, but it seemd to be less efficient because
        # messages are not so much bach-processed anymore. We should decide
        # on either method.
        self._timer = QtCore.QTimer(self)
        self._timer.setInterval(POLL_TIMER_INTERVAL)  # ms
        self._timer.setSingleShot(False)
        self._timer.timeout.connect(self.poll)
        self._timer.start()

        # Add context menu
        self._menu = ShellContextMenu(shell=self, parent=self)
        self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.customContextMenuRequested.connect(lambda p: self._menu.popup(
            self.mapToGlobal(p + QtCore.QPoint(0, 3))))

        # Start!
        self.resetVariables()
        self.connectToKernel(info)
Esempio n. 5
0
    def __init__(self, parent, **kwds):
        super().__init__(parent, showLineNumbers=True, **kwds)

        # Init filename and name
        self._filename = ''
        self._name = '<TMP>'

        # View settings
        self.setShowWhitespace(iep.config.view.showWhitespace)
        #TODO: self.setViewWrapSymbols(view.showWrapSymbols)
        self.setShowLineEndings(iep.config.view.showLineEndings)
        self.setShowIndentationGuides(iep.config.view.showIndentationGuides)
        #
        self.setWrap(bool(iep.config.view.wrap))
        self.setHighlightCurrentLine(iep.config.view.highlightCurrentLine)
        self.setLongLineIndicatorPosition(iep.config.view.edgeColumn)
        #TODO: self.setFolding( int(view.codeFolding)*5 )
        # bracematch is set in baseTextCtrl, since it also applies to shells
        # dito for zoom and tabWidth

        # Set line endings to default
        self.lineEndings = iep.config.settings.defaultLineEndings

        # Set encoding to default
        self.encoding = 'UTF-8'

        # Modification time to test file change
        self._modifyTime = 0

        self.modificationChanged.connect(self._onModificationChanged)

        # To see whether the doc has changed to update the parser.
        self.textChanged.connect(self._onModified)

        # This timer is used to hide the marker that shows which code is executed
        self._showRunCursorTimer = QtCore.QTimer()

        # Add context menu (the offset is to prevent accidental auto-clicking)
        self._menu = EditorContextMenu(self)
        self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.customContextMenuRequested.connect(lambda p: self._menu.popup(
            self.mapToGlobal(p) + QtCore.QPoint(0, 3)))
Esempio n. 6
0
 def __init__(self, parent, shellStack):
     QtGui.QToolButton.__init__(self, parent)
     
     # Store reference of shell stack
     self._shellStack = shellStack
     
     # Keep reference of actions corresponding to shells
     self._shellActions = []
     
     # Set text and tooltip
     self.setText('Warming up ...')
     self.setToolTip("Click to select shell.")
     self.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)
     self.setPopupMode(self.InstantPopup)
     
     # Set icon
     self._iconMaker = ShellIconMaker(self)
     self._iconMaker.updateIcon('busy') # Busy initializing
     
     # Create timer
     self._elapsedTimesTimer = QtCore.QTimer(self)
     self._elapsedTimesTimer.setInterval(200)
     self._elapsedTimesTimer.setSingleShot(False)
     self._elapsedTimesTimer.timeout.connect(self.onElapsedTimesTimer)
Esempio n. 7
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( iep.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 occurance 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 occurance 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(iep.config.state.find_matchCase) )
     self._regExp.setChecked( bool(iep.config.state.find_regExp) )
     self._wholeWord.setChecked(  bool(iep.config.state.find_wholeWord) )
     self._autoHide.setChecked(  bool(iep.config.state.find_autoHide) )
     
     # show or hide?
     if bool(iep.config.state.find_show):
         self.show()
     else:
         self.hide()