Example #1
0
class TextMode(object):
    def showDialog(self,text,dialog_type,parent):
        dialog = gtk.MessageDialog(parent, gtk.DIALOG_MODAL, dialog_type, gtk.BUTTONS_OK, text)
        dialog.run()
        dialog.destroy()
    def showInfo(self,text,parent=None):
        self.showDialog(text,gtk.MESSAGE_INFO,parent)
    def showWarning(self,text,parent=None):
        self.showDialog(text,gtk.MESSAGE_WARNING,parent)
    def showError(self,text,parent=None):
        self.showDialog(text,gtk.MESSAGE_ERROR,parent)
        
    def quit(self, widget):
        self.window = None
        self.GoGo.closePort()
        del self

    def __init__(self):
        #Carrega a interface a partir do arquivo glade
        
        self.gui = gtk.glade.XML('gui/text.glade')
        self.window = self.gui.get_widget('mainWindow')  
        
        self.GoGo = GoGoComms()

        self.statusbar=self.gui.get_widget('statusbar')
        self.gui.get_widget('statusbarVersion').push(0,'Versão '+VERSION)
        self.notebookMain = self.gui.get_widget('notebookMain')    
        self.liststore=gtk.ListStore(str,str,str) # Name, Unit, #Description
        
        self.sensorsTab     = SensorsTab(self.gui, self.liststore)
        self.sensorTypes    = self.sensorsTab.sensorTypes        
        self.proceduresTab  = ProceduresTab(self.gui, self.GoGo)
        self.consoleTab     = ConsoleTab(self.gui, self.GoGo, self.statusbar, self.liststore, self.sensorTypes)
        self.uploadTab      = UploadTab(self.gui, self.GoGo, self.liststore, self.sensorTypes)     
        
        self.notebookMain.set_current_page(0)    
        self.notebookMain.set_show_tabs(True)    
        
        #Conecta Sinais aos Callbacks:        
        dic = {"gtk_main_quit" : gtk.main_quit}
        self.gui.signal_autoconnect(dic)    
        self.gui.signal_autoconnect(self)
        
        self.window.connect("destroy", self.quit)
        
        #Exibe toda interface:
        self.window.show_all() 
        
        # Tenta conectar-se à GogoBoard
        if self.GoGo.autoConnect():
            i = self.GoGo.getPort()
            if os.name == 'nt':
                self.statusbar.push(0,"Gogo connected on"+" COM "+str(i+1)+" "+"port")
            else:
                self.statusbar.push(0,"Gogo connected on"+" /dev/ttyS"+str(i)+" "+"port")
            
        else:
            print "Gogo not found"
            self.showWarning("There was a problem with the connection\nVerify that the board is properly connected with your computer")
            self.window.destroy()
            return
            
    def __init__(self):
        window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        window.set_size_request(600, 600)
        window.connect("destroy", self.close_application)
        window.set_title("PyCricketLogo")
        window.set_border_width(10)

        box1 = gtk.VBox(False, 0)
        window.add(box1)
        box1.show()

        label = gtk.Label("Codigo")    
        label.set_alignment(0, 0)
        box1.pack_start(label, False, False, 0)
        label.show()

        box2 = gtk.VBox(False, 0) 
        box2.set_border_width(10)
        box1.pack_start(box2, True, True, 0)
        box2.show()

        sw = gtk.ScrolledWindow()
        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        textview = gtk.TextView()
        textbuffer = textview.get_buffer()
        sw.add(textview)
        sw.show()
        textview.show()

        box2.pack_start(sw)
        # Load the file textview-basic.py into the text window
        #infile = open("editor.py", "r")

        #if infile:
        #    string = infile.read()
        #    infile.close()
        #    textbuffer.set_text(string)

        separator2 = gtk.HSeparator()
        box1.pack_start(separator2, False, True, 0)
        separator2.show()

        label2 = gtk.Label("Resultado")    
        label2.set_alignment(0, 0)
        box1.pack_start(label2, False, False, 0)
        label2.show()

        box3 = gtk.HBox(False, 20)
        box3.set_border_width(10)
        box1.pack_start(box3, True, True, 0)
        box3.show()

        sw2 = gtk.ScrolledWindow()
        sw2.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        textview2 = gtk.TextView()
        textbuffer2 = textview2.get_buffer()
        sw2.add(textview2)
        sw2.show()
        textview2.show()

        box3.pack_start(sw2)

        separator = gtk.HSeparator()
        box1.pack_start(separator, False, True, 0)
        separator.show()

        box2 = gtk.HBox(False, 10)
        box2.set_border_width(10)
        box1.pack_start(box2, False, True, 0)
        box2.show()

        button = gtk.Button("Compilar")
        button.connect("clicked", self.compilar, textbuffer, textbuffer2)
        box2.pack_start(button, True, True, 0)        
        button.show()
        button1 = gtk.Button("Enviar")
        button1.connect("clicked", self.enviarGogo, textbuffer, textbuffer2)
        box2.pack_start(button1, True, True, 0)        
        button1.show()
        button2 = gtk.Button("Fechar")
        button2.connect("clicked", self.close_application)
        box2.pack_start(button2, True, True, 0)
        button2.set_flags(gtk.CAN_DEFAULT)
        button2.grab_default()
        button2.show()
        
        window.show()            
    
    def toggle_editable(self, checkbutton, textview):
        textview.set_editable(checkbutton.get_active())

    def toggle_cursor_visible(self, checkbutton, textview):
        textview.set_cursor_visible(checkbutton.get_active())

    def toggle_left_margin(self, checkbutton, textview):
        if checkbutton.get_active():
            textview.set_left_margin(50)
        else:
            textview.set_left_margin(0)

    def toggle_right_margin(self, checkbutton, textview):
        if checkbutton.get_active():
            textview.set_right_margin(50)
        else:
            textview.set_right_margin(0)

    def new_wrap_mode(self, radiobutton, textview, val):
        if radiobutton.get_active():
            textview.set_wrap_mode(val)

    def new_justification(self, radiobutton, textview, val):
        if radiobutton.get_active():
            textview.set_justification(val)

    def close_application(self, widget):
        gtk.main_quit()

    def compilar(self, widget, textbuffer, textbuffer2):
        compilado = '%s ' % self.ler_token(widget, textbuffer, textbuffer2)
        if  len(compilado) <= 5 :
            global ERCP
            #print "CCCCCCCCCCCCCCCCOMPILOU COM ERRRO  ?"
            textbuffer2.set_text("ERROR->Look for a text containing one of the words: " + ERCP[0] )
            #print "????????erroCOMP"
            #print ERCP[0]           
            #print "????????ERCP"

            
        else :
            textbuffer2.set_text(compilado)

    def enviarGogo(self, widget, textbuffer, textbuffer2):
        codigo = self.ler_token(widget, textbuffer, textbuffer2)
        c = pyCricketComunic.Comunic(0)    
        result = c.enviar(codigo)
        c.fechaPorta()
        dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO,
        gtk.BUTTONS_NONE, result)
        dialog.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)
        dialog.run()
        dialog.destroy()
        
    def ler_token(self, widget, textbuffer, textbuffer2):
        global ERCP
        start = textbuffer.get_start_iter()
        end = textbuffer.get_end_iter()
        texto = pyYacc.analisarCodigo(textbuffer.get_text(start, end),ERCP)
        print "ERCP", ERCP[0]
        return texto        
        #for i in texto:
        #    armazena = armazena + str(i) + '\n'
