示例#1
0
class test:
    btn_on = gtk.gdk.color_parse("green")
    btn_off = gtk.gdk.color_parse("grey")

    def __init__(self):
        self.wTree = glade.XML('gtktest.glade', None, None)
        dic = {'btnconnect_toggled_cb':self.btnconnect_toggled_cb}
        self.wTree.signal_autoconnect(dic)
        self.wTree.signal_connect('dlgwii_close_cb', self.main_quit) 
        self.wTree.signal_connect('btnclose_activate_cb', self.main_quit) 
    
        self.mainwindow = self.wTree.get_widget('dlgwii')
        self.connectbutton = self.wTree.get_widget('btnconnect')

        self.lblacc = self.wTree.get_widget('lblacc')
        self.lblbtn = self.wTree.get_widget('lblbtn')

        self.wiimote = WiimoteDevice()
        self.wiimote.rptmode = cwiid.RPT_BTN | cwiid.RPT_ACC
        self.wiimote.connect('mesg_btn', self.btn_cb)
        self.wiimote.connect('mesg_acc', self.acc_cb)
        self.wiimote.connect('associated', self.main_quit)

    def main_quit(self, obj):
        if self.wiimote.associated:
            self.wiimote.dissociate()
        gtk.main_quit()

    def btnconnect_toggled_cb(self, obj):
        if self.wiimote.associated:
            self.wiimote.dissociate()
        else:
            msg = "Put Wiimote in discoverable mode (press 1+2) and close me"
            dlg = gtk.MessageDialog(self.mainwindow, gtk.DIALOG_MODAL, 
                    gtk.MESSAGE_INFO, gtk.BUTTONS_NONE, msg)
            dlg.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)
            dlg.run()

            try:
                self.wiimote.associate()
            except exceptions.Exception, err:
                #FIXME: I think there must be a better way to block handler
                self.connectbutton.handler_block_by_func(self.connectbutton_toggled_cb)
                self.connectbutton.set_active(False)
                self.connectbutton.handler_unblock_by_func(self.connectbutton_toggled_cb)
                errdlg = gtk.MessageDialog(dlg, gtk.DIALOG_MODAL, 
                        gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, str(err.args))
                errdlg.run()
                errdlg.destroy()
            finally:
示例#2
0
文件: wmgui.py 项目: fontanon/wiimidi
class WmGUI:
    btn_on = gtk.gdk.color_parse('green')
    btn_off = gtk.gdk.color_parse('grey')

    def __init__(self):
        self.wTree = glade.XML('wmgui.glade', None, None)
        dic = {'connectbutton_toggled_cb':self.connectbutton_toggled_cb,
               'btncheck_toggled_cb':self.rptmode_toggled_cb,
               'accdatacheck_toggled_cb':self.rptmode_toggled_cb,
               'irdatacheck_toggled_cb':self.rptmode_toggled_cb,
               'extensiondata_toggled_cb':self.rptmode_toggled_cb,
               'rumblecheck_toggled_cb':self.rumblecheck_toggled_cb,
               'led1check_toggled_cb':self.calculate_led_cb,
               'led2check_toggled_cb':self.calculate_led_cb,
               'led3check_toggled_cb':self.calculate_led_cb,
               'led4check_toggled_cb':self.calculate_led_cb}
        self.wTree.signal_autoconnect(dic)
        self.wTree.signal_connect('wmgui_window_destroy_cb', self.main_quit) 
        self.wTree.signal_connect('quitmenuitem_activate_cb', self.main_quit) 

        self.wmguiwindow = self.wTree.get_widget('wmguiwindow')
        self.connectbutton = self.wTree.get_widget('connectbutton')

        self.btncheck = self.wTree.get_widget('btncheck')
        self.accdatacheck = self.wTree.get_widget('accdatacheck')
        self.irdatacheck = self.wTree.get_widget('irdatacheck')
        self.extensiondatacheck = self.wTree.get_widget('extensiondatacheck')
        self.rumblecheck = self.wTree.get_widget('rumblecheck')
        self.led1check = self.wTree.get_widget('led1check')
        self.led2check = self.wTree.get_widget('led2check')
        self.led3check = self.wTree.get_widget('led3check')
        self.led4check = self.wTree.get_widget('led4check')
        self.upevbox = self.wTree.get_widget('upevbox')
        self.downevbox = self.wTree.get_widget('downevbox')
        self.leftevbox = self.wTree.get_widget('leftevbox')
        self.rightevbox = self.wTree.get_widget('rightevbox')
        self.abtnevbox = self.wTree.get_widget('abtnevbox')
        self.bbtnevbox = self.wTree.get_widget('bbtnevbox')
        self.minusevbox = self.wTree.get_widget('minusevbox')
        self.homeevbox = self.wTree.get_widget('homeevbox')
        self.plusevbox = self.wTree.get_widget('plusevbox')
        self.oneevbox = self.wTree.get_widget('oneevbox')
        self.twoevbox = self.wTree.get_widget('twoevbox')
        self.progAccX = self.wTree.get_widget('progAccX')
        self.progAccY = self.wTree.get_widget('progAccY')
        self.progAccZ = self.wTree.get_widget('progAccZ')

        self.wiimote = WiimoteDevice()
        self.wiimote.rptmode = 0
        self.wiimote.connect('mesg_btn', self.btn_cb)
        self.wiimote.connect('mesg_acc', self.acc_cb)


    def main_quit(self, obj):
        if self.wiimote.associated:
            self.wiimote.dissociate()
        gtk.main_quit()

    def connectbutton_toggled_cb(self, obj):
        if self.wiimote.associated:
            self.wiimote.dissociate()
        else:
            msg = "Put Wiimote in discoverable mode (press 1+2) and close me"
            dlg = gtk.MessageDialog(self.wmguiwindow, gtk.DIALOG_MODAL, 
                    gtk.MESSAGE_INFO, gtk.BUTTONS_NONE, msg)
            dlg.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)
            dlg.run()

            try:
                self.wiimote.associate()
            except exceptions.Exception, err:
                #FIXME: I think there must be a better way to block handler
                self.connectbutton.handler_block_by_func(self.connectbutton_toggled_cb)
                self.connectbutton.set_active(False)
                self.connectbutton.handler_unblock_by_func(self.connectbutton_toggled_cb)
                errdlg = gtk.MessageDialog(self.wmguiwindow, gtk.DIALOG_MODAL, 
                        gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, str(err.args))
                errdlg.run()
                errdlg.destroy()
            finally: