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
=== modified file 'openlp/core/lib/plugin.py'
--- openlp/core/lib/plugin.py 2009-07-06 16:34:13 +0000
+++ openlp/core/lib/plugin.py 2009-07-10 13:16:15 +0000
@@ -31,42 +31,58 @@
31 Base class for openlp plugins to inherit from.31 Base class for openlp plugins to inherit from.
3232
33 Basic attributes are:33 Basic attributes are:
34 * name34
35 ``name``
35 The name that should appear in the plugins list.36 The name that should appear in the plugins list.
36 * version37
38 ``version``
37 The version number of this iteration of the plugin.39 The version number of this iteration of the plugin.
38 * icon40
41 ``icon``
39 An instance of QIcon, which holds an icon for this plugin.42 An instance of QIcon, which holds an icon for this plugin.
40 * config43
44 ``config``
41 An instance of PluginConfig, which allows plugins to read and write to45 An instance of PluginConfig, which allows plugins to read and write to
42 openlp.org's configuration. This is pre-instantiated.46 openlp.org's configuration. This is pre-instantiated.
43 * log47
48 ``log``
44 A log object used to log debugging messages. This is pre-instantiated.49 A log object used to log debugging messages. This is pre-instantiated.
4550
46 Hook functions:51 Hook functions:
47 * check_pre_conditions()52
53 ``check_pre_conditions()``
48 Provides the Plugin with a handle to check if it can be loaded.54 Provides the Plugin with a handle to check if it can be loaded.
49 * get_media_manager_item()55
56 ``get_media_manager_item()``
50 Returns an instance of MediaManagerItem to be used in the Media Manager.57 Returns an instance of MediaManagerItem to be used in the Media Manager.
51 * add_import_menu_item(import_menu)58
59 ``add_import_menu_item(import_menu)``
52 Add an item to the Import menu.60 Add an item to the Import menu.
53 * add_export_menu_item(export_menu)61
62 ``add_export_menu_item(export_menu)``
54 Add an item to the Export menu.63 Add an item to the Export menu.
55 * get_settings_tab()64
65 ``get_settings_tab()``
56 Returns an instance of SettingsTabItem to be used in the Settings dialog.66 Returns an instance of SettingsTabItem to be used in the Settings dialog.
57 * add_to_menu(menubar)67
68 ``add_to_menu(menubar)``
58 A method to add a menu item to anywhere in the menu, given the menu bar.69 A method to add a menu item to anywhere in the menu, given the menu bar.
59 * handle_event(event)70
71 ``handle_event(event)``
60 A method use to handle events, given an Event object.72 A method use to handle events, given an Event object.
61 * about()73
74 ``about()``
62 Used in the plugin manager, when a person clicks on the 'About' button.75 Used in the plugin manager, when a person clicks on the 'About' button.
63 * save(data)76
77 ``save(data)``
64 A method to convert the plugin's data to a string to be stored in the78 A method to convert the plugin's data to a string to be stored in the
65 Service file.79 Service file.
66 * load(string)80
81 ``load(string)``
67 A method to convert the string from a Service file into the plugin's82 A method to convert the string from a Service file into the plugin's
68 own data format.83 own data format.
69 * render(theme, screen_number)84
85 ``render(theme, screen_number)``
70 A method used to render something to the screen, given the current theme86 A method used to render something to the screen, given the current theme
71 and screen number.87 and screen number.
72 """88 """
@@ -78,11 +94,20 @@
78 """94 """
79 This is the constructor for the plugin object. This provides an easy95 This is the constructor for the plugin object. This provides an easy
80 way for descendent plugins to populate common data. This method *must*96 way for descendent plugins to populate common data. This method *must*
81 be overridden, like so:97 be overridden, like so::
82 class MyPlugin(Plugin):98
83 def __init__(self):99 class MyPlugin(Plugin):
84 Plugin.__init(self, 'MyPlugin', '0.1')100 def __init__(self):
85 ...101 Plugin.__init(self, u'MyPlugin', u'0.1')
102
103 ``name``
104 Defaults to *None*. The name of the plugin.
105
106 ``version``
107 Defaults to *None*. The version of the plugin.
108
109 ``plugin_helpers``
110 Defaults to *None*. A list of helper objects.
86 """111 """
87 if name is not None:112 if name is not None:
88 self.name = name113 self.name = name
@@ -107,50 +132,59 @@
107 def check_pre_conditions(self):132 def check_pre_conditions(self):
108 """133 """
109 Provides the Plugin with a handle to check if it can be loaded.134 Provides the Plugin with a handle to check if it can be loaded.
135
110 Returns True or False.136 Returns True or False.
111 """137 """
112 return True138 return True
113139
114 def get_media_manager_item(self):140 def get_media_manager_item(self):
115 """141 """
116 Construct a MediaManagerItem object with all the buttons and things you142 Construct a MediaManagerItem object with all the buttons and things
117 need, and return it for integration into openlp.org.143 you need, and return it for integration into openlp.org.
118 """144 """
119 pass145 pass
120146
121 def add_import_menu_item(self, import_menu):147 def add_import_menu_item(self, import_menu):
122 """148 """
123 Create a menu item and add it to the "Import" menu.149 Create a menu item and add it to the "Import" menu.
150
151 ``import_menu``
152 The Import menu.
124 """153 """
125 pass154 pass
126155
127 def add_export_menu_item(self, export_menu):156 def add_export_menu_item(self, export_menu):
128 """157 """
129 Create a menu item and add it to the "Export" menu.158 Create a menu item and add it to the "Export" menu.
159
160 ``export_menu``
161 The Export menu
130 """162 """
131 pass163 pass
132164
133 def get_settings_tab(self):165 def get_settings_tab(self):
134 """166 """
135 Create a menu item and add it to the "Import" menu.167 Create a tab for the settings window.
136 """168 """
137 pass169 pass
138170
139 def add_to_menu(self, menubar):171 def add_to_menu(self, menubar):
140 """172 """
141 Add menu items to the menu, given the menubar.173 Add menu items to the menu, given the menubar.
174
175 ``menubar``
176 The application's menu bar.
142 """177 """
143 pass178 pass
144179
145 def handle_event(self, event):180 def handle_event(self, event):
146 """181 """
147 Handle the event contained in the event object.
148 """
149 def handle_event(self, event):
150 """
151 Handle the event contained in the event object. If you want182 Handle the event contained in the event object. If you want
152 to use this default behaviour, you must set self.dnd_id equal183 to use this default behaviour, you must set self.dnd_id equal
153 to that sent by the dnd source - eg the MediaItem184 to that sent by the dnd source - eg the MediaItem
185
186 ``event``
187 An object describing the event.
154 """188 """
155 # default behaviour - can be overridden if desired189 # default behaviour - can be overridden if desired
156 log.debug(u'Handle event called with event %s with payload %s'%(event.event_type, event.payload))190 log.debug(u'Handle event called with event %s with payload %s'%(event.event_type, event.payload))
@@ -175,6 +209,9 @@
175 """209 """
176 Service item data is passed to this function, which should return a210 Service item data is passed to this function, which should return a
177 string which can be written to the service file.211 string which can be written to the service file.
212
213 ``data``
214 The data to be saved.
178 """215 """
179 pass216 pass
180217
@@ -182,12 +219,21 @@
182 """219 """
183 A string from the service file is passed in. This function parses and220 A string from the service file is passed in. This function parses and
184 sets up the internals of the plugin.221 sets up the internals of the plugin.
222
223 ``string``
224 The data to be loaded into the plugin.
185 """225 """
186 pass226 pass
187227
188 def render(self, theme, screen=None):228 def render(self, theme, screen=None):
189 """229 """
190 Render the screenth screenful of data using theme settings in theme.230 Render the screenth screenful of data using theme settings in theme.
231
232 ``theme``
233 The theme to use when rendering.
234
235 ``screen``
236 Defaults to *None*. The screen to render to.
191 """237 """
192 pass238 pass
193239
194240
=== modified file 'openlp/core/lib/pluginconfig.py'
--- openlp/core/lib/pluginconfig.py 2009-07-08 05:12:16 +0000
+++ openlp/core/lib/pluginconfig.py 2009-07-10 13:16:15 +0000
@@ -29,28 +29,50 @@
29 """29 """
30 Initialise the plugin config object, setting the section name to the30 Initialise the plugin config object, setting the section name to the
31 plugin name.31 plugin name.
32
33 ``plugin_name``
34 The name of the plugin to use as a section name.
32 """35 """
33 self.section = plugin_name.lower()36 self.section = plugin_name.lower()
3437
35 def get_config(self, key, default=None):38 def get_config(self, key, default=None):
36 """39 """
37 Get a configuration value from the configuration registry.40 Get a configuration value from the configuration registry.
41
42 ``key``
43 The name of configuration to load.
44
45 ``default``
46 Defaults to *None*. The default value to return if there is no
47 other value.
38 """48 """
39 return ConfigHelper.get_config(self.section, key, default)49 return ConfigHelper.get_config(self.section, key, default)
4050
41 def delete_config(self, key):51 def delete_config(self, key):
42 """52 """
43 Delete a configuration value from the configuration registry.53 Delete a configuration value from the configuration registry.
54
55 ``key``
56 The name of the configuration to remove.
44 """57 """
45 return ConfigHelper.delete_config(self.section, key)58 return ConfigHelper.delete_config(self.section, key)
4659
47 def set_config(self, key, value):60 def set_config(self, key, value):
48 """61 """
49 Set a configuration value in the configuration registry.62 Set a configuration value in the configuration registry.
63
64 ``key``
65 The name of the configuration to save.
66
67 ``value``
68 The value of the configuration to save.
50 """69 """
51 return ConfigHelper.set_config(self.section, key, value)70 return ConfigHelper.set_config(self.section, key, value)
5271
53 def get_data_path(self):72 def get_data_path(self):
73 """
74 Dynamically build the data file path for a plugin.
75 """
54 #app_data = ConfigHelper.get_data_path()76 #app_data = ConfigHelper.get_data_path()
55 app_data = ConfigHelper.get_data_path()77 app_data = ConfigHelper.get_data_path()
56 safe_name = self.section.replace(u' ',u'-')78 safe_name = self.section.replace(u' ',u'-')
@@ -61,9 +83,21 @@
61 return path83 return path
6284
63 def set_data_path(self, path):85 def set_data_path(self, path):
86 """
87 Set the data file path.
88
89 ``path``
90 The path to save.
91 """
64 return self.set_config(u'data path', os.path.basename(path))92 return self.set_config(u'data path', os.path.basename(path))
6593
66 def get_files(self, suffix=None):94 def get_files(self, suffix=None):
95 """
96 Get a list of files from the data files path.
97
98 ``suffix``
99 Defaults to *None*. The extension to search for.
100 """
67 try:101 try:
68 files = os.listdir(self.get_data_path())102 files = os.listdir(self.get_data_path())
69 except:103 except:
@@ -86,7 +120,10 @@
86120
87 def load_list(self, name):121 def load_list(self, name):
88 """122 """
89 Load a list from the config file123 Load a list from the config file.
124
125 ``name``
126 The name of the list.
90 """127 """
91 list_count = self.get_config(u'%s count' % name)128 list_count = self.get_config(u'%s count' % name)
92 if list_count is not None:129 if list_count is not None:
@@ -102,7 +139,13 @@
102139
103 def set_list(self, name, list):140 def set_list(self, name, list):
104 """141 """
105 Save a list to the config file142 Save a list to the config file.
143
144 ``name``
145 The name of the list to save.
146
147 ``list``
148 The list of values to save.
106 """149 """
107 old_count = int(self.get_config(u'%s count' % name, int(0)))150 old_count = int(self.get_config(u'%s count' % name, int(0)))
108 new_count = len(list)151 new_count = len(list)
@@ -116,7 +159,10 @@
116159
117 def get_last_dir(self, num=None):160 def get_last_dir(self, num=None):
118 """161 """
119 Read the last directory used for plugin162 Read the last directory used for plugin.
163
164 ``num``
165 Defaults to *None*. A further qualifier.
120 """166 """
121 if num is not None:167 if num is not None:
122 name = u'last directory %d' % num168 name = u'last directory %d' % num
@@ -129,7 +175,10 @@
129175
130 def set_last_dir(self, directory, num=None):176 def set_last_dir(self, directory, num=None):
131 """177 """
132 Save the last directory used for plugin178 Save the last directory used for plugin.
179
180 ``num``
181 Defaults to *None*. A further qualifier.
133 """182 """
134 if num is not None:183 if num is not None:
135 name = u'last directory %d' % num184 name = u'last directory %d' % num
136185
=== modified file 'openlp/core/lib/pluginmanager.py'
--- openlp/core/lib/pluginmanager.py 2009-07-08 05:12:16 +0000
+++ openlp/core/lib/pluginmanager.py 2009-07-10 13:16:15 +0000
@@ -34,8 +34,11 @@
3434
35 def __init__(self, dir):35 def __init__(self, dir):
36 """36 """
37 The constructor for the plugin manager.37 The constructor for the plugin manager. Passes the controllers on to
38 Passes the controllers on to the plugins for them to interact with via their ServiceItems38 the plugins for them to interact with via their ServiceItems.
39
40 ``dir``
41 The directory to search for plugins.
39 """42 """
40 log.info(u'Plugin manager initing')43 log.info(u'Plugin manager initing')
41 if not dir in sys.path:44 if not dir in sys.path:
@@ -49,7 +52,16 @@
4952
50 def find_plugins(self, dir, plugin_helpers, eventmanager):53 def find_plugins(self, dir, plugin_helpers, eventmanager):
51 """54 """
52 Scan the directory dir for objects inheriting from openlp.plugin55 Scan the directory dir for objects inheriting from ``openlp.plugin``.
56
57 ``dir``
58 The directory to scan.
59
60 ``plugin_helpers``
61 A list of helper objects to pass to the plugins.
62
63 ``eventmanager``
64 The event manager to pass to the plugins.
53 """65 """
54 self.plugin_helpers = plugin_helpers66 self.plugin_helpers = plugin_helpers
55 startdepth = len(os.path.abspath(dir).split(os.sep))67 startdepth = len(os.path.abspath(dir).split(os.sep))
@@ -104,8 +116,8 @@
104116
105 def hook_media_manager(self, mediatoolbox):117 def hook_media_manager(self, mediatoolbox):
106 """118 """
107 Loop through all the plugins. If a plugin has a valid media manager item,119 Loop through all the plugins. If a plugin has a valid media manager
108 add it to the media manager.120 item, add it to the media manager.
109121
110 ``mediatoolbox``122 ``mediatoolbox``
111 The Media Manager itself.123 The Media Manager itself.
@@ -118,8 +130,11 @@
118130
119 def hook_settings_tabs(self, settingsform=None):131 def hook_settings_tabs(self, settingsform=None):
120 """132 """
121 Loop through all the plugins. If a plugin has a valid settings tab item,133 Loop through all the plugins. If a plugin has a valid settings tab
122 add it to the settings tab.134 item, add it to the settings tab.
135
136 ``settingsform``
137 Defaults to *None*. The settings form to add tabs to.
123 """138 """
124 for plugin in self.plugins:139 for plugin in self.plugins:
125 settings_tab = plugin.get_settings_tab()140 settings_tab = plugin.get_settings_tab()
@@ -131,24 +146,30 @@
131146
132 def hook_import_menu(self, import_menu):147 def hook_import_menu(self, import_menu):
133 """148 """
134 Loop through all the plugins and give them an opportunity to add an item149 Loop through all the plugins and give them an opportunity to add an
135 to the import menu.150 item to the import menu.
151
152 ``import_menu``
153 The Import menu.
136 """154 """
137 for plugin in self.plugins:155 for plugin in self.plugins:
138 plugin.add_import_menu_item(import_menu)156 plugin.add_import_menu_item(import_menu)
139157
140 def hook_export_menu(self, export_menu):158 def hook_export_menu(self, export_menu):
141 """159 """
142 Loop through all the plugins and give them an opportunity to add an item160 Loop through all the plugins and give them an opportunity to add an
143 to the export menu.161 item to the export menu.
162
163 ``export_menu``
164 The Export menu.
144 """165 """
145 for plugin in self.plugins:166 for plugin in self.plugins:
146 plugin.add_export_menu_item(export_menu)167 plugin.add_export_menu_item(export_menu)
147168
148 def initialise_plugins(self):169 def initialise_plugins(self):
149 """170 """
150 Loop through all the plugins and give them an opportunity to add an item171 Loop through all the plugins and give them an opportunity to
151 to the export menu.172 initialise themselves.
152 """173 """
153 for plugin in self.plugins:174 for plugin in self.plugins:
154 plugin.initialise()175 plugin.initialise()
155176
=== modified file 'openlp/core/lib/renderer.py'
--- openlp/core/lib/renderer.py 2009-06-26 16:17:55 +0000
+++ openlp/core/lib/renderer.py 2009-07-10 13:16:15 +0000
@@ -18,12 +18,12 @@
18Place, Suite 330, Boston, MA 02111-1307 USA18Place, Suite 330, Boston, MA 02111-1307 USA
19"""19"""
20import logging20import logging
21import os, os.path21import os
22import sys22import sys
2323
24from PyQt4 import QtGui, QtCore24from PyQt4 import QtGui, QtCore
2525
26class Renderer:26class Renderer(object):
27 """27 """
28 Genarates a pixmap image of a array of text. The Text is formatted to28 Genarates a pixmap image of a array of text. The Text is formatted to
29 make sure it fits on the screen and if not extra frames a generated.29 make sure it fits on the screen and if not extra frames a generated.
@@ -33,6 +33,9 @@
33 log.info(u'Renderer Loaded')33 log.info(u'Renderer Loaded')
3434
35 def __init__(self):35 def __init__(self):
36 """
37 Initialise the renderer.
38 """
36 self._rect = None39 self._rect = None
37 self._debug = 040 self._debug = 0
38 self._right_margin = 64 # the amount of right indent41 self._right_margin = 64 # the amount of right indent
@@ -47,11 +50,20 @@
47 self._bg_frame_small = None50 self._bg_frame_small = None
4851
49 def set_debug(self, debug):52 def set_debug(self, debug):
53 """
54 Set the debug mode of the renderer.
55
56 ``debug``
57 The debug mode.
58 """
50 self._debug=debug59 self._debug=debug
5160
52 def set_theme(self, theme):61 def set_theme(self, theme):
53 """62 """
54 External API to pass in the theme to be used63 Set the theme to be used.
64
65 ``theme``
66 The theme to be used.
55 """67 """
56 log.debug(u'set theme')68 log.debug(u'set theme')
57 self._theme = theme69 self._theme = theme
@@ -64,12 +76,21 @@
64 self.set_bg_image(theme.background_filename)76 self.set_bg_image(theme.background_filename)
6577
66 def set_bg_image(self, filename):78 def set_bg_image(self, filename):
79 """
80 Set a background image.
81
82 ``filename``
83 The name of the image file.
84 """
67 log.debug(u'set bg image %s', filename)85 log.debug(u'set bg image %s', filename)
68 self._bg_image_filename = unicode(filename)86 self._bg_image_filename = unicode(filename)
69 if self._frame is not None:87 if self._frame is not None:
70 self.scale_bg_image()88 self.scale_bg_image()
7189
72 def scale_bg_image(self):90 def scale_bg_image(self):
91 """
92 Scale the background image to fit the screen.
93 """
73 assert self._frame94 assert self._frame
74 preview = QtGui.QImage(self._bg_image_filename)95 preview = QtGui.QImage(self._bg_image_filename)
75 width = self._frame.width()96 width = self._frame.width()
@@ -89,7 +110,16 @@
89110
90 def set_frame_dest(self, frame_width, frame_height, preview=False):111 def set_frame_dest(self, frame_width, frame_height, preview=False):
91 """112 """
92 External API to pass the frame size to be painted113 Set the size of the slide.
114
115 ``frame_width``
116 The width of the slide.
117
118 ``frame_height``
119 The height of the slide.
120
121 ``preview``
122 Defaults to *False*. Whether or not to generate a preview.
93 """123 """
94 if preview == True:124 if preview == True:
95 self._bg_frame = None125 self._bg_frame = None
@@ -103,7 +133,14 @@
103133
104 def format_slide(self, words, footer):134 def format_slide(self, words, footer):
105 """135 """
106 External API to sort out the text to pe placed on the frame136 Figure out how much text can appear on a slide, using the current
137 theme settings.
138
139 ``words``
140 The words to be fitted on the slide.
141
142 ``footer``
143 The footer of the slide.
107 """144 """
108 log.debug(u'format_slide - Start')145 log.debug(u'format_slide - Start')
109 verses = []146 verses = []
@@ -120,15 +157,28 @@
120157
121 def set_text_rectangle(self, rect_main, rect_footer):158 def set_text_rectangle(self, rect_main, rect_footer):
122 """159 """
123 Sets the rectangle within which text should be rendered160 Sets the rectangle within which text should be rendered.
161
162 ``rect_main``
163 The main text block.
164
165 ``rect_footer``
166 The footer text block.
124 """167 """
125 self._rect = rect_main168 self._rect = rect_main
126 self._rect_footer = rect_footer169 self._rect_footer = rect_footer
127170
128 def generate_frame_from_lines(self, lines, footer_lines=None):171 def generate_frame_from_lines(self, lines, footer_lines=None):
129 """172 """
130 Render a set of lines according to the theme, return bounding box173 Render a set of lines according to the theme, and return the block
131 """174 dimensions.
175
176 ``lines``
177 The lines to be rendered.
178
179 ``footer_lines``
180 Defaults to *None*. The footer to render.
181 """
132 log.debug(u'generate_frame_from_lines - Start')182 log.debug(u'generate_frame_from_lines - Start')
133 #print "Render Lines ", lines183 #print "Render Lines ", lines
134 bbox = self._render_lines_unaligned(lines, False)184 bbox = self._render_lines_unaligned(lines, False)
@@ -139,14 +189,15 @@
139 x, y = self._correctAlignment(self._rect, bbox)189 x, y = self._correctAlignment(self._rect, bbox)
140 bbox = self._render_lines_unaligned(lines, False, (x, y), True)190 bbox = self._render_lines_unaligned(lines, False, (x, y), True)
141 if footer_lines is not None:191 if footer_lines is not None:
142 bbox = self._render_lines_unaligned(footer_lines, True, (self._rect_footer.left(), self._rect_footer.top()), True )192 bbox = self._render_lines_unaligned(footer_lines, True,
193 (self._rect_footer.left(), self._rect_footer.top()), True)
143 log.debug(u'generate_frame_from_lines - Finish')194 log.debug(u'generate_frame_from_lines - Finish')
144 return self._frame195 return self._frame
145196
146 def _generate_background_frame(self):197 def _generate_background_frame(self):
147 """198 """
148 Generate a background frame to the same size as the frame to be used199 Generate a background frame to the same size as the frame to be used.
149 Results cached for performance reasons.200 Results are cached for performance reasons.
150 """201 """
151 assert(self._theme)202 assert(self._theme)
152 self._bg_frame = QtGui.QImage(self._frame.width(), self._frame.height(),203 self._bg_frame = QtGui.QImage(self._frame.width(), self._frame.height(),
@@ -196,11 +247,19 @@
196247
197 def _split_set_of_lines(self, lines, footer):248 def _split_set_of_lines(self, lines, footer):
198 """249 """
199 Given a list of lines, decide how to split them best if they don't all fit on the screen250 Given a list of lines, decide how to split them best if they don't all
200 - this is done by splitting at 1/2, 1/3 or 1/4 of the set251 fit on the screen. This is done by splitting at 1/2, 1/3 or 1/4 of the
201 If it doesn't fit, even at this size, just split at each opportunity.252 set. If it doesn't fit, even at this size, just split at each
202 We'll do this by getting the bounding box of each line, and then summing them appropriately253 opportunity. We'll do this by getting the bounding box of each line,
203 Returns a list of [lists of lines], one set for each screenful254 and then summing them appropriately.
255
256 Returns a list of [lists of lines], one set for each screenful.
257
258 ``lines``
259 The lines of text to split.
260
261 ``footer``
262 The footer text.
204 """263 """
205 bboxes = []264 bboxes = []
206 for line in lines:265 for line in lines:
@@ -254,6 +313,15 @@
254 return retval313 return retval
255314
256 def _correctAlignment(self, rect, bbox):315 def _correctAlignment(self, rect, bbox):
316 """
317 Corrects the vertical alignment of text.
318
319 ``rect``
320 The block dimentions.
321
322 ``bbox``
323 Footer dimensions?
324 """
257 x = rect.left()325 x = rect.left()
258 if int(self._theme.display_verticalAlign) == 0:326 if int(self._theme.display_verticalAlign) == 0:
259 # top align327 # top align
@@ -268,13 +336,26 @@
268 log.error(u'Invalid value for theme.VerticalAlign:%s' % self._theme.display_verticalAlign)336 log.error(u'Invalid value for theme.VerticalAlign:%s' % self._theme.display_verticalAlign)
269 return x, y337 return x, y
270338
271 def _render_lines_unaligned(self, lines, footer, tlcorner=(0,0), live=False):339 def _render_lines_unaligned(self, lines, footer, tlcorner=(0, 0), live=False):
272 """340 """
273 Given a list of lines to render, render each one in turn341 Given a list of lines to render, render each one in turn (using the
274 (using the _render_single_line fn - which may result in going342 ``_render_single_line`` fn - which may result in going off the bottom).
275 off the bottom) They are expected to be pre-arranged to less343 They are expected to be pre-arranged to less than a screenful (eg. by
276 than a screenful (eg. by using split_set_of_lines)344 using split_set_of_lines).
277 Returns the bounding box of the text as QRect345
346 Returns the bounding box of the text as QRect.
347
348 ``lines``
349 The lines of text to render.
350
351 ``footer``
352 The slide footer.
353
354 ``tlcorner``
355 Defaults to *``(0, 0)``*. Co-ordinates of the top left corner.
356
357 ``live``
358 Defaults to *False*. Whether or not this is a live screen.
278 """359 """
279 x, y = tlcorner360 x, y = tlcorner
280 brx = x361 brx = x
@@ -282,25 +363,37 @@
282 for line in lines:363 for line in lines:
283 # render after current bottom, but at original left edge364 # render after current bottom, but at original left edge
284 # keep track of right edge to see which is biggest365 # keep track of right edge to see which is biggest
285 (thisx, bry) = self._render_and_wrap_single_line(line, footer, (x , bry), live)366 (thisx, bry) = self._render_and_wrap_single_line(line, footer, (x, bry), live)
286 if (thisx > brx):367 if (thisx > brx):
287 brx = thisx368 brx = thisx
288 retval = QtCore.QRect(x, y,brx-x, bry-y)369 retval = QtCore.QRect(x, y, brx - x, bry - y)
289 if self._debug:370 if self._debug:
290 painter = QtGui.QPainter()371 painter = QtGui.QPainter()
291 painter.begin(self._frame)372 painter.begin(self._frame)
292 painter.setPen(QtGui.QPen(QtGui.QColor(0,0,255)))373 painter.setPen(QtGui.QPen(QtGui.QColor(0, 0, 255)))
293 painter.drawRect(retval)374 painter.drawRect(retval)
294 painter.end()375 painter.end()
295 return retval376 return retval
296377
297 def _render_and_wrap_single_line(self, line, footer, tlcorner=(0,0), live=False):378 def _render_and_wrap_single_line(self, line, footer, tlcorner=(0, 0), live=False):
298 """379 """
299 Render a single line of words onto the DC, top left corner380 Render a single line of words onto the DC, top left corner specified.
300 specified.381 If the line is too wide for the context, it wraps, but right-aligns
301 If the line is too wide for the context, it wraps, but382 the surplus words in the manner of song lyrics.
302 right-aligns the surplus words in the manner of song lyrics383
303 Returns the bottom-right corner (of what was rendered) as a tuple(x, y).384 Returns the bottom-right corner (of what was rendered) as a tuple(x, y).
385
386 ``line``
387 Line of text to be rendered.
388
389 ``footer``
390 The footer of the slide.
391
392 ``tlcorner``
393 Defaults to *``(0, 0)``*. The top left corner.
394
395 ``live``
396 Defaults to *False*. Whether or not this is a live screen.
304 """397 """
305 x, y = tlcorner398 x, y = tlcorner
306 # We draw the text to see how big it is and then iterate to make it fit399 # We draw the text to see how big it is and then iterate to make it fit
@@ -397,6 +490,9 @@
397 return brcorner490 return brcorner
398491
399 def _set_theme_font(self):492 def _set_theme_font(self):
493 """
494 Set the fonts from the current theme settings.
495 """
400 self.footerFont = QtGui.QFont(self._theme.font_footer_name,496 self.footerFont = QtGui.QFont(self._theme.font_footer_name,
401 int(self._theme.font_footer_proportion), # size497 int(self._theme.font_footer_proportion), # size
402 QtGui.QFont.Normal, # weight498 QtGui.QFont.Normal, # weight
@@ -408,11 +504,26 @@
408 0)# italic504 0)# italic
409 self.mainFont.setPixelSize(int(self._theme.font_main_proportion))505 self.mainFont.setPixelSize(int(self._theme.font_main_proportion))
410506
411 def _get_extent_and_render(self, line, footer, tlcorner=(0,0), draw=False, color=None):507 def _get_extent_and_render(self, line, footer, tlcorner=(0, 0), draw=False, color=None):
412 """508 """
413 Find bounding box of text - as render_single_line.509 Find bounding box of text - as render_single_line. If draw is set,
414 If draw is set, actually draw the text to the current DC as well510 actually draw the text to the current DC as well return width and
415 return width and height of text as a tuple (w,h)511 height of text as a tuple (w, h).
512
513 ``line``
514 The line of text to render.
515
516 ``footer``
517 The footer text.
518
519 ``tlcorner``
520 Defaults to *``(0, 0)``*. The top left corner co-ordinates.
521
522 ``draw``
523 Defaults to *False*. Draw the text to the current surface.
524
525 ``color``
526 Defaults to *None*. The colour to draw with.
416 """527 """
417 # setup defaults528 # setup defaults
418 painter = QtGui.QPainter()529 painter = QtGui.QPainter()
@@ -424,7 +535,7 @@
424 else:535 else:
425 font = self.mainFont536 font = self.mainFont
426 painter.setFont(font)537 painter.setFont(font)
427 if color == None:538 if color is None:
428 if footer:539 if footer:
429 painter.setPen(QtGui.QColor(self._theme.font_footer_color))540 painter.setPen(QtGui.QColor(self._theme.font_footer_color))
430 else:541 else:
@@ -443,7 +554,13 @@
443554
444 def snoop_Image(self, image, image2=None):555 def snoop_Image(self, image, image2=None):
445 """556 """
446 Debugging method to allow images to be viewed557 Debugging method to allow images to be viewed.
558
559 ``image``
560 An image to save to disk.
561
562 ``image2``
563 Defaults to *None*. Another image to save to disk.
447 """564 """
448 im = image.toImage()565 im = image.toImage()
449 im.save(u'renderer.png', u'png')566 im.save(u'renderer.png', u'png')
450567
=== modified file 'openlp/core/lib/rendermanager.py'
--- openlp/core/lib/rendermanager.py 2009-07-02 19:04:50 +0000
+++ openlp/core/lib/rendermanager.py 2009-07-10 13:16:15 +0000
@@ -18,26 +18,37 @@
18Place, Suite 330, Boston, MA 02111-1307 USA18Place, Suite 330, Boston, MA 02111-1307 USA
19"""19"""
20import logging20import logging
21import os, os.path21import os
22import sys22import sys
23import linecache
2324
24from PyQt4 import QtGui, QtCore25from PyQt4 import QtGui, QtCore
26
25from renderer import Renderer27from renderer import Renderer
2628
27import sys29class RenderManager(object):
28import linecache
29
30class RenderManager:
31 """30 """
32 Class to pull all Renderer interactions into one place.31 Class to pull all Renderer interactions into one place. The plugins will
33 The plugins will call helper methods to do the rendering but32 call helper methods to do the rendering but this class will provide
34 this class will provide display defense code.33 display defense code.
35 """34 """
36 global log35 global log
37 log=logging.getLogger(u'RenderManager')36 log=logging.getLogger(u'RenderManager')
38 log.info(u'RenderManager Loaded')37 log.info(u'RenderManager Loaded')
3938
40 def __init__(self, theme_manager, screen_list, screen_number=0):39 def __init__(self, theme_manager, screen_list, screen_number=0):
40 """
41 Initialise the render manager.
42
43 ``theme_manager``
44 The ThemeManager instance, used to get the current theme details.
45
46 ``screen_list``
47 The list of screens available.
48
49 ``screen_number``
50 Defaults to *0*. The index of the output/display screen.
51 """
41 log.debug(u'Initilisation started')52 log.debug(u'Initilisation started')
42 self.screen_list = screen_list53 self.screen_list = screen_list
43 self.theme_manager = theme_manager54 self.theme_manager = theme_manager
@@ -52,21 +63,46 @@
52 def update_display(self, screen_number):63 def update_display(self, screen_number):
53 """64 """
54 Updates the render manager's information about the current screen.65 Updates the render manager's information about the current screen.
66
67 ``screen_number``
68 The updated index of the output/display screen.
55 """69 """
56 log.debug(u'Update Display')70 log.debug(u'Update Display')
57 if self.current_display != screen_number:71 if self.current_display != screen_number:
58 self.current_display = screen_number72 self.current_display = screen_number
59 self.calculate_default(self.screen_list[self.current_display][u'size'])73 self.calculate_default(self.screen_list[self.current_display][u'size'])
6074
61 def set_global_theme(self, global_theme, global_style = u'Global'):75 def set_global_theme(self, global_theme, global_style=u'Global'):
76 """
77 Set the global-level theme and the theme level.
78
79 ``global_theme``
80 The global-level theme to be set.
81
82 ``global_style``
83 Defaults to *"Global"*. The theme level, can be "Global",
84 "Service" or "Song".
85 """
62 self.global_theme = global_theme86 self.global_theme = global_theme
63 self.global_style = global_style87 self.global_style = global_style
6488
65 def set_service_theme(self, service_theme):89 def set_service_theme(self, service_theme):
90 """
91 Set the service-level theme.
92
93 ``service_theme``
94 The service-level theme to be set.
95 """
66 self.service_theme = service_theme96 self.service_theme = service_theme
6797
68 def set_override_theme(self, theme):98 def set_override_theme(self, theme):
69 log.debug(u'set override theme to %s', theme)99 """
100 Set the appropriate theme depending on the theme level.
101
102 ``theme``
103 The name of the song-level theme.
104 """
105 log.debug(u'set override theme to %s', theme)
70 if self.global_style == u'Global':106 if self.global_style == u'Global':
71 self.theme = self.global_theme107 self.theme = self.global_theme
72 elif self.global_style == u'Service':108 elif self.global_style == u'Service':
@@ -84,7 +120,7 @@
84 self.theme = self.service_theme120 self.theme = self.service_theme
85 else:121 else:
86 self.theme = self.global_theme122 self.theme = self.global_theme
87 if self.theme is not self.renderer.theme_name:123 if self.theme != self.renderer.theme_name:
88 log.debug(u'theme is now %s', self.theme)124 log.debug(u'theme is now %s', self.theme)
89 self.themedata = self.theme_manager.getThemeData(self.theme)125 self.themedata = self.theme_manager.getThemeData(self.theme)
90 self.calculate_default(self.screen_list[self.current_display][u'size'])126 self.calculate_default(self.screen_list[self.current_display][u'size'])
@@ -92,7 +128,13 @@
92 self.build_text_rectangle(self.themedata)128 self.build_text_rectangle(self.themedata)
93129
94 def build_text_rectangle(self, theme):130 def build_text_rectangle(self, theme):
95 log.debug(u'build_text_rectangle ')131 """
132 Builds a text block using the settings in ``theme``.
133
134 ``theme``
135 The theme to build a text block for.
136 """
137 log.debug(u'build_text_rectangle')
96 main_rect = None138 main_rect = None
97 footer_rect = None139 footer_rect = None
98 if theme.font_main_override == False:140 if theme.font_main_override == False:
@@ -108,31 +150,52 @@
108 self.renderer.set_text_rectangle(main_rect,footer_rect)150 self.renderer.set_text_rectangle(main_rect,footer_rect)
109151
110 def generate_preview(self, themedata):152 def generate_preview(self, themedata):
153 """
154 Generate a preview of a theme.
155
156 ``themedata``
157 The theme to generated a preview for.
158 """
111 log.debug(u'generate preview')159 log.debug(u'generate preview')
112 self.calculate_default(QtCore.QSize(1024, 768))160 self.calculate_default(QtCore.QSize(1024, 768))
113 self.renderer.set_theme(themedata)161 self.renderer.set_theme(themedata)
114 self.build_text_rectangle(themedata)162 self.build_text_rectangle(themedata)
115 self.renderer.set_frame_dest(self.width, self.height, True)163 self.renderer.set_frame_dest(self.width, self.height, True)
116 lines = []164 verse = []
117 lines.append(u'Amazing Grace!')165 verse.append(u'Amazing Grace!')
118 lines.append(u'How sweet the sound')166 verse.append(u'How sweet the sound')
119 lines.append(u'To save a wretch like me;')167 verse.append(u'To save a wretch like me;')
120 lines.append(u'I once was lost but now am found,')168 verse.append(u'I once was lost but now am found,')
121 lines.append(u'Was blind, but now I see.')169 verse.append(u'Was blind, but now I see.')
122 lines1 = []170 footer = []
123 lines1.append(u'Amazing Grace (John Newton)' )171 footer.append(u'Amazing Grace (John Newton)' )
124 lines1.append(u'Public Domain')172 footer.append(u'Public Domain')
125 lines1.append(u'CCLI xxx')173 footer.append(u'CCLI xxx')
126 return self.renderer.generate_frame_from_lines(lines, lines1)174 return self.renderer.generate_frame_from_lines(verse, footer)
127175
128 def format_slide(self, words):176 def format_slide(self, words):
177 """
178 Calculate how much text can fid on a slide.
179
180 ``words``
181 The words to go on the slides.
182 """
129 log.debug(u'format slide')183 log.debug(u'format slide')
130 self.calculate_default(self.screen_list[self.current_display][u'size'])184 self.calculate_default(self.screen_list[self.current_display][u'size'])
131 self.build_text_rectangle(self.themedata)185 self.build_text_rectangle(self.themedata)
132 self.renderer.set_frame_dest(self.width, self.height)186 self.renderer.set_frame_dest(self.width, self.height)
133 return self.renderer.format_slide(words, False)187 return self.renderer.format_slide(words, False)
134188
135 def generate_slide(self,main_text, footer_text):189 def generate_slide(self, main_text, footer_text):
190 """
191 Generate the actual slide image.
192
193 ``main_text``
194 The text for the main area of the slide.
195
196 ``footer_text``
197 The text for the slide footer.
198 """
136 log.debug(u'generate slide')199 log.debug(u'generate slide')
137 self.calculate_default(self.screen_list[self.current_display][u'size'])200 self.calculate_default(self.screen_list[self.current_display][u'size'])
138 self.build_text_rectangle(self.themedata)201 self.build_text_rectangle(self.themedata)
@@ -140,6 +203,12 @@
140 return self.renderer.generate_frame_from_lines(main_text, footer_text)203 return self.renderer.generate_frame_from_lines(main_text, footer_text)
141204
142 def resize_image(self, image):205 def resize_image(self, image):
206 """
207 Resize an image to fit on the current screen.
208
209 ``image``
210 The image to resize.
211 """
143 preview = QtGui.QImage(image)212 preview = QtGui.QImage(image)
144 w = self.width213 w = self.width
145 h = self.height214 h = self.height
@@ -154,13 +223,19 @@
154 return newImage223 return newImage
155224
156 def calculate_default(self, screen):225 def calculate_default(self, screen):
157 log.debug(u'calculate default %s' , screen)226 """
227 Calculate the default dimentions of the screen.
228
229 ``screen``
230 The QWidget instance of the screen.
231 """
232 log.debug(u'calculate default %s', screen)
158 if self.current_display == 0:233 if self.current_display == 0:
159 self.width = 1024234 self.width = 1024
160 self.height = 768235 self.height = 768
161 else:236 else:
162 self.width = screen.width()237 self.width = screen.width()
163 self.height = screen.height()238 self.height = screen.height()
164 log.debug(u'calculate default %d,%d' , self.width, self.height)239 log.debug(u'calculate default %d, %d', self.width, self.height)
165 # 90% is start of footer240 # 90% is start of footer
166 self.footer_start = int(self.height * 0.90)241 self.footer_start = int(self.height * 0.90)
167242
=== modified file 'openlp/core/lib/serviceitem.py'
--- openlp/core/lib/serviceitem.py 2009-06-20 19:11:17 +0000
+++ openlp/core/lib/serviceitem.py 2009-07-10 13:16:15 +0000
@@ -20,10 +20,12 @@
20import logging20import logging
21import os21import os
22import time22import time
23
24from PyQt4 import QtCore, QtGui
25
23from openlp.core.lib import buildIcon26from openlp.core.lib import buildIcon
24from PyQt4 import QtCore, QtGui
2527
26class ServiceItem():28class ServiceItem(object):
27 """29 """
28 The service item is a base class for the plugins to use to interact with30 The service item is a base class for the plugins to use to interact with
29 the service manager, the slide controller, and the projection screen31 the service manager, the slide controller, and the projection screen
@@ -35,7 +37,10 @@
3537
36 def __init__(self, hostplugin=None):38 def __init__(self, hostplugin=None):
37 """39 """
38 Init Method40 Set up the service item.
41
42 ``hostplugin``
43 The plugin that this service item belongs to.
39 """44 """
40 self.plugin = hostplugin45 self.plugin = hostplugin
41 if hostplugin is not None:46 if hostplugin is not None:
@@ -56,6 +61,14 @@
56 self.service_frames = []61 self.service_frames = []
5762
58 def addIcon(self, icon):63 def addIcon(self, icon):
64 """
65 Add an icon to the service item. This is used when displaying the
66 service item in the service manager.
67
68 ``icon``
69 An instance of QIcon or a string to an icon in the resource or on
70 disk.
71 """
59 self.icon = icon72 self.icon = icon
60 self.iconic_representation = buildIcon(icon)73 self.iconic_representation = buildIcon(icon)
6174
@@ -89,27 +102,63 @@
89 else:102 else:
90 log.error(u'Invalid value renderer :%s' % self.service_item_type)103 log.error(u'Invalid value renderer :%s' % self.service_item_type)
91104
92 def add_from_image(self, path, frame_title, image):105 def add_from_image(self, path, frame_title, image):
106 """
107 Add an image slide to the service item.
108
109 ``path``
110 The directory in which the image file is located.
111
112 ``frame_title``
113 A title for the slide in the service item.
114
115 ``image``
116 The actual image file name.
117 """
93 self.service_item_type = u'image'118 self.service_item_type = u'image'
94 self.service_item_path = path119 self.service_item_path = path
95 self.service_frames.append({u'title': frame_title, u'image': image})120 self.service_frames.append({u'title': frame_title, u'image': image})
96121
97 def add_from_text(self, frame_title, raw_slide):122 def add_from_text(self, frame_title, raw_slide):
123 """
124 Add a text slide to the service item.
125
126 ``frame_title``
127 The title of the slide in the service item.
128
129 ``raw_slide``
130 The raw text of the slide.
131 """
98 self.service_item_type = u'text'132 self.service_item_type = u'text'
99 frame_title = frame_title.split(u'\n')[0]133 frame_title = frame_title.split(u'\n')[0]
100 self.service_frames.append({u'title': frame_title, u'raw_slide': raw_slide})134 self.service_frames.append({u'title': frame_title, u'raw_slide': raw_slide})
101135
102 def add_from_command(self, frame_title, command):136 def add_from_command(self, frame_title, command):
137 """
138 Add a slide from a command.
139
140 ``frame_title``
141 The title of the slide in the service item.
142
143 ``command``
144 The command of/for the slide.
145 """
103 self.service_item_type = u'command'146 self.service_item_type = u'command'
104 self.service_frames.append({u'title': frame_title, u'command': command})147 self.service_frames.append({u'title': frame_title, u'command': command})
105148
106 def get_oos_repr(self):149 def get_oos_repr(self):
107 """150 """
108 This method returns some text which can be saved into the OOS151 This method returns some text which can be saved into the OOS
109 file to represent this item152 file to represent this item.
110 """153 """
111 oos_header = {u'plugin': self.shortname,u'theme':self.theme, u'title':self.title,154 oos_header = {
112 u'icon':self.icon, u'footer':self.raw_footer, u'type':self.service_item_type}155 u'plugin': self.shortname,
156 u'theme':self.theme,
157 u'title':self.title,
158 u'icon':self.icon,
159 u'footer':self.raw_footer,
160 u'type':self.service_item_type
161 }
113 oos_data = []162 oos_data = []
114 if self.service_item_type == u'text':163 if self.service_item_type == u'text':
115 for slide in self.service_frames:164 for slide in self.service_frames:
@@ -124,8 +173,14 @@
124173
125 def set_from_oos(self, serviceitem, path=None):174 def set_from_oos(self, serviceitem, path=None):
126 """175 """
127 This method takes some oos list (passed from the ServiceManager)176 This method takes a service item from a saved service file (passed
128 and extracts the data actually required177 from the ServiceManager) and extracts the data actually required.
178
179 ``serviceitem``
180 The item to extract data from.
181
182 ``path``
183 Defaults to *None*. Any path data, usually for images.
129 """184 """
130 #print "sfs", serviceitem185 #print "sfs", serviceitem
131 header = serviceitem[u'serviceitem'][u'header']186 header = serviceitem[u'serviceitem'][u'header']
132187
=== modified file 'openlp/core/lib/settingstab.py'
--- openlp/core/lib/settingstab.py 2009-06-05 18:53:50 +0000
+++ openlp/core/lib/settingstab.py 2009-07-10 13:16:15 +0000
@@ -23,11 +23,20 @@
2323
24class SettingsTab(QtGui.QWidget):24class SettingsTab(QtGui.QWidget):
25 """25 """
26 SettingsTab is a helper widget for plugins to define Tabs for the settings dialog.26 SettingsTab is a helper widget for plugins to define Tabs for the settings
27 dialog.
27 """28 """
28 def __init__(self, title=None, section=None):29 def __init__(self, title=None, section=None):
29 """30 """
30 Constructor to create the Steetings tab item.31 Constructor to create the Settings tab item.
32
33 ``title``
34 Defaults to *None*. The title of the tab, which is usually
35 displayed on the tab.
36
37 ``section``
38 Defaults to *None*. This is the section in the configuration file
39 to write to when the ``save`` method is called.
31 """40 """
32 QtGui.QWidget.__init__(self)41 QtGui.QWidget.__init__(self)
33 self.tabTitle = title42 self.tabTitle = title
@@ -43,6 +52,9 @@
43 def setTitle(self, title):52 def setTitle(self, title):
44 """53 """
45 Set the title of the tab.54 Set the title of the tab.
55
56 ``title``
57 The title of the tab, which is usually displayed on the tab.
46 """58 """
47 self.tabTitle = title59 self.tabTitle = title
4860
4961
=== modified file 'openlp/core/lib/songxmlhandler.py'
--- openlp/core/lib/songxmlhandler.py 2009-06-21 16:26:33 +0000
+++ openlp/core/lib/songxmlhandler.py 2009-07-10 13:16:15 +0000
@@ -30,21 +30,34 @@
3030
31"""31"""
32import logging32import logging
33from xml.dom.minidom import Document33from xml.dom.minidom import Document
34from xml.etree.ElementTree import ElementTree, XML, dump34from xml.etree.ElementTree import ElementTree, XML, dump
3535
36class SongXMLBuilder():36class SongXMLBuilder():
37 """
38 This class builds the XML used to describe songs.
39 """
37 def __init__(self):40 def __init__(self):
41 """
42 Set up the song builder.
43 """
38 # Create the minidom document44 # Create the minidom document
39 self.song_xml = Document()45 self.song_xml = Document()
4046
41 def new_document(self):47 def new_document(self):
48 """
49 Create a new song XML document.
50 """
42 # Create the <song> base element51 # Create the <song> base element
43 self.song = self.song_xml.createElement(u'song')52 self.song = self.song_xml.createElement(u'song')
44 self.song_xml.appendChild(self.song)53 self.song_xml.appendChild(self.song)
45 self.song.setAttribute(u'version', u'1.0')54 self.song.setAttribute(u'version', u'1.0')
4655
47 def add_lyrics_to_song(self):56 def add_lyrics_to_song(self):
57 """
58 Set up and add a ``<lyrics>`` tag which contains the lyrics of the
59 song.
60 """
48 # Create the main <lyrics> element61 # Create the main <lyrics> element
49 self.lyrics = self.song_xml.createElement(u'lyrics')62 self.lyrics = self.song_xml.createElement(u'lyrics')
50 self.lyrics.setAttribute(u'language', u'en')63 self.lyrics.setAttribute(u'language', u'en')
@@ -52,50 +65,72 @@
5265
53 def add_verse_to_lyrics(self, type, number, content):66 def add_verse_to_lyrics(self, type, number, content):
54 """67 """
55 type - type of verse (Chorus, Verse , Bridge, Custom etc68 Add a verse to the ``<lyrics>`` tag.
56 number - number of item eg verse 169
57 content - the text to be stored70 ``type``
71 A string denoting the type of verse. Possible values are "Chorus",
72 "Verse", "Bridge", and "Custom".
73
74 ``number``
75 An integer denoting the number of the item, for example: verse 1.
76
77 ``content``
78 The actual text of the verse to be stored.
58 """79 """
59 verse = self.song_xml.createElement(u'verse')80 verse = self.song_xml.createElement(u'verse')
60 verse.setAttribute(u'type', type)81 verse.setAttribute(u'type', type)
61 verse.setAttribute(u'label', number)82 verse.setAttribute(u'label', number)
62 self.lyrics.appendChild(verse)83 self.lyrics.appendChild(verse)
6384 # add data as a CDATA section to protect the XML from special chars
64 # add data as a CDATA section
65 cds = self.song_xml.createCDATASection(content)85 cds = self.song_xml.createCDATASection(content)
66 verse.appendChild(cds)86 verse.appendChild(cds)
6787
68 def dump_xml(self):88 def dump_xml(self):
69 # Debugging aid to see what we have89 """
90 Debugging aid to dump XML so that we can see what we have.
91 """
70 print self.song_xml.toprettyxml(indent=u' ')92 print self.song_xml.toprettyxml(indent=u' ')
7193
72 def extract_xml(self):94 def extract_xml(self):
73 # Print our newly created XML95 """
96 Extract our newly created XML song.
97 """
74 return self.song_xml.toxml(u'utf-8')98 return self.song_xml.toxml(u'utf-8')
7599
76class SongXMLParser():100class SongXMLParser():
101 """
102 A class to read in and parse a song's XML.
103 """
77 global log104 global log
78 log = logging.getLogger(u'SongXMLParser')105 log = logging.getLogger(u'SongXMLParser')
79 log.info(u'SongXMLParser Loaded')106 log.info(u'SongXMLParser Loaded')
80107
81 def __init__(self, xml):108 def __init__(self, xml):
82 #print xml109 """
110 Set up our song XML parser.
111
112 ``xml``
113 The XML of the song to be parsed.
114 """
83 try:115 try:
84 self.song_xml = ElementTree(element=XML(xml))116 self.song_xml = ElementTree(element=XML(xml))
85 except:117 except:
86 #print "invalid xml ", xml118 log.debug(u'Invalid xml %s', xml)
87 log.debug(u'invalid xml %s', xml)
88119
89 def get_verses(self):120 def get_verses(self):
90 #return a list of verse's and attributes121 """
91 iter=self.song_xml.getiterator()122 Iterates through the verses in the XML and returns a list of verses
123 and their attributes.
124 """
125 iter = self.song_xml.getiterator()
92 verse_list = []126 verse_list = []
93 for element in iter:127 for element in iter:
94 #print element.tag, element.attrib, element.text
95 if element.tag == u'verse':128 if element.tag == u'verse':
96 verse_list.append([element.attrib, element.text])129 verse_list.append([element.attrib, element.text])
97 return verse_list130 return verse_list
98131
99 def dump_xml(self):132 def dump_xml(self):
100 # Debugging aid to see what we have133 """
134 Debugging aid to dump XML so that we can see what we have.
135 """
101 print dump(self.song_xml)136 print dump(self.song_xml)
102137
=== modified file 'openlp/core/lib/themexmlhandler.py'
--- openlp/core/lib/themexmlhandler.py 2009-07-08 06:55:08 +0000
+++ openlp/core/lib/themexmlhandler.py 2009-07-10 13:16:15 +0000
@@ -345,5 +345,5 @@
345 s = u''345 s = u''
346 for k in dir(self):346 for k in dir(self):
347 if k[0:1] != u'_':347 if k[0:1] != u'_':
348 s += u'%30s : %s\n' %(k, getattr(self, k))348 s += u'%30s: %s\n' %(k, getattr(self, k))
349 return s349 return s