Exemple #1
0
    def paintEvent(self, event):
        font_metrics = QtGui.QFontMetrics(self.editor.font)
        page_bottom = self.editor.viewport().height()
       
        painter = QtGui.QPainter(self)
        painter.fillRect(self.rect(), self.background)

        block = self.editor.firstVisibleBlock()
        viewport_offset = self.editor.contentOffset()
        
        while block.isValid():
            # The top left position of the block in the document
            position = self.editor.blockBoundingGeometry(block).topLeft() + viewport_offset
            # Check if the position of the block is out side of the visible area
            if position.y() > page_bottom:
                break

            # Draw the line number right justified at the y position of the line.
            if block.isVisible() and block in self.editor.bookmarkListModel:
                painter.drawPixmap(0,
                    round(position.y()) + font_metrics.ascent() + font_metrics.descent() - self.bookmarkflagImage.height(),
                    self.bookmarkflagImage)

            block = block.next()

        painter.end()
        QtGui.QWidget.paintEvent(self, event)
Exemple #2
0
    def paintEvent(self, event):
        font_metrics = QtGui.QFontMetrics(self.editor.font)
        page_bottom = self.editor.viewport().height()
        
        lineHeight = font_metrics.height()

        scrollBar = self.editor.verticalScrollBar()
        if scrollBar.isVisible():
            rectRelation = float(scrollBar.height()) / float(self.editor.document().blockCount())
        else:
            rectRelation = lineHeight
        rectHeight = round(rectRelation) if rectRelation >= 1 else 1

        painter = QtGui.QPainter(self)
        painter.fillRect(self.rect(), self.background)

        viewport_offset = self.editor.contentOffset()

        for extra in self.editor.searchExtraSelections("selection"):
            y = round(extra.cursor.block().blockNumber() * rectRelation)
            if rectRelation == lineHeight:
                y += viewport_offset.y()
            painter.fillRect(0, y, 10, rectHeight, self.editor.colours['selection'])

        painter.end()
        QtGui.QWidget.paintEvent(self, event)
Exemple #3
0
 def setupWidgetStatus(self):
     tableView = QtGui.QTableView(self)
     tableView.setModel(self.application.supportManager.syntaxProxyModel)
     tableView.resizeColumnsToContents()
     tableView.resizeRowsToContents()
     tableView.verticalHeader().setVisible(False)
     tableView.horizontalHeader().setVisible(False)
     tableView.setShowGrid(False)
     tableView.setMinimumWidth(tableView.horizontalHeader().length() + 25)
     tableView.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
     tableView.setSelectionMode(QtGui.QAbstractItemView.SingleSelection)
     tableView.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
     tableView.setAutoScroll(False)
     self.comboBoxSyntaxes.setModel(self.application.supportManager.syntaxProxyModel);
     self.comboBoxSyntaxes.setView(tableView)
     self.comboBoxSyntaxes.setModelColumn(0)
     
     #Connect tab size context menu
     self.labelTabSize.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
     self.labelTabSize.customContextMenuRequested.connect(self.showTabSizeContextMenu)
     
     #Create bundle menu
     self.menuBundle = QtGui.QMenu(self)
     self.application.supportManager.appendMenuToBundleMenuGroup(self.menuBundle)
     self.toolButtonMenuBundle.setMenu(self.menuBundle)
Exemple #4
0
 def paintEvent(self, event):
     p = QtGui.QPainter(self)
     r = self.rect()
     opt = QtGui.QStyleOptionToolButton()
     opt.init(self)
     opt.state |= QtGui.QStyle.State_AutoRaise
     if self.isEnabled() and self.underMouse() and \
        not self.isChecked() and not self.isDown():
         opt.state |= QtGui.QStyle.State_Raised
     if self.isChecked():
         opt.state |= QtGui.QStyle.State_On
     if self.isDown():
         opt.state |= QtGui.QStyle.State_Sunken
     self.style().drawPrimitive(QtGui.QStyle.PE_PanelButtonTool, opt, p,
                                self)
     opt.icon = self.icon()
     opt.subControls = QtGui.QStyle.SubControls()
     opt.activeSubControls = QtGui.QStyle.SubControls()
     opt.features = QtGui.QStyleOptionToolButton.None
     opt.arrowType = QtCore.Qt.NoArrow
     size = self.style().pixelMetric(QtGui.QStyle.PM_SmallIconSize, None,
                                     self)
     opt.iconSize = QtCore.QSize(size, size)
     self.style().drawComplexControl(QtGui.QStyle.CC_ToolButton, opt, p,
                                     self)
