예제 #1
0
    def del_task(self, task):
        """ Suppression de tâches """
        rep = askyesno(
            _("Confirmation"),
            _("Are you sure you want to delete the task {task}? This action cannot be undone."
              ).format(task=task.capitalize()))
        if rep:
            CONFIG.remove_option("PomodoroTasks", task)
            # remove stats
            db = sqlite3.connect(PATH_STATS)
            cursor = db.cursor()
            try:
                cursor.execute('DROP TABLE {}'.format(
                    scrub(task.lower().replace(' ', '_'))))
                db.commit()
            except sqlite3.OperationalError:
                pass  # no stats yet
            db.close()
            self.tasks[task].destroy()
            self._tasks_btns[task].destroy()
            del self.tasks[task]
            del self._tasks_btns[task]

            if len(CONFIG.options("PomodoroTasks")) == 1:
                CONFIG.set("PomodoroTasks", _("Work"), CMAP[0])
                self._tasks_btns[CONFIG.options("PomodoroTasks")[0]].state(
                    ['disabled'])
            save_config()
예제 #2
0
 def show(self):
     ''' make widget sticky '''
     self.deiconify()
     self.update_idletasks()
     splash_supp = CONFIG.getboolean('General',
                                     'splash_supported',
                                     fallback=True)
     try:
         pos = self._position.get()
         for w in self.ewmh.getClientList():
             if w.get_wm_name() == self.title():
                 if pos == 'above':
                     self.attributes('-type', 'dock')
                     self.ewmh.setWmState(w, 1, '_NET_WM_STATE_ABOVE')
                     self.ewmh.setWmState(w, 0, '_NET_WM_STATE_BELOW')
                     self.ewmh.setWmState(w, 1, '_NET_WM_STATE_STICKY')
                     self.ewmh.setWmState(w, 1,
                                          '_NET_WM_STATE_SKIP_TASKBAR')
                     self.ewmh.setWmState(w, 1, '_NET_WM_STATE_SKIP_PAGER')
                 elif pos == 'below':
                     self.attributes('-type', 'desktop')
                     self.ewmh.setWmState(w, 0, '_NET_WM_STATE_ABOVE')
                     self.ewmh.setWmState(w, 1, '_NET_WM_STATE_BELOW')
                     self.ewmh.setWmState(w, 1, '_NET_WM_STATE_STICKY')
                     self.ewmh.setWmState(w, 1,
                                          '_NET_WM_STATE_SKIP_TASKBAR')
                     self.ewmh.setWmState(w, 1, '_NET_WM_STATE_SKIP_PAGER')
                 else:
                     if splash_supp:
                         self.attributes('-type', 'splash')
                     else:
                         self.attributes('-type', 'toolbar')
                     self.ewmh.setWmState(w, 0, '_NET_WM_STATE_BELOW')
                     self.ewmh.setWmState(w, 0, '_NET_WM_STATE_ABOVE')
                     self.ewmh.setWmState(w, 1, '_NET_WM_STATE_STICKY')
                     self.ewmh.setWmState(w, 1,
                                          '_NET_WM_STATE_SKIP_TASKBAR')
                     self.ewmh.setWmState(w, 1, '_NET_WM_STATE_SKIP_PAGER')
         self.ewmh.display.flush()
         if not splash_supp:
             self.withdraw()
             self.deiconify()
         CONFIG.set(self.name, 'visible', 'True')
         self.variable.set(True)
         save_config()
     except TypeError:
         pass
예제 #3
0
    def __init__(self, name, master=None, **kw):
        """
        Create a  desktop widget that sticks on the desktop.
        """
        Toplevel.__init__(self, master)
        self.name = name
        if CONFIG.getboolean('General', 'splash_supported', fallback=True):
            self.attributes('-type', 'splash')
        else:
            self.attributes('-type', 'toolbar')

        self.style = Style(self)

        self._position = StringVar(self, CONFIG.get(self.name, 'position'))
        self._position.trace_add(
            'write',
            lambda *x: CONFIG.set(self.name, 'position', self._position.get()))

        self.ewmh = EWMH()
        self.title('scheduler.{}'.format(self.name.lower()))

        self.withdraw()

        # control main menu checkbutton
        self.variable = BooleanVar(self, False)

        # --- menu
        self.menu = Menu(self, relief='sunken', activeborderwidth=0)
        self._populate_menu()

        self.create_content(**kw)

        self.x = None
        self.y = None

        # --- geometry
        geometry = CONFIG.get(self.name, 'geometry')
        self.update_idletasks()
        if geometry:
            self.geometry(geometry)
        self.update_idletasks()

        if CONFIG.getboolean(self.name, 'visible', fallback=True):
            self.show()

        # --- bindings
        self.bind('<Configure>', self._on_configure)
