Go Back   maemo.org - Talk > Software > Applications
 
Register FAQ Community Calendar Today's Posts Search

Notices

Reply
 
Thread Tools
  #1  
Old 2010-04-08, 20:47
xelahu xelahu is offline
 
Join Date: Apr 2010
Posts: 2
Thanks!: 0
Thanked 0 Times in 0 Posts
Default [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?
Reply With Quote
  #2  
Old 2010-04-09, 02:55
CrashandDie CrashandDie is offline
 
Join Date: Apr 2008
Location: France
Posts: 336
Thanks!: 309
Thanked 610 Times in 168 Posts
Default 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

Last edited by CrashandDie; 2010-04-09 at 02:57.
Reply With Quote
The Following User Says Thank You to CrashandDie For This Useful Post:
  #3  
Old 2010-04-13, 01:47
CrashandDie CrashandDie is offline
 
Join Date: Apr 2008
Location: France
Posts: 336
Thanks!: 309
Thanked 610 Times in 168 Posts
Default 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()
Reply With Quote
  #4  
Old 2010-04-13, 09:36
xelahu xelahu is offline
 
Join Date: Apr 2010
Posts: 2
Thanks!: 0
Thanked 0 Times in 0 Posts
Smile Re: Programming a Binary Clock on the N900

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
Attached Images
 

Last edited by xelahu; 2010-04-13 at 09:39.
Reply With Quote
  #5  
Old 2010-04-13, 11:35
CrashandDie CrashandDie is offline
 
Join Date: Apr 2008
Location: France
Posts: 336
Thanks!: 309
Thanked 610 Times in 168 Posts
Default 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.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 18:56.