From: Paul Philippov Date: Wed, 4 Feb 2009 12:33:31 +0000 (+0200) Subject: initial commit X-Git-Url: http://git.maemo.org/git/?p=beats-applet;a=commitdiff_plain;h=979db20bec107c169ac91e69473ec29b1b4e115c initial commit --- diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..71bf810 --- /dev/null +++ b/src/Makefile @@ -0,0 +1,100 @@ +# Example custom makefile for creating .deb without using dpkg tools. +# +# Author: Tim Wegener +# +# This requires deb_hand.mak + +# Sources: +# SOURCE_DIR - directory containing files to be packaged +# ICON_SOURCE - 26x26 icon file for maemo +# description.txt - description with summary on first line +# preinst, postinst, prerm, postrm - optional control shell scripts + +PACKAGE = beats-applet +VERSION = 0.1 +SECTION = user/other +PRIORITY = optional +ARCH = armel +DEPENDS = python2.5, python2.5-gobject, python2.5-gtk2, python2.5-osso, python2.5-hildon, python2.5-mutagen +MAINTAINER = Paul Philippov + +SOURCE_DIR = . +PACKAGE_DIR ?= .. +ICON_SOURCE = ${SOURCE_DIR}/beats26.png +CTRL_EXTRAS ?= ${wildcard preinst postinst prerm postrm} + +${PACKAGE_DIR}/data: ${SOURCE_DIR} + rm -rf $@ + mkdir -p $@ + mkdir -p $@/usr/lib/hildon-desktop + cp ${SOURCE_DIR}/beats-applet.py $@/usr/lib/hildon-desktop/ + mkdir -p ${PACKAGE_DIR}/data/usr/share/applications/hildon-home + cp ${SOURCE_DIR}/beats-applet.desktop $@/usr/share/applications/hildon-home/ + mkdir -p ${PACKAGE_DIR}/data/usr/share/pixmaps + cp ${SOURCE_DIR}/beats26.png $@/usr/share/pixmaps/beats.png + mkdir -p ${PACKAGE_DIR}/data/usr/share/icons/hicolor/26x26/apps + cp ${SOURCE_DIR}/beats26.png $@/usr/share/icons/hicolor/26x26/apps/beats.png + mkdir -p ${PACKAGE_DIR}/data/usr/share/icons/hicolor/128x128/apps + cp ${SOURCE_DIR}/beats128.png $@/usr/share/icons/hicolor/128x128/apps/beats.png + mkdir -p ${PACKAGE_DIR}/data/usr/share/icons/hicolor/scalable/apps + cp ${SOURCE_DIR}/beats.svg $@/usr/share/icons/hicolor/scalable/apps + mkdir -p ${PACKAGE_DIR}/data/usr/share/beats + cp ${SOURCE_DIR}/prefs.glade $@/usr/share/beats/ + +${PACKAGE_DIR}/control: ${PACKAGE_DIR}/data ${CTRL_EXTRAS} description.txt ${ICON_SOURCE} + rm -rf $@ + mkdir -p $@ + +ifneq (${CTRL_EXTRAS},) + cp ${CTRL_EXTRAS} $@ +endif + + echo "Package: ${PACKAGE}" > $@/control + echo "Version: ${VERSION}" >> $@/control + echo "Section: ${SECTION}" >> $@/control + echo "Priority: ${PRIORITY}" >> $@/control + echo "Architecture: ${ARCH}" >> $@/control + echo "Depends: ${DEPENDS}" >> $@/control + echo "Installed-Size: ${shell du -s ${PACKAGE_DIR}/data | cut -f1}" >> $@/control + echo "Maintainer: ${MAINTAINER}" >> $@/control + echo -n "Description:" >> $@/control + cat description.txt | gawk '{print " "$$0;}' >> $@/control + +ifneq (${ICON_SOURCE},) + echo "Maemo-Icon-26:" >> $@/control + base64 ${ICON_SOURCE} | gawk '{print " "$$0;}' >> $@/control +endif + + cd ${PACKAGE_DIR}/data && find . -type f -exec md5sum {} \; | sed -e 's| \./||' > $@/md5sums + +${PACKAGE_DIR}/debian-binary: + echo "2.0" > $@ + +${PACKAGE_DIR}/build: ${PACKAGE_DIR}/debian-binary ${PACKAGE_DIR}/control + rm -rf $@ + mkdir -p $@ + + cp ${PACKAGE_DIR}/debian-binary $@/ + cd ${PACKAGE_DIR}/control && tar czvf $@/control.tar.gz ./* + cd ${PACKAGE_DIR}/data && tar czvf $@/data.tar.gz ./* + +${PACKAGE_DIR}/${PACKAGE}_${VERSION}_${ARCH}.deb: ${PACKAGE_DIR}/build + ar -rc $@tmp $ $@fail + rm -f $@tmp + mv $@fail $@ + +.PHONY: data +data: ${PACKAGE_DIR}/data + +.PHONY: control +control: ${PACKAGE_DIR}/control + +.PHONY: build +build: ${PACKAGE_DIR}/build + +.PHONY: deb +deb: ${PACKAGE_DIR}/${PACKAGE}_${VERSION}_${ARCH}.deb + +clobber: + rm -rf ${PACKAGE_DIR}/debian_binary ${PACKAGE_DIR}/control ${PACKAGE_DIR}/data ${PACKAGE_DIR}/build diff --git a/src/beats-applet.desktop b/src/beats-applet.desktop new file mode 100644 index 0000000..ee76976 --- /dev/null +++ b/src/beats-applet.desktop @@ -0,0 +1,5 @@ +[Desktop Entry] +Name=Beats (Swatch Internet Time) +Comment=Swatch Internet Time applet +Type=python +X-Path=beats-applet diff --git a/src/beats-applet.py b/src/beats-applet.py new file mode 100644 index 0000000..0dbbc7d --- /dev/null +++ b/src/beats-applet.py @@ -0,0 +1,200 @@ +''' +Beats +2009 (c) Paul Philippov +Swatch Internet Time applet for Hildon +''' +import gtk +from gtk import gdk +import hildondesktop +import cairo +import gobject +import pango +import time +from datetime import timedelta, datetime, tzinfo +from ConfigParser import * + +Pi = 3.14 +Beat = 86.4 + +class BeatsApplet(hildondesktop.HomeItem): + + def __init__(self): + hildondesktop.HomeItem.__init__(self) + + self.timer = None + + self.connect("settings", self._DoSettings) + self.connect("expose-event", self.expose) + self.connect("screen-changed", self.screen_changed) + self.connect("unrealize", self.unrealize) + self.connect("background", self.set_timer, False) + self.connect("foreground", self.set_timer, True) + + self.label = gtk.Label() + self.label.set_use_markup(True) + self.label.set_markup('@---.-') + self.add(self.label) + self.set_size_request(-1, -1) + + self.redraw() + + self.inbackground = False + self.set_timer(self, True) + self.show_all() + + def redraw(self): + self.set_resize_type(hildondesktop.HOME_ITEM_RESIZE_NONE) + self.label.modify_font(pango.FontDescription(self._prefRead('font'))) +# self.label.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(self._prefRead('background'))) + self.label.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(self._prefRead('foreground'))) + self.label.set_padding(15, 20) + self.label.set_size_request(-1, -1) + self.set_size_request(-1, -1) + + def expose(self, widget, event): + width, height = self.allocation[2], self.allocation[3] + radius = min(15, width/2, height/2) + x0 = 0; x1 = x0 + width + y0 = 0; y1 = y0 + height + + cr = widget.window.cairo_create() + cr.set_source_rgba(1.0, 1.0, 1.0, 0.0) + cr.set_operator(cairo.OPERATOR_SOURCE) + cr.paint() + + cr.move_to(x0, y0 + radius); cr.arc(x0 + radius, y0 + radius, radius, Pi, 1.5 * Pi) + cr.line_to(x1 - radius, y0); cr.arc(x1 - radius, y0 + radius, radius, 1.5 * Pi, 0.0) + cr.line_to(x1, y1 - radius); cr.arc(x1 - radius, y1 - radius, radius, 0.0, 0.5 * Pi) + cr.line_to(x0 + radius, y1); cr.arc(x0 + radius, y1 - radius, radius, 0.5 * Pi, Pi) + cr.close_path() + bg_color = gtk.gdk.color_parse(self._prefRead('background')) + cr.set_source_rgba( + bg_color.red / 65535.0, + bg_color.green / 65535.0, + bg_color.blue / 65535.0, + float(self._prefRead('background_alpha')) / 65535.0 + ) + cr.fill() + return False + + def screen_changed(self, widget, old_screen=None): + screen = self.get_screen() + self.set_colormap(screen.get_rgba_colormap()) + return False + + def unrealize(self, widget, date=None): + self._prefSave('pos_x', self.allocation[0]) + self._prefSave('pos_y', self.allocation[1]) + if self.timer: + v = gobject.source_remove(self.timer) + self.timer = None + + def set_timer(self, widget, on): + if self.timer != None: + gobject.source_remove(self.timer) + if on: + self.timer = gobject.timeout_add(Beat * 100, self.update) + self.update() + + def update(self): + btm_now = datetime.utcnow() + timedelta(hours=1) + delta = timedelta( + hours = btm_now.hour, + minutes = btm_now.minute, + seconds = btm_now.second, + microseconds = btm_now.microsecond + ) + beats = (delta.seconds + delta.microseconds / 1000000.0) / Beat + self.label.set_markup("@%05.1f" % beats) + self.label.set_size_request(-1, -1) + self.set_size_request(-1, -1) + return not self.inbackground + + def _DoSettings(self, widget, data=None): + menuitem = gtk.MenuItem("Beats (Swatch Internet Time)") + menuitem.connect_object("activate", self._ShowSettings, None) + return menuitem + + def _ShowSettings(self, widget, data=None): + import gtk.glade + self._widgetTree = gtk.glade.XML('/usr/lib/beats-applet/prefs.glade') + self._window = self._widgetTree.get_widget("prefs") + self._widgetTree.get_widget("color_background").set_current_color(gtk.gdk.color_parse(self._prefRead('background'))) + self._widgetTree.get_widget("color_background").set_has_opacity_control(True) + self._widgetTree.get_widget("color_background").set_current_alpha(int(self._prefRead('background_alpha'))) + self._widgetTree.get_widget("color_foreground").set_current_color(gtk.gdk.color_parse(self._prefRead('foreground'))) + self._widgetTree.get_widget("color_foreground").set_current_alpha(int(self._prefRead('foreground_alpha'))) + self._widgetTree.get_widget("color_foreground").set_has_opacity_control(True) + self._widgetTree.get_widget("fontselection").set_font_name(self._prefRead('font')) + callbackMapping = { + "on_bCancel_clicked": self._cancel, + "on_bValidate_clicked": self._validate, + } + self._widgetTree.signal_autoconnect(callbackMapping) + self._window.connect("delete-event", self._closebox) + self._window.show() + return True + + def _color_to_string(self, c): + t = "#" + if len(hex(c.red)[2:4])==1: + t = t+'0'+hex(c.red)[2:4] + else: + t = t+hex(c.red)[2:4] + if len(hex(c.green)[2:4])==1: + t = t+'0'+hex(c.green)[2:4] + else: + t = t+hex(c.green)[2:4] + if len(hex(c.blue)[2:4])==1: + t = t+'0'+hex(c.blue)[2:4] + else: + t = t+hex(c.blue)[2:4] + return t + + def _validate(self, widget, *data): + self._prefSave('background', self._color_to_string(self._widgetTree.get_widget("color_background").get_current_color())) + self._prefSave('foreground', self._color_to_string(self._widgetTree.get_widget("color_foreground").get_current_color())) + self._prefSave('background_alpha', str(self._widgetTree.get_widget("color_background").get_current_alpha())) + self._prefSave('foreground_alpha', str(self._widgetTree.get_widget("color_foreground").get_current_alpha())) + self._prefSave('font', self._widgetTree.get_widget("fontselection").get_font_name()) + self._window.destroy() + + def _cancel(self, widget, *data): + self._window.destroy() + + def _closebox(self, widget, *data): + self._window.destroy() + + def _prefRead(self, key): + default = { + 'background':'#000000', + 'background_alpha':'32767', + 'foreground':'#FFFFFF', + 'foreground_alpha':'65535', + 'font':'Sans 16', + 'pos_x':'0', + 'pos_y':'0' + } + c = ConfigParser(default) + c.read('/home/user/.beats') + return c.get("DEFAULT", key) + + def _prefSave(self, key, value): + default = { + 'background':'#000000', + 'background_alpha':'32767', + 'foreground':'#FFFFFF', + 'foreground_alpha':'65535', + 'font':'Sans 16', + } + c = ConfigParser(default) + c.read('/home/user/.beats') + c.set('DEFAULT', key, value) + fp = open('/home/user/.beats', 'w') + c.write(fp) + fp.close() + self.redraw() + +def hd_plugin_get_objects(): + plugin = BeatsApplet() + return [plugin] diff --git a/src/beats.svg b/src/beats.svg new file mode 100644 index 0000000..500315e --- /dev/null +++ b/src/beats.svg @@ -0,0 +1,139 @@ + + + + + + + + + + + + + + + image/svg+xml + + + + + + + @ + + + + + + diff --git a/src/beats128.png b/src/beats128.png new file mode 100644 index 0000000..935da04 Binary files /dev/null and b/src/beats128.png differ diff --git a/src/beats26.png b/src/beats26.png new file mode 100644 index 0000000..b0cf02c Binary files /dev/null and b/src/beats26.png differ diff --git a/src/description.txt b/src/description.txt new file mode 100644 index 0000000..eb1f4c8 --- /dev/null +++ b/src/description.txt @@ -0,0 +1,7 @@ +Swatch beats plugin for Hildon Desktop +A small cairo Swatch Internet Time applet for Hildon Desktop. +Swatch Internet Time was a decimal time concept introduced +in 1998 by the Swatch corporation as an alternative, decimal +measure of time. The goals was to simplify the way people in +different time zones communicate about time, by eliminating +time zones altogether. diff --git a/src/prefs.glade b/src/prefs.glade new file mode 100644 index 0000000..3f50cd0 --- /dev/null +++ b/src/prefs.glade @@ -0,0 +1,249 @@ + + + + + + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + False + True + GTK_WIN_POS_CENTER_ALWAYS + True + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + True + + + True + + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + True + True + True + #000000000000 + + + 1 + + + + + + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + Background + + + tab + False + + + + + True + + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + True + True + True + #000000000000 + + + 1 + + + + + + + + 1 + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + Foreground + + + tab + 1 + False + + + + + True + + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 8 + @931.42 + + + 1 + + + + + + + + 2 + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + Font + + + tab + 2 + False + + + + + True + + + True + 40 + beats.png + 0 + + + + + True + <b>Beats v0.1</b> +Swatch Internet Time + True + GTK_JUSTIFY_CENTER + + + 1 + + + + + True + True + True + True + beatswatch-maemo.googlecode.com + GTK_RELIEF_NONE + 0 + http://beatswatch-maemo.googlecode.com/ + + + 2 + + + + + True + 8 + 2009 Paul Philippov + + + 3 + + + + + 3 + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + About + + + tab + 3 + False + + + + + + + True + + + True + 0 + + + + 128 + 42 + True + gtk-go-back + + + + + False + + + + + True + 0 + + + + 128 + 42 + True + gtk-apply + + + + + False + 1 + + + + + False + False + 1 + + + + + +