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

« back to all changes in this revision

Viewing changes to pykde4/solid_processor.py

  • Committer: Richard A. Johnson
  • Date: 2010-03-22 21:24:55 UTC
  • mto: This revision was merged to the branch mainline in revision 50.
  • Revision ID: nixternal@ubuntu.com-20100322212455-3g71ntumplad9xgj
Adding PyKDE4 snippets - more to come in the future

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
# [SNIPPET_NAME: Solid (Processor)]
 
4
# [SNIPPET_CATEGORIES: PyKDE4]
 
5
# [SNIPPET_DESCRIPTION: Device integration framework for a processor]
 
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.Processor.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.Processor objects retrieve information about the processor on a machine. The
 
20
table below shows the data for your machine. Not all computers make processor info
 
21
accessible, so the table may be empty.
 
22
 
 
23
We use Solid.Device.allDevices () to get a list of all devices, and then
 
24
filter it for Solid.Processor types.
 
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 ()        
 
35
        display.setHeaderLabels (["Processor", "Max Speed", "Number", "Change Freq"])
 
36
        
 
37
        # retrieve a list of Solid.Device for this machine
 
38
        deviceList = Solid.Device.allDevices ()
 
39
 
 
40
        # filter the list of all devices and display matching results
 
41
        for device in deviceList:
 
42
            if device.isDeviceInterface (Solid.DeviceInterface.Processor):
 
43
                cpu = device.asDeviceInterface (Solid.DeviceInterface.Processor)
 
44
                QTreeWidgetItem (display, [device.product (),
 
45
                                           str (cpu.maxSpeed ()),
 
46
                                           str (cpu.number ()),
 
47
                                           str (cpu.canChangeFrequency ())])
 
48
 
 
49
        
 
50
        
 
51
 
 
52
# This example can be run standalone
 
53
 
 
54
if __name__ == '__main__':
 
55
 
 
56
    import sys
 
57
    
 
58
    from PyKDE4.kdecore import KCmdLineArgs, KAboutData, KLocalizedString, ki18n
 
59
    from PyKDE4.kdeui import KApplication, KMainWindow
 
60
    
 
61
    
 
62
    class MainWin (KMainWindow):
 
63
        def __init__ (self, *args):
 
64
            KMainWindow.__init__ (self)
 
65
 
 
66
            self.resize(640, 480)
 
67
            self.setCentralWidget (MainFrame (self))
 
68
    
 
69
    
 
70
    #-------------------- main ------------------------------------------------
 
71
    
 
72
    appName     = "Solid_StorageDrive"
 
73
    catalog     = ""
 
74
    programName = ki18n ("Solid_StorageDrive")                 #ki18n required here
 
75
    version     = "1.0"
 
76
    description = ki18n ("Solid.StorageDrive Example")         #ki18n required here
 
77
    license     = KAboutData.License_GPL
 
78
    copyright   = ki18n ("(c) 2007 Jim Bublitz")    #ki18n required here
 
79
    text        = ki18n ("none")                    #ki18n required here
 
80
    homePage    = "www.riverbankcomputing.com"
 
81
    bugEmail    = "jbublitz@nwinternet.com"
 
82
 
 
83
    aboutData   = KAboutData (appName, catalog, programName, version, description,
 
84
                              license, copyright, text, homePage, bugEmail)
 
85
 
 
86
    # ki18n required for first two addAuthor () arguments
 
87
    aboutData.addAuthor (ki18n ("Troy Melhase"), ki18n ("original concept"))
 
88
    aboutData.addAuthor (ki18n ("Jim Bublitz"), ki18n ("pykdedocs"))
 
89
    
 
90
    KCmdLineArgs.init (sys.argv, aboutData)
 
91
    
 
92
    app = KApplication ()
 
93
    mainWindow = MainWin (None, "main window")
 
94
    mainWindow.show()
 
95
    app.connect (app, SIGNAL ("lastWindowClosed ()"), app.quit)
 
96
    app.exec_ ()