Merge lp:~googol-deactivatedaccount/openlp/bug-900399 into lp:openlp

Proposed by Andreas Preikschat
Status: Superseded
Proposed branch: lp:~googol-deactivatedaccount/openlp/bug-900399
Merge into: lp:openlp
Diff against target: 251 lines (+34/-53)
6 files modified
openlp/core/lib/plugin.py (+16/-17)
openlp/core/lib/pluginmanager.py (+9/-27)
openlp/core/ui/mainwindow.py (+1/-1)
openlp/plugins/media/mediaplugin.py (+2/-2)
openlp/plugins/presentations/presentationplugin.py (+5/-5)
openlp/plugins/songs/forms/editsongform.py (+1/-1)
To merge this branch: bzr merge lp:~googol-deactivatedaccount/openlp/bug-900399
Reviewer Review Type Date Requested Status
Tim Bentley Pending
Review via email: mp+84989@code.launchpad.net

This proposal supersedes a proposal from 2011-12-07.

This proposal has been superseded by a proposal from 2011-12-08.

Commit message

bzr commit -m "-Fixed media item recreation (which caused bug #900399)
- Doc/method clean up
- Replaced continue with break
- Replaced method with one-liner"

Description of the change

Hello,

1) Fixed media item recreation (which caused bug #900399)
2) Doc/method clean up
3) Replaced continue with break (after "continuing" the first the x times follow where we continue, so we can just break the first time instead)
4) Replaced method with one-liner

To post a comment you must log in.
Revision history for this message
Tim Bentley (trb143) wrote : Posted in a previous version of this proposal

131 is an incorrect removal as when a plugin is disabled the settings dialog will fail as the value ins not defined.
Renaming fields is also iffy in a feature freeze. They are not a bug.
Code simplification is just Ok.

review: Needs Fixing
Revision history for this message
Andreas Preikschat (googol-deactivatedaccount) wrote :

> Renaming fields is also iffy in a feature freeze. They are not a bug.

I renamed getMediaManagerItem() and getSettingsTab() because their names caused this bug (line 190).

Revision history for this message
Raoul Snyman (raoul-snyman) wrote :

Andreas, my apologies, I didnt' explain myself well enough. What I meant by changing those "getMediaManagerItem" to "createMediaManagerItem" was not just renaming the methods, but actually doing the assignment inside the method, as opposed to externally.