Example #2
0
class BoardMonitor(object):
    def showDialog(self,text,dialog_type,parent):
        dialog = gtk.MessageDialog(parent, gtk.DIALOG_MODAL, dialog_type, gtk.BUTTONS_OK, text)
        dialog.run()
        dialog.destroy()
    def showInfo(self,text,parent=None):
        self.showDialog(text,gtk.MESSAGE_INFO,parent)
    def showWarning(self,text,parent=None):
        self.showDialog(text,gtk.MESSAGE_WARNING,parent)
    def showError(self,text,parent=None):
        self.showDialog(text,gtk.MESSAGE_ERROR,parent)
        
    def quit(self, widget):
        self.window = None
        self.GoGo.closePort()
        del self
        
    def __init__(self):
        #Carrega a interface a partir do arquivo glade
        
        self.gui = gtk.glade.XML('gui/monitor.glade')
        self.window = self.gui.get_widget('mainWindow')  
        
        self.GoGo = GoGoComms()

        self.statusbar=self.gui.get_widget('statusbar')
        self.gui.get_widget('statusbarVersion').push(0,'Versão '+VERSION)
        self.notebookMain = self.gui.get_widget('notebookMain')    
        self.liststore=gtk.ListStore(str,str,str) # Name, Unit, #Description
        
        self.sensorsTab     = SensorsTab(self.gui, self.statusbar, self.liststore)
        self.sensorTypes    = self.sensorsTab.sensorTypes        
        self.consoleTab     = ConsoleTab(self.gui, self.GoGo, self.statusbar, self.liststore, self.sensorTypes)
        self.uploadTab      = UploadTab(self.gui, self.GoGo, self.liststore, self.sensorTypes)     
        
        self.notebookMain.set_current_page(0)    
        self.notebookMain.set_show_tabs(True)    
        
        #Conecta Sinais aos Callbacks:        
        dic = {"gtk_main_quit" : gtk.main_quit}
        self.gui.signal_autoconnect(dic)    
        self.gui.signal_autoconnect(self)
        
        self.window.connect("destroy", self.quit)
        
        #Exibe toda interface:
        self.window.show_all() 
        
        # Tenta conectar-se à GogoBoard
        if self.GoGo.autoConnect():
            i = self.GoGo.getPort()
            if os.name == 'nt':
                self.statusbar.push(0,_("GoGo connected on:")+" COM "+str(i+1)+" "+"port")
            else:
                self.statusbar.push(0,_("GoGo connected on:")+" /dev/ttyS"+str(i)+" "+"port")
            
        else:
            print "Gogo not found"
            self.showWarning(_("There was a problem with the connection\nVerify that the board is properly connected with your computer"))
            self.window.destroy()
            return
        
