コード例 #1
0
    def __init__(self):
        if dbus.SessionBus().request_name(
                "es.atareao.calendar-indicator"
        ) != dbus.bus.REQUEST_NAME_REPLY_PRIMARY_OWNER:
            print("application already running")
            exit(0)
        self.indicator = appindicator.Indicator.new(
            'Calendar-Indicator', 'Calendar-Indicator',
            appindicator.IndicatorCategory.APPLICATION_STATUS)
        self.notification = Notify.Notification.new('', '', None)
        self.googlecalendar = GoogleCalendar(token_file=comun.TOKEN_FILE)
        error = True
        while (error):
            if self.googlecalendar.do_refresh_authorization() is None:
                p = Preferences()
                if p.run() == Gtk.ResponseType.ACCEPT:
                    p.save_preferences()
                p.destroy()
                self.googlecalendar = GoogleCalendar(
                    token_file=comun.TOKEN_FILE)
                if (not os.path.exists(comun.TOKEN_FILE)) or (
                        self.googlecalendar.do_refresh_authorization() is
                        None):
                    md = Gtk.MessageDialog(
                        parent=None,
                        flags=Gtk.DialogFlags.MODAL
                        | Gtk.DialogFlags.DESTROY_WITH_PARENT,
                        type=Gtk.MessageType.ERROR,
                        buttons=Gtk.ButtonsType.OK_CANCEL,
                        message_format=
                        _('You have to authorize Calendar-Indicator to manage your Google Calendar.\n Do you want to authorize?'
                          ))
                    if md.run() == Gtk.ResponseType.CANCEL:
                        exit(3)
                    md.destroy()
                else:
                    self.googlecalendar = GoogleCalendar(
                        token_file=comun.TOKEN_FILE)
                    if self.googlecalendar.do_refresh_authorization() is None:
                        error = False
            else:
                error = False
        self.load_preferences()

        self.load_css()

        self.events = []
        self.create_menu()
        self.sync()
        self.update_menu()
        self.actualization_time = time.time()
        GLib.timeout_add_seconds(60, self.work)
コード例 #2
0
 def set_active(self):
     self.store.clear()
     configuration = Configuration()
     calendars_options = configuration.get('calendars')
     if os.path.exists(comun.TOKEN_FILE):
         if self.googlecalendar is not None:
             calendars = self.googlecalendar.calendars.values()
         else:
             gca = GoogleCalendar(token_file=comun.TOKEN_FILE)
             gca.read()
             calendars = gca.get_calendars().values()
         for calendar in calendars:
             calendar_options = get_calendar_from_options(
                 configuration.get('calendars'), calendar['id'])
             if calendar_options:
                 background_color = calendar_options['background']
                 foreground_color = calendar_options['foreground']
                 visible = calendar_options['visible']
                 if 'name' in calendar_options.keys():
                     calendar_name = calendar_options['name']
                 else:
                     calendar_name = calendar['summary']
             else:
                 background_color = tohex()
                 foreground_color = contraste(background_color)
                 visible = True
                 calendar_name = calendar['summary']
             self.store.append([
                 calendar['summary'], background_color, foreground_color,
                 calendar['id'], visible, calendar_name
             ])
コード例 #3
0
 def load_preferences(self):
     self.switch1.set_active(os.path.exists(comun.TOKEN_FILE))
     configuration = Configuration()
     time = configuration.get('time')
     theme = configuration.get('theme')
     calendars_options = configuration.get('calendars')
     self.spin3.set_value(time)
     if os.path.exists(
             os.path.join(
                 os.getenv("HOME"),
                 ".config/autostart/calendar-indicator-autostart.desktop")):
         self.switch4.set_active(True)
     if theme == 'light':
         self.switch5.set_active(True)
     else:
         self.switch5.set_active(False)
     if os.path.exists(comun.TOKEN_FILE):
         if self.googlecalendar is not None:
             calendars = self.googlecalendar.calendars.values()
         else:
             gca = GoogleCalendar(token_file=comun.TOKEN_FILE)
             gca.read()
             calendars = gca.get_calendars().values()
         self.store.clear()
         for calendar in calendars:
             calendar_options = get_calendar_from_options(
                 configuration.get('calendars'), calendar['id'])
             if calendar_options:
                 background_color = calendar_options['background']
                 foreground_color = calendar_options['foreground']
                 visible = calendar_options['visible']
                 if 'name' in calendar_options.keys():
                     calendar_name = calendar_options['name']
                 else:
                     calendar_name = calendar['summary']
             else:
                 background_color = tohex(random.randint(0, 16777215))
                 foreground_color = tohex(random.randint(0, 16777215))
                 visible = True
                 calendar_name = calendar['summary']
             self.store.append([
                 calendar['summary'], background_color, foreground_color,
                 calendar['id'], visible, calendar_name
             ])
コード例 #4
0
 def on_switch1_changed(self, widget, data):
     if self.switch1.get_active():
         if os.path.exists(comun.TOKEN_FILE):
             os.remove(comun.TOKEN_FILE)
     else:
         googlecalendar = GoogleCalendar(token_file=comun.TOKEN_FILE)
         if googlecalendar.do_refresh_authorization() is None:
             authorize_url = googlecalendar.get_authorize_url()
             ld = LoginDialog(authorize_url)
             ld.run()
             googlecalendar.get_authorization(ld.code)
             ld.destroy()
             if googlecalendar.do_refresh_authorization() is None:
                 md = Gtk.MessageDialog(
                     parent=self,
                     flags=Gtk.DialogFlags.MODAL
                     | Gtk.DialogFlags.DESTROY_WITH_PARENT,
                     type=Gtk.MessageType.ERROR,
                     buttons=Gtk.ButtonsType.OK_CANCEL,
                     message_format=
                     _('You have to authorize Calendar-Indicator to use it, do you want to authorize?'
                       ))
                 if md.run() == Gtk.ResponseType.CANCEL:
                     exit(3)
             else:
                 if googlecalendar.do_refresh_authorization() is None:
                     exit(3)
         self.switch1.set_active(True)
         self.store.clear()
         for calendar in googlecalendar.get_calendars().values():
             self.store.append([
                 calendar['summary'],
                 tohex(random.randint(0, 16777215)),
                 tohex(random.randint(0, 16777215)), calendar['id'], True,
                 calendar['summary']
             ])