maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Applications (https://talk.maemo.org/forumdisplay.php?f=41)
-   -   [Maemo 5] Binary Clock on the N900? (https://talk.maemo.org/showthread.php?t=49553)

xelahu 2010-04-08 20:47

[Maemo 5] Binary Clock on the N900?
 
unfortunaly I am not able to do that. But I think it will look great. Can somebody do this?

CrashandDie 2010-04-09 02:55

Re: Programming a Binary Clock on the N900
 
Code:

#!/bin/python

VERBOSE_MODE = True # Set to False for no information.

import time

class BinaryClock:
        t = time.time()
        localtime = time.localtime(t)
       
        def display(self, verbose = False):
                hour = str(self.localtime[3])
                minute = str(self.localtime[4])
                second = str(self.localtime[5])

                hms = (hour, minute, second)
               
                for line in reversed(range(4)):
                        if verbose:
                                timeline = "%s  " % (1 << line)
                        else:
                                timeline = ""
                       
                        for tt in hms:
                                if len(tt) == 1:
                                        tt = "0" + tt
                                       
                                for i in range(2):
                                        if self.bit_at_p(int(tt[i]), line) == 1:
                                                timeline += "*"
                                        else:
                                                timeline += " "
                                               
                                timeline += "  "
                                       
                        print timeline
                       
                if verbose:
                        print "    %s%s : %s%s : %s%s" % (hour[0], hour[1], minute[0], minute[1], second[0], second[1])
                       
        def bit_at_p(self, N, p):
                dis = 1 << p
                x = N & dis
               
                return int(x > 0)

bc = BinaryClock()
bc.display(VERBOSE_MODE)

Done.

Sample output:

Silent mode:

Code:

    **    *
 *    *  *
*    **    *

Verbose mode:
Code:

8              *
4        **
2    *
1  *    **  **
    12 : 55 : 19


CrashandDie 2010-04-13 01:47

Re: Programming a Binary Clock on the N900
 
Updated version

Code:

#!/bin/python

VERBOSE_MODE = True # Set to False for no information.

import time

class BinaryClock:
        localtime = time.localtime(time.time())
       
        def display(self, verbose = False):
                hms = (self.pad_zero(self.localtime[3]), self.pad_zero(self.localtime[4]), self.pad_zero(self.localtime[5]))
               
                for line in reversed(range(4)):
                        if verbose:
                                timeline = "%s  " % (1 << line)
                        else:
                                timeline = ""
                       
                        for tt in hms:
                                for i in range(2):
                                        if self.bit_at_p(int(tt[i]), line) == 1:
                                                timeline += "*"
                                        else:
                                                timeline += " "
                                               
                                timeline += "  "
                                       
                        print timeline
                       
                if verbose:
                        print "    %s%s : %s%s : %s%s" % (hms[0][0], hms[0][1], hms[1][0], hms[1][1], hms[2][0], hms[2][1])
                       
        def bit_at_p(self, N, p):
                dis = 1 << p
                x = N & dis
               
                return int(x > 0)
               
        def update(self):
                self.localtime = time.localtime(time.time())
               
        def pad_zero(self, tt):
                tt = str(tt)
               
                if len(tt) == 1:
                        return "0" + tt
               
                else:
                        return tt

               
bc = BinaryClock()

while True:
        print "\n" * 24
        bc.display(VERBOSE_MODE)
        time.sleep(1)
        bc.update()


xelahu 2010-04-13 09:36

Re: Programming a Binary Clock on the N900
 
1 Attachment(s)
Thank you very much for the Code :-). But i ment that I am not able to Programm for the N900. I made a Picture for a Binary Clock (Example).

This would be nice. Can somebody do that?
Xelahu

CrashandDie 2010-04-13 11:35

Re: Programming a Binary Clock on the N900
 
Save the code to a file (binaryclock.py), and in the X-Terminal, run:

python binaryclock.py

It will show the above, without the fancy graphics. I haven't done any graphical programming on the N900 lately, so wouldn't be able to make it run with a nice frontend as you shown above, but the initial idea is there.

If anyone can point me to an easy tutorial on how to use Qt/Widget with python, I'd be happy to give it a shot. If anyone fancies writing a GTK frontend to it, please, join in, the more the merrier.


All times are GMT. The time now is 20:00.

vBulletin® Version 3.8.8