Merge lp:~raoul-snyman/openlp/docstrings into lp:openlp

Proposed by Raoul Snyman
Status: Merged
Merged at revision: not available
Proposed branch: lp:~raoul-snyman/openlp/docstrings
Merge into: lp:openlp
Diff against target: None lines
To merge this branch: bzr merge lp:~raoul-snyman/openlp/docstrings
Reviewer Review Type Date Requested Status
Tim Bentley Approve
Review via email: mp+8546@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Raoul Snyman (raoul-snyman) wrote :

Some more docstrings cleanups.

Revision history for this message
Tim Bentley (trb143) wrote :

Looks fine to me.

review: Approve
lp:~raoul-snyman/openlp/docstrings updated
488. By Raoul Snyman

Merging from docstrings branch.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openlp/core/lib/plugin.py'
2--- openlp/core/lib/plugin.py 2009-07-06 16:34:13 +0000
3+++ openlp/core/lib/plugin.py 2009-07-10 13:16:15 +0000
4@@ -31,42 +31,58 @@
5 Base class for openlp plugins to inherit from.
6
7 Basic attributes are:
8- * name
9+
10+ ``name``
11 The name that should appear in the plugins list.
12- * version
13+
14+ ``version``
15 The version number of this iteration of the plugin.
16- * icon
17+
18+ ``icon``
19 An instance of QIcon, which holds an icon for this plugin.
20- * config
21+
22+ ``config``
23 An instance of PluginConfig, which allows plugins to read and write to
24 openlp.org's configuration. This is pre-instantiated.
25- * log
26+
27+ ``log``
28 A log object used to log debugging messages. This is pre-instantiated.
29
30 Hook functions:
31- * check_pre_conditions()
32+
33+ ``check_pre_conditions()``
34 Provides the Plugin with a handle to check if it can be loaded.
35- * get_media_manager_item()
36+
37+ ``get_media_manager_item()``
38 Returns an instance of MediaManagerItem to be used in the Media Manager.
39- * add_import_menu_item(import_menu)
40+
41+ ``add_import_menu_item(import_menu)``
42 Add an item to the Import menu.
43- * add_export_menu_item(export_menu)
44+
45+ ``add_export_menu_item(export_menu)``
46 Add an item to the Export menu.
47- * get_settings_tab()
48+
49+ ``get_settings_tab()``
50 Returns an instance of SettingsTabItem to be used in the Settings dialog.
51- * add_to_menu(menubar)
52+
53+ ``add_to_menu(menubar)``
54 A method to add a menu item to anywhere in the menu, given the menu bar.
55- * handle_event(event)
56+
57+ ``handle_event(event)``
58 A method use to handle events, given an Event object.
59- * about()
60+
61+ ``about()``
62 Used in the plugin manager, when a person clicks on the 'About' button.
63- * save(data)
64+
65+ ``save(data)``
66 A method to convert the plugin's data to a string to be stored in the
67 Service file.
68- * load(string)
69+
70+ ``load(string)``
71 A method to convert the string from a Service file into the plugin's
72 own data format.
73- * render(theme, screen_number)
74+
75+ ``render(theme, screen_number)``
76 A method used to render something to the screen, given the current theme
77 and screen number.
78 """
79@@ -78,11 +94,20 @@
80 """
81 This is the constructor for the plugin object. This provides an easy
82 way for descendent plugins to populate common data. This method *must*
83- be overridden, like so:
84- class MyPlugin(Plugin):
85- def __init__(self):
86- Plugin.__init(self, 'MyPlugin', '0.1')
87- ...
88+ be overridden, like so::
89+
90+ class MyPlugin(Plugin):
91+ def __init__(self):
92+ Plugin.__init(self, u'MyPlugin', u'0.1')
93+
94+ ``name``
95+ Defaults to *None*. The name of the plugin.
96+
97+ ``version``
98+ Defaults to *None*. The version of the plugin.
99+
100+ ``plugin_helpers``
101+ Defaults to *None*. A list of helper objects.
102 """
103 if name is not None:
104 self.name = name
105@@ -107,50 +132,59 @@
106 def check_pre_conditions(self):
107 """
108 Provides the Plugin with a handle to check if it can be loaded.
109+
110 Returns True or False.
111 """
112 return True
113
114 def get_media_manager_item(self):
115 """
116- Construct a MediaManagerItem object with all the buttons and things you
117- need, and return it for integration into openlp.org.
118+ Construct a MediaManagerItem object with all the buttons and things
119+ you need, and return it for integration into openlp.org.
120 """
121 pass
122
123 def add_import_menu_item(self, import_menu):
124 """
125 Create a menu item and add it to the "Import" menu.
126+
127+ ``import_menu``
128+ The Import menu.
129 """
130 pass
131
132 def add_export_menu_item(self, export_menu):
133 """
134 Create a menu item and add it to the "Export" menu.
135+
136+ ``export_menu``
137+ The Export menu
138 """
139 pass
140
141 def get_settings_tab(self):
142 """
143- Create a menu item and add it to the "Import" menu.
144+ Create a tab for the settings window.
145 """
146 pass
147
148 def add_to_menu(self, menubar):
149 """
150 Add menu items to the menu, given the menubar.
151+
152+ ``menubar``
153+ The application's menu bar.
154 """
155 pass
156
157 def handle_event(self, event):
158 """
159- Handle the event contained in the event object.
160- """
161- def handle_event(self, event):
162- """
163 Handle the event contained in the event object. If you want
164 to use this default behaviour, you must set self.dnd_id equal
165 to that sent by the dnd source - eg the MediaItem
166+
167+ ``event``
168+ An object describing the event.
169 """
170 # default behaviour - can be overridden if desired
171 log.debug(u'Handle event called with event %s with payload %s'%(event.event_type, event.payload))
172@@ -175,6 +209,9 @@
173 """
174 Service item data is passed to this function, which should return a
175 string which can be written to the service file.
176+
177+ ``data``
178+ The data to be saved.
179 """
180 pass
181
182@@ -182,12 +219,21 @@
183 """
184 A string from the service file is passed in. This function parses and
185 sets up the internals of the plugin.
186+
187+ ``string``
188+ The data to be loaded into the plugin.
189 """
190 pass
191
192 def render(self, theme, screen=None):
193 """
194 Render the screenth screenful of data using theme settings in theme.
195+
196+ ``theme``
197+ The theme to use when rendering.
198+
199+ ``screen``
200+ Defaults to *None*. The screen to render to.
201 """
202 pass
203
204
205=== modified file 'openlp/core/lib/pluginconfig.py'
206--- openlp/core/lib/pluginconfig.py 2009-07-08 05:12:16 +0000
207+++ openlp/core/lib/pluginconfig.py 2009-07-10 13:16:15 +0000
208@@ -29,28 +29,50 @@
209 """
210 Initialise the plugin config object, setting the section name to the
211 plugin name.
212+
213+ ``plugin_name``
214+ The name of the plugin to use as a section name.
215 """
216 self.section = plugin_name.lower()
217
218 def get_config(self, key, default=None):
219 """
220 Get a configuration value from the configuration registry.
221+
222+ ``key``
223+ The name of configuration to load.
224+
225+ ``default``
226+ Defaults to *None*. The default value to return if there is no
227+ other value.
228 """
229 return ConfigHelper.get_config(self.section, key, default)
230
231 def delete_config(self, key):
232 """
233 Delete a configuration value from the configuration registry.
234+
235+ ``key``
236+ The name of the configuration to remove.
237 """
238 return ConfigHelper.delete_config(self.section, key)
239
240 def set_config(self, key, value):
241 """
242 Set a configuration value in the configuration registry.
243+
244+ ``key``
245+ The name of the configuration to save.
246+
247+ ``value``
248+ The value of the configuration to save.
249 """
250 return ConfigHelper.set_config(self.section, key, value)
251
252 def get_data_path(self):
253+ """
254+ Dynamically build the data file path for a plugin.
255+ """
256 #app_data = ConfigHelper.get_data_path()
257 app_data = ConfigHelper.get_data_path()
258 safe_name = self.section.replace(u' ',u'-')
259@@ -61,9 +83,21 @@
260 return path
261
262 def set_data_path(self, path):
263+ """
264+ Set the data file path.
265+
266+ ``path``
267+ The path to save.
268+ """
269 return self.set_config(u'data path', os.path.basename(path))
270
271 def get_files(self, suffix=None):
272+ """
273+ Get a list of files from the data files path.
274+
275+ ``suffix``
276+ Defaults to *None*. The extension to search for.
277+ """
278 try:
279 files = os.listdir(self.get_data_path())
280 except:
281@@ -86,7 +120,10 @@
282
283 def load_list(self, name):
284 """
285- Load a list from the config file
286+ Load a list from the config file.
287+
288+ ``name``
289+ The name of the list.
290 """
291 list_count = self.get_config(u'%s count' % name)
292 if list_count is not None:
293@@ -102,7 +139,13 @@
294
295 def set_list(self, name, list):
296 """
297- Save a list to the config file
298+ Save a list to the config file.
299+
300+ ``name``
301+ The name of the list to save.
302+
303+ ``list``
304+ The list of values to save.
305 """
306 old_count = int(self.get_config(u'%s count' % name, int(0)))
307 new_count = len(list)
308@@ -116,7 +159,10 @@
309
310 def get_last_dir(self, num=None):
311 """
312- Read the last directory used for plugin
313+ Read the last directory used for plugin.
314+
315+ ``num``
316+ Defaults to *None*. A further qualifier.
317 """
318 if num is not None:
319 name = u'last directory %d' % num
320@@ -129,7 +175,10 @@
321
322 def set_last_dir(self, directory, num=None):
323 """
324- Save the last directory used for plugin
325+ Save the last directory used for plugin.
326+
327+ ``num``
328+ Defaults to *None*. A further qualifier.
329 """
330 if num is not None:
331 name = u'last directory %d' % num
332
333=== modified file 'openlp/core/lib/pluginmanager.py'
334--- openlp/core/lib/pluginmanager.py 2009-07-08 05:12:16 +0000
335+++ openlp/core/lib/pluginmanager.py 2009-07-10 13:16:15 +0000
336@@ -34,8 +34,11 @@
337
338 def __init__(self, dir):
339 """
340- The constructor for the plugin manager.
341- Passes the controllers on to the plugins for them to interact with via their ServiceItems
342+ The constructor for the plugin manager. Passes the controllers on to
343+ the plugins for them to interact with via their ServiceItems.
344+
345+ ``dir``
346+ The directory to search for plugins.
347 """
348 log.info(u'Plugin manager initing')
349 if not dir in sys.path:
350@@ -49,7 +52,16 @@
351
352 def find_plugins(self, dir, plugin_helpers, eventmanager):
353 """
354- Scan the directory dir for objects inheriting from openlp.plugin
355+ Scan the directory dir for objects inheriting from ``openlp.plugin``.
356+
357+ ``dir``
358+ The directory to scan.
359+
360+ ``plugin_helpers``
361+ A list of helper objects to pass to the plugins.
362+
363+ ``eventmanager``
364+ The event manager to pass to the plugins.
365 """
366 self.plugin_helpers = plugin_helpers
367 startdepth = len(os.path.abspath(dir).split(os.sep))
368@@ -104,8 +116,8 @@
369
370 def hook_media_manager(self, mediatoolbox):
371 """
372- Loop through all the plugins. If a plugin has a valid media manager item,
373- add it to the media manager.
374+ Loop through all the plugins. If a plugin has a valid media manager
375+ item, add it to the media manager.
376
377 ``mediatoolbox``
378 The Media Manager itself.
379@@ -118,8 +130,11 @@
380
381 def hook_settings_tabs(self, settingsform=None):
382 """
383- Loop through all the plugins. If a plugin has a valid settings tab item,
384- add it to the settings tab.
385+ Loop through all the plugins. If a plugin has a valid settings tab
386+ item, add it to the settings tab.
387+
388+ ``settingsform``
389+ Defaults to *None*. The settings form to add tabs to.
390 """
391 for plugin in self.plugins:
392 settings_tab = plugin.get_settings_tab()
393@@ -131,24 +146,30 @@
394
395 def hook_import_menu(self, import_menu):
396 """
397- Loop through all the plugins and give them an opportunity to add an item
398- to the import menu.
399+ Loop through all the plugins and give them an opportunity to add an
400+ item to the import menu.
401+
402+ ``import_menu``
403+ The Import menu.
404 """
405 for plugin in self.plugins:
406 plugin.add_import_menu_item(import_menu)
407
408 def hook_export_menu(self, export_menu):
409 """
410- Loop through all the plugins and give them an opportunity to add an item
411- to the export menu.
412+ Loop through all the plugins and give them an opportunity to add an
413+ item to the export menu.
414+
415+ ``export_menu``
416+ The Export menu.
417 """
418 for plugin in self.plugins:
419 plugin.add_export_menu_item(export_menu)
420
421 def initialise_plugins(self):
422 """
423- Loop through all the plugins and give them an opportunity to add an item
424- to the export menu.
425+ Loop through all the plugins and give them an opportunity to
426+ initialise themselves.
427 """
428 for plugin in self.plugins:
429 plugin.initialise()
430
431=== modified file 'openlp/core/lib/renderer.py'
432--- openlp/core/lib/renderer.py 2009-06-26 16:17:55 +0000
433+++ openlp/core/lib/renderer.py 2009-07-10 13:16:15 +0000
434@@ -18,12 +18,12 @@
435 Place, Suite 330, Boston, MA 02111-1307 USA
436 """
437 import logging
438-import os, os.path
439+import os
440 import sys
441
442 from PyQt4 import QtGui, QtCore
443
444-class Renderer:
445+class Renderer(object):
446 """
447 Genarates a pixmap image of a array of text. The Text is formatted to
448 make sure it fits on the screen and if not extra frames a generated.
449@@ -33,6 +33,9 @@
450 log.info(u'Renderer Loaded')
451
452 def __init__(self):
453+ """
454+ Initialise the renderer.
455+ """
456 self._rect = None
457 self._debug = 0
458 self._right_margin = 64 # the amount of right indent
459@@ -47,11 +50,20 @@
460 self._bg_frame_small = None
461
462 def set_debug(self, debug):
463+ """
464+ Set the debug mode of the renderer.
465+
466+ ``debug``
467+ The debug mode.
468+ """
469 self._debug=debug
470
471 def set_theme(self, theme):
472 """
473- External API to pass in the theme to be used
474+ Set the theme to be used.
475+
476+ ``theme``
477+ The theme to be used.
478 """
479 log.debug(u'set theme')
480 self._theme = theme
481@@ -64,12 +76,21 @@
482 self.set_bg_image(theme.background_filename)
483
484 def set_bg_image(self, filename):
485+ """
486+ Set a background image.
487+
488+ ``filename``
489+ The name of the image file.
490+ """
491 log.debug(u'set bg image %s', filename)
492 self._bg_image_filename = unicode(filename)
493 if self._frame is not None:
494 self.scale_bg_image()
495
496 def scale_bg_image(self):
497+ """
498+ Scale the background image to fit the screen.
499+ """
500 assert self._frame
501 preview = QtGui.QImage(self._bg_image_filename)
502 width = self._frame.width()
503@@ -89,7 +110,16 @@
504
505 def set_frame_dest(self, frame_width, frame_height, preview=False):
506 """
507- External API to pass the frame size to be painted
508+ Set the size of the slide.
509+
510+ ``frame_width``
511+ The width of the slide.
512+
513+ ``frame_height``
514+ The height of the slide.
515+
516+ ``preview``
517+ Defaults to *False*. Whether or not to generate a preview.
518 """
519 if preview == True:
520 self._bg_frame = None
521@@ -103,7 +133,14 @@
522
523 def format_slide(self, words, footer):
524 """
525- External API to sort out the text to pe placed on the frame
526+ Figure out how much text can appear on a slide, using the current
527+ theme settings.
528+
529+ ``words``
530+ The words to be fitted on the slide.
531+
532+ ``footer``
533+ The footer of the slide.
534 """
535 log.debug(u'format_slide - Start')
536 verses = []
537@@ -120,15 +157,28 @@
538
539 def set_text_rectangle(self, rect_main, rect_footer):
540 """
541- Sets the rectangle within which text should be rendered
542+ Sets the rectangle within which text should be rendered.
543+
544+ ``rect_main``
545+ The main text block.
546+
547+ ``rect_footer``
548+ The footer text block.
549 """
550 self._rect = rect_main
551 self._rect_footer = rect_footer
552
553 def generate_frame_from_lines(self, lines, footer_lines=None):
554 """
555- Render a set of lines according to the theme, return bounding box
556- """
557+ Render a set of lines according to the theme, and return the block
558+ dimensions.
559+
560+ ``lines``
561+ The lines to be rendered.
562+
563+ ``footer_lines``
564+ Defaults to *None*. The footer to render.
565+ """
566 log.debug(u'generate_frame_from_lines - Start')
567 #print "Render Lines ", lines
568 bbox = self._render_lines_unaligned(lines, False)
569@@ -139,14 +189,15 @@
570 x, y = self._correctAlignment(self._rect, bbox)
571 bbox = self._render_lines_unaligned(lines, False, (x, y), True)
572 if footer_lines is not None:
573- bbox = self._render_lines_unaligned(footer_lines, True, (self._rect_footer.left(), self._rect_footer.top()), True )
574+ bbox = self._render_lines_unaligned(footer_lines, True,
575+ (self._rect_footer.left(), self._rect_footer.top()), True)
576 log.debug(u'generate_frame_from_lines - Finish')
577 return self._frame
578
579 def _generate_background_frame(self):
580 """
581- Generate a background frame to the same size as the frame to be used
582- Results cached for performance reasons.
583+ Generate a background frame to the same size as the frame to be used.
584+ Results are cached for performance reasons.
585 """
586 assert(self._theme)
587 self._bg_frame = QtGui.QImage(self._frame.width(), self._frame.height(),
588@@ -196,11 +247,19 @@
589
590 def _split_set_of_lines(self, lines, footer):
591 """
592- Given a list of lines, decide how to split them best if they don't all fit on the screen
593- - this is done by splitting at 1/2, 1/3 or 1/4 of the set
594- If it doesn't fit, even at this size, just split at each opportunity.
595- We'll do this by getting the bounding box of each line, and then summing them appropriately
596- Returns a list of [lists of lines], one set for each screenful
597+ Given a list of lines, decide how to split them best if they don't all
598+ fit on the screen. This is done by splitting at 1/2, 1/3 or 1/4 of the
599+ set. If it doesn't fit, even at this size, just split at each
600+ opportunity. We'll do this by getting the bounding box of each line,
601+ and then summing them appropriately.
602+
603+ Returns a list of [lists of lines], one set for each screenful.
604+
605+ ``lines``
606+ The lines of text to split.
607+
608+ ``footer``
609+ The footer text.
610 """
611 bboxes = []
612 for line in lines:
613@@ -254,6 +313,15 @@
614 return retval
615
616 def _correctAlignment(self, rect, bbox):
617+ """
618+ Corrects the vertical alignment of text.
619+
620+ ``rect``
621+ The block dimentions.
622+
623+ ``bbox``
624+ Footer dimensions?
625+ """
626 x = rect.left()
627 if int(self._theme.display_verticalAlign) == 0:
628 # top align
629@@ -268,13 +336,26 @@
630 log.error(u'Invalid value for theme.VerticalAlign:%s' % self._theme.display_verticalAlign)
631 return x, y
632
633- def _render_lines_unaligned(self, lines, footer, tlcorner=(0,0), live=False):
634+ def _render_lines_unaligned(self, lines, footer, tlcorner=(0, 0), live=False):
635 """
636- Given a list of lines to render, render each one in turn
637- (using the _render_single_line fn - which may result in going
638- off the bottom) They are expected to be pre-arranged to less
639- than a screenful (eg. by using split_set_of_lines)
640- Returns the bounding box of the text as QRect
641+ Given a list of lines to render, render each one in turn (using the
642+ ``_render_single_line`` fn - which may result in going off the bottom).
643+ They are expected to be pre-arranged to less than a screenful (eg. by
644+ using split_set_of_lines).
645+
646+ Returns the bounding box of the text as QRect.
647+
648+ ``lines``
649+ The lines of text to render.
650+
651+ ``footer``
652+ The slide footer.
653+
654+ ``tlcorner``
655+ Defaults to *``(0, 0)``*. Co-ordinates of the top left corner.
656+
657+ ``live``
658+ Defaults to *False*. Whether or not this is a live screen.
659 """
660 x, y = tlcorner
661 brx = x
662@@ -282,25 +363,37 @@
663 for line in lines:
664 # render after current bottom, but at original left edge
665 # keep track of right edge to see which is biggest
666- (thisx, bry) = self._render_and_wrap_single_line(line, footer, (x , bry), live)
667+ (thisx, bry) = self._render_and_wrap_single_line(line, footer, (x, bry), live)
668 if (thisx > brx):
669 brx = thisx
670- retval = QtCore.QRect(x, y,brx-x, bry-y)
671+ retval = QtCore.QRect(x, y, brx - x, bry - y)
672 if self._debug:
673 painter = QtGui.QPainter()
674 painter.begin(self._frame)
675- painter.setPen(QtGui.QPen(QtGui.QColor(0,0,255)))
676+ painter.setPen(QtGui.QPen(QtGui.QColor(0, 0, 255)))
677 painter.drawRect(retval)
678 painter.end()
679- return retval
680+ return retval
681
682- def _render_and_wrap_single_line(self, line, footer, tlcorner=(0,0), live=False):
683+ def _render_and_wrap_single_line(self, line, footer, tlcorner=(0, 0), live=False):
684 """
685- Render a single line of words onto the DC, top left corner
686- specified.
687- If the line is too wide for the context, it wraps, but
688- right-aligns the surplus words in the manner of song lyrics
689+ Render a single line of words onto the DC, top left corner specified.
690+ If the line is too wide for the context, it wraps, but right-aligns
691+ the surplus words in the manner of song lyrics.
692+
693 Returns the bottom-right corner (of what was rendered) as a tuple(x, y).
694+
695+ ``line``
696+ Line of text to be rendered.
697+
698+ ``footer``
699+ The footer of the slide.
700+
701+ ``tlcorner``
702+ Defaults to *``(0, 0)``*. The top left corner.
703+
704+ ``live``
705+ Defaults to *False*. Whether or not this is a live screen.
706 """
707 x, y = tlcorner
708 # We draw the text to see how big it is and then iterate to make it fit
709@@ -397,6 +490,9 @@
710 return brcorner
711
712 def _set_theme_font(self):
713+ """
714+ Set the fonts from the current theme settings.
715+ """
716 self.footerFont = QtGui.QFont(self._theme.font_footer_name,
717 int(self._theme.font_footer_proportion), # size
718 QtGui.QFont.Normal, # weight
719@@ -408,11 +504,26 @@
720 0)# italic
721 self.mainFont.setPixelSize(int(self._theme.font_main_proportion))
722
723- def _get_extent_and_render(self, line, footer, tlcorner=(0,0), draw=False, color=None):
724+ def _get_extent_and_render(self, line, footer, tlcorner=(0, 0), draw=False, color=None):
725 """
726- Find bounding box of text - as render_single_line.
727- If draw is set, actually draw the text to the current DC as well
728- return width and height of text as a tuple (w,h)
729+ Find bounding box of text - as render_single_line. If draw is set,
730+ actually draw the text to the current DC as well return width and
731+ height of text as a tuple (w, h).
732+
733+ ``line``
734+ The line of text to render.
735+
736+ ``footer``
737+ The footer text.
738+
739+ ``tlcorner``
740+ Defaults to *``(0, 0)``*. The top left corner co-ordinates.
741+
742+ ``draw``
743+ Defaults to *False*. Draw the text to the current surface.
744+
745+ ``color``
746+ Defaults to *None*. The colour to draw with.
747 """
748 # setup defaults
749 painter = QtGui.QPainter()
750@@ -424,7 +535,7 @@
751 else:
752 font = self.mainFont
753 painter.setFont(font)
754- if color == None:
755+ if color is None:
756 if footer:
757 painter.setPen(QtGui.QColor(self._theme.font_footer_color))
758 else:
759@@ -443,7 +554,13 @@
760
761 def snoop_Image(self, image, image2=None):
762 """
763- Debugging method to allow images to be viewed
764+ Debugging method to allow images to be viewed.
765+
766+ ``image``
767+ An image to save to disk.
768+
769+ ``image2``
770+ Defaults to *None*. Another image to save to disk.
771 """
772 im = image.toImage()
773 im.save(u'renderer.png', u'png')
774
775=== modified file 'openlp/core/lib/rendermanager.py'
776--- openlp/core/lib/rendermanager.py 2009-07-02 19:04:50 +0000
777+++ openlp/core/lib/rendermanager.py 2009-07-10 13:16:15 +0000
778@@ -18,26 +18,37 @@
779 Place, Suite 330, Boston, MA 02111-1307 USA
780 """
781 import logging
782-import os, os.path
783+import os
784 import sys
785+import linecache
786
787 from PyQt4 import QtGui, QtCore
788+
789 from renderer import Renderer
790
791-import sys
792-import linecache
793-
794-class RenderManager:
795+class RenderManager(object):
796 """
797- Class to pull all Renderer interactions into one place.
798- The plugins will call helper methods to do the rendering but
799- this class will provide display defense code.
800+ Class to pull all Renderer interactions into one place. The plugins will
801+ call helper methods to do the rendering but this class will provide
802+ display defense code.
803 """
804 global log
805 log=logging.getLogger(u'RenderManager')
806 log.info(u'RenderManager Loaded')
807
808 def __init__(self, theme_manager, screen_list, screen_number=0):
809+ """
810+ Initialise the render manager.
811+
812+ ``theme_manager``
813+ The ThemeManager instance, used to get the current theme details.
814+
815+ ``screen_list``
816+ The list of screens available.
817+
818+ ``screen_number``
819+ Defaults to *0*. The index of the output/display screen.
820+ """
821 log.debug(u'Initilisation started')
822 self.screen_list = screen_list
823 self.theme_manager = theme_manager
824@@ -52,21 +63,46 @@
825 def update_display(self, screen_number):
826 """
827 Updates the render manager's information about the current screen.
828+
829+ ``screen_number``
830+ The updated index of the output/display screen.
831 """
832 log.debug(u'Update Display')
833 if self.current_display != screen_number:
834 self.current_display = screen_number
835 self.calculate_default(self.screen_list[self.current_display][u'size'])
836
837- def set_global_theme(self, global_theme, global_style = u'Global'):
838+ def set_global_theme(self, global_theme, global_style=u'Global'):
839+ """
840+ Set the global-level theme and the theme level.
841+
842+ ``global_theme``
843+ The global-level theme to be set.
844+
845+ ``global_style``
846+ Defaults to *"Global"*. The theme level, can be "Global",
847+ "Service" or "Song".
848+ """
849 self.global_theme = global_theme
850 self.global_style = global_style
851
852 def set_service_theme(self, service_theme):
853+ """
854+ Set the service-level theme.
855+
856+ ``service_theme``
857+ The service-level theme to be set.
858+ """
859 self.service_theme = service_theme
860
861 def set_override_theme(self, theme):
862- log.debug(u'set override theme to %s', theme)
863+ """
864+ Set the appropriate theme depending on the theme level.
865+
866+ ``theme``
867+ The name of the song-level theme.
868+ """
869+ log.debug(u'set override theme to %s', theme)
870 if self.global_style == u'Global':
871 self.theme = self.global_theme
872 elif self.global_style == u'Service':
873@@ -84,7 +120,7 @@
874 self.theme = self.service_theme
875 else:
876 self.theme = self.global_theme
877- if self.theme is not self.renderer.theme_name:
878+ if self.theme != self.renderer.theme_name:
879 log.debug(u'theme is now %s', self.theme)
880 self.themedata = self.theme_manager.getThemeData(self.theme)
881 self.calculate_default(self.screen_list[self.current_display][u'size'])
882@@ -92,7 +128,13 @@
883 self.build_text_rectangle(self.themedata)
884
885 def build_text_rectangle(self, theme):
886- log.debug(u'build_text_rectangle ')
887+ """
888+ Builds a text block using the settings in ``theme``.
889+
890+ ``theme``
891+ The theme to build a text block for.
892+ """
893+ log.debug(u'build_text_rectangle')
894 main_rect = None
895 footer_rect = None
896 if theme.font_main_override == False:
897@@ -108,31 +150,52 @@
898 self.renderer.set_text_rectangle(main_rect,footer_rect)
899
900 def generate_preview(self, themedata):
901+ """
902+ Generate a preview of a theme.
903+
904+ ``themedata``
905+ The theme to generated a preview for.
906+ """
907 log.debug(u'generate preview')
908 self.calculate_default(QtCore.QSize(1024, 768))
909 self.renderer.set_theme(themedata)
910 self.build_text_rectangle(themedata)
911 self.renderer.set_frame_dest(self.width, self.height, True)
912- lines = []
913- lines.append(u'Amazing Grace!')
914- lines.append(u'How sweet the sound')
915- lines.append(u'To save a wretch like me;')
916- lines.append(u'I once was lost but now am found,')
917- lines.append(u'Was blind, but now I see.')
918- lines1 = []
919- lines1.append(u'Amazing Grace (John Newton)' )
920- lines1.append(u'Public Domain')
921- lines1.append(u'CCLI xxx')
922- return self.renderer.generate_frame_from_lines(lines, lines1)
923+ verse = []
924+ verse.append(u'Amazing Grace!')
925+ verse.append(u'How sweet the sound')
926+ verse.append(u'To save a wretch like me;')
927+ verse.append(u'I once was lost but now am found,')
928+ verse.append(u'Was blind, but now I see.')
929+ footer = []
930+ footer.append(u'Amazing Grace (John Newton)' )
931+ footer.append(u'Public Domain')
932+ footer.append(u'CCLI xxx')
933+ return self.renderer.generate_frame_from_lines(verse, footer)
934
935 def format_slide(self, words):
936+ """
937+ Calculate how much text can fid on a slide.
938+
939+ ``words``
940+ The words to go on the slides.
941+ """
942 log.debug(u'format slide')
943 self.calculate_default(self.screen_list[self.current_display][u'size'])
944 self.build_text_rectangle(self.themedata)
945 self.renderer.set_frame_dest(self.width, self.height)
946 return self.renderer.format_slide(words, False)
947
948- def generate_slide(self,main_text, footer_text):
949+ def generate_slide(self, main_text, footer_text):
950+ """
951+ Generate the actual slide image.
952+
953+ ``main_text``
954+ The text for the main area of the slide.
955+
956+ ``footer_text``
957+ The text for the slide footer.
958+ """
959 log.debug(u'generate slide')
960 self.calculate_default(self.screen_list[self.current_display][u'size'])
961 self.build_text_rectangle(self.themedata)
962@@ -140,6 +203,12 @@
963 return self.renderer.generate_frame_from_lines(main_text, footer_text)
964
965 def resize_image(self, image):
966+ """
967+ Resize an image to fit on the current screen.
968+
969+ ``image``
970+ The image to resize.
971+ """
972 preview = QtGui.QImage(image)
973 w = self.width
974 h = self.height
975@@ -154,13 +223,19 @@
976 return newImage
977
978 def calculate_default(self, screen):
979- log.debug(u'calculate default %s' , screen)
980+ """
981+ Calculate the default dimentions of the screen.
982+
983+ ``screen``
984+ The QWidget instance of the screen.
985+ """
986+ log.debug(u'calculate default %s', screen)
987 if self.current_display == 0:
988 self.width = 1024
989 self.height = 768
990 else:
991 self.width = screen.width()
992 self.height = screen.height()
993- log.debug(u'calculate default %d,%d' , self.width, self.height)
994+ log.debug(u'calculate default %d, %d', self.width, self.height)
995 # 90% is start of footer
996 self.footer_start = int(self.height * 0.90)
997
998=== modified file 'openlp/core/lib/serviceitem.py'
999--- openlp/core/lib/serviceitem.py 2009-06-20 19:11:17 +0000
1000+++ openlp/core/lib/serviceitem.py 2009-07-10 13:16:15 +0000
1001@@ -20,10 +20,12 @@
1002 import logging
1003 import os
1004 import time
1005+
1006+from PyQt4 import QtCore, QtGui
1007+
1008 from openlp.core.lib import buildIcon
1009-from PyQt4 import QtCore, QtGui
1010
1011-class ServiceItem():
1012+class ServiceItem(object):
1013 """
1014 The service item is a base class for the plugins to use to interact with
1015 the service manager, the slide controller, and the projection screen
1016@@ -35,7 +37,10 @@
1017
1018 def __init__(self, hostplugin=None):
1019 """
1020- Init Method
1021+ Set up the service item.
1022+
1023+ ``hostplugin``
1024+ The plugin that this service item belongs to.
1025 """
1026 self.plugin = hostplugin
1027 if hostplugin is not None:
1028@@ -56,6 +61,14 @@
1029 self.service_frames = []
1030
1031 def addIcon(self, icon):
1032+ """
1033+ Add an icon to the service item. This is used when displaying the
1034+ service item in the service manager.
1035+
1036+ ``icon``
1037+ An instance of QIcon or a string to an icon in the resource or on
1038+ disk.
1039+ """
1040 self.icon = icon
1041 self.iconic_representation = buildIcon(icon)
1042
1043@@ -89,27 +102,63 @@
1044 else:
1045 log.error(u'Invalid value renderer :%s' % self.service_item_type)
1046
1047- def add_from_image(self, path, frame_title, image):
1048+ def add_from_image(self, path, frame_title, image):
1049+ """
1050+ Add an image slide to the service item.
1051+
1052+ ``path``
1053+ The directory in which the image file is located.
1054+
1055+ ``frame_title``
1056+ A title for the slide in the service item.
1057+
1058+ ``image``
1059+ The actual image file name.
1060+ """
1061 self.service_item_type = u'image'
1062 self.service_item_path = path
1063 self.service_frames.append({u'title': frame_title, u'image': image})
1064
1065 def add_from_text(self, frame_title, raw_slide):
1066+ """
1067+ Add a text slide to the service item.
1068+
1069+ ``frame_title``
1070+ The title of the slide in the service item.
1071+
1072+ ``raw_slide``
1073+ The raw text of the slide.
1074+ """
1075 self.service_item_type = u'text'
1076 frame_title = frame_title.split(u'\n')[0]
1077 self.service_frames.append({u'title': frame_title, u'raw_slide': raw_slide})
1078
1079 def add_from_command(self, frame_title, command):
1080+ """
1081+ Add a slide from a command.
1082+
1083+ ``frame_title``
1084+ The title of the slide in the service item.
1085+
1086+ ``command``
1087+ The command of/for the slide.
1088+ """
1089 self.service_item_type = u'command'
1090 self.service_frames.append({u'title': frame_title, u'command': command})
1091
1092 def get_oos_repr(self):
1093 """
1094 This method returns some text which can be saved into the OOS
1095- file to represent this item
1096+ file to represent this item.
1097 """
1098- oos_header = {u'plugin': self.shortname,u'theme':self.theme, u'title':self.title,
1099- u'icon':self.icon, u'footer':self.raw_footer, u'type':self.service_item_type}
1100+ oos_header = {
1101+ u'plugin': self.shortname,
1102+ u'theme':self.theme,
1103+ u'title':self.title,
1104+ u'icon':self.icon,
1105+ u'footer':self.raw_footer,
1106+ u'type':self.service_item_type
1107+ }
1108 oos_data = []
1109 if self.service_item_type == u'text':
1110 for slide in self.service_frames:
1111@@ -124,8 +173,14 @@
1112
1113 def set_from_oos(self, serviceitem, path=None):
1114 """
1115- This method takes some oos list (passed from the ServiceManager)
1116- and extracts the data actually required
1117+ This method takes a service item from a saved service file (passed
1118+ from the ServiceManager) and extracts the data actually required.
1119+
1120+ ``serviceitem``
1121+ The item to extract data from.
1122+
1123+ ``path``
1124+ Defaults to *None*. Any path data, usually for images.
1125 """
1126 #print "sfs", serviceitem
1127 header = serviceitem[u'serviceitem'][u'header']
1128
1129=== modified file 'openlp/core/lib/settingstab.py'
1130--- openlp/core/lib/settingstab.py 2009-06-05 18:53:50 +0000
1131+++ openlp/core/lib/settingstab.py 2009-07-10 13:16:15 +0000
1132@@ -23,11 +23,20 @@
1133
1134 class SettingsTab(QtGui.QWidget):
1135 """
1136- SettingsTab is a helper widget for plugins to define Tabs for the settings dialog.
1137+ SettingsTab is a helper widget for plugins to define Tabs for the settings
1138+ dialog.
1139 """
1140 def __init__(self, title=None, section=None):
1141 """
1142- Constructor to create the Steetings tab item.
1143+ Constructor to create the Settings tab item.
1144+
1145+ ``title``
1146+ Defaults to *None*. The title of the tab, which is usually
1147+ displayed on the tab.
1148+
1149+ ``section``
1150+ Defaults to *None*. This is the section in the configuration file
1151+ to write to when the ``save`` method is called.
1152 """
1153 QtGui.QWidget.__init__(self)
1154 self.tabTitle = title
1155@@ -43,6 +52,9 @@
1156 def setTitle(self, title):
1157 """
1158 Set the title of the tab.
1159+
1160+ ``title``
1161+ The title of the tab, which is usually displayed on the tab.
1162 """
1163 self.tabTitle = title
1164
1165
1166=== modified file 'openlp/core/lib/songxmlhandler.py'
1167--- openlp/core/lib/songxmlhandler.py 2009-06-21 16:26:33 +0000
1168+++ openlp/core/lib/songxmlhandler.py 2009-07-10 13:16:15 +0000
1169@@ -30,21 +30,34 @@
1170
1171 """
1172 import logging
1173-from xml.dom.minidom import Document
1174+from xml.dom.minidom import Document
1175 from xml.etree.ElementTree import ElementTree, XML, dump
1176
1177 class SongXMLBuilder():
1178+ """
1179+ This class builds the XML used to describe songs.
1180+ """
1181 def __init__(self):
1182+ """
1183+ Set up the song builder.
1184+ """
1185 # Create the minidom document
1186 self.song_xml = Document()
1187
1188 def new_document(self):
1189+ """
1190+ Create a new song XML document.
1191+ """
1192 # Create the <song> base element
1193 self.song = self.song_xml.createElement(u'song')
1194 self.song_xml.appendChild(self.song)
1195 self.song.setAttribute(u'version', u'1.0')
1196
1197 def add_lyrics_to_song(self):
1198+ """
1199+ Set up and add a ``<lyrics>`` tag which contains the lyrics of the
1200+ song.
1201+ """
1202 # Create the main <lyrics> element
1203 self.lyrics = self.song_xml.createElement(u'lyrics')
1204 self.lyrics.setAttribute(u'language', u'en')
1205@@ -52,50 +65,72 @@
1206
1207 def add_verse_to_lyrics(self, type, number, content):
1208 """
1209- type - type of verse (Chorus, Verse , Bridge, Custom etc
1210- number - number of item eg verse 1
1211- content - the text to be stored
1212+ Add a verse to the ``<lyrics>`` tag.
1213+
1214+ ``type``
1215+ A string denoting the type of verse. Possible values are "Chorus",
1216+ "Verse", "Bridge", and "Custom".
1217+
1218+ ``number``
1219+ An integer denoting the number of the item, for example: verse 1.
1220+
1221+ ``content``
1222+ The actual text of the verse to be stored.
1223 """
1224 verse = self.song_xml.createElement(u'verse')
1225 verse.setAttribute(u'type', type)
1226 verse.setAttribute(u'label', number)
1227 self.lyrics.appendChild(verse)
1228-
1229- # add data as a CDATA section
1230+ # add data as a CDATA section to protect the XML from special chars
1231 cds = self.song_xml.createCDATASection(content)
1232 verse.appendChild(cds)
1233
1234 def dump_xml(self):
1235- # Debugging aid to see what we have
1236+ """
1237+ Debugging aid to dump XML so that we can see what we have.
1238+ """
1239 print self.song_xml.toprettyxml(indent=u' ')
1240
1241 def extract_xml(self):
1242- # Print our newly created XML
1243+ """
1244+ Extract our newly created XML song.
1245+ """
1246 return self.song_xml.toxml(u'utf-8')
1247
1248 class SongXMLParser():
1249+ """
1250+ A class to read in and parse a song's XML.
1251+ """
1252 global log
1253 log = logging.getLogger(u'SongXMLParser')
1254 log.info(u'SongXMLParser Loaded')
1255
1256 def __init__(self, xml):
1257- #print xml
1258+ """
1259+ Set up our song XML parser.
1260+
1261+ ``xml``
1262+ The XML of the song to be parsed.
1263+ """
1264 try:
1265 self.song_xml = ElementTree(element=XML(xml))
1266 except:
1267- #print "invalid xml ", xml
1268- log.debug(u'invalid xml %s', xml)
1269+ log.debug(u'Invalid xml %s', xml)
1270
1271 def get_verses(self):
1272- #return a list of verse's and attributes
1273- iter=self.song_xml.getiterator()
1274+ """
1275+ Iterates through the verses in the XML and returns a list of verses
1276+ and their attributes.
1277+ """
1278+ iter = self.song_xml.getiterator()
1279 verse_list = []
1280 for element in iter:
1281- #print element.tag, element.attrib, element.text
1282 if element.tag == u'verse':
1283 verse_list.append([element.attrib, element.text])
1284 return verse_list
1285
1286 def dump_xml(self):
1287- # Debugging aid to see what we have
1288+ """
1289+ Debugging aid to dump XML so that we can see what we have.
1290+ """
1291 print dump(self.song_xml)
1292
1293=== modified file 'openlp/core/lib/themexmlhandler.py'
1294--- openlp/core/lib/themexmlhandler.py 2009-07-08 06:55:08 +0000
1295+++ openlp/core/lib/themexmlhandler.py 2009-07-10 13:16:15 +0000
1296@@ -345,5 +345,5 @@
1297 s = u''
1298 for k in dir(self):
1299 if k[0:1] != u'_':
1300- s += u'%30s : %s\n' %(k, getattr(self, k))
1301+ s += u'%30s: %s\n' %(k, getattr(self, k))
1302 return s