~matias-wilkman/calendar-indicator/fix-1394124

« back to all changes in this revision

Viewing changes to src/addeventwindow.py

  • Committer: Lorenzo Carbonell
  • Date: 2012-11-26 21:13:19 UTC
  • Revision ID: lorenzo.carbonell.cerezo@gmail.com-20121126211319-rwf56ujpxgjmyvxz
Add, edit and delete events

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python3
 
2
# -*- coding: utf-8 -*-
 
3
#
 
4
__author__='atareao'
 
5
__date__ ='$19/02/2012$'
 
6
#
 
7
#
 
8
# Copyright (C) 2011,2012 Lorenzo Carbonell
 
9
# lorenzo.carbonell.cerezo@gmail.com
 
10
#
 
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.
 
15
#
 
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.
 
20
#
 
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/>.
 
23
#
 
24
#
 
25
#
 
26
 
 
27
from gi.repository import Gtk, Gdk
 
28
import locale
 
29
import gettext
 
30
import datetime
 
31
import comun
 
32
from comboboxcalendar import ComboBoxCalendar
 
33
from hourentry import HourEntry
 
34
 
 
35
locale.setlocale(locale.LC_ALL, '')
 
36
gettext.bindtextdomain(comun.APP, comun.LANGDIR)
 
37
gettext.textdomain(comun.APP)
 
38
_ = gettext.gettext
 
39
 
 
40
class AddEventWindow(Gtk.Dialog):
 
41
        def __init__(self, calendars=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)
 
48
                #
 
49
                vbox0 = Gtk.VBox(spacing = 5)
 
50
                vbox0.set_border_width(5)
 
51
                self.get_content_area().add(vbox0)
 
52
                #
 
53
                frame1 = Gtk.Frame()
 
54
                vbox0.add(frame1)
 
55
                #
 
56
                table1 = Gtk.Table(rows = 7, columns = 3, homogeneous = False)
 
57
                table1.set_border_width(2)
 
58
                table1.set_col_spacings(2)
 
59
                table1.set_row_spacings(2)
 
60
                frame1.add(table1)
 
61
                #
 
62
                label1 = Gtk.Label(_('To calendar')+':')
 
63
                label1.set_alignment(0,.5)
 
64
                table1.attach(label1,0,1,0,1, xoptions = Gtk.AttachOptions.FILL, yoptions = Gtk.AttachOptions.SHRINK)
 
65
                #
 
66
                self.liststore = Gtk.ListStore(str,str)         
 
67
                if calendars is not None:
 
68
                        for calendar in calendars:
 
69
                                self.liststore.append(calendar['summary'],calendar['id'])
 
70
                self.entry1 = Gtk.ComboBox.new_with_model(model=self.liststore)
 
71
                renderer_text = Gtk.CellRendererText()
 
72
                self.entry1.pack_start(renderer_text, True)
 
73
                self.entry1.add_attribute(renderer_text, "text", 0)
 
74
                self.entry1.set_active(0)
 
75
                table1.attach(self.entry1,1,3,0,1, xoptions = Gtk.AttachOptions.EXPAND, yoptions = Gtk.AttachOptions.SHRINK)                                            
 
76
                #
 
77
                label2 = Gtk.Label(_('Title')+':')
 
78
                label2.set_alignment(0.,0.5)
 
79
                table1.attach(label2,0,1,1,2,xoptions = Gtk.AttachOptions.FILL, yoptions = Gtk.AttachOptions.SHRINK)
 
80
                
 
81
                self.entry2 = Gtk.Entry()
 
82
                self.entry2.set_width_chars(30)
 
83
                table1.attach(self.entry2,1,3,1,2,xoptions = Gtk.AttachOptions.FILL, yoptions = Gtk.AttachOptions.FILL)
 
84
                #
 
85
                label3 = Gtk.Label(_('All day event')+':')
 
86
                label3.set_alignment(0.,0.5)
 
87
                table1.attach(label3,0,2,2,3,xoptions = Gtk.AttachOptions.FILL, yoptions = Gtk.AttachOptions.SHRINK)
 
88
                
 
89
                self.entry3 = Gtk.CheckButton()
 
90
                self.entry3.connect('toggled',self.on_check_button_toggled)
 
91
                table1.attach(self.entry3,2,3,2,3,xoptions = Gtk.AttachOptions.FILL, yoptions = Gtk.AttachOptions.FILL)         
 
92
                #
 
93
                label4 = Gtk.Label(_('Start date')+':')
 
94
                label4.set_alignment(0.,0.5)
 
95
                table1.attach(label4,0,1,3,4,xoptions = Gtk.AttachOptions.FILL, yoptions = Gtk.AttachOptions.SHRINK)
 
