コード例 #1
0
class FILESELECTOR(LabelFrame):
    '''
        Widget de clase Button que abre un filedialog y permite al usuario seleccionar un archivo.
        El nombre de archivo es utilizado como texto del botón.

                NOTA:
                    en este caso el filedilog esta configurado
                    para archivos con extención .mp3 | .wav | .wma

    '''
    def __init__(self, master, row, column, columnspan, text, command=None):
        super().__init__(master)
        self.master
        self.row = row
        self.column = column
        self.columnspan = columnspan
        self.text = text
        self.command = command
        self.currentSelection = StringVar() # la dirección del archivo de sonido(file full path)
        self.currentSelection.set(' tono/mp3')
        self.newSelectionPath = StringVar()
        self.newSelectionPath.set('')
        self.selectorTitle = StringVar()
        self.selectorTitle.set(self.text)
        self.currentSelectionName = StringVar() # el nombre del archivo de sonido sin extensión(file name)
        self.currentSelectionName.set(self.currentSelection.get())
        self.grid(row=self.row, column=self.column, columnspan=self.columnspan)
        self.config(bg=self.master['bg'], text=self.selectorTitle.get(), labelanchor='n', fg='white', padx=len(self.currentSelection.get()))
        self.btn = Button(self, textvariable=self.currentSelection, width=14, command=self.fld)
        self.btn.grid(row=0, column=0, ipadx=len(self.currentSelection.get()))
        self.btn.config(bg='red', fg='white')
        self.ledSS = ledSS.LEDSS(string=self.currentSelection.get())

    def fld(self):
        '''
            abre la ventana de dialogo para
            permitir la selección de 
            archivos en este caso de sonido mp3, wav, wma.
        '''
        ftypes = [("mp3, wav, wma files","*.mp3 *.wav *.wma"),("all files","*.*")]
        dlg = filedialog.Open(filetypes=ftypes)
        phfl = dlg.show()      
        if phfl != '':
            self.newSelectionPath.set(phfl)
            if self.command is not None:
                self.command()

    def ledScreenSimulation(self):
        '''
            usa el nombre del archivo seleccionado como
            texto para el botón y aplica una animación.
        '''
        self.currentSelection.set(self.ledSS.roll())
        self.btn.config(textvariable=self.currentSelection)
        self.btn.after(round(3000 / len(self.currentSelection.get())), self.ledScreenSimulation)
    
    def updateSelectorTitle(self):
        self.config(text=self.selectorTitle.get())

    def updateSelectorLabel(self):
        self.ledSS.update(self.currentSelection.get())

    def reset(self):
        self.selectorTitle.set('Selección')
        self.currentSelection.set(' tono/mp3')
        self.updateSelectorTitle()
        self.updateSelectorLabel()
