[conduit/config-google: 17/20] Cnverted YouTube and Google Documents to new config
- From: Alexandre Rosenfeld <arosenfeld src gnome org>
- To: svn-commits-list gnome org
- Subject: [conduit/config-google: 17/20] Cnverted YouTube and Google Documents to new config
- Date: Sun, 17 May 2009 00:04:10 -0400 (EDT)
commit aefc44f649884ee69889d0bc9a2814a1cc276162
Author: Alexandre Rosenfeld <airmind gmail com>
Date: Fri May 15 08:57:01 2009 -0300
Cnverted YouTube and Google Documents to new config
Finished the YouTube and Google Documents to the new config
system.
Added disable_check and disabled_value to ConfigItems.
It allows a config item to be enabled and disabled by
a checkbox in the config's label, while returning a specific
value for when it is disabled. It is used in the YouTube
configuration.
---
conduit/gtkui/ConfigItems.py | 46 +++++++---
conduit/modules/GoogleModule/GoogleModule.py | 136 +++++++-------------------
2 files changed, 70 insertions(+), 112 deletions(-)
diff --git a/conduit/gtkui/ConfigItems.py b/conduit/gtkui/ConfigItems.py
index 092d110..1c19887 100644
--- a/conduit/gtkui/ConfigItems.py
+++ b/conduit/gtkui/ConfigItems.py
@@ -109,13 +109,14 @@ class ItemBase(gobject.GObject):
def __init__(self, container, title, order, config_name = None,
config_type = None, choices = [], needs_label = True,
needs_space = False, initial_value = None, initial_value_callback = None,
- save_callback = None, fill = False, enabled = True):
+ save_callback = None, fill = False, enabled = True, disable_check = False,
+ disabled_value = None):
'''
Creates a config item.
- The parameters can customize how the item behaves:
- @param config_name: Used to save/load the configuration value from the
- dataprovider.
+ The parameters customize how the item behaves and/or looks:
+ @param config_name: Used in the configuration dict that saves and restores
+ this item value.
@param config_type: ``function(value)`` that converts the config value into
something a dataprovider will accept. This could be something
like int, str, etc., or a custom function.
@@ -134,7 +135,9 @@ class ItemBase(gobject.GObject):
to be aligned to the right in the window, set this to True.
@param enabled: If the widget can be edited by the user.
@param save_callback: A ``function(item, value)`` called when apply is
- selected and the value must be saved.
+ selected and the value must be saved.
+ @param disable_check: When true a checkmark to disable the item is added
+ @param disabled_value: A value returned when the item is disabled
'''
gobject.GObject.__init__(self)
@@ -143,7 +146,7 @@ class ItemBase(gobject.GObject):
self.read_only = False
# Properties that take in effect while the configuration is running
- # Access then using with their public attributes (as implemented
+ # Access then using their public attributes (as implemented
# with properties below), such as ``item.enabled = False``
self.__widget = None
self.__label = None
@@ -157,6 +160,7 @@ class ItemBase(gobject.GObject):
self.save_callback = save_callback
self.initial_value = initial_value
self.initial_value_callback = initial_value_callback
+ self.disabled_value = disabled_value
# These properties takes no effect while the configuration is running,
# unless the widgets are rebuilt (there are no provisions to make that
@@ -166,6 +170,7 @@ class ItemBase(gobject.GObject):
self.needs_label = needs_label
self.needs_space = needs_space
self.fill = fill
+ self.disable_check = disable_check
def _value_changed(self, *args):
'''
@@ -273,8 +278,14 @@ class ItemBase(gobject.GObject):
label_text = self.title
if label_text and not label_text.rstrip().endswith(':'):
label_text += ':'
- self.__label = gtk.Label(label_text)
- self.__label.set_alignment(0.0, 0.5)
+ if not self.disable_check:
+ self.__label = gtk.Label(label_text)
+ self.__label.set_alignment(0.0, 0.5)
+ else:
+ self.__label = gtk.CheckButton()
+ self.__label.set_label(self.title)
+ self.__label.set_active(self.__enabled)
+ self.__label.connect("toggled", lambda widget: self.set_enabled(widget.get_active()))
return self.__label
def set_label(self, label):
@@ -293,7 +304,7 @@ class ItemBase(gobject.GObject):
if not self.__widget:
self._build_widget()
if not self.__widget:
- raise Error("Widget could not be built")
+ raise Error("Widget could not be built")
self.reset()
return self.__widget
@@ -352,7 +363,14 @@ class ItemBase(gobject.GObject):
'''
if not self.config_name:
return None
- value = self.get_value()
+ #FIXME: This is a hack to allow the Youtube configuration to work.
+ # The way this should be implemented is adding a callback to this function
+ # or something similar. But because we already have too much callbacks
+ # this way is simpler
+ if (not self.enabled) and (self.disabled_value is not None):
+ value = self.disabled_value
+ else:
+ value = self.get_value()
try:
if self.config_type:
self.config_type(value)
@@ -371,7 +389,10 @@ class ItemBase(gobject.GObject):
def _set_enabled(self, enabled):
self.widget.set_sensitive(enabled)
if self.label:
- self.label.set_sensitive(enabled)
+ if self.disable_check:
+ self.__label.set_active(enabled)
+ else:
+ self.label.set_sensitive(enabled)
def set_enabled(self, enabled):
'''
@@ -398,7 +419,7 @@ class ItemBase(gobject.GObject):
def save_state(self):
'''
- Seve the current value as the initial value.
+ Save the current value as the initial value.
'''
value = self.get_value()
self.initial_value = value
@@ -442,6 +463,7 @@ class ConfigButton(ItemBase):
def __init__(self, *args, **kwargs):
action = kwargs.pop('action', None)
+ image = kwargs.pop('image', None)
ItemBase.__init__(self, *args, **kwargs)
self.callback = None
self.needs_space = kwargs.get('needs_space', False)
diff --git a/conduit/modules/GoogleModule/GoogleModule.py b/conduit/modules/GoogleModule/GoogleModule.py
index 0222a65..7519ac4 100644
--- a/conduit/modules/GoogleModule/GoogleModule.py
+++ b/conduit/modules/GoogleModule/GoogleModule.py
@@ -446,6 +446,7 @@ class GoogleCalendarTwoWay(_GoogleBase, DataProvider.TwoWay):
tree.get_widget("okBtn").set_sensitive(True)
dlg.window.set_cursor(oldCursor)
+ #TODO: Convert Calendar to new config
def configure(self, window):
import gtk
tree = Utils.dataprovider_glade_get_widget(
@@ -971,6 +972,7 @@ class ContactsTwoWay(_GoogleBase, DataProvider.TwoWay):
group_config = config.add_item("Group", "combo", config_name = "selectedGroup")
load_group_config = config.add_item("Load contact groups", "button", action = _load_groups)
+ #TODO Test Contacts new config and remove old config
def configure_(self, window):
"""
Configures the PicasaTwoWay
@@ -1094,9 +1096,11 @@ class DocumentsSink(_GoogleBase, DataProvider.DataSink):
DataProvider.DataSink.__init__(self)
_GoogleBase.__init__(self,gdata.docs.service.DocsService())
- self.documentFormat = 'ODT'
- self.spreadsheetFormat = 'ODS'
- self.presentationFormat = 'PPT'
+ self.update_configuration(
+ documentFormat = 'ODT',
+ spreadsheetFormat = 'ODS',
+ presentationFormat = 'PPT',
+ )
self._docs = {}
@@ -1288,52 +1292,18 @@ class DocumentsSink(_GoogleBase, DataProvider.DataSink):
self.service.Delete(gdoc.editLink)
return True
return False
-
- def configure(self, window):
- import gtk
-
- def make_combo(widget, docType, val, values):
- cb = widget.get_widget("%sCombo" % docType)
-
- #FIXME: Make these unsensitive when download works better
- cb.set_property("sensitive", False)
-
- store = gtk.ListStore(str)
- cell = gtk.CellRendererText()
-
- cb.set_model(store)
- cb.pack_start(cell, True)
- cb.add_attribute(cell, 'text', 0)
-
- for name in values:
- rowref = store.append( (name,) )
- if name == val:
- cb.set_active_iter(rowref)
-
-
- widget = Utils.dataprovider_glade_get_widget(
- __file__,
- "documents-config.glade",
- "GoogleDocumentsConfigDialog")
-
- #get a whole bunch of widgets
- username = widget.get_widget("username")
- password = widget.get_widget("password")
+
+ def config_setup(self, config):
+ username_config, password_config = _GoogleBase.config_setup(self, config)
- #preload the widgets
- username.set_text(self.username)
- password.set_text(self.password)
-
- #preload the combos
- for i in (("document", self.documentFormat,self.SUPPORTED_DOCUMENTS),("spreadsheet", self.spreadsheetFormat,self.SUPPORTED_SPREADSHEETS),("presentation",self.presentationFormat,self.SUPPORTED_PRESENTATIONS)):
- make_combo(widget, *i)
+ config.add_section("Downloaded document format")
- dlg = widget.get_widget("GoogleDocumentsConfigDialog")
- response = Utils.run_dialog (dlg, window)
- if response == True:
- self._set_username(username.get_text())
- self._set_password(password.get_text())
- dlg.destroy()
+ config.add_item("Documents", "combo", config_name = "documentFormat",
+ choices = self.SUPPORTED_DOCUMENTS)
+ config.add_item("Spreadsheets", "combo", config_name = "spreadsheetFormat",
+ choices = self.SUPPORTED_SPREADSHEETS)
+ config.add_item("Presentations", "combo", config_name = "presentationFormat",
+ choices = self.SUPPORTED_PRESENTATIONS)
class VideoUploadInfo:
"""
@@ -1390,52 +1360,26 @@ class YouTubeTwoWay(_GoogleBase, DataProvider.TwoWay):
_GoogleBase.__init__(self,youtube_service)
self.entries = None
- self.max_downloads = 0
- #filter type {0 = mostviewed, 1 = toprated, 2 = user upload, 3 = user favorites}
- self.filter_type = 0
-
- def configure(self, window):
- tree = Utils.dataprovider_glade_get_widget (
- __file__,
- "youtube-config.glade",
- "YouTubeTwoWayConfigDialog")
-
- dlg = tree.get_widget ("YouTubeTwoWayConfigDialog")
- mostviewedRb = tree.get_widget("mostviewed")
- topratedRb = tree.get_widget("toprated")
- uploadedbyRb = tree.get_widget("uploadedby")
- favoritesofRb = tree.get_widget("favoritesof")
- max_downloads = tree.get_widget("maxdownloads")
- username = tree.get_widget("username")
- password = tree.get_widget("password")
-
- if self.filter_type == 0:
- mostviewedRb.set_active(True)
- elif self.filter_type == 1:
- topratedRb.set_active(True)
- elif self.filter_type == 2:
- uploadedbyRb.set_active(True)
- else:
- favoritesofRb.set_active(True)
- max_downloads.set_value(self.max_downloads)
- username.set_text(self.username)
- password.set_text(self.password)
-
- response = Utils.run_dialog(dlg, window)
- if response == True:
- if mostviewedRb.get_active():
- self.filter_type = 0
- elif topratedRb.get_active():
- self.filter_type = 1
- elif uploadedbyRb.get_active():
- self.filter_type = 2
- else:
- self.filter_type = 3
- self.max_downloads = int(max_downloads.get_value())
- self.username = username.get_text()
- self.password = password.get_text()
+ self.update_configuration(
+ max_downloads = 0,
+ filter_type = 0, #(0 = mostviewed, 1 = toprated, 2 = user upload, 3 = user favorites)
+ )
- dlg.destroy()
+ def config_setup(self, config):
+ username_config, password_config = _GoogleBase.config_setup(self, config)
+
+ config.add_section("Download videos")
+ config.add_item(None, "radio", config_name = "filter_type",
+ choices = ((0, "Most viewed"),
+ (1, "Top rated"),
+ (2, "User uploaded"),
+ (3, "User favorites")))
+ config.add_item("Limit downloads", "spin",
+ config_name = "max_downloads",
+ minimum = 1,
+ disable_check = True,
+ disabled_value = 0,
+ enabled = self.max_downloads > 0)
def _get_video_info (self, id):
if self.entries.has_key(id):
@@ -1557,14 +1501,6 @@ class YouTubeTwoWay(_GoogleBase, DataProvider.TwoWay):
DataProvider.TwoWay.finish(self)
self.entries = None
- def get_configuration(self):
- return {
- "filter_type" : self.filter_type,
- "max_downloads" : self.max_downloads,
- "username" : self.username,
- "password" : self.password
- }
-
def get_UID(self):
return Utils.get_user_string()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]