Exemple #5
0
    def __init__(self, name, area, parent):
        QtGui.QToolBar.__init__(self, parent)
        assert isinstance(parent, QtGui.QMainWindow)
        assert area in self.DOCK_AREA_TO_TB
        self._area = area
        self.setObjectName(text2objectname(name, prefix="ToolBar"))
        self.setWindowTitle(name)

        #Button Style
        #self.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)

        self.setFloatable(False)
        self.setMovable(False)
        self.setSizePolicy(
            QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed,
                              QtGui.QSizePolicy.MinimumExpanding))
        self.setIconSize(QtCore.QSize(16, 16))

        #Restore action
        self.restoreAction = QtGui.QAction(self)
        self.restoreAction.setIcon(resources.getIcon("image-stack"))
        self.restoreAction.triggered.connect(self.hide)
        self.addAction(self.restoreAction)

        self.visibilityChanged.connect(self.on_visibilityChanged)
Exemple #6
0
def get_icon(index, default=None):
    '''
    Makes the best effort to find an icon for an index.
    Index can be a path, a Qt resource path, an integer.
    @return: QIcon instance or None if no icon could be retrieved
    '''
    #Try icon in db
    path = getResourcePath(index, ["Icons", "External"])
    if path is not None:
        return QtGui.QIcon(path)
    elif isinstance(index, basestring):
        #Try file path
        if os.path.isfile(index):
            return __fileIconProvider.icon(QtCore.QFileInfo(index))
        elif os.path.isdir(index):
            return __fileIconProvider.icon(QtGui.QFileIconProvider.Folder)
        elif QtGui.QIcon.hasThemeIcon(index):
            return QtGui.QIcon._fromTheme(index)
        elif default is not None:
            return default
        else:
            return QtGui.QIcon(getResourcePath("notfound", ["Icons"]))
    elif isinstance(index, int):
        #Try icon by int index in fileicon provider
        return __fileIconProvider.icon(index)
Exemple #7
0
def get_image(index, default=None):
    path = getResourcePath(index, ["Images", "Icons"])
    if path is not None:
        return QtGui.QPixmap(path)
    elif default is not None:
        return default
    else:
        return QtGui.QPixmap(getResourcePath("notfound", ["Icons"]))
Exemple #8
0
def get_std_icon(name, size=None):
    """Get standard platform icon
    Call 'show_std_icons()' for details"""
    if not name.startswith('SP_'):
        name = 'SP_' + name
    icon = QtGui.QWidget().style().standardIcon(getattr(QtGui.QStyle, name))
    if size is None:
        return icon
    else:
        return QtGui.QIcon(icon.pixmap(size, size))
Exemple #9
0
 def setup(self):
     logging.root.addHandler(self.handler)
     self.debug_levels_menu = QtGui.QMenu()
     self.debug_levels_action_group = QtGui.QActionGroup(self)
     for level, value in filter(lambda (key, value): type(key) == str,
                                logging._levelNames.iteritems()):
         action = QtGui.QAction(level.title(), self)
         action.setData({'name': level, 'level': value})
         action.setCheckable(True)
         self.debug_levels_action_group.addAction(action)
         self.debug_levels_menu.addAction(action)
