Merge lp:~nixternal/python-snippets/pykde4 into lp:~jonobacon/python-snippets/trunk

Proposed by Rich Johnson
Status: Merged
Merged at revision: not available
Proposed branch: lp:~nixternal/python-snippets/pykde4
Merge into: lp:~jonobacon/python-snippets/trunk
Diff against target: 1926 lines (+1836/-0)
18 files modified
pykde4/kaboutapplicationdialog.py (+94/-0)
pykde4/kaboutkdedialog.py (+85/-0)
pykde4/kapplication.py (+72/-0)
pykde4/katepart.py (+50/-0)
pykde4/kcolorbutton.py (+130/-0)
pykde4/kcolordialog.py (+93/-0)
pykde4/kcombobox.py (+119/-0)
pykde4/kdatepicker.py (+98/-0)
pykde4/kfontdialog.py (+96/-0)
pykde4/kstandarddirs.py (+113/-0)
pykde4/solid_audiointerface.py (+136/-0)
pykde4/solid_demo.py (+101/-0)
pykde4/solid_device.py (+91/-0)
pykde4/solid_networkinterface.py (+118/-0)
pykde4/solid_processor.py (+96/-0)
pykde4/solid_storageaccess.py (+104/-0)
pykde4/solid_storagedrive.py (+126/-0)
pykde4/solid_storagevolume.py (+114/-0)
To merge this branch: bzr merge lp:~nixternal/python-snippets/pykde4
Reviewer Review Type Date Requested Status
Jono Bacon Pending
Review via email: mp+22004@code.launchpad.net

Description of the change

