Home Forums Wiki Doc Install Extras Screenshots Source Code Projects Blog Users Groups Register
Glx-Dock / Cairo-Dock List of forums Technical discussions | Discussions techniques FaceBook Applet
The latest stable release is the *3.4.0* : How to install it here.
Note: We just switched from BZR to Git on Github! (only to host the code and your future pull requests)
Technical discussions | Discussions techniques

Subjects Author Language Messages Last message
[Locked] FaceBook Applet
Page : 1 2 3
jesuisbenjamin English 58 jesuisbenjamin [Read]
27 April 2011 à 16:57

jesuisbenjamin, Thursday 14 April 2011 à 15:15


Subscription date : 28 October 2009
Messages : 415
Hi there!

I'm working with Python to make a FaceBook applet. I have a configuration file from which i want to retrieve option settings for the applet. For this i use the get_config() process.
The odd thing is it is working for 6 options and not for the 7th i am adding, the "NoOptionError" is raised. Since my 7th option has an integer as a value rather than a boolean, i thought it was due to that, even though i use the keyfile.getint(). But changing the value to boolean or text does not make any difference. I don't understand why it doesn't want to pick up that one... Any idea?

Here is the section:

    def get_config(self,keyfile):
        print "...getting user-configuration"
        # get user configuration:
        ## which notifications should be added to counter?
        self.config['messages']     = keyfile.get('Configuration', 'messages')
        self.config['pokes']         = keyfile.get('Configuration', 'pokes')
        self.config['shares']         = keyfile.get('Configuration', 'shares')
        self.config['friends']         = keyfile.get('Configuration', 'friends')
        self.config['groups']         = keyfile.get('Configuration', 'groups')
        self.config['events']         = keyfile.get('Configuration', 'events')
        ## how often should notifications be checked?
        self.config['refresh']         = keyfile.getint('Configuration', 'refresh')
        print self.config


And here is the error:

...getting user-configuration
Traceback (most recent call last):
File "./faceBook", line 77, in <module>
Applet().run()
File "./faceBook", line 37, in __init__
CDApplet.__init__(self)
File "/usr/lib/python2.6/dist-packages/CDApplet.py", line 82, in __init__
self._get_config()
File "/usr/lib/python2.6/dist-packages/CDApplet.py", line 216, in _get_config
self.get_config(keyfile)
File "./faceBook", line 56, in get_config
self.config['refresh']         = keyfile.getint('Configuration', 'refresh')
File "/usr/lib/python2.6/ConfigParser.py", line 340, in getint
return self._get(section, int, option)
File "/usr/lib/python2.6/ConfigParser.py", line 337, in _get
return conv(self.get(section, option))
File "/usr/lib/python2.6/ConfigParser.py", line 321, in get
raise NoOptionError(option, section)
ConfigParser.NoOptionError: No option 'refresh' in section: 'Configuration'


Finally, the .conf file section with configuration settings:
[Configuration]

#k Shortkey
shortkey =

messages = true
pokes = false
shares = true
friends = false
groups = false
events = false
refresh = 1

matttbe, Thursday 14 April 2011 à 15:34


Subscription date : 24 January 2009
Messages : 12573
Hello,

Finally, the .conf file section with configuration settings:
Is it a preview of this file? => ~/.config/cairo-dock/current_theme/plug-ins/faceBook/faceBook.conf

PS: you can use a getboolean for other parameters.

jesuisbenjamin, Thursday 14 April 2011 à 15:38


Subscription date : 28 October 2009
Messages : 415
Ooooh nooo
The file i'm editing is in ~/.config/cairo-dock/third-party/faceBook/faceBook.conf

How's this working? I'm getting confused between what's in the /current_theme section and outside of it now...

matttbe, Thursday 14 April 2011 à 19:20


Subscription date : 24 January 2009
Messages : 12573