예제 #4
0
파일: settings.py 프로젝트: j4321/Scheduler
    def ok(self):
        # --- General
        CONFIG.set("General", "language", REV_LANGUAGES[self.lang.get()])
        CONFIG.set("General", "trayicon", self.gui.get().lower())
        # CONFIG.set("General", "check_update", str('selected' in self.confirm_update.state()))
        CONFIG.set('General', 'splash_supported',
                   str(not self.splash_support.instate(('selected', ))))

        eyes = self.eyes_interval.get()
        if eyes == '':
            eyes = '20'
        CONFIG.set("General", "eyes_interval", eyes)
        # --- Reminders
        CONFIG.set("Reminders", 'window',
                   str("selected" in self.reminders_window.state()))
        CONFIG.set("Reminders", 'window_bg',
                   self.reminders_window_bg.get_color())
        CONFIG.set("Reminders", 'window_fg',
                   self.reminders_window_fg.get_color())
        CONFIG.set("Reminders", "window_alpha",
                   "%.2f" % (self.reminders_opacity.get_opacity()))
        CONFIG.set("Reminders", 'window_bg_alternate',
                   self.reminders_window_bg_alt.get_color())
        CONFIG.set("Reminders", 'window_fg_alternate',
                   self.reminders_window_fg_alt.get_color())
        CONFIG.set("Reminders", 'blink',
                   str("selected" in self.reminders_blink.state()))
        CONFIG.set("Reminders", 'notification',
                   str("selected" in self.reminders_notif.state()))
        alarm, mute = self.reminders_sound.get()
        CONFIG.set("Reminders", 'alarm', alarm)
        timeout = self.reminders_timeout.get()
        if timeout == '':
            timeout = '5'
        CONFIG.set("Reminders", 'timeout', timeout)
        CONFIG.set("Reminders", 'mute', str(mute))
        # --- Calendar
        CONFIG.set("Calendar", "alpha",
                   "%.2f" % (self.cal_opacity.get_opacity()))

        font = self.cal_font.get_font()
        CONFIG.set(
            "Calendar", "font",
            "{} {}".format(font['family'].replace(' ', '\ '), font['size']))
        CONFIG.set("Calendar", "bordercolor", self.cal_bd.get_color())
        CONFIG.set("Calendar", "background", self.cal_bg.get_color())
        CONFIG.set("Calendar", "foreground", self.cal_fg.get_color())
        for name, widget in self.cal_colors.items():
            CONFIG.set("Calendar", name, widget.get_color())

        for cat, (l, bg, fg, b) in self.cats.items():
            CONFIG.set("Categories", cat,
                       "{}, {}".format(fg.get_color(), bg.get_color()))

        # --- Events
        CONFIG.set("Events", "alpha",
                   "%.2f" % (self.events_opacity.get_opacity()))

        font = self.events_font.get_font()
        CONFIG.set(
            "Events", "font", "{} {}".format(font['family'].replace(' ', '\ '),
                                             font['size']))
        font_title = self.events_font_title.get_font()
        title = [
            font_title['family'].replace(' ', '\ '),
            str(font_title['size']), font_title['weight'], font_title['slant']
        ]
        if font_title['underline']:
            title.append('underline')
        CONFIG.set("Events", "font_title", " ".join(title))

        font_day = self.events_font_day.get_font()
        day = [
            font_day['family'].replace(' ', '\ '),
            str(font_day['size']), font_day['weight'], font_day['slant']
        ]
        if font_day['underline']:
            day.append('underline')
        CONFIG.set("Events", "font_day", " ".join(day))

        CONFIG.set("Events", "background", self.events_bg.get_color())
        CONFIG.set("Events", "foreground", self.events_fg.get_color())

        # --- Tasks
        CONFIG.set("Tasks", "alpha",
                   "%.2f" % (self.tasks_opacity.get_opacity()))

        font = self.tasks_font.get_font()
        CONFIG.set(
            "Tasks", "font", "{} {}".format(font['family'].replace(' ', '\ '),
                                            font['size']))
        font_title = self.tasks_font_title.get_font()
        title = [
            font_title['family'].replace(' ', '\ '),
            str(font_title['size']), font_title['weight'], font_title['slant']
        ]
        if font_title['underline']:
            title.append('underline')
        CONFIG.set("Tasks", "font_title", " ".join(title))

        CONFIG.set("Tasks", "background", self.tasks_bg.get_color())
        CONFIG.set("Tasks", "foreground", self.tasks_fg.get_color())
        CONFIG.set('Tasks', 'hide_completed', str(self.tasks_hide_comp.get()))

        # --- Timer
        CONFIG.set("Timer", "alpha",
                   "%.2f" % (self.timer_opacity.get_opacity()))

        font_time = self.timer_font_time.get_font()
        CONFIG.set(
            "Timer", "font_time",
            "{} {}".format(font_time['family'].replace(' ', '\ '),
                           font_time['size']))
        font_intervals = self.timer_font_intervals.get_font()
        CONFIG.set(
            "Timer", "font_intervals",
            "{} {}".format(font_intervals['family'].replace(' ', '\ '),
                           font_intervals['size']))

        CONFIG.set("Timer", "background", self.timer_bg.get_color())
        CONFIG.set("Timer", "foreground", self.timer_fg.get_color())

        # --- Pomodoro
        stop_pomodoro = self.frames[_('Pomodoro')].valide()
        if stop_pomodoro:
            self.master.widgets['Pomodoro'].stop(False)
        save_config()
        self.destroy()