Here are your PyKDE4 snippets, all SNIPPET_'d out, with doc links, and all!

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added directory 'pykde4'
=== added file 'pykde4/kaboutapplicationdialog.py'
--- pykde4/kaboutapplicationdialog.py 1970-01-01 00:00:00 +0000
+++ pykde4/kaboutapplicationdialog.py 2010-03-24 06:55:25 +0000
@@ -0,0 +1,94 @@
1#!/usr/bin/env python
2
3# [SNIPPET_NAME: About Application Dialog]
4# [SNIPPET_CATEGORIES: PyKDE4]
5# [SNIPPET_DESCRIPTION: PyKDE4 example showing the About application dialog]
6# [SNIPPET_AUTHOR: Jim Bublitz <jbublitz@nwinternet.com>]
7# [SNIPPET_LICENSE: GPL]
8# [SNIPPET_DOCS: http://api.kde.org/pykde-4.3-api/kdecore/KAboutData.html]
9
10from PyQt4.QtCore import SIGNAL, Qt
11from PyQt4.QtGui import QLabel, QSizePolicy
12
13from PyKDE4.kdecore import i18n, ki18n, KAboutData
14from PyKDE4.kdeui import KVBox, KHBox, KPushButton, KAboutApplicationDialog
15
16helpText = """The KAboutApplicationDialog is normally displayed from the
17applications Help menu.
18
19It requires a KAboutData object to provide the information displayed in
20the dialog. This is usually the same KAboutData object constructed when
21you start your program, although a different object could be used.
22
23Press the button below to display the dialog.
24"""
25
26dialogName = "KAboutApplicationDialog"
27
28appName = "kaboutapplicationdialog.py"
29catalog = ""
30programName = ki18n ("kaboutapplicationdialog") #ki18n required here
31version = "1.0"
32description = ki18n ("KAboutApplicationDialog Example") #ki18n required here
33license = KAboutData.License_GPL
34copyright = ki18n ("(c) 2007 Jim Bublitz") #ki18n required here
35text = ki18n ("none") #ki18n required here
36homePage = "www.riverbankcomputing.com"
37bugEmail = "jbublitz@nwinternet.com"
38
39aboutData = KAboutData (appName, catalog, programName, version, description,
40 license, copyright, text, homePage, bugEmail)
41
42# ki18n required for first two addAuthor () arguments
43aboutData.addAuthor (ki18n ("Troy Melhase"), ki18n ("original concept"))
44aboutData.addAuthor (ki18n ("Jim Bublitz"), ki18n ("pykdedocs"))
45
46
47class MainFrame(KVBox):
48 def __init__(self, parent):
49 KVBox.__init__(self, parent)
50 self.help = QLabel (helpText, self)
51 self.layout ().setAlignment (self.help, Qt.AlignHCenter)
52
53 hBox = KHBox (self)
54 self.button = KPushButton(i18n("Show %s" % dialogName), hBox)
55 self.button.setMaximumSize (250, 30)
56
57 self.connect(self.button, SIGNAL('clicked()'), self.showDialog)
58
59 def showDialog(self):
60 dlg = KAboutApplicationDialog (aboutData, self.parent ())
61 dlg.exec_ ()
62
63
64
65# This example can be run standalone
66
67if __name__ == '__main__':
68
69 import sys
70
71 from PyQt4.QtCore import SIGNAL
72
73 from PyKDE4.kdecore import KCmdLineArgs, KAboutData, KLocalizedString, ki18n
74 from PyKDE4.kdeui import KApplication, KMainWindow
75
76
77 class MainWin (KMainWindow):
78 def __init__ (self, *args):
79 KMainWindow.__init__ (self)
80
81 self.resize (640, 480)
82 self.setCentralWidget (MainFrame (self))
83
84
85 #-------------------- main ------------------------------------------------
86
87
88 KCmdLineArgs.init (sys.argv, aboutData)
89
90 app = KApplication ()
91 mainWindow = MainWin (None, "main window")
92 mainWindow.show()
93 app.connect (app, SIGNAL ("lastWindowClosed ()"), app.quit)
94 app.exec_ ()
095
=== added file 'pykde4/kaboutkdedialog.py'
--- pykde4/kaboutkdedialog.py 1970-01-01 00:00:00 +0000
+++ pykde4/kaboutkdedialog.py 2010-03-24 06:55:25 +0000
@@ -0,0 +1,85 @@
1#!/usr/bin/env python
2
3# [SNIPPET_NAME: About KDE Dialog]
4# [SNIPPET_CATEGORIES: PyKDE4]
5# [SNIPPET_DESCRIPTION: PyKDE4 example showing the About KDE dialog]
6# [SNIPPET_AUTHOR: Jim Bublitz <jbublitz@nwinternet.com>]
7# [SNIPPET_LICENSE: GPL]
8# [SNIPPET_DOCS: http://api.kde.org/pykde-4.3-api/kdecore/KAboutData.html]
9
10from PyQt4.QtCore import SIGNAL, Qt
11from PyQt4.QtGui import QLabel
12
13from PyKDE4.kdecore import i18n
14from PyKDE4.kdeui import KVBox, KHBox, KPushButton, KAboutKdeDialog
15
16helpText = """The KAboutKdeDialog is the dialog that is normally
17available from the help menu.
18
19Press the button below to display the dialog.
20"""
21
22dialogName = "KAboutKdeDialog"
23
24class MainFrame(KVBox):
25 def __init__(self, parent):
26 KVBox.__init__(self, parent)
27 self.help = QLabel (helpText, self)
28 self.layout ().setAlignment (self.help, Qt.AlignHCenter)
29
30 hBox = KHBox (self)
31 self.button = KPushButton(i18n("Show %s" % dialogName), hBox)
32 self.button.setMaximumSize (250, 30)
33
34 self.connect(self.button, SIGNAL('clicked()'), self.showDialog)
35
36 def showDialog(self):
37 dlg = KAboutKdeDialog (self.parent ())
38 dlg.exec_ ()
39
40
41
42# This example can be run standalone
43
44if __name__ == '__main__':
45
46 import sys
47
48 from PyKDE4.kdecore import KCmdLineArgs, KAboutData, KLocalizedString, ki18n
49 from PyKDE4.kdeui import KApplication, KMainWindow
50
51
52 class MainWin (KMainWindow):
53 def __init__ (self, *args):
54 KMainWindow.__init__ (self)
55
56 self.resize(640, 480)
57 self.setCentralWidget (MainFrame (self))
58
59 #-------------------- main ------------------------------------------------
60
61 appName = "kaboutkdedialog.py"
62 catalog = ""
63 programName = ki18n ("kaboutkdedialog")
64 version = "1.0"
65 description = ki18n ("KAboutKdeDialog Example")
66 license = KAboutData.License_GPL
67 copyright = ki18n ("(c) 2007 Jim Bublitz")
68 text = ki18n ("none")
69 homePage = "www.riverbankcomputing.com"
70 bugEmail = "jbublitz@nwinternet.com"
71
72 aboutData = KAboutData (appName, catalog, programName, version, description,
73 license, copyright, text, homePage, bugEmail)
74
75 # ki18n required for first two addAuthor () arguments
76 aboutData.addAuthor (ki18n ("Troy Melhase"), ki18n ("original concept"))
77 aboutData.addAuthor (ki18n ("Jim Bublitz"), ki18n ("pykdedocs"))
78
79 KCmdLineArgs.init (sys.argv, aboutData)
80
81 app = KApplication ()
82 mainWindow = MainWin (None, "main window")
83 mainWindow.show()
84 app.connect (app, SIGNAL ("lastWindowClosed ()"), app.quit)
85 app.exec_ ()
086
=== added file 'pykde4/kapplication.py'
--- pykde4/kapplication.py 1970-01-01 00:00:00 +0000
+++ pykde4/kapplication.py 2010-03-24 06:55:25 +0000
@@ -0,0 +1,72 @@
1#!/usr/bin/env python
2
3# [SNIPPET_NAME: Main Window Application]
4# [SNIPPET_CATEGORIES: PyKDE4]
5# [SNIPPET_DESCRIPTION: PyKDE4 example showing KMainWindow and KApplication]
6# [SNIPPET_AUTHOR: Jim Bublitz <jbublitz@nwinternet.com>]
7# [SNIPPET_LICENSE: GPL]
8# [SNIPPET_DOCS: http://api.kde.org/pykde-4.3-api/kdeui/KApplication.html, http://api.kde.org/pykde-4.3-api/kdeui/KMainWindow.html]
9
10import sys
11
12from PyKDE4.kdecore import ki18n, KAboutData, KCmdLineArgs
13from PyKDE4.kdeui import KApplication, KMainWindow
14
15from PyQt4.QtGui import QLabel
16
17runner = True
18
19helpText = """This short program is the basic KDE application.
20
21It uses KAboutData to initialize some basic program information
22that is used by KDE (beyond simply setting up the About dialog
23box in a more complex program).
24
25It creates a KMainWindow, so the program has a place to display
26its output and interact with users.
27
28It also creates a KApplication object, which is necessary for
29the use of most KDE widgets and other classes, and makes
30available access to standard information about things like
31icons, directory locations, colors, fonts and similar data.
32
33Lastly, it starts an event loop (app.exec_) to allow a user
34to interact with the program.
35
36Click the button to launch the application.
37"""
38
39
40
41class MainWindow (KMainWindow):
42 def __init__ (self):
43 KMainWindow.__init__ (self)
44
45 self.resize (640, 480)
46 label = QLabel ("This is a simple PyKDE4 program", self)
47 label.setGeometry (10, 10, 200, 20)
48
49#--------------- main ------------------
50if __name__ == '__main__':
51
52 appName = "KApplication"
53 catalog = ""
54 programName = ki18n ("KApplication")
55 version = "1.0"
56 description = ki18n ("KApplication/KMainWindow/KAboutData example")
57 license = KAboutData.License_GPL
58 copyright = ki18n ("(c) 2007 Jim Bublitz")
59 text = ki18n ("none")
60 homePage = "www.riverbankcomputing.com"
61 bugEmail = "jbublitz@nwinternet.com"
62
63 aboutData = KAboutData (appName, catalog, programName, version, description,
64 license, copyright, text, homePage, bugEmail)
65
66
67 KCmdLineArgs.init (sys.argv, aboutData)
68
69 app = KApplication ()
70 mainWindow = MainWindow ()
71 mainWindow.show ()
72 app.exec_ ()
073
=== added file 'pykde4/katepart.py'
--- pykde4/katepart.py 1970-01-01 00:00:00 +0000
+++ pykde4/katepart.py 2010-03-24 06:55:25 +0000
@@ -0,0 +1,50 @@
1#!/usr/bin/env python
2
3# [SNIPPET_NAME: KPart (Kate)]
4# [SNIPPET_CATEGORIES: PyKDE4]
5# [SNIPPET_DESCRIPTION: KPart example using the Kate part]
6# [SNIPPET_AUTHOR: Jonathan Riddell <jriddell@ubuntu.com>]
7# [SNIPPET_LICENSE: GPL]
8# [SNIPPET_DOCS: http://api.kde.org/pykde-4.3-api/kdecore/KLibLoader.html, http://api.kde.org/pykde-4.3-api/kparts/index.html]
9
10import sys
11
12from PyKDE4.kdecore import *
13from PyKDE4.kdeui import *
14from PyKDE4.kparts import *
15
16from PyQt4.QtGui import QLabel
17
18class MainWindow (KMainWindow):
19 def __init__ (self):
20 KMainWindow.__init__(self)
21
22 self.resize(640, 480)
23
24 factory = KLibLoader.self().factory("katepart")
25 part = factory.create(self, "KatePart")
26 self.setCentralWidget(part.widget())
27
28#--------------- main ------------------
29if __name__ == '__main__':
30
31 appName = "katepart_example"
32 catalog = ""
33 programName = ki18n("Kate Part Example")
34 version = "1.0"
35 description = ki18n("Example loading a Kate Part")
36 license = KAboutData.License_GPL
37 copyright = ki18n("(c) 2009 Canonical Ltd")
38 text = ki18n("none")
39 homePage = "www.kubuntu.org"
40 bugEmail = "jriddell@ubuntu.com"
41
42 aboutData = KAboutData(appName, catalog, programName, version, description,
43 license, copyright, text, homePage, bugEmail)
44
45 KCmdLineArgs.init(sys.argv, aboutData)
46
47 app = KApplication()
48 mainWindow = MainWindow()
49 mainWindow.show()
50 app.exec_()
051
=== added file 'pykde4/kcolorbutton.py'
--- pykde4/kcolorbutton.py 1970-01-01 00:00:00 +0000
+++ pykde4/kcolorbutton.py 2010-03-24 06:55:25 +0000
@@ -0,0 +1,130 @@
1#!/usr/bin/env python
2
3# [SNIPPET_NAME: Pushbutton (Color Selection)]
4# [SNIPPET_CATEGORIES: PyKDE4]
5# [SNIPPET_DESCRIPTION: A pushbutton to display or allow user selection of a color]
6# [SNIPPET_AUTHOR: Jim Bublitz <jbublitz@nwinternet.com>]
7# [SNIPPET_LICENSE: GPL]
8# [SNIPPET_DOCS: http://api.kde.org/pykde-4.3-api/kdeui/KColorButton.html]
9
10from PyQt4.QtCore import SIGNAL, Qt
11from PyQt4.QtGui import QLabel
12
13from PyKDE4.kdecore import i18n
14from PyKDE4.kdeui import KVBox, KHBox, KColorButton, KColorCells, KColorCombo, KColorPatch
15
16helpText = """These are examples of three ways of changing colors interactively,
17and one widget that displays a chosen color.
18
19When KColorButton is clicked, it pops up a color selection dialog.
20
21KColorCells offers one way to present a pre-selected range of color
22choices, and may have more rows and columns than displayed here.
23Click on a cell to select a color.
24
25KColorCombo provides a programmable drop down list of colors to select
26from.
27
28Finally, KColorPatch will display a specified color. In this example, using
29any of the other three widgets to select a color will change the color of
30the KColorPatch.
31"""
32
33class MainFrame(KVBox):
34 def __init__(self, parent=None):
35 KVBox.__init__(self, parent)
36 self.help = QLabel (helpText, self)
37 self.layout ().setAlignment (self.help, Qt.AlignHCenter)
38
39 hBox1 = KHBox (self)
40 hBox1.setSpacing (10)
41 hBox1.setMargin (40)
42
43
44 colorButtonLabel = QLabel ("KColorButton", hBox1)
45 colorButton = KColorButton (hBox1)
46
47 colorCellsLabel = QLabel ("KColorCells", hBox1)
48 colorCells = KColorCells (hBox1, 1, 8)
49 colorCells.setMaximumSize (160, 20)
50 colorCells.setColor (0, Qt.black)
51 colorCells.setColor (1, Qt.red)
52 colorCells.setColor (2, Qt.yellow)
53 colorCells.setColor (3, Qt.blue)
54 colorCells.setColor (4, Qt.darkGreen)
55 colorCells.setColor (5, Qt.magenta)
56 colorCells.setColor (6, Qt.gray)
57 colorCells.setColor (7, Qt.white)
58
59
60 colorComboLabel = QLabel ("KColorCombo", hBox1)
61 colorCombo = KColorCombo (hBox1)
62
63 colorList = [Qt.black, Qt.red, Qt.yellow, Qt.blue, Qt.darkGreen, Qt.magenta, Qt.gray, Qt.white]
64 colorCombo.setColors (colorList)
65 colorCombo.setMaximumWidth (80)
66
67 hBox2 = KHBox (self)
68 hBox2.setSpacing (10)
69 self.layout ().setAlignment (hBox2, Qt.AlignHCenter | Qt.AlignTop)
70 self.setStretchFactor (hBox2, 1)
71
72 colorPatchLabel = QLabel ("KColorPatch", hBox2)
73 hBox2.layout ().setAlignment (colorPatchLabel, Qt.AlignHCenter)
74 self.colorPatch = KColorPatch (hBox2)
75 self.colorPatch.setFixedSize (40, 40)
76 hBox2.layout ().setAlignment (self.colorPatch, Qt.AlignHCenter)
77
78 self.colorPatch.setColor (Qt.red)
79 self.colorPatch.show ()
80
81 self.connect (colorButton, SIGNAL ("changed (const QColor&)"), self.colorPatch.setColor)
82 self.connect (colorCells, SIGNAL ("colorSelected (int, const QColor&)"), self.colorCellSelected)
83 self.connect (colorCombo, SIGNAL ("activated (const QColor&)"), self.colorPatch.setColor)
84
85 def colorCellSelected (self, int, color):
86 self.colorPatch.setColor (color)
87
88# This example can be run standalone
89
90if __name__ == '__main__':
91
92 import sys
93
94 from PyKDE4.kdecore import KCmdLineArgs, KAboutData, KLocalizedString, ki18n
95 from PyKDE4.kdeui import KApplication, KMainWindow
96
97 class MainWin (KMainWindow):
98 def __init__ (self, *args):
99 KMainWindow.__init__ (self)
100
101 self.resize(640, 480)
102 self.setCentralWidget (MainFrame (self))
103
104 #-------------------- main ------------------------------------------------
105
106 appName = "default"
107 catalog = ""
108 programName = ki18n ("default") #ki18n required here
109 version = "1.0"
110 description = ki18n ("Default Example") #ki18n required here
111 license = KAboutData.License_GPL
112 copyright = ki18n ("(c) 2007 Jim Bublitz") #ki18n required here
113 text = ki18n ("none") #ki18n required here
114 homePage = "www.riverbankcomputing.com"
115 bugEmail = "jbublitz@nwinternet.com"
116
117 aboutData = KAboutData (appName, catalog, programName, version, description,
118 license, copyright, text, homePage, bugEmail)
119
120 # ki18n required for first two addAuthor () arguments
121 aboutData.addAuthor (ki18n ("Troy Melhase"), ki18n ("original concept"))
122 aboutData.addAuthor (ki18n ("Jim Bublitz"), ki18n ("pykdedocs"))
123
124 KCmdLineArgs.init (sys.argv, aboutData)
125
126 app = KApplication ()
127 mainWindow = MainWin (None, "main window")
128 mainWindow.show()
129 app.connect (app, SIGNAL ("lastWindowClosed ()"), app.quit)
130 app.exec_ ()
0131
=== added file 'pykde4/kcolordialog.py'
--- pykde4/kcolordialog.py 1970-01-01 00:00:00 +0000
+++ pykde4/kcolordialog.py 2010-03-24 06:55:25 +0000
@@ -0,0 +1,93 @@
1#!/usr/bin/env python
2
3# [SNIPPET_NAME: Dialog (Color Selection)]
4# [SNIPPET_CATEGORIES: PyKDE4]
5# [SNIPPET_DESCRIPTION: A color selection dialog]
6# [SNIPPET_AUTHOR: Jim Bublitz <jbublitz@nwinternet.com>]
7# [SNIPPET_LICENSE: GPL]
8# [SNIPPET_DOCS: http://api.kde.org/pykde-4.3-api/kdeui/KColorDialog.html]
9
10from PyQt4.QtCore import SIGNAL, Qt
11from PyQt4.QtGui import QLabel
12from PyQt4.QtGui import QColor
13
14from PyKDE4.kdecore import i18n
15from PyKDE4.kdeui import KVBox, KHBox, KPushButton, KColorDialog, KColorPatch
16
17helpText = """This example uses KColorDialog.getColor (color, parent) to
18popup a dialog that allows the user to set the color of the KColorPatch
19next to the button.
20
21Click the button to run the dialog and select a color.
22"""
23
24dialogName = "KColorDialog"
25
26class MainFrame(KVBox):
27 def __init__(self, parent):
28 KVBox.__init__(self, parent)
29 self.help = QLabel (helpText, self)
30 self.layout ().setAlignment (self.help, Qt.AlignHCenter)
31
32 hBox = KHBox (self)
33 self.button = KPushButton(i18n("Show %s" % dialogName), hBox)
34 self.button.setMaximumSize (250, 30)
35
36 self.connect(self.button, SIGNAL('clicked()'), self.showDialog)
37
38 self.colorPatch = KColorPatch (hBox)
39 self.colorPatch.setColor (Qt.red)
40 self.colorPatch.setMaximumSize (40, 40)
41
42
43 def showDialog(self):
44 color = QColor ()
45 result = KColorDialog.getColor (color, self)
46 self.colorPatch.setColor (color)
47
48
49
50# This example can be run standalone
51
52if __name__ == '__main__':
53
54 import sys
55
56 from PyKDE4.kdecore import KCmdLineArgs, KAboutData, KLocalizedString, ki18n
57 from PyKDE4.kdeui import KApplication, KMainWindow
58
59
60 class MainWin (KMainWindow):
61 def __init__ (self, *args):
62 KMainWindow.__init__ (self)
63
64 self.resize(640, 480)
65 self.setCentralWidget (MainFrame (self))
66
67 #-------------------- main ------------------------------------------------
68
69 appName = "default.py"
70 catalog = ""
71 programName = ki18n ("default") #ki18n required here
72 version = "1.0"
73 description = ki18n ("Default Example") #ki18n required here
74 license = KAboutData.License_GPL
75 copyright = ki18n ("(c) 2007 Jim Bublitz") #ki18n required here
76 text = ki18n ("none") #ki18n required here
77 homePage = "www.riverbankcomputing.com"
78 bugEmail = "jbublitz@nwinternet.com"
79
80 aboutData = KAboutData (appName, catalog, programName, version, description,
81 license, copyright, text, homePage, bugEmail)
82
83 # ki18n required for first two addAuthor () arguments
84 aboutData.addAuthor (ki18n ("Troy Melhase"), ki18n ("original concept"))
85 aboutData.addAuthor (ki18n ("Jim Bublitz"), ki18n ("pykdedocs"))
86
87 KCmdLineArgs.init (sys.argv, aboutData)
88
89 app = KApplication ()
90 mainWindow = MainWin (None, "main window")
91 mainWindow.show()
92 app.connect (app, SIGNAL ("lastWindowClosed ()"), app.quit)
93 app.exec_ ()
094
=== added file 'pykde4/kcombobox.py'
--- pykde4/kcombobox.py 1970-01-01 00:00:00 +0000
+++ pykde4/kcombobox.py 2010-03-24 06:55:25 +0000
@@ -0,0 +1,119 @@
1#!/usr/bin/env python
2
3# [SNIPPET_NAME: Combo Box]
4# [SNIPPET_CATEGORIES: PyKDE4]
5# [SNIPPET_DESCRIPTION: An enhanced combo box which is a combined button, line-edit and popup list widget]
6# [SNIPPET_AUTHOR: Jim Bublitz <jbublitz@nwinternet.com>]
7# [SNIPPET_LICENSE: GPL]
8# [SNIPPET_DOCS: http://api.kde.org/pykde-4.3-api/kdeui/KComboBox.html]
9
10from PyQt4.QtCore import SIGNAL, Qt
11from PyQt4.QtGui import QLabel
12
13from PyKDE4.kdecore import i18n, KStandardDirs
14from PyKDE4.kdeui import KVBox, KHBox, KComboBox, KListWidget
15
16helpText = """
17KListWidget and KComboBox are useful for displaying or
18interacting with lists of items. In this case, we
19display the KStandardDirs file types and directory
20locations.
21
22KComboBox is filled from the QStringList that the
23method "allTypes()" returns. It can also be filled
24with a single item at a time, and we can sort or
25add/remove items later. KDE has specialized KComboBox
26subclasses for other purposes. It inherits methods
27from QComboBox
28
29KListWidget also displays lists of information, but all
30are visible at the same time. It inherits classes
31from QListWidget and QListView.
32"""
33
34class MainFrame(KVBox):
35 def __init__(self, parent=None):
36 KVBox.__init__(self, parent)
37 self.help = QLabel (i18n (helpText), self)
38 self.layout ().setAlignment (self.help, Qt.AlignHCenter)
39 self.setSpacing (10)
40
41 hBox = KHBox (self)
42 self.layout ().setAlignment (hBox, Qt.AlignHCenter)
43
44 cBox = KVBox (hBox)
45 hBox.layout ().setAlignment (cBox, Qt.AlignTop)
46 hBox.setSpacing (25)
47 hBox.setMargin (10)
48
49 self.stdDirs = KStandardDirs ()
50 types = self.stdDirs.allTypes ()
51
52 comboLbl = QLabel ("Types", cBox)
53 combo = KComboBox (cBox)
54 combo.addItems (types)
55 cBox.layout ().setAlignment (comboLbl, Qt.AlignTop)
56 cBox.layout ().setAlignment (combo, Qt.AlignTop)
57
58 self.connect (combo, SIGNAL ("currentIndexChanged (const QString&)"), self.slotIndexChanged)
59
60 lBox = KVBox (hBox)
61 listLbl = QLabel ("Directories", lBox)
62 self.location = KListWidget (lBox)
63 self.location.setMaximumSize (400, 200)
64 lBox.layout ().setAlignment (listLbl, Qt.AlignTop)
65 lBox.layout ().setAlignment (self.location, Qt.AlignTop)
66
67 self.slotIndexChanged (combo.currentText ())
68
69
70 def slotIndexChanged (self, s):
71 self.location.clear ()
72 self.location.insertItems (0, self.stdDirs.resourceDirs (str (s)))
73
74
75
76
77# This example can be run standalone
78
79if __name__ == '__main__':
80
81 import sys
82
83 from PyKDE4.kdecore import KCmdLineArgs, KAboutData, KLocalizedString, ki18n
84 from PyKDE4.kdeui import KApplication, KMainWindow
85
86 class MainWin (KMainWindow):
87 def __init__ (self, *args):
88 KMainWindow.__init__ (self)
89
90 self.resize(640, 480)
91 self.setCentralWidget (MainFrame (self))
92
93 #-------------------- main ------------------------------------------------
94
95 appName = "default"
96 catalog = ""
97 programName = ki18n ("default") #ki18n required here
98 version = "1.0"
99 description = ki18n ("Default Example") #ki18n required here
100 license = KAboutData.License_GPL
101 copyright = ki18n ("(c) 2007 Jim Bublitz") #ki18n required here
102 text = ki18n ("none") #ki18n required here
103 homePage = "www.riverbankcomputing.com"
104 bugEmail = "jbublitz@nwinternet.com"
105
106 aboutData = KAboutData (appName, catalog, programName, version, description,
107 license, copyright, text, homePage, bugEmail)
108
109 # ki18n required for first two addAuthor () arguments
110 aboutData.addAuthor (ki18n ("Troy Melhase"), ki18n ("original concept"))
111 aboutData.addAuthor (ki18n ("Jim Bublitz"), ki18n ("pykdedocs"))
112
113 KCmdLineArgs.init (sys.argv, aboutData)
114
115 app = KApplication ()
116 mainWindow = MainWin (None, "main window")
117 mainWindow.show()
118 app.connect (app, SIGNAL ("lastWindowClosed ()"), app.quit)
119 app.exec_ ()
0120
=== added file 'pykde4/kdatepicker.py'
--- pykde4/kdatepicker.py 1970-01-01 00:00:00 +0000
+++ pykde4/kdatepicker.py 2010-03-24 06:55:25 +0000
@@ -0,0 +1,98 @@
1#!/usr/bin/env python
2
3# [SNIPPET_NAME: Date Selection Widget]
4# [SNIPPET_CATEGORIES: PyKDE4]
5# [SNIPPET_DESCRIPTION: Provides a widget for calendar date input]
6# [SNIPPET_AUTHOR: Troy Melhase]
7# [SNIPPET_LICENSE: GPL]
8# [SNIPPET_DOCS: http://api.kde.org/pykde-4.3-api/kdeui/KDatePicker.html]
9
10from PyQt4.QtCore import SIGNAL, Qt
11from PyQt4.QtGui import QLabel
12
13from PyKDE4.kdecore import i18n
14from PyKDE4.kdeui import KVBox, KHBox, KDatePicker, KDateWidget
15
16
17helpText = """Date selection widgets - KDatePicker and KDateWidget - provide widgets for calendar
18date input.
19
20KDatePicker emits two types of signals, either dateSelected() or dateEntered().
21
22A line edit allows the user to select a date directly by entering numbers like
2319990101 or 990101 into KDatePicker."""
24
25class MainFrame(KVBox):
26 def __init__(self, parent=None):
27 KVBox.__init__(self, parent)
28 self.help = QLabel (i18n (helpText), self)
29 self.layout ().setAlignment (self.help, Qt.AlignHCenter | Qt.AlignTop)
30 self.setSpacing (40)
31
32 hBox = KHBox (self)
33 vBox1 = KVBox (hBox)
34 vBox2 = KVBox (hBox)
35
36 hBox.layout ().setAlignment (vBox1, Qt.AlignHCenter)
37 hBox.layout ().setAlignment (vBox2, Qt.AlignHCenter)
38 vBox1.setMargin (20)
39 vBox2.setSpacing (20)
40
41 self.datePickerLabel = QLabel ("KDatePicker", vBox1)
42
43 self.datePicker = KDatePicker(vBox2)
44 self.datePicker.setFixedSize (400, 200)
45
46 self.other = QLabel('KDateWidget', vBox1)
47 vBox1.layout ().setAlignment (self.other, Qt.AlignBottom)
48
49 self.dateDisplay = KDateWidget(vBox2)
50
51
52 self.connect(self.datePicker, SIGNAL('dateChanged(QDate)'),
53 self.dateDisplay.setDate)
54
55
56# This example can be run standalone
57
58if __name__ == '__main__':
59
60 import sys
61
62 from PyKDE4.kdecore import KCmdLineArgs, KAboutData, KLocalizedString, ki18n
63 from PyKDE4.kdeui import KApplication, KMainWindow
64
65
66 class MainWin (KMainWindow):
67 def __init__ (self, *args):
68 KMainWindow.__init__ (self)
69
70 self.resize(640, 500)
71 self.setCentralWidget (MainFrame (self))
72
73 #-------------------- main ------------------------------------------------
74
75 appName = "kdatepicker"
76 catalog = ""
77 programName = ki18n ("kdatepicker")
78 version = "1.0"
79 description = ki18n ("KDatePicker Example")
80 license = KAboutData.License_GPL
81 copyright = ki18n ("(c) 2006 Troy Melhase")
82 text = ki18n ("none")
83 homePage = "www.riverbankcomputing.com"
84 bugEmail = "jbublitz@nwinternet.com"
85
86 aboutData = KAboutData (appName, catalog, programName, version, description,
87 license, copyright, text, homePage, bugEmail)
88
89 aboutData.addAuthor (ki18n ("Troy Melhase"), ki18n ("original concept"))
90 aboutData.addAuthor (ki18n ("Jim Bublitz"), ki18n ("pykdedocs"))
91
92 KCmdLineArgs.init (sys.argv, aboutData)
93
94 app = KApplication ()
95 mainWindow = MainWin (None, "main window")
96 mainWindow.show()
97 app.connect (app, SIGNAL ("lastWindowClosed ()"), app.quit)
98 app.exec_ ()
099
=== added file 'pykde4/kfontdialog.py'
--- pykde4/kfontdialog.py 1970-01-01 00:00:00 +0000
+++ pykde4/kfontdialog.py 2010-03-24 06:55:25 +0000
@@ -0,0 +1,96 @@
1#!/usr/bin/env python
2
3# [SNIPPET_NAME: Dialog (Font Selection)]
4# [SNIPPET_CATEGORIES: PyKDE4]
5# [SNIPPET_DESCRIPTION: A dialog that provides interactive font selection]
6# [SNIPPET_AUTHOR: Jim Bublitz <jbublitz@nwinternet.com>]
7# [SNIPPET_LICENSE: GPL]
8# [SNIPPET_DOCS: http://api.kde.org/pykde-4.3-api/kdeui/KFontDialog.html]
9
10from PyQt4.QtCore import SIGNAL, Qt
11from PyQt4.QtGui import QLabel, QDialog, QFont
12
13from PyKDE4.kdecore import i18n
14from PyKDE4.kdeui import KVBox, KHBox, KPushButton, KFontDialog
15
16helpText = """A KFontDialog allows the user to select a new font.
17
18Click the button to change the font of the displayed text.
19"""
20
21quote = """Now is the winter of our discontent
22made summer by this glorious sun of York.
23"""
24
25dialogName = "KFontDialog"
26
27class MainFrame(KVBox):
28 def __init__(self, parent):
29 KVBox.__init__(self, parent)
30 self.setSpacing (40)
31 self.help = QLabel (i18n (helpText), self)
32 self.layout ().setAlignment (self.help, Qt.AlignHCenter)
33
34 self.button = KPushButton(i18n("Show %s" % dialogName), self)
35 self.button.setFixedSize (200, 30)
36 self.layout ().setAlignment (self.button, Qt.AlignHCenter)
37 self.fontLabel = QLabel (quote, self)
38 self.layout ().setAlignment (self.fontLabel, Qt.AlignHCenter)
39
40 self.connect(self.button, SIGNAL('clicked()'), self.showDialog)
41
42 def showDialog(self):
43 font = QFont ()
44 result, checkState = KFontDialog.getFont (font)
45 if result == QDialog.Accepted:
46 self.fontLabel.setFont (font)
47
48
49
50# This example can be run standalone
51
52if __name__ == '__main__':
53
54 import sys
55
56 from PyQt4.QtCore import Qt
57 from PyQt4.QtGui import QFrame, QVBoxLayout
58
59 from PyKDE4.kdecore import KCmdLineArgs, KAboutData, KLocalizedString, ki18n
60 from PyKDE4.kdeui import KApplication, KMainWindow
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 = "default.py"
73 catalog = ""
74 programName = ki18n ("default") #ki18n required here
75 version = "1.0"
76 description = ki18n ("Default 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_ ()
097
=== added file 'pykde4/kstandarddirs.py'
--- pykde4/kstandarddirs.py 1970-01-01 00:00:00 +0000
+++ pykde4/kstandarddirs.py 2010-03-24 06:55:25 +0000
@@ -0,0 +1,113 @@
1#!/usr/bin/env python
2
3# [SNIPPET_NAME: KDE Standard Directories]
4# [SNIPPET_CATEGORIES: PyKDE4]
5# [SNIPPET_DESCRIPTION: Site-independent access to standard KDE directories]
6# [SNIPPET_AUTHOR: Jim Bublitz <jbublitz@nwinternet.com>]
7# [SNIPPET_LICENSE: GPL]
8# [SNIPPET_DOCS: http://api.kde.org/pykde-4.3-api/kdecore/KStandardDirs.html]
9
10from PyQt4.QtCore import SIGNAL, Qt
11from PyQt4.QtGui import QLabel
12
13from PyKDE4.kdecore import i18n, KStandardDirs
14from PyKDE4.kdeui import KVBox, KHBox, KComboBox, KListWidget
15
16helpText = """KStandardDirs provides methods for locating KDE objects
17 within the filesystem - for example, icons, configuration
18 files, etc.
19
20 KStandardDirs recognizes a number of data types (shown in the
21 combo box at left) and associates the types with directories.
22
23 You can use this information to locate a resource, or to
24 determine where to install a resource for you program.
25"""
26
27class 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 hBox = KHBox (self)
35 self.layout ().setAlignment (hBox, Qt.AlignHCenter)
36
37 cBox = KVBox (hBox)
38 hBox.layout ().setAlignment (cBox, Qt.AlignTop)
39 hBox.setSpacing (25)
40 hBox.setMargin (10)
41
42 self.stdDirs = KStandardDirs ()
43 types = self.stdDirs.allTypes ()
44
45 comboLbl = QLabel ("Types", cBox)
46 combo = KComboBox (cBox)
47 combo.addItems (types)
48 cBox.layout ().setAlignment (comboLbl, Qt.AlignTop)
49 cBox.layout ().setAlignment (combo, Qt.AlignTop)
50
51 self.connect (combo, SIGNAL ("currentIndexChanged (const QString&)"), self.slotIndexChanged)
52
53 lBox = KVBox (hBox)
54 listLbl = QLabel ("Directories", lBox)
55 self.location = KListWidget (lBox)
56 self.location.setMaximumSize (400, 200)
57 lBox.layout ().setAlignment (listLbl, Qt.AlignTop)
58 lBox.layout ().setAlignment (self.location, Qt.AlignTop)
59
60 QLabel (self.stdDirs.installPath ("ui"), self)
61
62 self.slotIndexChanged (combo.currentText ())
63
64 def slotIndexChanged (self, s):
65 self.location.clear ()
66 self.location.insertItems (0, self.stdDirs.resourceDirs (str (s)))
67
68
69
70
71# This example can be run standalone
72
73if __name__ == '__main__':
74
75 import sys
76
77 from PyKDE4.kdecore import KCmdLineArgs, KAboutData, KLocalizedString, ki18n
78 from PyKDE4.kdeui import KApplication, KMainWindow
79
80 class MainWin (KMainWindow):
81 def __init__ (self, *args):
82 KMainWindow.__init__ (self)
83
84 self.resize(640, 480)
85 self.setCentralWidget (MainFrame (self))
86
87 #-------------------- main ------------------------------------------------
88
89 appName = "default"
90 catalog = ""
91 programName = ki18n ("default") #ki18n required here
92 version = "1.0"
93 description = ki18n ("Default Example") #ki18n required here
94 license = KAboutData.License_GPL
95 copyright = ki18n ("(c) 2007 Jim Bublitz") #ki18n required here
96 text = ki18n ("none") #ki18n required here
97 homePage = "www.riverbankcomputing.com"
98 bugEmail = "jbublitz@nwinternet.com"
99
100 aboutData = KAboutData (appName, catalog, programName, version, description,
101 license, copyright, text, homePage, bugEmail)
102
103 # ki18n required for first two addAuthor () arguments
104 aboutData.addAuthor (ki18n ("Troy Melhase"), ki18n ("original concept"))
105 aboutData.addAuthor (ki18n ("Jim Bublitz"), ki18n ("pykdedocs"))
106
107 KCmdLineArgs.init (sys.argv, aboutData)
108
109 app = KApplication ()
110 mainWindow = MainWin (None, "main window")
111 mainWindow.show()
112 app.connect (app, SIGNAL ("lastWindowClosed ()"), app.quit)
113 app.exec_ ()
0114
=== added file 'pykde4/solid_audiointerface.py'
--- pykde4/solid_audiointerface.py 1970-01-01 00:00:00 +0000
+++ pykde4/solid_audiointerface.py 2010-03-24 06:55:25 +0000
@@ -0,0 +1,136 @@
1#!/usr/bin/env python
2
3# [SNIPPET_NAME: Solid (Audio Interface)]
4# [SNIPPET_CATEGORIES: PyKDE4]
5# [SNIPPET_DESCRIPTION: Device integration framework for an audio interface]
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.AudioInterface.html]
9
10from PyQt4.QtCore import Qt
11from PyQt4.QtGui import QSizePolicy, QTreeWidget, QTreeWidgetItem, QLabel
12
13from PyKDE4.kdecore import i18n
14from PyKDE4.solid import Solid, Solid
15from PyKDE4.kdeui import KVBox, KHBox, KTextEdit
16
17helpText = """The Solid class discovers information about the hardware on a machine.
18
19Solid.AudioInterface objects retrieve information about the sound system
20on a machine.
21
22We use Solid.Device.allDevices () to get a list of all devices, and then
23filter it for Solid.AudioInterface types.
24"""
25
26class MainFrame(KVBox):
27 def __init__(self, parent=None):
28 KVBox.__init__(self, parent)
29 self.help = QLabel (i18n (helpText), self)
30 self.layout ().setAlignment (self.help, Qt.AlignHCenter)
31 self.setSpacing (10)
32
33 audioDriverStr = {
34 Solid.AudioInterface.Alsa: "Alsa",\
35 Solid.AudioInterface.OpenSoundSystem: "Open Sound",\
36 Solid.AudioInterface.UnknownAudioDriver: "Unknown"
37 }
38
39
40 audioInterfaceTypeStr = {
41 Solid.AudioInterface.UnknownAudioInterfaceType: "Unknown",\
42 Solid.AudioInterface.AudioControl: "Control",\
43 Solid.AudioInterface.AudioInput: "In",\
44 Solid.AudioInterface.AudioOutput: "Out"
45 }
46
47 soundcardTypeStr = {
48 Solid.AudioInterface.InternalSoundcard: "Internal",\
49 Solid.AudioInterface.UsbSoundcard: "USB",\
50 Solid.AudioInterface.FirewireSoundcard: "Firewire",\
51 Solid.AudioInterface.Headset: "Headset",\
52 Solid.AudioInterface.Modem: "Modem"
53 }
54
55 hBox = KHBox (self)
56
57 display = QTreeWidget (hBox)
58 display.setSizePolicy (QSizePolicy.Expanding, QSizePolicy.Expanding)
59 display.setHeaderLabels (["Item", "Name", "Driver", "I/F Type", "Sound Card Type"])
60 display.setColumnWidth (0, 300)
61 display.setColumnWidth (1, 300)
62 display.setColumnWidth (3, 75)
63
64 # retrieve a list of Solid.Device for this machine
65 deviceList = Solid.Device.allDevices ()
66
67
68 # filter the list of all devices and display matching results
69 # note that we never create a Solid.AudioInterface object, but
70 # receive one from the 'asDeviceInterface' call
71 for device in deviceList:
72 if device.isDeviceInterface (Solid.DeviceInterface.AudioInterface):
73 audio = device.asDeviceInterface (Solid.DeviceInterface.AudioInterface)
74 devtype = audio.deviceType ()
75 devstr = []
76 for key in audioInterfaceTypeStr:
77 flag = key & devtype
78 if flag:
79 devstr.append (audioInterfaceTypeStr [key])
80
81 QTreeWidgetItem (display, [device.product (),
82 audio.name (),
83 audioDriverStr [audio.driver ()],
84 "/".join (devstr),
85 soundcardTypeStr [audio.soundcardType ()]])
86
87
88
89
90# This example can be run standalone
91
92if __name__ == '__main__':
93
94 import sys
95
96 from PyQt4.QtCore import SIGNAL
97
98 from PyKDE4.kdecore import KCmdLineArgs, KAboutData, KLocalizedString, ki18n
99 from PyKDE4.kdeui import KApplication, KMainWindow
100
101
102 class MainWin (KMainWindow):
103 def __init__ (self, *args):
104 KMainWindow.__init__ (self)
105
106 self.resize(640, 480)
107 self.setCentralWidget (MainFrame (self))
108
109
110 #-------------------- main ------------------------------------------------
111
112 appName = "Solid_StorageDrive"
113 catalog = ""
114 programName = ki18n ("Solid_StorageDrive") #ki18n required here
115 version = "1.0"
116 description = ki18n ("Solid.StorageDrive Example") #ki18n required here
117 license = KAboutData.License_GPL
118 copyright = ki18n ("(c) 2007 Jim Bublitz") #ki18n required here
119 text = ki18n ("none") #ki18n required here
120 homePage = "www.riverbankcomputing.com"
121 bugEmail = "jbublitz@nwinternet.com"
122
123 aboutData = KAboutData (appName, catalog, programName, version, description,
124 license, copyright, text, homePage, bugEmail)
125
126 # ki18n required for first two addAuthor () arguments
127 aboutData.addAuthor (ki18n ("Troy Melhase"), ki18n ("original concept"))
128 aboutData.addAuthor (ki18n ("Jim Bublitz"), ki18n ("pykdedocs"))
129
130 KCmdLineArgs.init (sys.argv, aboutData)
131
132 app = KApplication ()
133 mainWindow = MainWin (None, "main window")
134 mainWindow.show()
135 app.connect (app, SIGNAL ("lastWindowClosed ()"), app.quit)
136 app.exec_ ()
0137
=== added file 'pykde4/solid_demo.py'
--- pykde4/solid_demo.py 1970-01-01 00:00:00 +0000
+++ pykde4/solid_demo.py 2010-03-24 06:55:25 +0000
@@ -0,0 +1,101 @@
1#!/usr/bin/env python
2
3# [SNIPPET_NAME: Solid Demo]
4# [SNIPPET_CATEGORIES: PyKDE4]
5# [SNIPPET_DESCRIPTION: Demos some of the features of Solid]
6# [SNIPPET_AUTHOR: Simon Edwards <simon@simonzone.com>]
7# [SNIPPET_LICENSE: GPL3]
8# [SNIPPET_DOCS: http://api.kde.org/pykde-4.3-api/solid/index.html]
9
10###########################################################################
11# solid_demo.py - Demonstrates use of Solid.
12#
13###########################################################################
14# Copyright (C) 2007 Simon Edwards <simon@simonzone.com>
15#
16# This program is free software; you can redistribute it and/or modify
17# it under the terms of the GNU General Public License as published by
18# the Free Software Foundation; either version 2 of the License or (at
19# your option) version 3 or, at the discretion of KDE e.V. (which shall
20# act as a proxy as in section 14 of the GPLv3), any later version.
21#
22# This program is distributed in the hope that it will be useful,
23# but WITHOUT ANY WARRANTY; without even the implied warranty of
24# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25# GNU General Public License for more details.
26#
27# You should have received a copy of the GNU General Public License along
28# with this program; if not, write to the Free Software Foundation, Inc.,
29# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30
31from PyKDE4.kdecore import *
32from PyKDE4.solid import *
33
34def main():
35 componentData = KComponentData("solid_demo")
36
37 print("All devices found by Solid")
38 print("--------------------------")
39 for device in Solid.Device.allDevices():
40 print(device.udi())
41 print("")
42
43 print("All audio devices found by Solid")
44 print("--------------------------------")
45 for device in Solid.Device.listFromType(Solid.DeviceInterface.AudioInterface, ""):
46 print(device.udi())
47 print("")
48
49 print("Processor found by Solid")
50 print("------------------------")
51
52 # Get a Processor
53 device_list = Solid.Device.listFromType(Solid.DeviceInterface.Processor, "")
54
55 # take the first processor
56 device = device_list[0]
57 if device.isDeviceInterface(Solid.DeviceInterface.Processor):
58 print("We've got a processor! %i to be exact..." % len(device_list))
59 else:
60 print("Device is not a processor.")
61
62 processor = device.asDeviceInterface(Solid.DeviceInterface.Processor)
63 print("This processors maximum speed is: " + str(processor.maxSpeed()))
64
65 extensions = processor.instructionSets()
66 print("Intel MMX supported: " + ("yes" if extensions & Solid.Processor.IntelMmx else "no"))
67 print("Intel SSE supported: " + ("yes" if extensions & Solid.Processor.IntelSse else "no"))
68 print("Intel SSE2 supported: " + ("yes" if extensions & Solid.Processor.IntelSse2 else "no"))
69 print("Intel SSE3 supported: " + ("yes" if extensions & Solid.Processor.IntelSse3 else "no"))
70 print("Intel SSE4 supported: " + ("yes" if extensions & Solid.Processor.IntelSse4 else "no"))
71 print("AMD 3DNOW supported: " + ("yes" if extensions & Solid.Processor.Amd3DNow else "no"))
72 print("PPC AltiVec supported: " + ("yes" if extensions & Solid.Processor.AltiVec else "no"))
73 print("")
74
75 print("Checking network status")
76 print("-----------------------")
77
78 if Solid.Networking.status() == Solid.Networking.Connected:
79 print("Networking is enabled. Feel free to go online!")
80 else:
81 print("Network not available.")
82 print("")
83
84 # get a Network Device
85 netlist = Solid.Device.listFromType(Solid.DeviceInterface.NetworkInterface, "")
86
87 # check to see if no network devices were found
88 if len(netlist)==0:
89 print("No network devices found!")
90 else:
91 print("Found %s network device(s)" % len(netlist))
92 for device in netlist:
93 netdev = device.asDeviceInterface(Solid.DeviceInterface.NetworkInterface)
94
95 # keep the program from crashing in the event that there's a bug in solid
96 if netdev is None:
97 print("Device could not be converted. There is a bug.")
98 else:
99 print("The iface of %s is %s" % (str(device.udi()),str(netdev.ifaceName())))
100
101main()
0102
=== added file 'pykde4/solid_device.py'
--- pykde4/solid_device.py 1970-01-01 00:00:00 +0000
+++ pykde4/solid_device.py 2010-03-24 06:55:25 +0000
@@ -0,0 +1,91 @@
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
10from PyQt4.QtCore import SIGNAL, Qt
11from PyQt4.QtGui import QTreeWidget, QTreeWidgetItem, QLabel
12
13from PyKDE4.kdecore import i18n
14from PyKDE4.solid import Solid
15from PyKDE4.kdeui import KVBox
16
17helpText = """The Solid class discovers information about the hardware on a machine.
18
19Solid.Device is the base class for the various types of devices. It provides a list
20of the types of devices on the machine. The table below shows the data for your
21machine.
22
23Individual device type classes can be interrogated to discover specific information
24suitable to each device type.
25"""
26
27class 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
49if __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_ ()
092
=== added file 'pykde4/solid_networkinterface.py'
--- pykde4/solid_networkinterface.py 1970-01-01 00:00:00 +0000
+++ pykde4/solid_networkinterface.py 2010-03-24 06:55:25 +0000
@@ -0,0 +1,118 @@
1#!/usr/bin/env python
2
3# [SNIPPET_NAME: Solid (Network Interface)]
4# [SNIPPET_CATEGORIES: PyKDE4]
5# [SNIPPET_DESCRIPTION: Device integration framework for a network interface]
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.NetworkInterface.html]
9
10from PyQt4.QtCore import Qt
11from PyQt4.QtGui import QSizePolicy, QTreeWidget, QTreeWidgetItem, QLabel
12
13from PyKDE4.kdecore import i18n
14from PyKDE4.solid import Solid, Solid
15from PyKDE4.kdeui import KVBox, KHBox, KTextEdit
16
17helpText = """The Solid class discovers information about the hardware on a machine.
18
19Solid.NetworkInterface objects retrieve information about the network
20on a machine.
21
22We use Solid.Device.allDevices () to get a list of all devices, and then
23filter it for Solid.NetworkInterface types.
24"""
25
26class MainFrame(KVBox):
27 def __init__(self, parent=None):
28 KVBox.__init__(self, parent)
29 self.help = QLabel (i18n (helpText), self)
30 self.layout ().setAlignment (self.help, Qt.AlignHCenter)
31 self.setSpacing (10)
32
33 statusString = {
34 Solid.Networking.Unknown: "Unknown",\
35 Solid.Networking.Unconnected: "Unconnected",\
36 Solid.Networking.Disconnecting: "Disconnecting",\
37 Solid.Networking.Connecting: "Connecting",\
38 Solid.Networking.Connected: "Connected"\
39 }
40
41 status = Solid.Networking.status ()
42 self.label = QLabel ("Status: %s" % statusString [status], self)
43
44 hBox = KHBox (self)
45
46 display = QTreeWidget (hBox)
47 display.setSizePolicy (QSizePolicy.Expanding, QSizePolicy.Expanding)
48 display.setHeaderLabels (["Interface", "Name", "Wireless", "HW Addr", "MAC Addr"])
49 display.setColumnWidth (0, 200)
50 display.setColumnWidth (1, 75)
51 display.setColumnWidth (3, 150)
52
53 # retrieve a list of Solid.Device for this machine
54 deviceList = Solid.Device.allDevices ()
55
56
57 # filter the list of all devices and display matching results
58 # note that we never create a Solid.NetworkInterface object, but
59 # receive one from the 'asDeviceInterface' call
60 for device in deviceList:
61 if device.isDeviceInterface (Solid.DeviceInterface.NetworkInterface):
62 iface = device.asDeviceInterface (Solid.DeviceInterface.NetworkInterface)
63 QTreeWidgetItem (display, [device.product (),
64 iface.ifaceName (),
65 str (iface.isWireless ()),
66 iface.hwAddress (),
67 str (iface.macAddress ())])
68
69
70
71
72# This example can be run standalone
73
74if __name__ == '__main__':
75
76 import sys
77
78 from PyQt4.QtCore import SIGNAL
79
80 from PyKDE4.kdecore import KCmdLineArgs, KAboutData, KLocalizedString, ki18n
81 from PyKDE4.kdeui import KApplication, KMainWindow
82
83
84 class MainWin (KMainWindow):
85 def __init__ (self, *args):
86 KMainWindow.__init__ (self)
87
88 self.resize(640, 480)
89 self.setCentralWidget (MainFrame (self))
90
91
92 #-------------------- main ------------------------------------------------
93
94 appName = "Solid_StorageDrive"
95 catalog = ""
96 programName = ki18n ("Solid_StorageDrive") #ki18n required here
97 version = "1.0"
98 description = ki18n ("Solid.StorageDrive Example") #ki18n required here
99 license = KAboutData.License_GPL
100 copyright = ki18n ("(c) 2007 Jim Bublitz") #ki18n required here
101 text = ki18n ("none") #ki18n required here
102 homePage = "www.riverbankcomputing.com"
103 bugEmail = "jbublitz@nwinternet.com"
104
105 aboutData = KAboutData (appName, catalog, programName, version, description,
106 license, copyright, text, homePage, bugEmail)
107
108 # ki18n required for first two addAuthor () arguments
109 aboutData.addAuthor (ki18n ("Troy Melhase"), ki18n ("original concept"))
110 aboutData.addAuthor (ki18n ("Jim Bublitz"), ki18n ("pykdedocs"))
111
112 KCmdLineArgs.init (sys.argv, aboutData)
113
114 app = KApplication ()
115 mainWindow = MainWin (None, "main window")
116 mainWindow.show()
117 app.connect (app, SIGNAL ("lastWindowClosed ()"), app.quit)
118 app.exec_ ()
0119
=== added file 'pykde4/solid_processor.py'
--- pykde4/solid_processor.py 1970-01-01 00:00:00 +0000
+++ pykde4/solid_processor.py 2010-03-24 06:55:25 +0000
@@ -0,0 +1,96 @@
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
10from PyQt4.QtCore import SIGNAL, Qt
11from PyQt4.QtGui import QTreeWidget, QTreeWidgetItem, QLabel
12
13from PyKDE4.kdecore import i18n
14from PyKDE4.solid import Solid
15from PyKDE4.kdeui import KVBox
16
17helpText = """The Solid class discovers information about the hardware on a machine.
18
19Solid.Processor objects retrieve information about the processor on a machine. The
20table below shows the data for your machine. Not all computers make processor info
21accessible, so the table may be empty.
22
23We use Solid.Device.allDevices () to get a list of all devices, and then
24filter it for Solid.Processor types.
25"""
26
27class 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
54if __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_ ()
097
=== added file 'pykde4/solid_storageaccess.py'
--- pykde4/solid_storageaccess.py 1970-01-01 00:00:00 +0000
+++ pykde4/solid_storageaccess.py 2010-03-24 06:55:25 +0000
@@ -0,0 +1,104 @@
1#!/usr/bin/env python
2
3# [SNIPPET_NAME: Solid (Storage Access)]
4# [SNIPPET_CATEGORIES: PyKDE4]
5# [SNIPPET_DESCRIPTION: Device integration framework for storage access]
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.StorageAccess.html]
9
10from PyQt4.QtCore import Qt
11from PyQt4.QtGui import QSizePolicy, QTreeWidget, QTreeWidgetItem, QLabel
12
13from PyKDE4.kdecore import i18n
14from PyKDE4.solid import Solid
15from PyKDE4.kdeui import KVBox, KHBox
16
17helpText = """The Solid class discovers information about the hardware on a machine.
18
19Solid.StorageAccess objects retrieve information about the accessibility of
20storage on a machine. It also allows interaction, like mounting and unmounting. The
21table below shows the data for your machine.
22
23We use Solid.Device.allDevices () to get a list of all devices, and then
24filter it for Solid.StorageAccess types.
25"""
26
27class 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 hBox = KHBox (self)
35
36 display = QTreeWidget (hBox)
37 display.setSizePolicy (QSizePolicy.Expanding, QSizePolicy.Expanding)
38 display.setHeaderLabels (["Volume", "File Path", "Accessible"])
39 display.setColumnWidth (0, 200)
40 display.setColumnWidth (1, 300)
41
42 # retrieve a list of Solid.Device for this machine
43 deviceList = Solid.Device.allDevices ()
44
45 # filter the list of all devices and display matching results
46 # note that we never create a Solid.StorageAccess object, but
47 # receive one from the 'asDeviceInterface' call
48 for device in deviceList:
49 if device.isDeviceInterface (Solid.DeviceInterface.StorageAccess):
50 access = device.asDeviceInterface (Solid.DeviceInterface.StorageAccess)
51 QTreeWidgetItem (display, [device.product (),
52 access.filePath (),
53 str (access.isAccessible ())])
54
55
56
57
58# This example can be run standalone
59
60if __name__ == '__main__':
61
62 import sys
63
64 from PyQt4.QtCore import SIGNAL
65
66 from PyKDE4.kdecore import KCmdLineArgs, KAboutData, KLocalizedString, ki18n
67 from PyKDE4.kdeui import KApplication, KMainWindow
68
69
70 class MainWin (KMainWindow):
71 def __init__ (self, *args):
72 KMainWindow.__init__ (self)
73
74 self.resize(640, 480)
75 self.setCentralWidget (MainFrame (self))
76
77
78 #-------------------- main ------------------------------------------------
79
80 appName = "Solid_StorageDrive"
81 catalog = ""
82 programName = ki18n ("Solid_StorageDrive") #ki18n required here
83 version = "1.0"
84 description = ki18n ("Solid.StorageDrive Example") #ki18n required here
85 license = KAboutData.License_GPL
86 copyright = ki18n ("(c) 2007 Jim Bublitz") #ki18n required here
87 text = ki18n ("none") #ki18n required here
88 homePage = "www.riverbankcomputing.com"
89 bugEmail = "jbublitz@nwinternet.com"
90
91 aboutData = KAboutData (appName, catalog, programName, version, description,
92 license, copyright, text, homePage, bugEmail)
93
94 # ki18n required for first two addAuthor () arguments
95 aboutData.addAuthor (ki18n ("Troy Melhase"), ki18n ("original concept"))
96 aboutData.addAuthor (ki18n ("Jim Bublitz"), ki18n ("pykdedocs"))
97
98 KCmdLineArgs.init (sys.argv, aboutData)
99
100 app = KApplication ()
101 mainWindow = MainWin (None, "main window")
102 mainWindow.show()
103 app.connect (app, SIGNAL ("lastWindowClosed ()"), app.quit)
104 app.exec_ ()
0105
=== added file 'pykde4/solid_storagedrive.py'
--- pykde4/solid_storagedrive.py 1970-01-01 00:00:00 +0000
+++ pykde4/solid_storagedrive.py 2010-03-24 06:55:25 +0000
@@ -0,0 +1,126 @@
1#!/usr/bin/env python
2
3# [SNIPPET_NAME: Solid (Storage Drive)]
4# [SNIPPET_CATEGORIES: PyKDE4]
5# [SNIPPET_DESCRIPTION: Device integration framework for a storage drive]
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.StorageDrive.html]
9
10from PyQt4.QtCore import Qt
11from PyQt4.QtGui import QSizePolicy, QTreeWidget, QTreeWidgetItem, QLabel
12
13from PyKDE4.kdecore import i18n
14from PyKDE4.solid import Solid
15from PyKDE4.kdeui import KVBox, KHBox, KColorButton
16
17helpText = """The Solid class discovers information about the hardware on a machine.
18
19Solid.StorageDrive objects retrieve information about storage devices on a
20machine. the table below shows the data for your machine.
21
22We use Solid.Device.allDevices () to get a list of all devices, and then
23filter it for Solid.StorageDrive types.
24"""
25
26class MainFrame(KVBox):
27 def __init__(self, parent=None):
28 KVBox.__init__(self, parent)
29 self.help = QLabel (i18n (helpText), self)
30 self.layout ().setAlignment (self.help, Qt.AlignHCenter)
31 self.setSpacing (10)
32
33 hBox = KHBox (self)
34
35 display = QTreeWidget (hBox)
36 display.setSizePolicy (QSizePolicy.Expanding, QSizePolicy.Expanding)
37 display.setHeaderLabels (["Device", "Bus", "Type", "Hot Plug", "Removable"])
38 display.setColumnWidth (0, 150)
39
40 # convert enum values to strings for display
41 bus2Str = {Solid.StorageDrive.Ide : "IDE",\
42 Solid.StorageDrive.Usb : "USB",\
43 Solid.StorageDrive. Ieee1394 : "IEE1394",\
44 Solid.StorageDrive.Scsi : "SCSI",\
45 Solid.StorageDrive.Sata : "SATA",\
46 Solid.StorageDrive.Platform : "Platform"
47 }
48
49
50 driveType2Str = {Solid.StorageDrive.HardDisk : "Hard Disk",\
51 Solid.StorageDrive.CdromDrive : "CD ROM",\
52 Solid.StorageDrive.Floppy : "Floppy",\
53 Solid.StorageDrive.Tape : "Tape",\
54 Solid.StorageDrive.CompactFlash : "Compact Flash",\
55 Solid.StorageDrive.MemoryStick : "Memory Stick",\
56 Solid.StorageDrive.SmartMedia : "Smart Media",\
57 Solid.StorageDrive.SdMmc : "SD MMC",\
58 Solid.StorageDrive.Xd : "XD"
59 }
60
61
62 # retrieve a list of Solid.Device for this machine
63 deviceList = Solid.Device.allDevices ()
64
65 # filter the list of all devices and display matching results
66 # note that we never create a Solid.StorageDrive object, but
67 # receive one from the call to 'asDeviceInterface'
68 for device in deviceList:
69 if device.isDeviceInterface (Solid.DeviceInterface.StorageDrive):
70 drive = device.asDeviceInterface (Solid.DeviceInterface.StorageDrive)
71 QTreeWidgetItem (display, [device.product (),
72 bus2Str [drive.bus ()],
73 driveType2Str [drive.driveType ()],
74 str (drive.isHotpluggable ()),
75 str (drive.isRemovable ())])
76
77
78
79
80# This example can be run standalone
81
82if __name__ == '__main__':
83
84 import sys
85
86 from PyQt4.QtCore import SIGNAL
87
88 from PyKDE4.kdecore import KCmdLineArgs, KAboutData, KLocalizedString, ki18n
89 from PyKDE4.kdeui import KApplication, KMainWindow
90
91
92
93 class MainWin (KMainWindow):
94 def __init__ (self, *args):
95 KMainWindow.__init__ (self)
96
97 self.resize(640, 480)
98 self.setCentralWidget (MainFrame (self))
99
100 #-------------------- main ------------------------------------------------
101
102 appName = "Solid_StorageDrive"
103 catalog = ""
104 programName = ki18n ("Solid_StorageDrive") #ki18n required here
105 version = "1.0"
106 description = ki18n ("Solid.StorageDrive Example") #ki18n required here
107 license = KAboutData.License_GPL
108 copyright = ki18n ("(c) 2007 Jim Bublitz") #ki18n required here
109 text = ki18n ("none") #ki18n required here
110 homePage = "www.riverbankcomputing.com"
111 bugEmail = "jbublitz@nwinternet.com"
112
113 aboutData = KAboutData (appName, catalog, programName, version, description,
114 license, copyright, text, homePage, bugEmail)
115
116 # ki18n required for first two addAuthor () arguments
117 aboutData.addAuthor (ki18n ("Troy Melhase"), ki18n ("original concept"))
118 aboutData.addAuthor (ki18n ("Jim Bublitz"), ki18n ("pykdedocs"))
119
120 KCmdLineArgs.init (sys.argv, aboutData)
121
122 app = KApplication ()
123 mainWindow = MainWin (None, "main window")
124 mainWindow.show()
125 app.connect (app, SIGNAL ("lastWindowClosed ()"), app.quit)
126 app.exec_ ()
0127
=== added file 'pykde4/solid_storagevolume.py'
--- pykde4/solid_storagevolume.py 1970-01-01 00:00:00 +0000
+++ pykde4/solid_storagevolume.py 2010-03-24 06:55:25 +0000
@@ -0,0 +1,114 @@
1#!/usr/bin/env python
2
3# [SNIPPET_NAME: Solid (Storage Volume)]
4# [SNIPPET_CATEGORIES: PyKDE4]
5# [SNIPPET_DESCRIPTION: Device integration framework for a storage volume]
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.StorageVolume.html]
9
10from PyQt4.QtCore import Qt
11from PyQt4.QtGui import QSizePolicy, QTreeWidget, QTreeWidgetItem, QLabel
12
13from PyKDE4.kdecore import i18n
14from PyKDE4.solid import Solid
15from PyKDE4.kdeui import KVBox, KHBox, KColorButton
16
17helpText = """The Solid class discovers information about the hardware on a machine.
18
19Solid.StorageVolume objects retrieve information about storage volumes on a
20machine. The table below shows the data for your machine.
21
22We use Solid.Device.allDevices () to get a list of all devices, and then
23filter it for Solid.StorageVolume types.
24"""
25
26class MainFrame(KVBox):
27 def __init__(self, parent=None):
28 KVBox.__init__(self, parent)
29 self.help = QLabel (i18n (helpText), self)
30 self.layout ().setAlignment (self.help, Qt.AlignHCenter)
31 self.setSpacing (10)
32
33 hBox = KHBox (self)
34
35 display = QTreeWidget (hBox)
36 display.setSizePolicy (QSizePolicy.Expanding, QSizePolicy.Expanding)
37 display.setHeaderLabels (["Volume", "FS Type", "Label", "Ignored", "Size", "Usage"])
38 display.setColumnWidth (0, 150)
39
40 # convert enum values to strings for display
41 usageType2Str = { Solid.StorageVolume.Other : "Other",\
42 Solid.StorageVolume.Unused : "Unused",\
43 Solid.StorageVolume.FileSystem : "File System",
44 Solid.StorageVolume.PartitionTable : "Partition Tbl",\
45 Solid.StorageVolume.Raid : "Raid",\
46 Solid.StorageVolume.Encrypted : "Encrypted"
47 }
48
49 # retrieve a list of Solid.Device for this machine
50 deviceList = Solid.Device.allDevices ()
51
52 # filter the list of all devices and display matching results
53 # note that we never create a Solid.StorageVolume object,
54 # but receive one from the 'asDeviceInterface" call
55 for device in deviceList:
56 if device.isDeviceInterface (Solid.DeviceInterface.StorageVolume):
57 volume = device.asDeviceInterface (Solid.DeviceInterface.StorageVolume)
58 QTreeWidgetItem (display, [device.product (),
59 volume.fsType (),
60 volume.label (),
61 str (volume.isIgnored ()),
62 "%i MB" % (volume.size ()/1024/1024),
63 usageType2Str [volume.usage ()]])
64
65
66
67
68# This example can be run standalone
69
70if __name__ == '__main__':
71
72 import sys
73
74 from PyQt4.QtCore import SIGNAL
75
76 from PyKDE4.kdecore import KCmdLineArgs, KAboutData, KLocalizedString, ki18n
77 from PyKDE4.kdeui import KApplication, KMainWindow
78
79
80
81 class MainWin (KMainWindow):
82 def __init__ (self, *args):
83 KMainWindow.__init__ (self)
84
85 self.resize(640, 480)
86 self.setCentralWidget (MainFrame (self))
87
88 #-------------------- main ------------------------------------------------
89
90 appName = "Solid_StorageDrive"
91 catalog = ""
92 programName = ki18n ("Solid_StorageDrive") #ki18n required here
93 version = "1.0"
94 description = ki18n ("Solid.StorageDrive Example") #ki18n required here
95 license = KAboutData.License_GPL
96 copyright = ki18n ("(c) 2007 Jim Bublitz") #ki18n required here
97 text = ki18n ("none") #ki18n required here
98 homePage = "www.riverbankcomputing.com"
99 bugEmail = "jbublitz@nwinternet.com"
100
101 aboutData = KAboutData (appName, catalog, programName, version, description,
102 license, copyright, text, homePage, bugEmail)
103
104 # ki18n required for first two addAuthor () arguments
105 aboutData.addAuthor (ki18n ("Troy Melhase"), ki18n ("original concept"))
106 aboutData.addAuthor (ki18n ("Jim Bublitz"), ki18n ("pykdedocs"))
107
108 KCmdLineArgs.init (sys.argv, aboutData)
109
110 app = KApplication ()
111 mainWindow = MainWin (None, "main window")
112 mainWindow.show()
113 app.connect (app, SIGNAL ("lastWindowClosed ()"), app.quit)
114 app.exec_ ()

Subscribers

People subscribed via source and target branches