Exemple #1
0
    def display(self, group):
        def is_date_only(value):
            return (isinstance(value, datetime.date)
                and not isinstance(value, datetime.datetime))
        dtstart = self.attrs['dtstart']
        dtend = self.attrs.get('dtend')
        if self.view_calendar.record:
            record = self.view_calendar.record
            date = record[dtstart].get(record)
            if date:  # select the day of the current record
                self.select(date)

        event_store = goocalendar.EventStore()

        model_access = MODELACCESS[self.view_calendar.screen.model_name]
        editable = (
            bool(int(self.view_calendar.attributes.get('editable', 1)))
            and model_access['write'])

        for record in group:
            if not record[dtstart].get(record):
                continue

            start = record[dtstart].get_client(record)
            record[dtstart].state_set(record)
            if dtend:
                end = record[dtend].get_client(record)
                record[dtend].state_set(record)
            else:
                end = None
            midnight = datetime.time(0)
            all_day = is_date_only(start) and (not end or is_date_only(end))
            if not isinstance(start, datetime.datetime):
                start = datetime.datetime.combine(start, midnight)
            if end and not isinstance(end, datetime.datetime):
                end = datetime.datetime.combine(end, midnight)

            # Skip invalid event
            if end is not None and start > end:
                continue

            text_color, bg_color = self.get_colors(record)
            label = '\n'.join(record[attrs['name']].get_client(record)
                for attrs in self.fields).rstrip()
            event_editable = (
                editable
                and not record[dtstart].get_state_attrs(record).get(
                    'readonly', False)
                and (not dtend
                    or not record[dtend].get_state_attrs(record).get(
                        'readonly', False)))
            event = goocalendar.Event(label, start, end, text_color=text_color,
                bg_color=bg_color, all_day=all_day, editable=event_editable)
            event.record = record
            event_store.add(event)
        self.event_store = event_store

        self.grab_focus(self.get_root_item())
Exemple #2
0
 def __init__(self):
     self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
     event_store = goocalendar.EventStore()
     calendar = goocalendar.Calendar(event_store)
     for occurrence in kopano.User(sys.argv[1]).calendar.occurrences():
         event = goocalendar.Event(caption=occurrence.subject, start=occurrence.start, end=occurrence.end)
         event_store.add(event)
     calendar.show()
     self.window.add(calendar)
     self.window.show()
Exemple #3
0
    def display(self, group):
        attrs = common.node_attributes(self.root_node)
        dtstart = attrs.get('dtstart')
        dtend = attrs.get('dtend') or dtstart
        if self.screen.current_record:
            record = self.screen.current_record
            date = record[dtstart].get(record)
            if date:  # select the day of the current record
                self.select(date)

        if self._event_store:
            self._event_store.clear()
        else:
            event_store = goocalendar.EventStore()
            self.event_store = event_store

        fields = []
        for node in self.root_node.childNodes:
            if not node.nodeType == node.ELEMENT_NODE:
                continue
            if node.localName == 'field':
                attrs = common.node_attributes(node)
                fields.append(attrs.get('name'))

        for record in group:
            if not record[dtstart].get(record):
                continue

            start = record[dtstart].get_client(record)
            end = record[dtend].get_client(record)
            midnight = datetime.time(0)
            all_day = False
            if not isinstance(start, datetime.datetime):
                start = datetime.datetime.combine(start, midnight)
            if end and not isinstance(end, datetime.datetime):
                end = datetime.datetime.combine(end, midnight)
                all_day = True
            elif not end:
                all_day = True

            # TODO define color code
            label = '\n'.join(record[name].get_client(record)
                              for name in fields).rstrip()
            event = goocalendar.Event(label,
                                      start,
                                      end,
                                      bg_color='lightblue',
                                      all_day=all_day)
            event.record = record
            self._event_store.add(event)

        self.grab_focus(self.get_root_item())
    def display(self, group):
        dtstart = self.attrs['dtstart']
        dtend = self.attrs.get('dtend')
        if self.screen.current_record:
            record = self.screen.current_record
            date = record[dtstart].get(record)
            if date:  # select the day of the current record
                self.select(date)

        if self._event_store:
            self._event_store.clear()
        else:
            event_store = goocalendar.EventStore()
            self.event_store = event_store

        for record in group:
            if not record[dtstart].get(record):
                continue

            start = record[dtstart].get_client(record)
            if dtend:
                end = record[dtend].get_client(record)
            else:
                end = None
            midnight = datetime.time(0)
            all_day = False
            if not isinstance(start, datetime.datetime):
                start = datetime.datetime.combine(start, midnight)
            if end and not isinstance(end, datetime.datetime):
                end = datetime.datetime.combine(end, midnight)
                all_day = True
            elif not end:
                all_day = True

            # Skip invalid event
            if end is not None and start > end:
                continue

            text_color, bg_color = self.get_colors(record)
            label = '\n'.join(record[attrs['name']].get_client(record)
                              for attrs in self.fields).rstrip()
            event = goocalendar.Event(label,
                                      start,
                                      end,
                                      text_color=text_color,
                                      bg_color=bg_color,
                                      all_day=all_day)
            event.record = record
            self._event_store.add(event)

        self.grab_focus(self.get_root_item())
Exemple #5
0
def on_day_selected(calendar, day):
    print "Day %s was selected" % day


def on_key_pressed(widget, event):
    if (event.state & gtk.gdk.CONTROL_MASK
            and event.keyval == gtk.gdk.keyval_from_name('l')):
        if widget.view == 'week':
            widget.set_view('month')
        else:
            widget.set_view('week')


window = gtk.Window()
event_store = goocalendar.EventStore()
calendar = goocalendar.Calendar(event_store)
calendar.set_has_tooltip(True)

# Normal events.
event = goocalendar.Event('Event number 1',
                          datetime.datetime(2007, 10, 8, 02),
                          datetime.datetime(2007, 10, 8, 17),
                          bg_color='lightgreen')
event_store.add(event)
event = goocalendar.Event('Event number 2',
                          datetime.datetime(2007, 10, 8, 12),
                          datetime.datetime(2007, 10, 8, 14),
                          bg_color='lightblue')
event_store.add(event)
event = goocalendar.Event('Event number 3',