コード例 #2
0
class uiWidgets:
    def __init__(self, master):
        self.master = master
        self.master.geometry("%dx%d-%d-%d" % (330, 302, 50, 80))
        self.master.resizable(False, False)
        self.master.title(
            '%s/%s' %
            (ec2.configFile, ec2.profileName[ec2.profileName.rfind(' ') + 1:]))
        # === 建立圖形界面裡會顯示的變數 =======
        self.startORstop = StringVar()
        self.showStatus = StringVar()
        self.makeConnection = StringVar()
        self.showFQDN = StringVar()
        self.showIP = StringVar()
        # === 建立開關機計數器變數 =======
        self.counter = 0
        # === 建立 [設定檔] === User Profile 框架 =======
        self.userprofileFrame = LabelFrame(self.master, text='設定檔')
        # === 建立 [設定檔] instance ID 標籤與文字 =======
        self.identiferLabel = Label(self.userprofileFrame,
                                    text='載入的 EC2 Inatance ID')
        self.identiferLabel.grid(row=0, column=0)
        self.identiferText = Entry(self.userprofileFrame)
        self.identiferText.grid(row=0, column=1)
        # === 建立 [設定檔] region 標籤與文字 =======
        self.regionalLabel = Label(self.userprofileFrame,
                                   text='該 EC2 Inatance 的 Region')
        self.regionalLabel.grid(row=1, column=0)
        self.regionalText = Entry(self.userprofileFrame)
        self.regionalText.grid(row=1, column=1)
        # === 定位 [設定檔] 包裝 User Profile 框架 Frame =======
        self.userprofileFrame.pack(padx=10, pady=5, ipadx=5, ipady=5)
        # === 插入 [EC2 的 instance ID 文字] 到文字框 =======
        self.identiferText.insert(0, ec2.instanceID)
        # === 插入 [EC2 的 user region 文字] 到文字框 =======
        self.regionalText.insert(0, ec2.userRegion)
        # === 建立 [開/關機] start/stop switch 按鈕 =======
        self.switchButton = Button(self.master,
                                   textvariable=self.startORstop,
                                   width=10,
                                   command=self.switchbuttonClicked)
        # === 定位 [開/關機] start/stop switch 按鈕 =======
        self.switchButton.pack(padx=10, pady=5)
        # === 建立 [目前狀態] instance state 框架 Frame =======
        self.instancestatusFrame = LabelFrame(self.master, text='目前狀態')
        # === 建立 [目前狀態] instance state 標籤與文字 =======
        self.machinestateLabel = Label(self.instancestatusFrame,
                                       text='目前的 EC2 Inatance 狀態')
        self.machinestateLabel.grid(row=0, column=0)
        self.machinestateText = Entry(
            self.instancestatusFrame,
            textvariable=self.showStatus)  # 顯示 [EC2 Instance(虛擬機器) 的 State]
        self.machinestateText.grid(row=0, column=1)
        # === 定位 [目前狀態] 包裝 instance state 框架 Frame =======
        self.instancestatusFrame.pack(padx=10, pady=5, ipadx=5, ipady=5)
        # === 建立 [細節] instance description 框架 Frame =======
        self.statisticsFrame = LabelFrame(self.master, text='細節')
        # === 建立 [細節] instance fqdn 標籤與文字 =======
        self.instanceFQDNLable = Label(self.statisticsFrame,
                                       text='目前 EC2 Inatance 的 FQDN')
        self.instanceFQDNLable.grid(row=0, column=0)
        self.instanceFQDNNameText = Entry(
            self.statisticsFrame,
            textvariable=self.showFQDN)  # 顯示 [EC2 Instance(虛擬機器) 的 FQDN]
        self.instanceFQDNNameText.grid(row=0, column=1)
        # ===  建立 [細節] instance ip addr 標籤與文字   =======
        self.instanceIPaddrLable = Label(self.statisticsFrame,
                                         text='目前 EC2 Inatance 的 IP')
        self.instanceIPaddrLable.grid(row=1, column=0)
        self.instanceIPaddrText = Entry(
            self.statisticsFrame,
            textvariable=self.showIP)  # 顯示 [EC2 Instance(虛擬機器) 的 IP]
        self.instanceIPaddrText.grid(row=1, column=1)
        # === 定位 [細節] 包裝 instance description 框架 Frame =======
        self.statisticsFrame.pack(padx=10, pady=5, ipadx=5, ipady=5)
        # === 建立 [連線伺服器] make connection 按鈕 =======
        self.connectButton = Button(self.master,
                                    textvariable=self.makeConnection,
                                    width=10,
                                    command=self.connectbuttonClicked)
        # === 定位 [連線伺服器] make connection 按鈕 =======
        self.connectButton.pack(padx=10, pady=5)
        # === 更新所有顯示變數  =======
        self.variablesRefreshing()

    # === 更新變數 ===
    def variablesRefreshing(self):
        ec2.getStastictics()
        if ec2.status in ['running', 'stopped']:
            if ec2.status == 'running':
                self.startORstop.set('關機 [Stop]')
                self.makeConnection.set('連線伺服器')
            elif ec2.status == 'stopped':
                self.startORstop.set('開機 [Start]')
                self.makeConnection.set(' - 尚未開機  - ')
        else:
            self.makeConnection.set(' - - - - - ')
        self.showStatus.set(ec2.status)  # EC2 Instance(虛擬機器) 狀態
        self.showFQDN.set(ec2.fqdn)  # EC2 Instance(虛擬機器) 的公開 FQDN 位址
        self.showIP.set(ec2.ip)  # EC2 Instance(虛擬機器) 的公開 IP 位址

    def executeTerminal(self):
        os.system(self.cmd2exec)

    # === 連線按鈕 ===
    def connectbuttonClicked(self):
        if ec2.status == 'running':
            if ec2.accountPwd.lower().endswith('.pem'):
                self.cmd2exec = 'ssh -o "ServerAliveInterval 40" -o StrictHostKeyChecking=no -i "%s" ubuntu@%s' % (
                    ec2.accountPwd, ec2.fqdn)
            else:
                self.cmd2exec = 'cmdkey /generic:%ec2IP% /user:Administrator /pass:"******" && mstsc /admin /v:%ec2IP%'
            try:
                with open(os.path.expanduser(r'~/.aws/executedCmd.%s.txt' %
                                             ec2.configFile),
                          'w',
                          encoding='utf-8-sig') as f:
                    f.write(self.cmd2exec)  # 將命令列寫入檔案, ** 注意 rdp 包含密碼的明碼
            except Exception:
                logging.warning('執行下列命令寫入桌面檔案錯誤: %s' % self.cmd2exec)
            os.environ['ec2IP'] = ec2.ip
            cmd = threading.Thread(target=self.executeTerminal)
            cmd.start()
            logging.debug('外部命令視窗啟動是否啟動? %s' % cmd.is_alive())

    # === 開關機按鈕 ===
    def switchbuttonClicked(self):
        if ec2.status in ['running', 'stopped']:
            if ec2.status == 'running':  # 如果伺服器EC2 Instance 為啟動中
                ec2.setStopped()  #  ->則關機
            elif ec2.status == 'stopped':
                ec2.setRunning()  # ->否則開機
        self.countingBtn()

    # === 按下開關機按鈕後計數 ===
    def countingBtn(self):
        self.counter += 1  # 增加計數
        self.startORstop.set('- - %s - -' % str(self.counter))  # 顯示計數內容
        self.variablesRefreshing()  # 更新畫面上的變數
        if ec2.status not in ['running', 'stopped']:  # 如果狀態已為開或關機表示作業完成
            self.btnSwitchId = self.switchButton.after(
                2000, self.switchbuttonClicked)  # 否則排定下個2秒(=2000ms)就再更新畫面一次
        else:
            self.counter = 0
            self.switchButton.after_cancel(self.btnSwitchId)  # 所以取消每2秒更新一次的動作