96
                
 
97
                self.entry4 = HourEntry()
 
98
                self.entry4.set_visible(True)
 
99
                table1.attach(self.entry4,1,2,3,4,xoptions = Gtk.AttachOptions.FILL, yoptions = Gtk.AttachOptions.FILL)
 
100
 
 
101
                self.entry5 = ComboBoxCalendar(self)
 
102
                table1.attach(self.entry5,2,3,3,4,xoptions = Gtk.AttachOptions.FILL, yoptions = Gtk.AttachOptions.FILL)
 
103
                #
 
104
                label5 = Gtk.Label(_('End date')+':')
 
105
                label5.set_alignment(0.,0.5)
 
106
                table1.attach(label5,0,1,4,5,xoptions = Gtk.AttachOptions.FILL, yoptions = Gtk.AttachOptions.SHRINK)
 
107
                
 
108
                self.entry6 = HourEntry()
 
109
                self.entry6.set_visible(True)
 
110
                table1.attach(self.entry6,1,2,4,5,xoptions = Gtk.AttachOptions.FILL, yoptions = Gtk.AttachOptions.FILL)
 
111
 
 
112
                self.entry7 = ComboBoxCalendar(self)
 
113
                table1.attach(self.entry7,2,3,4,5,xoptions = Gtk.AttachOptions.FILL, yoptions = Gtk.AttachOptions.FILL)
 
114
                #
 
115
                label6 = Gtk.Label(_('Description')+':')
 
116
                label6.set_alignment(0.,0.5)
 
117
                table1.attach(label6,0,1,5,6,xoptions = Gtk.AttachOptions.FILL, yoptions = Gtk.AttachOptions.SHRINK)            
 
118
                #
 
119
                scrolledwindow = Gtk.ScrolledWindow()
 
120
                scrolledwindow.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
 
121
                scrolledwindow.set_shadow_type(Gtk.ShadowType.ETCHED_OUT)
 
122
                scrolledwindow.set_size_request(300, 300)
 
123
                table1.attach(scrolledwindow,0,3,6,7,xoptions = Gtk.AttachOptions.FILL, yoptions = Gtk.AttachOptions.FILL)
 
124
                self.entry8 = Gtk.TextView()
 
125
                self.entry8.set_wrap_mode(Gtk.WrapMode.WORD)
 
126
                scrolledwindow.add(self.entry8)         
 
127
                #
 
128
                self.show_all()
 
129
        
 
130
        def on_check_button_toggled(self,widget):
 
131
                is_on = not self.entry3.get_active()
 
132
                self.entry4.set_visible(is_on)
 
133
                self.entry6.set_visible(is_on)                  
 
134
        
 
135
        def close_application(self,widget):
 
136
                self.hide()
 
137
        
 
138
        def get_calendar_id(self):
 
139
                tree_iter = self.entry1.get_active_iter()
 
140
                if tree_iter != None:
 
141
                        model = self.entry1.get_model()
 
142
                        return model[tree_iter][1]
 
143
                return None
 
144
 
 
145
        def get_summary(self):
 
146
                return self.entry2.get_text()
 
147
 
 
148
        def get_all_day_event(self):
 
149
                return self.entry3.get_active()
 
150
        
 
151
        def get_start_date(self):
 
152
                if self.entry3.get_active():
 
153
                        return self.entry5.get_date()
 
154
                else:
 
155
                        adate = self.entry5.get_date()
 
156
                        atime = self.entry4.get_time()
 
157
                        return datetime.datetime(adate.year,adate.month,adate.day,atime.hour,atime.minute)
 
158
 
 
159
        def get_end_date(self):
 
160
                if self.entry3.get_active():
 
161
                        return self.entry7.get_date()
 
162
                else:
 
163
                        adate = self.entry7.get_date()
 
164
                        atime = self.entry6.get_time()
 
165
                        return datetime.datetime(adate.year,adate.month,adate.day,atime.hour,atime.minute)
 
166
                        
 
167
        def get_description(self):
 
168
                tbuffer =self.entry8.get_buffer()
 
169
                inicio = tbuffer.get_start_iter()
 
170
                fin = tbuffer.get_end_iter()
 
171
                description = tbuffer.get_text(inicio,fin,True)
 
172
                if len(description)>0:
 
173
                        return description
 
174
                return None
 
175
 
 
176
                                
 
177
 
 
178
if __name__ == "__main__":
 
179
        p = AddEventWindow()
 
180
        if p.run() == Gtk.ResponseType.ACCEPT:
 
181
                pass
 
182
        p.destroy()
 
183
        exit(0)
 
184