mountpad.py 31.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732
# -*- coding: utf-8 -*-
import tkinter as tk
from tkinter import ttk
import tkinter.font as tkFont
import os, sys

path = os.path.join(os.path.dirname(__file__), '..')
if path not in sys.path:
    sys.path.append(path)    
# --- celme imports
modulename = 'celme'
if modulename in dir():
    del celme
if modulename not in dir():
    import celme

try:       
    from .mounttools import Mounttools
except:
    from mounttools import Mounttools
    
# #####################################################################
# #####################################################################
# #####################################################################
# Class Mountpad
# #####################################################################
# #####################################################################
# This class provides a pad
# #####################################################################

class Mountpad():
    """
    Pad to drive the mount.
    
    To access to methods of the main thread of the mount
    one can use the line under the pad console and type:
    
    ::
        
        dir(self._main)
        
    """

    # === Constant for error codes
    NO_ERROR = 0
    ERR_UNKNOWN = 1

    _side_items = ['Auto','Tube West','Tube East']
        
    def __init__(self, main, pad_type):
        self._main = main
        self.tkroot = None
        self._pad_type = pad_type
        self._command_history = []
        self._command_history.append('self._main')
        self._command_history.append('self._main.putread(0,"ALMCLR")')
        self._command_history.append('self._main.update_motion_states()')
        self._command_history.append("self._main.radec_cat2app(celme.Date('now').jd(), 90,0 ,{'EQUINOX':'J2000'})")
        self._command_history_index = len(self._command_history)
        # ---
        if self._main!=None:
            self._side_items = ['Auto',self._main.get_param("LABEL_REGULAR"),self._main.get_param("LABEL_FLIPED")]
        # ---
        pad_types = ["pad_dev1"]
        found = False
        for pad_type in pad_types :
            if self._pad_type==pad_type:
                self.pad_gui_create() # gui will block the code here
                found = True
                break
        if found==False:
            msg = "pad_type not found amongst {}".format(pad_types)
            raise Exception(msg)

    # ==========================================    
    # ==========================================    
    # === pad_dev
    # ==========================================    
    # ==========================================    

    def pad_cbk_getalarms(self):
        texte = "No alarm infos for this mode"
        if self._main!=None:
            texte = ""
            for kaxis in range(4):
                current_axis = self._main.axis[kaxis]
                if current_axis == None:
                    continue
                if current_axis.real == False:
                    continue
                err, res = self._main.putread(kaxis,"ALM")
                #print("pad_cbk_getalarms err={} res={}".format(err,str(res)))
                if err!=0 or res[0] == "":
                    texte += "Axis {} {} Pb connection (err={} res={}) ".format(kaxis,current_axis.name,err,str(res)) + "\n"
                else:
                    res = res[1]
                    texte += "Axis {} {} code = ".format(kaxis,current_axis.name) + str(res) + "\n"
                    found, dico = self._main.error_messages(res)
                    for key, val in dico.items():
                        texte += str(key) + ": " + str(val) + "\n"
                texte += "\n"
        self.pad_var_getalm1.set(texte)

    def pad_cbk_stop(self):
        if self._main!=None:
            self._main.hadec_stop()

    def pad_cbk_goto(self):
        ha =self.pad_var_ha.get()
        dec = self.pad_var_dec.get()
        side_item = self._pad_combobox_side_hadec.get()
        side_index = self._side_items.index(side_item)
        if self._main!=None:
            if side_index==0:
                theside = self._main.axis[0].PIERSIDE_AUTO
            else:
                if side_index==1:
                    theside = self._main.axis[0].PIERSIDE_POS1
                else:
                    theside = self._main.axis[0].PIERSIDE_POS2
            #print("side_index={} theside={}".format(side_index, theside))
            self._main.hadec_goto(ha, dec, side=theside, blocking=False, drift_ha=0, drift_dec=0)

    def pad_cbk_name2coord(self):
        name =self.pad_var_object_name.get()
        tools = Mounttools()
        found, ra, dec = tools.vo_simbad(name)
        if found==0:
            found, ra, dec= tools.name2coord(name)
        if found==1:
            self.pad_var_radec_ra.set(ra)
            self.pad_var_radec_dec.set(dec)

    def pad_cbk_radec_goto(self):
        ra =self.pad_var_radec_ra.get()
        dec = self.pad_var_radec_dec.get()
        side_item = self._pad_combobox_side_radec.get()
        side_index = self._side_items.index(side_item)
        if self._main!=None:
            if side_index==0:
                theside = self._main.axis[0].PIERSIDE_AUTO
            else:
                if side_index==1:
                    theside = self._main.axis[0].PIERSIDE_POS1
                else:
                    theside = self._main.axis[0].PIERSIDE_POS2
            #print("side_index={} theside={}".format(side_index, theside))
            self._main.radec_goto(ra, dec, side=theside, blocking=False, drift_ra="sideral", drift_dec=0)

    def pad_cbk_compute_coord(self):
        err = self.NO_ERROR
        try:
            if self._main!=None:
                ha, dec, side = self._main.hadec_coord()
            else:
                ha, dec, side = (0, 0, 0)
            if side==1:
                side = self._main.get_param("LABEL_REGULAR")
            elif side==-1:
                side = self._main.get_param("LABEL_FLIPED")
            else:
                side = "Unknown"
            coord = "H.A.="+str(ha)+" Dec="+str(dec)+" Side="+str(side)
            self.pad_var_coord.set(coord)
            #
            if self._main!=None:
                ra2000, dec2000, side_radec = self._main.radec_coord(EQUINOX="J2000")
            else:
                ra2000, dec2000, side_radec = (0, 0, 0)
            if side_radec==1:
                side_radec = self._main.get_param("LABEL_REGULAR")
            elif side_radec==-1:
                side_radec = self._main.get_param("LABEL_FLIPED")
            else:
                side_radec = "Unknown"
            coord = "R.A.="+str(ra2000)+" Dec="+str(dec2000)+" Side="+str(side_radec)
            self.pad_var_radec_coord.set(coord)
        except:
            print("pb coord")
            ha, dec, side = (0,0,0)
            err= self.ERR_UNKNOWN
        return err, ha, dec, side

    def pad_cbk_compute_coord_repeated(self):
        self.pad_cbk_compute_coord()
        self.tkroot.after(700,self.pad_cbk_compute_coord_repeated)

    def pad_cbk_compute_motions_repeated(self):
        if self._main!=None:
            slewing_state, tracking_state, axes_motion_states = self._main.update_motion_states()            
            for kaxis in range(2):
                current_axis = self._main.axis[kaxis]
                # ---
                if current_axis == None:
                    continue
                if current_axis.real == True:
                    simureal = "real"
                else:
                    simureal = "simulation"
                # ---
                axis_motion = axes_motion_states[kaxis]
                motion = "Unknown"
                if axis_motion==0:
                    motion = "Stoped"
                elif axis_motion==1:
                    motion = "Slewing"
                if axis_motion==2:
                    motion = "Drifting"
                if axis_motion==3:
                    motion = "Moving"
                # ---
                if kaxis==0:
                    label = "Motor R.A."
                else:
                    label = "Motor Dec"
                # ---
                texte = "{} ({}) is {}".format(label,simureal,motion)
                # ---
                if kaxis==0:
                    self.pad_var_motion_axis_base.set(texte)
                else:
                    self.pad_var_motion_axis_polar.set(texte)
        self.tkroot.after(1000,self.pad_cbk_compute_motions_repeated)

    def pad_cbk_decinc0(self, get=0):
        if self._main!=None:
            current_axis = self._main.axis[1]
            # --- Get the current value
            inc0 = current_axis._inc0
            if get==1:
                return inc0
            # --- Get the new value
            inc0 = self.pad_var_dec_inc0.get()
            # --- Set the new value
            current_axis._inc0 = inc0
            self.pad_var_dec_inc0.set(inc0)
            # --- Get current position to keep the H.A. value
            ha, dec, side = self._main.hadec_coord()
            # --- Compute the declination of the visible pole
            if self._main.site.latitude >= 0:
                dec = 90
            else:
                dec = -90
            # ---GOTO pole
            #print("inc0 ha={} dec={}".format(ha,dec))
            self._main.hadec_goto(ha, dec, side=side, blocking=False, drift_ha=0, drift_dec=0)
        
    def pad_cbk_coord_detailed(self):
        err, ha, dec, side = self.pad_cbk_compute_coord()
        if err==self.NO_ERROR:
            if self._main!=None:
                self._main.disp()
        
    def pad_cbk_move_n_event(self,event):
        if event.type==tk.EventType.ButtonPress:
            ha_move_deg_per_sec = 0
            dec_move_deg_per_sec = -self.pad_var_speed_move.get()
            if self._main!=None:
                self._main.hadec_move(ha_move_deg_per_sec, dec_move_deg_per_sec)
        if event.type==tk.EventType.ButtonRelease:
            if self._main!=None:
                self._main.hadec_move_stop()

    def pad_cbk_move_e_event(self,event):
        if event.type==tk.EventType.ButtonPress:
            ha_move_deg_per_sec = self.pad_var_speed_move.get()
            dec_move_deg_per_sec = 0
            if self._main!=None:
                self._main.hadec_move(ha_move_deg_per_sec, dec_move_deg_per_sec)
        if event.type==tk.EventType.ButtonRelease:
            if self._main!=None:
                self._main.hadec_move_stop()
            
    def pad_cbk_move_w_event(self,event):
        if event.type==tk.EventType.ButtonPress:
            ha_move_deg_per_sec = -self.pad_var_speed_move.get()
            dec_move_deg_per_sec = 0
            if self._main!=None:
                self._main.hadec_move(ha_move_deg_per_sec, dec_move_deg_per_sec)
        if event.type==tk.EventType.ButtonRelease:
            if self._main!=None:
                self._main.hadec_move_stop()
            
    def pad_cbk_move_s_event(self,event):
        if event.type==tk.EventType.ButtonPress:
            ha_move_deg_per_sec = 0
            dec_move_deg_per_sec = self.pad_var_speed_move.get()
            if self._main!=None:
                self._main.hadec_move(ha_move_deg_per_sec, dec_move_deg_per_sec)
        if event.type==tk.EventType.ButtonRelease:
            if self._main!=None:
                self._main.hadec_move_stop()

    def pad_cbk_move_w_lim(self,event):
        if event.type==tk.EventType.ButtonPress:
            incsimus = [0 for kaxis in range(2)]
            increals, incsimus = self._main.read_encs(incsimus)            
            kaxis = 1
            current_axis = self._main.axis[kaxis]
            inc0 = current_axis.inc0
            print("increals={} inc0={}".format(increals[kaxis],inc0))
            if current_axis.real==True:
                if abs(increals[kaxis] - inc0) < 2:
                    kaxis = 0
                    current_axis = self._main.axis[kaxis]
                    pc = -1*current_axis.inc_per_sky_rev *0.25
                    err, res = self._main.inc_goto(kaxis, pc, 30000)
                    pass

    def pad_cbk_move_e_lim(self,event):
        if event.type==tk.EventType.ButtonPress:
            incsimus = [0 for kaxis in range(2)]
            increals, incsimus = self._main.read_encs(incsimus)            
            kaxis = 1
            current_axis = self._main.axis[kaxis]
            inc0 = current_axis.inc0
            print("increals={} inc0={}".format(increals[kaxis],inc0))
            if current_axis.real==True:
                if abs(increals[kaxis] - inc0) < 2:
                    kaxis = 0
                    current_axis = self._main.axis[kaxis]
                    pc = current_axis.inc_per_sky_rev *0.25
                    err, res = self._main.inc_goto(kaxis, pc, 30000)
                    pass
            
    def pad_cbk_park(self):
        if self._main!=None:
            ha = self._main.park_ha
            dec = self._main.park_dec
            theside = self._main.park_side
            self._main.hadec_park(ha, dec, theside)
        else:
            ha = 90
            dec = 90
            theside = self._main.axis[0].PIERSIDE_POS1
            self._main.hadec_goto(ha, dec, side=theside, blocking=False)
    
    def pad_cbk_quit(self):
        # --- We can destroy the windows of the gui
        self.tkroot.destroy()

    def pad_cbk_snychro(self):
        if self._main!=None:
            # --- Get the side from the current position
            ha, dec, side = self._main.hadec_coord()
            theside = side
            # --- Get the ra,dec from the form
            ra =self.pad_var_radec_ra.get()
            dec = self.pad_var_radec_dec.get()
            # --- Synchronize the mount
            self._main.radec_synchronize(ra, dec, side=theside)

    def pad_cbk_console(self, event):
        command =self.pad_var_console.get()
        res = ""
        try:
            exec(f"""locals()['temp'] = {command}""")
            res = locals()['temp']
            #exec(f"""globals()['temp'] = {command}""")
            #res = globals()['temp']
            #print("res={}".format(res))
        except Exception as err:
            res = err
        #print("type(res)={}".format(type(res)))
        #print("(2) res={}".format(res))
        self.text_console.insert(tk.END,command+"\n","command")
        self.text_console.yview_moveto(1.0)
        res = "# "+str(res)+"\n"
        self.text_console.insert(tk.END,res,"result")
        self.text_console.yview_moveto(1.0)
        self._command_history.append(command)
        self._command_history_index = len(self._command_history)
        command =self.pad_var_console.set("")
        
    def pad_cbk_command_prev(self, event):
        k = self._command_history_index
        k -= 1
        if k>=0:
            self._command_history_index = k
            command = self._command_history[k]
            self.pad_var_console.set(command)
            self.entry_console.icursor(tk.END)
    
    def pad_cbk_command_next(self, event):
        n = len(self._command_history)
        k = self._command_history_index
        k += 1
        if k<n:
            self._command_history_index = k
            command = self._command_history[k]
            self.pad_var_console.set(command)
            self.entry_console.icursor(tk.END)

    def pad_cbk_compute_lst(self):
        if self._main!=None:
            angle = str(self._main.site.longitude)
        else:
            angle = str(0)
        date = celme.Date("now")
        jd = date.jd()
        dateiso = date.iso(0," ")
        longuai = celme.Angle(angle).rad()
        meca = celme.Mechanics()
        lst = meca._mc_tsl(jd,-longuai)
        ang = celme.Angle(str(lst)+"r")
        lst_hms = ang.sexagesimal("H0.0")
        self.pad_var_date.set("UTC {}".format(dateiso))
        self.pad_var_lst.set("Local Sideral Time {}".format(lst_hms))

    def pad_cbk_compute_lst_repeated(self):
        self.pad_cbk_compute_lst()
        self.tkroot.after(500,self.pad_cbk_compute_lst_repeated)
    
    def pad_gui_create(self):
        self.tkroot = tk.Tk()
        
        self.tkroot.geometry("+50+50")
        self.tkroot.title("Mount pad") 
        
        fontStyle_1 = tkFont.Font(family="Arial", size=14, weight="bold")
        fontStyle_2 = tkFont.Font(family="Arial", size=12, weight="bold")
        fontStyle_3 = tkFont.Font(family="Arial", size=10, weight="bold")
        
        notebook = ttk.Notebook(self.tkroot)
        tab1 = ttk.Frame(notebook)
        tab2 = ttk.Frame(notebook)
        tab3 = ttk.Frame(notebook)
        tab4 = ttk.Frame(notebook)

        # =====================================================
        # Onglet 1
        # =====================================================
        
        # === Frame of Date & Local Sideral Time
        self.pad_var_date = tk.StringVar()
        self.pad_var_lst = tk.StringVar()
        frame_lst = tk.Frame(tab1)
        label_date = tk.Label(frame_lst, textvariable=self.pad_var_date, font=fontStyle_2)
        label_date.pack(side = tk.TOP)
        label_lst = tk.Label(frame_lst, textvariable=self.pad_var_lst, font=fontStyle_2)
        label_lst.pack(side = tk.TOP)
        frame_lst.pack(side = tk.TOP, pady=5)

        # === Frame of RA,Dec COORD
        self.pad_var_radec_coord=tk.StringVar()
        self.pad_var_radec_coord.set("")
        frame_radec_coord = tk.Frame(tab1)
        label_radec_coord = tk.Label(frame_radec_coord, textvariable=self.pad_var_radec_coord, font=fontStyle_1)
        label_radec_coord.pack(side = tk.LEFT)
        frame_radec_coord.pack(side = tk.TOP, pady=5)

        # === Frame of name resolver
        self.pad_var_object_name = tk.StringVar()
        self.pad_var_object_name.set("vega")
        frame_name2coord = tk.Frame(tab1)
        label_name2coord_name = tk.Label(frame_name2coord, text="Object name", font=fontStyle_3)
        label_name2coord_name.pack(side = tk.LEFT)
        entry_name2coord_name = tk.Entry(frame_name2coord, textvariable=self.pad_var_object_name, font=fontStyle_3)
        entry_name2coord_name.pack(side = tk.LEFT)
        button_name2coord_resolver = tk.Button(frame_name2coord, text="Get coordinates", command=self.pad_cbk_name2coord, font=fontStyle_3)
        button_name2coord_resolver.pack(side = tk.LEFT)
        frame_name2coord.pack(side = tk.TOP, pady=5)

        # === Frame of RA,Dec GOTO
        self.pad_var_radec_ra = tk.StringVar()
        self.pad_var_radec_dec = tk.StringVar()
        self.pad_var_radec_ra.set(self.pad_var_lst.get())
        self.pad_var_radec_dec.set("0d")
        frame_radec_goto = tk.Frame(tab1)
        label_radec_ra = tk.Label(frame_radec_goto, text="RA", font=fontStyle_3)
        label_radec_ra.pack(side = tk.LEFT)
        entry_radec_ra = tk.Entry(frame_radec_goto, textvariable=self.pad_var_radec_ra, font=fontStyle_3)
        entry_radec_ra.pack(side = tk.LEFT)
        label_radec_dec = tk.Label(frame_radec_goto, text="Dec", font=fontStyle_3)
        label_radec_dec.pack(side = tk.LEFT)
        entry_radec_dec = tk.Entry(frame_radec_goto, textvariable=self.pad_var_radec_dec, font=fontStyle_3)
        entry_radec_dec.pack(side = tk.LEFT)
        label_radec_side = tk.Label(frame_radec_goto, text="Side", font=fontStyle_3)
        label_radec_side.pack(side = tk.LEFT)
        self._pad_combobox_side_radec = ttk.Combobox(frame_radec_goto,values=self._side_items)
        self._pad_combobox_side_radec.current(0)
        self._pad_combobox_side_radec.pack(side = tk.LEFT)
        button_radec_goto = tk.Button(frame_radec_goto, text="GOTO", command=self.pad_cbk_radec_goto, font=fontStyle_3)
        button_radec_goto.pack(side = tk.LEFT)
        frame_radec_goto.pack(side = tk.TOP, pady=5)

        # === Frame of RA,Dec MOVE
        self.pad_var_speed_move=tk.DoubleVar()
        self.pad_var_speed_move.set(1)
        frame_move = tk.Frame(tab1)
        # Configuration of the grid manager
        tab1.rowconfigure(0, weight=1)
        tab1.columnconfigure(0, weight=1)
        button_N = tk.Button(frame_move, text="N", height=3, width=10, font=fontStyle_1)
        button_N.grid(row=0, column=2, sticky="nsew")
        button_N.bind('<Button-1>',self.pad_cbk_move_n_event)
        button_N.bind('<ButtonRelease>',self.pad_cbk_move_n_event)
        
        button_E = tk.Button(frame_move, text="E", height=3, width=10, font=fontStyle_1)
        button_E.bind('<Button-1>',self.pad_cbk_move_e_event)
        button_E.bind('<ButtonRelease>',self.pad_cbk_move_e_event)
        button_E.grid(row=1, column=1, sticky="nsew")
        entry_speed_drift = tk.Entry(frame_move, textvariable=self.pad_var_speed_move, width=10, justify='center', font=fontStyle_1)
        entry_speed_drift.grid(row=1, column=2, sticky="nsew")
        button_W = tk.Button(frame_move, text="W", height=3, width=10, font=fontStyle_1)
        button_W.bind('<Button-1>',self.pad_cbk_move_w_event)
        button_W.bind('<ButtonRelease>',self.pad_cbk_move_w_event)
        button_W.grid(row=1, column=3, sticky="nsew")

        button_S = tk.Button(frame_move, text="S", height=3, width=10, font=fontStyle_1)
        button_S.bind('<Button-1>',self.pad_cbk_move_s_event)
        button_S.bind('<ButtonRelease>',self.pad_cbk_move_s_event)
        button_S.grid(row=2, column=2, sticky="nsew")
        frame_move.pack(side = tk.TOP, pady=5)
        
        # === Frames buttons
        frame_stop = tk.Frame(tab1)
        button_stop = tk.Button(frame_stop, text="STOP", command=self.pad_cbk_stop, font=fontStyle_3)
        button_stop.pack(side = tk.LEFT)
        frame_stop.pack(side = tk.TOP, pady=5)
            
        frame_bottom = tk.Frame(tab1)        
        button_synchro = tk.Button(frame_bottom, text="Synchro", command=self.pad_cbk_snychro, font=fontStyle_3)
        button_synchro.pack(side = tk.LEFT, padx=5, pady=5)
        button_park = tk.Button(frame_bottom, text="Park", command=self.pad_cbk_park, font=fontStyle_3)
        button_park.pack(side = tk.LEFT, padx=5, pady=5)
        button_quit = tk.Button(frame_bottom, text="Quit", command=self.pad_cbk_quit, font=fontStyle_3)
        button_quit.pack(side = tk.LEFT, padx=5, pady=5)
        frame_bottom.pack(side = tk.TOP, pady=5)

        # === Frame of info labels
        self.pad_var_motion_axis_base  = tk.StringVar()
        self.pad_var_motion_axis_base.set("R.A.")
        self.pad_var_motion_axis_polar = tk.StringVar()
        self.pad_var_motion_axis_polar.set("Dec.")
        frame_motion_axis = tk.Frame(tab1)
        label_motion_axis_base = tk.Label(frame_motion_axis, textvariable=self.pad_var_motion_axis_base, font=fontStyle_3)
        label_motion_axis_base.pack(side = tk.LEFT)
        label_motion_axis_polar = tk.Label(frame_motion_axis, textvariable=self.pad_var_motion_axis_polar, font=fontStyle_3)
        label_motion_axis_polar.pack(side = tk.RIGHT)
        frame_motion_axis.pack(side = tk.TOP, pady=5, fill=tk.X)

        # --- repeat the pad_cbk_* every x sec
        self.pad_cbk_compute_lst_repeated()
        self.pad_cbk_compute_coord_repeated()
        self.pad_cbk_compute_motions_repeated()
        
        tab1.pack()
        
        # =====================================================
        # Onglet 2
        # =====================================================

        # === Title
        frame_tab2_title = tk.Frame(tab2)
        label_tab2_title = tk.Label(frame_tab2_title, text="Calibrations", font=fontStyle_1)
        label_tab2_title.pack(side = tk.TOP)
        frame_tab2_title.pack(side = tk.TOP, pady=5)

        # === Frame of HA,Dec COORD
        self.pad_var_coord=tk.StringVar()
        frame_coord = tk.Frame(tab2)
        label_coord = tk.Label(frame_coord, textvariable=self.pad_var_coord, font=fontStyle_1)
        label_coord.pack(side = tk.LEFT)
        button_coord = tk.Button(frame_coord, text="DETAILS", command=self.pad_cbk_coord_detailed, font=fontStyle_3)
        button_coord.pack(side = tk.LEFT)
        frame_coord.pack(side = tk.TOP, pady=5)

        # === Frame of HA,Dec GOTO
        self.pad_var_ha = tk.StringVar()
        self.pad_var_ha.set("0h")
        self.pad_var_dec = tk.StringVar()
        self.pad_var_dec.set("0d")
        frame_goto = tk.Frame(tab2)
        label_ha = tk.Label(frame_goto, text="HA", font=fontStyle_3)
        label_ha.pack(side = tk.LEFT)
        entry_ha = tk.Entry(frame_goto, textvariable=self.pad_var_ha, font=fontStyle_3)
        entry_ha.pack(side = tk.LEFT)
        label_dec = tk.Label(frame_goto, text="Dec", font=fontStyle_3)
        label_dec.pack(side = tk.LEFT)
        entry_dec = tk.Entry(frame_goto, textvariable=self.pad_var_dec, font=fontStyle_3)
        entry_dec.pack(side = tk.LEFT)
        label_side = tk.Label(frame_goto, text="Side", font=fontStyle_3)
        label_side.pack(side = tk.LEFT)
        self._pad_combobox_side_hadec = ttk.Combobox(frame_goto,values=self._side_items)
        self._pad_combobox_side_hadec.current(0)
        self._pad_combobox_side_hadec.pack(side = tk.LEFT)
        button_goto = tk.Button(frame_goto, text="GOTO", command=self.pad_cbk_goto, font=fontStyle_3)
        button_goto.pack(side = tk.LEFT)
        frame_goto.pack(side = tk.TOP, pady=5)
        
        # === Frame of HA,Dec MOVE
        self.pad_var_speed_move_hadec=tk.DoubleVar()
        self.pad_var_speed_move_hadec.set(1)
        frame_move_hadec = tk.Frame(tab2)
        # Configuration of the grid manager
        tab2.rowconfigure(0, weight=1)
        tab2.columnconfigure(0, weight=1)
        button_N_hadec = tk.Button(frame_move_hadec, text="N", height=3, width=10, font=fontStyle_1)
        button_N_hadec.grid(row=0, column=2, sticky="nsew")
        button_N_hadec.bind('<Button-1>',self.pad_cbk_move_n_event)
        button_N_hadec.bind('<ButtonRelease>',self.pad_cbk_move_n_event)
        
        button_limE_hadec = tk.Button(frame_move_hadec, text="Lim E", height=3, width=5, font=fontStyle_1)
        button_limE_hadec.bind('<Button-1>',self.pad_cbk_move_e_lim)
        button_limE_hadec.grid(row=1, column=0, sticky="nsew")
        button_E_hadec = tk.Button(frame_move_hadec, text="E", height=3, width=10, font=fontStyle_1)
        button_E_hadec.bind('<Button-1>',self.pad_cbk_move_e_event)
        button_E_hadec.bind('<ButtonRelease>',self.pad_cbk_move_e_event)
        button_E_hadec.grid(row=1, column=1, sticky="nsew")
        entry_speed_drift_hadec = tk.Entry(frame_move_hadec, textvariable=self.pad_var_speed_move, width=10, justify='center', font=fontStyle_1)
        entry_speed_drift_hadec.grid(row=1, column=2, sticky="nsew")
        button_W_hadec = tk.Button(frame_move_hadec, text="W", height=3, width=10, font=fontStyle_1)
        button_W_hadec.bind('<Button-1>',self.pad_cbk_move_w_event)
        button_W_hadec.bind('<ButtonRelease>',self.pad_cbk_move_w_event)
        button_W_hadec.grid(row=1, column=3, sticky="nsew")
        button_limW_hadec = tk.Button(frame_move_hadec, text="Lim W", height=3, width=5, font=fontStyle_1)
        button_limW_hadec.bind('<Button-1>',self.pad_cbk_move_w_lim)
        button_limW_hadec.grid(row=1, column=4, sticky="nsew")

        button_S_hadec = tk.Button(frame_move_hadec, text="S", height=3, width=10, font=fontStyle_1)
        button_S_hadec.bind('<Button-1>',self.pad_cbk_move_s_event)
        button_S_hadec.bind('<ButtonRelease>',self.pad_cbk_move_s_event)
        button_S_hadec.grid(row=2, column=2, sticky="nsew")
        frame_move_hadec.pack(side = tk.TOP, pady=5)

        # === Frame of inc0 of declination
        self.pad_var_dec_inc0 = tk.DoubleVar()
        inc0 = self.pad_cbk_decinc0(1)
        self.pad_var_dec_inc0.set(inc0)
        frame_decinc0 = tk.Frame(tab2)
        label_decinc0 = tk.Label(frame_decinc0, text="Declination inc0", font=fontStyle_3)
        label_decinc0.pack(side = tk.LEFT)
        entry_decinc0 = tk.Entry(frame_decinc0, textvariable=self.pad_var_dec_inc0, font=fontStyle_3)
        entry_decinc0.pack(side = tk.LEFT)
        button_decinc0 = tk.Button(frame_decinc0, text="VALID and GOTO pole", command=self.pad_cbk_decinc0, font=fontStyle_3)
        button_decinc0.pack(side = tk.LEFT)
        frame_decinc0.pack(side = tk.TOP, pady=5)

        # === Frames of console
        self.pad_var_console = tk.StringVar()
        frame_console = tk.Frame(tab2)
        self.text_console = tk.Text(frame_console, height=6, wrap="word", font=fontStyle_3)
        self.text_console.pack(side = tk.TOP, padx=5, pady=1)
        self.text_console.tag_config('command', foreground="red")
        self.text_console.tag_config('result', foreground="blue")
        self.entry_console = tk.Entry(frame_console, textvariable=self.pad_var_console, font=fontStyle_3)
        self.entry_console.pack(side = tk.TOP, padx=5, pady=1, fill="both")
        self.entry_console.bind("<Return>", self.pad_cbk_console)
        self.entry_console.bind("<Up>", self.pad_cbk_command_prev)
        self.entry_console.bind("<Down>", self.pad_cbk_command_next)
        frame_console.pack(side = tk.TOP, pady=5)
                
        
        tab2.pack()

        # =====================================================
        # Onglet 3
        # =====================================================

        # === Title
        frame_tab3_title = tk.Frame(tab3)
        label_tab3_title = tk.Label(frame_tab3_title, text="Configuration", font=fontStyle_1)
        label_tab3_title.pack(side = tk.TOP)
        frame_tab3_title.pack(side = tk.TOP, pady=5)

        # === Config
        texte = ""
        if self._main != None:
            for key,val in self._main.get_params().items():
                if key=="SITE":
                    texte += "{} = {}\n".format(key,val.gps)
                else:
                    texte += "{} = {}\n".format(key,val)
        frame_tab3_conf1 = tk.Frame(tab3)
        label_tab3_conf1 = tk.Label(frame_tab3_title, text=texte, font=fontStyle_3)
        label_tab3_conf1.pack(side = tk.TOP)
        frame_tab3_conf1.pack(side = tk.TOP, pady=5)

        tab3.pack()

        # =====================================================
        # Onglet 4
        # =====================================================

        # === Title
        frame_tab4_title = tk.Frame(tab4)
        label_tab4_title = tk.Label(frame_tab4_title, text="Alarms", font=fontStyle_1)
        label_tab4_title.pack(side = tk.TOP)
        frame_tab4_title.pack(side = tk.TOP, pady=5)

        # === Alamrs
        self.pad_var_getalm1 = tk.StringVar()
        frame_tab4_alm = tk.Frame(tab4)
        button_alm = tk.Button(frame_tab4_alm, text="Get alarms", command=self.pad_cbk_getalarms, font=fontStyle_3)
        button_alm.pack(side = tk.TOP)
        label_tab4_alm1 = tk.Label(frame_tab4_alm, textvariable=self.pad_var_getalm1, font=fontStyle_3)
        label_tab4_alm1.pack(side = tk.TOP)
        frame_tab4_alm.pack(side = tk.TOP, pady=10)

        tab4.pack()

        # =====================================================
        # Event loop
        # =====================================================

        notebook.add(tab1, text="Drive the mount")
        notebook.add(tab2, text="Calibrations")
        notebook.add(tab3, text="Configuration")
        notebook.add(tab4, text="Alarms")
        notebook.pack()
        
        self.tkroot.lift()
        
        self.tkroot.mainloop()

if __name__ == "__main__":

    example = 1
    print("Example       = {}".format(example))

    if example == 1:
        # --- try to catch the Ctrl+C interrupt
        try:
            # --- We launch the pad
            print("Create the pad. Tk Event loop activated.")
            pad = Mountpad(None,"pad_dev1") # replace None by the instancied object which provides coordinates, etc.
            print("Pad deleted. Tk Event loop stopped")
        except (KeyboardInterrupt, SystemExit):
            pass
        except:
            raise