maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Applications (https://talk.maemo.org/forumdisplay.php?f=41)
-   -   [Support thread] Billboard Standby Screen (https://talk.maemo.org/showthread.php?t=84507)

slarti 2013-01-12 09:30

Re: [Support thread] Billboard Standby Screen
 
Quote:

Originally Posted by Win7Mac (Post 1313922)
Big thanks slarti! :cool:

I couldn't get it to work by simply adding import sys at the top too. So what about the syntax errors?

You wrote the command in shell, not in the python interpreter. If you add import sys to where import dbus is and run the modified script with:
Code:

python myscript.py
it will tell you where the problem is.

Quote:

Originally Posted by Win7Mac (Post 1313922)
Yeah! Now I got the picture about the special chars in python. Works great. :)

Great!

Quote:

Originally Posted by Win7Mac (Post 1313922)
Almost done now, just get rid of the 'No alarms' msg in a way that the line in BB disappears (and won't leave a blank line), if there's no alarm. Add the second alarm probably?

Just replace the command that prints the "No alarms" with pass.

I'll have to think about the second alarm. I'm only learning python and scripting myself and this script was meant for just the next one. It sorts the alarms chronologically and prints the next one (from now) in the list. It could print the next two but then this next part would be more difficult:

Quote:

Originally Posted by Win7Mac (Post 1313922)
Edit: I'm already using your script for short weekday, could this be implemented in the above script to adopt to my language? I prefer short weekday very much over the "+1" from {events}, good idea!

I added a "translator" to this version and changed the No alarms part to what you wanted. It's in finnish, though, so you'll have to change abb_weekdays to what you want. Just make sure you start from sunday.

Code:

#!/usr/bin/python

import dbus
from datetime import datetime, timedelta
import time

bus = dbus.SystemBus()

time_obj = bus.get_object('com.nokia.time', '/com/nokia/time')
time_intf = dbus.Interface(time_obj, 'com.nokia.time')

cookies = time_intf.get_cookies_by_attributes({'enabled': '1'})
today = datetime.now()
tomorrow = today + timedelta(days=1)

def list_queued_alarms():
    for cookie in cookies:
        attributes = time_intf.query_attributes(cookie)
        alarmtime = attributes['alarmtime']
        if attributes['STATE'] == 'QUEUED':
            if 'recurrence' in attributes:
                days = tuple(attributes['recurrence'])
            else:
                if datetime.time(datetime.strptime(alarmtime, ("%H:%M"))) > datetime.time(datetime.now()):
                    days = time.strftime("%w")
                else:
                    days = tomorrow.strftime("%w")
            weekdays = dict([(day, time.strptime((day + " " + alarmtime),'%w %H:%M' )) for day in days])
            for day in days:
                yield ' '.join((day,time.strftime('%H:%M',weekdays[day]),attributes['TITLE']))


findme_list = [' '.join((time.strftime('%w %H:%M'),'findme'))]
L = list(list_queued_alarms()) + findme_list
L.sort()
findme_string = ' '.join((time.strftime('%w %H:%M'),'findme'))
findme_int = L.index(findme_string)
if len(L) == 1:
    pass
else:
    if findme_int == (len(L) - 1):
        next_alarm = L[0]
    else:
        next_alarm = L[findme_int + 1]

abb_weekdays = ['Su','Ma','Ti','Ke','To','Pe','La']
next_alarm_list = next_alarm.split(' ' ,1)

print ' '.join((abb_weekdays[int(next_alarm_list[0])],next_alarm_list[1])).encode('utf-8') + '\xe2\x98\x9a'


Win7Mac 2013-01-13 02:04

Re: [Support thread] Billboard Standby Screen
 
1 Attachment(s)
Quote:

Originally Posted by coderus (Post 1313951)
its sh-bang.

Thanks, so it is always required, right?

Quote:

Originally Posted by slarti (Post 1313995)
You wrote the command in shell, not in the python interpreter. If you add import sys to where import dbus is and run the modified script with:
Code:

python myscript.py
it will tell you where the problem is.

Ah, ok. Included import sys and it works in terminal and BB now.
So the syntax errors can be ignored?

I'll settle for your edited script if I can't resolve this multi-line fields issue, many thanks for that.

Quote:

Originally Posted by thp (Post 1313659)
Yes, {{color}} only goes to the end of the current line for now. What you could do is set the global color to blue, and then prefix every line that you don't want to have in blue with the desired color. At least this works as long as you don't have any other multi-line fields (for scripts, you can modify them to output the color prefix on every line).

That works, with mentioned limitations.
I tried to place {{color}} and add special characters in several places in upcoming_alarms.py without success, where does it belong?

Here's a screenshot, so you get a better idea what I'm trying to achieve:

slarti 2013-01-13 09:37

Re: [Support thread] Billboard Standby Screen
 
I just realised that the alarm trigger timestamps and cookies ARE in the contextkit. I'll write a much simpler script later today.

slarti 2013-01-14 13:59

Re: [Support thread] Billboard Standby Screen
 
Ok, took a bit longer than I thought but here is the *Ultimate Customizable Alarm Attribute Getter*™

It's a lot more accurate than the ones before because it gets the times directly from the contextkit timestamps so they are always correct and in order. It even shows when an alarm will go off again after pressing snooze.

Just follow the instructions in the comments and print out anything about an alarm or alarms.

Code:

#!/usr/bin/python
# Print various attributes of alarm(s) by modifying the last line
# Author: Slarti

import dbus
from datetime import datetime, timedelta, date

bus = dbus.SystemBus()

time_obj = bus.get_object('com.nokia.time', '/com/nokia/time')
time_intf = dbus.Interface(time_obj, 'com.nokia.time')
alarm_obj = bus.get_object('com.nokia.time', '/org/maemo/contextkit/Alarm/Trigger')
alarms = alarm_obj.Get(dbus_interface='org.maemo.contextkit.Property')[0]
cookies = alarms[0].keys()
alarms_list = []
for cookie in cookies:
        timestamp = alarms[0][cookie]
        attributes = time_intf.query_attributes(cookie)
        alarms_list.append(((timestamp,cookie,attributes)))

alarms_list.sort()

# Change these to your own language in the order
# they are in if you want to print the weekday:

abb_weekdays = ['Mon','Tue','Wed','Thu','Fri','Sat','Sun']

# Choose the limit for the number of alarms (lines) to print:

limit = 5

# Don't touch this:

if len(alarms_list) < limit:
        limit = len(alarms_list)

# This generates what to print on every line:

for i in range(limit):

# Don't touch this:

        alarm_timestamp = datetime.fromtimestamp((alarms_list[i][0])/1000000000)

# You can choose from these:

        weekday = abb_weekdays[date.weekday(alarm_timestamp)]
        title = alarms_list[i][2]['TITLE']
        alarmtime = datetime.strftime(alarm_timestamp,"%H:%M")
        time_to_alarm = ':'.join(str(alarm_timestamp - datetime.now()).split(':')[:2])
        snooze = alarms_list[i][2]['snooze']+'min'

# This is the special character. Look for the Python source code
# string at e.g. http://www.fileformat.info/info/unicode/block/index.htm

        sc = u"\u2691"

# Here you can decide what to print in which order:

        print (weekday+' '+title+' '+alarmtime+' '+time_to_alarm+' '+snooze+' '+sc).encode('utf-8')


Win7Mac 2013-01-14 15:37

Re: [Support thread] Billboard Standby Screen
 
Whow... now we're talking... :D
Great job, very cool! :cool:
I wish we could have this for events.

Only thing left: where to put the {{color}} tag in the script for all alarms?

@thp: a button to update/refresh all info would be nice.
Actually I start/close music player every time...

coderus 2013-01-14 15:41

Re: [Support thread] Billboard Standby Screen
 
look for update script and use it with profilematic

slarti 2013-01-14 16:03

Re: [Support thread] Billboard Standby Screen
 
Quote:

Originally Posted by Win7Mac (Post 1314738)
Whow... now we're talking... :D
Great job, very cool! :cool:
I wish we could have this for events.

Thanks.

It's possible to get the cookies for the queued events, too. Might be doable with some changes. What attributes would have to be included?

Quote:

Originally Posted by Win7Mac (Post 1314738)
Only thing left: where to put the {{color}} tag in the script for all alarms?

Anywhere on the last line. You just have to surround it with quotes. If you want the whole line(s) to be green, put it in the front.

Example:

Code:

print ('{{green}}'+weekday+' '+title+' '+alarmtime+' '+time_to_alarm+' '+snooze+' '+sc).encode('utf-8')

Win7Mac 2013-01-14 16:32

Re: [Support thread] Billboard Standby Screen
 
Quote:

Originally Posted by coderus (Post 1314740)
look for update script and use it with profilematic

OK, so I found this and ran in terminal:
Code:

text=$(gconftool -g /apps/billboard/text)
gconftool -s -t string /apps/billboard/text "{{white}}Updating..."
gconftool -s -t string /apps/billboard/text "${text}"

and now my LPS shows "Updating..." - not so great! :(
The text in BB is still there, but it's not showing anymore.
I also tried without the middle line, but it remains telling me "Updating..."
Could you please provide a fix and the correct code for terminal too?

Quote:

Originally Posted by slarti (Post 1314754)
It's possible to get the cookies for the queued events, too. Might be doable with some changes. What attributes would have to be included?

Just the way you have it put in the *Ultimate Customizable Alarm Attribute Getter*™... :D

Quote:

Originally Posted by slarti (Post 1314754)
Anywhere on the last line. You just have to surround it with quotes. If you want the whole line(s) to be green, put it in the front.

Ah, I didn't know about the additional quotes.
Too bad actually I can't test it, because of the above issue...

slarti 2013-01-14 18:14

Re: [Support thread] Billboard Standby Screen
 
Quote:

Originally Posted by Win7Mac (Post 1314765)
The text in BB is still there, but it's not showing anymore.
I also tried without the middle line, but it remains telling me "Updating..."
Could you please provide a fix and the correct code for terminal too?

If you haven't fixed this already and billboard still shows you your own text in the app (which I doubt), copy it all and in terminal write:

Code:

gconftool -s -t string /apps/billboard/text "PASTE YOUR TEXT HERE"
Coderus' script takes the gconf value that gets written by Billboard and stores it in the variable $text. Then it replaces that value in gconf with "Updating..." and immediately after that it writes over that with the original text. This forces an update in Billboard. It works like a charm but probably the last command didn't get executed when you tried it in terminal. It should be used as a script so that all commands get executed.

As your original text is probably lost, you'll just have to write it again...:(

Win7Mac 2013-01-14 18:58

Re: [Support thread] Billboard Standby Screen
 
BIG BIG THANKS SLARTI! :)
Works again, text was still there in BB. I started editing in there and whoops, it came back...
And after disabling and reenabling other logo and meecast appearence settings, the meecast logo came back too... :D

So, for use in terminal is this script usable or does it have to be modified?
Anyway, a button in BB would be way more comfortable, not only for Linux-noobs like me... ;)

slarti, your script works great, I love it!


All times are GMT. The time now is 08:44.

vBulletin® Version 3.8.8