From 61536ca548691b15e7f63340a0fbfb5a3055d5be Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kristoffer=20Gr=C3=B6nlund?= Date: Tue, 5 Jan 2010 17:04:21 +0100 Subject: [PATCH 1/1] Added 'helldon' to transparently port the thing to the desktop :P --- helldon/__init__.py | 76 ++++++++++++++++++++++++++++++++++++++++++++++++ jamaendo/api.py | 3 ++ jamaui/__init__.py | 13 +++++++-- jamaui/albumlist.py | 5 +++- jamaui/colors.py | 36 ++++++++++++++++++----- jamaui/favorites.py | 5 +++- jamaui/featured.py | 5 +++- jamaui/listbox.py | 5 +++- jamaui/player.py | 2 +- jamaui/playerwindow.py | 11 ++++--- jamaui/playlists.py | 5 +++- jamaui/radios.py | 5 +++- jamaui/search.py | 5 +++- jamaui/showalbum.py | 5 +++- jamaui/showartist.py | 5 +++- jamaui/ui.py | 4 +-- 16 files changed, 164 insertions(+), 26 deletions(-) create mode 100644 helldon/__init__.py diff --git a/helldon/__init__.py b/helldon/__init__.py new file mode 100644 index 0000000..d3aa134 --- /dev/null +++ b/helldon/__init__.py @@ -0,0 +1,76 @@ +import gtk + +gtk.HILDON_SIZE_AUTO = -1 +gtk.HILDON_SIZE_AUTO_WIDTH = -1 +gtk.HILDON_SIZE_FINGER_HEIGHT = 32 +gtk.HILDON_SIZE_THUMB_HEIGHT = 48 + +BUTTON_ARRANGEMENT_VERTICAL = 1 + +def hildon_gtk_window_set_progress_indicator(wnd, onoff): + pass + +class Program(gtk.Window): + instance = None + + def __init__(self): + gtk.Window.__init__(self, type=gtk.WINDOW_TOPLEVEL) + self._vbox = gtk.VBox() + self._title = gtk.Label("Jamaendo") + self._backbtn = gtk.Button("<<<") + self._hbox = gtk.HBox() + self._hbox.pack_start(self._title, True) + self._hbox.pack_start(self._backbtn, False) + self._notebook = gtk.Notebook() + self._notebook.set_size_request(800, 445) + self._notebook.set_show_tabs(False) + self._vbox.pack_start(self._hbox, False) + self._vbox.pack_start(self._notebook, True) + self.add(self._vbox) + self.show_all() + Program.instance = self + + def add_window(self, wnd): + pass + + def add_stackable(self, wnd): + idx = self._notebook.append_page(wnd) + self._notebook.set_current_page(idx) + wnd.show_all() + wnd._nb_index = idx + +class StackableWindow(gtk.Frame): + def __init__(self): + gtk.Frame.__init__(self) + self._nb_index = 0 + Program.instance.add_stackable(self) + def set_app_menu(self, menu): + pass + + def set_title(self, title): + Program.instance._title.set_text(title)#_notebook.set_tab_label_text(self, title) + +class AppMenu(object): + def __init__(self): + pass + + def append(self, widget): + pass + + def show_all(self): + pass + +class GtkButton(gtk.Button): + def __init__(self, size): + gtk.Button.__init__(self) + + +class Button(gtk.Button): + def __init__(self, size, layout): + gtk.Button.__init__(self) + + def set_text(self, title, subtitle): + self.set_label(title) + +class PannableArea(gtk.ScrolledWindow): + pass diff --git a/jamaendo/api.py b/jamaendo/api.py index feeb17d..7792c33 100644 --- a/jamaendo/api.py +++ b/jamaendo/api.py @@ -277,6 +277,9 @@ class CoverFetcher(threading.Thread): self.work = [] def _retrieve(self, url, fname): + BROKEN = 'http://imgjam.com/radios/default/default.100.png' + if url == BROKEN: + return None f = open(fname, 'wb') c = pycurl.Curl() c.setopt(pycurl.FOLLOWLOCATION, 1) diff --git a/jamaui/__init__.py b/jamaui/__init__.py index 9705ea1..819b0d7 100644 --- a/jamaui/__init__.py +++ b/jamaui/__init__.py @@ -27,7 +27,16 @@ import sys LOG_FILENAME = '/tmp/jamaendo.log' LOG_LEVEL = logging.DEBUG -#LOG_FORMAT = "%(asctime)s %(name)-19s %(levelname)-5s - %(message)s" LOG_FORMAT = "%(asctime)s %(name)-10s: [%(lineno)4d] %(levelname)-5s %(message)s" -logging.basicConfig(filename=LOG_FILENAME, level=LOG_LEVEL, format=LOG_FORMAT) + +_rootlogger = logging.getLogger() +_fhandler = logging.FileHandler(LOG_FILENAME) +_shandler = logging.StreamHandler() +_formatter = logging.Formatter(LOG_FORMAT) +_fhandler.setFormatter(_formatter) +_shandler.setFormatter(_formatter) + +_rootlogger.addHandler(_fhandler) +_rootlogger.addHandler(_shandler) +_rootlogger.setLevel(LOG_LEVEL) diff --git a/jamaui/albumlist.py b/jamaui/albumlist.py index 5653310..dbaa8ff 100644 --- a/jamaui/albumlist.py +++ b/jamaui/albumlist.py @@ -1,7 +1,10 @@ import os import gtk import gobject -import hildon +try: + import hildon +except: + import helldon as hildon import jamaendo import util from settings import settings diff --git a/jamaui/colors.py b/jamaui/colors.py index c17dbc9..391d18a 100644 --- a/jamaui/colors.py +++ b/jamaui/colors.py @@ -1,7 +1,12 @@ # hildon colors import gtk -import hildon +try: + import hildon + _using_helldon = False +except: + import helldon as hildon + _using_helldon = True # See the Fremantle Master Layout Guide for more information: # http://tinyurl.com/fremantle-master-layout-guide @@ -30,6 +35,10 @@ def get_font_desc(logicalfontname): settings = gtk.settings_get_default() font_style = gtk.rc_get_style_by_paths(settings, logicalfontname, \ None, None) + if not font_style: + font_style = gtk.rc_get_style_by_paths(settings, + 'GtkButton', 'GtkButton', gtk.Button) + font_desc = font_style.font_desc return font_desc @@ -37,20 +46,31 @@ def get_color(logicalcolorname): settings = gtk.settings_get_default() color_style = gtk.rc_get_style_by_paths(settings, 'GtkButton', \ 'osso-logical-colors', gtk.Button) - return color_style.lookup_color(logicalcolorname) -def font(name): - return get_font_desc(name).to_string() + if not color_style: + font_style = gtk.rc_get_style_by_paths(settings, + 'GtkButton', 'GtkButton', gtk.Button) + return color_style.lookup_color(logicalcolorname) +if _using_helldon: + def font(name): + return "normal" +else: + def font(name): + return get_font_desc(name).to_string() -def color(name): - return get_color('SecondaryTextColor').to_string() +if _using_helldon: + def color(name): + return "#333333" +else: + def color(name): + return get_color('SecondaryTextColor').to_string() import sys current_module = sys.modules[__name__] for fnt in logical_font_names: - setattr(current_module, fnt, font(fnt)) + setattr(current_module, fnt, lambda: font(fnt)) for clr in logical_color_names: - setattr(current_module, clr, color(clr)) + setattr(current_module, clr, lambda: color(clr)) diff --git a/jamaui/favorites.py b/jamaui/favorites.py index 5a0474c..6e829ac 100644 --- a/jamaui/favorites.py +++ b/jamaui/favorites.py @@ -22,7 +22,10 @@ # (based on http://pygstdocs.berlios.de/pygst-tutorial/seeking.html) # import gtk -import hildon +try: + import hildon +except: + import helldon as hildon import jamaendo from playerwindow import open_playerwindow from showartist import ShowArtist diff --git a/jamaui/featured.py b/jamaui/featured.py index 3f9aa20..2eef82d 100644 --- a/jamaui/featured.py +++ b/jamaui/featured.py @@ -22,7 +22,10 @@ # (based on http://pygstdocs.berlios.de/pygst-tutorial/seeking.html) # import gtk -import hildon +try: + import hildon +except: + import helldon as hildon import jamaendo from playerwindow import open_playerwindow from showartist import ShowArtist diff --git a/jamaui/listbox.py b/jamaui/listbox.py index edef878..bc34d09 100644 --- a/jamaui/listbox.py +++ b/jamaui/listbox.py @@ -1,6 +1,9 @@ # what the fuck, GTK import gtk -import hildon +try: + import hildon +except: + import helldon as hildon class ListBox(gtk.TreeView): def __init__(self): diff --git a/jamaui/player.py b/jamaui/player.py index 70d261a..7908dea 100644 --- a/jamaui/player.py +++ b/jamaui/player.py @@ -158,7 +158,7 @@ class GStreamer(_Player): self.filesrc = self.player self.filesrc_property = 'uri' self.volume_control = self.player - self.volume_multiplier = 1. + self.volume_multiplier = 10. self.volume_property = 'volume' def _on_decoder_pad_added(self, decoder, src_pad, sink_pad): diff --git a/jamaui/playerwindow.py b/jamaui/playerwindow.py index c9b965b..2fd350a 100644 --- a/jamaui/playerwindow.py +++ b/jamaui/playerwindow.py @@ -23,7 +23,10 @@ # import gtk import gobject -import hildon +try: + import hildon +except: + import helldon as hildon import util import pango import jamaendo @@ -205,11 +208,11 @@ class PlayerWindow(hildon.StackableWindow): if self.playlist.radio_mode: ppstr = 'Radio: %s'%(cgi.escape(self.playlist.radio_name)) else: - ppstr = 'Track %s of %s'%(colors.SmallSystemFont, colors.SecondaryTextColor, int(playlist_pos)+1, playlist_size) + ppstr = 'Track %s of %s'%(colors.SmallSystemFont(), colors.SecondaryTextColor(), int(playlist_pos)+1, playlist_size) self.playlist_pos.set_markup(ppstr) - self.track.set_markup('%s'%(colors.LargeSystemFont, cgi.escape(track))) + self.track.set_markup('%s'%(colors.LargeSystemFont(), cgi.escape(track))) self.artist.set_markup('%s'%(cgi.escape(artist))) - self.album.set_markup('%s'%(colors.SecondaryTextColor, cgi.escape(album))) + self.album.set_markup('%s'%(colors.SecondaryTextColor(), cgi.escape(album))) def show_banner(self, message, timeout = 2000): banner = hildon.hildon_banner_show_information(self, '', message) diff --git a/jamaui/playlists.py b/jamaui/playlists.py index ece1527..3012e29 100644 --- a/jamaui/playlists.py +++ b/jamaui/playlists.py @@ -22,7 +22,10 @@ # (based on http://pygstdocs.berlios.de/pygst-tutorial/seeking.html) # import gtk -import hildon +try: + import hildon +except: + import helldon as hildon import jamaendo from settings import settings import logging diff --git a/jamaui/radios.py b/jamaui/radios.py index da10c77..44d92f3 100644 --- a/jamaui/radios.py +++ b/jamaui/radios.py @@ -22,7 +22,10 @@ # (based on http://pygstdocs.berlios.de/pygst-tutorial/seeking.html) # import gtk -import hildon +try: + import hildon +except: + import helldon as hildon import jamaendo from playerwindow import open_playerwindow from albumlist import RadioList diff --git a/jamaui/search.py b/jamaui/search.py index 4092048..4ea8dd3 100644 --- a/jamaui/search.py +++ b/jamaui/search.py @@ -22,7 +22,10 @@ # (based on http://pygstdocs.berlios.de/pygst-tutorial/seeking.html) # import gtk -import hildon +try: + import hildon +except: + import helldon as hildon import jamaendo from playerwindow import open_playerwindow from showartist import ShowArtist diff --git a/jamaui/showalbum.py b/jamaui/showalbum.py index a13ffe8..218d998 100644 --- a/jamaui/showalbum.py +++ b/jamaui/showalbum.py @@ -23,7 +23,10 @@ # import gtk import cgi -import hildon +try: + import hildon +except: + import helldon as hildon import jamaendo from player import Playlist from playerwindow import open_playerwindow diff --git a/jamaui/showartist.py b/jamaui/showartist.py index 9cae975..6751b97 100644 --- a/jamaui/showartist.py +++ b/jamaui/showartist.py @@ -22,7 +22,10 @@ # (based on http://pygstdocs.berlios.de/pygst-tutorial/seeking.html) # import gtk -import hildon +try: + import hildon +except: + import helldon as hildon import jamaendo from playerwindow import open_playerwindow from albumlist import AlbumList diff --git a/jamaui/ui.py b/jamaui/ui.py index 2eb3261..dda0ecc 100644 --- a/jamaui/ui.py +++ b/jamaui/ui.py @@ -47,8 +47,8 @@ except: log.critical('Using GTK widgets, install "python2.5-hildon" ' 'for this to work properly.') else: - log.critical('This ui only works in maemo') - sys.exit(1) + log.critical('This ui (probably) only works in maemo') + import helldon as hildon from dbus.mainloop.glib import DBusGMainLoop -- 1.7.9.5