Merge lp:~nixternal/python-snippets/pykde4 into lp:~jonobacon/python-snippets/trunk
- pykde4
- Merge into 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 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jono Bacon | Pending | ||
Review via email: mp+22004@code.launchpad.net |
Commit message
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
1 | === added directory 'pykde4' |
2 | === added file 'pykde4/kaboutapplicationdialog.py' |
3 | --- pykde4/kaboutapplicationdialog.py 1970-01-01 00:00:00 +0000 |
4 | +++ pykde4/kaboutapplicationdialog.py 2010-03-24 06:55:25 +0000 |
5 | @@ -0,0 +1,94 @@ |
6 | +#!/usr/bin/env python |
7 | + |
8 | +# [SNIPPET_NAME: About Application Dialog] |
9 | +# [SNIPPET_CATEGORIES: PyKDE4] |
10 | +# [SNIPPET_DESCRIPTION: PyKDE4 example showing the About application dialog] |
11 | +# [SNIPPET_AUTHOR: Jim Bublitz <jbublitz@nwinternet.com>] |
12 | +# [SNIPPET_LICENSE: GPL] |
13 | +# [SNIPPET_DOCS: http://api.kde.org/pykde-4.3-api/kdecore/KAboutData.html] |
14 | + |
15 | +from PyQt4.QtCore import SIGNAL, Qt |
16 | +from PyQt4.QtGui import QLabel, QSizePolicy |
17 | + |
18 | +from PyKDE4.kdecore import i18n, ki18n, KAboutData |
19 | +from PyKDE4.kdeui import KVBox, KHBox, KPushButton, KAboutApplicationDialog |
20 | + |
21 | +helpText = """The KAboutApplicationDialog is normally displayed from the |
22 | +applications Help menu. |
23 | + |
24 | +It requires a KAboutData object to provide the information displayed in |
25 | +the dialog. This is usually the same KAboutData object constructed when |
26 | +you start your program, although a different object could be used. |
27 | + |
28 | +Press the button below to display the dialog. |
29 | +""" |
30 | + |
31 | +dialogName = "KAboutApplicationDialog" |
32 | + |
33 | +appName = "kaboutapplicationdialog.py" |
34 | +catalog = "" |
35 | +programName = ki18n ("kaboutapplicationdialog") #ki18n required here |
36 | +version = "1.0" |
37 | +description = ki18n ("KAboutApplicationDialog Example") #ki18n required here |
38 | +license = KAboutData.License_GPL |
39 | +copyright = ki18n ("(c) 2007 Jim Bublitz") #ki18n required here |
40 | +text = ki18n ("none") #ki18n required here |
41 | +homePage = "www.riverbankcomputing.com" |
42 | +bugEmail = "jbublitz@nwinternet.com" |
43 | + |
44 | +aboutData = KAboutData (appName, catalog, programName, version, description, |
45 | + license, copyright, text, homePage, bugEmail) |
46 | + |
47 | +# ki18n required for first two addAuthor () arguments |
48 | +aboutData.addAuthor (ki18n ("Troy Melhase"), ki18n ("original concept")) |
49 | +aboutData.addAuthor (ki18n ("Jim Bublitz"), ki18n ("pykdedocs")) |
50 | + |
51 | + |
52 | +class MainFrame(KVBox): |
53 | + def __init__(self, parent): |
54 | + KVBox.__init__(self, parent) |
55 | + self.help = QLabel (helpText, self) |
56 | + self.layout ().setAlignment (self.help, Qt.AlignHCenter) |
57 | + |
58 | + hBox = KHBox (self) |
59 | + self.button = KPushButton(i18n("Show %s" % dialogName), hBox) |
60 | + self.button.setMaximumSize (250, 30) |
61 | + |
62 | + self.connect(self.button, SIGNAL('clicked()'), self.showDialog) |
63 | + |
64 | + def showDialog(self): |
65 | + dlg = KAboutApplicationDialog (aboutData, self.parent ()) |
66 | + dlg.exec_ () |
67 | + |
68 | + |
69 | + |
70 | +# This example can be run standalone |
71 | + |
72 | +if __name__ == '__main__': |
73 | + |
74 | + import sys |
75 | + |
76 | + from PyQt4.QtCore import SIGNAL |
77 | + |
78 | + from PyKDE4.kdecore import KCmdLineArgs, KAboutData, KLocalizedString, ki18n |
79 | + from PyKDE4.kdeui import KApplication, KMainWindow |
80 | + |
81 | + |
82 | + class MainWin (KMainWindow): |
83 | + def __init__ (self, *args): |
84 | + KMainWindow.__init__ (self) |
85 | + |
86 | + self.resize (640, 480) |
87 | + self.setCentralWidget (MainFrame (self)) |
88 | + |
89 | + |
90 | + #-------------------- main ------------------------------------------------ |
91 | + |
92 | + |
93 | + KCmdLineArgs.init (sys.argv, aboutData) |
94 | + |
95 | + app = KApplication () |
96 | + mainWindow = MainWin (None, "main window") |
97 | + mainWindow.show() |
98 | + app.connect (app, SIGNAL ("lastWindowClosed ()"), app.quit) |
99 | + app.exec_ () |
100 | |
101 | === added file 'pykde4/kaboutkdedialog.py' |
102 | --- pykde4/kaboutkdedialog.py 1970-01-01 00:00:00 +0000 |
103 | +++ pykde4/kaboutkdedialog.py 2010-03-24 06:55:25 +0000 |
104 | @@ -0,0 +1,85 @@ |
105 | +#!/usr/bin/env python |
106 | + |
107 | +# [SNIPPET_NAME: About KDE Dialog] |
108 | +# [SNIPPET_CATEGORIES: PyKDE4] |
109 | +# [SNIPPET_DESCRIPTION: PyKDE4 example showing the About KDE dialog] |
110 | +# [SNIPPET_AUTHOR: Jim Bublitz <jbublitz@nwinternet.com>] |
111 | +# [SNIPPET_LICENSE: GPL] |
112 | +# [SNIPPET_DOCS: http://api.kde.org/pykde-4.3-api/kdecore/KAboutData.html] |
113 | + |
114 | +from PyQt4.QtCore import SIGNAL, Qt |
115 | +from PyQt4.QtGui import QLabel |
116 | + |
117 | +from PyKDE4.kdecore import i18n |
118 | +from PyKDE4.kdeui import KVBox, KHBox, KPushButton, KAboutKdeDialog |
119 | + |
120 | +helpText = """The KAboutKdeDialog is the dialog that is normally |
121 | +available from the help menu. |
122 | + |
123 | +Press the button below to display the dialog. |
124 | +""" |
125 | + |
126 | +dialogName = "KAboutKdeDialog" |
127 | + |
128 | +class MainFrame(KVBox): |
129 | + def __init__(self, parent): |
130 | + KVBox.__init__(self, parent) |
131 | + self.help = QLabel (helpText, self) |
132 | + self.layout ().setAlignment (self.help, Qt.AlignHCenter) |
133 | + |
134 | + hBox = KHBox (self) |
135 | + self.button = KPushButton(i18n("Show %s" % dialogName), hBox) |
136 | + self.button.setMaximumSize (250, 30) |
137 | + |
138 | + self.connect(self.button, SIGNAL('clicked()'), self.showDialog) |
139 | + |
140 | + def showDialog(self): |
141 | + dlg = KAboutKdeDialog (self.parent ()) |
142 | + dlg.exec_ () |
143 | + |
144 | + |
145 | + |
146 | +# This example can be run standalone |
147 | + |
148 | +if __name__ == '__main__': |
149 | + |
150 | + import sys |
151 | + |
152 | + from PyKDE4.kdecore import KCmdLineArgs, KAboutData, KLocalizedString, ki18n |
153 | + from PyKDE4.kdeui import KApplication, KMainWindow |
154 | + |
155 | + |
156 | + class MainWin (KMainWindow): |
157 | + def __init__ (self, *args): |
158 | + KMainWindow.__init__ (self) |
159 | + |
160 | + self.resize(640, 480) |
161 | + self.setCentralWidget (MainFrame (self)) |
162 | + |
163 | + #-------------------- main ------------------------------------------------ |
164 | + |
165 | + appName = "kaboutkdedialog.py" |
166 | + catalog = "" |
167 | + programName = ki18n ("kaboutkdedialog") |
168 | + version = "1.0" |
169 | + description = ki18n ("KAboutKdeDialog Example") |
170 | + license = KAboutData.License_GPL |
171 | + copyright = ki18n ("(c) 2007 Jim Bublitz") |
172 | + text = ki18n ("none") |
173 | + homePage = "www.riverbankcomputing.com" |
174 | + bugEmail = "jbublitz@nwinternet.com" |
175 | + |
176 | + aboutData = KAboutData (appName, catalog, programName, version, description, |
177 | + license, copyright, text, homePage, bugEmail) |
178 | + |
179 | + # ki18n required for first two addAuthor () arguments |
180 | + aboutData.addAuthor (ki18n ("Troy Melhase"), ki18n ("original concept")) |
181 | + aboutData.addAuthor (ki18n ("Jim Bublitz"), ki18n ("pykdedocs")) |
182 | + |
183 | + KCmdLineArgs.init (sys.argv, aboutData) |
184 | + |
185 | + app = KApplication () |
186 | + mainWindow = MainWin (None, "main window") |
187 | + mainWindow.show() |
188 | + app.connect (app, SIGNAL ("lastWindowClosed ()"), app.quit) |
189 | + app.exec_ () |
190 | |
191 | === added file 'pykde4/kapplication.py' |
192 | --- pykde4/kapplication.py 1970-01-01 00:00:00 +0000 |
193 | +++ pykde4/kapplication.py 2010-03-24 06:55:25 +0000 |
194 | @@ -0,0 +1,72 @@ |
195 | +#!/usr/bin/env python |
196 | + |
197 | +# [SNIPPET_NAME: Main Window Application] |
198 | +# [SNIPPET_CATEGORIES: PyKDE4] |
199 | +# [SNIPPET_DESCRIPTION: PyKDE4 example showing KMainWindow and KApplication] |
200 | +# [SNIPPET_AUTHOR: Jim Bublitz <jbublitz@nwinternet.com>] |
201 | +# [SNIPPET_LICENSE: GPL] |
202 | +# [SNIPPET_DOCS: http://api.kde.org/pykde-4.3-api/kdeui/KApplication.html, http://api.kde.org/pykde-4.3-api/kdeui/KMainWindow.html] |
203 | + |
204 | +import sys |
205 | + |
206 | +from PyKDE4.kdecore import ki18n, KAboutData, KCmdLineArgs |
207 | +from PyKDE4.kdeui import KApplication, KMainWindow |
208 | + |
209 | +from PyQt4.QtGui import QLabel |
210 | + |
211 | +runner = True |
212 | + |
213 | +helpText = """This short program is the basic KDE application. |
214 | + |
215 | +It uses KAboutData to initialize some basic program information |
216 | +that is used by KDE (beyond simply setting up the About dialog |
217 | +box in a more complex program). |
218 | + |
219 | +It creates a KMainWindow, so the program has a place to display |
220 | +its output and interact with users. |
221 | + |
222 | +It also creates a KApplication object, which is necessary for |
223 | +the use of most KDE widgets and other classes, and makes |
224 | +available access to standard information about things like |
225 | +icons, directory locations, colors, fonts and similar data. |
226 | + |
227 | +Lastly, it starts an event loop (app.exec_) to allow a user |
228 | +to interact with the program. |
229 | + |
230 | +Click the button to launch the application. |
231 | +""" |
232 | + |
233 | + |
234 | + |
235 | +class MainWindow (KMainWindow): |
236 | + def __init__ (self): |
237 | + KMainWindow.__init__ (self) |
238 | + |
239 | + self.resize (640, 480) |
240 | + label = QLabel ("This is a simple PyKDE4 program", self) |
241 | + label.setGeometry (10, 10, 200, 20) |
242 | + |
243 | +#--------------- main ------------------ |
244 | +if __name__ == '__main__': |
245 | + |
246 | + appName = "KApplication" |
247 | + catalog = "" |
248 | + programName = ki18n ("KApplication") |
249 | + version = "1.0" |
250 | + description = ki18n ("KApplication/KMainWindow/KAboutData example") |
251 | + license = KAboutData.License_GPL |
252 | + copyright = ki18n ("(c) 2007 Jim Bublitz") |
253 | + text = ki18n ("none") |
254 | + homePage = "www.riverbankcomputing.com" |
255 | + bugEmail = "jbublitz@nwinternet.com" |
256 | + |
257 | + aboutData = KAboutData (appName, catalog, programName, version, description, |
258 | + license, copyright, text, homePage, bugEmail) |
259 | + |
260 | + |
261 | + KCmdLineArgs.init (sys.argv, aboutData) |
262 | + |
263 | + app = KApplication () |
264 | + mainWindow = MainWindow () |
265 | + mainWindow.show () |
266 | + app.exec_ () |
267 | |
268 | === added file 'pykde4/katepart.py' |
269 | --- pykde4/katepart.py 1970-01-01 00:00:00 +0000 |
270 | +++ pykde4/katepart.py 2010-03-24 06:55:25 +0000 |
271 | @@ -0,0 +1,50 @@ |
272 | +#!/usr/bin/env python |
273 | + |
274 | +# [SNIPPET_NAME: KPart (Kate)] |
275 | +# [SNIPPET_CATEGORIES: PyKDE4] |
276 | +# [SNIPPET_DESCRIPTION: KPart example using the Kate part] |
277 | +# [SNIPPET_AUTHOR: Jonathan Riddell <jriddell@ubuntu.com>] |
278 | +# [SNIPPET_LICENSE: GPL] |
279 | +# [SNIPPET_DOCS: http://api.kde.org/pykde-4.3-api/kdecore/KLibLoader.html, http://api.kde.org/pykde-4.3-api/kparts/index.html] |
280 | + |
281 | +import sys |
282 | + |
283 | +from PyKDE4.kdecore import * |
284 | +from PyKDE4.kdeui import * |
285 | +from PyKDE4.kparts import * |
286 | + |
287 | +from PyQt4.QtGui import QLabel |
288 | + |
289 | +class MainWindow (KMainWindow): |
290 | + def __init__ (self): |
291 | + KMainWindow.__init__(self) |
292 | + |
293 | + self.resize(640, 480) |
294 | + |
295 | + factory = KLibLoader.self().factory("katepart") |
296 | + part = factory.create(self, "KatePart") |
297 | + self.setCentralWidget(part.widget()) |
298 | + |
299 | +#--------------- main ------------------ |
300 | +if __name__ == '__main__': |
301 | + |
302 | + appName = "katepart_example" |
303 | + catalog = "" |
304 | + programName = ki18n("Kate Part Example") |
305 | + version = "1.0" |
306 | + description = ki18n("Example loading a Kate Part") |
307 | + license = KAboutData.License_GPL |
308 | + copyright = ki18n("(c) 2009 Canonical Ltd") |
309 | + text = ki18n("none") |
310 | + homePage = "www.kubuntu.org" |
311 | + bugEmail = "jriddell@ubuntu.com" |
312 | + |
313 | + aboutData = KAboutData(appName, catalog, programName, version, description, |
314 | + license, copyright, text, homePage, bugEmail) |
315 | + |
316 | + KCmdLineArgs.init(sys.argv, aboutData) |
317 | + |
318 | + app = KApplication() |
319 | + mainWindow = MainWindow() |
320 | + mainWindow.show() |
321 | + app.exec_() |
322 | |
323 | === added file 'pykde4/kcolorbutton.py' |
324 | --- pykde4/kcolorbutton.py 1970-01-01 00:00:00 +0000 |
325 | +++ pykde4/kcolorbutton.py 2010-03-24 06:55:25 +0000 |
326 | @@ -0,0 +1,130 @@ |
327 | +#!/usr/bin/env python |
328 | + |
329 | +# [SNIPPET_NAME: Pushbutton (Color Selection)] |
330 | +# [SNIPPET_CATEGORIES: PyKDE4] |
331 | +# [SNIPPET_DESCRIPTION: A pushbutton to display or allow user selection of a color] |
332 | +# [SNIPPET_AUTHOR: Jim Bublitz <jbublitz@nwinternet.com>] |
333 | +# [SNIPPET_LICENSE: GPL] |
334 | +# [SNIPPET_DOCS: http://api.kde.org/pykde-4.3-api/kdeui/KColorButton.html] |
335 | + |
336 | +from PyQt4.QtCore import SIGNAL, Qt |
337 | +from PyQt4.QtGui import QLabel |
338 | + |
339 | +from PyKDE4.kdecore import i18n |
340 | +from PyKDE4.kdeui import KVBox, KHBox, KColorButton, KColorCells, KColorCombo, KColorPatch |
341 | + |
342 | +helpText = """These are examples of three ways of changing colors interactively, |
343 | +and one widget that displays a chosen color. |
344 | + |
345 | +When KColorButton is clicked, it pops up a color selection dialog. |
346 | + |
347 | +KColorCells offers one way to present a pre-selected range of color |
348 | +choices, and may have more rows and columns than displayed here. |
349 | +Click on a cell to select a color. |
350 | + |
351 | +KColorCombo provides a programmable drop down list of colors to select |
352 | +from. |
353 | + |
354 | +Finally, KColorPatch will display a specified color. In this example, using |
355 | +any of the other three widgets to select a color will change the color of |
356 | +the KColorPatch. |
357 | +""" |
358 | + |
359 | +class MainFrame(KVBox): |
360 | + def __init__(self, parent=None): |
361 | + KVBox.__init__(self, parent) |
362 | + self.help = QLabel (helpText, self) |
363 | + self.layout ().setAlignment (self.help, Qt.AlignHCenter) |
364 | + |
365 | + hBox1 = KHBox (self) |
366 | + hBox1.setSpacing (10) |
367 | + hBox1.setMargin (40) |
368 | + |
369 | + |
370 | + colorButtonLabel = QLabel ("KColorButton", hBox1) |
371 | + colorButton = KColorButton (hBox1) |
372 | + |
373 | + colorCellsLabel = QLabel ("KColorCells", hBox1) |
374 | + colorCells = KColorCells (hBox1, 1, 8) |
375 | + colorCells.setMaximumSize (160, 20) |
376 | + colorCells.setColor (0, Qt.black) |
377 | + colorCells.setColor (1, Qt.red) |
378 | + colorCells.setColor (2, Qt.yellow) |
379 | + colorCells.setColor (3, Qt.blue) |
380 | + colorCells.setColor (4, Qt.darkGreen) |
381 | + colorCells.setColor (5, Qt.magenta) |
382 | + colorCells.setColor (6, Qt.gray) |
383 | + colorCells.setColor (7, Qt.white) |
384 | + |
385 | + |
386 | + colorComboLabel = QLabel ("KColorCombo", hBox1) |
387 | + colorCombo = KColorCombo (hBox1) |
388 | + |
389 | + colorList = [Qt.black, Qt.red, Qt.yellow, Qt.blue, Qt.darkGreen, Qt.magenta, Qt.gray, Qt.white] |
390 | + colorCombo.setColors (colorList) |
391 | + colorCombo.setMaximumWidth (80) |
392 | + |
393 | + hBox2 = KHBox (self) |
394 | + hBox2.setSpacing (10) |
395 | + self.layout ().setAlignment (hBox2, Qt.AlignHCenter | Qt.AlignTop) |
396 | + self.setStretchFactor (hBox2, 1) |
397 | + |
398 | + colorPatchLabel = QLabel ("KColorPatch", hBox2) |
399 | + hBox2.layout ().setAlignment (colorPatchLabel, Qt.AlignHCenter) |
400 | + self.colorPatch = KColorPatch (hBox2) |
401 | + self.colorPatch.setFixedSize (40, 40) |
402 | + hBox2.layout ().setAlignment (self.colorPatch, Qt.AlignHCenter) |
403 | + |
404 | + self.colorPatch.setColor (Qt.red) |
405 | + self.colorPatch.show () |
406 | + |
407 | + self.connect (colorButton, SIGNAL ("changed (const QColor&)"), self.colorPatch.setColor) |
408 | + self.connect (colorCells, SIGNAL ("colorSelected (int, const QColor&)"), self.colorCellSelected) |
409 | + self.connect (colorCombo, SIGNAL ("activated (const QColor&)"), self.colorPatch.setColor) |
410 | + |
411 | + def colorCellSelected (self, int, color): |
412 | + self.colorPatch.setColor (color) |
413 | + |
414 | +# This example can be run standalone |
415 | + |
416 | +if __name__ == '__main__': |
417 | + |
418 | + import sys |
419 | + |
420 | + from PyKDE4.kdecore import KCmdLineArgs, KAboutData, KLocalizedString, ki18n |
421 | + from PyKDE4.kdeui import KApplication, KMainWindow |
422 | + |
423 | + class MainWin (KMainWindow): |
424 | + def __init__ (self, *args): |
425 | + KMainWindow.__init__ (self) |
426 | + |
427 | + self.resize(640, 480) |
428 | + self.setCentralWidget (MainFrame (self)) |
429 | + |
430 | + #-------------------- main ------------------------------------------------ |
431 | + |
432 | + appName = "default" |
433 | + catalog = "" |
434 | + programName = ki18n ("default") #ki18n required here |
435 | + version = "1.0" |
436 | + description = ki18n ("Default Example") #ki18n required here |
437 | + license = KAboutData.License_GPL |
438 | + copyright = ki18n ("(c) 2007 Jim Bublitz") #ki18n required here |
439 | + text = ki18n ("none") #ki18n required here |
440 | + homePage = "www.riverbankcomputing.com" |
441 | + bugEmail = "jbublitz@nwinternet.com" |
442 | + |
443 | + aboutData = KAboutData (appName, catalog, programName, version, description, |
444 | + license, copyright, text, homePage, bugEmail) |
445 | + |
446 | + # ki18n required for first two addAuthor () arguments |
447 | + aboutData.addAuthor (ki18n ("Troy Melhase"), ki18n ("original concept")) |
448 | + aboutData.addAuthor (ki18n ("Jim Bublitz"), ki18n ("pykdedocs")) |
449 | + |
450 | + KCmdLineArgs.init (sys.argv, aboutData) |
451 | + |
452 | + app = KApplication () |
453 | + mainWindow = MainWin (None, "main window") |
454 | + mainWindow.show() |
455 | + app.connect (app, SIGNAL ("lastWindowClosed ()"), app.quit) |
456 | + app.exec_ () |
457 | |
458 | === added file 'pykde4/kcolordialog.py' |
459 | --- pykde4/kcolordialog.py 1970-01-01 00:00:00 +0000 |
460 | +++ pykde4/kcolordialog.py 2010-03-24 06:55:25 +0000 |
461 | @@ -0,0 +1,93 @@ |
462 | +#!/usr/bin/env python |
463 | + |
464 | +# [SNIPPET_NAME: Dialog (Color Selection)] |
465 | +# [SNIPPET_CATEGORIES: PyKDE4] |
466 | +# [SNIPPET_DESCRIPTION: A color selection dialog] |
467 | +# [SNIPPET_AUTHOR: Jim Bublitz <jbublitz@nwinternet.com>] |
468 | +# [SNIPPET_LICENSE: GPL] |
469 | +# [SNIPPET_DOCS: http://api.kde.org/pykde-4.3-api/kdeui/KColorDialog.html] |
470 | + |
471 | +from PyQt4.QtCore import SIGNAL, Qt |
472 | +from PyQt4.QtGui import QLabel |
473 | +from PyQt4.QtGui import QColor |
474 | + |
475 | +from PyKDE4.kdecore import i18n |
476 | +from PyKDE4.kdeui import KVBox, KHBox, KPushButton, KColorDialog, KColorPatch |
477 | + |
478 | +helpText = """This example uses KColorDialog.getColor (color, parent) to |
479 | +popup a dialog that allows the user to set the color of the KColorPatch |
480 | +next to the button. |
481 | + |
482 | +Click the button to run the dialog and select a color. |
483 | +""" |
484 | + |
485 | +dialogName = "KColorDialog" |
486 | + |
487 | +class MainFrame(KVBox): |
488 | + def __init__(self, parent): |
489 | + KVBox.__init__(self, parent) |
490 | + self.help = QLabel (helpText, self) |
491 | + self.layout ().setAlignment (self.help, Qt.AlignHCenter) |
492 | + |
493 | + hBox = KHBox (self) |
494 | + self.button = KPushButton(i18n("Show %s" % dialogName), hBox) |
495 | + self.button.setMaximumSize (250, 30) |
496 | + |
497 | + self.connect(self.button, SIGNAL('clicked()'), self.showDialog) |
498 | + |
499 | + self.colorPatch = KColorPatch (hBox) |
500 | + self.colorPatch.setColor (Qt.red) |
501 | + self.colorPatch.setMaximumSize (40, 40) |
502 | + |
503 | + |
504 | + def showDialog(self): |
505 | + color = QColor () |
506 | + result = KColorDialog.getColor (color, self) |
507 | + self.colorPatch.setColor (color) |
508 | + |
509 | + |
510 | + |
511 | +# This example can be run standalone |
512 | + |
513 | +if __name__ == '__main__': |
514 | + |
515 | + import sys |
516 | + |
517 | + from PyKDE4.kdecore import KCmdLineArgs, KAboutData, KLocalizedString, ki18n |
518 | + from PyKDE4.kdeui import KApplication, KMainWindow |
519 | + |
520 | + |
521 | + class MainWin (KMainWindow): |
522 | + def __init__ (self, *args): |
523 | + KMainWindow.__init__ (self) |
524 | + |
525 | + self.resize(640, 480) |
526 | + self.setCentralWidget (MainFrame (self)) |
527 | + |
528 | + #-------------------- main ------------------------------------------------ |
529 | + |
530 | + appName = "default.py" |
531 | + catalog = "" |
532 | + programName = ki18n ("default") #ki18n required here |
533 | + version = "1.0" |
534 | + description = ki18n ("Default Example") #ki18n required here |
535 | + license = KAboutData.License_GPL |
536 | + copyright = ki18n ("(c) 2007 Jim Bublitz") #ki18n required here |
537 | + text = ki18n ("none") #ki18n required here |
538 | + homePage = "www.riverbankcomputing.com" |
539 | + bugEmail = "jbublitz@nwinternet.com" |
540 | + |
541 | + aboutData = KAboutData (appName, catalog, programName, version, description, |
542 | + license, copyright, text, homePage, bugEmail) |
543 | + |
544 | + # ki18n required for first two addAuthor () arguments |
545 | + aboutData.addAuthor (ki18n ("Troy Melhase"), ki18n ("original concept")) |
546 | + aboutData.addAuthor (ki18n ("Jim Bublitz"), ki18n ("pykdedocs")) |
547 | + |
548 | + KCmdLineArgs.init (sys.argv, aboutData) |
549 | + |
550 | + app = KApplication () |
551 | + mainWindow = MainWin (None, "main window") |
552 | + mainWindow.show() |
553 | + app.connect (app, SIGNAL ("lastWindowClosed ()"), app.quit) |
554 | + app.exec_ () |
555 | |
556 | === added file 'pykde4/kcombobox.py' |
557 | --- pykde4/kcombobox.py 1970-01-01 00:00:00 +0000 |
558 | +++ pykde4/kcombobox.py 2010-03-24 06:55:25 +0000 |
559 | @@ -0,0 +1,119 @@ |
560 | +#!/usr/bin/env python |
561 | + |
562 | +# [SNIPPET_NAME: Combo Box] |
563 | +# [SNIPPET_CATEGORIES: PyKDE4] |
564 | +# [SNIPPET_DESCRIPTION: An enhanced combo box which is a combined button, line-edit and popup list widget] |
565 | +# [SNIPPET_AUTHOR: Jim Bublitz <jbublitz@nwinternet.com>] |
566 | +# [SNIPPET_LICENSE: GPL] |
567 | +# [SNIPPET_DOCS: http://api.kde.org/pykde-4.3-api/kdeui/KComboBox.html] |
568 | + |
569 | +from PyQt4.QtCore import SIGNAL, Qt |
570 | +from PyQt4.QtGui import QLabel |
571 | + |
572 | +from PyKDE4.kdecore import i18n, KStandardDirs |
573 | +from PyKDE4.kdeui import KVBox, KHBox, KComboBox, KListWidget |
574 | + |
575 | +helpText = """ |
576 | +KListWidget and KComboBox are useful for displaying or |
577 | +interacting with lists of items. In this case, we |
578 | +display the KStandardDirs file types and directory |
579 | +locations. |
580 | + |
581 | +KComboBox is filled from the QStringList that the |
582 | +method "allTypes()" returns. It can also be filled |
583 | +with a single item at a time, and we can sort or |
584 | +add/remove items later. KDE has specialized KComboBox |
585 | +subclasses for other purposes. It inherits methods |
586 | +from QComboBox |
587 | + |
588 | +KListWidget also displays lists of information, but all |
589 | +are visible at the same time. It inherits classes |
590 | +from QListWidget and QListView. |
591 | +""" |
592 | + |
593 | +class MainFrame(KVBox): |
594 | + def __init__(self, parent=None): |
595 | + KVBox.__init__(self, parent) |
596 | + self.help = QLabel (i18n (helpText), self) |
597 | + self.layout ().setAlignment (self.help, Qt.AlignHCenter) |
598 | + self.setSpacing (10) |
599 | + |
600 | + hBox = KHBox (self) |
601 | + self.layout ().setAlignment (hBox, Qt.AlignHCenter) |
602 | + |
603 | + cBox = KVBox (hBox) |
604 | + hBox.layout ().setAlignment (cBox, Qt.AlignTop) |
605 | + hBox.setSpacing (25) |
606 | + hBox.setMargin (10) |
607 | + |
608 | + self.stdDirs = KStandardDirs () |
609 | + types = self.stdDirs.allTypes () |
610 | + |
611 | + comboLbl = QLabel ("Types", cBox) |
612 | + combo = KComboBox (cBox) |
613 | + combo.addItems (types) |
614 | + cBox.layout ().setAlignment (comboLbl, Qt.AlignTop) |
615 | + cBox.layout ().setAlignment (combo, Qt.AlignTop) |
616 | + |
617 | + self.connect (combo, SIGNAL ("currentIndexChanged (const QString&)"), self.slotIndexChanged) |
618 | + |
619 | + lBox = KVBox (hBox) |
620 | + listLbl = QLabel ("Directories", lBox) |
621 | + self.location = KListWidget (lBox) |
622 | + self.location.setMaximumSize (400, 200) |
623 | + lBox.layout ().setAlignment (listLbl, Qt.AlignTop) |
624 | + lBox.layout ().setAlignment (self.location, Qt.AlignTop) |
625 | + |
626 | + self.slotIndexChanged (combo.currentText ()) |
627 | + |
628 | + |
629 | + def slotIndexChanged (self, s): |
630 | + self.location.clear () |
631 | + self.location.insertItems (0, self.stdDirs.resourceDirs (str (s))) |
632 | + |
633 | + |
634 | + |
635 | + |
636 | +# This example can be run standalone |
637 | + |
638 | +if __name__ == '__main__': |
639 | + |
640 | + import sys |
641 | + |
642 | + from PyKDE4.kdecore import KCmdLineArgs, KAboutData, KLocalizedString, ki18n |
643 | + from PyKDE4.kdeui import KApplication, KMainWindow |
644 | + |
645 | + class MainWin (KMainWindow): |
646 | + def __init__ (self, *args): |
647 | + KMainWindow.__init__ (self) |
648 | + |
649 | + self.resize(640, 480) |
650 | + self.setCentralWidget (MainFrame (self)) |
651 | + |
652 | + #-------------------- main ------------------------------------------------ |
653 | + |
654 | + appName = "default" |
655 | + catalog = "" |
656 | + programName = ki18n ("default") #ki18n required here |
657 | + version = "1.0" |
658 | + description = ki18n ("Default Example") #ki18n required here |
659 | + license = KAboutData.License_GPL |
660 | + copyright = ki18n ("(c) 2007 Jim Bublitz") #ki18n required here |
661 | + text = ki18n ("none") #ki18n required here |
662 | + homePage = "www.riverbankcomputing.com" |
663 | + bugEmail = "jbublitz@nwinternet.com" |
664 | + |
665 | + aboutData = KAboutData (appName, catalog, programName, version, description, |
666 | + license, copyright, text, homePage, bugEmail) |
667 | + |
668 | + # ki18n required for first two addAuthor () arguments |
669 | + aboutData.addAuthor (ki18n ("Troy Melhase"), ki18n ("original concept")) |
670 | + aboutData.addAuthor (ki18n ("Jim Bublitz"), ki18n ("pykdedocs")) |
671 | + |
672 | + KCmdLineArgs.init (sys.argv, aboutData) |
673 | + |
674 | + app = KApplication () |
675 | + mainWindow = MainWin (None, "main window") |
676 | + mainWindow.show() |
677 | + app.connect (app, SIGNAL ("lastWindowClosed ()"), app.quit) |
678 | + app.exec_ () |
679 | |
680 | === added file 'pykde4/kdatepicker.py' |
681 | --- pykde4/kdatepicker.py 1970-01-01 00:00:00 +0000 |
682 | +++ pykde4/kdatepicker.py 2010-03-24 06:55:25 +0000 |
683 | @@ -0,0 +1,98 @@ |
684 | +#!/usr/bin/env python |
685 | + |
686 | +# [SNIPPET_NAME: Date Selection Widget] |
687 | +# [SNIPPET_CATEGORIES: PyKDE4] |
688 | +# [SNIPPET_DESCRIPTION: Provides a widget for calendar date input] |
689 | +# [SNIPPET_AUTHOR: Troy Melhase] |
690 | +# [SNIPPET_LICENSE: GPL] |
691 | +# [SNIPPET_DOCS: http://api.kde.org/pykde-4.3-api/kdeui/KDatePicker.html] |
692 | + |
693 | +from PyQt4.QtCore import SIGNAL, Qt |
694 | +from PyQt4.QtGui import QLabel |
695 | + |
696 | +from PyKDE4.kdecore import i18n |
697 | +from PyKDE4.kdeui import KVBox, KHBox, KDatePicker, KDateWidget |
698 | + |
699 | + |
700 | +helpText = """Date selection widgets - KDatePicker and KDateWidget - provide widgets for calendar |
701 | +date input. |
702 | + |
703 | +KDatePicker emits two types of signals, either dateSelected() or dateEntered(). |
704 | + |
705 | +A line edit allows the user to select a date directly by entering numbers like |
706 | +19990101 or 990101 into KDatePicker.""" |
707 | + |
708 | +class MainFrame(KVBox): |
709 | + def __init__(self, parent=None): |
710 | + KVBox.__init__(self, parent) |
711 | + self.help = QLabel (i18n (helpText), self) |
712 | + self.layout ().setAlignment (self.help, Qt.AlignHCenter | Qt.AlignTop) |
713 | + self.setSpacing (40) |
714 | + |
715 | + hBox = KHBox (self) |
716 | + vBox1 = KVBox (hBox) |
717 | + vBox2 = KVBox (hBox) |
718 | + |
719 | + hBox.layout ().setAlignment (vBox1, Qt.AlignHCenter) |
720 | + hBox.layout ().setAlignment (vBox2, Qt.AlignHCenter) |
721 | + vBox1.setMargin (20) |
722 | + vBox2.setSpacing (20) |
723 | + |
724 | + self.datePickerLabel = QLabel ("KDatePicker", vBox1) |
725 | + |
726 | + self.datePicker = KDatePicker(vBox2) |
727 | + self.datePicker.setFixedSize (400, 200) |
728 | + |
729 | + self.other = QLabel('KDateWidget', vBox1) |
730 | + vBox1.layout ().setAlignment (self.other, Qt.AlignBottom) |
731 | + |
732 | + self.dateDisplay = KDateWidget(vBox2) |
733 | + |
734 | + |
735 | + self.connect(self.datePicker, SIGNAL('dateChanged(QDate)'), |
736 | + self.dateDisplay.setDate) |
737 | + |
738 | + |
739 | +# This example can be run standalone |
740 | + |
741 | +if __name__ == '__main__': |
742 | + |
743 | + import sys |
744 | + |
745 | + from PyKDE4.kdecore import KCmdLineArgs, KAboutData, KLocalizedString, ki18n |
746 | + from PyKDE4.kdeui import KApplication, KMainWindow |
747 | + |
748 | + |
749 | + class MainWin (KMainWindow): |
750 | + def __init__ (self, *args): |
751 | + KMainWindow.__init__ (self) |
752 | + |
753 | + self.resize(640, 500) |
754 | + self.setCentralWidget (MainFrame (self)) |
755 | + |
756 | + #-------------------- main ------------------------------------------------ |
757 | + |
758 | + appName = "kdatepicker" |
759 | + catalog = "" |
760 | + programName = ki18n ("kdatepicker") |
761 | + version = "1.0" |
762 | + description = ki18n ("KDatePicker Example") |
763 | + license = KAboutData.License_GPL |
764 | + copyright = ki18n ("(c) 2006 Troy Melhase") |
765 | + text = ki18n ("none") |
766 | + homePage = "www.riverbankcomputing.com" |
767 | + bugEmail = "jbublitz@nwinternet.com" |
768 | + |
769 | + aboutData = KAboutData (appName, catalog, programName, version, description, |
770 | + license, copyright, text, homePage, bugEmail) |
771 | + |
772 | + aboutData.addAuthor (ki18n ("Troy Melhase"), ki18n ("original concept")) |
773 | + aboutData.addAuthor (ki18n ("Jim Bublitz"), ki18n ("pykdedocs")) |
774 | + |
775 | + KCmdLineArgs.init (sys.argv, aboutData) |
776 | + |
777 | + app = KApplication () |
778 | + mainWindow = MainWin (None, "main window") |
779 | + mainWindow.show() |
780 | + app.connect (app, SIGNAL ("lastWindowClosed ()"), app.quit) |
781 | + app.exec_ () |
782 | |
783 | === added file 'pykde4/kfontdialog.py' |
784 | --- pykde4/kfontdialog.py 1970-01-01 00:00:00 +0000 |
785 | +++ pykde4/kfontdialog.py 2010-03-24 06:55:25 +0000 |
786 | @@ -0,0 +1,96 @@ |
787 | +#!/usr/bin/env python |
788 | + |
789 | +# [SNIPPET_NAME: Dialog (Font Selection)] |
790 | +# [SNIPPET_CATEGORIES: PyKDE4] |
791 | +# [SNIPPET_DESCRIPTION: A dialog that provides interactive font selection] |
792 | +# [SNIPPET_AUTHOR: Jim Bublitz <jbublitz@nwinternet.com>] |
793 | +# [SNIPPET_LICENSE: GPL] |
794 | +# [SNIPPET_DOCS: http://api.kde.org/pykde-4.3-api/kdeui/KFontDialog.html] |
795 | + |
796 | +from PyQt4.QtCore import SIGNAL, Qt |
797 | +from PyQt4.QtGui import QLabel, QDialog, QFont |
798 | + |
799 | +from PyKDE4.kdecore import i18n |
800 | +from PyKDE4.kdeui import KVBox, KHBox, KPushButton, KFontDialog |
801 | + |
802 | +helpText = """A KFontDialog allows the user to select a new font. |
803 | + |
804 | +Click the button to change the font of the displayed text. |
805 | +""" |
806 | + |
807 | +quote = """Now is the winter of our discontent |
808 | +made summer by this glorious sun of York. |
809 | +""" |
810 | + |
811 | +dialogName = "KFontDialog" |
812 | + |
813 | +class MainFrame(KVBox): |
814 | + def __init__(self, parent): |
815 | + KVBox.__init__(self, parent) |
816 | + self.setSpacing (40) |
817 | + self.help = QLabel (i18n (helpText), self) |
818 | + self.layout ().setAlignment (self.help, Qt.AlignHCenter) |
819 | + |
820 | + self.button = KPushButton(i18n("Show %s" % dialogName), self) |
821 | + self.button.setFixedSize (200, 30) |
822 | + self.layout ().setAlignment (self.button, Qt.AlignHCenter) |
823 | + self.fontLabel = QLabel (quote, self) |
824 | + self.layout ().setAlignment (self.fontLabel, Qt.AlignHCenter) |
825 | + |
826 | + self.connect(self.button, SIGNAL('clicked()'), self.showDialog) |
827 | + |
828 | + def showDialog(self): |
829 | + font = QFont () |
830 | + result, checkState = KFontDialog.getFont (font) |
831 | + if result == QDialog.Accepted: |
832 | + self.fontLabel.setFont (font) |
833 | + |
834 | + |
835 | + |
836 | +# This example can be run standalone |
837 | + |
838 | +if __name__ == '__main__': |
839 | + |
840 | + import sys |
841 | + |
842 | + from PyQt4.QtCore import Qt |
843 | + from PyQt4.QtGui import QFrame, QVBoxLayout |
844 | + |
845 | + from PyKDE4.kdecore import KCmdLineArgs, KAboutData, KLocalizedString, ki18n |
846 | + from PyKDE4.kdeui import KApplication, KMainWindow |
847 | + |
848 | + class MainWin (KMainWindow): |
849 | + def __init__ (self, *args): |
850 | + KMainWindow.__init__ (self) |
851 | + |
852 | + self.resize(640, 480) |
853 | + self.setCentralWidget (MainFrame (self)) |
854 | + |
855 | + |
856 | + #-------------------- main ------------------------------------------------ |
857 | + |
858 | + appName = "default.py" |
859 | + catalog = "" |
860 | + programName = ki18n ("default") #ki18n required here |
861 | + version = "1.0" |
862 | + description = ki18n ("Default Example") #ki18n required here |
863 | + license = KAboutData.License_GPL |
864 | + copyright = ki18n ("(c) 2007 Jim Bublitz") #ki18n required here |
865 | + text = ki18n ("none") #ki18n required here |
866 | + homePage = "www.riverbankcomputing.com" |
867 | + bugEmail = "jbublitz@nwinternet.com" |
868 | + |
869 | + aboutData = KAboutData (appName, catalog, programName, version, description, |
870 | + license, copyright, text, homePage, bugEmail) |
871 | + |
872 | + # ki18n required for first two addAuthor () arguments |
873 | + aboutData.addAuthor (ki18n ("Troy Melhase"), ki18n ("original concept")) |
874 | + aboutData.addAuthor (ki18n ("Jim Bublitz"), ki18n ("pykdedocs")) |
875 | + |
876 | + KCmdLineArgs.init (sys.argv, aboutData) |
877 | + |
878 | + app = KApplication () |
879 | + mainWindow = MainWin (None, "main window") |
880 | + mainWindow.show() |
881 | + app.connect (app, SIGNAL ("lastWindowClosed ()"), app.quit) |
882 | + app.exec_ () |
883 | |
884 | === added file 'pykde4/kstandarddirs.py' |
885 | --- pykde4/kstandarddirs.py 1970-01-01 00:00:00 +0000 |
886 | +++ pykde4/kstandarddirs.py 2010-03-24 06:55:25 +0000 |
887 | @@ -0,0 +1,113 @@ |
888 | +#!/usr/bin/env python |
889 | + |
890 | +# [SNIPPET_NAME: KDE Standard Directories] |
891 | +# [SNIPPET_CATEGORIES: PyKDE4] |
892 | +# [SNIPPET_DESCRIPTION: Site-independent access to standard KDE directories] |
893 | +# [SNIPPET_AUTHOR: Jim Bublitz <jbublitz@nwinternet.com>] |
894 | +# [SNIPPET_LICENSE: GPL] |
895 | +# [SNIPPET_DOCS: http://api.kde.org/pykde-4.3-api/kdecore/KStandardDirs.html] |
896 | + |
897 | +from PyQt4.QtCore import SIGNAL, Qt |
898 | +from PyQt4.QtGui import QLabel |
899 | + |
900 | +from PyKDE4.kdecore import i18n, KStandardDirs |
901 | +from PyKDE4.kdeui import KVBox, KHBox, KComboBox, KListWidget |
902 | + |
903 | +helpText = """KStandardDirs provides methods for locating KDE objects |
904 | + within the filesystem - for example, icons, configuration |
905 | + files, etc. |
906 | + |
907 | + KStandardDirs recognizes a number of data types (shown in the |
908 | + combo box at left) and associates the types with directories. |
909 | + |
910 | + You can use this information to locate a resource, or to |
911 | + determine where to install a resource for you program. |
912 | +""" |
913 | + |
914 | +class MainFrame(KVBox): |
915 | + def __init__(self, parent=None): |
916 | + KVBox.__init__(self, parent) |
917 | + self.help = QLabel (i18n (helpText), self) |
918 | + self.layout ().setAlignment (self.help, Qt.AlignHCenter) |
919 | + self.setSpacing (10) |
920 | + |
921 | + hBox = KHBox (self) |
922 | + self.layout ().setAlignment (hBox, Qt.AlignHCenter) |
923 | + |
924 | + cBox = KVBox (hBox) |
925 | + hBox.layout ().setAlignment (cBox, Qt.AlignTop) |
926 | + hBox.setSpacing (25) |
927 | + hBox.setMargin (10) |
928 | + |
929 | + self.stdDirs = KStandardDirs () |
930 | + types = self.stdDirs.allTypes () |
931 | + |
932 | + comboLbl = QLabel ("Types", cBox) |
933 | + combo = KComboBox (cBox) |
934 | + combo.addItems (types) |
935 | + cBox.layout ().setAlignment (comboLbl, Qt.AlignTop) |
936 | + cBox.layout ().setAlignment (combo, Qt.AlignTop) |
937 | + |
938 | + self.connect (combo, SIGNAL ("currentIndexChanged (const QString&)"), self.slotIndexChanged) |
939 | + |
940 | + lBox = KVBox (hBox) |
941 | + listLbl = QLabel ("Directories", lBox) |
942 | + self.location = KListWidget (lBox) |
943 | + self.location.setMaximumSize (400, 200) |
944 | + lBox.layout ().setAlignment (listLbl, Qt.AlignTop) |
945 | + lBox.layout ().setAlignment (self.location, Qt.AlignTop) |
946 | + |
947 | + QLabel (self.stdDirs.installPath ("ui"), self) |
948 | + |
949 | + self.slotIndexChanged (combo.currentText ()) |
950 | + |
951 | + def slotIndexChanged (self, s): |
952 | + self.location.clear () |
953 | + self.location.insertItems (0, self.stdDirs.resourceDirs (str (s))) |
954 | + |
955 | + |
956 | + |
957 | + |
958 | +# This example can be run standalone |
959 | + |
960 | +if __name__ == '__main__': |
961 | + |
962 | + import sys |
963 | + |
964 | + from PyKDE4.kdecore import KCmdLineArgs, KAboutData, KLocalizedString, ki18n |
965 | + from PyKDE4.kdeui import KApplication, KMainWindow |
966 | + |
967 | + class MainWin (KMainWindow): |
968 | + def __init__ (self, *args): |
969 | + KMainWindow.__init__ (self) |
970 | + |
971 | + self.resize(640, 480) |
972 | + self.setCentralWidget (MainFrame (self)) |
973 | + |
974 | + #-------------------- main ------------------------------------------------ |
975 | + |
976 | + appName = "default" |
977 | + catalog = "" |
978 | + programName = ki18n ("default") #ki18n required here |
979 | + version = "1.0" |
980 | + description = ki18n ("Default Example") #ki18n required here |
981 | + license = KAboutData.License_GPL |
982 | + copyright = ki18n ("(c) 2007 Jim Bublitz") #ki18n required here |
983 | + text = ki18n ("none") #ki18n required here |
984 | + homePage = "www.riverbankcomputing.com" |
985 | + bugEmail = "jbublitz@nwinternet.com" |
986 | + |
987 | + aboutData = KAboutData (appName, catalog, programName, version, description, |
988 | + license, copyright, text, homePage, bugEmail) |
989 | + |
990 | + # ki18n required for first two addAuthor () arguments |
991 | + aboutData.addAuthor (ki18n ("Troy Melhase"), ki18n ("original concept")) |
992 | + aboutData.addAuthor (ki18n ("Jim Bublitz"), ki18n ("pykdedocs")) |
993 | + |
994 | + KCmdLineArgs.init (sys.argv, aboutData) |
995 | + |
996 | + app = KApplication () |
997 | + mainWindow = MainWin (None, "main window") |
998 | + mainWindow.show() |
999 | + app.connect (app, SIGNAL ("lastWindowClosed ()"), app.quit) |
1000 | + app.exec_ () |
1001 | |
1002 | === added file 'pykde4/solid_audiointerface.py' |
1003 | --- pykde4/solid_audiointerface.py 1970-01-01 00:00:00 +0000 |
1004 | +++ pykde4/solid_audiointerface.py 2010-03-24 06:55:25 +0000 |
1005 | @@ -0,0 +1,136 @@ |
1006 | +#!/usr/bin/env python |
1007 | + |
1008 | +# [SNIPPET_NAME: Solid (Audio Interface)] |
1009 | +# [SNIPPET_CATEGORIES: PyKDE4] |
1010 | +# [SNIPPET_DESCRIPTION: Device integration framework for an audio interface] |
1011 | +# [SNIPPET_AUTHOR: Jim Bublitz <jbublitz@nwinternet.com>] |
1012 | +# [SNIPPET_LICENSE: GPL] |
1013 | +# [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] |
1014 | + |
1015 | +from PyQt4.QtCore import Qt |
1016 | +from PyQt4.QtGui import QSizePolicy, QTreeWidget, QTreeWidgetItem, QLabel |
1017 | + |
1018 | +from PyKDE4.kdecore import i18n |
1019 | +from PyKDE4.solid import Solid, Solid |
1020 | +from PyKDE4.kdeui import KVBox, KHBox, KTextEdit |
1021 | + |
1022 | +helpText = """The Solid class discovers information about the hardware on a machine. |
1023 | + |
1024 | +Solid.AudioInterface objects retrieve information about the sound system |
1025 | +on a machine. |
1026 | + |
1027 | +We use Solid.Device.allDevices () to get a list of all devices, and then |
1028 | +filter it for Solid.AudioInterface types. |
1029 | +""" |
1030 | + |
1031 | +class MainFrame(KVBox): |
1032 | + def __init__(self, parent=None): |
1033 | + KVBox.__init__(self, parent) |
1034 | + self.help = QLabel (i18n (helpText), self) |
1035 | + self.layout ().setAlignment (self.help, Qt.AlignHCenter) |
1036 | + self.setSpacing (10) |
1037 | + |
1038 | + audioDriverStr = { |
1039 | + Solid.AudioInterface.Alsa: "Alsa",\ |
1040 | + Solid.AudioInterface.OpenSoundSystem: "Open Sound",\ |
1041 | + Solid.AudioInterface.UnknownAudioDriver: "Unknown" |
1042 | + } |
1043 | + |
1044 | + |
1045 | + audioInterfaceTypeStr = { |
1046 | + Solid.AudioInterface.UnknownAudioInterfaceType: "Unknown",\ |
1047 | + Solid.AudioInterface.AudioControl: "Control",\ |
1048 | + Solid.AudioInterface.AudioInput: "In",\ |
1049 | + Solid.AudioInterface.AudioOutput: "Out" |
1050 | + } |
1051 | + |
1052 | + soundcardTypeStr = { |
1053 | + Solid.AudioInterface.InternalSoundcard: "Internal",\ |
1054 | + Solid.AudioInterface.UsbSoundcard: "USB",\ |
1055 | + Solid.AudioInterface.FirewireSoundcard: "Firewire",\ |
1056 | + Solid.AudioInterface.Headset: "Headset",\ |
1057 | + Solid.AudioInterface.Modem: "Modem" |
1058 | + } |
1059 | + |
1060 | + hBox = KHBox (self) |
1061 | + |
1062 | + display = QTreeWidget (hBox) |
1063 | + display.setSizePolicy (QSizePolicy.Expanding, QSizePolicy.Expanding) |
1064 | + display.setHeaderLabels (["Item", "Name", "Driver", "I/F Type", "Sound Card Type"]) |
1065 | + display.setColumnWidth (0, 300) |
1066 | + display.setColumnWidth (1, 300) |
1067 | + display.setColumnWidth (3, 75) |
1068 | + |
1069 | + # retrieve a list of Solid.Device for this machine |
1070 | + deviceList = Solid.Device.allDevices () |
1071 | + |
1072 | + |
1073 | + # filter the list of all devices and display matching results |
1074 | + # note that we never create a Solid.AudioInterface object, but |
1075 | + # receive one from the 'asDeviceInterface' call |
1076 | + for device in deviceList: |
1077 | + if device.isDeviceInterface (Solid.DeviceInterface.AudioInterface): |
1078 | + audio = device.asDeviceInterface (Solid.DeviceInterface.AudioInterface) |
1079 | + devtype = audio.deviceType () |
1080 | + devstr = [] |
1081 | + for key in audioInterfaceTypeStr: |
1082 | + flag = key & devtype |
1083 | + if flag: |
1084 | + devstr.append (audioInterfaceTypeStr [key]) |
1085 | + |
1086 | + QTreeWidgetItem (display, [device.product (), |
1087 | + audio.name (), |
1088 | + audioDriverStr [audio.driver ()], |
1089 | + "/".join (devstr), |
1090 | + soundcardTypeStr [audio.soundcardType ()]]) |
1091 | + |
1092 | + |
1093 | + |
1094 | + |
1095 | +# This example can be run standalone |
1096 | + |
1097 | +if __name__ == '__main__': |
1098 | + |
1099 | + import sys |
1100 | + |
1101 | + from PyQt4.QtCore import SIGNAL |
1102 | + |
1103 | + from PyKDE4.kdecore import KCmdLineArgs, KAboutData, KLocalizedString, ki18n |
1104 | + from PyKDE4.kdeui import KApplication, KMainWindow |
1105 | + |
1106 | + |
1107 | + class MainWin (KMainWindow): |
1108 | + def __init__ (self, *args): |
1109 | + KMainWindow.__init__ (self) |
1110 | + |
1111 | + self.resize(640, 480) |
1112 | + self.setCentralWidget (MainFrame (self)) |
1113 | + |
1114 | + |
1115 | + #-------------------- main ------------------------------------------------ |
1116 | + |
1117 | + appName = "Solid_StorageDrive" |
1118 | + catalog = "" |
1119 | + programName = ki18n ("Solid_StorageDrive") #ki18n required here |
1120 | + version = "1.0" |
1121 | + description = ki18n ("Solid.StorageDrive Example") #ki18n required here |
1122 | + license = KAboutData.License_GPL |
1123 | + copyright = ki18n ("(c) 2007 Jim Bublitz") #ki18n required here |
1124 | + text = ki18n ("none") #ki18n required here |
1125 | + homePage = "www.riverbankcomputing.com" |
1126 | + bugEmail = "jbublitz@nwinternet.com" |
1127 | + |
1128 | + aboutData = KAboutData (appName, catalog, programName, version, description, |
1129 | + license, copyright, text, homePage, bugEmail) |
1130 | + |
1131 | + # ki18n required for first two addAuthor () arguments |
1132 | + aboutData.addAuthor (ki18n ("Troy Melhase"), ki18n ("original concept")) |
1133 | + aboutData.addAuthor (ki18n ("Jim Bublitz"), ki18n ("pykdedocs")) |
1134 | + |
1135 | + KCmdLineArgs.init (sys.argv, aboutData) |
1136 | + |
1137 | + app = KApplication () |
1138 | + mainWindow = MainWin (None, "main window") |
1139 | + mainWindow.show() |
1140 | + app.connect (app, SIGNAL ("lastWindowClosed ()"), app.quit) |
1141 | + app.exec_ () |
1142 | |
1143 | === added file 'pykde4/solid_demo.py' |
1144 | --- pykde4/solid_demo.py 1970-01-01 00:00:00 +0000 |
1145 | +++ pykde4/solid_demo.py 2010-03-24 06:55:25 +0000 |
1146 | @@ -0,0 +1,101 @@ |
1147 | +#!/usr/bin/env python |
1148 | + |
1149 | +# [SNIPPET_NAME: Solid Demo] |
1150 | +# [SNIPPET_CATEGORIES: PyKDE4] |
1151 | +# [SNIPPET_DESCRIPTION: Demos some of the features of Solid] |
1152 | +# [SNIPPET_AUTHOR: Simon Edwards <simon@simonzone.com>] |
1153 | +# [SNIPPET_LICENSE: GPL3] |
1154 | +# [SNIPPET_DOCS: http://api.kde.org/pykde-4.3-api/solid/index.html] |
1155 | + |
1156 | +########################################################################### |
1157 | +# solid_demo.py - Demonstrates use of Solid. |
1158 | +# |
1159 | +########################################################################### |
1160 | +# Copyright (C) 2007 Simon Edwards <simon@simonzone.com> |
1161 | +# |
1162 | +# This program is free software; you can redistribute it and/or modify |
1163 | +# it under the terms of the GNU General Public License as published by |
1164 | +# the Free Software Foundation; either version 2 of the License or (at |
1165 | +# your option) version 3 or, at the discretion of KDE e.V. (which shall |
1166 | +# act as a proxy as in section 14 of the GPLv3), any later version. |
1167 | +# |
1168 | +# This program is distributed in the hope that it will be useful, |
1169 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
1170 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1171 | +# GNU General Public License for more details. |
1172 | +# |
1173 | +# You should have received a copy of the GNU General Public License along |
1174 | +# with this program; if not, write to the Free Software Foundation, Inc., |
1175 | +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
1176 | + |
1177 | +from PyKDE4.kdecore import * |
1178 | +from PyKDE4.solid import * |
1179 | + |
1180 | +def main(): |
1181 | + componentData = KComponentData("solid_demo") |
1182 | + |
1183 | + print("All devices found by Solid") |
1184 | + print("--------------------------") |
1185 | + for device in Solid.Device.allDevices(): |
1186 | + print(device.udi()) |
1187 | + print("") |
1188 | + |
1189 | + print("All audio devices found by Solid") |
1190 | + print("--------------------------------") |
1191 | + for device in Solid.Device.listFromType(Solid.DeviceInterface.AudioInterface, ""): |
1192 | + print(device.udi()) |
1193 | + print("") |
1194 | + |
1195 | + print("Processor found by Solid") |
1196 | + print("------------------------") |
1197 | + |
1198 | + # Get a Processor |
1199 | + device_list = Solid.Device.listFromType(Solid.DeviceInterface.Processor, "") |
1200 | + |
1201 | + # take the first processor |
1202 | + device = device_list[0] |
1203 | + if device.isDeviceInterface(Solid.DeviceInterface.Processor): |
1204 | + print("We've got a processor! %i to be exact..." % len(device_list)) |
1205 | + else: |
1206 | + print("Device is not a processor.") |
1207 | + |
1208 | + processor = device.asDeviceInterface(Solid.DeviceInterface.Processor) |
1209 | + print("This processors maximum speed is: " + str(processor.maxSpeed())) |
1210 | + |
1211 | + extensions = processor.instructionSets() |
1212 | + print("Intel MMX supported: " + ("yes" if extensions & Solid.Processor.IntelMmx else "no")) |
1213 | + print("Intel SSE supported: " + ("yes" if extensions & Solid.Processor.IntelSse else "no")) |
1214 | + print("Intel SSE2 supported: " + ("yes" if extensions & Solid.Processor.IntelSse2 else "no")) |
1215 | + print("Intel SSE3 supported: " + ("yes" if extensions & Solid.Processor.IntelSse3 else "no")) |
1216 | + print("Intel SSE4 supported: " + ("yes" if extensions & Solid.Processor.IntelSse4 else "no")) |
1217 | + print("AMD 3DNOW supported: " + ("yes" if extensions & Solid.Processor.Amd3DNow else "no")) |
1218 | + print("PPC AltiVec supported: " + ("yes" if extensions & Solid.Processor.AltiVec else "no")) |
1219 | + print("") |
1220 | + |
1221 | + print("Checking network status") |
1222 | + print("-----------------------") |
1223 | + |
1224 | + if Solid.Networking.status() == Solid.Networking.Connected: |
1225 | + print("Networking is enabled. Feel free to go online!") |
1226 | + else: |
1227 | + print("Network not available.") |
1228 | + print("") |
1229 | + |
1230 | + # get a Network Device |
1231 | + netlist = Solid.Device.listFromType(Solid.DeviceInterface.NetworkInterface, "") |
1232 | + |
1233 | + # check to see if no network devices were found |
1234 | + if len(netlist)==0: |
1235 | + print("No network devices found!") |
1236 | + else: |
1237 | + print("Found %s network device(s)" % len(netlist)) |
1238 | + for device in netlist: |
1239 | + netdev = device.asDeviceInterface(Solid.DeviceInterface.NetworkInterface) |
1240 | + |
1241 | + # keep the program from crashing in the event that there's a bug in solid |
1242 | + if netdev is None: |
1243 | + print("Device could not be converted. There is a bug.") |
1244 | + else: |
1245 | + print("The iface of %s is %s" % (str(device.udi()),str(netdev.ifaceName()))) |
1246 | + |
1247 | +main() |
1248 | |
1249 | === added file 'pykde4/solid_device.py' |
1250 | --- pykde4/solid_device.py 1970-01-01 00:00:00 +0000 |
1251 | +++ pykde4/solid_device.py 2010-03-24 06:55:25 +0000 |
1252 | @@ -0,0 +1,91 @@ |
1253 | +#!/usr/bin/env python |
1254 | + |
1255 | +# [SNIPPET_NAME: Solid (Device)] |
1256 | +# [SNIPPET_CATEGORIES: PyKDE4] |
1257 | +# [SNIPPET_DESCRIPTION: Device integration framework for a device] |
1258 | +# [SNIPPET_AUTHOR: Jim Bublitz <jbublitz@nwinternet.com>] |
1259 | +# [SNIPPET_LICENSE: GPL] |
1260 | +# [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] |
1261 | + |
1262 | +from PyQt4.QtCore import SIGNAL, Qt |
1263 | +from PyQt4.QtGui import QTreeWidget, QTreeWidgetItem, QLabel |
1264 | + |
1265 | +from PyKDE4.kdecore import i18n |
1266 | +from PyKDE4.solid import Solid |
1267 | +from PyKDE4.kdeui import KVBox |
1268 | + |
1269 | +helpText = """The Solid class discovers information about the hardware on a machine. |
1270 | + |
1271 | +Solid.Device is the base class for the various types of devices. It provides a list |
1272 | +of the types of devices on the machine. The table below shows the data for your |
1273 | +machine. |
1274 | + |
1275 | +Individual device type classes can be interrogated to discover specific information |
1276 | +suitable to each device type. |
1277 | +""" |
1278 | + |
1279 | +class MainFrame(KVBox): |
1280 | + def __init__(self, parent=None): |
1281 | + KVBox.__init__(self, parent) |
1282 | + self.help = QLabel (i18n (helpText), self) |
1283 | + self.layout ().setAlignment (self.help, Qt.AlignHCenter) |
1284 | + self.setSpacing (10) |
1285 | + |
1286 | + display = QTreeWidget (self) |
1287 | + display.setHeaderLabels (["Product", "Vendor", "UDI"]) |
1288 | + display.setColumnWidth (0, 300) |
1289 | + |
1290 | + # retrieve a list of Solid.Device for this machine |
1291 | + deviceList = Solid.Device.allDevices () |
1292 | + |
1293 | + for device in deviceList: |
1294 | + item = QTreeWidgetItem (display, [device.product (), device.vendor (), device.udi ()]) |
1295 | + |
1296 | + |
1297 | + |
1298 | + |
1299 | +# This example can be run standalone |
1300 | + |
1301 | +if __name__ == '__main__': |
1302 | + |
1303 | + import sys |
1304 | + |
1305 | + from PyKDE4.kdecore import KCmdLineArgs, KAboutData, KLocalizedString, ki18n |
1306 | + from PyKDE4.kdeui import KApplication, KMainWindow |
1307 | + |
1308 | + |
1309 | + |
1310 | + class MainWin (KMainWindow): |
1311 | + def __init__ (self, *args): |
1312 | + KMainWindow.__init__ (self) |
1313 | + |
1314 | + self.resize(640, 480) |
1315 | + self.setCentralWidget (MainFrame (self)) |
1316 | + |
1317 | + #-------------------- main ------------------------------------------------ |
1318 | + |
1319 | + appName = "Solid_Devices" |
1320 | + catalog = "" |
1321 | + programName = ki18n ("Solid_Devices") #ki18n required here |
1322 | + version = "1.0" |
1323 | + description = ki18n ("Solid.Devices Example") #ki18n required here |
1324 | + license = KAboutData.License_GPL |
1325 | + copyright = ki18n ("(c) 2007 Jim Bublitz") #ki18n required here |
1326 | + text = ki18n ("none") #ki18n required here |
1327 | + homePage = "www.riverbankcomputing.com" |
1328 | + bugEmail = "jbublitz@nwinternet.com" |
1329 | + |
1330 | + aboutData = KAboutData (appName, catalog, programName, version, description, |
1331 | + license, copyright, text, homePage, bugEmail) |
1332 | + |
1333 | + # ki18n required for first two addAuthor () arguments |
1334 | + aboutData.addAuthor (ki18n ("Troy Melhase"), ki18n ("original concept")) |
1335 | + aboutData.addAuthor (ki18n ("Jim Bublitz"), ki18n ("pykdedocs")) |
1336 | + |
1337 | + KCmdLineArgs.init (sys.argv, aboutData) |
1338 | + |
1339 | + app = KApplication () |
1340 | + mainWindow = MainWin (None, "main window") |
1341 | + mainWindow.show() |
1342 | + app.connect (app, SIGNAL ("lastWindowClosed ()"), app.quit) |
1343 | + app.exec_ () |
1344 | |
1345 | === added file 'pykde4/solid_networkinterface.py' |
1346 | --- pykde4/solid_networkinterface.py 1970-01-01 00:00:00 +0000 |
1347 | +++ pykde4/solid_networkinterface.py 2010-03-24 06:55:25 +0000 |
1348 | @@ -0,0 +1,118 @@ |
1349 | +#!/usr/bin/env python |
1350 | + |
1351 | +# [SNIPPET_NAME: Solid (Network Interface)] |
1352 | +# [SNIPPET_CATEGORIES: PyKDE4] |
1353 | +# [SNIPPET_DESCRIPTION: Device integration framework for a network interface] |
1354 | +# [SNIPPET_AUTHOR: Jim Bublitz <jbublitz@nwinternet.com>] |
1355 | +# [SNIPPET_LICENSE: GPL] |
1356 | +# [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] |
1357 | + |
1358 | +from PyQt4.QtCore import Qt |
1359 | +from PyQt4.QtGui import QSizePolicy, QTreeWidget, QTreeWidgetItem, QLabel |
1360 | + |
1361 | +from PyKDE4.kdecore import i18n |
1362 | +from PyKDE4.solid import Solid, Solid |
1363 | +from PyKDE4.kdeui import KVBox, KHBox, KTextEdit |
1364 | + |
1365 | +helpText = """The Solid class discovers information about the hardware on a machine. |
1366 | + |
1367 | +Solid.NetworkInterface objects retrieve information about the network |
1368 | +on a machine. |
1369 | + |
1370 | +We use Solid.Device.allDevices () to get a list of all devices, and then |
1371 | +filter it for Solid.NetworkInterface types. |
1372 | +""" |
1373 | + |
1374 | +class MainFrame(KVBox): |
1375 | + def __init__(self, parent=None): |
1376 | + KVBox.__init__(self, parent) |
1377 | + self.help = QLabel (i18n (helpText), self) |
1378 | + self.layout ().setAlignment (self.help, Qt.AlignHCenter) |
1379 | + self.setSpacing (10) |
1380 | + |
1381 | + statusString = { |
1382 | + Solid.Networking.Unknown: "Unknown",\ |
1383 | + Solid.Networking.Unconnected: "Unconnected",\ |
1384 | + Solid.Networking.Disconnecting: "Disconnecting",\ |
1385 | + Solid.Networking.Connecting: "Connecting",\ |
1386 | + Solid.Networking.Connected: "Connected"\ |
1387 | + } |
1388 | + |
1389 | + status = Solid.Networking.status () |
1390 | + self.label = QLabel ("Status: %s" % statusString [status], self) |
1391 | + |
1392 | + hBox = KHBox (self) |
1393 | + |
1394 | + display = QTreeWidget (hBox) |
1395 | + display.setSizePolicy (QSizePolicy.Expanding, QSizePolicy.Expanding) |
1396 | + display.setHeaderLabels (["Interface", "Name", "Wireless", "HW Addr", "MAC Addr"]) |
1397 | + display.setColumnWidth (0, 200) |
1398 | + display.setColumnWidth (1, 75) |
1399 | + display.setColumnWidth (3, 150) |
1400 | + |
1401 | + # retrieve a list of Solid.Device for this machine |
1402 | + deviceList = Solid.Device.allDevices () |
1403 | + |
1404 | + |
1405 | + # filter the list of all devices and display matching results |
1406 | + # note that we never create a Solid.NetworkInterface object, but |
1407 | + # receive one from the 'asDeviceInterface' call |
1408 | + for device in deviceList: |
1409 | + if device.isDeviceInterface (Solid.DeviceInterface.NetworkInterface): |
1410 | + iface = device.asDeviceInterface (Solid.DeviceInterface.NetworkInterface) |
1411 | + QTreeWidgetItem (display, [device.product (), |
1412 | + iface.ifaceName (), |
1413 | + str (iface.isWireless ()), |
1414 | + iface.hwAddress (), |
1415 | + str (iface.macAddress ())]) |
1416 | + |
1417 | + |
1418 | + |
1419 | + |
1420 | +# This example can be run standalone |
1421 | + |
1422 | +if __name__ == '__main__': |
1423 | + |
1424 | + import sys |
1425 | + |
1426 | + from PyQt4.QtCore import SIGNAL |
1427 | + |
1428 | + from PyKDE4.kdecore import KCmdLineArgs, KAboutData, KLocalizedString, ki18n |
1429 | + from PyKDE4.kdeui import KApplication, KMainWindow |
1430 | + |
1431 | + |
1432 | + class MainWin (KMainWindow): |
1433 | + def __init__ (self, *args): |
1434 | + KMainWindow.__init__ (self) |
1435 | + |
1436 | + self.resize(640, 480) |
1437 | + self.setCentralWidget (MainFrame (self)) |
1438 | + |
1439 | + |
1440 | + #-------------------- main ------------------------------------------------ |
1441 | + |
1442 | + appName = "Solid_StorageDrive" |
1443 | + catalog = "" |
1444 | + programName = ki18n ("Solid_StorageDrive") #ki18n required here |
1445 | + version = "1.0" |
1446 | + description = ki18n ("Solid.StorageDrive Example") #ki18n required here |
1447 | + license = KAboutData.License_GPL |
1448 | + copyright = ki18n ("(c) 2007 Jim Bublitz") #ki18n required here |
1449 | + text = ki18n ("none") #ki18n required here |
1450 | + homePage = "www.riverbankcomputing.com" |
1451 | + bugEmail = "jbublitz@nwinternet.com" |
1452 | + |
1453 | + aboutData = KAboutData (appName, catalog, programName, version, description, |
1454 | + license, copyright, text, homePage, bugEmail) |
1455 | + |
1456 | + # ki18n required for first two addAuthor () arguments |
1457 | + aboutData.addAuthor (ki18n ("Troy Melhase"), ki18n ("original concept")) |
1458 | + aboutData.addAuthor (ki18n ("Jim Bublitz"), ki18n ("pykdedocs")) |
1459 | + |
1460 | + KCmdLineArgs.init (sys.argv, aboutData) |
1461 | + |
1462 | + app = KApplication () |
1463 | + mainWindow = MainWin (None, "main window") |
1464 | + mainWindow.show() |
1465 | + app.connect (app, SIGNAL ("lastWindowClosed ()"), app.quit) |
1466 | + app.exec_ () |
1467 | |
1468 | === added file 'pykde4/solid_processor.py' |
1469 | --- pykde4/solid_processor.py 1970-01-01 00:00:00 +0000 |
1470 | +++ pykde4/solid_processor.py 2010-03-24 06:55:25 +0000 |
1471 | @@ -0,0 +1,96 @@ |
1472 | +#!/usr/bin/env python |
1473 | + |
1474 | +# [SNIPPET_NAME: Solid (Processor)] |
1475 | +# [SNIPPET_CATEGORIES: PyKDE4] |
1476 | +# [SNIPPET_DESCRIPTION: Device integration framework for a processor] |
1477 | +# [SNIPPET_AUTHOR: Jim Bublitz <jbublitz@nwinternet.com>] |
1478 | +# [SNIPPET_LICENSE: GPL] |
1479 | +# [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] |
1480 | + |
1481 | +from PyQt4.QtCore import SIGNAL, Qt |
1482 | +from PyQt4.QtGui import QTreeWidget, QTreeWidgetItem, QLabel |
1483 | + |
1484 | +from PyKDE4.kdecore import i18n |
1485 | +from PyKDE4.solid import Solid |
1486 | +from PyKDE4.kdeui import KVBox |
1487 | + |
1488 | +helpText = """The Solid class discovers information about the hardware on a machine. |
1489 | + |
1490 | +Solid.Processor objects retrieve information about the processor on a machine. The |
1491 | +table below shows the data for your machine. Not all computers make processor info |
1492 | +accessible, so the table may be empty. |
1493 | + |
1494 | +We use Solid.Device.allDevices () to get a list of all devices, and then |
1495 | +filter it for Solid.Processor types. |
1496 | +""" |
1497 | + |
1498 | +class MainFrame(KVBox): |
1499 | + def __init__(self, parent=None): |
1500 | + KVBox.__init__(self, parent) |
1501 | + self.help = QLabel (i18n (helpText), self) |
1502 | + self.layout ().setAlignment (self.help, Qt.AlignHCenter) |
1503 | + self.setSpacing (10) |
1504 | + |
1505 | + display = QTreeWidget () |
1506 | + display.setHeaderLabels (["Processor", "Max Speed", "Number", "Change Freq"]) |
1507 | + |
1508 | + # retrieve a list of Solid.Device for this machine |
1509 | + deviceList = Solid.Device.allDevices () |
1510 | + |
1511 | + # filter the list of all devices and display matching results |
1512 | + for device in deviceList: |
1513 | + if device.isDeviceInterface (Solid.DeviceInterface.Processor): |
1514 | + cpu = device.asDeviceInterface (Solid.DeviceInterface.Processor) |
1515 | + QTreeWidgetItem (display, [device.product (), |
1516 | + str (cpu.maxSpeed ()), |
1517 | + str (cpu.number ()), |
1518 | + str (cpu.canChangeFrequency ())]) |
1519 | + |
1520 | + |
1521 | + |
1522 | + |
1523 | +# This example can be run standalone |
1524 | + |
1525 | +if __name__ == '__main__': |
1526 | + |
1527 | + import sys |
1528 | + |
1529 | + from PyKDE4.kdecore import KCmdLineArgs, KAboutData, KLocalizedString, ki18n |
1530 | + from PyKDE4.kdeui import KApplication, KMainWindow |
1531 | + |
1532 | + |
1533 | + class MainWin (KMainWindow): |
1534 | + def __init__ (self, *args): |
1535 | + KMainWindow.__init__ (self) |
1536 | + |
1537 | + self.resize(640, 480) |
1538 | + self.setCentralWidget (MainFrame (self)) |
1539 | + |
1540 | + |
1541 | + #-------------------- main ------------------------------------------------ |
1542 | + |
1543 | + appName = "Solid_StorageDrive" |
1544 | + catalog = "" |
1545 | + programName = ki18n ("Solid_StorageDrive") #ki18n required here |
1546 | + version = "1.0" |
1547 | + description = ki18n ("Solid.StorageDrive Example") #ki18n required here |
1548 | + license = KAboutData.License_GPL |
1549 | + copyright = ki18n ("(c) 2007 Jim Bublitz") #ki18n required here |
1550 | + text = ki18n ("none") #ki18n required here |
1551 | + homePage = "www.riverbankcomputing.com" |
1552 | + bugEmail = "jbublitz@nwinternet.com" |
1553 | + |
1554 | + aboutData = KAboutData (appName, catalog, programName, version, description, |
1555 | + license, copyright, text, homePage, bugEmail) |
1556 | + |
1557 | + # ki18n required for first two addAuthor () arguments |
1558 | + aboutData.addAuthor (ki18n ("Troy Melhase"), ki18n ("original concept")) |
1559 | + aboutData.addAuthor (ki18n ("Jim Bublitz"), ki18n ("pykdedocs")) |
1560 | + |
1561 | + KCmdLineArgs.init (sys.argv, aboutData) |
1562 | + |
1563 | + app = KApplication () |
1564 | + mainWindow = MainWin (None, "main window") |
1565 | + mainWindow.show() |
1566 | + app.connect (app, SIGNAL ("lastWindowClosed ()"), app.quit) |
1567 | + app.exec_ () |
1568 | |
1569 | === added file 'pykde4/solid_storageaccess.py' |
1570 | --- pykde4/solid_storageaccess.py 1970-01-01 00:00:00 +0000 |
1571 | +++ pykde4/solid_storageaccess.py 2010-03-24 06:55:25 +0000 |
1572 | @@ -0,0 +1,104 @@ |
1573 | +#!/usr/bin/env python |
1574 | + |
1575 | +# [SNIPPET_NAME: Solid (Storage Access)] |
1576 | +# [SNIPPET_CATEGORIES: PyKDE4] |
1577 | +# [SNIPPET_DESCRIPTION: Device integration framework for storage access] |
1578 | +# [SNIPPET_AUTHOR: Jim Bublitz <jbublitz@nwinternet.com>] |
1579 | +# [SNIPPET_LICENSE: GPL] |
1580 | +# [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] |
1581 | + |
1582 | +from PyQt4.QtCore import Qt |
1583 | +from PyQt4.QtGui import QSizePolicy, QTreeWidget, QTreeWidgetItem, QLabel |
1584 | + |
1585 | +from PyKDE4.kdecore import i18n |
1586 | +from PyKDE4.solid import Solid |
1587 | +from PyKDE4.kdeui import KVBox, KHBox |
1588 | + |
1589 | +helpText = """The Solid class discovers information about the hardware on a machine. |
1590 | + |
1591 | +Solid.StorageAccess objects retrieve information about the accessibility of |
1592 | +storage on a machine. It also allows interaction, like mounting and unmounting. The |
1593 | +table below shows the data for your machine. |
1594 | + |
1595 | +We use Solid.Device.allDevices () to get a list of all devices, and then |
1596 | +filter it for Solid.StorageAccess types. |
1597 | +""" |
1598 | + |
1599 | +class MainFrame(KVBox): |
1600 | + def __init__(self, parent=None): |
1601 | + KVBox.__init__(self, parent) |
1602 | + self.help = QLabel (i18n (helpText), self) |
1603 | + self.layout ().setAlignment (self.help, Qt.AlignHCenter) |
1604 | + self.setSpacing (10) |
1605 | + |
1606 | + hBox = KHBox (self) |
1607 | + |
1608 | + display = QTreeWidget (hBox) |
1609 | + display.setSizePolicy (QSizePolicy.Expanding, QSizePolicy.Expanding) |
1610 | + display.setHeaderLabels (["Volume", "File Path", "Accessible"]) |
1611 | + display.setColumnWidth (0, 200) |
1612 | + display.setColumnWidth (1, 300) |
1613 | + |
1614 | + # retrieve a list of Solid.Device for this machine |
1615 | + deviceList = Solid.Device.allDevices () |
1616 | + |
1617 | + # filter the list of all devices and display matching results |
1618 | + # note that we never create a Solid.StorageAccess object, but |
1619 | + # receive one from the 'asDeviceInterface' call |
1620 | + for device in deviceList: |
1621 | + if device.isDeviceInterface (Solid.DeviceInterface.StorageAccess): |
1622 | + access = device.asDeviceInterface (Solid.DeviceInterface.StorageAccess) |
1623 | + QTreeWidgetItem (display, [device.product (), |
1624 | + access.filePath (), |
1625 | + str (access.isAccessible ())]) |
1626 | + |
1627 | + |
1628 | + |
1629 | + |
1630 | +# This example can be run standalone |
1631 | + |
1632 | +if __name__ == '__main__': |
1633 | + |
1634 | + import sys |
1635 | + |
1636 | + from PyQt4.QtCore import SIGNAL |
1637 | + |
1638 | + from PyKDE4.kdecore import KCmdLineArgs, KAboutData, KLocalizedString, ki18n |
1639 | + from PyKDE4.kdeui import KApplication, KMainWindow |
1640 | + |
1641 | + |
1642 | + class MainWin (KMainWindow): |
1643 | + def __init__ (self, *args): |
1644 | + KMainWindow.__init__ (self) |
1645 | + |
1646 | + self.resize(640, 480) |
1647 | + self.setCentralWidget (MainFrame (self)) |
1648 | + |
1649 | + |
1650 | + #-------------------- main ------------------------------------------------ |
1651 | + |
1652 | + appName = "Solid_StorageDrive" |
1653 | + catalog = "" |
1654 | + programName = ki18n ("Solid_StorageDrive") #ki18n required here |
1655 | + version = "1.0" |
1656 | + description = ki18n ("Solid.StorageDrive Example") #ki18n required here |
1657 | + license = KAboutData.License_GPL |
1658 | + copyright = ki18n ("(c) 2007 Jim Bublitz") #ki18n required here |
1659 | + text = ki18n ("none") #ki18n required here |
1660 | + homePage = "www.riverbankcomputing.com" |
1661 | + bugEmail = "jbublitz@nwinternet.com" |
1662 | + |
1663 | + aboutData = KAboutData (appName, catalog, programName, version, description, |
1664 | + license, copyright, text, homePage, bugEmail) |
1665 | + |
1666 | + # ki18n required for first two addAuthor () arguments |
1667 | + aboutData.addAuthor (ki18n ("Troy Melhase"), ki18n ("original concept")) |
1668 | + aboutData.addAuthor (ki18n ("Jim Bublitz"), ki18n ("pykdedocs")) |
1669 | + |
1670 | + KCmdLineArgs.init (sys.argv, aboutData) |
1671 | + |
1672 | + app = KApplication () |
1673 | + mainWindow = MainWin (None, "main window") |
1674 | + mainWindow.show() |
1675 | + app.connect (app, SIGNAL ("lastWindowClosed ()"), app.quit) |
1676 | + app.exec_ () |
1677 | |
1678 | === added file 'pykde4/solid_storagedrive.py' |
1679 | --- pykde4/solid_storagedrive.py 1970-01-01 00:00:00 +0000 |
1680 | +++ pykde4/solid_storagedrive.py 2010-03-24 06:55:25 +0000 |
1681 | @@ -0,0 +1,126 @@ |
1682 | +#!/usr/bin/env python |
1683 | + |
1684 | +# [SNIPPET_NAME: Solid (Storage Drive)] |
1685 | +# [SNIPPET_CATEGORIES: PyKDE4] |
1686 | +# [SNIPPET_DESCRIPTION: Device integration framework for a storage drive] |
1687 | +# [SNIPPET_AUTHOR: Jim Bublitz <jbublitz@nwinternet.com>] |
1688 | +# [SNIPPET_LICENSE: GPL] |
1689 | +# [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] |
1690 | + |
1691 | +from PyQt4.QtCore import Qt |
1692 | +from PyQt4.QtGui import QSizePolicy, QTreeWidget, QTreeWidgetItem, QLabel |
1693 | + |
1694 | +from PyKDE4.kdecore import i18n |
1695 | +from PyKDE4.solid import Solid |
1696 | +from PyKDE4.kdeui import KVBox, KHBox, KColorButton |
1697 | + |
1698 | +helpText = """The Solid class discovers information about the hardware on a machine. |
1699 | + |
1700 | +Solid.StorageDrive objects retrieve information about storage devices on a |
1701 | +machine. the table below shows the data for your machine. |
1702 | + |
1703 | +We use Solid.Device.allDevices () to get a list of all devices, and then |
1704 | +filter it for Solid.StorageDrive types. |
1705 | +""" |
1706 | + |
1707 | +class MainFrame(KVBox): |
1708 | + def __init__(self, parent=None): |
1709 | + KVBox.__init__(self, parent) |
1710 | + self.help = QLabel (i18n (helpText), self) |
1711 | + self.layout ().setAlignment (self.help, Qt.AlignHCenter) |
1712 | + self.setSpacing (10) |
1713 | + |
1714 | + hBox = KHBox (self) |
1715 | + |
1716 | + display = QTreeWidget (hBox) |
1717 | + display.setSizePolicy (QSizePolicy.Expanding, QSizePolicy.Expanding) |
1718 | + display.setHeaderLabels (["Device", "Bus", "Type", "Hot Plug", "Removable"]) |
1719 | + display.setColumnWidth (0, 150) |
1720 | + |
1721 | + # convert enum values to strings for display |
1722 | + bus2Str = {Solid.StorageDrive.Ide : "IDE",\ |
1723 | + Solid.StorageDrive.Usb : "USB",\ |
1724 | + Solid.StorageDrive. Ieee1394 : "IEE1394",\ |
1725 | + Solid.StorageDrive.Scsi : "SCSI",\ |
1726 | + Solid.StorageDrive.Sata : "SATA",\ |
1727 | + Solid.StorageDrive.Platform : "Platform" |
1728 | + } |
1729 | + |
1730 | + |
1731 | + driveType2Str = {Solid.StorageDrive.HardDisk : "Hard Disk",\ |
1732 | + Solid.StorageDrive.CdromDrive : "CD ROM",\ |
1733 | + Solid.StorageDrive.Floppy : "Floppy",\ |
1734 | + Solid.StorageDrive.Tape : "Tape",\ |
1735 | + Solid.StorageDrive.CompactFlash : "Compact Flash",\ |
1736 | + Solid.StorageDrive.MemoryStick : "Memory Stick",\ |
1737 | + Solid.StorageDrive.SmartMedia : "Smart Media",\ |
1738 | + Solid.StorageDrive.SdMmc : "SD MMC",\ |
1739 | + Solid.StorageDrive.Xd : "XD" |
1740 | + } |
1741 | + |
1742 | + |
1743 | + # retrieve a list of Solid.Device for this machine |
1744 | + deviceList = Solid.Device.allDevices () |
1745 | + |
1746 | + # filter the list of all devices and display matching results |
1747 | + # note that we never create a Solid.StorageDrive object, but |
1748 | + # receive one from the call to 'asDeviceInterface' |
1749 | + for device in deviceList: |
1750 | + if device.isDeviceInterface (Solid.DeviceInterface.StorageDrive): |
1751 | + drive = device.asDeviceInterface (Solid.DeviceInterface.StorageDrive) |
1752 | + QTreeWidgetItem (display, [device.product (), |
1753 | + bus2Str [drive.bus ()], |
1754 | + driveType2Str [drive.driveType ()], |
1755 | + str (drive.isHotpluggable ()), |
1756 | + str (drive.isRemovable ())]) |
1757 | + |
1758 | + |
1759 | + |
1760 | + |
1761 | +# This example can be run standalone |
1762 | + |
1763 | +if __name__ == '__main__': |
1764 | + |
1765 | + import sys |
1766 | + |
1767 | + from PyQt4.QtCore import SIGNAL |
1768 | + |
1769 | + from PyKDE4.kdecore import KCmdLineArgs, KAboutData, KLocalizedString, ki18n |
1770 | + from PyKDE4.kdeui import KApplication, KMainWindow |
1771 | + |
1772 | + |
1773 | + |
1774 | + class MainWin (KMainWindow): |
1775 | + def __init__ (self, *args): |
1776 | + KMainWindow.__init__ (self) |
1777 | + |
1778 | + self.resize(640, 480) |
1779 | + self.setCentralWidget (MainFrame (self)) |
1780 | + |
1781 | + #-------------------- main ------------------------------------------------ |
1782 | + |
1783 | + appName = "Solid_StorageDrive" |
1784 | + catalog = "" |
1785 | + programName = ki18n ("Solid_StorageDrive") #ki18n required here |
1786 | + version = "1.0" |
1787 | + description = ki18n ("Solid.StorageDrive Example") #ki18n required here |
1788 | + license = KAboutData.License_GPL |
1789 | + copyright = ki18n ("(c) 2007 Jim Bublitz") #ki18n required here |
1790 | + text = ki18n ("none") #ki18n required here |
1791 | + homePage = "www.riverbankcomputing.com" |
1792 | + bugEmail = "jbublitz@nwinternet.com" |
1793 | + |
1794 | + aboutData = KAboutData (appName, catalog, programName, version, description, |
1795 | + license, copyright, text, homePage, bugEmail) |
1796 | + |
1797 | + # ki18n required for first two addAuthor () arguments |
1798 | + aboutData.addAuthor (ki18n ("Troy Melhase"), ki18n ("original concept")) |
1799 | + aboutData.addAuthor (ki18n ("Jim Bublitz"), ki18n ("pykdedocs")) |
1800 | + |
1801 | + KCmdLineArgs.init (sys.argv, aboutData) |
1802 | + |
1803 | + app = KApplication () |
1804 | + mainWindow = MainWin (None, "main window") |
1805 | + mainWindow.show() |
1806 | + app.connect (app, SIGNAL ("lastWindowClosed ()"), app.quit) |
1807 | + app.exec_ () |
1808 | |
1809 | === added file 'pykde4/solid_storagevolume.py' |
1810 | --- pykde4/solid_storagevolume.py 1970-01-01 00:00:00 +0000 |
1811 | +++ pykde4/solid_storagevolume.py 2010-03-24 06:55:25 +0000 |
1812 | @@ -0,0 +1,114 @@ |
1813 | +#!/usr/bin/env python |
1814 | + |
1815 | +# [SNIPPET_NAME: Solid (Storage Volume)] |
1816 | +# [SNIPPET_CATEGORIES: PyKDE4] |
1817 | +# [SNIPPET_DESCRIPTION: Device integration framework for a storage volume] |
1818 | +# [SNIPPET_AUTHOR: Jim Bublitz <jbublitz@nwinternet.com>] |
1819 | +# [SNIPPET_LICENSE: GPL] |
1820 | +# [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] |
1821 | + |
1822 | +from PyQt4.QtCore import Qt |
1823 | +from PyQt4.QtGui import QSizePolicy, QTreeWidget, QTreeWidgetItem, QLabel |
1824 | + |
1825 | +from PyKDE4.kdecore import i18n |
1826 | +from PyKDE4.solid import Solid |
1827 | +from PyKDE4.kdeui import KVBox, KHBox, KColorButton |
1828 | + |
1829 | +helpText = """The Solid class discovers information about the hardware on a machine. |
1830 | + |
1831 | +Solid.StorageVolume objects retrieve information about storage volumes on a |
1832 | +machine. The table below shows the data for your machine. |
1833 | + |
1834 | +We use Solid.Device.allDevices () to get a list of all devices, and then |
1835 | +filter it for Solid.StorageVolume types. |
1836 | +""" |
1837 | + |
1838 | +class MainFrame(KVBox): |
1839 | + def __init__(self, parent=None): |
1840 | + KVBox.__init__(self, parent) |
1841 | + self.help = QLabel (i18n (helpText), self) |
1842 | + self.layout ().setAlignment (self.help, Qt.AlignHCenter) |
1843 | + self.setSpacing (10) |
1844 | + |
1845 | + hBox = KHBox (self) |
1846 | + |
1847 | + display = QTreeWidget (hBox) |
1848 | + display.setSizePolicy (QSizePolicy.Expanding, QSizePolicy.Expanding) |
1849 | + display.setHeaderLabels (["Volume", "FS Type", "Label", "Ignored", "Size", "Usage"]) |
1850 | + display.setColumnWidth (0, 150) |
1851 | + |
1852 | + # convert enum values to strings for display |
1853 | + usageType2Str = { Solid.StorageVolume.Other : "Other",\ |
1854 | + Solid.StorageVolume.Unused : "Unused",\ |
1855 | + Solid.StorageVolume.FileSystem : "File System", |
1856 | + Solid.StorageVolume.PartitionTable : "Partition Tbl",\ |
1857 | + Solid.StorageVolume.Raid : "Raid",\ |
1858 | + Solid.StorageVolume.Encrypted : "Encrypted" |
1859 | + } |
1860 | + |
1861 | + # retrieve a list of Solid.Device for this machine |
1862 | + deviceList = Solid.Device.allDevices () |
1863 | + |
1864 | + # filter the list of all devices and display matching results |
1865 | + # note that we never create a Solid.StorageVolume object, |
1866 | + # but receive one from the 'asDeviceInterface" call |
1867 | + for device in deviceList: |
1868 | + if device.isDeviceInterface (Solid.DeviceInterface.StorageVolume): |
1869 | + volume = device.asDeviceInterface (Solid.DeviceInterface.StorageVolume) |
1870 | + QTreeWidgetItem (display, [device.product (), |
1871 | + volume.fsType (), |
1872 | + volume.label (), |
1873 | + str (volume.isIgnored ()), |
1874 | + "%i MB" % (volume.size ()/1024/1024), |
1875 | + usageType2Str [volume.usage ()]]) |
1876 | + |
1877 | + |
1878 | + |
1879 | + |
1880 | +# This example can be run standalone |
1881 | + |
1882 | +if __name__ == '__main__': |
1883 | + |
1884 | + import sys |
1885 | + |
1886 | + from PyQt4.QtCore import SIGNAL |
1887 | + |
1888 | + from PyKDE4.kdecore import KCmdLineArgs, KAboutData, KLocalizedString, ki18n |
1889 | + from PyKDE4.kdeui import KApplication, KMainWindow |
1890 | + |
1891 | + |
1892 | + |
1893 | + class MainWin (KMainWindow): |
1894 | + def __init__ (self, *args): |
1895 | + KMainWindow.__init__ (self) |
1896 | + |
1897 | + self.resize(640, 480) |
1898 | + self.setCentralWidget (MainFrame (self)) |
1899 | + |
1900 | + #-------------------- main ------------------------------------------------ |
1901 | + |
1902 | + appName = "Solid_StorageDrive" |
1903 | + catalog = "" |
1904 | + programName = ki18n ("Solid_StorageDrive") #ki18n required here |
1905 | + version = "1.0" |
1906 | + description = ki18n ("Solid.StorageDrive Example") #ki18n required here |
1907 | + license = KAboutData.License_GPL |
1908 | + copyright = ki18n ("(c) 2007 Jim Bublitz") #ki18n required here |
1909 | + text = ki18n ("none") #ki18n required here |
1910 | + homePage = "www.riverbankcomputing.com" |
1911 | + bugEmail = "jbublitz@nwinternet.com" |
1912 | + |
1913 | + aboutData = KAboutData (appName, catalog, programName, version, description, |
1914 | + license, copyright, text, homePage, bugEmail) |
1915 | + |
1916 | + # ki18n required for first two addAuthor () arguments |
1917 | + aboutData.addAuthor (ki18n ("Troy Melhase"), ki18n ("original concept")) |
1918 | + aboutData.addAuthor (ki18n ("Jim Bublitz"), ki18n ("pykdedocs")) |
1919 | + |
1920 | + KCmdLineArgs.init (sys.argv, aboutData) |
1921 | + |
1922 | + app = KApplication () |
1923 | + mainWindow = MainWin (None, "main window") |
1924 | + mainWindow.show() |
1925 | + app.connect (app, SIGNAL ("lastWindowClosed ()"), app.quit) |
1926 | + app.exec_ () |