All .conf files in this directory (~/.config/cairo-dock/third-party/ but also /usr/share/cairo-dock/plug-ins/) are used to update conf files of the user. If you want to add some parameters, do it in .conf files of these folders and .conf files linked to your current theme will be automatically updated next time that you launch the dock.
Note that if you modify some parameters, you have to increase the version of your applet.

jesuisbenjamin, Thursday 14 April 2011 à 19:37


Subscription date : 28 October 2009
Messages : 415
Well...when i restart the dock (or even reboot my computer) it does not see the changes in the .conf in the /third-party/faceBook/ folder ...
I was guessing: the /third-party/faceBook/ folder's conf is the default conf and loads in the /current_theme/ fro then on.
Right now i am working with the /current_theme/ folder since changes occur when reloading Cairo, i'll copy it in the /third-party/ where it'll be safe.

The applet is moving forward (albeit slowly), but less slowly than the thesis i should be writing!

matttbe, Thursday 14 April 2011 à 19:41


Subscription date : 24 January 2009
Messages : 12573
The applet is moving forward (albeit slowly), but less slowly than the thesis i should be writing!


Well...when i restart the dock (or even reboot my computer) it does not see the changes in the .conf in the /third-party/faceBook/ folder ...
No, you've to edit this .conf file and the .conf file in current_theme/plug-ins/... will be automatically updated (don't forget to change the version number but before the first version of your applet, it's maybe easier to directly edit this file in current_theme/plug-ins/...)

jesuisbenjamin, Thursday 14 April 2011 à 19:50


Subscription date : 28 October 2009
Messages : 415
haaa i understand: changing the version number tells Cairo to reload the conf!
I thought it was just some fancy thing to do

jesuisbenjamin, Thursday 14 April 2011 à 19:52


Subscription date : 28 October 2009
Messages : 415
PS i have question:

i am now thinking of how i should create a loop and wait to check the FB status. Should i summon a wait() process in the begin() process of the applet? Or somewhere else?

[EDIT] let me put it in other words:

i want to put in begin(self) something like:

while applet == True:
check_facebook()
time.sleep(sometime)


would that work?
if a callback is triggered during the sleep time will it still work?

jesuisbenjamin, Thursday 14 April 2011 à 22:08


Subscription date : 28 October 2009
Messages : 415
Well i tried to put the time.sleep(sometime) in the begin() process but then there is not response to callbacks...
I've no experience with that, please let me know what to do?

matttbe, Thursday 14 April 2011 à 22:21


Subscription date : 24 January 2009
Messages : 12573
I guess you've to create a new thread (or a new process?). It's not so hard to do that in Python, just have a look into the doc or somewhere else

jesuisbenjamin, Friday 15 April 2011 à 01:14


Subscription date : 28 October 2009
Messages : 415
I looked into threading http://en.wikibooks.org/wiki/Python_Programming/Threading and more, but it didn't work out for me.
I tried to define the thread as a process of Applet, as a global function or as an object, in each case it failed, (without error message).
I'm not sure how to deal with threads in the case of OO programming.

Here is the current version of my code:
#!/usr/bin/python

# This is a part of the external applets for Cairo-Dock
# Copyright : (C) 2011 by Benjamin
# E-mail : jesuisbenjamin(...)
#
# 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 2
# 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.
# http://www.gnu.org/licenses/licenses.html#GPL
#
# This program depends on fbcmd, a command line interface (CLI) for facebook.
# http://fbcmd.dtompkins.com/ 

####################
### dependancies ###
####################

from CDApplet import CDApplet
import os
import threading
import time


####################
### Thread Class ###
####################

class countdown(threading.Thread):
    
def run(self):
        print 
"...thread initialised"


####################
### Applet class ###
####################
class Applet(CDApplet):
    
def __init__(self):
        
# define internal variables:
        # counter to display
        
self.counter 1
        
# data retrieved from faceBook with fbcmd
        
self.fb = {}
        
# timer before refreshing data
        
self.timer 1
        
# call high-level init
        
CDApplet.__init__(self)
        
    
##### private methods #####
    
