Skip to content

Commit

Permalink
Some refactoring. Might need to refactor more later.
Browse files Browse the repository at this point in the history
  • Loading branch information
shuhaowu authored and marianoguerra committed Sep 7, 2011
1 parent fa6220d commit c282c7f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
19 changes: 16 additions & 3 deletions emesene/gui/gtkui/ExtensionList.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ def on_cursor_changed(self, list_view, type_, extra_button=None):
'''called when a row is selected'''
if extra_button is None:
extra_button = self.no_button
model, iter_ = list_view.get_selection().get_selected()
if iter_ is not None:
value = model.get_value(iter_, 2)

value = self.get_selected_name(list_view)
if value is not None:
if value in self.download_list.get(type_, []):
self.download_item = value
self.download_button.show()
Expand All @@ -209,6 +209,19 @@ def on_cursor_changed(self, list_view, type_, extra_button=None):
self.download_button.hide()
extra_button.show()

def get_selected_name(self, list_view=None):
'''Gets the current selected name in the list view.'''
if list_view is None: # Q: is this really necessary, same goes for L197's list_view
# TypeError: on_cursor_changed() takes at most 2 arguments (3 given) <-- where is this even coming from..
list_view = self.list_view

model, iter = list_view.get_selection().get_selected()
if iter is not None:
name = model.get_value(iter, 2)
return name
else:
return None # Q: should something be done here?

def on_change_source(self, combobox):
'''called when the source is changed'''
self.thc_cur_name = combobox.get_active_text()
Expand Down
25 changes: 11 additions & 14 deletions emesene/gui/gtkui/PluginWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import e3

from pluginmanager import get_pluginmanager
from ExtensionList import ExtensionDownloadList
from ExtensionList import ExtensionDownloadList # uh.. is this safe?

class PluginMainVBox(ExtensionDownloadList):
def __init__(self, session, init_path):
Expand Down Expand Up @@ -69,45 +69,42 @@ def on_toggled(self, widget, path, model, type_):

def on_cursor_changed(self, list_view, type_='plugin'):
'''called when a row is selected'''

ExtensionDownloadList.on_cursor_changed(self, list_view, type_, self.config_button)

def on_start(self, *args):
'''start the selected plugin'''
sel = self.list_view.get_selection()
model, iter = sel.get_selected()
if iter is not None:
name = model.get_value(iter, 2)
name = self.get_selected_name()
if name is not None:
pluginmanager = get_pluginmanager()
pluginmanager.plugin_start(name, self.session)

if name not in self.session.config.l_active_plugins:
self.session.config.l_active_plugins.append(name)

model, iter = self.list_view.get_selection().get_selected()
model.set_value(iter, 0, bool(pluginmanager.plugin_is_active(name)))
self.on_cursor_changed(self.list_view)

def on_stop(self, *args):
'''stop the selected plugin'''
sel = self.list_view.get_selection()
model, iter = sel.get_selected()
if iter is not None:
name = model.get_value(iter, 2)
name = self.get_selected_name()
if name is not None:
pluginmanager = get_pluginmanager()
pluginmanager.plugin_stop(name)

if name in self.session.config.l_active_plugins:
self.session.config.l_active_plugins.remove(name)

model, iter = self.list_view.get_selection().get_selected()
model.set_value(iter, 0, pluginmanager.plugin_is_active(name))

self.on_cursor_changed(self.list_view)

def on_config(self, *args):
'''Called when user hits the Preferences button'''

sel = self.list_view.get_selection()
model, iter = sel.get_selected()
if iter is not None:
name = model.get_value(iter, 2)
name = self.get_selected_name()
if name is not None:
pluginmanager = get_pluginmanager()

if pluginmanager.plugin_is_active(name):
Expand Down

0 comments on commit c282c7f

Please sign in to comment.