i.e. instead of:

    if self.settings_tab_class:
        return self.settings_tab_class(parent, self.name, ...

do this:

    if settings_tab_class:
        self.settings_tab = self.settings_tab_class(parent, self.name, ...

Revision history for this message
Raoul Snyman (raoul-snyman) wrote :

Not that this is your problem, it's just some general code cleanup that should happen somewhere.

1823. By Andreas Preikschat

assign variables in methods instead of returning them

1824. By Andreas Preikschat

fixed plugins

Unmerged revisions

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 2011-10-26 20:11:15 +0000
3+++ openlp/core/lib/plugin.py 2011-12-08 17:57:24 +0000
4@@ -91,8 +91,9 @@
5 ``checkPreConditions()``
6 Provides the Plugin with a handle to check if it can be loaded.
7
8- ``getMediaManagerItem()``
9- Returns an instance of MediaManagerItem to be used in the Media Manager.
10+ ``createMediaManagerItem()``
11+ Creates a new instance of MediaManagerItem to be used in the Media
12+ Manager.
13
14 ``addImportMenuItem(import_menu)``
15 Add an item to the Import menu.
16@@ -100,8 +101,8 @@
17 ``addExportMenuItem(export_menu)``
18 Add an item to the Export menu.
19
20- ``getSettingsTab()``
21- Returns an instance of SettingsTabItem to be used in the Settings
22+ ``createSettingsTab()``
23+ Creates a new instance of SettingsTabItem to be used in the Settings
24 dialog.
25
26 ``addToMenu(menubar)``
27@@ -156,10 +157,10 @@
28 self.icon = None
29 self.media_item_class = media_item_class
30 self.settings_tab_class = settings_tab_class
31+ self.settings_tab = None
32+ self.mediaItem = None
33 self.weight = 0
34 self.status = PluginStatus.Inactive
35- # Set up logging
36- self.log = logging.getLogger(self.name)
37 self.previewController = plugin_helpers[u'preview']
38 self.liveController = plugin_helpers[u'live']
39 self.renderer = plugin_helpers[u'renderer']
40@@ -178,7 +179,7 @@
41 Provides the Plugin with a handle to check if it can be loaded.
42 Failing Preconditions does not stop a settings Tab being created
43
44- Returns True or False.
45+ Returns ``True`` or ``False``.
46 """
47 return True
48
49@@ -210,15 +211,14 @@
50 """
51 return self.status == PluginStatus.Active
52
53- def getMediaManagerItem(self):
54+ def createMediaManagerItem(self):
55 """
56 Construct a MediaManagerItem object with all the buttons and things
57- you need, and return it for integration into openlp.org.
58+ you need, and return it for integration into OpenLP.
59 """
60 if self.media_item_class:
61- return self.media_item_class(self.mediadock.media_dock, self,
62- self.icon)
63- return None
64+ self.mediaItem = self.media_item_class(self.mediadock.media_dock,
65+ self, self.icon)
66
67 def addImportMenuItem(self, importMenu):
68 """
69@@ -247,16 +247,15 @@
70 """
71 pass
72
73- def getSettingsTab(self, parent):
74+ def createSettingsTab(self, parent):
75 """
76- Create a tab for the settings window to display the configurable
77- options for this plugin to the user.
78+ Create a tab for the settings window to display the configurable options
79+ for this plugin to the user.
80 """
81 if self.settings_tab_class:
82- return self.settings_tab_class(parent, self.name,
83+ self.settings_tab = self.settings_tab_class(parent, self.name,
84 self.getString(StringContent.VisibleName)[u'title'],
85 self.icon_path)
86- return None
87
88 def addToMenu(self, menubar):
89 """
90
91=== modified file 'openlp/core/lib/pluginmanager.py'
92--- openlp/core/lib/pluginmanager.py 2011-12-03 12:51:40 +0000
93+++ openlp/core/lib/pluginmanager.py 2011-12-08 17:57:24 +0000
94@@ -90,7 +90,7 @@
95 thisdepth = len(path.split(os.sep))
96 if thisdepth - startdepth > 2:
97 # skip anything lower down
98- continue
99+ break
100 modulename = os.path.splitext(path)[0]
101 prefix = os.path.commonprefix([self.basepath, path])
102 # hack off the plugin base path
103@@ -113,7 +113,7 @@
104 plugin_objects.append(plugin)
105 except TypeError:
106 log.exception(u'Failed to load plugin %s', unicode(p))
107- plugins_list = sorted(plugin_objects, self.order_by_weight)
108+ plugins_list = sorted(plugin_objects, key=lambda plugin: plugin.weight)
109 for plugin in plugins_list:
110 if plugin.checkPreConditions():
111 log.debug(u'Plugin %s active', unicode(plugin.name))
112@@ -122,29 +122,13 @@
113 plugin.status = PluginStatus.Disabled
114 self.plugins.append(plugin)
115
116- def order_by_weight(self, x, y):
117- """
118- Sort two plugins and order them by their weight.
119-
120- ``x``
121- The first plugin.
122-
123- ``y``
124- The second plugin.
125- """
126- return cmp(x.weight, y.weight)
127-
128- def hook_media_manager(self, mediadock):
129- """
130- Loop through all the plugins. If a plugin has a valid media manager
131- item, add it to the media manager.
132-
133- ``mediatoolbox``
134- The Media Manager itself.
135+ def hook_media_manager(self):
136+ """
137+ Create the plugins' media manager items.
138 """
139 for plugin in self.plugins:
140 if plugin.status is not PluginStatus.Disabled:
141- plugin.mediaItem = plugin.getMediaManagerItem()
142+ plugin.createMediaManagerItem()
143
144 def hook_settings_tabs(self, settings_form=None):
145 """
146@@ -152,14 +136,12 @@
147 item, add it to the settings tab.
148 Tabs are set for all plugins not just Active ones
149
150- ``settingsform``
151+ ``settings_form``
152 Defaults to *None*. The settings form to add tabs to.
153 """
154 for plugin in self.plugins:
155 if plugin.status is not PluginStatus.Disabled:
156- plugin.settings_tab = plugin.getSettingsTab(settings_form)
157- else:
158- plugin.settings_tab = None
159+ plugin.createSettingsTab(settings_form)
160 settings_form.plugins = self.plugins
161
162 def hook_import_menu(self, import_menu):
163@@ -225,7 +207,7 @@
164
165 def get_plugin_by_name(self, name):
166 """
167- Return the plugin which has a name with value ``name``
168+ Return the plugin which has a name with value ``name``.
169 """
170 for plugin in self.plugins:
171 if plugin.name == name:
172
173=== modified file 'openlp/core/ui/mainwindow.py'
174--- openlp/core/ui/mainwindow.py 2011-12-05 21:40:56 +0000
175+++ openlp/core/ui/mainwindow.py 2011-12-08 17:57:24 +0000
176@@ -655,7 +655,7 @@
177 self.pluginManager.hook_settings_tabs(self.settingsForm)
178 # Find and insert media manager items
179 log.info(u'hook media')
180- self.pluginManager.hook_media_manager(self.mediaDockManager)
181+ self.pluginManager.hook_media_manager()
182 # Call the hook method to pull in import menus.
183 log.info(u'hook menus')
184 self.pluginManager.hook_import_menu(self.fileImportMenu)
185
186=== modified file 'openlp/plugins/media/mediaplugin.py'
187--- openlp/plugins/media/mediaplugin.py 2011-12-02 21:13:05 +0000
188+++ openlp/plugins/media/mediaplugin.py 2011-12-08 17:57:24 +0000
189@@ -52,12 +52,12 @@
190 for ext in self.video_extensions_list:
191 self.serviceManager.supportedSuffixes(ext[2:])
192
193- def getSettingsTab(self, parent):
194+ def createSettingsTab(self, parent):
195 """
196 Create the settings Tab
197 """
198 visible_name = self.getString(StringContent.VisibleName)
199- return MediaTab(parent, self.name, visible_name[u'title'],
200+ self.settings_tab = MediaTab(parent, self.name, visible_name[u'title'],
201 self.mediaController.mediaPlayers, self.icon_path)
202
203 def about(self):
204
205=== modified file 'openlp/plugins/presentations/presentationplugin.py'
206--- openlp/plugins/presentations/presentationplugin.py 2011-10-03 20:12:57 +0000
207+++ openlp/plugins/presentations/presentationplugin.py 2011-12-08 17:57:24 +0000
208@@ -57,13 +57,13 @@
209 self.icon_path = u':/plugins/plugin_presentations.png'
210 self.icon = build_icon(self.icon_path)
211
212- def getSettingsTab(self, parent):
213+ def createSettingsTab(self, parent):
214 """
215 Create the settings Tab
216 """
217 visible_name = self.getString(StringContent.VisibleName)
218- return PresentationTab(parent, self.name, visible_name[u'title'],
219- self.controllers, self.icon_path)
220+ self.settings_tab = PresentationTab(parent, self.name,
221+ visible_name[u'title'], self.controllers, self.icon_path)
222
223 def initialise(self):
224 """
225@@ -94,11 +94,11 @@
226 controller.kill()
227 Plugin.finalise(self)
228
229- def getMediaManagerItem(self):
230+ def createMediaManagerItem(self):
231 """
232 Create the Media Manager List
233 """
234- return PresentationMediaItem(
235+ self.mediaItem = PresentationMediaItem(
236 self.mediadock.media_dock, self, self.icon, self.controllers)
237
238 def registerControllers(self, controller):
239
240=== modified file 'openlp/plugins/songs/forms/editsongform.py'
241--- openlp/plugins/songs/forms/editsongform.py 2011-12-02 20:17:57 +0000
242+++ openlp/plugins/songs/forms/editsongform.py 2011-12-08 17:57:24 +0000
243@@ -181,7 +181,7 @@
244 plugin.status == PluginStatus.Active:
245 self.audioAddFromMediaButton.setVisible(True)
246 self.mediaForm.populateFiles(
247- plugin.getMediaManagerItem().getList(MediaType.Audio))
248+ plugin.mediaItem.getList(MediaType.Audio))
249 break
250
251 def newSong(self):