### Main Window Callbacks:
    def imagemenuitemAbout_activate_cb(self,widget):    
        about = gtk.AboutDialog()        
        about.set_name(NAME)
        about.set_version(VERSION)
        #about.set_copyright(copyright)
        #about.set_comments(comments)
        #about.set_license(license)
        #about.set_wrap_license(license)
        #about.set_website(website)
        #about.set_website_label(website_label)
        about.set_authors(AUTHORS)
        #about.set_documenters(documenters)
        #about.set_artists(artists)
        #about.set_translator_credits(translator_credits)    
        #about.set_logo(gtk.gdk.pixbuf_new_from_file("gui/gogo.png"))
        about.set_logo(self.gui.get_widget('imageMonitor').get_pixbuf())
        #about.set_logo_icon_name(icon_name)
        
        about.run()
        about.destroy()
    def imagemenuitemHelp_activate_cb(self,widget):
        pass
### Board Console Callbacks:    
    def buttonBeep_clicked_cb(self, widget):
        self.consoleTab.buttonBeep_clicked_cb(widget)        
        
    def buttonLedOn_clicked_cb(self, widget):
        self.consoleTab.buttonLedOn_clicked_cb(widget)        
        
    def buttonLedOff_clicked_cb(self, widget):
        self.consoleTab.buttonLedOff_clicked_cb(widget)        
       
