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