Source

pyqtwidgets / tests / test_widgetlist.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from PyQt4.QtCore import *
from PyQt4.QtGui import *

from qtwidgets.widgetlist import WidgetList



def test_widgetlist():
    # Firefox-like add-list
    class AddOn(QWidget):
        active = None
        
        def __init__(self, parent, name):
            QWidget.__init__(self, parent)
            self.hblayout = QHBoxLayout(self)
            self.label = QLabel("Addon <b>%s</b>" % name, self)
            self.label.setFocusProxy(parent)
            self.hblayout.addWidget(self.label)
            self.hblayout.addStretch()
            
            self.buttons = QWidget(self)
            self.hblayout.addWidget(self.buttons)
            self.vblayout = QVBoxLayout(self.buttons)
            
            self.prefs = QPushButton("Preferences", self.buttons)
            self.vblayout.addWidget(self.prefs)
            self.uninstall = QPushButton("Uninstall", self.buttons)
            self.vblayout.addWidget(self.uninstall)
            
            self.buttons.hide()            
            self.setFixedHeight(self.sizeHint().height())
           
        def show_actions(self):
            self.buttons.show()
            self.setFixedHeight(self.sizeHint().height())
            self.parent().update()
            
        def hide_actions(self):
            self.buttons.hide()
            self.setFixedHeight(self.sizeHint().height())

    import sys
    app = QApplication(sys.argv)
    win = WidgetList()
    win.resize(640,480)
    win.show()
    def toggle(add_on):
        if AddOn.active:
            AddOn.active.hide_actions()
        add_on.show_actions()
        AddOn.active = add_on

    win.connect(win, SIGNAL("widget_clicked"), toggle)
    add_ons = []
    for i in range(5):
        a = AddOn(win, i)
        win.add_widget(a)
        add_ons.append(a)
        #print a.sizeHint(), a.size(), a.label.size(), a.uninstall.size(), a.prefs.size()
    l = QLabel("<a href='http://www.google.de'>Updates available</a>", win)
    win.insert_widget(0, l)
    app.exec_()
    print win.current_row_index()



if __name__ == "__main__":
    test_widgetlist()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.