#    def buttonRun_clicked_cb(self, widget):
#        self.consoleTab.buttonRun_clicked_cb(widget)
        
    def checkbuttonMotor_toggled_cb(self,widget):
        self.consoleTab.checkbuttonMotor_toggled_cb(widget)        
        
    def buttonMotorControlOn_clicked_cb(self, widget):
        self.consoleTab.buttonMotorControlOn_clicked_cb(widget)        
    
    def buttonMotorControlOff_clicked_cb(self, widget):        
        self.consoleTab.buttonMotorControlOff_clicked_cb(widget)
    
    def buttonMotorControlBreak_clicked_cb(self, widget):
        self.consoleTab.buttonMotorControlBreak_clicked_cb(widget)
        
    def buttonMotorControlCoast_clicked_cb(self, widget):
        self.consoleTab.buttonMotorControlCoast_clicked_cb(widget)
    
    def buttonPowerSet_clicked_cb(self, widget):
        self.consoleTab.buttonPowerSet_clicked_cb(widget)
    
    def buttonMotorControlThisway_clicked_cb(self, widget):
        self.consoleTab.buttonMotorControlThisway_clicked_cb(widget)
        
    def buttonMotorControlThatway_clicked_cb(self, widget):
        self.consoleTab.buttonMotorControlThatway_clicked_cb(widget)
        
    def buttonMotorControlReverse_clicked_cb(self, widget):
        self.consoleTab.buttonMotorControlReverse_clicked_cb(widget)
        
    
    # def entryMinPwmDuty_changed_cb(self,widget):
        # print "entryMinPwmDuty_changed_cb"
        # #self.consoleTab.entryMaxPwmDuty_changed_cb(widget)
            
    # def entryMaxPwmDuty_changed_cb(self,widget):
        # print "entryMaxPwmDuty_changed_cb"
        # #self.consoleTab.entryMaxPwmDuty_changed_cb(widget)
    
    def entryMinPwmDuty_changed_cb(self,widget):
        self.consoleTab.entryMinPwmDuty_changed_cb(widget)
        
    def entryMaxPwmDuty_changed_cb(self,widget):
        self.consoleTab.entryMaxPwmDuty_changed_cb(widget)
        
    def buttonSetPwmDuty_clicked_cb(self,widget):
        print "buttonSetPwmDuty_clicked_cb"
        self.consoleTab.buttonSetPwmDuty_clicked_cb(widget)
    
    def buttonRefreshAll_clicked_cb(self,widget):
        self.consoleTab.buttonRefreshAll_clicked_cb(widget)
    
    def buttonSensorBurstOn_clicked_cb(self,widget):
        self.consoleTab.buttonSensorBurstOn_clicked_cb(widget)
        
    def radiobuttonBurstFast_toggled_cb(self,widget):
        self.consoleTab.radiobuttonBurstFast_toggled_cb(widget)
            
    def radiobuttonBurstSlow_toggled_cb(self,widget):
        self.consoleTab.radiobuttonBurstSlow_toggled_cb(widget)
    
    def buttonSensorBurstOff_clicked_cb(self,widget):
        self.consoleTab.buttonSensorBurstOff_clicked_cb(widget)    
    
        
### /Board Console    
    
### Upload Data Callbacks:    
    def buttonStartUpload_clicked_cb(self,widget):
        self.uploadTab.buttonStartUpload_clicked_cb(widget)
        
    def buttonSaveData_clicked_cb(self,widget):
        self.uploadTab.buttonSaveData_clicked_cb(widget)
        
    def buttonClearData_clicked_cb(self,widget):
        self.uploadTab.buttonClearData_clicked_cb(widget)
        
    def spinbuttonColumns_changed_cb(self,widget):
        self.uploadTab.spinbuttonColumns_changed_cb(widget)
        
    def colSpec_changed_cb(self,widget):
        self.uploadTab.colSpec_changed_cb(widget)
        
    def checkbuttonShowHeaders_toggled_cb(self,widget):
        self.uploadTab.checkbuttonShowHeaders_toggled_cb(widget)
        
    def checkbuttonTwoLineHeader_toggled_cb(self,widget):
        self.uploadTab.checkbuttonTwoLineHeader_toggled_cb(widget)
            
    def notebookDataView_switch_page_cb(self,widget,page,page_num):
        self.uploadTab.notebookDataView_switch_page_cb(widget,page,page_num)
        
### /Recorded Data

    
### SensorLab Callbacks:
    def sensorPoint_edited_cb(self,cell, path, new_text, column):
        self.sensorsTab.sensorPoint_edited_cb(cell, path, new_text, column)    
        
    def treeviewSensors_edited_cb(self,cell, path, new_text, column):        
        self.sensorsTab.edited_cb(cell, path, new_text, column)        
            
    def treeviewSensors_cursor_changed_cb(self,treeviewSensors):
        self.sensorsTab.treeviewSensors_cursor_changed_cb(treeviewSensors)    
    
    def buttonAddSensor_clicked_cb(self,widget):
        self.sensorsTab.buttonAddSensor_clicked_cb(widget)        
        
    def buttonRemoveSensor_clicked_cb(self,widget):
        self.sensorsTab.buttonRemoveSensor_clicked_cb(widget)
    
    def buttonImportSensors_clicked_cb(self,widget):
        self.sensorsTab.buttonImportSensors_clicked_cb(widget)
        
    def buttonExportSensors_clicked_cb(self,widget):
        self.sensorsTab.buttonExportSensors_clicked_cb(widget)
        
    def buttonExportSensorsCSV_clicked_cb(self,widget):
        self.sensorsTab.buttonExportSensorsCSV_clicked_cb(widget)
    
    def buttonInsertPoint_clicked_cb(self,widget):
        self.sensorsTab.buttonInsertPoint_clicked_cb(widget)
            
    def buttonRemovePoint_clicked_cb(self,widget):
        self.sensorsTab.buttonRemovePoint_clicked_cb(widget)