예제 #5
0
    def valide(self):
        """Update config and return whether the pomodor timer should be stopped."""
        old_tpsw = CONFIG.getint("Pomodoro", "work_time")
        old_tpsp = CONFIG.getint("Pomodoro", "break_time")
        old_tpsr = CONFIG.getint("Pomodoro", "rest_time")
        try:
            tpsw = int(self.travail.get())
        except ValueError:  # empty entry
            tpsw = 0
        if tpsw == 0:
            tpsw = old_tpsw
        try:
            tpsp = int(self.pause.get())
        except ValueError:
            tpsp = 0
        if tpsp == 0:
            tpsp = old_tpsp
        try:
            tpsr = int(self.rest.get())
        except ValueError:
            tpsr = 0
        if tpsr == 0:
            tpsr = old_tpsr

        sound, mute = self.sound.get()
        font_prop = self.font.get_font()
        font = "{} {}".format(font_prop['family'].replace(' ', '\ '),
                              font_prop['size'])
        try:
            legend_rows = int(self.legend_row_nb.get())
        except ValueError:
            legend_rows = 0
        if legend_rows == 0:
            legend_rows = CONFIG.getint("Pomodoro", "legend_max_height")

        if not os.path.exists(sound):
            showerror(
                _("Error"),
                _("The file {filepath} does not exists, the old file will be used."
                  ).format(filepath=sound))
            sound = CONFIG.get("Pomodoro", "beep")

        CONFIG.set("Pomodoro", "alpha", str(self.opacity.get_opacity()))
        CONFIG.set("Pomodoro", "font", font)
        CONFIG.set("Pomodoro", "background", self.bg.get_color())
        CONFIG.set("Pomodoro", "foreground", self.fg.get_color())
        CONFIG.set("Pomodoro", "work_time", str(tpsw))
        CONFIG.set("Pomodoro", "work_bg", self.work_bg.get_color())
        CONFIG.set("Pomodoro", "work_fg", self.work_fg.get_color())
        CONFIG.set("Pomodoro", "break_time", str(tpsp))
        CONFIG.set("Pomodoro", "break_bg", self.break_bg.get_color())
        CONFIG.set("Pomodoro", "break_fg", self.break_fg.get_color())
        CONFIG.set("Pomodoro", "rest_time", str(tpsr))
        CONFIG.set("Pomodoro", "rest_bg", self.rest_bg.get_color())
        CONFIG.set("Pomodoro", "rest_fg", self.rest_fg.get_color())
        CONFIG.set("Pomodoro", "beep", sound)
        CONFIG.set("Pomodoro", "mute", str(mute))
        CONFIG.set("Pomodoro", "legend_max_height", str(legend_rows))
        for task, widget in self.tasks.items():
            CONFIG.set("PomodoroTasks", task, widget.get_color())

        return old_tpsw != tpsw or old_tpsp != tpsp or old_tpsr != old_tpsr
예제 #6
0
 def hide(self):
     CONFIG.set(self.name, 'visible', 'False')
     self.variable.set(False)
     save_config()
     self.withdraw()
예제 #7
0
 def _on_configure(self, event):
     CONFIG.set(self.name, 'geometry', self.geometry())
     save_config()
