diff --git a/GooCalendar/Calendar.py b/GooCalendar/Calendar.py index d5cfb107dfe4a5b046970a5319cbd5b857eca644_R29vQ2FsZW5kYXIvQ2FsZW5kYXIucHk=..e39abbe6986537fa6f923360cfa6645a1d43e85c_R29vQ2FsZW5kYXIvQ2FsZW5kYXIucHk= 100644 --- a/GooCalendar/Calendar.py +++ b/GooCalendar/Calendar.py @@ -19,7 +19,7 @@ ZOOM_MONTH = 1 ZOOM_WEEK = 2 - def __init__(self, event_store=None): + def __init__(self, event_store=None, zoom=ZOOM_MONTH): super(Calendar, self).__init__() self.cal = calendar.Calendar(calendar.SUNDAY) self.today = time.localtime(time.time())[:3] @@ -33,5 +33,4 @@ self._event_removed_sigid = None self._event_added_sigid = None self.set_event_store(event_store) - self.days = [None for i in xrange(6 * 7)] self.event_items = [] @@ -37,5 +36,5 @@ self.event_items = [] - self.zoom = self.ZOOM_MONTH + self.zoom = zoom self.set_bounds(0, 0, 200, 200) self.set_flags(gtk.CAN_FOCUS) self.set_events(gtk.gdk.EXPOSURE_MASK @@ -52,6 +51,19 @@ self.connect('size-allocate', self.on_size_allocate) self.connect('key-press-event', self.on_key_press_event) + # Initialize background and days and add them to canvas + root = self.get_root_item() + style = self.get_style() + color = util.color_to_string(style.bg[gtk.STATE_PRELIGHT]) + self.bg_rect = goocanvas.Rect(parent=root, x=0, y=0, \ + stroke_color=color, fill_color=color) + self.days = [] + while len(self.days) < 42: # 6 rows of 7 days + box = DayItem(self) + root.add_child(box) + box.connect('button_press_event', self.on_button_press_event) + self.days.append(box) + def select_from_tuple(self, new_date): old_date = self.selected_date old_day = self.selected_day @@ -162,5 +174,4 @@ self.draw_events() def draw_background(self): - style = self.get_style() x, y, w, h = self.get_bounds() @@ -166,12 +177,6 @@ x, y, w, h = self.get_bounds() - root = self.get_root_item() - color = util.color_to_string(style.bg[gtk.STATE_PRELIGHT]) - if self.bg_rect is not None: - self.bg_rect.set_property('width', w) - self.bg_rect.set_property('height', h) - return - self.bg_rect = goocanvas.Rect(parent=root, x=0, y=0, width=w, height=h, - stroke_color=color, fill_color=color) + self.bg_rect.set_property('width', w) + self.bg_rect.set_property('height', h) def draw_week(self): """ @@ -238,7 +243,6 @@ Draws the currently selected month. """ style = self.get_style() - root = self.get_root_item() x1, y1, w, h = self.get_bounds() day_width = w / 7 day_height = (h - self.line_height) / 6 @@ -287,12 +291,6 @@ # Draw a box for the day. box = self.days[weekno * 7 + dayno] - if box is None: - box = DayItem(self) - root.add_child(box) - box.connect('button_press_event', - self.on_button_press_event) - self.days[weekno * 7 + dayno] = box box.x = day_width * dayno box.y = y_pos box.width = day_width - 2 @@ -403,7 +401,8 @@ day.update() continue - max_y = max((free_line + 2) * day.line_height + 2, max_y) + max_line_height = max(x.line_height for x in days) + max_y = max((free_line + 2) * max_line_height + 2, max_y) for day in days: day.lines[free_line] = 1 diff --git a/GooCalendar/DayItem.py b/GooCalendar/DayItem.py index d5cfb107dfe4a5b046970a5319cbd5b857eca644_R29vQ2FsZW5kYXIvRGF5SXRlbS5weQ==..e39abbe6986537fa6f923360cfa6645a1d43e85c_R29vQ2FsZW5kYXIvRGF5SXRlbS5weQ== 100644 --- a/GooCalendar/DayItem.py +++ b/GooCalendar/DayItem.py @@ -14,13 +14,13 @@ super(DayItem, self).__init__() self.cal = cal - self.x = kwargs.get('x') - self.y = kwargs.get('y') - self.width = kwargs.get('width') - self.height = kwargs.get('height') + self.x = kwargs.get('x', 0) + self.y = kwargs.get('y', 0) + self.width = kwargs.get('width', 0) + self.height = kwargs.get('height', 0) self.border_color = kwargs.get('border_color') self.body_color = kwargs.get('body_color') self.full_border = kwargs.get('full_border') self.date = kwargs.get('date') self.type = kwargs.get('type', 'month') self.show_indic = False @@ -21,10 +21,10 @@ self.border_color = kwargs.get('border_color') self.body_color = kwargs.get('body_color') self.full_border = kwargs.get('full_border') self.date = kwargs.get('date') self.type = kwargs.get('type', 'month') self.show_indic = False - self.line_height = None - self.font_size = None + self.line_height = 0 + self.font_size = 0 self.lines = {} self.n_lines = 0 @@ -29,5 +29,6 @@ self.lines = {} self.n_lines = 0 + self.title_text_color = "" # Create canvas items. self.border = goocanvas.Rect(parent=self) @@ -35,9 +36,6 @@ self.box = goocanvas.Rect(parent=self) self.indic = goocanvas.Rect(parent=self) - if self.x is not None: - self.update() - def update(self): if self.type == 'month': self.font_size = max(self.height / 12, 10) @@ -49,10 +47,13 @@ font_descr = style.font_desc.copy() font_descr.set_absolute_size(self.font_size * pango.SCALE) self.font = font_descr.to_string() - date_tuple = self.date.timetuple()[:3] - week_day = calendar.weekday(*date_tuple) - day_name = calendar.day_name[week_day] - caption = '%s %s' % (date_tuple[2], day_name) + if self.date: + date_tuple = self.date.timetuple()[:3] + week_day = calendar.weekday(*date_tuple) + day_name = calendar.day_name[week_day] + caption = '%s %s' % (date_tuple[2], day_name) + else: + caption = "" # Draw the border. self.border.set_property('x', self.x) @@ -74,8 +75,8 @@ if self.full_border: box_x = self.x + 2 box_y = self.y + self.line_height - box_width = self.width - 4 - box_height = self.height - self.line_height - 3 + box_width = max(self.width - 4, 0) + box_height = max(self.height - self.line_height - 3, 0) else: box_x = self.x + 1 box_y = self.y + self.line_height @@ -79,8 +80,8 @@ else: box_x = self.x + 1 box_y = self.y + self.line_height - box_width = self.width - 2 - box_height = self.height - self.line_height + box_width = max(self.width - 2, 0) + box_height = max(self.height - self.line_height, 0) self.box.set_property('x', box_x) self.box.set_property('y', box_y) self.box.set_property('width', box_width)