Exemple #10
0
 def setupComboBoxLocation(self):
     #Combo Dir Model
     self.comboDirModel = QtGui.QDirModel(self)
     self.comboTreeView = QtGui.QTreeView(self)
     self.comboTreeView.setModel(self.comboDirModel)
     self.comboBoxLocation.setView(self.comboTreeView)
     self.comboBoxLocation.setModel(self.comboDirModel)
     #self.comboBoxLocation.setModelColumn(1)
     pIndex = self.treeViewFileSystem.rootIndex()
     rootPath = self.fileSystemProxyModel.filePath(pIndex)
     comboIndex = self.comboBoxLocation.model().index(rootPath)
     #self.comboBoxLocation.setRootModelIndex(comboIndex)
     self.comboBoxLocation.setCurrentIndex(comboIndex.row())
Exemple #11
0
    def initialize(self, editor):
        SideBarWidgetAddon.initialize(self, editor)
        self.background = self.editor.colours['gutter'] if 'gutter' in self.editor.colours else self.editor.colours['background']
        self.foreground = self.editor.colours["foreground"]
        self.normalFont = QtGui.QFont(self.editor.font)
        self.boldFont = QtGui.QFont(self.editor.font)
        self.boldFont.setBold(True)
        self.normalMetrics = QtGui.QFontMetrics(self.normalFont)
        self.boldMetrics = QtGui.QFontMetrics(self.boldFont)
        
        self.setFixedWidth(self.boldMetrics.width("#") + self.MARGIN * 2)

        self.editor.blockCountChanged.connect(self.updateWidth)
        self.editor.themeChanged.connect(self.updateColours)
Exemple #12
0
def create_menu(parent,
                settings,
                useSeparatorName=False,
                connectActions=False):
    text = settings.get("text", "Menu")
    menu = QtGui.QMenu(text, parent)
    menu.setObjectName(text2objectname(text, prefix="menu"))

    # attrs
    if settings.has_key("icon"):
        icon = settings["icon"]
        if isinstance(icon, basestring):
            icon = resources.getIcon(icon)
        menu.setIcon(icon)

    # actions
    actions = extend_menu(menu, settings.get("items", []), useSeparatorName)
    if connectActions:
        for action in actions:
            if hasattr(action, 'callback'):
                if action.isCheckable():
                    parent.connect(action, QtCore.SIGNAL('triggered(bool)'),
                                   action.callback)
                else:
                    parent.connect(action, QtCore.SIGNAL('triggered()'),
                                   action.callback)
    return menu, actions
Exemple #13
0
 def textCharFormat_spell_builder(self):
     format = QtGui.QTextCharFormat()
     format.setFontUnderline(True)
     format.setUnderlineColor(QtCore.Qt.red)
     format.setUnderlineStyle(QtGui.QTextCharFormat.SpellCheckUnderline)
     format.setBackground(QtCore.Qt.transparent)
     return format
Exemple #14
0
    def __init__(self, parent=None):
        QtGui.QDockWidget.__init__(self, parent)
        PMXBaseDock.__init__(self)
        self.setupUi(self)

        self.fileManager = self.application.fileManager

        #File System model
        self.fileSystemModel = QtGui.QFileSystemModel(self)
        self.fileSystemModel.setFilter(
            QtCore.QDir.NoDotAndDotDot | QtCore.QDir.AllEntries
        )  #http://doc.qt.nokia.com/latest/qdir.html#Filter-enum
        self.fileSystemModel.setRootPath(QtCore.QDir.rootPath())

        #Proxy para el file system tree view
        self.fileSystemProxyModel = SortFilterFileSystemProxyModel(self)
        self.fileSystemProxyModel.setSourceModel(self.fileSystemModel)

        self.setupComboBoxLocation()
        self.setupTreeViewFileSystem()

        self.treeViewFileSystem.installEventFilter(self)
        self.comboBoxLocation.installEventFilter(self)

        self.setupButtons()
