-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Michael Shiloh wrote:
> That is a wonderful story. Thanks for sharing!
> 
> So, will the baby be named in some way for Openmoko :-)?
> 
> Thanks for the great story and the great smile, and best of luck!
> 
> Michael

I don't know which will be his/her name, but for sure he/she will know
the story of Openmoko.

Here as attachment (I know it not to much nice to send attachments in a
ML, but are two very little text files :) there are the source of the
program I wrote.

Is not complete, I have still to work a lot on it, but may be someone
may be interested on it (any sugestion is welcome).


Michele Renda
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iEYEARECAAYFAkiIvU0ACgkQSIAU/I6SkT17UQCeKQRk+nZOB3FlAcQ+o0wnyUWD
CIIAmgIIacXfl4CRygFaOD1zlQ4fL1w/
=mGPw
-----END PGP SIGNATURE-----
#       ogino.py
#       
#       Copyright 2008 Michele Renda <[EMAIL PROTECTED]>
#       
#       This program is free software; you can redistribute it and/or modify
#       it under the terms of the GNU General Public License as published by
#       the Free Software Foundation; either version 2 of the License, or
#       (at your option) any later version.
#       
#       This program is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#       GNU General Public License for more details.
#       
#       You should have received a copy of the GNU General Public License
#       along with this program; if not, write to the Free Software
#       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#       MA 02110-1301, USA.
#!/usr/bin/env python



import datetime

class Ogino:
	
	UNKNOW		=  -1
	MESTRUATION	=	0
	NONE		=	1
	LOW			=	2
	HIGH		=	3
	
	def __init__(self, start_date, duration_min, duration_max=None):
		
		
		self.start_date = start_date
		
		self.duration_min	= duration_min
		
		if isinstance(duration_max, int):
			self.duration_max	= duration_max
		else:
			self.duration_max	= duration_min
			
	def getStartDate(self):
		
		return self.start_date
		
	def getEndDateMin(self):
		
		return self.start_date + datetime.timedelta(self.duration_min)
		
	def getEndDateMax(self):
		
		return self.start_date + datetime.timedelta(self.duration_max)
		
		
	def getHighFertilityStartDate(self):
		
		return self.getEndDateMin()     - datetime.timedelta(16)
		
	def getHighFertilityEndDate(self):
		
		return self.getEndDateMax() - datetime.timedelta(12)
		
	def getLowFertilityStartDate(self):
		
		return self.getHighFertilityStartDate() - datetime.timedelta(3)
		
	def getLowFertilityEndDate(self):
		
		return self.getHighFertilityEndDate()   + datetime.timedelta(1)
		
	def getFertilityStatus(self, day):
		
		if day ==  self.getStartDate() or (day >= self.getEndDateMin() and day <= self.getEndDateMax()):
			return self.MESTRUATION
		elif day >= self.getHighFertilityStartDate() and day <= self.getHighFertilityEndDate():
			return self.HIGH
		elif day >= self.getLowFertilityStartDate()  and day <= self.getLowFertilityEndDate() :
			return self.LOW
		elif day >= self.getStartDate() and day <= self.getEndDateMax():
			return self.NONE
		else:
			return self.UNKNOW
		
		
	def getFertilityStatusString(self, day):
		
		ris = self.getFertilityStatus(day)
		
		if   ris == self.UNKNOW:
			return 'UNKNOW'
		elif ris == self.MESTRUATION:
			return 'MESTRUATION'
		elif ris == self.NONE:
			return 'NONE'
		elif ris == self.LOW:
			return 'LOW'
		elif ris == self.HIGH:
			return 'HIGH'
		else:
			return '???'
#       ogino-gtk.py
#       
#       Copyright 2008 Michele Renda <[EMAIL PROTECTED]>
#       
#       This program is free software; you can redistribute it and/or modify
#       it under the terms of the GNU General Public License as published by
#       the Free Software Foundation; either version 2 of the License, or
#       (at your option) any later version.
#       
#       This program is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#       GNU General Public License for more details.
#       
#       You should have received a copy of the GNU General Public License
#       along with this program; if not, write to the Free Software
#       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#       MA 02110-1301, USA.
#!/usr/bin/env python

import pygtk
pygtk.require('2.0')
import gtk

import ogino
from datetime import datetime
from datetime import timedelta

class MessageWindow:
	def __init__(self):
		self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
		self.window.show()

	def main(self):
		gtk.main()
		
		
