2
# -*- coding: utf-8 -*-
5
__date__ ='$19/02/2012$'
8
# Copyright (C) 2011,2012 Lorenzo Carbonell
9
# lorenzo.carbonell.cerezo@gmail.com
11
# This program is free software: you can redistribute it and/or modify
12
# it under the terms of the GNU General Public License as published by
13
# the Free Software Foundation, either version 3 of the License, or
14
# (at your option) any later version.
16
# This program is distributed in the hope that it will be useful,
17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
# GNU General Public License for more details.
21
# You should have received a copy of the GNU General Public License
22
# along with this program. If not, see <http://www.gnu.org/licenses/>.
27
from gi.repository import Gtk, Gdk
32
from comboboxcalendar import ComboBoxCalendar
33
from hourentry import HourEntry
35
locale.setlocale(locale.LC_ALL, '')
36
gettext.bindtextdomain(comun.APP, comun.LANGDIR)
37
gettext.textdomain(comun.APP)
40
class EventWindow(Gtk.Dialog):
41
def __init__(self, calendars=None, event=None):
42
title = comun.APPNAME + ' | '+_('Calendar')
43
Gtk.Dialog.__init__(self,title,None,Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,(Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT,Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT))
44
self.set_size_request(300, 50)
45
self.set_resizable(False)
46
self.set_icon_from_file(comun.ICON)
47
self.connect('destroy', self.close_application)
49
vbox0 = Gtk.VBox(spacing = 5)
50
vbox0.set_border_width(5)
51
self.get_content_area().add(vbox0)
59
self.button3 = Gtk.ToggleButton()
60
self.button3.set_size_request(40,40)
61
self.button3.set_image(Gtk.Image.new_from_stock(Gtk.STOCK_DELETE, Gtk.IconSize.BUTTON))
62
self.button3.connect('toggled',self.on_button_toggled,3)
63
hbox.pack_end(self.button3,expand=False, fill=False, padding=0)
65
self.button2 = Gtk.ToggleButton()
66
self.button2.set_size_request(40,40)
67
self.button2.set_image(Gtk.Image.new_from_stock(Gtk.STOCK_EDIT, Gtk.IconSize.BUTTON))
68
self.button2.connect('toggled',self.on_button_toggled,2)
69
hbox.pack_end(self.button2,expand=False, fill=False, padding=0)
71
self.button1 = Gtk.ToggleButton()
72
self.button1.set_size_request(40,40)
73
self.button1.set_image(Gtk.Image.new_from_stock(Gtk.STOCK_FIND, Gtk.IconSize.BUTTON))
74
self.button1.connect('toggled',self.on_button_toggled,1)
75
hbox.pack_end(self.button1,expand=False, fill=False, padding=0)
80
table1 = Gtk.Table(rows = 7, columns = 3, homogeneous = False)
81
table1.set_border_width(2)
82
table1.set_col_spacings(2)
83
table1.set_row_spacings(2)
86
label1 = Gtk.Label(_('To calendar')+':')
87
label1.set_alignment(0,.5)
88
table1.attach(label1,0,1,0,1, xoptions = Gtk.AttachOptions.FILL, yoptions = Gtk.AttachOptions.SHRINK)
90
self.liststore = Gtk.ListStore(str,str)
91
if calendars is not None:
92
for calendar in calendars:
93
self.liststore.append([calendar['summary'],calendar['id']])
94
self.entry1 = Gtk.ComboBox.new_with_model(model=self.liststore)
95
renderer_text = Gtk.CellRendererText()
96
self.entry1.pack_start(renderer_text, True)
97
self.entry1.add_attribute(renderer_text, "text", 0)
98
self.entry1.set_active(0)
99
table1.attach(self.entry1,1,3,0,1, xoptions = Gtk.AttachOptions.EXPAND, yoptions = Gtk.AttachOptions.SHRINK)
101
label2 = Gtk.Label(_('Title')+':')
102
label2.set_alignment(0.,0.5)
103
table1.attach(label2,0,1,1,2,xoptions = Gtk.AttachOptions.FILL, yoptions = Gtk.AttachOptions.SHRINK)
105
self.entry2 = Gtk.Entry()
106
self.entry2.set_width_chars(30)
107
table1.attach(self.entry2,1,3,1,2,xoptions = Gtk.AttachOptions.FILL, yoptions = Gtk.AttachOptions.FILL)
109
label3 = Gtk.Label(_('All day event')+':')
110
label3.set_alignment(0.,0.5)
111
table1.attach(label3,0,2,2,3,xoptions = Gtk.AttachOptions.FILL, yoptions = Gtk.AttachOptions.SHRINK)
113
self.entry3 = Gtk.CheckButton()
114
self.entry3.connect('toggled',self.on_check_button_toggled)
115
table1.attach(self.entry3,2,3,2,3,xoptions = Gtk.AttachOptions.FILL, yoptions = Gtk.AttachOptions.FILL)
117
label4 = Gtk.Label(_('Start date')+':')
118
label4.set_alignment(0.,0.5)
119
table1.attach(label4,0,1,3,4,xoptions = Gtk.AttachOptions.FILL, yoptions = Gtk.AttachOptions.SHRINK)
121
self.entry4 = HourEntry()
122
self.entry4.set_visible(True)
123
table1.attach(self.entry4,1,2,3,4,xoptions = Gtk.AttachOptions.FILL, yoptions = Gtk.AttachOptions.FILL)
125
self.entry5 = ComboBoxCalendar(self)
126
table1.attach(self.entry5,2,3,3,4,xoptions = Gtk.AttachOptions.FILL, yoptions = Gtk.AttachOptions.FILL)
128
label5 = Gtk.Label(_('End date')+':')
129
label5.set_alignment(0.,0.5)
130
table1.attach(label5,0,1,4,5,xoptions = Gtk.AttachOptions.FILL, yoptions = Gtk.AttachOptions.SHRINK)
132
self.entry6 = HourEntry()
133
self.entry6.set_visible(True)
134
table1.attach(self.entry6,1,2,4,5,xoptions = Gtk.AttachOptions.FILL, yoptions = Gtk.AttachOptions.FILL)
136
self.entry7 = ComboBoxCalendar(self)
137
table1.attach(self.entry7,2,3,4,5,xoptions = Gtk.AttachOptions.FILL, yoptions = Gtk.AttachOptions.FILL)
139
label6 = Gtk.Label(_('Description')+':')
140
label6.set_alignment(0.,0.5)
141
table1.attach(label6,0,1,5,6,xoptions = Gtk.AttachOptions.FILL, yoptions = Gtk.AttachOptions.SHRINK)
143
scrolledwindow = Gtk.ScrolledWindow()
144
scrolledwindow.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
145
scrolledwindow.set_shadow_type(Gtk.ShadowType.ETCHED_OUT)
146
scrolledwindow.set_size_request(300, 300)
147
table1.attach(scrolledwindow,0,3,6,7,xoptions = Gtk.AttachOptions.FILL, yoptions = Gtk.AttachOptions.FILL)
148
self.entry8 = Gtk.TextView()
149
self.entry8.set_wrap_mode(Gtk.WrapMode.WORD)
150
scrolledwindow.add(self.entry8)
154
if event is not None:
155
self.button1.set_active(True)
156
self.entry1.set_sensitive(False)
157
for i,item in enumerate(self.liststore):
158
if event['calendar_id'] == item[1]:
159
self.entry1.set_active(i)
161
if 'summary' in event.keys():
162
self.entry2.set_text(event['summary'])
163
now = datetime.datetime.now()
164
if 'date' in event['start'].keys():
165
self.entry3.set_active(True)
166
self.entry5.set_date(event.get_start_date(now).date())
167
self.entry7.set_date(event.get_end_date(now).date())
169
self.entry3.set_active(False)
170
self.entry4.set_time(event.get_start_date(now).time())
171
self.entry5.set_date(event.get_start_date(now).date())
172
self.entry6.set_time(event.get_end_date(now).time())
173
self.entry7.set_date(event.get_end_date(now).date())
174
if 'description' in event.keys():
175
self.entry8.get_buffer().set_text(event['description'])
177
anow = (datetime.datetime.now()+datetime.timedelta(days=1)).replace(minute=0)
178
anowd = anow + datetime.timedelta(hours=1)
179
self.entry4.set_time(anow.time())
180
self.entry5.set_date(anow.date())
181
self.entry6.set_time(anowd.time())
182
self.entry7.set_date(anowd.date())
183
self.button2.set_active(True)
184
self.entry1.set_sensitive(True)
185
self.button1.set_sensitive(False)
186
self.button2.set_sensitive(False)
187
self.button3.set_sensitive(False)
189
def on_button_toggled(self,widget,button_index):
190
active = widget.get_active()
192
if button_index == 1:
193
self.button2.set_active(not active)
194
self.button3.set_active(not active)
195
self.set_sensitive(False)
196
elif button_index == 2:
197
self.button1.set_active(not active)
198
self.button3.set_active(not active)
199
self.set_sensitive(True)
200
elif button_index == 3:
201
self.button1.set_active(not active)
202
self.button2.set_active(not active)
203
self.set_sensitive(False)
205
if self.button1.get_active() == False and self.button2.get_active() == False and self.button3.get_active() == False:
206
self.button1.set_active(True)
208
def set_sensitive(self,sensitive,et=False):
210
self.button1.set_sensitive(sensitive)
211
self.button2.set_sensitive(sensitive)
212
self.button3.set_sensitive(sensitive)
213
self.entry2.set_sensitive(sensitive)
214
self.entry3.set_sensitive(sensitive)
215
self.entry4.set_sensitive(sensitive)
216
self.entry5.set_sensitive(sensitive)
217
self.entry6.set_sensitive(sensitive)
218
self.entry7.set_sensitive(sensitive)
219
self.entry8.set_sensitive(sensitive)
220
def on_check_button_toggled(self,widget):
221
is_on = not self.entry3.get_active()
222
self.entry4.set_visible(is_on)
223
self.entry6.set_visible(is_on)
225
def close_application(self,widget):
228
def get_calendar_id(self):
229
tree_iter = self.entry1.get_active_iter()
230
if tree_iter != None:
231
model = self.entry1.get_model()
232
return model[tree_iter][1]
235
def get_summary(self):
236
return self.entry2.get_text()
238
def get_all_day_event(self):
239
return self.entry3.get_active()
241
def get_start_date(self):
242
if self.entry3.get_active():
243
return self.entry5.get_date()
245
adate = self.entry5.get_date()
246
atime = self.entry4.get_time()
247
return datetime.datetime.combine(adate,atime)
249
def get_end_date(self):
250
if self.entry3.get_active():
251
return self.entry7.get_date()
253
adate = self.entry7.get_date()
254
atime = self.entry6.get_time()
255
return datetime.datetime.combine(adate,atime)
257
def get_description(self):
258
tbuffer =self.entry8.get_buffer()
259
inicio = tbuffer.get_start_iter()
260
fin = tbuffer.get_end_iter()
261
description = tbuffer.get_text(inicio,fin,True)
262
if len(description)>0:
266
def get_operation(self):
267
if self.button3.get_active():
269
elif self.button2.get_active():
276
if __name__ == "__main__":
278
if p.run() == Gtk.ResponseType.ACCEPT: