Ejemplo n.º 1
0
class StatusBar(Frame):
    def __init__(self, master, progressMax=100, **kwargs):
        Frame.__init__(self, master, **kwargs)

        self.label = Label(self, text="Ready...")
        self.label.pack(anchor=Tkc.W)

        self.progressVar = IntVar()
        self.progress = Progressbar(self,
                                    mode='determinate',
                                    maximum=abs(progressMax),
                                    length="150",
                                    variable=self.progressVar)

    def showText(self, message):
        self.label.configure(text=message)
        self.progress.stop()
        self.progress.pack_forget()
        self.label.pack(anchor=Tkc.W)

    def showProgress(self):
        self.progress.configure(mode='determinate')
        self.label.pack_forget()
        self.progress.pack(anchor=Tkc.W)
        self.update_idletasks()

    def setProgress(self, value):
        self.progressVar.set(value)
        self.update_idletasks()

    def setProgressMax(self, value):
        self.progress.configure(maximum=abs(value))

    def showActivity(self):
        self.progress.configure(mode='indeterminate')
        self.progress.start()
        self.showProgress()
Ejemplo n.º 2
0
class MainApp():
    def __init__(self):
        self.File_name = None
        self.Programe_Name = "CHE-Editor"
        self.WDG = Tk()
        self.WDG.title(self.Programe_Name)
        self.WDG.iconbitmap("icons/icon_editor.ico")
        self.WDG.geometry("860x620")
        self.WDG.maxsize(width=1340, height=700)
        self.WDG.minsize(width=860, height=620)
        self.Main_UI()

    def Main_UI(self):
        self.MenuBar = Menu(self.WDG)

        #1      #MenuBar
        #File_menu
        self.File_menu = Menu(self.MenuBar, tearoff=0, title="File")
        self.MenuBar.add_cascade(label="File", menu=self.File_menu)
        #Edit_menu
        self.Edit_menu = Menu(self.MenuBar, tearoff=0, title="Edit")
        self.MenuBar.add_cascade(label="Edit", menu=self.Edit_menu)
        #View_menu
        self.View_menu = Menu(self.MenuBar, tearoff=0, title="View")
        self.MenuBar.add_cascade(label="View", menu=self.View_menu)
        #Theme_menu in View
        self.Theme_menu = Menu(self.View_menu, tearoff=0, title="Theme")
        self.View_menu.add_cascade(label="Theme", menu=self.Theme_menu)
        #Option_menu
        self.Options_menu = Menu(self.MenuBar, tearoff=0, title="Options")
        self.MenuBar.add_cascade(label="Options", menu=self.Options_menu)
        #Help_menu
        self.Help_menu = Menu(self.MenuBar, tearoff=0, title="Help")
        self.MenuBar.add_cascade(label="Help", menu=self.Help_menu)

        #2      #Icons Variables
        #Edit_Menu Icons
        Undo = PhotoImage(file="icons/Undo.gif")
        Redo = PhotoImage(file="icons/redo.gif")
        Paste = PhotoImage(file="icons/paste.gif")
        Copy = PhotoImage(file="icons/copy.gif")
        Cut = PhotoImage(file="icons/cut.gif")
        #Help_Menu_Icons
        Help = PhotoImage(file="icons/help.gif")
        About = PhotoImage(file="icons/about.gif")
        #File_Menu_Icons
        New = PhotoImage(file="icons/new.gif")
        Open = PhotoImage(file="icons/open.gif")
        Save = PhotoImage(file="icons/save.gif")
        Save_As = PhotoImage(file="icons/save_as.gif")
        Exit = PhotoImage(file="icons/exit.gif")

        #Appear menubar in app
        self.WDG.config(menu=self.MenuBar)
        #self.WDG.config(menu=self.IconBar)

        #3      #Set commands in menus
        #File_Menu
        self.File_menu.add_command(label="New",
                                   accelerator="Ctrl+N",
                                   compound="left",
                                   underline=0,
                                   command=self.New)
        self.File_menu.add_command(label="Open",
                                   accelerator="Ctrl+O",
                                   compound="left",
                                   underline=0,
                                   command=self.Open)
        self.File_menu.add_command(label="Save",
                                   accelerator="Ctrl+S",
                                   compound="left",
                                   underline=0,
                                   command=self.Save)
        self.File_menu.add_command(label="Save as",
                                   accelerator="Shift+Ctrl+S",
                                   compound="left",
                                   underline=0,
                                   command=self.Save_As)
        self.File_menu.add_separator()
        self.File_menu.add_command(label="Exit",
                                   accelerator="F4",
                                   compound="left",
                                   underline=0,
                                   command=self.Exit)
        #Edit_Menu
        self.Edit_menu.add_command(label="Undo",
                                   accelerator="Ctrl+Z",
                                   compound="left",
                                   underline=0,
                                   command=self.Undo)
        self.Edit_menu.add_command(label="Redo",
                                   accelerator='Ctrl+Y',
                                   compound='left',
                                   underline=0,
                                   command=self.Redo)
        self.Edit_menu.add_command(label="Select all",
                                   accelerator='Ctrl+A',
                                   compound='left',
                                   underline=0,
                                   command=self.Select)
        self.Edit_menu.add_command(label="Cut",
                                   accelerator='Ctrl+X',
                                   compound='left',
                                   underline=7,
                                   command=self.Cut)
        self.Edit_menu.add_command(label="Copy",
                                   accelerator='Ctrl+C',
                                   compound='left',
                                   underline=0,
                                   command=self.Copy)
        self.Edit_menu.add_command(label="Paste",
                                   accelerator='Ctrl+V',
                                   compound='left',
                                   underline=0,
                                   command=self.Paste)
        self.Edit_menu.add_command(label="Search",
                                   accelerator='Ctrl+F',
                                   compound='left',
                                   underline=0,
                                   command=self.Search)
        #Help_Menu
        self.Help_menu.add_command(label="Help",
                                   accelerator="F1",
                                   compound="left",
                                   underline=0,
                                   command=self.Help)
        self.Help_menu.add_command(label="About",
                                   compound="left",
                                   underline=0,
                                   command=self.About)
        #View_Menu
        self.Show_line_number = IntVar()
        self.Show_line_number.set(1)
        self.theme_name = StringVar()
        self.View_menu.add_checkbutton(label="Show Line Number",
                                       variable=self.Show_line_number)
        self.Highlightline = BooleanVar()
        self.View_menu.add_checkbutton(label='Highlight Current Line',
                                       onvalue=1,
                                       offvalue=0,
                                       variable=self.Highlightline,
                                       command=self.Toggle_highlight)
        self.cursorcoord = BooleanVar()
        self.View_menu.add_checkbutton(label='Show Cursor Location',
                                       variable=self.cursorcoord,
                                       command=self.Show_cursor_coord)
        self.Theme_menu.add_radiobutton(label="Default",
                                        variable=self.theme_name)

        #4      #add Shortcut_Bar & Row_Number_Bar
        #Shortcut_Bar
        self.Shortcut_Bar = Frame(self.WDG, height=25)
        self.Shortcut_Bar.pack(expand='no', fill='x')
        Icons = ['New', 'Open', 'Save', 'Copy', 'Cut', 'Paste', 'Undo', 'Redo']
        for i, icon in enumerate(Icons):
            Tool_icon = PhotoImage(file='icons/{}.gif'.format(icon))
            #c_var = 'self.{}'.format(icon)
            cmd = eval('self.{}'.format(icon))
            self.Tool_bar_btn = Button(self.Shortcut_Bar,
                                       image=Tool_icon,
                                       command=cmd)
            self.Tool_bar_btn.image = Tool_icon
            self.Tool_bar_btn.pack(side='left')
        #Row_Number_Bar
        self.Row_Number_Bar = Text(self.WDG,
                                   width=3,
                                   padx=3,
                                   takefocus=0,
                                   border=0,
                                   background='khaki',
                                   state='disabled',
                                   wrap='none')
        self.Row_Number_Bar.pack(side='left', fill='y')

        #5      #add Content_Text
        self.Content_Text = Text(self.WDG, wrap='word', undo=1)
        self.Content_Text.pack(expand='yes', fill='both')
        self.Content_Text.tag_configure('active_line', background='ivory2')
        self.Scroll_Bar = Scrollbar(self.Content_Text)
        self.Content_Text.configure(yscrollcommand=self.Scroll_Bar.set)
        self.Scroll_Bar.config(command=self.Content_Text.yview)
        self.Scroll_Bar.pack(side='right', fill='y')

        #6      #add_Cursor_Coord_Bar
        self.Cursor_Coord_Bar = Label(self.Content_Text,
                                      text='Row: 1 | Column: 1')
        self.Cursor_Coord_Bar.pack(fill=None,
                                   expand='no',
                                   side='right',
                                   anchor='se')

        #7      #Binding
        self.Content_Text.bind("<Control-o>", self.Open)
        self.Content_Text.bind("<Control-O>", self.Open)
        self.Content_Text.bind("<Control-s>", self.Save)
        self.Content_Text.bind("<Control-S>", self.Save)
        self.Content_Text.bind("<Shift-Control-KeyPress-s>", self.Save_As)
        self.Content_Text.bind("<Shift-Control-KeyPress-S>", self.Save_As)
        self.Content_Text.bind("<Control-n>", self.New)
        self.Content_Text.bind("<Control-N>", self.New)
        self.Content_Text.bind("<Control-z>", self.Undo)
        self.Content_Text.bind("<Control-Z>", self.Undo)
        self.Content_Text.bind("<Control-y>", self.Redo)
        self.Content_Text.bind("<Control-Y>", self.Redo)
        self.Content_Text.bind("<Control-x>", self.Cut)
        self.Content_Text.bind("<Control-X>", self.Cut)
        self.Content_Text.bind("<Control-a>", self.Select)
        self.Content_Text.bind("<Control-A>", self.Select)
        self.Content_Text.bind("<Control-c>", self.Copy)
        self.Content_Text.bind("<Control-C>", self.Copy)
        self.Content_Text.bind("<Control-v>", self.Paste)
        self.Content_Text.bind("<Control-V>", self.Paste)
        self.Content_Text.bind("<Control-f>", self.Search)
        self.Content_Text.bind("<Control-F>", self.Search)
        self.Content_Text.bind("<Any-KeyPress>", self.Content_changed)
        self.WDG.bind_all("<KeyPress-F1>", self.Help)
        self.WDG.bind_all("<KeyPress-F4>", self.Exit)


#8  #Built In Finctions
#File_Menu_Functions

    def New(self, event=None):
        self.Content_Text.delete(1., 'end')
        self.WDG.title('{} - {}'.format('Untitled', self.Programe_Name))

    ##
    def Open(self, event=None):
        self.Open_file_name = filedialog.askopenfilename(
            defaultextension=".txt",
            filetypes=[("All Files", "*.*"), ("Text Documents", "*.txt")])
        if self.Open_file_name:
            self.File_name = self.Open_file_name
            self.WDG.title("{} - {}".format(os.path.basename(self.File_name),
                                            self.Programe_Name))
            self.Content_Text.delete(1.0, 'end')
            with open(self.File_name) as _File:
                self.Content_Text.insert(1.0, _File.read())

    ##
    def Save(self, event=None):
        if not self.File_name:
            self.Save_As()
        else:
            self.Write_to_file(self.File_name)
        return "break"

    ##
    def Save_As(self, event=None):
        self.Save_file_name = filedialog.asksaveasfilename(
            defaultextension='.txt',
            filetypes=[('All Files', '*.*'), ('Text Documents', '*.txt')])
        if self.Save_file_name:
            self.File_name = self.Save_file_name
            self.Write_to_file(self.File_name)
            self.WDG.title('{} - {}'.format(os.path.basename(self.File_name),
                                            self.Programe_Name))
        return "break"

    ##
    def Write_to_file(self, filename):
        try:
            self.content = self.Content_Text.get(1.0, 'end')
            with open(self.File_name, 'w') as the_file:
                the_file.write(self.content)
        except IOError as er:
            print(er)

    ##
    def Exit(self, event=None):
        self.msg_exit = messagebox.askyesno('Exit Editor',
                                            'Do you want to exit?')
        if self.msg_exit:
            self.WDG.destroy()

    #Edit_Menu_Functions
    ##
    def Select(self, event=None):
        self.Content_Text.tag_add("sel", 1.0, "end")
        print("Done1")
        return "breake"

    ##
    def Cut(self, event=None):
        self.Content_Text.event_generate("<<Cut>>")
        return "breake"

    ##
    def Copy(self, event=None):
        self.Content_Text.event_generate("<<Copy>>")
        return "breake"

    ##
    def Paste(self, event=None):
        self.Content_Text.event_generate("<<Paste>>")
        return "breake"

    ##
    def Undo(self, event=None):
        self.Content_Text.event_generate("<<Undo>>")
        return "breake"

    ##
    def Redo(self, event=None):
        self.Content_Text.event_generate("<<Redo>>")
        return "breake"

    ##
    def Search(self, event=None):
        self.Search_Window = Toplevel(self.WDG)
        self.Search_Window.title("Search About...")
        self.Search_Window.transient(self.WDG)
        self.Search_Window.resizable(False, False)
        self.S_lbl_1 = Label(self.Search_Window, text='Search About :')
        self.S_lbl_1.grid(row=0, column=0, sticky='e')
        self.S_ent_1 = Entry(self.Search_Window, width=28)
        self.S_ent_1.grid(row=0, column=1, padx=2, pady=2, sticky='we')
        self.S_ent_1.focus_set()
        Ignore_case_value = IntVar()
        self.S_chk_1 = Checkbutton(self.Search_Window,
                                   text='Ignor Case',
                                   variable=Ignore_case_value)
        self.S_chk_1.grid(row=1, column=1, padx=2, pady=2, sticky='e')
        self.S_btn_1 = Button(
            self.Search_Window,
            text='Find',
            underline=0,
            command=lambda: self.Search_results(self.S_ent_1.get(
            ), Ignore_case_value.get(), self.Content_Text, self.Search_Window,
                                                self.S_ent_1))
        self.S_btn_1.grid(row=0, column=2, padx=2, pady=2, sticky='e' + 'w')
        self.S_btn_2 = Button(self.Search_Window,
                              text='Cancel',
                              underline=0,
                              command=self.Close_Search_Window)
        self.S_btn_2.grid(row=1, column=2, padx=2, pady=2, sticky='e' + 'w')

    ##
    def Search_results(self, Keyword, IfIgnoreCase, Content, Output, Input):
        Content.tag_remove('match', '1.0', 'end')
        matches_found = 0
        if Keyword:
            start_pos = '1.0'
            while True:
                start_pos = Content.search(Keyword,
                                           start_pos,
                                           nocase=IfIgnoreCase,
                                           stopindex='end')
                if not start_pos:
                    break
                end_pos = "{} + {}c".format(start_pos, len(Keyword))
                Content.tag_add('match', start_pos, end_pos)
                matches_found += 1
                start_pos = end_pos
            Content.tag_config('match', foreground='red', background='yellow')
            Input.focus_set()
            Output.title("{} matches found".format(matches_found))

    ##
    def Close_Search_Window(self):
        self.Content_Text.tag_remove('match', '1.0', 'end')
        self.Search_Window.destroy()
        #self.Search_Window.protocol('WM_DELETE_WINDOW',self.Close_Search_Window)
        return "break"

    #View_Menu_Functions
    ##
    def Content_changed(self, event=None):
        self.Update_line_numbers()
        self.Update_cursor_coord()

    ##
    def Get_line_numbers(self, event=None):
        self.Number = ""
        if self.Show_line_number.get():
            self.Row, self.Column = self.Content_Text.index('end').split('.')
            for i in range(1, int(self.Row)):
                self.Number += str(i) + "\n"
        return self.Number

    ##
    def Update_line_numbers(self):
        self.Line_Number = self.Get_line_numbers()
        self.Row_Number_Bar.config(state='normal')
        self.Row_Number_Bar.delete(1.0, 'end')
        self.Row_Number_Bar.insert(1.0, self.Line_Number)
        self.Row_Number_Bar.config(state='disabled')

    ##
    def Toggle_highlight(self, event=None):
        if self.Highlightline.get():
            self.Highlight_line()
        else:
            self.Undo_highlight()

    ##
    def Highlight_line(self, interval=100):
        self.Content_Text.tag_remove('active_line', 1.0, 'end')
        self.Content_Text.tag_add('active_line', "insert linestart",
                                  "insert lineend+1c")
        self.Content_Text.after(interval, self.Toggle_highlight)

    ##
    def Undo_highlight(self):
        self.Content_Text.tag_remove('active_line', 1.0, 'end')

    ##
    def Show_cursor_coord(self):
        self.cursor_coord_checked = self.cursorcoord.get()
        if self.cursor_coord_checked:
            self.Cursor_Coord_Bar.pack(expand='no',
                                       fill=None,
                                       side='right',
                                       anchor='se')
        else:
            self.Cursor_Coord_Bar.pack_forget()

    ##
    def Update_cursor_coord(self):
        self.Row_2, self.Column_2 = self.Content_Text.index('insert').split(
            '.')
        self.row_num, self.col_num = str(int(
            self.Row_2)), str(int(self.Column_2) + 1)
        self.Coord = "Row: {} | Column: {}".format(self.row_num, self.col_num)
        self.Cursor_Coord_Bar.config(text=self.Coord)

    #Help_Menu_Functions
    ##
    def About(self, event=None):
        messagebox.showinfo(
            'About', '{} {}'.format(self.Programe_Name,
                                    '\nDeveloped by \n TaReK'))

    ##
    def Help(self, event=None):
        messagebox.showinfo('Help',
                            'Text Editor building in python',
                            icon='question')