def read_fb(self):
        print 
"...reading data from faceBook"
        
# run the "fbcmd NOTIFY" command and return and parse result in "fblist" list
        
fblist os.popen("fbcmd NOTIFY").readlines()
        
# omit friend request details and feed result into a the "self.fb" dictionary
        
for i in fblist:
            
ii i.split()
            try:
                
number int(ii[-1])
                
self.fb[ii[0]] = number
            except
:
                
pass
        
print self.fb
         
    def get_config
(self,keyfile):
        print 
"...getting user-configuration"
        
# get user configuration:
        ## which notifications should be added to counter?
        
self.config['MESSAGES_UNREAD']     = keyfile.getboolean('Configuration''MESSAGES_UNREAD')
        
self.config['POKES']         = keyfile.getboolean('Configuration''POKES')
        
self.config['SHARES_UNREAD']         = keyfile.getboolean('Configuration''SHARES_UNREAD')
        
self.config['FRIEND_REQUESTS']         = keyfile.getboolean('Configuration''FRIEND_REQUESTS')
        
self.config['GROUP_INVITES']         = keyfile.getboolean('Configuration''GROUP_INVITES')
        
self.config['EVENT_INVITES']         = keyfile.getboolean('Configuration''EVENT_INVITES')
        
## how often should notifications be checked?
        
self.config['REFRESH']                 = keyfile.getint('Configuration''REFRESH')
        
self.timer self.config['REFRESH'] * 6
        
## when should user be notified?
        
self.config['ATTENTION_WHEN']            = keyfile.get('Configuration''ATTENTION_WHEN')
        print 
self.config
            
    def begin
(self):
        
# retrieve data from faceBook 
        
self.read_fb()
        
self.set_counter()
        print 
"...instantiating thread"
        
clock countdown()
        print 
"...starting thread"
        
clock.start()
            
    
def set_counter(self):
        print 
"...setting counter"
        
# counting the current value for counter
        
new_counter 0
        
for i in self.config:
            
# omitting non-boolean values from the config
            
if self.config[i].__class__ != bool:
                
pass
            
# omitting disabled notifications
            
elif self.config[i] == False:
                
pass
            
# remains enabled notifications
            # adding their value to current value of counter
            
else:
                
new_counter += self.fb[i]
        
# record difference between current and prior counter
        
diff self.counter new_counter
        
# set counter to current value if != 0
        
self.counter new_counter
        
if self.counter != 0:
            
self.icon.SetQuickInfo(format(self.counter))
        else:
            
pass
        
# check if attention is needed
        
att self.config["ATTENTION_WHEN"]
        if 
att == "always" and self.counter != 0:
            
self.icon.DemandsAttention(True,"bounce")
            
time.sleep(2)
            