예제 #8
0
    def create_content(self, **kw):
        self.minsize(190, 190)

        self.on = False  # is the timer on?

        if not CONFIG.options("Tasks"):
            CONFIG.set("Tasks", _("Work"), CMAP[0])

        self._stats = None

        # --- colors
        self.background = {
            _("Work"): CONFIG.get("Pomodoro", "work_bg"),
            _("Break"): CONFIG.get("Pomodoro", "break_bg"),
            _("Rest"): CONFIG.get("Pomodoro", "rest_bg")
        }
        self.foreground = {
            _("Work"): CONFIG.get("Pomodoro", "work_fg"),
            _("Break"): CONFIG.get("Pomodoro", "break_fg"),
            _("Rest"): CONFIG.get("Pomodoro", "rest_fg")
        }

        self.rowconfigure(1, weight=1)
        self.columnconfigure(0, weight=1)
        self.columnconfigure(1, weight=1)

        # nombre de séquence de travail effectuées d'affilée (pour
        # faire des pauses plus longues tous les 4 cycles)
        self.nb_cycles = 0
        self.pomodori = IntVar(self, 0)

        # --- images
        self.im_go = PhotoImage(master=self, file=IM_START)
        self.im_stop = PhotoImage(master=self, file=IM_STOP)
        self.im_tomate = PhotoImage(master=self, file=IM_POMODORO)
        self.im_graph = PhotoImage(master=self, file=IM_GRAPH)

        # --- tasks list
        tasks_frame = Frame(self, style='pomodoro.TFrame')
        tasks_frame.grid(row=3, column=0, columnspan=3, sticky="wnse")
        tasks = [t.capitalize() for t in CONFIG.options("PomodoroTasks")]
        tasks.sort()
        self.task = StringVar(self, tasks[0])
        self.menu_tasks = Menu(tasks_frame,
                               relief='sunken',
                               activeborderwidth=0)
        self.choose_task = Menubutton(tasks_frame,
                                      textvariable=self.task,
                                      menu=self.menu_tasks,
                                      style='pomodoro.TMenubutton')
        Label(tasks_frame,
              text=_("Task: "),
              style='pomodoro.TLabel',
              font="TkDefaultFont 12",
              width=6,
              anchor="e").pack(side="left", padx=4)
        self.choose_task.pack(side="right", fill="x", pady=4)

        # --- display
        self.tps = [CONFIG.getint("Pomodoro", "work_time"),
                    0]  # time: min, sec
        self.activite = StringVar(self, _("Work"))
        self.titre = Label(self,
                           textvariable=self.activite,
                           font='TkDefaultFont 14',
                           style='timer.pomodoro.TLabel',
                           anchor="center")
        self.titre.grid(row=0,
                        column=0,
                        columnspan=2,
                        sticky="we",
                        pady=(4, 0),
                        padx=4)
        self.temps = Label(self,
                           text="{0:02}:{1:02}".format(self.tps[0],
                                                       self.tps[1]),
                           style='timer.pomodoro.TLabel',
                           anchor="center")
        self.temps.grid(row=1, column=0, columnspan=2, sticky="nswe", padx=4)
        self.aff_pomodori = Label(self,
                                  textvariable=self.pomodori,
                                  anchor='e',
                                  padding=(20, 4, 20, 4),
                                  image=self.im_tomate,
                                  compound="left",
                                  style='timer.pomodoro.TLabel',
                                  font='TkDefaultFont 14')
        self.aff_pomodori.grid(row=2, columnspan=2, sticky="ew", padx=4)

        # --- buttons
        self.b_go = Button(self,
                           image=self.im_go,
                           command=self.go,
                           style='pomodoro.TButton')
        self.b_go.grid(row=4, column=0, sticky="ew")
        self.b_stats = Button(self,
                              image=self.im_graph,
                              command=self.display_stats,
                              style='pomodoro.TButton')
        self.b_stats.grid(row=4, column=1, sticky="ew")

        self._corner = Sizegrip(self, style="pomodoro.TSizegrip")
        self._corner.place(relx=1, rely=1, anchor='se')

        # --- bindings
        self.bind('<3>', lambda e: self.menu.tk_popup(e.x_root, e.y_root))
        tasks_frame.bind('<ButtonPress-1>', self._start_move)
        tasks_frame.bind('<ButtonRelease-1>', self._stop_move)
        tasks_frame.bind('<B1-Motion>', self._move)
        self.titre.bind('<ButtonPress-1>', self._start_move)
        self.titre.bind('<ButtonRelease-1>', self._stop_move)
        self.titre.bind('<B1-Motion>', self._move)
        self.temps.bind('<ButtonPress-1>', self._start_move)
        self.temps.bind('<ButtonRelease-1>', self._stop_move)
        self.temps.bind('<B1-Motion>', self._move)
        self.b_stats.bind('<Enter>', self._on_enter)
        self.b_stats.bind('<Leave>', self._on_leave)
예제 #9
0
 def _on_configure(self, event):
     geo = self.geometry().split('+')[1:]
     CONFIG.set(self.name, 'geometry', '+%s+%s' % tuple(geo))
     save_config()