Esempio n. 1
0
    def display_alarms(self):
        self.active_alarms = {}

        if not self.save_file_dict:
            tk.Label(self,
                     text='No Alarms',
                     bg='white',
                     fg=rgb(167, 167, 167),
                     font=('arial', 15)).pack(side=tk.TOP, anchor=tk.W)
            return
        scroll_bar = ScrolledFrame(self, hscrollmode='none', borderframe=0)
        scroll_bar.pack(fill='both', expand=1)
        scroll_frame = scroll_bar.interior()
        scroll_frame.configure(bg='white')
        for it, alarm in enumerate(self.save_file_dict):
            main_frame = tk.Frame(scroll_frame, bg='white')
            main_frame.bind(
                '<Enter>',
                lambda e, s=self, f=main_frame: s.set_frame_color(f))
            main_frame.bind(
                '<Leave>',
                lambda e, s=self, f=main_frame: s.set_frame_color(f, False))
            cur_file = self.save_file_dict[alarm]
            time = cur_file['alarm_time']
            ind = time.rfind(':')
            alarm_time = time[:ind] + ' ' + time[ind + 1:]

            text_frame = tk.Frame(main_frame, bg='white', width=350, height=70)
            text_frame.pack_propagate(0)
            tk.Label(text_frame,
                     text=alarm_time,
                     bg='white',
                     font=('arial', 15)).pack(side=tk.TOP, anchor=tk.W)
            name_label = tk.Label(text_frame,
                                  text=cur_file['alarm_name'],
                                  bg='white',
                                  font=('arial', 11, 'bold'))
            name_label.pack(side=tk.TOP, anchor=tk.W)
            tk.Label(text_frame,
                     text=cur_file['trim_repeat_days'],
                     bg='white',
                     font=('arial', 11)).pack(side=tk.TOP, anchor=tk.W)
            text_frame.pack(side=tk.LEFT)

            # check_button_frame = tk.Frame(main_frame, bg='white', width=60, height=70)
            # check_button_frame.pack_propagate(0)
            check_button_frame = tk.Frame(main_frame,
                                          bg='white',
                                          width=95,
                                          height=70)
            check_button_frame.pack_propagate(0)

            check_name = tk.StringVar()
            check_bool = tk.BooleanVar()
            check_bool.set(cur_file['active'])
            # check_button = tk.Checkbutton(check_button_frame, textvar=check_name, state=tk.NORMAL, bg='white', anchor=tk.W,
            #                variable=check_bool, takefocus=0)
            # check_button.bind('<Button-1>', lambda e, s=self, a=alarm: s.display(a))
            # check_button.pack(side=tk.RIGHT, ipadx=(40))
            check_button = TickButton(
                check_button_frame,
                on_off_text=('Off', 'On'),
                function=lambda s=self, a=alarm: s.specialised_button(a),
                textvar=check_name,
                variable=check_bool,
                bg='white')
            check_button.pack(side=tk.RIGHT, ipadx=(40))
            check_button_frame.pack(side=tk.RIGHT)
            self.active_alarms[alarm] = [
                time, name_label, check_name, check_bool
            ]
            self.display(alarm, True)
            #this applies mouse button event to all the widgets except for the checkbutton
            self.apply_binding_toall(
                main_frame,
                '<Button-1>',
                lambda x, s=self, a=alarm: s.show_alarm_details(a),
                [check_button])

            main_frame.pack(side=tk.TOP,
                            expand=False,
                            anchor=tk.N + tk.W,
                            fill=tk.Y,
                            pady=(0, 9))
Esempio n. 2
0
    def __init__(self, configobj):
        self.window = Toplevel()
        # self.window.option_add("*Background", "white")
        self.window.protocol('WM_DELETE_WINDOW', self.cancel)

        f0 = Frame(self.window)
        f0.pack(side='top', anchor='w', expand=False, fill='x')
        t = _(
            'Note that most changes become effective only after restarting the program.'
        )
        text = Text(f0, height=len(t) // 80 + 1, width=80, wrap='word')
        text.insert(1.0, _(t))
        text.config(state='disabled')
        text.pack(side='left', expand=True, fill='x')
        Button(f0, text=_('Save'), command=self.save,
               bg='lightgreen').pack(side='right', anchor='e')
        Button(f0, text=_('Cancel'), command=self.cancel,
               bg='orange').pack(side='right', anchor='e')

        self.configobj = configobj
        self.variables = {
        }  # will store the Tkinter variables containing the values
        special_values = [
            '# -----',
            '# section',
            '# label',
            '# editable',
            '# values',
        ]

        sf = ScrolledFrame(self.window, usehullsize=1, hull_height=500)
        sf.pack(side='top', anchor='w', expand=True, fill='both')
        f = sf.interior()
        ctr = -1

        for prop in configobj['options']:
            comments = configobj['options'].comments[prop]

            # new "section"?
            sec = self.retrieve('# section:', comments)
            if sec:
                ctr += 1
                Label(f,
                      text=_(sec),
                      justify='left',
                      bg='#eeeeee',
                      font=('Helvetica', 14, 'bold')).grid(row=ctr,
                                                           column=0,
                                                           columnspan=3,
                                                           sticky='we',
                                                           pady=10)

            if '# editable' in comments:
                ctr += 1

                label = self.retrieve('# label:', comments) or prop
                label = label.strip()
                values = self.retrieve('# values:', comments)
                if values:
                    values = values.split(', ')
                else:
                    values = []
                help_text = ' '.join(
                    x[1:].strip() for x in comments
                    if not any(x.startswith(v)
                               for v in special_values)).strip()

                if 'BOOLEAN' in values:
                    self.variables[prop] = BooleanVar()
                else:
                    self.variables[prop] = StringVar()

                if '--' in values and configobj['options'][prop] == '':
                    self.variables[prop].set('--')
                else:
                    self.variables[prop].set(configobj['options'][prop])

                if 'BOOLEAN' in values:
                    Checkbutton(f,
                                text=_(label),
                                indicatoron=1,
                                variable=self.variables[prop]).grid(
                                    row=ctr, column=1, sticky='nw', pady=5)
                elif values and not 'INT' in values:
                    Label(f, text=_(label), justify='left').grid(row=ctr,
                                                                 column=0,
                                                                 sticky='nw',
                                                                 pady=5)
                    Combobox(
                        f,
                        justify='left',
                        textvariable=self.variables[prop],
                        values=values,
                    ).grid(row=ctr, column=1, sticky='nw', pady=5)
                else:
                    Label(f, text=_(label), justify='left').grid(row=ctr,
                                                                 column=0,
                                                                 sticky='nw',
                                                                 pady=5)
                    Entry(f, width=20,
                          textvariable=self.variables[prop]).grid(row=ctr,
                                                                  column=1,
                                                                  sticky='nw',
                                                                  pady=5)
                if help_text:
                    ht = _(help_text)
                    text = Text(f,
                                height=len(ht) // 60 + 1,
                                width=60,
                                borderwidth=0,
                                wrap='word')
                    text.insert(1.0, _(help_text))
                    text.config(state='disabled')
                    text.grid(row=ctr, column=2, sticky='nsew', pady=5)

        self.window.update_idletasks()

        self.window.focus()
        self.window.grab_set()
        self.window.wait_window()