def ting(): """ joue le son marquant le changement de période """ if not CONFIG.getboolean("Pomodoro", "mute", fallback=False): Popen([ CONFIG.get("General", "soundplayer"), CONFIG.get("Pomodoro", "beep") ])
def _setup_style(self): # scrollbars for widget in ['Events', 'Tasks']: bg = CONFIG.get(widget, 'background', fallback='gray10') fg = CONFIG.get(widget, 'foreground', fallback='white') widget_bg = self.winfo_rgb(bg) widget_fg = tuple( round(c * 255 / 65535) for c in self.winfo_rgb(fg)) active_bg = active_color(*widget_bg) active_bg2 = active_color(*active_color(*widget_bg, 'RGB')) slider_vert = Image.new('RGBA', (13, 28), active_bg) slider_vert.putalpha(self._slider_alpha) slider_vert_active = Image.new('RGBA', (13, 28), widget_fg) slider_vert_active.putalpha(self._slider_alpha) slider_vert_prelight = Image.new('RGBA', (13, 28), active_bg2) slider_vert_prelight.putalpha(self._slider_alpha) self._im_trough[widget].put(" ".join( ["{" + " ".join([bg] * 15) + "}"] * 15)) self._im_slider_vert_active[widget].paste(slider_vert_active) self._im_slider_vert[widget].paste(slider_vert) self._im_slider_vert_prelight[widget].paste(slider_vert_prelight) for widget in self.widgets.values(): widget.update_style()
def stop(self, confirmation=True): """ Arrête le décompte du temps et le réinitialise, demande une confirmation avant de le faire si confirmation=True """ tps = int( CONFIG.getint("Pomodoro", "work_time") - self.tps[0] - self.tps[1] / 60) self.on = False rep = True if confirmation: rep = askyesno( title=_("Confirmation"), message=_( "Are you sure you want to give up the current session?")) if rep: self.choose_task.state(["!disabled"]) self.b_go.configure(image=self.im_go) if self.activite.get() == _("Work"): self.stats(tps) self.pomodori.set(0) self.nb_cycles = 0 self.tps = [CONFIG.getint("Pomodoro", "work_time"), 0] self.temps.configure( text="{0:02}:{1:02}".format(self.tps[0], self.tps[1])) act = _("Work") self.activite.set(act) self.style.configure('timer.pomodoro.TLabel', background=self.background[act], foreground=self.foreground[act]) logging.info('Pomodoro session interrupted.') else: self.on = True self.affiche() return rep
def settings(self): splash_supp = CONFIG.get('General', 'splash_supported', fallback=True) dialog = Settings(self) self.wait_window(dialog) self._setup_style() if splash_supp != CONFIG.get('General', 'splash_supported'): for widget in self.widgets.values(): widget.update_position()
def del_cat(self, cat): rep = askyesno( _("Confirmation"), _("Are you sure you want to delete the category {category}? This action cannot be undone." ).format(category=cat)) if rep: CONFIG.remove_option("Categories", cat) for w in self.cats[cat]: w.destroy() del self.cats[cat] save_config()
def display_tasks(self, force=False): tasks = self.master.get_tasks() tasks.sort(key=lambda ev: ev['End']) self.display.configure(state='normal') self.display.delete('1.0', 'end') for ev in tasks: if not self.hide_completed or ev['Task'] != 'Completed': if ev["WholeDay"]: end = format_date(ev['End'], locale=CONFIG.get("General", "locale")) else: end = format_datetime(ev['End'], locale=CONFIG.get("General", "locale")) picto = TASK_STATE.get(ev['Task'], ev['Task']) txt = "\t%s\t%s [%s]\n" % (picto, ev['Summary'], end) self.display.insert('end', txt) self.display.configure(state='disabled')
def stats(self, time=None): """Save stats.""" if time is None: time = CONFIG.getint("Pomodoro", "work_time") today = dt.date.today().toordinal() task = self.task.get().lower().replace(' ', '_') db = sqlite3.connect(PATH_STATS) cursor = db.cursor() try: cursor.execute('SELECT * FROM {} ORDER BY id DESC LIMIT 1'.format( scrub(task))) key, date, work = cursor.fetchone() except sqlite3.OperationalError: cursor.execute('''CREATE TABLE {} (id INTEGER PRIMARY KEY, date INTEGER, work INTEGER)'''.format( scrub(task))) cursor.execute( 'INSERT INTO {}(date, work) VALUES (?, ?)'.format(scrub(task)), (today, time)) else: if today != date: cursor.execute( 'INSERT INTO {}(date, work) VALUES (?, ?)'.format( scrub(task)), (today, time)) else: # update day's value cursor.execute( 'UPDATE {} SET work=? WHERE id=?'.format(scrub(task)), (work + time, key)) finally: db.commit() db.close()
def ajoute(event=None): task = nom.get().lower().strip() if task in self.tasks: showerror( _("Error"), _("The task {task} already exists.").format(task=task), parent=self) elif task: coul = CMAP[(len(self.tasks) + 1) % len(CMAP)] i = self.task_frame.grid_size()[1] + 1 self.tasks[task] = ColorFrame(self.task_frame, coul, task.capitalize()) self.tasks[task].grid(row=i, column=0, sticky='e', padx=4, pady=4) b = Button(self.task_frame, image=self.im_moins, padding=2, command=lambda t=task: self.del_task(t)) b.grid(row=i, column=1, sticky='w', padx=4, pady=4) self._tasks_btns[task] = b self._tasks_btns[CONFIG.options("PomodoroTasks")[0]].state( ['!disabled']) top.destroy()
def create_content(self, **kw): self.rowconfigure(2, weight=1) self.columnconfigure(0, weight=1) self.minsize(50, 50) self.hide_completed = CONFIG.getboolean('Tasks', 'hide_completed') # --- elements label = Label(self, text=_('Tasks').upper(), style='title.Tasks.TLabel', anchor='center') label.grid(row=0, columnspan=2, pady=4, sticky='ew') Separator(self, style='Tasks.TSeparator').grid(row=1, columnspan=2, sticky='we') self.display = Text(self, width=20, height=10, relief='flat', cursor='arrow', wrap='word', highlightthickness=0, state='disabled', spacing1=5, tabs=('35', 'right', '45', 'left')) self.display.grid(sticky='nsew', row=2, column=0, padx=2, pady=2) scroll = AutoScrollbar(self, orient='vertical', style='Tasks.Vertical.TScrollbar', command=self.display.yview) scroll.grid(row=2, column=1, sticky='ns', pady=(2, 16)) self.display.configure(yscrollcommand=scroll.set) self.display_tasks() corner = Sizegrip(self, style="Tasks.TSizegrip") corner.place(relx=1, rely=1, anchor='se') # --- bindings self.bind('<3>', lambda e: self.menu.tk_popup(e.x_root, e.y_root)) label.bind('<ButtonPress-1>', self._start_move) label.bind('<ButtonRelease-1>', self._stop_move) label.bind('<B1-Motion>', self._move)
def get_next_week_events(self): """Return events scheduled for the next 7 days """ locale = CONFIG.get("General", "locale") next_ev = {} today = datetime.now().date() for d in range(7): day = today + timedelta(days=d) evts = self.widgets['Calendar'].get_events(day) if evts: evts = [self.events[iid] for iid in evts] evts.sort(key=lambda ev: ev.get_start_time()) desc = [] for ev in evts: if ev["WholeDay"]: date = "" else: date = "%s - %s " % ( format_time(ev['Start'], locale=locale), format_time(ev['End'], locale=locale)) place = "(%s)" % ev['Place'] if place == "()": place = "" desc.append(("%s%s %s\n" % (date, ev['Summary'], place), ev['Description'])) next_ev[day.strftime('%A')] = desc return next_ev
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)
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
def update_style(self): bg = CONFIG.get(self.name, 'background', fallback='grey10') fg = CONFIG.get(self.name, 'foreground', fallback='white') active_bg = active_color(*self.winfo_rgb(bg)) self.attributes('-alpha', CONFIG.get(self.name, 'alpha', fallback=0.85)) self.configure(bg=bg) self.menu.configure(bg=bg, fg=fg, selectcolor=fg, activeforeground=fg, activebackground=active_bg) self.menu_pos.configure(bg=bg, fg=fg, selectcolor=fg, activeforeground=fg, activebackground=active_bg)
def update_position(self): if self._position.get() == 'normal': if CONFIG.getboolean('General', 'splash_supported', fallback=True): self.attributes('-type', 'splash') else: self.attributes('-type', 'toolbar') if self.variable.get(): self.withdraw() self.deiconify()
def values(self): """ return the values (Summary, Place, Start, End) to put in the main window treeview """ locale = CONFIG.get("General", "locale") if self['WholeDay']: start = format_date(self['Start'], locale=locale) end = format_date(self['End'], locale=locale) else: start = format_datetime(self['Start'], locale=locale) end = format_datetime(self['End'], locale=locale) return self['Summary'], self['Place'], start, end, self['Category']
def update_style(self): self.attributes('-alpha', CONFIG.get(self.name, 'alpha', fallback=0.85)) bg = CONFIG.get('Timer', 'background') fg = CONFIG.get('Timer', 'foreground') active_bg = active_color(*self.winfo_rgb(bg)) self.configure(bg=bg) self.menu.configure(bg=bg, fg=fg, selectcolor=fg, activeforeground=fg, activebackground=active_bg) self.menu_pos.configure(bg=bg, fg=fg, selectcolor=fg, activeforeground=fg, activebackground=active_bg) self.display.configure(font=CONFIG.get('Timer', 'font_time')) self.intervals.configure(bg=bg, fg=fg, font=CONFIG.get('Timer', 'font_intervals')) self.style.configure('timer.TButton', background=bg, relief='flat', foreground=fg, borderwidth=0) self.style.configure('timer.TLabel', background=bg, foreground=fg) self.style.configure('timer.TSizegrip', background=bg) self.style.map('timer.TSizegrip', background=[('active', active_bg)]) self.style.map('timer.TButton', background=[('disabled', bg), ('!disabled', 'active', active_bg)])
def update_style(self): bg = CONFIG.get('Events', 'background') fg = CONFIG.get('Events', 'foreground') active_bg = active_color(*self.winfo_rgb(bg)) self.attributes('-alpha', CONFIG.get(self.name, 'alpha', fallback=0.85)) self.style.configure('Events.TFrame', background=bg) self.style.configure('Events.TSizegrip', background=bg) self.style.configure('Events.TSeparator', background=bg) self.style.configure('Events.TLabel', background=bg, foreground=fg, font=CONFIG.get('Events', 'font')) self.style.configure('title.Events.TLabel', font=CONFIG.get('Events', 'font_title')) self.style.configure('day.Events.TLabel', font=CONFIG.get('Events', 'font_day')) self.style.configure('Toggle', background=bg) self.configure(bg=bg) self.menu_pos.configure(bg=bg, fg=fg, selectcolor=fg, activeforeground=fg, activebackground=active_bg) self.menu.configure(bg=bg, fg=fg, selectcolor=fg, activeforeground=fg, activebackground=active_bg) self.canvas.configure(bg=bg)
def update_style(self): bg = CONFIG.get(self.name, 'background', fallback='grey10') fg = CONFIG.get(self.name, 'foreground', fallback='white') active_bg = active_color(*self.winfo_rgb(bg)) self.attributes('-alpha', CONFIG.get(self.name, 'alpha', fallback=0.85)) self.configure(bg=bg) self._calendar.menu.configure(bg=bg, fg=fg, selectcolor=fg, activeforeground=fg, activebackground=active_bg) self.menu.configure(bg=bg, fg=fg, selectcolor=fg, activeforeground=fg, activebackground=active_bg) self.menu_pos.configure(bg=bg, fg=fg, selectcolor=fg, activeforeground=fg, activebackground=active_bg) keys = self._calendar.keys() opts = { opt: CONFIG.get('Calendar', opt) for opt in CONFIG.options('Calendar') if opt in keys } self._calendar.configure(**opts) self._calendar['font'] = CONFIG.get('Calendar', 'font') self._calendar.update_style()
def affiche(self): if self.on: self.tps[1] -= 1 if self.tps[1] == 0: if self.tps[0] == 0: self.ting() if self.activite.get() == _("Work"): self.pomodori.set(self.pomodori.get() + 1) self.nb_cycles += 1 self.choose_task.state(["!disabled"]) logging.info( 'Pomodoro: completed work session for task ' + self.task.get()) if self.nb_cycles % 4 == 0: # pause longue self.stats() self.activite.set(_("Rest")) self.tps = [ CONFIG.getint("Pomodoro", "rest_time"), 0 ] else: # pause courte self.stats() self.activite.set(_("Break")) self.tps = [ CONFIG.getint("Pomodoro", "break_time"), 0 ] else: self.choose_task.state(["disabled"]) self.activite.set(_("Work")) self.tps = [CONFIG.getint("Pomodoro", "work_time"), 0] act = self.activite.get() self.style.configure('timer.pomodoro.TLabel', background=self.background[act], foreground=self.foreground[act]) elif self.tps[1] == -1: self.tps[0] -= 1 self.tps[1] = 59 self.temps.configure(text="{0:02}:{1:02}".format(*self.tps)) self.after(1000, self.affiche)
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()
def __init__(self, scheduler, iid=None, **kw): d = datetime.now() + timedelta(minutes=5) d = d.replace(minute=(d.minute // 5) * 5) d = kw.pop('Start', d) self.scheduler = scheduler defaults = { 'Summary': '', 'Place': '', 'Description': '', 'Start': d, 'End': d + timedelta(hours=1), 'Task': False, 'Repeat': {}, 'WholeDay': False, 'Reminders': {}, 'Category': CONFIG.options('Categories')[0] } defaults.update(kw) self._properties = defaults self.iid = iid
def _init_timer(self): self.frames[_('Timer')].columnconfigure(0, weight=1) # --- Fonts frame_font = ttk.Frame(self.frames[_('Timer')]) frame_font.columnconfigure(2, weight=1) ttk.Label(frame_font, text=_('Font'), style='title.TLabel').grid(row=0, column=0, sticky='w', padx=4, pady=4) # --- --- time ttk.Label(frame_font, style='subtitle.TLabel', text=_('Time')).grid(row=1, column=0, sticky='nw', padx=4, pady=8) self.timer_font_time = FontFrame(frame_font, CONFIG.get('Timer', 'font_time'), sample_text="02:17") self.timer_font_time.grid(row=1, column=1, padx=4, pady=4) ttk.Separator(frame_font, orient='horizontal').grid(row=2, columnspan=3, padx=10, pady=4, sticky='ew') # --- --- intervals ttk.Label(frame_font, style='subtitle.TLabel', text=_('Intervals')).grid(row=5, column=0, sticky='nw', padx=4, pady=8) self.timer_font_intervals = FontFrame(frame_font, CONFIG.get( 'Timer', 'font_intervals'), sample_text="02:17") self.timer_font_intervals.grid(row=5, column=1, padx=4, pady=4) # --- opacity self.timer_opacity = OpacityFrame( self.frames[_('Timer')], CONFIG.getfloat("Timer", "alpha", fallback=0.85)) # --- colors frame_color = ttk.Frame(self.frames[_('Timer')]) ttk.Label(frame_color, text=_('Colors'), style='title.TLabel').grid(row=0, column=0, sticky='w', padx=8, pady=4) self.timer_bg = ColorFrame(frame_color, CONFIG.get('Timer', 'background'), _('Background')) self.timer_bg.grid(row=0, column=1, sticky='e', padx=8, pady=4) self.timer_fg = ColorFrame(frame_color, CONFIG.get('Timer', 'foreground'), _('Foreground')) self.timer_fg.grid(row=0, column=2, sticky='e', padx=8, pady=4) # --- placement frame_font.grid(sticky='ew') ttk.Separator(self.frames[_('Timer')], orient='horizontal').grid(sticky='ew', pady=8) self.timer_opacity.grid(sticky='w', padx=4) ttk.Separator(self.frames[_('Timer')], orient='horizontal').grid(sticky='ew', pady=8) frame_color.grid(sticky='w')
def _init_tasks(self): self.frames[_('Tasks')].columnconfigure(0, weight=1) self.tasks_hide_comp = tk.BooleanVar( self, CONFIG.getboolean('Tasks', 'hide_completed')) # --- Fonts frame_font = ttk.Frame(self.frames[_('Tasks')]) frame_font.columnconfigure(2, weight=1) ttk.Label(frame_font, text=_('Font'), style='title.TLabel').grid(row=0, column=0, sticky='w', padx=4, pady=4) # --- --- title ttk.Label(frame_font, style='subtitle.TLabel', text=_('Title')).grid(row=1, column=0, sticky='nw', padx=4, pady=8) self.tasks_font_title = FontFrame(frame_font, CONFIG.get('Tasks', 'font_title'), True) self.tasks_font_title.grid(row=1, column=1, padx=4, pady=4) ttk.Separator(frame_font, orient='horizontal').grid(row=2, columnspan=3, padx=10, pady=4, sticky='ew') # --- --- text ttk.Label(frame_font, style='subtitle.TLabel', text=_('Text')).grid(row=5, column=0, sticky='nw', padx=4, pady=8) self.tasks_font = FontFrame(frame_font, CONFIG.get('Tasks', 'font')) self.tasks_font.grid(row=5, column=1, padx=4, pady=4) # --- opacity self.tasks_opacity = OpacityFrame( self.frames[_('Tasks')], CONFIG.getfloat("Tasks", "alpha", fallback=0.85)) # --- colors frame_color = ttk.Frame(self.frames[_('Tasks')]) ttk.Label(frame_color, text=_('Colors'), style='title.TLabel').grid(row=0, column=0, sticky='w', padx=8, pady=4) self.tasks_bg = ColorFrame(frame_color, CONFIG.get('Tasks', 'background'), _('Background')) self.tasks_bg.grid(row=0, column=1, sticky='e', padx=8, pady=4) self.tasks_fg = ColorFrame(frame_color, CONFIG.get('Tasks', 'foreground'), _('Foreground')) self.tasks_fg.grid(row=0, column=2, sticky='e', padx=8, pady=4) # --- placement frame_font.grid(sticky='ew') ttk.Separator(self.frames[_('Tasks')], orient='horizontal').grid(sticky='ew', pady=8) self.tasks_opacity.grid(sticky='w', padx=4) ttk.Separator(self.frames[_('Tasks')], orient='horizontal').grid(sticky='ew', pady=8) frame_color.grid(sticky='w') ttk.Separator(self.frames[_('Tasks')], orient='horizontal').grid(sticky='ew', pady=8) ttk.Checkbutton(self.frames[_('Tasks')], text=_('Hide completed tasks'), variable=self.tasks_hide_comp).grid(sticky='w', padx=4, pady=4)
def _init_events(self): self.frames[_('Events')].columnconfigure(0, weight=1) # --- Fonts frame_font = ttk.Frame(self.frames[_('Events')]) frame_font.columnconfigure(2, weight=1) ttk.Label(frame_font, text=_('Font'), style='title.TLabel').grid(row=0, column=0, sticky='w', padx=4, pady=4) # --- --- title ttk.Label(frame_font, style='subtitle.TLabel', text=_('Title')).grid(row=1, column=0, sticky='ne', padx=4, pady=8) self.events_font_title = FontFrame(frame_font, CONFIG.get('Events', 'font_title'), True) self.events_font_title.grid(row=1, column=1, padx=4, pady=4) ttk.Separator(frame_font, orient='horizontal').grid(row=2, columnspan=3, padx=10, pady=4, sticky='ew') # --- --- day ttk.Label(frame_font, style='subtitle.TLabel', text=_('Day')).grid(row=3, column=0, sticky='ne', padx=4, pady=8) self.events_font_day = FontFrame(frame_font, CONFIG.get('Events', 'font_day'), True) self.events_font_day.grid(row=3, column=1, padx=4, pady=4) ttk.Separator(frame_font, orient='horizontal').grid(row=4, columnspan=3, padx=10, pady=4, sticky='ew') # --- --- text ttk.Label(frame_font, style='subtitle.TLabel', text=_('Text')).grid(row=5, column=0, sticky='ne', padx=4, pady=8) self.events_font = FontFrame(frame_font, CONFIG.get('Events', 'font')) self.events_font.grid(row=5, column=1, padx=4, pady=4) # --- opacity self.events_opacity = OpacityFrame( self.frames[_('Events')], CONFIG.getfloat("Events", "alpha", fallback=0.85)) # --- colors frame_color = ttk.Frame(self.frames[_('Events')]) ttk.Label(frame_color, text=_('Colors'), style='title.TLabel').grid(row=0, column=0, sticky='w', padx=8, pady=4) self.events_bg = ColorFrame(frame_color, CONFIG.get('Events', 'background'), _('Background')) self.events_bg.grid(row=0, column=1, sticky='e', padx=8, pady=4) self.events_fg = ColorFrame(frame_color, CONFIG.get('Events', 'foreground'), _('Foreground')) self.events_fg.grid(row=0, column=2, sticky='e', padx=8, pady=4) # --- placement frame_font.grid(sticky='ew') ttk.Separator(self.frames[_('Events')], orient='horizontal').grid(sticky='ew', pady=8) self.events_opacity.grid(sticky='w', padx=4) ttk.Separator(self.frames[_('Events')], orient='horizontal').grid(sticky='ew', pady=8) frame_color.grid(sticky='w')
def _init_calendar(self): # --- general config general = ttk.Frame(self.frames[_('Calendar')], padding=4) general.columnconfigure(1, weight=1) self.frames[_('Calendar')].add(general, text=_('General')) # --- --- opacity self.cal_opacity = OpacityFrame( general, CONFIG.getfloat('Calendar', 'alpha', fallback=0.85)) self.cal_opacity.grid(row=0, columnspan=2, sticky='w', padx=4) ttk.Separator(general, orient='horizontal').grid(row=1, columnspan=2, pady=10, sticky='ew') # --- --- font ttk.Label(general, text=_('Font'), style='title.TLabel').grid(row=2, sticky='nw', padx=4, pady=4) self.cal_font = FontFrame(general, CONFIG.get('Calendar', 'font')) self.cal_font.grid(row=2, column=1, sticky='w', padx=4, pady=4) # --- Colors frame_color = ttk.Frame(self.frames[_('Calendar')], padding=4) frame_color.columnconfigure(3, weight=1) self.frames[_('Calendar')].add(frame_color, text=_('Colors')) self.cal_colors = {} ttk.Label(frame_color, style='subtitle.TLabel', text=_('General')).grid(row=0, column=0, sticky='w') self.cal_bg = ColorFrame(frame_color, CONFIG.get('Calendar', 'background'), _('Background')) self.cal_fg = ColorFrame(frame_color, CONFIG.get('Calendar', 'foreground'), _('Foreground')) self.cal_bd = ColorFrame(frame_color, CONFIG.get('Calendar', 'bordercolor'), _('Border')) self.cal_bg.grid(row=0, column=1, sticky='e', padx=8, pady=4) self.cal_fg.grid(row=0, column=2, sticky='e', padx=8, pady=4) self.cal_bd.grid(row=1, column=1, sticky='e', padx=8, pady=4) cal_colors = { 'normal': _('Normal day'), 'weekend': _('Weekend'), 'othermonth': _('Other month day'), 'othermonthwe': _('Other month weekend'), 'select': _('Selected day'), 'headers': _('Headers'), 'tooltip': _('Tooltip') } for i, (name, label) in enumerate(cal_colors.items()): bg = ColorFrame(frame_color, CONFIG.get('Calendar', name + 'background'), _('Background')) fg = ColorFrame(frame_color, CONFIG.get('Calendar', name + 'foreground'), _('Foreground')) self.cal_colors[name + 'background'] = bg self.cal_colors[name + 'foreground'] = fg ttk.Separator(frame_color, orient='horizontal').grid(row=2 + 2 * i, columnspan=4, pady=10, sticky='ew') ttk.Label(frame_color, style='subtitle.TLabel', wraplength=110, text=label).grid(row=3 + 2 * i, column=0, sticky='w') bg.grid(row=3 + 2 * i, column=1, sticky='e', padx=8, pady=4) fg.grid(row=3 + 2 * i, column=2, sticky='e', padx=8, pady=4) # --- Categories categories = ttk.Frame(self.frames[_('Calendar')], padding=4) categories.columnconfigure(0, weight=1) categories.rowconfigure(0, weight=1) self.frames[_('Calendar')].add(categories, text=_('Event categories')) can = tk.Canvas(categories, bg=self['bg'], highlightthickness=0, width=1, relief='flat') scroll = AutoScrollbar(categories, orient='vertical', command=can.yview) can.configure(yscrollcommand=scroll.set) can.grid(row=0, column=0, sticky='ewns') scroll.grid(row=0, column=1, sticky='ns') ttk.Button(categories, image=self._im_plus, command=self.add_cat).grid(row=1, column=0, sticky='w', pady=4) self.cat_frame = ttk.Frame(can) can.create_window(0, 0, anchor='nw', window=self.cat_frame) self.cats = {} for i, cat in enumerate(CONFIG.options("Categories")): l = ttk.Label(self.cat_frame, text=cat, style='subtitle.TLabel') col = CONFIG.get('Categories', cat).split(', ') bg = ColorFrame(self.cat_frame, col[1].strip(), _('Background')) fg = ColorFrame(self.cat_frame, col[0].strip(), _('Foreground')) b = ttk.Button(self.cat_frame, image=self._im_moins, padding=2, command=lambda c=cat: self.del_cat(c)) self.cats[cat] = [l, bg, fg, b] l.grid(row=i, column=0, sticky='e', padx=4, pady=4) bg.grid(row=i, column=1, sticky='e', padx=4, pady=4) fg.grid(row=i, column=2, sticky='e', padx=4, pady=4) b.grid(row=i, column=3, sticky='e', padx=4, pady=4) self.update_idletasks() can.configure(width=self.cat_frame.winfo_reqwidth()) can.configure(scrollregion=can.bbox('all')) can.bind('<4>', lambda e: self._scroll(e, -1)) can.bind('<5>', lambda e: self._scroll(e, 1)) self.cat_frame.bind( '<Configure>', lambda e: can.configure(scrollregion=can.bbox('all')))
def _init_reminders(self): # --- window def toggle_window(): b = 'selected' in self.reminders_window.state() state = [b * '!' + 'disabled'] label.state(state) self.reminders_timeout.state(state) self.reminders_blink.state(state) self.reminders_sound.state(state) frame_window = ttk.Frame(self.frames[_('Reminders')]) frame_window.columnconfigure(0, weight=1) self.reminders_window = ttk.Checkbutton(frame_window, text=_('Banner'), style='title.TCheckbutton', command=toggle_window) self.reminders_window.grid(sticky='w', row=0, columnspan=2, column=0, pady=4) self.reminders_window.state( ('!alternate', '!' * (not CONFIG.getboolean('Reminders', 'window')) + 'selected')) # --- --- timeout frame_timeout = ttk.Frame(frame_window) frame_timeout.grid(sticky='w', padx=(16, 4), pady=4) label = ttk.Label(frame_timeout, text=_('Timeout (min)')) label.pack(side='left') self.reminders_timeout = ttk.Entry(frame_timeout, width=5, justify='center', validate='key', validatecommand=(self._only_nb, '%P')) self.reminders_timeout.insert(0, CONFIG.get('Reminders', 'timeout')) self.reminders_timeout.pack(side='left', padx=4) # --- --- colors frame_color = ttk.Frame(frame_window) frame_color.grid(sticky='w', padx=(16, 4), pady=4) self.reminders_window_bg = ColorFrame( frame_color, CONFIG.get('Reminders', 'window_bg'), _('Background')) self.reminders_window_bg.pack(side='left', padx=(0, 4)) self.reminders_window_fg = ColorFrame( frame_color, CONFIG.get('Reminders', 'window_fg'), _('Foreground')) self.reminders_window_fg.pack(side='left', padx=(4, 0)) # --- --- opacity self.reminders_opacity = OpacityFrame(frame_window, CONFIG.getfloat('Reminders', 'window_alpha', fallback=0.75), style='TLabel') self.reminders_opacity.grid(sticky='w', padx=(16, 4), pady=4) ttk.Separator(frame_window, orient='horizontal').grid(sticky='ew', padx=(16, 10), pady=10) # --- --- blink frame_blink = ttk.Frame(frame_window) frame_blink.grid(sticky='w', padx=(16, 4), pady=4) def toggle_blink(): b = 'selected' in self.reminders_blink.state() state = [b * '!' + 'disabled'] self.reminders_window_bg_alt.state(state) self.reminders_window_fg_alt.state(state) self.reminders_blink = ttk.Checkbutton(frame_blink, text=_('Blink'), command=toggle_blink) self.reminders_blink.pack(anchor='nw') self.reminders_blink.state( ('!alternate', '!' * (not CONFIG.getboolean('Reminders', 'blink')) + 'selected')) self.reminders_window_bg_alt = ColorFrame( frame_blink, CONFIG.get('Reminders', 'window_bg_alternate'), _('Alternate Background')) self.reminders_window_bg_alt.pack(side='left', padx=(16, 4)) self.reminders_window_fg_alt = ColorFrame( frame_blink, CONFIG.get('Reminders', 'window_fg_alternate'), _('Alternate Foreground')) self.reminders_window_fg_alt.pack(side='left', padx=10) toggle_blink() ttk.Separator(frame_window, orient='horizontal').grid(sticky='ew', padx=(16, 10), pady=10) # --- --- alarm self.reminders_sound = SoundFrame(frame_window, CONFIG.get('Reminders', 'alarm'), CONFIG.get('Reminders', 'mute'), _('Alarm')) self.reminders_sound.grid(sticky='ew', padx=(16, 10), pady=4) # --- notif frame_notif = ttk.Frame(self.frames[_('Reminders')]) self.reminders_notif = ttk.Checkbutton(frame_notif, text=_('Notification'), style='title.TCheckbutton') self.reminders_notif.grid(sticky='w', pady=4) self.reminders_notif.state( ('!alternate', '!' * (not CONFIG.getboolean('Reminders', 'notification')) + 'selected')) # --- placement frame_window.pack(anchor='nw', fill='x') ttk.Separator(self.frames[_('Reminders')], orient='horizontal').pack(fill='x', pady=10) frame_notif.pack(anchor='nw')
def _init_general(self): self.frames[_('General')].columnconfigure(0, weight=1) # --- variables self.gui = tk.StringVar(self, CONFIG.get("General", "trayicon").capitalize()) self.lang = tk.StringVar(self, LANGUAGES[CONFIG.get("General", "language")]) # --- Langue lang_frame = ttk.Frame(self.frames[_('General')]) ttk.Label(lang_frame, text=_("Language")).pack(side="left") languages = list(REV_LANGUAGES) self.cb_lang = ttk.Combobox(lang_frame, textvariable=self.lang, state='readonly', style='menu.TCombobox', exportselection=False, width=len(max(languages, key=len)) + 1, values=languages) self.cb_lang.pack(side="left", padx=4) self.cb_lang.bind('<<ComboboxSelected>>', self.change_langue) # --- gui toolkit frame_gui = ttk.Frame(self.frames[_('General')]) ttk.Label( frame_gui, text=_("GUI Toolkit for the system tray icon")).pack(side="left") self.cb_gui = ttk.Combobox( frame_gui, textvariable=self.gui, state='readonly', style='menu.TCombobox', exportselection=False, width=4, values=[t.capitalize() for (t, b) in TOOLKITS.items() if b]) self.cb_gui.pack(side="left", padx=4) self.cb_gui.bind('<<ComboboxSelected>>', self.change_gui) # --- Update checks # self.confirm_update = ttk.Checkbutton(self.frames[_('General')], # text=_("Check for updates on start-up")) # if CONFIG.getboolean('General', 'check_update', fallback=True): # self.confirm_update.state(('selected', '!alternate')) # else: # self.confirm_update.state(('!selected', '!alternate')) # --- eyes frame_eyes = ttk.Frame(self.frames[_('General')]) ttk.Label(frame_eyes, text=_("Eyes' rest"), style='title.TLabel').grid(sticky='w', padx=4, pady=4) ttk.Label(frame_eyes, text=_("Interval between two eyes' rest (min)")).grid( row=1, column=0, sticky='w', padx=4, pady=4) self.eyes_interval = ttk.Entry(frame_eyes, width=4, justify='center', validate='key', validatecommand=(self._only_nb, '%P')) self.eyes_interval.insert( 0, CONFIG.get("General", "eyes_interval", fallback='20')) self.eyes_interval.grid(row=1, column=1, sticky='w', padx=4, pady=4) # --- Splash supported self.splash_support = ttk.Checkbutton( self.frames[_('General')], text=_("Check this box if the widgets disappear when you click")) if not CONFIG.getboolean('General', 'splash_supported', fallback=True): self.splash_support.state(('selected', '!alternate')) else: self.splash_support.state(('!selected', '!alternate')) # --- Maintenance frame_maintenance = ttk.Frame(self.frames[_('General')]) ttk.Label(frame_maintenance, text=_("Maintenance"), style='title.TLabel').grid(sticky='w', padx=4, pady=4) ttk.Label(frame_maintenance, text=_("Delete all outdated events")).grid(row=1, column=0, sticky='w', padx=4, pady=4) ttk.Button(frame_maintenance, image=self._im_cleanup, padding=1, command=self.cleanup).grid(row=1, column=1, sticky='w', padx=4, pady=4) ttk.Label( frame_maintenance, text= _("Refresh scheduled reminders\n(needed after APScheduler's updates)" )).grid(row=2, column=0, sticky='w', padx=4, pady=4) ttk.Button(frame_maintenance, image=self._im_refresh, padding=1, command=self.refresh).grid(row=2, column=1, sticky='w', padx=4, pady=4) # --- placement ttk.Label(self.frames[_('General')], text=_("Interface"), style='title.TLabel').grid(sticky='w', pady=4) lang_frame.grid(pady=4, sticky="ew") frame_gui.grid(pady=4, sticky="ew") # self.confirm_update.grid(pady=4, sticky='w') self.splash_support.grid(pady=4, sticky='w') ttk.Separator(self.frames[_('General')], orient='horizontal').grid(sticky='ew', pady=10) frame_eyes.grid(pady=4, sticky="ew") ttk.Separator(self.frames[_('General')], orient='horizontal').grid(sticky='ew', pady=10) frame_maintenance.grid(pady=4, sticky="ew")
def __init__(self, parent, **options): """ créer le Toplevel permettant de modifier les paramètres """ Frame.__init__(self, parent, **options) self.onglets = Notebook(self) self.onglets.pack(fill='both', expand=True) self.im_color = PhotoImage(master=self, file=IM_COLOR) self.im_plus = PhotoImage(master=self, file=IM_ADD) self.im_moins = PhotoImage(master=self, file=IM_DEL) self.okfct = self.register(only_nb) self.style = Style(self) self.nb_task = len(CONFIG.options("PomodoroTasks")) # --- Général (temps, police et langue) self.general = Frame(self.onglets, padding=10) self.general.columnconfigure(1, weight=1) self.onglets.add(self.general, text=_("General")) # --- --- Temps Label(self.general, text=_("Times (min)"), style='title.TLabel').grid(row=0, pady=4, padx=(2, 10), sticky="w") self.time_frame = Frame(self.general) self.time_frame.grid(row=0, column=1, sticky="w", padx=4) Label(self.time_frame, text=_("Work")).grid(row=0, padx=4, column=0) self.travail = Entry(self.time_frame, width=4, justify='center', validatecommand=(self.okfct, '%P'), validate='key') self.travail.insert(0, CONFIG.get("Pomodoro", "work_time")) self.travail.grid(row=0, column=1, padx=(0, 10)) Label(self.time_frame, text=_("Break")).grid(row=0, column=2, padx=4) self.pause = Entry(self.time_frame, width=4, justify='center', validatecommand=(self.okfct, '%P'), validate='key') self.pause.insert(0, CONFIG.get("Pomodoro", "break_time")) self.pause.grid(row=0, column=3, padx=(0, 10)) Label(self.time_frame, text=_("Rest")).grid(row=0, column=4, padx=4) self.rest = Entry(self.time_frame, width=4, justify='center', validatecommand=(self.okfct, '%P'), validate='key') self.rest.insert(0, CONFIG.get("Pomodoro", "rest_time")) self.rest.grid(row=0, column=5) Separator(self.general, orient='horizontal').grid(row=1, columnspan=2, sticky="ew", pady=10) # --- --- Police Label(self.general, text=_("Font"), style='title.TLabel').grid(row=2, sticky='nw', padx=(2, 10)) self.font = FontFrame(self.general, font=CONFIG.get('Pomodoro', 'font'), sample_text="02:17") self.font.grid(row=2, column=1, padx=4, sticky='w') Separator(self.general, orient='horizontal').grid(row=3, columnspan=2, sticky="ew", pady=10) # --- --- Opacity self.opacity = OpacityFrame(self.general) self.opacity.grid(row=5, columnspan=2, sticky='w', padx=(2, 4), pady=4) Separator(self.general, orient='horizontal').grid(row=6, columnspan=2, sticky="ew", pady=10) # --- --- Son self.sound = SoundFrame(self.general, CONFIG.get("Pomodoro", "beep"), mute=CONFIG.getboolean("Pomodoro", "mute"), label=_("Sound"), style='title.TLabel') self.sound.grid(row=7, columnspan=2, sticky='ew', pady=4) # --- Couleurs self.couleurs = Frame(self.onglets, padding=10) self.couleurs.columnconfigure(3, weight=1) self.onglets.add(self.couleurs, text=_("Colors")) self.bg = ColorFrame(self.couleurs, CONFIG.get("Pomodoro", "background"), _("Background")) self.work_bg = ColorFrame(self.couleurs, CONFIG.get("Pomodoro", "work_bg"), _("Background")) self.break_bg = ColorFrame(self.couleurs, CONFIG.get("Pomodoro", "break_bg"), _("Background")) self.rest_bg = ColorFrame(self.couleurs, CONFIG.get("Pomodoro", "rest_bg"), _("Background")) self.fg = ColorFrame(self.couleurs, CONFIG.get("Pomodoro", "foreground"), _("Foreground")) self.work_fg = ColorFrame(self.couleurs, CONFIG.get("Pomodoro", "work_fg"), _("Foreground")) self.break_fg = ColorFrame(self.couleurs, CONFIG.get("Pomodoro", "break_fg"), _("Foreground")) self.rest_fg = ColorFrame(self.couleurs, CONFIG.get("Pomodoro", "rest_fg"), _("Foreground")) Label(self.couleurs, text=_("General"), style='title.TLabel').grid(row=0, column=0, pady=4, padx=(2, 10), sticky="w") self.bg.grid(row=0, column=1, sticky='e', padx=8, pady=4) self.fg.grid(row=0, column=2, sticky='e', padx=8, pady=4) Separator(self.couleurs, orient='horizontal').grid(row=1, sticky="ew", pady=10, columnspan=4) Label(self.couleurs, text=_("Work"), style='title.TLabel').grid(row=2, column=0, pady=4, padx=(2, 10), sticky="w") self.work_bg.grid(row=2, column=1, sticky='e', padx=8, pady=4) self.work_fg.grid(row=2, column=2, sticky='e', padx=8, pady=4) Separator(self.couleurs, orient='horizontal').grid(row=3, sticky="ew", pady=10, columnspan=4) Label(self.couleurs, text=_("Break"), style='title.TLabel').grid(row=4, column=0, pady=4, padx=(2, 10), sticky="w") self.break_bg.grid(row=4, column=1, sticky='e', padx=8, pady=4) self.break_fg.grid(row=4, column=2, sticky='e', padx=8, pady=4) Separator(self.couleurs, orient='horizontal').grid(row=5, sticky="ew", pady=10, columnspan=4) Label(self.couleurs, text=_("Rest"), style='title.TLabel').grid(row=6, column=0, pady=4, padx=(2, 10), sticky="w") self.rest_bg.grid(row=6, column=1, sticky='e', padx=8, pady=4) self.rest_fg.grid(row=6, column=2, sticky='e', padx=8, pady=4) # --- Tasks self.stats = Frame(self.onglets, padding=10) self.stats.columnconfigure(0, weight=1) self.stats.rowconfigure(2, weight=1) self.onglets.add(self.stats, text=_("Tasks")) # graph legend legend_frame = Frame(self.stats) Label(legend_frame, style='title.TLabel', text=_('Maximum number of rows in the legend')).pack(side='left') self.legend_row_nb = Entry(legend_frame, width=4, justify='center', validatecommand=(self.okfct, '%P'), validate='key') self.legend_row_nb.insert( 0, CONFIG.get('Pomodoro', 'legend_max_height', fallback='6')) self.legend_row_nb.pack(side='left', padx=4) # task colors can = Canvas(self.stats, bg=self.style.lookup('TFrame', 'background'), highlightthickness=0, width=1, relief='flat') scroll = AutoScrollbar(self.stats, orient='vertical', command=can.yview) can.configure(yscrollcommand=scroll.set) self.task_frame = Frame(can) can.create_window(0, 0, anchor='nw', window=self.task_frame) tasks = CONFIG.options("PomodoroTasks") tasks.sort() cmap = [CONFIG.get("PomodoroTasks", task) for task in tasks] self.tasks = {} self._tasks_btns = {} for i, (coul, task) in enumerate(zip(cmap, tasks)): self.tasks[task] = ColorFrame(self.task_frame, coul, task.capitalize()) self.tasks[task].grid(row=i, column=0, sticky='e', padx=4, pady=4) b = Button(self.task_frame, image=self.im_moins, padding=2, command=lambda t=task: self.del_task(t)) b.grid(row=i, column=1, sticky='w', padx=4, pady=4) self._tasks_btns[task] = b if len(tasks) == 1: self._tasks_btns[tasks[0]].state(['disabled']) legend_frame.grid(row=0, columnspan=2, sticky='w', pady=4) Label(self.stats, text=_('Colors in the statistic graph'), style='title.TLabel').grid(row=1, column=0, sticky='w', pady=4) can.grid(row=2, column=0, sticky='ewns') scroll.grid(row=2, column=1, sticky='ns') Button(self.stats, image=self.im_plus, command=self.add_task).grid(row=3, column=0, sticky='w') self.update_idletasks() can.configure(width=self.task_frame.winfo_reqwidth()) can.configure(scrollregion=can.bbox('all')) can.bind('<4>', lambda e: self._scroll(e, -1)) can.bind('<5>', lambda e: self._scroll(e, 1)) self.task_frame.bind( '<Configure>', lambda e: can.configure(scrollregion=can.bbox('all')))
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()
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