E4Gui/E4ToolBox.py

Sat, 02 Jan 2010 15:11:35 +0000

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 02 Jan 2010 15:11:35 +0000
changeset 12
1d8dd9706f46
parent 0
de9c2efb9d02
child 13
1af94a91f439
permissions
-rw-r--r--

First commit after changing to Python 3.1.

# -*- coding: utf-8 -*-

# Copyright (c) 2008 - 2009 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing a horizontal and a vertical toolbox class.
"""

from PyQt4.QtGui import QToolBox, QTabWidget

from .E4TabWidget import E4TabWidget

class E4VerticalToolBox(QToolBox):
    """
    Class implementing a ToolBox class substituting QToolBox to support wheel events.
    """
    def __init__(self, parent = None):
        """
        Constructor
        
        @param parent reference to the parent widget (QWidget)
        """
        QToolBox.__init__(self, parent)
    
    def wheelEvent(self, event):
        """
        Protected slot to support wheel events.
        
        @param reference to the wheel event (QWheelEvent)
        """
        index = self.currentIndex()
        if event.delta() > 0:
            index -= 1
        else:
            index += 1
        if index < 0:
            index = self.count() - 1
        elif index == self.count():
            index = 0
        
        self.setCurrentIndex(index)
        
        event.accept()

class E4HorizontalToolBox(E4TabWidget):
    """
    Class implementing a vertical QToolBox like widget.
    """
    def __init__(self, parent = None):
        """
        Constructor
        
        @param parent reference to the parent widget (QWidget)
        """
        E4TabWidget.__init__(self, parent)
        self.setTabPosition(QTabWidget.West)
    
    def addItem(self, widget, icon, text):
        """
        Public method to add a widget to the toolbox.
        
        @param widget reference to the widget to be added (QWidget)
        @param icon the icon to be shown (QIcon)
        @param text the text to be shown (string)
        @return index of the added widget (integer)
        """
        index = self.addTab(widget, icon, "")
        self.setTabToolTip(index, text)
        return index
    
    def insertItem(self, index, widget, icon, text):
        """
        Public method to add a widget to the toolbox.
        
        @param index position at which the widget should be inserted (integer)
        @param widget reference to the widget to be added (QWidget)
        @param icon the icon to be shown (QIcon)
        @param text the text to be shown (string)
        @return index of the added widget (integer)
        """
        index = self.insertTab(index, widget, icon, "")
        self.setTabToolTip(index, text)
        return index
    
    def setItemToolTip(self, index, toolTip):
        """
        Public method to set the tooltip of an item.
        
        @param index index of the item (integer)
        @param toolTip tooltip text to be set (string)
        """
        self.setTabToolTip(index, toolTip)
    
    def setItemEnabled(self, index, enabled):
        """
        Public method to set the enabled state of an item.
        
        @param index index of the item (integer)
        @param enabled flag indicating the enabled state (boolean)
        """
        self.setTabEnabled(index, enabled)

eric ide

mercurial