Exemple #15
0
    def resizeEvent(self, event):
        q = self.parentWidget()
        fw = q.isFloating() and q.style().pixelMetric(
            QtGui.QStyle.PM_DockWidgetFrameWidth, None, q) or 0
        opt = QtGui.QStyleOptionDockWidgetV2()
        opt.initFrom(q)
        opt.rect = QtCore.QRect(
            QtCore.QPoint(fw, fw),
            QtCore.QSize(self.geometry().width() - (fw * 2),
                         self.geometry().height() - (fw * 2)))
        opt.title = q.windowTitle()
        opt.closable = hasFeature(q, QtGui.QDockWidget.DockWidgetClosable)
        opt.floatable = hasFeature(q, QtGui.QDockWidget.DockWidgetFloatable)

        floatRect = q.style().subElementRect(
            QtGui.QStyle.SE_DockWidgetFloatButton, opt, q)
        if not floatRect.isNull():
            self.floatButton.setGeometry(floatRect)
        closeRect = q.style().subElementRect(
            QtGui.QStyle.SE_DockWidgetCloseButton, opt, q)
        if not closeRect.isNull():
            self.closeButton.setGeometry(closeRect)
        top = fw
        if not floatRect.isNull():
            top = floatRect.y()
        elif not closeRect.isNull():
            top = closeRect.y()
        size = self.collapseButton.size()
        if not closeRect.isNull():
            size = self.closeButton.size()
        elif not floatRect.isNull():
            size = self.floatButton.size()
        collapseRect = QtCore.QRect(QtCore.QPoint(fw, top), size)
        self.collapseButton.setGeometry(collapseRect)
Exemple #16
0
    def __init__(self, parent):
        '''
        This label is managed from PMXMessageOverlay mixin, should not be
        used outside this module
        '''
        QtGui.QLabel.__init__(self, parent)
        
        self.setStyleSheet(self.STYLESHEET)
        self.linkActivated.connect(self.linkHandler)
        
        self.goe = QtGui.QGraphicsOpacityEffect(self)
        self.setGraphicsEffect(self.goe)

        self.timeoutTimer = QtCore.QTimer(self)
        self.timeoutTimer.setSingleShot(True)
        
        self.animationIn = QtCore.QPropertyAnimation(self.goe, "opacity")
        self.animationIn.setDuration(300)
        self.animationIn.setStartValue(0)
        self.animationIn.setEndValue(1.0)
        self.animationIn.finished.connect(self.timeoutTimer.start)

        self.animationOut = QtCore.QPropertyAnimation(self.goe, "opacity")
        self.animationOut.setDuration(300)
        self.animationOut.setStartValue(1.0)
        self.animationOut.setEndValue(0)
        self.animationOut.finished.connect(self.hide)

        self.timeoutTimer.timeout.connect(self.animationOut.start)
        self.hide()
Exemple #17
0
 def setCurrentEditor(self, editor):
     self.stackedWidget.setCurrentWidget(editor)
     self.labelTitle.setText(editor.title)
     scope = editor.getScope()
     tabTrigger = editor.getTabTrigger()
     keyEquivalent = editor.getKeyEquivalent()
     self.lineEditScope.setEnabled(scope is not None)
     self.lineKeyEquivalentActivation.setEnabled(keyEquivalent is not None)
     self.lineTabTriggerActivation.setEnabled(tabTrigger is not None)
     self.comboBoxActivation.setEnabled(tabTrigger is not None or keyEquivalent is not None)
     if scope is not None:
         self.lineEditScope.setText(scope)
     else:
         self.lineEditScope.clear()
     if not keyEquivalent and not tabTrigger:
         self.lineKeyEquivalentActivation.clear()
         self.lineTabTriggerActivation.clear()
         self.comboBoxActivation.setCurrentIndex(0)
         self.lineTabTriggerActivation.setVisible(False)
     else:
         if keyEquivalent is not None:
             self.lineKeyEquivalentActivation.setText(QtGui.QKeySequence(keyEquivalent).toString())
         if tabTrigger is not None:
             self.lineTabTriggerActivation.setText(tabTrigger)
         index = 0 if keyEquivalent else 1
         self.comboBoxActivation.setCurrentIndex(index)
