Main index > About new desklets > arhythmlet

By cs-cam (Desklet Author), on Tue Apr 19 04:59:40 2005: arhythmlet.

Hey,

I want to write a version of rhythmlet (gDesklets) for adesklets. Doesn't sound too hard, however I had a look at the code for xmms_bar and was wondering, your button_press event looks very neat, could you give me some insight as to how you did this? I'm not familiar with the objects you used or how you did it. I've read the code I'm just a little lost. Here's how I handled the button_press in my pacman tracker desklet (95% working, still working out some issues with how I've used libpypac, trying to get hold of the author for some help there :P).

Code:


def button_press(self, delayed, x, y, button):
                if x>35 and x<150 and y>233 and y<244: #  is mouse over the button area?
                        if self._button_text == 'check for updates': # primitive check status
                                self._pacman_Sy()
                        elif self._button_text == 'update now':
                                self._pacman_Su()


Obviously it works, it's messy but with more buttons such as play/pause, stop, next, prev etc it'd just be a huge mistake.

So yeah, any tutorials orcould you perhaps give me a quick runthrough of how your code works? With something to work from I could probably pick it up.

Thanks :)

By syfou (Core Developer & Desklet Author), on Tue Apr 19 13:42:53 2005.

Basically, what I do for xmms_bar, in Events::button_press() is not different from what you do in your code snipset:

The only significant structural difference is that I dynamically compute the icons placement at run time based on the content of Events::icons, which is better since the code, while being cleaner, does not need to be changed if the icons images are modified. Just add a

Code:


print self.icons_display


statement at the beginning of Events::button_press() if you want to follow the code more easily. I should point-out to you though that I made the assumption that the icons were aligned on a single horizontal line (this is a bar) all over the code, so this is not a generic 2D position detection routine.

If you want to do such things, I believe you should go with something similar to test/widgets.py from the base package, by dynamically creating icons widgets that would know about placement and size, and that you could iterate through to find which icon you are in using derivative from Widget::execute()... But its your work. ;-)

By cs-cam (Desklet Author), on Wed Apr 20 02:07:55 2005.

Okay, this is about as base as it comes but it works.

http://www.myfilebin.com/userfiles/cam/arhythmlet-0.0.1.tar.gz

It's nowhere near finished but I was over coding Python so I tarred up what I'd done so far and uploaded it for now. Works, is only 3 icons thus far but it's golden. I've used most of the backend code from the gDesklets rhythmlet since he had a ton of base objects that weren't gdesklets-oriented. I've given him all the credit and plan to get in contact with him once I've done a bit more and have some more to show for it. However if anyone wants to rip shreds out of it so far and give me feedback I'm all ears. I've got the covers and scrobbler objects in the archive, they aren't currently implemented but will be down the track so I just chucked the files in for now.

By cs-cam (Desklet Author), on Wed Apr 20 19:54:38 2005.

http://www.myfilebin.com/userfiles/cam/arhythmlet-0.0.2.tar.gz

And now with ID3 text and cover art. And a changelog so I can keep track of what was done when since I'd rather a heap of little releases than one or two with a lot of changes. I'm a dork that way. It works but I think I need some expert input, I'm attempting to use threads from a very hard to understand tutorial to I don't hav to wait for it to search Amazon before it displays. Any hints would be very much appreciated :)

By cs-cam (Desklet Author), on Wed Apr 20 22:27:19 2005.

And I get this at random, usually when I do something in actual Rhythmbox rather than via the desklet.

Code:


Traceback (most recent call last):
  File "arhythmlet.py", line 215, in ?
    Events(dirname(__file__)).pause()
  File "/usr/lib/python2.4/site-packages/adesklets/events_handler.py", line 228, in pause
    posix_signal.pause()
  File "/usr/lib/python2.4/site-packages/adesklets/events_handler.py", line 188, in _fire_event
    self._alarm()
  File "/usr/lib/python2.4/site-packages/adesklets/events_handler.py", line 296, in _alarm
    timeout=self.alarm()
  File "arhythmlet.py", line 146, in alarm
    self._display()
  File "arhythmlet.py", line 175, in _display
    self.c.start()
  File "/usr/lib/python2.4/threading.py", line 410, in start
    assert not self.__started, "thread already started"
AssertionError: thread already started

By syfou (Core Developer & Desklet Author), on Thu Apr 21 16:33:18 2005.

Sorry for not trying out your code, but it uses too many components I am not willing to install - I read it though; so I can comment on it a little.

First, let me say I am less impressed than you are with Mr. Alex Revo effort. I am not flamebaiting here (this is none of your fault anyway), and I am not saying it is not working, usable code, or that Mr. Revo did a bad coding work, but he certainly made discutable choices. I find the solution used a big resource hog... Managing to use most of gnome, CORBA, PIL, and a specialized SOAP module just to use playlists and get some songs informations? That's some real achievement. :lol:

Once again, it doesn't mean it is bad code, and it certainly doesn't mean I will stand against arythmlet publication on adesklets site later on. But it certainly goes somewhat against adesklets whole objective of a leaner desklets solution.

From what I read from your code, it appears you want these functionnalities:

There are already plenty of python modules, relying only on the bare environments, to do all this... Managing AudioScrobbler, Amazon connections, playing a variety of files to your sound card (gstreamer already used here is pretty lean... No reason for you not to invoque it from the command line in Python through gst-launch).

As for your threading problem, it is hard for me to give you an answer, since I cannot run your code. I can only state you the obvious: you are trying to launch a thread that was already started previously, which seems possible, since the Cover constructor is only invoked in Events::ready(). So, at the second iteration through Events::_display(), this can very well strike you if the thread did not exist already.

I'd like to add that you have to be extra careful with adesklets python package when using threading, as adesklets rely on correct basic signal handlings to work. On POSIX systems, asynchronous signals such as SIGUSR1. often sent by the adesklets interpreter to the python script, are by default handled by an arbitrary thread within the process. If it get caught by anything than the launching thread, you could be in trouble.

By cs-cam (Desklet Author), on Sat Apr 23 00:46:04 2005.

Okay, thanks for the feedback, especially on the code I'm using. I'll probably end up releasing something using this code since I've writeen for it a fair bit but later on when I'm more apt in Python I can always try rewriting it with resource-usage in mind. At this stage I'm in a "if it works then yippee" mindset, once they work mroe often I'll get into the "well how can I make this use less resources" mindset.

I've tried threading with my pacman one as well with no luck but you can't test that either since you'd have to install a whole distro :p Or at least get another distros package manager to work with whatever you use hehe. The Arch forums seem to have some pretty able Python-ers though so I'll finish it up sans threads, get them to test it and then get some help making it threaded. Once I'm at that stage then I'll see how I can incorporate it into other desklets etc. I'm getting thereand it's pretty fun working on it so we'll see how it turns out ;)


adesklets is proud to be hosted on:

SourceForge.net Logo

Back to adesklets.sf.net.