/[gplan]/gplan.in
ViewVC logotype

Contents of /gplan.in

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26