Exemple #18
0
 def __init__(self, bundleEditor):
     super(PMXBundleFilter, self).__init__(bundleEditor)
     self.setupUi(self)
     self.manager = bundleEditor.application.supportManager
     self.setWindowFlags(QtCore.Qt.Dialog)
     self.proxy = QtGui.QSortFilterProxyModel(self)
     self.tableBundleItems.setModel(self.proxy)
Exemple #19
0
 def __init__(self, editor):
     QtGui.QWidget.__init__(self, editor)
     self.editor = editor
     self.horizontalLayout = QtGui.QHBoxLayout(self)
     self.horizontalLayout.setObjectName("horizontalLayout")
     self.horizontalLayout.setSpacing(0)
     self.horizontalLayout.setMargin(0)
Exemple #20
0
class ConfigureTreeNode(TreeNodeBase):
    NAMESPACE = ""
    ICON = QtGui.QIcon()
    TITLE = ""

    def __init__(self, name, parent=None):
        TreeNodeBase.__init__(self, name, parent)
        self.setTitle(self.TITLE)
        self.setIcon(self.ICON)

    def filterString(self):
        return self.nodeName() + self.title() + reduce(
            lambda initial, child: initial + child.filterString(),
            self.childrenNodes, "")

    def title(self):
        return self.__title

    def setTitle(self, title):
        self.__title = title

    def icon(self):
        return self.__icon

    def setIcon(self, icon):
        self.__icon = icon
Exemple #21
0
    def __init__(self, parent):
        QtGui.QPlainTextEdit.__init__(self, parent)
        font = self.document().defaultFont()
        font.setPixelSize(1)
        self.document().setDefaultFont(font)
        self.setWordWrapMode(QtGui.QTextOption.NoWrap)
        self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setReadOnly(True)
        self.setCenterOnScroll(True)
        self.setMouseTracking(True)
        self.viewport().setCursor(QtCore.Qt.PointingHandCursor)
        self.setTextInteractionFlags(QtCore.Qt.NoTextInteraction)

        self.editor = None
        self.highlighter = None
        self.lines_count = 0

        self.goe = QtGui.QGraphicsOpacityEffect()
        self.setGraphicsEffect(self.goe)
        self.goe.setOpacity(50)
        self.animation = QtCore.QPropertyAnimation(self.goe, "opacity")

        self.slider = SliderArea(self)
        self.slider.show()
        self.setFixedWidth(60)
Exemple #22
0
 def eventFilter(self, obj, event):
     if event.type() == QtCore.QEvent.KeyPress and obj == self.lineKeyEquivalentActivation:
         keyseq = int(event.modifiers()) + event.key()
         self.stackedWidget.currentWidget().setKeyEquivalent(keyseq)
         self.lineKeyEquivalentActivation.setText(QtGui.QKeySequence(keyseq).toString())
         return True
     return super(PMXBundleEditor, self).eventFilter(obj, event)
Exemple #23
0
    def _vertical_split(self, spl, idx, hs):
        """ Returns a tuple of the splitter and index where the new tab widget
        should be put.
        """

        if spl.orientation() == QtCore.Qt.Horizontal:
            if hs == self._HS_EAST:
                idx += 1
        elif spl is self and spl.count() == 1:
            # The splitter is the root and only has one child so we can just
            # change its orientation.
            spl.setOrientation(QtCore.Qt.Horizontal)

            if hs == self._HS_EAST:
                idx = -1
        else:
            new_spl = QtGui.QSplitter(QtCore.Qt.Horizontal)
            new_spl.addWidget(spl.widget(idx))
            spl.insertWidget(idx, new_spl)

            if hs == self._HS_EAST:
                idx = -1
            else:
                idx = 0

            spl = new_spl

        return (spl, idx)
Exemple #24
0
 def trigger(self):
     trigger = []
     if self.tabTrigger != None:
         trigger.append(u"%s⇥" % (self.tabTrigger))
     if self.keyEquivalent != None:
         trigger.append(u"%s" %
                        QtGui.QKeySequence(self.keyEquivalent).toString())
     return ", ".join(trigger)
