Eduardo Mucelli Rezende Oliveira has proposed merging lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/Quote into lp:cairo-dock-plug-ins-extras.
Requested reviews: Cairo-Dock Team (cairo-dock-team) Added the applet Quote, quotes of the day for you -- https://code.launchpad.net/~eduardo-mucelli/cairo-dock-plug-ins-extras/Quote/+merge/41414 Your team Cairo-Dock Team is requested to review the proposed merge of lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/Quote into lp:cairo-dock-plug-ins-extras.
=== added directory 'Quote' === added file 'Quote/Quote' --- Quote/Quote 1970-01-01 00:00:00 +0000 +++ Quote/Quote 2010-11-21 15:39:53 +0000 @@ -0,0 +1,156 @@ +#!/usr/bin/python + +# This is a part of the external Quote applet for Cairo-Dock +# +# Author: Eduardo Mucelli Rezende Oliveira +# E-mail: [email protected] or [email protected] +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# This applet provides a "Quote of the day" feature + +import gobject, dbus, os, urllib, ConfigParser, itertools +from dbus.mainloop.glib import DBusGMainLoop +from dbus import glib +from sgmllib import SGMLParser +from urllib import FancyURLopener +from util import log + +DBusGMainLoop(set_as_default=True) + +class AgentOpener(FancyURLopener): + """Masked user-agent otherwise the access would be forbidden""" + version = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11' + +class TranslatorParser(SGMLParser): + + def reset(self): + SGMLParser.reset(self) + self.quote = [] + self.author = [] + self.inside_dt_a_element = False # indica se o parser esta dentro de <dt><a></a></dt> tag + self.inside_dt_element = False # indica se o parser esta dentro de <dt></dt> tag + + self.inside_dd_element = False # indica se o parser esta dentro de <dd></dd> tag + self.inside_dd_b_element = False # indica se o parser esta dentro de <dt><b><b></dt> tag + self.inside_dd_b_a_element = False # indica se o parser esta dentro de <dt><b><a><a><b></dt> tag + + def start_dt(self, attrs): + for name, value in attrs: + if name == "class" and value == "quote": # <dt class="quote">...</dt> + self.inside_dt_element = True + + def end_dt(self): + self.inside_dt_element = False + + def start_dd(self, attrs): + for name, value in attrs: + if name == "class" and value == "author": # <dd class="author">...</dd> + self.inside_dd_element = True + + def end_dd(self): + self.inside_dd_element = False + + def start_b(self, attrs): + if self.inside_dd_element: + self.inside_dd_b_element = True + + def end_b(self): + self.inside_dd_b_element = False + + def start_a(self, attrs): + if self.inside_dt_element: + self.inside_dt_a_element = True # <dt class="quote"><a>Quote</a></dt> + if self.inside_dd_b_element: + self.inside_dd_b_a_element = True # <dd class="author"><b><a>Quote</a></b></dd> + + def end_a(self): + self.inside_dt_a_element = False + self.inside_dd_b_a_element = False + + def handle_data(self, text): + if self.inside_dt_a_element: # estamos dentro de <dt><a>...</a></dt> + self.quote.append(text) + if self.inside_dd_b_a_element: # estamos dentro de <dd><b><a>...</a></b></dd> + self.author.append(text) + + def parse(self, page): + self.feed(page) # feed the parser with the page's html + self.close() + +class Interface: + + def __init__(self): + self.author = [] + self.quote = [] + + def fetch(self): + parser = TranslatorParser() # create the parser + opener = AgentOpener() # opens the web connection with masked user-agent + url = "http://www.quotationspage.com/qotd.html" + try: + page = opener.open(url) # get the HTML + except IOError: + print ("Problem to open the remote quotation site") + else: + parser.parse(page.read()) # feed the parser to get the specific content: translated text + page.close() # lets close the page connection + self.quote = parser.quote + self.author = parser.author + return self.quote, self.author + +class Quote: + + def start(self): + bus = dbus.SessionBus() + applet_name = os.path.basename(os.path.abspath(".")) # name of the applet must the same as the folder + applet_path = "/org/cairodock/CairoDock/%s" % applet_name # path where our object is stored on the bus + applet_object = bus.get_object("org.cairodock.CairoDock", applet_path) + icon = dbus.Interface(applet_object, "org.cairodock.CairoDock.applet") + + applet = Applet(icon) + applet.start() + + loop = gobject.MainLoop() + loop.run() + sys.exit(0) + +class Applet: + + def __init__(self, icon): + self.icon = icon + self.authors = None + self.quotes = None + self.dialog_active_time = 10 # time in seconds that the dialog window will be active + + def start(self): + log ("Applet started") + self.connect_to_callbacks() + self.get_quotes_from_web() + + def connect_to_callbacks(self): # when reiceves the signal named as 1st parameter ... + self.icon.connect_to_signal("on_click", self.action_on_click) # ... chama a funcao callback que eh o segundo parametro + + def get_quotes_from_web(self): + interface = Interface() + quote, author = interface.fetch() # N-esima quote refere-se ao N-esimo autor. "quote[x] ~ author[x]" + self.quotes = itertools.cycle(quote) + self.authors = itertools.cycle(author) + + def action_on_click(self, param): + self.show_quote() + + def show_quote(self): + quotation = "\"%s\" ~ %s" % (self.quotes.next(), self.authors.next()) + self.icon.ShowDialog(quotation, self.dialog_active_time) + +if __name__ == '__main__': + Quote().start() === added file 'Quote/Quote.conf' --- Quote/Quote.conf 1970-01-01 00:00:00 +0000 +++ Quote/Quote.conf 2010-11-21 15:39:53 +0000 @@ -0,0 +1,91 @@ +#!en;0.0.1 + +#[gtk-about] +[Icon] +#j+[0;128] Desired icon size for this applet +#{Set to 0 to use the default applet size} +icon size = 0;0 + +#s Name of the icon as it will appear in its label in the dock : +name = Quote + +#S+ Image's filename : +#{Let empty to use the default one.} +icon = + +#d Name of the dock it belongs to: +dock name = + +order= + +#F[Applet's Handbook] +frame_hand= +#A +handbook=Quote + +#[gtk-convert] +[Desklet] + +#j+[48;512] Desklet's dimension (width x height) : +#{Depending on your WindowManager, you can resize it with ALT + middle_click or ALT + left_click for exemple.} +size = 164;96 + +#i[-2048;2048] Desklet's position (x ; y) : +#{Depending on your WindowManager, you can move it with ALT + left_click} +x position=0 +#i[-2048;2048] ... +y position=0 + +#b Is detached from the dock ? +initially detached=false +#l[Normal;Keep above;Keep below;On Widget Layer;Reserve space] Accessibility : +#{for CompizFusion's "widget layer", set behaviour in Compiz to: (class=Cairo-dock & type=utility)} +accessibility=0 +#b Should be visible on all desktops ? +sticky=true + +#b Lock position ? +#{If locked, the desklet can't be moved by simply dragging it with the left mouse button. Of course you can still move it with ALT + left_click.} +locked = false + +#I[-180;180] Rotation : +#{in degrees.} +rotation = 0 + +use size= + +#F[Decorations;gtk-orientation-portrait] +frame_deco= + +#o+ Choose a decoration theme for this desklet : +#{Choose the 'personnal' one to define your own decorations below.} +decorations = default + +#v +sep_deco = + +#S+ Background image : +#{It's an image that will be displayed below the drawings, like a frame for exemple. Let empty to not use any.} +bg desklet = +#e+[0;1] Background tansparency : +bg alpha = 1 +#i+[0;256] Left offset : +#{in pixels. Use this to adjust the left position of the drawings.} +left offset = 0 +#i+[0;256] Top offset : +#{in pixels. Use this to adjust the top position of the drawings.} +top offset = 0 +#i+[0;256] Right offset : +#{in pixels. Use this to adjust the right position of the drawings.} +right offset = 0 +#i+[0;256] Bottom offset : +#{in pixels. Use this to adjust the bottom position of the drawings.} +bottom offset = 0 +#S+ Foreground image : +#{It's an image that will be displayed above the drawings, like a reflect for exemple. Let empty to not use any.} +fg desklet = +#e+[0;1] Foreground tansparency : +fg alpha = 1 + +#[gtk-preferences] +[Configuration] === added file 'Quote/auto-load.conf' --- Quote/auto-load.conf 1970-01-01 00:00:00 +0000 +++ Quote/auto-load.conf 2010-11-21 15:39:53 +0000 @@ -0,0 +1,13 @@ +[Register] + +# Author of the applet +author = Eduardo Mucelli Rezende Oliveira + +# A short description of the applet and how to use it. +description = This applet provides the so wonderful "Quotes of the day" feature. + +# Category of the applet : 2 = files, 3 = internet, 4 = Desktop, 5 = accessory, 6 = system, 7 = fun +category = 5 + +# Version of the applet; change it everytime you change something in the config file. Don't forget to update the version both in this file and in the config file. +version = 0.0.1 === added file 'Quote/icon' Binary files Quote/icon 1970-01-01 00:00:00 +0000 and Quote/icon 2010-11-21 15:39:53 +0000 differ === added file 'Quote/preview.png' Binary files Quote/preview.png 1970-01-01 00:00:00 +0000 and Quote/preview.png 2010-11-21 15:39:53 +0000 differ === added file 'Quote/util.py' --- Quote/util.py 1970-01-01 00:00:00 +0000 +++ Quote/util.py 2010-11-21 15:39:53 +0000 @@ -0,0 +1,9 @@ +#!/usr/bin/python + +# This is a part of the external Quote applet for Cairo-Dock +# +# Author: Eduardo Mucelli Rezende Oliveira +# E-mail: [email protected] or [email protected] + +def log (string): + print "[+] Quote: %s" % string
_______________________________________________ Mailing list: https://launchpad.net/~cairo-dock-team Post to : [email protected] Unsubscribe : https://launchpad.net/~cairo-dock-team More help : https://help.launchpad.net/ListHelp