コード例 #3
0
ファイル: window.py プロジェクト: Tbeck-91/soulstruct
 def mimic_click(button: tk.Button):
     button["relief"] = SUNKEN
     button.update_idletasks()
     button.after(100, lambda: button.config(relief=RAISED))
コード例 #4
0
class Emulatore(object):

    """
    Interfaccia grafica per l'emulatore del pdp8
    """

    def __init__(self, master, codice, calcolatore, emulatore):
        """
        Inizializza i frame per l'interfaccia dell'emulatore
        """
        self.CD = calcolatore
        self.codice = codice
        self.delay = 100
        self.master = Frame(master)
        self.root = emulatore

        # Memoria Ram
        self.ram = LabelFrame(
            self.master,
            text="Memoria RAM",
            relief=RIDGE,
            borderwidth=5,
            labelanchor="n",
            pady=5,
        )
        self.ram.rowconfigure(0, weight=1)
        self.ram.columnconfigure(0, weight=1)
        self.ram.grid(row=0, column=0, rowspan=3, columnspan=5, sticky=W + E + N + S)

        # Controlli
        self.controlli = Frame(self.master, padx=10, pady=10)
        self.controlli.grid(row=0, column=5, rowspan=1)

        # Status CD
        self.registri = LabelFrame(
            self.master,
            text="REGISTRI",
            relief=RIDGE,
            borderwidth=5,
            labelanchor="n",
            padx=25,
            pady=10,
        )
        self.registri.grid(row=0, column=6, rowspan=1, sticky=W + E + N + S)
        self.unita = LabelFrame(
            self.master,
            text="UC",
            relief=RIDGE,
            borderwidth=5,
            labelanchor="n",
            padx=10,
            pady=10,
        )
        self.unita.grid(row=2, column=6, rowspan=1, sticky=N)

        # Var
        self.variabili = Frame(self.master)
        self.variabili.grid(row=2, column=5)
        self.nstep = LabelFrame(
            self.variabili,
            text="Num. Step",
            relief=RIDGE,
            borderwidth=5,
            labelanchor="n",
        )
        self.nstep.grid(row=0, column=5, sticky=W + E)
        self.delays = LabelFrame(
            self.variabili, text="Delay", relief=RIDGE, borderwidth=5, labelanchor="n"
        )
        self.delays.grid(row=1, column=5, sticky=W + E)
        self.tempo = LabelFrame(
            self.variabili, text="Tempo", relief=RIDGE, borderwidth=5, labelanchor="n"
        )
        self.tempo.grid(row=1, column=6, sticky=W + E)

        # Unita' di controllo
        self.unitas = LabelFrame(self.unita, text="S", labelanchor="s", padx=10)
        self.unitas.grid(row=0, column=0, sticky=N)
        self.unitaf = LabelFrame(self.unita, text="F", labelanchor="s", padx=10)
        self.unitaf.grid(row=0, column=1, sticky=N)
        self.unitar = LabelFrame(self.unita, text="R", labelanchor="s", padx=10)
        self.unitar.grid(row=0, column=2, sticky=N)
        self.unitaint = LabelFrame(self.unita, text="Int.", labelanchor="s", padx=10)
        self.unitaint.grid(row=0, column=3, sticky=N)

        # Registri
        self.programc = LabelFrame(
            self.registri, text="PC", relief=FLAT, labelanchor="e", padx=5
        )
        self.programc.grid(row=0, column=0, sticky=W + E)
        self.mar = LabelFrame(
            self.registri, text="MAR", relief=FLAT, labelanchor="e", padx=5
        )
        self.mar.grid(row=1, column=0, sticky=W + E)
        self.mbr = LabelFrame(
            self.registri, text="MBR", relief=FLAT, labelanchor="e", padx=5
        )
        self.mbr.grid(row=2, column=0, sticky=W + E)
        self.lopr = LabelFrame(
            self.registri, text="OPR", relief=FLAT, labelanchor="e", padx=5
        )
        self.lopr.grid(row=3, column=0, sticky=W + E)
        self.vari = LabelFrame(
            self.registri, text="I", relief=FLAT, labelanchor="e", padx=5
        )
        self.vari.grid(row=4, column=0, sticky=W + E)
        self.vare = LabelFrame(
            self.registri, text="E", relief=FLAT, labelanchor="e", padx=5
        )
        self.vare.grid(row=5, column=0, sticky=W + E)
        self.lac = LabelFrame(
            self.registri, text="AC", relief=FLAT, labelanchor="e", padx=5
        )
        self.lac.grid(row=6, column=0, sticky=W + E)
        self.lacint = LabelFrame(
            self.registri, text="INT AC", relief=FLAT, labelanchor="e", padx=5
        )
        self.lacint.grid(row=7, column=0, sticky=W + E)
        self.lachex = LabelFrame(
            self.registri, text="HEX AC", relief=FLAT, labelanchor="e", padx=5
        )
        self.lachex.grid(row=8, column=0, sticky=W + E)

        # Microistruzioni
        self.micro = LabelFrame(
            self.master,
            text="Microistruzioni eseguite",
            relief=RIDGE,
            borderwidth=5,
            labelanchor="n",
            pady=5,
        )
        self.micro.rowconfigure(0, weight=1)
        self.micro.columnconfigure(0, weight=1)
        self.micro.grid(row=3, column=4, rowspan=5, columnspan=5, sticky=W + E + N + S)

        # Inout
        self.inout = LabelFrame(
            self.master,
            text="Input & Output",
            relief=RIDGE,
            borderwidth=5,
            labelanchor="n",
            pady=5,
        )
        self.inout.rowconfigure(0, weight=1)
        self.inout.columnconfigure(0, weight=1)
        self.inout.grid(row=3, column=0, columnspan=4, sticky=W + E + N + S)

        self.create_widgets()

    def create_widgets(self):
        """
        Crea il layout del programma, finestra dell'emulatore
        """
        # Memoria RAM
        self.Visualizza = Text(self.ram, width=80)
        self.Visualizzascrollbar = Scrollbar(self.ram)
        self.Visualizzascrollbar.config(command=self.Visualizza.yview)
        self.Visualizza.config(yscrollcommand=self.Visualizzascrollbar.set)
        self.Visualizzascrollbar.grid(row=0, column=1, sticky=N + S)
        self.Visualizza.grid(row=0, column=0, sticky=W)

        # INOUT
        self.Visualizzainout = Text(
            self.inout, width=62, height=7, fg="green", bg="black"
        )
        self.Visualizzascrollbar_inout = Scrollbar(self.inout)
        self.Visualizzascrollbar_inout.config(command=self.Visualizzainout.yview)
        self.Visualizzainout.config(yscrollcommand=self.Visualizzascrollbar_inout.set)
        self.Visualizzascrollbar_inout.grid(row=0, column=1, sticky=N + S)
        self.Visualizzainout.grid(row=0, column=0, sticky=W)

        # Mircroistruzioni
        self.Visualizzamicro = Text(self.micro, width=55, height=7)
        self.Visualizzascrollbar_m = Scrollbar(self.micro)
        self.Visualizzascrollbar_m.config(command=self.Visualizzamicro.yview)
        self.Visualizzamicro.config(yscrollcommand=self.Visualizzascrollbar_m.set)
        self.Visualizzascrollbar_m.grid(row=0, column=1, sticky=N + S)
        self.Visualizzamicro.grid(row=0, column=0, sticky=W)

        # Pulsanti
        self.butload = Button(
            self.controlli,
            text="LOAD",
            anchor=CENTER,
            width=15,
            command=self.loading,
            bg="SkyBlue",
        )
        self.butload.grid(row=0, column=0)
        self.butstep = Button(
            self.controlli,
            text="Step",
            anchor=CENTER,
            width=15,
            command=self.step,
            bg="linen",
        )
        self.butstep.grid(row=1, column=0)
        self.butminstep = Button(
            self.controlli,
            text="miniStep",
            anchor=CENTER,
            width=15,
            command=self.mini_step,
            bg="linen",
        )
        self.butminstep.grid(row=2, column=0)
        self.butstep = Button(
            self.controlli,
            text="microStep",
            anchor=CENTER,
            width=15,
            command=self.micro_step,
            bg="linen",
        )
        self.butstep.grid(row=3, column=0)
        self.butsetstep = Button(
            self.controlli,
            text="Set n Step",
            anchor=CENTER,
            width=15,
            command=self.setnstep,
            bg="linen",
        )
        self.butsetstep.grid(row=4, column=0)
        self.butsetdelay = Button(
            self.controlli,
            text="Set Delay",
            anchor=CENTER,
            width=15,
            command=self.setdelay,
            bg="linen",
        )
        self.butsetdelay.grid(row=5, column=0)
        self.butstart = Button(
            self.controlli,
            text="START",
            anchor=CENTER,
            width=15,
            command=self.start,
            bg="DarkOliveGreen3",
        )
        self.butstart.grid(row=6, column=0)
        self.butreset = Button(
            self.controlli,
            text="RESET",
            anchor=CENTER,
            width=15,
            command=self.resetCD,
            bg="Orange3",
        )
        self.butreset.grid(row=7, column=0)
        self.butstop = Button(
            self.controlli,
            text="STOP",
            anchor=CENTER,
            width=15,
            command=self.stop,
            bg="IndianRed",
        )
        self.butstop.grid(row=8, column=0)
        self.butbreak = Button(
            self.controlli,
            text="BREAK",
            anchor=CENTER,
            width=15,
            command=self.breakpoint,
            bg="Magenta2",
        )
        self.butbreak.grid(row=9, column=0)
        self.butcontinue = Button(
            self.controlli,
            text="CONTINUA",
            anchor=CENTER,
            width=15,
            command=self.continua,
            bg="Magenta2",
        )
        self.butcontinue.grid(row=10, column=0)
        self.butesegui = Button(
            self.controlli,
            text="ESEGUI",
            anchor=CENTER,
            width=15,
            command=self.esegui,
            bg="Yellow",
        )
        self.butesegui.grid(row=11, column=0)

        # Labels
        self.labelprogramc = Label(
            self.programc, text="00000000000", relief=SUNKEN, bg="red"
        )
        self.labelprogramc.grid()
        self.labelmar = Label(self.mar, text="00000000000", relief=SUNKEN, bg="yellow")
        self.labelmar.grid()
        self.labelmbr = Label(self.mbr, text="000000000000000", relief=SUNKEN)
        self.labelmbr.grid()
        self.labelvari = Label(self.vari, text="0", relief=SUNKEN)
        self.labelvari.grid()
        self.labelopr = Label(self.lopr, text="000", relief=SUNKEN)
        self.labelopr.grid()
        self.labelucs = Label(self.unitas, text="0")
        self.labelucs.grid()
        self.labelucf = Label(self.unitaf, text="0")
        self.labelucf.grid()
        self.labelucr = Label(self.unitar, text="0")
        self.labelucr.grid()
        self.labelucint = Label(self.unitaint, text="0")
        self.labelucint.grid()
        self.labelnstep = Label(self.nstep, text="1")
        self.labelnstep.grid()
        self.labeldelay = Label(self.delays, text=str(self.delay))
        self.labeldelay.grid()
        self.labeltempo = Label(self.tempo, text=str(self.CD.tempo))
        self.labeltempo.grid()
        self.labelac = Label(self.lac, text="000000000000000", relief=SUNKEN)
        self.labelac.grid()
        self.labelacint = Label(self.lacint, text="000000000000000", relief=SUNKEN)
        self.labelacint.grid()
        self.labelachex = Label(self.lachex, text="000000000000000", relief=SUNKEN)
        self.labelachex.grid()
        self.labelvare = Label(self.vare, text="0", relief=SUNKEN)
        self.labelvare.grid()

    def continua(self):
        """
        Continua l'esecuzione dopo un break
        """
        self.CD.S = True
        self.esegui()

    def micro_step(self):
        """
        Esegue il metodo step del calcolatore didattico ed aggiorna
        """
        if self.CD.S:
            self.CD.step(self.root, self.codice)
            if self.CD.tempo == 0 and not self.CD.F and not self.CD.R:
                self.CD.previstr = self.CD.nextistr
            self.aggiornaall()

    def step(self):
        """
        Esegue il metodo step del calcolatore didattico ed aggiorna
        """
        var = True
        if self.CD.S and self.CD.nstep > 0:
            while var and self.CD.S:
                self.CD.step(self.root, self.codice)
                if not self.CD.F and not self.CD.R and self.CD.tempo == 0:
                    self.CD.nstep -= 1
                    self.aggiornaall()
                    self.CD.previstr = self.CD.nextistr
                    var = False
            if self.CD.nstep > 0:
                self.butstep.after(self.delay, self.step)
            else:
                self.CD.setnstep(1)
        else:
            self.CD.setnstep(1)
            self.aggiornaall()

    def esegui(self):
        """
        Esegue il programma fino all'arresto della macchina tramite
        l'istruzione HLT
        """
        while self.CD.S:
            self.CD.step(self.root, self.codice)
            if not self.CD.F and not self.CD.R and self.CD.tempo == 0:
                self.aggiornaall()
                self.CD.previstr = self.CD.nextistr
                break
        if self.CD.S:
            self.butesegui.after(self.delay, self.esegui)
        else:
            self.CD.setnstep(1)
            self.aggiornaall()

    def mini_step(self):
        """
        Esegue un singolo ciclo della macchina
        """
        if self.CD.S:
            for x in range(0, 4):
                self.CD.step(self.root, self.codice)
                self.CD.nstep = 1
                self.aggiornaall()
            if self.CD.F is False and self.CD.R is False:
                self.CD.previstr = self.CD.nextistr

    def cerca_istr_prev(self):
        """
        Evidenzia di VERDE l'ultima istruzione eseguita
        """
        if self.CD.PC == "000000000000":
            return
        try:
            if self.CD.previstr == "" and int(self.CD.PC, 2) == self.CD.START:
                return
            else:
                pospc = str(3.0 + self.CD.previstr)
                self.Visualizza.tag_add(
                    "PISTR", str(pospc[:-1] + "16"), str(pospc[:-1] + "end")
                )
                self.Visualizza.tag_config("PISTR", background="green")
                self.Visualizza.see(pospc)
        except TypeError:
            pass  # Errore che si ottiene durante il reset del CD

    # NOTA : METODO NON NECESSARIO NEL PROGRAMMA FINALE
    # def cerca_istr_corr(self):
    #    """
    #    Evidenzia di verde l'istruzione che si dovrà eseguire
    #    """
    #    if self.CD.PC == '000000000000':
    #        return
    #    try:
    #        if int(self.CD.PC,2) == self.CD.START:
    # Inizio esecuzione del programma
    # Il PC e l'istruzione da eseguire sono allo stesso 'livello'
    #            pos = str(3.0)
    #            self.Visualizza.tag_add("ISTR", str(pos[0]+'.16'), str(pos[:-1]+'end'))
    #            self.Visualizza.tag_config("ISTR", background = "green")
    #        else:
    #            pospc = str(3.0 + self.CD.nextistr)
    #            self.Visualizza.tag_add("ISTR", str(pospc[:-1]+'16'),  str(pospc[:-1]+'end'))
    #            self.Visualizza.tag_config("ISTR", background = "green")
    #            self.Visualizza.see(pospc)
    #    except TypeError:
    # pass ## Errore che si ottiene durante il reset del CD

    def cerca_MAR(self):
        """
        Evidenzia di giallo l'indirizzo puntato dal MAR
        """
        try:
            pos = 3.0
            stringa = self.Visualizza.get(str(pos), "end")
            while (
                stringa[:12] != self.CD.MAR
                and int(pos) < len(self.CD.RAM) + 3
                and len(self.CD.RAM) > 0
            ):
                pos += 1
                stringa = self.Visualizza.get(str(pos), "end")
            if int(pos) >= len(self.CD.RAM) + 3:
                return
            self.Visualizza.tag_add("MAR", pos, str(float(pos) + 0.12))
            self.Visualizza.tag_config("MAR", background="yellow")
        except TypeError:
            pass  # Errore che si ottiene durante il reset del CD

    def cerca_PC(self):
        """
        Evidenzia di rosso l'indirizzo puntato da PC
        """
        try:
            pos = 3.0
            stringa = self.Visualizza.get(str(pos), "end")
            while (
                stringa[:12] != self.CD.PC
                and int(pos) < len(self.CD.RAM) + 3
                and len(self.CD.RAM) > 0
            ):
                pos += 1
                stringa = self.Visualizza.get(str(pos), "end")
            if int(pos) >= len(self.CD.RAM) + 3:
                return
            self.Visualizza.tag_add("PC", pos, str(float(pos) + 0.12))
            self.Visualizza.tag_config("PC", background="red")
        except TypeError:
            pass  # Errore che si ottiene durante il reset del CD

    def aggiornaout(self):
        """
        Aggiorna micro e input/output
        """
        self.aggiornamicro()
        self.aggiornainout()

    def aggiornamicro(self):
        """
        Aggiorna le microistruzioni eseguite
        """
        self.Visualizzamicro.delete(1.0, END)
        stringa = self.CD.microistruzioni
        self.Visualizzamicro.insert(INSERT, stringa)
        self.Visualizzamicro.see(END)

    def aggiornainout(self):
        """
        Aggiorna gli input ed output di sistema
        """
        self.Visualizzainout.delete(1.0, END)
        stringa = self.CD.inout
        self.Visualizzainout.insert(INSERT, stringa)
        self.Visualizzainout.see(END)

    def aggiornaram(self):
        """
        Aggiorna lo stato della RAM
        """
        self.Visualizza.delete(1.0, END)
        stringa = self.CD.statusRAM()
        self.Visualizza.insert(INSERT, stringa)
        self.cerca_MAR()
        self.cerca_PC()
        self.cerca_istr_prev()
        # self.cerca_istr_corr() #Non più necessaria nella versione finale

    def aggiornareg(self):
        """
        Aggiorna lo stato dei Registri
        """
        self.labelprogramc.config(text=self.CD.PC)
        self.labelmar.config(text=self.CD.MAR)
        self.labelmbr.config(text=self.CD.MBR)
        self.labelac.config(text=self.CD.AC)
        self.labelacint.config(text=str(self.CD.range(int(self.CD.AC, 2))))
        self.labelachex.config(text=str((hex(int(self.CD.AC, 2))[2:].upper())).zfill(4))
        self.labelvare.config(text=self.CD.E)
        self.labelvari.config(text=self.CD.I)
        self.labelopr.config(text=self.CD.OPR)

    def aggiornauc(self):
        """
        Aggiorna lo stato dell'unita' di controllo
        """
        if self.CD.S and not self.CD.breaks:
            self.labelucs.config(text=self.CD.S, bg="green")
            self.unitas.config(bg="green")
        elif not self.CD.S and self.CD.breaks:
            self.labelucs.config(text=self.CD.S, bg="Magenta2")
            self.unitas.config(bg="Magenta2")
        else:
            self.labelucs.config(text=self.CD.S, bg="red")
            self.unitas.config(bg="red")
        self.labelucf.config(text=self.CD.F)
        self.labelucr.config(text=self.CD.R)
        self.labelucint.config(text=self.CD.Interrupt)
        self.labeltempo.config(text=self.CD.tempo)

    def aggiornaall(self):
        """
        Aggiorna tutto
        """
        self.aggiornaram()
        self.aggiornareg()
        self.aggiornauc()
        self.aggiornamicro()
        self.aggiornaout()
        self.labelnstep.config(text=self.CD.nstep)

    def loading(self):
        """
        Carica il contenuto del codice assembly decodificandolo in binario
        nella RAM
        """
        contenuto = self.codice.Inserisci.get(1.0, END)
        if len(contenuto) > 1:
            self.resetCD()
            if self.CD.carica(contenuto, self) is not None:
                self.CD.S = 0
                self.aggiornaall()

    def resetCD(self):
        """
        Resetta il calcolatore didattico
        """
        self.CD = pdp8()
        self.aggiornaall()

    def start(self):
        """
        Mette la variabile Start (S) ad 1, cioe' True
        """
        self.CD.S = True
        if self.CD.breaks == True:
            self.CD.breaks = False
        self.aggiornauc()

    def stop(self):
        """
        Mette la variabile Start (S) ad 0, cioe' False
        """
        self.CD.S = False
        self.aggiornauc()

    def setnstep(self):
        """
        Setta, in base al valore passato, il numero di cicli da eseguire
        """
        temp = askinteger(
            "Num Step",
            "Numero di step da eseguire",
            initialvalue=1,
            minvalue=1,
            parent=self.root,
        )
        if temp is None:
            self.CD.setnstep(1)
        else:
            self.CD.setnstep(temp)
            self.labelnstep.config(text=self.CD.nstep)

    def setdelay(self):
        """
        Setta, in base al valore passato, il ritardo di esecuzione.
        Il valore è espresso in millisecondi, di default = 1000
        """
        temp = askinteger(
            "Set Delay",
            "Ritardo in millisecondi",
            initialvalue=100,
            minvalue=1,
            parent=self.root,
        )
        if temp is not None:
            self.delay = temp
            self.labeldelay.config(text=self.delay)

    def breakpoint(self):
        """
        Setta o elimina i breakpoint dal programma caricato in memoria
        """
        temp = askstring("Cella di memoria", "Indirizzo esadecimale", parent=self.root)
        if temp is not None:
            temp = self.CD.binario(int(temp, 16)).zfill(12)
            self.CD.breakpoint(temp)
            self.aggiornaram()

    def exit(self):
        """
        Esce dal programma
        """
        if askquestion("Exit", "Sicuro di voler uscire?", parent=self.master) == YES:
            self.codice.master.quit()
            self.codice.master.destroy()
        else:
            showinfo(
                "Suggerimento",
                """Forse e' meglio fare una pausa!""",
                icon=WARNING,
                parent=self.master,
            )