Exemple #25
0
 def showTableViewFilesContextMenu(self, point):
     index = self.tableViewFiles.indexAt(point)
     if index.isValid():
         # TODO Obtener el item y armar el menu
         menu = QtGui.QMenu(self)
         for action in self.actions:
             menu.addAction(action["name"])
         menu.popup(self.tableViewFiles.mapToGlobal(point))
Exemple #26
0
    def setupUi(self):
        layout = QtGui.QHBoxLayout()
        layout.setSpacing(0)
        layout.setMargin(0)

        self.buttonBold = QtGui.QPushButton("B")
        self.buttonBold.setCheckable(True)
        font = QtGui.QFont()
        font.setWeight(QtGui.QFont.Bold)
        self.buttonBold.setFont(font)
        self.buttonBold.setMaximumWidth(30)

        self.buttonItalic = QtGui.QPushButton("I")
        self.buttonItalic.setCheckable(True)
        font = QtGui.QFont()
        font.setItalic(True)
        self.buttonItalic.setFont(font)
        self.buttonItalic.setMaximumWidth(30)

        self.buttonUnderline = QtGui.QPushButton("U")
        self.buttonUnderline.setCheckable(True)
        font = QtGui.QFont()
        font.setUnderline(True)
        self.buttonUnderline.setFont(font)
        self.buttonUnderline.setMaximumWidth(30)

        layout.addWidget(self.buttonBold)
        layout.addWidget(self.buttonItalic)
        layout.addWidget(self.buttonUnderline)
        self.setLayout(layout)
Exemple #27
0
 def paintEvent(self, event):
     p = QtGui.QStylePainter(self)
     q = self.parentWidget()
     fw = q.isFloating() and q.style().pixelMetric(
         QtGui.QStyle.PM_DockWidgetFrameWidth, None, q) or 0
     mw = q.style().pixelMetric(QtGui.QStyle.PM_DockWidgetTitleMargin, None,
                                q)
     titleOpt = QtGui.QStyleOptionDockWidgetV2()
     titleOpt.initFrom(q)
     titleOpt.rect = QtCore.QRect(QtCore.QPoint(fw + mw + self.collapseButton.size().width(), fw),
         QtCore.QSize(
            self.geometry().width() - (fw * 2) - \
            mw - self.collapseButton.size().width(),
            self.geometry().height() - (fw * 2)))
     titleOpt.title = q.windowTitle()
     titleOpt.closable = hasFeature(q, QtGui.QDockWidget.DockWidgetClosable)
     titleOpt.floatable = hasFeature(q,
                                     QtGui.QDockWidget.DockWidgetFloatable)
     p.drawControl(QtGui.QStyle.CE_DockWidgetTitle, titleOpt)
Exemple #28
0
    def setTabTextColor(self, w, color=None):
        """ Set the tab text color on a particular widget w
        """
        tw, tidx = self._tab_widget(w)

        if tw is not None:
            if color is None:
                # null color reverts to foreground role color
                color = QtGui.QColor()
            tw.tabBar().setTabTextColor(tidx, color)
Exemple #29
0
def get_family(families):
    """Return the first installed font family in family list"""
    if not isinstance(families, list):
        families = [families]
    for family in families:
        if font_is_installed(family):
            return family
    else:
        print "Warning: None of the following fonts is installed: %r" % families
        return QtGui.QFont().family()
Exemple #30
0
def center_widget(widget, scale=None):
    """
    Center de widget in the screen
    Scale is a tuple with width and height ex: (0.7, 0.65)
    """
    screen = QtGui.QDesktopWidget().screenGeometry()
    if scale is not None:
        widget.resize(screen.width() * scale[0], screen.height() * scale[1])
    widget.move((screen.width() - widget.size().width()) / 2,
                (screen.height() - widget.size().height()) / 2)