class MainWindow:
	def __init__(self):
		self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
		self.window.set_title("Ogino")
		self.window.resize(280, 380)
		
		self.window.connect("delete_event", self.delete)
		self.window.connect("destroy_event", self.destroy)


		menu		= self.getMenu()
		input_box	= self.getInputBox()

		self.main_vbox = gtk.VBox(False, 0)
		self.window.add(self.main_vbox)
		
		menu_box = gtk.HBox(False, 0)
		menu_box.pack_start(menu, True)
		
		
		self.main_vbox.pack_start(menu_box,  False,	False);
		self.main_vbox.pack_start(input_box, False);
		#main_vbox.pack_start(table, False,	False, 0);
		
		self.window.show_all()
		
	def getMenu(self):
		
		ui = gtk.UIManager()

		menu = '''<ui>
		<menubar name="MenuBar">
		  <menu action="File">
			<menuitem action="Quit"/>
		  </menu>
		  <menu action="Edit">
			<menuitem action="Preferences"/>
		  </menu>
		</menubar>
		</ui>'''
		
		accel_group = ui.get_accel_group()
		self.window.add_accel_group(accel_group)

		action_group = gtk.ActionGroup('Main')
		action_group.add_actions([
									('Quit', gtk.STOCK_QUIT, '_Quit', None, 'Quit the Program', self.close),
									('File', None, '_File'),
									('Edit', None, '_Edit'),
									('Preferences', gtk.STOCK_PREFERENCES, '_Preferences', '<Control>p', 'Edit preferences')])
		
		ui.insert_action_group(action_group, 0)
		ui.add_ui_from_string(menu)
		
		menu = ui.get_widget('/MenuBar')
		menu.show()
		
		return menu


		
	def getInputBox(self):
		hbox = gtk.HBox(False, 0)
		
		lbl1				= gtk.Label("Last cicle was on: (dd/mm/yyyy)")
		
		self.txt_start_date	= gtk.Entry(10)
		self.txt_start_date.set_text('25/07/2008')
		
