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]
10
from PyQt4.QtCore import SIGNAL, Qt
11
from PyQt4.QtGui import QTreeWidget, QTreeWidgetItem, QLabel
13
from PyKDE4.kdecore import i18n
14
from PyKDE4.solid import Solid
15
from PyKDE4.kdeui import KVBox
17
helpText = """The Solid class discovers information about the hardware on a machine.
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.
23
We use Solid.Device.allDevices () to get a list of all devices, and then
24
filter it for Solid.Processor types.
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)
34
display = QTreeWidget ()
35
display.setHeaderLabels (["Processor", "Max Speed", "Number", "Change Freq"])
37
# retrieve a list of Solid.Device for this machine
38
deviceList = Solid.Device.allDevices ()
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 ()),
47
str (cpu.canChangeFrequency ())])
52
# This example can be run standalone
54
if __name__ == '__main__':
58
from PyKDE4.kdecore import KCmdLineArgs, KAboutData, KLocalizedString, ki18n
59
from PyKDE4.kdeui import KApplication, KMainWindow
62
class MainWin (KMainWindow):
63
def __init__ (self, *args):
64
KMainWindow.__init__ (self)
67
self.setCentralWidget (MainFrame (self))
70
#-------------------- main ------------------------------------------------
72
appName = "Solid_StorageDrive"
74
programName = ki18n ("Solid_StorageDrive") #ki18n required here
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"
83
aboutData = KAboutData (appName, catalog, programName, version, description,
84
license, copyright, text, homePage, bugEmail)
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"))
90
KCmdLineArgs.init (sys.argv, aboutData)
93
mainWindow = MainWin (None, "main window")
95
app.connect (app, SIGNAL ("lastWindowClosed ()"), app.quit)