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

« back to all changes in this revision

Viewing changes to src/hourentry.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: iso-8859-15 -*-
 
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
 
28
import datetime
 
29
 
 
30
class HourEntry(Gtk.HBox):
 
31
        def __init__(self,value=None):
 
32
                Gtk.HBox.__init__(self)
 
33
                self.set_no_show_all(True)
 
34
                self.hour = Gtk.SpinButton()
 
35
                self.hour.set_width_chars(2)
 
36
                self.hour.set_adjustment(Gtk.Adjustment(value=0, lower=0, upper=23, step_incr=1, page_incr=5))
 
37
                self.hour.set_digits(0)         
 
38
                self.minute = Gtk.SpinButton()
 
39
                self.minute.set_width_chars(2)
 
40
                self.minute.set_adjustment(Gtk.Adjustment(value=0, lower=0, upper=59, step_incr=5, page_incr=10))
 
41
                self.minute.set_digits(0)
 
42
                self.pack_start(self.hour, 0, 0, 0)
 
43
                self.label = Gtk.Label(':')
 
44
                self.pack_start(self.label, 0, 0, 0)
 
45
                self.pack_start(self.minute, 0, 0, 0)
 
46
 
 
47
        def set_editable(self,editable):
 
48
                self.hour.set_editable(editable)
 
49
                self.minute.set_editable(editable)
 
50
        
 
51
        def set_sensitive(self,sensitive):
 
52
                self.hour.set_sensitive(sensitive)
 
53
                self.minute.set_sensitive(sensitive)
 
54
 
 
55
        def set_visible(self,visible):
 
56
                if visible:
 
57
                        self.show()
 
58
                        self.hour.show_all()
 
59
                        self.minute.show_all()
 
60
                        self.label.show_all()
 
61
                else:
 
62
                        self.hide()                     
 
63
 
 
64
        def get_time(self):
 
65
                h = self.hour.get_value_as_int()
 
66
                m = self.minute.get_value_as_int()
 
67
                return datetime.time(h,m)
 
68
        
 
69
        def set_time(self,time):
 
70
                self.hour.set_value(time.hour)
 
71
                self.minute.set_value(time.minute)
 
72