Ejemplo n.º 3
0
class CalibrationDialog(BeeDialog):

    _main_window = None  #: tk.Tk
    _hive = None  #: Hive
    _bar = None  #: Progressbar
    _close_enabled = True

    _button_box = None  #: Frame
    _start_button = None

    _calibration = None

    _humidity = None

    _yes_button = None
    _no_button = None

    _header = None

    _expected_weight_label = None  #: : tk.Label
    _expected_weight_field = None  #: : tk.Entry
    _expected_weight_box = None

    _weight_display = None
    _temp_display = None

    def __init__(self, main_window: tk.Tk, hive: Hive):
        self._main_window = main_window
        self._hive = hive
        super().__init__(parent=main_window,
                         title="Waage kalibrieren",
                         width=310,
                         height=120)

    def _init_expected_weight_box(self):
        self._expected_weight_box = Frame(self)

        self._expected_weight_label = Label(self._expected_weight_box,
                                            text='Gewicht (g)',
                                            font=('Arial', 10),
                                            anchor='e',
                                            wraplength=100,
                                            background='#ffffcc')
        self._expected_weight_label.grid(column=0, row=0, sticky='e')
        self._expected_weight_field = Entry(self._expected_weight_box,
                                            font=('Arial', 8),
                                            width="20")
        self._expected_weight_field.grid(column=1, row=0)

    def open(self):
        pass

    def cancel(self, event=None):
        if self._close_enabled:
            super().cancel(event)

    def body(self, master):
        self._calibration = HiveCalibration()
        self._header = Label(master, text="")
        self._bar = Progressbar(master, length=210)
        self._init_expected_weight_box()
        self._weight_display = Label(master, text="")
        self._temp_display = Label(master, text="")
        self._prepare_tara()

    def _prepare_tara(self):
        self._header.config(
            text='Drücken Sie "Start" um die Waage\n zu tarieren.')
        self._header.pack()

    def _standard_buttons(self):
        self._button_box = Frame(self)
        self._button_box.pack()
        self._start_button = Button(self._button_box,
                                    text="Start",
                                    width=10,
                                    command=self._calc_offset,
                                    default=ACTIVE)
        self._start_button.pack(side=LEFT, padx=5, pady=5)
        w = Button(self._button_box,
                   text="Abbrechen",
                   width=10,
                   command=self.cancel)
        w.pack(side=LEFT, padx=5, pady=5)

    def _yes_no_buttons(self):
        self._yes_no_button_box = Frame(self)

        self._yes_button = Button(self._yes_no_button_box,
                                  text="Ja",
                                  width=10,
                                  command=self._satisfied,
                                  default=ACTIVE)
        self._yes_button.pack(side=LEFT, padx=5, pady=5)
        self._no_button = Button(self._yes_no_button_box,
                                 text="Nein",
                                 width=10,
                                 command=self._not_satisfied)
        self._no_button.pack(side=LEFT, padx=5, pady=5)

    def init_calc_offset(self):
        pass

    def _satisfied(self):
        DbAccess.update_hive_calibration(self._calibration)
        self._close_enabled = True
        self.cancel()

    def _not_satisfied(self):
        self._start_button.config(command=self._calc_offset)
        self._calibration = HiveCalibration()
        self._yes_no_button_box.pack_forget()
        self._temp_display.pack_forget()
        self._weight_display.pack_forget()
        self._prepare_tara()
        self._button_box.pack()
        self.update_idletasks()

    def buttonbox(self):
        self._standard_buttons()
        self._yes_no_buttons()
        '''add standard button box.

        override if you do not want the standard buttons
        '''
        '''
        w = Button(box, text="OK", width=10, command=self.ok, default=ACTIVE)
        w.pack(side=LEFT, padx=5, pady=5)
        w = Button(box, text="Cancel", width=10, command=self.cancel)
        w.pack(side=LEFT, padx=5, pady=5)

        self.bind("<Return>", self.ok)
        self.bind("<Escape>", self.cancel)
        '''

    def _progress(self, i, maximum=15):
        self._bar['value'] = int(210 / (maximum - i))
        self.update_idletasks()

    def _calc_reference_unit(self, event=None):
        expected_weight_string = self._expected_weight_field.get()
        print('calc-reference-unit.expected_weight_string: ',
              expected_weight_string)
        expected = int(expected_weight_string)
        print('calc-reference-unit.expected: ', expected)
        self._calibration.entity_id = self._hive.get_id()
        self._humidity = None
        self._bar['value'] = 0
        self._bar.pack()
        self.update_idletasks()
        try:
            self._close_enabled = False
            self._button_box.pack_forget()
            self._close_enabled = False
            self._bar.pack()
            self.update_idletasks()

            pins = self._hive.get_weight().get_bcm().split(",")
            data_pin = pins[0]
            clk_pin = pins[1]

            print('data_pin ' + data_pin)
            print('clk_pin ' + clk_pin)

            hx = HX711(int(data_pin), int(clk_pin), gain=128)
            hx.set_reading_format("LSB", "MSB")
            print('_offset:', self._calibration.offset)
            hx.set_offset(self._calibration.offset)
            self._calibration.value_per_gram = hx.calc_reference_unit(
                lambda i: self._progress(i, 10), expected)
            print('reference_unit -> ', self._calibration.value_per_gram)
            self._calc_temp()
            clean()
            self._start_button.config(command=self._check_weight)
            self._header.config(
                text='Drücken Sie Start um das Gewicht\nzu überprüfen.')
            self._button_box.pack()
            self._bar.pack_forget()
            self._expected_weight_box.pack_forget()
            self._weight_display.pack()
            self._temp_display.pack()
            self.update_idletasks()
            self._close_enabled = True
        except Exception as e:
            print('Error ', e)
            clean()
            self._calibration.offset = None
            self._close_enabled = True

    def _calc_temp(self):
        temp_sensor = self._hive.get_temperature_outside()

        if temp_sensor.get_bcm() == '' or temp_sensor.get_product() == '':
            return

        if temp_sensor.get_product() == 'DHT22':
            self._humidity, self._calibration.temp = dht.read_retry(
                dht.DHT22, int(temp_sensor.get_bcm()))
            print('Temp={0:0.1f}*C  Humidity={1:0.1f}%'.format(
                self._calibration.temp, self._humidity))
        elif temp_sensor.get_product() == 'DHT11':
            self._humidity, self._temp = dht.read_retry(
                dht.DHT11, int(temp_sensor.get_bcm()))
            print('Temp={0:0.1f}*C  Humidity={1:0.1f}%'.format(
                self._calibration.temp, self._humidity))
        else:
            print('Unsupported product ', temp_sensor.get_product())

    def _check_weight(self):
        try:
            self._close_enabled = False
            pins = self._hive.get_weight().get_bcm().split(",")
            data_pin = pins[0]
            clk_pin = pins[1]
            hx = HX711(int(data_pin), int(clk_pin), gain=128)
            hx.set_reading_format("LSB", "MSB")
            print('_reference_unit:', self._calibration.value_per_gram)
            hx.set_reference_unit(self._calibration.value_per_gram)
            hx.reset()
            print('_offset:', self._calibration.offset)
            hx.set_offset(self._calibration.offset)
            val = hx.get_weight(5)
            print('value -> ', val)
            self._header.config(text='Sind Sie mit dem Ergebnis\nzufrieden?')
            self._weight_display.config(
                text=('Gewicht: {0:0.1f}g'.format(val)))
            if self._calibration.temp is not None:
                self._temp_display.config(
                    text=('Temp: {0:0.1f}°C'.format(self._calibration.temp)))
            else:
                self._temp_display.config(text='')

            print('reference_unit -> ', self._calibration.value_per_gram)
            clean()
            self._button_box.pack_forget()
            self._yes_no_button_box.pack()
            self.update_idletasks()
            self._close_enabled = True
        except Exception as e:
            print('Error ', e)
            clean()
            self._calibration.offset = None
            self._close_enabled = True

    def _calc_offset(self, event=None):
        self._calibration.offset = None
        try:
            self._button_box.pack_forget()
            self._close_enabled = False
            self._bar.pack()
            self.update_idletasks()

            pins = self._hive.get_weight().get_bcm().split(",")
            data_pin = pins[0]
            clk_pin = pins[1]

            print('data_pin ' + data_pin)
            print('clk_pin ' + clk_pin)

            hx = HX711(int(data_pin), int(clk_pin), gain=128)
            hx.set_reading_format("LSB", "MSB")
            self._calibration.offset = hx.calc_offset(
                lambda i: self._progress(i))
            print('offset -> ', self._calibration.offset)
            clean()
            self._start_button.config(command=self._calc_reference_unit)
            self._header.config(text='Geben Sie ein Gewicht auf die Waage.')
            self._expected_weight_box.pack()
            self._button_box.pack()
            self._bar.pack_forget()

            self.update_idletasks()
        except Exception as e:
            print('Fehler', e)
            clean()
            self._close_enabled = True
            self._calibration.offset = None