#		lbl2				= gtk.Label("(DD/MM/YYYY)")
		lbl3				= gtk.Label("between two cicle there are")
		
		self.txt_duration_min	= gtk.Entry(2)
		self.txt_duration_min.set_width_chars(4)
		self.txt_duration_min.set_text('28')
		
		lbl4				= gtk.Label("from")
		lbl5				= gtk.Label("to")
		
		self.txt_duration_max	= gtk.Entry(2);
		self.txt_duration_max.set_width_chars(4)
		self.txt_duration_max.set_text('28')
		
		lbl6				= gtk.Label("days")
		
		self.table			= None
		
		self.btn_calculate	= gtk.Button("Calculate")
		
		self.btn_calculate.connect('button_release_event', self.btnCalculate, None)

		
		
		table = gtk.Table(5, 5, False)
		
		lbl1.set_alignment(0.0, 0.0)
		#lbl2.set_alignment(0.0, 0.0)

		table.attach(lbl1,					0, 5, 0, 1, gtk.SHRINK, gtk.SHRINK)
		
		table.attach(self.txt_start_date,	1, 4, 1, 2)
		
		table.attach(lbl3, 					0, 5, 2, 3, gtk.SHRINK, gtk.SHRINK)
		
		table.attach(lbl4, 					0, 1, 3, 4, gtk.SHRINK, gtk.SHRINK)
		table.attach(self.txt_duration_min,	1, 2, 3, 4, gtk.SHRINK, gtk.SHRINK)
		table.attach(lbl5, 					2, 3, 3, 4, gtk.SHRINK, gtk.SHRINK)
		table.attach(self.txt_duration_max,	3, 4, 3, 4, gtk.SHRINK, gtk.SHRINK)
		table.attach(lbl6, 					4, 5, 3, 4, gtk.SHRINK, gtk.SHRINK)
		
		table.attach(self.btn_calculate,	0, 5, 4, 5)
		
		#table.set_size_request(0,0)
		#table.size_allocate(gtk.gdk.Rectangle(width=100, height=100))

		return table
		
		
	def getTableBox(self, engine):
		
		self.start_date = engine.getStartDate()
		self.end_date   = engine.getEndDateMax()
		
		# I make the calculation of the first day I have to display and of the last day I have to display too.
		
		# First day of the week Monday
		self.view_start_date = datetime.strptime(self.start_date.strftime('%Y 1 %W'), '%Y %w %W')
		# First day of the week Sunday
		# self.view_start_date = datetime.strptime(self.start_date.strftime('%Y 0 %U'), '%Y %w %U')
		
		# First day of the week Monday
		self.view_end_date = datetime.strptime(self.end_date.strftime('%Y 0 %W'), '%Y %w %W')
		# First day of the week Sunday
		# self.view_end_date = datetime.strptime(self.start_end.strftime('%Y 6 %U'), '%Y %w %W')
		
		
		
		#gtk.gdk
		
		
		num_week = (self.view_end_date - self.view_start_date).days // 7
		table = gtk.Table(num_week + 1, 7, True) # +1 for week label
		
		i = 0;
		d = self.view_start_date
		while d >= self.view_start_date and d <= self.view_start_date + timedelta(6):
			l = gtk.Label(d.strftime('%a'))
			table.attach(l, i, i+1, 0, 1, gtk.SHRINK, gtk.SHRINK)
			d = d + timedelta(1)
			i = i + 1
			
			
		i = 0;
		d = self.view_start_date
		while d >= self.view_start_date and d <= self.view_end_date:
			row = i // 7
			col = i % 7
			
			b = gtk.Button(d.strftime('%d'));
			
			fertility = engine.getFertilityStatus(d) 
			if fertility == engine.MESTRUATION:
				c = gtk.gdk.Color(65535,0,0)
				b.modify_bg(gtk.STATE_NORMAL,		c)
				b.modify_bg(gtk.STATE_PRELIGHT,	c)
				b.modify_bg(gtk.STATE_ACTIVE,		c)
				
			elif fertility == engine.NONE:
				c = gtk.gdk.Color(34000,45000,65535)
				b.modify_bg(gtk.STATE_NORMAL,		c)
				b.modify_bg(gtk.STATE_PRELIGHT,	c)
				b.modify_bg(gtk.STATE_ACTIVE,		c)
				
			elif fertility == engine.LOW:
				c = gtk.gdk.Color(32767,65535,32767)
				b.modify_bg(gtk.STATE_NORMAL,		c)
				b.modify_bg(gtk.STATE_PRELIGHT,	c)
				b.modify_bg(gtk.STATE_ACTIVE,		c)
				
			elif fertility == engine.HIGH:
				c = gtk.gdk.Color(0,56000,0)
				b.modify_bg(gtk.STATE_NORMAL,		c)
				b.modify_bg(gtk.STATE_PRELIGHT,	c)
				b.modify_bg(gtk.STATE_ACTIVE,		c)
				
			b.set_size_request(40,40)
			
			if d.date() == datetime.today().date():
				if b.get_use_stock():
					label = b.child.get_children()[1]
				elif isinstance(b.child, gtk.Label):
					label = b.child
				else:
					raise ValueError("button does not have a label")
									
				label.set_markup('<b>' + d.strftime('%d') + '</b>')
				#label.modify_font(pango.set_weight(pango.WEIGHT_BOLD))


 
			
			table.attach(b, col, col+1, 1+row, 1+row+1, gtk.SHRINK, gtk.SHRINK)
			d = d + timedelta(1)
			i = i + 1
		
		
		
		return table;
		
		
	def btnCalculate(self, widget, event, callback_data ):
		
		self.start_date = datetime.strptime(self.txt_start_date.get_text(), '%d/%m/%Y')
		self.duration_min   = int(self.txt_duration_min.get_text())
		self.duration_max   = int(self.txt_duration_max.get_text())
		
		
		self.engin = ogino.Ogino(self.start_date, self.duration_min, self.duration_max)
		
		if self.table is not None:
			self.table.destroy()
		
		self.table = self.getTableBox(self.engin)
		self.main_vbox.pack_start(self.table, False,	False, 0);
		
		self.table.show()
		self.window.show_all()
		
		
	def main(self):
		gtk.main()
		
	def close(self, widget, data=None):
		gtk.main_quit()
	def delete(self, widget, event, data=None):
		print "delete signal occurred"
		gtk.main_quit()	
	def destroy(self, widget, data=None):
		print "destroy signal occurred"
		gtk.main_quit()

		
	def showMessage(self, message):
		self.window.set_title(message)

  	


if __name__ == "__main__":
	MainWindow().main();
_______________________________________________
Openmoko community mailing list
community@lists.openmoko.org
http://lists.openmoko.org/mailman/listinfo/community

Reply via email to