self.icon.DemandsAttention(False,"bounce"
        
elif att == "different" and diff != 0:
            
self.icon.Animate("bounce",4)
        
elif att == "superior" and diff 0:
            
self.icon.Animate("bounce",4)
        else:
            
pass
        
##### callbacks #####
    
def on_click(selfiState):
        print 
"You have"self.counter"unread message(s) on your faceBook account."
############
### main ###
############
if __name__ == '__main__':
    
Applet().run()


matttbe, Friday 15 April 2011 à 10:38


Subscription date : 24 January 2009
Messages : 12573
I'm not a Python expert but I think it's maybe better to use a Timer:
import threading
import time

def CustomTimer
(temp 1.0):
    
threading.Timer(tempCustomTimer, [temp]).start()
    print 
"Hello World %d second" temp

CustomTimer
(2.0)

jesuisbenjamin, Friday 15 April 2011 à 11:58


Subscription date : 28 October 2009
Messages : 415
Thanks! But there is still something going wrong, i can't think why.

I made a test run first (to see how to run the timer from within a process) and it works fine:

#!/usr/bin/python

import time
import threading

def timer
(sometimeobj):
    print 
"...beginning timer"
    
threading.Timer(sometimetimer, [sometimeobj])
    
t.start()
    
obj.poke()

class 
thing(object):
    
def __init__(self):
        
self.time 5

    def run_timer
(self):
        
timer(self.timeself)

    
def poke(self):
        print 
"ouch!"

if __name__ == '__main__':
    
thing()
    
o.run_timer()




But when i apply this to my Applet's code, it appears the countdown() function runs only once

Current code:

#!/usr/bin/python

# This is a part of the external applets for Cairo-Dock
# Copyright : (C) 2011 by Benjamin
# E-mail : jesuisbenjamin...
#
# 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 2
# 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.
# http://www.gnu.org/licenses/licenses.html#GPL
#
# This program depends on fbcmd, a command line interface (CLI) for facebook.
# http://fbcmd.dtompkins.com/ 

####################
### dependancies ###
####################

from CDApplet import CDApplet
import os
import threading
import time


####################
### Thread Class ###
####################

def countdown(sometimeapp):
    print 
"...countdown started"
    
threading.Timer(sometimecountdown, [sometimeapp])
    
t.start()
    
app.read_fb()

####################
### Applet class ###
####################
class Applet(CDApplet):
    
def __init__(self):
        
# define internal variables:
        # counter to display
        
self.counter 1
        
# data retrieved from faceBook with fbcmd
        
self.fb = {}
        
# timer before refreshing data
        
self.timer 1
        
# call high-level init
        
CDApplet.__init__(self)
        
    
##### private methods #####
    
def read_fb(self):
        print 
"...reading data from faceBook"
        
# run the "fbcmd NOTIFY" command and return and parse result in "fblist" list
        
fblist os.popen("fbcmd NOTIFY").readlines()
        
# omit friend request details and feed result into a the "self.fb" dictionary
        
for i in fblist:
            
ii i.split()
            try:
                
number int(ii[-1])
                
self.fb[ii[0]] = number
            except
:
                
pass
        
print self.fb
         
    def get_config
(self,keyfile):
        print 
"...getting user-configuration"
        
# get user configuration:
        ## which notifications should be added to counter?
        
self.config['MESSAGES_UNREAD']     = keyfile.getboolean('Configuration''MESSAGES_UNREAD')
        
self.config['POKES']         = keyfile.getboolean('Configuration''POKES')
        
self.config['SHARES_UNREAD']         = keyfile.getboolean('Configuration''SHARES_UNREAD')
        
self.config['FRIEND_REQUESTS']         = keyfile.getboolean('Configuration''FRIEND_REQUESTS')
        
self.config['GROUP_INVITES']         = keyfile.getboolean('Configuration''GROUP_INVITES')
        
self.config['EVENT_INVITES']         = keyfile.getboolean('Configuration''EVENT_INVITES')
        
## how often should notifications be checked?
        
self.config['REFRESH']                 = keyfile.getint('Configuration''REFRESH')
        
self.timer self.config['REFRESH'] * 6
        
## when should user be notified?
        
self.config['ATTENTION_WHEN']            = keyfile.get('Configuration''ATTENTION_WHEN')
        print 
self.config
            
    def begin
(self):
        
# retrieve data from faceBook 
        
self.read_fb()
        
self.set_counter()
        print 
"...summoning countdown"
        
countdown(5self)
            
    
def set_counter(self):
        print 
"...setting counter"
        
# counting the current value for counter
        
new_counter 0
        
for i in self.config:
            
# omitting non-boolean values from the config
            
if self.config[i].__class__ != bool:
                
pass
            
# omitting disabled notifications
            
elif self.config[i] == False:
                
pass
            
# remains enabled notifications
            # adding their value to current value of counter
            
else:
                
new_counter += self.fb[i]
        
# record difference between current and prior counter
        
diff self.counter new_counter
        
# set counter to current value if != 0
        
self.counter new_counter
        
if self.counter != 0:
            
self.icon.SetQuickInfo(format(self.counter))
        else:
            
pass
        
# check if attention is needed
        
att self.config["ATTENTION_WHEN"]
        if 
att == "always" and self.counter != 0:
            
self.icon.DemandsAttention(True,"bounce")
            
time.sleep(2)
            
self.icon.DemandsAttention(False,"bounce"
        
elif att == "different" and diff != 0:
            
self.icon.Animate("bounce",4)
        
elif att == "superior" and diff 0:
            
self.icon.Animate("bounce",4)
        else:
            
pass
        
##### callbacks #####
    
def on_click(selfiState):
        print 
"You have"self.counter"unread message(s) on your faceBook account."
############
### main ###
############
if __name__ == '__main__':
    
Applet().run()



I posted this too on the Ubuntu Forum, hoping to get some guidance.

Cheers
Benjamin

matttbe, Saturday 16 April 2011 à 10:09


Subscription date : 24 January 2009
Messages : 12573
I think (but it's maybe much better to wait for an answer on the Ubuntu forum ) that you've to define your countdown function in the Applet class.
And if you want to stop this thread, you've to access to this t variable which is not currently possible I think.

PS: don't forget to hid your mail address and it's better to add =C next to the code balise => code=C] (...) [/code]

jesuisbenjamin, Saturday 16 April 2011 à 10:48


Subscription date : 28 October 2009
Messages : 415
Thanks

jesuisbenjamin, Sunday 17 April 2011 à 02:34


Subscription date : 28 October 2009
Messages : 415
I tried many things and have exhausted most possibilities (at least i can't think of any other).
With the Timer.isAlive() process i can tell the Timer thread is running.
I tested this Timer by telling it to os.system("gedit") to see if anything happened outside the applet. Indeed it worked out, but only after i killed the applet (Ctrl+C from Terminal). This suggests the Timer thread is enqueued somehow and cannot start till the applet's killed.
I have no understanding of the API, but i believe its structure prevents a thread from running simultaneously as an attribute of the applet.
So the idea comes to my mind to make another script which can run on parallel with it and triggers it every now and then. Only i don't know how to reach the running applet from outside the script. Is there any way to do that?

fabounet, Sunday 17 April 2011 à 10:34


Subscription date : 30 November 2007
Messages : 17118
did you try to take a look at the other python applets ?
Eduardo made several ones and I think he may have needed threads in one of them (maybe Quote of the Day, or Translator, or Google, since they make html requests)

jesuisbenjamin, Sunday 17 April 2011 à 10:41


Subscription date : 28 October 2009
Messages : 415
fabounet :
did you try to take a look at the other python applets ?
Eduardo made several ones and I think he may have needed threads in one of them (maybe Quote of the Day, or Translator, or Google, since they make html requests)


I did look, saw nothing -- but will look again, i may have missed it

fabounet, Sunday 17 April 2011 à 11:19


Subscription date : 30 November 2007
Messages : 17118
if you use the http module of Python (I believe it's called urllib), maybe there are already some functions that are threaded ?
I'm sorry I can't help you more, I'm still a beginner in Python

jesuisbenjamin, Sunday 17 April 2011 à 12:07


Subscription date : 28 October 2009
Messages : 415
Ha! it seems he used dbus to loop back into the applet That's what i also concluded last night.
That's going to be fun!

Technical discussions | Discussions techniques

Subjects Author Language Messages Last message
[Locked] FaceBook Applet
Page : 1 2 3
jesuisbenjamin English 58 jesuisbenjamin [Read]
27 April 2011 à 16:57


Glx-Dock / Cairo-Dock List of forums Technical discussions | Discussions techniques FaceBook Applet Top

Online users :

Powered by ElementSpeak © 2007 Adrien Pilleboue, 2009-2013 Matthieu Baerts.
Dock based on CSS Dock Menu (Ndesign) with jQuery. Icons by zgegball
Cairo-Dock is a free software under GNU-GPL3 licence. First stable version created by Fabounet.
Many thanks to TuxFamily for the web Hosting and Mav for the domain name.