~ben-uberelvis/python-snippets/python-snippets

« back to all changes in this revision

Viewing changes to pykde4/solid_device.py

  • Committer: Jono Bacon
  • Date: 2010-03-24 06:59:55 UTC
  • mfrom: (49.1.1 python-snippets)
  • Revision ID: jono@ubuntu.com-20100324065955-g6nbs0zaxhxek62m
A bunch of fantastic KDE snippets thanks to nixternal!

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
# [SNIPPET_NAME: Solid (Device)]
 
4
# [SNIPPET_CATEGORIES: PyKDE4]
 
5
# [SNIPPET_DESCRIPTION: Device integration framework for a device]
 
6
# [SNIPPET_AUTHOR: Jim Bublitz <jbublitz@nwinternet.com>]
 
7
# [SNIPPET_LICENSE: GPL]
 
8
# [SNIPPET_DOCS: http://api.kde.org/pykde-4.3-api/solid/index.html, http://api.kde.org/pykde-4.3-api/solid/Solid.Device.html]
 
9
 
 
10
from PyQt4.QtCore import SIGNAL, Qt
 
11
from PyQt4.QtGui import QTreeWidget, QTreeWidgetItem, QLabel
 
12
 
 
13
from PyKDE4.kdecore import i18n
 
14
from PyKDE4.solid import Solid
 
15
from PyKDE4.kdeui import KVBox
 
16
 
 
17
helpText = """The Solid class discovers information about the hardware on a machine.
 
18
 
 
19
Solid.Device is the base class for the various types of devices. It provides a list
 
20
of the types of devices on the machine. The table below shows the data for your
 
21
machine.
 
22
 
 
23
Individual device type classes can be interrogated to discover specific information
 
24
suitable to each device type.
 
25
"""
 
26
 
 
27
class MainFrame(KVBox):
 
28
    def __init__(self, parent=None):
 
29
        KVBox.__init__(self, parent)
 
30
        self.help  = QLabel (i18n (helpText), self)
 
31
        self.layout ().setAlignment (self.help, Qt.AlignHCenter)
 
32
        self.setSpacing (10)
 
33
        
 
34
        display = QTreeWidget (self)        
 
35
        display.setHeaderLabels (["Product", "Vendor", "UDI"])
 
36
        display.setColumnWidth (0, 300)
 
37
 
 
38
        # retrieve a list of Solid.Device for this machine
 
39
        deviceList = Solid.Device.allDevices ()
 
40
        
 
41
        for device in deviceList:
 
42
            item = QTreeWidgetItem (display, [device.product (), device.vendor (), device.udi ()])
 
43
 
 
44
        
 
45
        
 
46
 
 
47
# This example can be run standalone
 
48
 
 
49
if __name__ == '__main__':
 
50
 
 
51
    import sys
 
52
    
 
53
    from PyKDE4.kdecore import KCmdLineArgs, KAboutData, KLocalizedString, ki18n
 
54
    from PyKDE4.kdeui import KApplication, KMainWindow
 
55
    
 
56
    
 
57
            
 
58
    class MainWin (KMainWindow):
 
59
        def __init__ (self, *args):
 
60
            KMainWindow.__init__ (self)
 
61
 
 
62
            self.resize(640, 480)
 
63
            self.setCentralWidget (MainFrame (self))
 
64
    
 
65
    #-------------------- main ------------------------------------------------
 
66
    
 
67
    appName     = "Solid_Devices"
 
68
    catalog     = ""
 
69
    programName = ki18n ("Solid_Devices")                 #ki18n required here
 
70
    version     = "1.0"
 
71
    description = ki18n ("Solid.Devices Example")         #ki18n required here
 
72
    license     = KAboutData.License_GPL
 
73
    copyright   = ki18n ("(c) 2007 Jim Bublitz")    #ki18n required here
 
74
    text        = ki18n ("none")                    #ki18n required here
 
75
    homePage    = "www.riverbankcomputing.com"
 
76
    bugEmail    = "jbublitz@nwinternet.com"
 
77
 
 
78
    aboutData   = KAboutData (appName, catalog, programName, version, description,
 
79
                              license, copyright, text, homePage, bugEmail)
 
80
 
 
81
    # ki18n required for first two addAuthor () arguments
 
82
    aboutData.addAuthor (ki18n ("Troy Melhase"), ki18n ("original concept"))
 
83
    aboutData.addAuthor (ki18n ("Jim Bublitz"), ki18n ("pykdedocs"))
 
84
    
 
85
    KCmdLineArgs.init (sys.argv, aboutData)
 
86
    
 
87
    app = KApplication ()
 
88
    mainWindow = MainWin (None, "main window")
 
89
    mainWindow.show()
 
90
    app.connect (app, SIGNAL ("lastWindowClosed ()"), app.quit)
 
91
    app.exec_ ()