/[gplan]/gplan.in
ViewVC logotype

Contents of /gplan.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 13 - (show annotations)
Thu Oct 8 09:20:49 2009 UTC (9 years, 11 months ago) by ben
File size: 3658 byte(s)
removed sys module, unused
1 #!/usr/bin/env python
2 # gplan, copyright 2009 Benoit Rouits <brouits@free.fr>
3 #
4 import pygtk, gtk
5 pygtk.require('2.0')
6 import time, os
7
8 class Application:
9 iconpath = "ICONPATH"
10 def mark_days(self, w):
11 """mark days that have a journal in the current month"""
12 for days in range(1,31):
13 self.calendar.unmark_day(days)
14 year, month, unused = self.calendar.get_date()
15 date = time.mktime((year, month +1, days, 0, 0, 0, 0, 0, -1))
16 filename = time.strftime("%Y-%m-%d" + ".txt", time.localtime(date))
17 filename = os.path.join(self.work, filename)
18 if os.access(filename, os.F_OK):
19 self.calendar.mark_day(days)
20
21 def get_plan_for(self, w):
22 """get a journal for the date specified by the calendar"""
23 year, month, day = self.calendar.get_date()
24 date = time.mktime((year, month +1, day, 0, 0, 0, 0, 0, -1))
25 filename = time.strftime("%Y-%m-%d" + ".txt", time.localtime(date))
26 filename = os.path.join(self.work, filename)
27 try:
28 filehandler = open (filename, "r")
29 text = "".join(filehandler.readlines())
30 self.buffer.set_text(text)
31 filehandler.close()
32 except IOError:
33 self.buffer.set_text("")
34 return
35
36 def set_plan_for(self, w):
37 """save a journal in work directory"""
38 year, month, day = self.calendar.get_date()
39 date = time.mktime((year, month +1, day, 0, 0, 0, 0, 0, -1))
40 filename = time.strftime("%Y-%m-%d" + ".txt", time.localtime(date))
41 filename = os.path.join(self.work, filename)
42 try:
43 filehandler = open (filename, "w")
44 except IOError:
45 filehandler = open(filename, "a").close()
46 filehandler = open(filename, "w")
47 start, end = self.buffer.get_bounds()
48 text = self.buffer.get_text(start, end)
49 filehandler.write(text)
50 filehandler.close()
51 if start.is_end():
52 os.unlink(filename)
53 self.mark_days(self.calendar)
54 return
55
56 def __init__(self):
57 """build the main window and init the application"""
58 #main window
59 self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
60 self.window.set_title("Gplan")
61 self.window.set_border_width(5)
62 self.window.connect("destroy", lambda x: gtk.main_quit())
63 self.window.set_default_size(470, 200)
64 self.window.set_resizable(True)
65 self.window.set_icon_from_file(self.iconpath);
66 #main vbox
67 self.vbox = gtk.VBox(False, 10)
68 self.window.add(self.vbox)
69 #hbox in vbox
70 self.hbox = gtk.HBox(False, 10)
71 self.vbox.pack_start(self.hbox, True, True, 10)
72 #calendar in hbox
73 self.calendar = gtk.Calendar()
74 self.hbox.pack_start(self.calendar, False, False, 10)
75 #textview in hbox
76 self.buffer = gtk.TextBuffer(None)
77 self.buffer.set_text("")
78 self.textview = gtk.TextView()
79 self.textview.set_buffer(self.buffer)
80 self.textview.set_editable(True)
81 self.textview.set_wrap_mode(gtk.WRAP_WORD)
82 self.hbox.pack_start(self.textview, True, True, 10)
83 #buttons in vbox
84 self.buttons = gtk.HButtonBox()
85 self.vbox.pack_start(self.buttons, False, False, 10)
86 self.buttons.set_layout(gtk.BUTTONBOX_SPREAD)
87 self.buttons.set_spacing(5)
88 self.close = gtk.Button(None,gtk.STOCK_CLOSE)
89 self.close.connect("clicked", lambda w: gtk.main_quit())
90 self.buttons.add(self.close)
91 self.ok = gtk.Button(None, gtk.STOCK_OK)
92 self.ok.connect("clicked", self.set_plan_for)
93 self.buttons.add(self.ok)
94 #handler conections
95 self.calendar.connect("day_selected", self.get_plan_for)
96 self.calendar.connect("month-changed", self.mark_days)
97 self.window.show_all()
98 #initialization
99 self.work = os.path.join(os.getenv("HOME"), ".gplan")
100 if not os.access(self.work, os.F_OK):
101 os.mkdir(self.work)
102 self.mark_days(self.calendar)
103 #default date is today
104 self.get_plan_for(self.calendar)
105
106 if __name__ == "__main__":
107 app = Application()
108 gtk.main()
109

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26