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

« back to all changes in this revision

Viewing changes to src/addcalendarwindow.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 os
 
29
import shutil
 
30
import locale
 
31
import gettext
 
32
import datetime
 
33
from configurator import Configuration
 
34
from googlecalendarapi import GoogleCalendar
 
35
from logindialog import LoginDialog
 
36
import comun
 
37
 
 
38
locale.setlocale(locale.LC_ALL, '')
 
39
gettext.bindtextdomain(comun.APP, comun.LANGDIR)
 
40
gettext.textdomain(comun.APP)
 
41
_ = gettext.gettext
 
42
 
 
43
DAY_OF_WEEK = [_('Monday'),_('Tuesday'),_('Wednesday'),_('Thursday'),_('Friday'),_('Saturday'),_('Sunday')]
 
44
 
 
45
def first_day_of_month(adatetime):
 
46
        adatetime = adatetime.replace(day=1)
 
47
        return adatetime.weekday()
 
48
 
 
49
class DayWidget(Gtk.VBox):
 
50
        def __init__(self,adate=None):
 
51
                Gtk.VBox.__init__(self)
 
52
                self.set_size_request(150, 100)
 
53
                scrolledwindow = Gtk.ScrolledWindow()
 
54
                scrolledwindow.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
 
55
                scrolledwindow.set_shadow_type(Gtk.ShadowType.ETCHED_OUT)               
 
56
                self.pack_start(scrolledwindow,True,True,0)
 
57
                self.store = Gtk.ListStore(str, object,str)
 
58
                self.treeview = Gtk.TreeView(self.store)
 
59
                self.column = Gtk.TreeViewColumn('',  Gtk.CellRendererText(), text=0, background=2)
 
60
                self.treeview.append_column(self.column)
 
61
                scrolledwindow.add(self.treeview)
 
62
                if adate is not None:
 
63
                        self.set_date(adate)            
 
64
 
 
65
        def set_date(self,adate):
 
66
                self.adate = adate
 
67
                self.column.set_title(str(adate.day))
 
68
 
 
69
        def get_date(self):
 
70
                return self.adate
 
71
                
 
72
        def clear(self):
 
73
                self.store.clear()
 
74
                
 
75
        def set_events(self,events):
 
76
                configuration = Configuration()
 
77
                self.store.clear()
 
78
                for event in events:
 
79
                        label = ''
 
80
                        if 'summary' in event.keys():
 
81
                                label = event['summary']
 
82
                        if configuration.has(event['calendar_id']):
 
83
                                color = configuration.get(event['calendar_id'])
 
84
                        else:
 
85
                                color = '#AFDEDF'
 
86
                        self.store.append([label,event,color])
 
87
        def set_background_color(self,color):
 
88
                self.treeview.modify_bg(Gtk.StateType.NORMAL, color)
 
89
        
 
90
                
 
91
class AddCalendarWindow(Gtk.Dialog):
 
92
        def __init__(self):
 
93
                title = comun.APPNAME + ' | '+_('Calendar')
 
94
                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))
 
95
                self.set_size_request(300, 50)
 
96
                self.set_resizable(False)
 
97
                self.set_icon_from_file(comun.ICON)
 
98
                self.connect('destroy', self.close_application)
 
99
                #
 
100
                vbox0 = Gtk.VBox(spacing = 5)
 
101
                vbox0.set_border_width(5)
 
102
                self.get_content_area().add(vbox0)
 
103
                #
 
104
                frame1 = Gtk.Frame()
 
105
                vbox0.add(frame1)
 
106
                #
 
107
                table1 = Gtk.Table(rows = 1, columns = 2, homogeneous = False)
 
108
                table1.set_border_width(2)
 
109
                table1.set_col_spacings(2)
 
110
                table1.set_row_spacings(2)
 
111
                frame1.add(table1)
 
112
                #
 
113
                label = Gtk.Label(_('Calendar name')+':')
 
114
                label.set_alignment(0.,0.5)
 
115
                table1.attach(label,0,1,0,1,xoptions = Gtk.AttachOptions.SHRINK, yoptions = Gtk.AttachOptions.SHRINK)
 
116
                
 
117
                self.entry = Gtk.Entry()
 
118
                self.entry.set_width_chars(30)
 
119
                table1.attach(self.entry,1,2,0,1,xoptions = Gtk.AttachOptions.FILL, yoptions = Gtk.AttachOptions.FILL)
 
120
                #
 
121
                self.show_all()
 
122
 
 
123
        def close_application(self,widget):
 
124
                self.ok = False
 
125
        
 
126
if __name__ == "__main__":
 
127
        p = AddCalendarWindow()
 
128
        if p.run() == Gtk.ResponseType.ACCEPT:
 
129
                pass
 
130
        p.destroy()
 
131
        exit(0)
 
132