def __init__(self, parent):
     super(CommPortPage, self).__init__(parent, 'Communication Port Setting',
                                        'Set the serial port through which BitPim communicates with the phone.')
     self._ports=[{'name': 'auto', 'description': 'BitPim will try to detect the correct port automatically when accessing your phone'}]+\
                  [x for x in comscan.comscan() if x.get('available', False)]
     self._populate()
     self._set_max_size()
 def detect(self, using_port=None):
     coms=comscan.comscan()
     self.log('coms:'+str(coms))
     available_modem_coms=[x['name'] for x in coms if x['available'] \
                           and x['class']=='modem']
     if using_port is None:
         available_coms=[x['name'] for x in coms if x['available']]
     else:
         available_coms=[using_port]
         available_modem_coms=[x for x in available_coms if x in available_modem_coms]
     self.log('Available ports: '+str(available_coms))
     self.log('Available modem ports: '+str(available_modem_coms))
     self.__q_on=True
     threads=[threading.Thread(target=self.do_get_data, args=(e,)) \
              for e in available_modem_coms]
     for t in threads:
         t.start()
     for t in threads:
         t.join()
     self.__q_on=False
     while not self.__q_log.empty():
         q=self.__q_log.get_nowait()
         if isinstance(q, (list, tuple)):
             self.logdata(*q)
         else:
             self.log(q)
     pm=phones.phonemodels
     models=pm.keys()
     models.sort()
     found_port=found_model=None
     for model in models:
         self.log('Checking for model: '+model)
         module=common.importas(pm[model])
         if hasattr(module.Phone, 'detectphone'):
             likely_ports=[x['name'] for x in coms if \
                           x['available'] and \
                           comdiagnose.islikelyport(x, module)]
             self.log('Likely ports:'+str(likely_ports))
             found_port=getattr(module.Phone, 'detectphone')(coms,
                                                             likely_ports,
                                                             self.__data,
                                                             module,
                                                             self)
             self.log('Detect Phone result: '+`self.__data`)
             if found_port is not None:
                 self.log('Phone '+model+' returned port:'+`found_port`)
                 found_model=model
                 break
         found_port=self.__check_profile(module.Profile)
         if found_port is not None:
             found_model=model
             break
     if found_port is None:
         found_port, found_model=self.__check_for_other_cdma()
     if found_port is not None and found_model is not None:
         self.log('Found phone:'+found_model+' port:'+`found_port`)
         return { 'port': found_port, 'phone_name': found_model,
                  'phone_module': pm[found_model],
                  'phone_esn': self.__data[found_port]['esn'] }
Exemplo n.º 3
0
 def __init__(self, parent):
     super(CommPortPage, self).__init__(parent, 'Communication Port Setting',
                                        'Set the serial port through which BitPim communicates with the phone.')
     self._ports=[{'name': 'auto', 'description': 'BitPim will try to detect the correct port automatically when accessing your phone'}]+\
                  [x for x in comscan.comscan()+usbscan.usbscan() \
                   if x.get('available', False)]
     self._populate()
     self._set_max_size()
Exemplo n.º 4
0
def GetArduinoCOMPort():
    res=comscan.comscan()
    lst = []
    for r in res:
        rkeys=r.keys()
        
        rkeys.sort()
        if r['active']:
            if "arduino" in r['driverprovider'] or "Arduino" in r['description']:
                lst.append((r['name'], r['description']))
    return lst
def autoguessports(phonemodule):

    """Returns a list of ports (most likely first) for finding the phone on"""

    res=[]

    ports=[(islikelyportscore(port, phonemodule), port) for port in comscan.comscan()+usbscan.usbscan()+bitflingscan.flinger.scan() if port['available']]

    ports.sort()

    return [ (port['name'], port) for score,port in ports if score>=0]
Exemplo n.º 6
0
def autoguessports(phonemodule):
    """Returns a list of ports (most likely first) for finding the phone on"""
    # this function also demonsrates the use of list comprehensions :-)
    res = []
    # we only care about available ports
    ports = [(islikelyportscore(port, phonemodule), port)
             for port in comscan.comscan() + usbscan.usbscan() +
             bitflingscan.flinger.scan() if port['available']]
    # sort on score
    ports.sort()
    # return all ones with score >=0
    return [(port['name'], port) for score, port in ports if score >= 0]
Exemplo n.º 7
0
def GetArduinoCOMPort():
    res = comscan.comscan()
    lst = []
    for r in res:
        rkeys = r.keys()

        rkeys.sort()
        if r['active']:
            if "arduino" in r['driverprovider'] or "Arduino" in r[
                    'description']:
                lst.append((r['name'], r['description']))
    return lst
Exemplo n.º 8
0
def autoguessports(phonemodule):
    """Returns a list of ports (most likely first) for finding the phone on"""
    # this function also demonsrates the use of list comprehensions :-)
    res = []
    # we only care about available ports
    ports = [
        (islikelyportscore(port, phonemodule), port)
        for port in comscan.comscan() + usbscan.usbscan() + bitflingscan.flinger.scan()
        if port["available"]
    ]
    # sort on score
    ports.sort()
    # return all ones with score >=0
    return [(port["name"], port) for score, port in ports if score >= 0]
Exemplo n.º 9
0
 def exp_scan(self, context):
     if usb is None:
         return comscan.comscan()
     else:
         return usbscan.usbscan()+comscan.comscan()
Exemplo n.º 10
0
    def detect(self, using_port=None, using_model=None):
        # start the detection process
        # 1st, get the list of available ports
        coms = comscan.comscan() + usbscan.usbscan()
        self.log('coms:' + str(coms))
        available_modem_coms=[x['name'] for x in coms if x['available'] \
                              and x.get('class', None)=='modem']
        if not using_port:
            available_coms = [x['name'] for x in coms if x['available']]
        else:
            available_coms = [using_port]
            available_modem_coms = [
                x for x in available_coms if x in available_modem_coms
            ]
        # loop through each port and gather data
        self.log('Available ports: ' + str(available_coms))
        self.log('Available modem ports: ' + str(available_modem_coms))
        # only try those AT commands on modem ports
        # using threads
        self.__q_on = True
        threads=[threading.Thread(target=self.do_get_data, args=(e,)) \
                 for e in available_modem_coms]
        for t in threads:
            t.start()
        for t in threads:
            t.join()
        self.__q_on = False
        while not self.__q_log.empty():
            q = self.__q_log.get_nowait()
            if isinstance(q, (list, tuple)):
                self.logdata(*q)
            else:
                self.log(q)
        # non-thread version
##        for e in available_modem_coms:
##            self.do_get_data(e)
# go through each phone and ask it
##        pm=phones.phonemodels
        if using_model:
            models = [using_model]
        else:
            models = phones.phonemodels
        found_port = found_model = None
        for model in models:
            self.log('Checking for model: ' + model)
            module = common.importas(phones.module(model))
            # check for detectphone in module.Phone or
            # phone_model and phone_manufacturer in module.Profile
            if hasattr(module.Phone, 'detectphone'):
                if using_port is None:
                    likely_ports=[x['name'] for x in coms if \
                                  x['available'] and \
                                  comdiagnose.islikelyport(x, module)]
                else:
                    likely_ports = [using_port]
                self.log('Likely ports:' + str(likely_ports))
                found_port = getattr(module.Phone,
                                     'detectphone')(coms, likely_ports,
                                                    self.__data, module, self)
                self.log('Detect Phone result: ' + ` self.__data `)
                if found_port is not None:
                    self.log('Phone ' + model + ' returned port:' +
                             ` found_port `)
                    # found it
                    found_model = model
                    break
            found_port = self.__check_profile(module.Profile)
            if found_port is not None:
                found_model = model
                break
        if found_port is None and using_port is None and using_model is None:
            # if we're not looking for a specific model on a specific port,
            # scan for other CDMA phone
            found_port, found_model = self.__check_for_other_cdma()
        if found_port is not None and found_model is not None:
            self.log('Found phone:' + found_model + ' port:' + ` found_port `)
            return {
                'port': found_port,
                'phone_name': found_model,
                'phone_module': phones.module(found_model),
                'phone_esn': self.__data[found_port]['esn']
            }
	def get(self, data):

        pass

    
	def set(self, data):

        pass



class  CommPortPage (MyPage) :
	detail_fields=(
        ('name', 'Name', None),
        ('description', 'Description', None),
        ('hardwareinstance', 'Hardware Info', None),
        ('driverprovider', 'Driver Provider', None),
        ('driverversion', 'Driver Version', None),
        ('driverdescription', 'Driver Description', None),
        ('class', 'Class', None),
        ('active', 'Active', None),
        )
	    def __init__(self, parent):

        super(CommPortPage, self).__init__(parent, 'Communication Port Setting',
                                           'Set the serial port through which BitPim communicates with the phone.')

        self._ports=[{'name': 'auto', 'description': 'BitPim will try to detect the correct port automatically when accessing your phone'}]+\
                     [x for x in comscan.comscan() if x.get('available', False)]

        self._populate()

        self._set_max_size()

    
	def GetMyControls(self):

        hs=wx.BoxSizer(wx.HORIZONTAL)

        _sbs1=wx.StaticBoxSizer(wx.StaticBox(self, -1, 'Available Ports'),
                                wx.VERTICAL)

        self._ports_lb=wx.ListBox(self, -1,
                                  style=wx.LB_SINGLE|wx.LB_HSCROLL|wx.LB_NEEDED_SB)

        wx.EVT_LISTBOX(self, self._ports_lb.GetId(),
                       self.OnPortSelected)

        _sbs1.Add(self._ports_lb, 1, wx.EXPAND|wx.ALL, 5)

        hs.Add(_sbs1, 0, wx.EXPAND|wx.ALL, 5)

        _sbs2=wx.StaticBoxSizer(wx.StaticBox(self, -1, 'Port Detail'),
                                wx.VERTICAL)

        fgs=wx.FlexGridSizer(0, 2, 5, 5)

        fgs.AddGrowableCol(1)

        self._w=[]

        for e in CommPortPage.detail_fields:

            fgs.Add(wx.StaticText(self, -1, e[1]), 0, wx.EXPAND|wx.ALL, 0)

            w=wx.StaticText(self, -1, 100*' ')

            fgs.Add(w, 0, wx.EXPAND|wx.LEFT, 5)

            self._w.append(w)

        _sbs2.Add(fgs, 1, wx.EXPAND|wx.ALL, 5)

        self._port_details_bs=_sbs2

        hs.Add(_sbs2, 0, wx.EXPAND|wx.ALL, 5)

        return hs

    
	def ok(self):

        return self._ports_lb.GetSelection()!=wx.NOT_FOUND

    
	def get(self, data):

        data['com']=self._ports_lb.GetStringSelection()

    
	def _set_max_size(self):

        _max_size=wx.Size(0,0)

        for e in self._ports:

            self._populate_each(e)

            _ms=self._port_details_bs.GetMinSize()

            _max_size[0]=max(_max_size[0], _ms[0])

            _max_size[1]=max(_max_size[1], _ms[1])

        self._port_details_bs.SetMinSize(_max_size)

        for w in self._w:

            w.SetLabel('')

    
	def Clear(self):

        self._ports_lb.Clear()

        for w in self._w:

            w.SetLabel('')

    
	def _populate(self):

        self.Clear()

        for e in self._ports:

            self._ports_lb.Append(e['name'])

    
	def _populate_each(self, data):

        for i,e in enumerate(CommPortPage.detail_fields):

            v=data.get(e[0], '')

            self._w[i].SetLabel(str(v))

        self._port_details_bs.Layout()

    
	def OnPortSelected(self, evt):

        self._populate_each(self._ports[evt.GetInt()])



class  PhoneModelPage (MyPage) :
	def __init__(self, parent):

        super(PhoneModelPage, self).__init__(parent, 'Phone Model Setting',
                                        'Set your phone model.')

        self._populate()

    
	def GetMyControls(self):

        hs=wx.BoxSizer(wx.HORIZONTAL)

        _sbs=wx.StaticBoxSizer(wx.StaticBox(self, -1, 'Carriers'),
                              wx.VERTICAL)

        self._carriers_lb=wx.ListBox(self, -1,
                                     style=wx.LB_SINGLE|wx.LB_HSCROLL|wx.LB_NEEDED_SB)

        wx.EVT_LISTBOX(self, self._carriers_lb.GetId(), self.OnCarriersLB)

        _sbs.Add(self._carriers_lb, 1, wx.EXPAND|wx.ALL, 5)

        hs.Add(_sbs, 0, wx.EXPAND|wx.ALL, 5)

        _sbs=wx.StaticBoxSizer(wx.StaticBox(self, -1, 'Manufacturers'),
                               wx.VERTICAL)

        self._manuf_lb=wx.ListBox(self, -1,
                                  style=wx.LB_SINGLE|wx.LB_HSCROLL|wx.LB_NEEDED_SB)

        wx.EVT_LISTBOX(self, self._manuf_lb.GetId(), self.OnCarriersLB)

        _sbs.Add(self._manuf_lb, 1, wx.EXPAND|wx.ALL, 5)

        hs.Add(_sbs, 0, wx.EXPAND|wx.ALL, 5)

        _sbs=wx.StaticBoxSizer(wx.StaticBox(self, -1, 'Models'),
                               wx.VERTICAL)

        self._models_lb=wx.ListBox(self, -1,
                                   style=wx.LB_SINGLE|wx.LB_HSCROLL|wx.LB_NEEDED_SB)

        wx.EVT_LISTBOX(self, self._models_lb.GetId(), self.OnModelsLB)

        _sbs.Add(self._models_lb, 1, wx.EXPAND|wx.ALL, 5)

        hs.Add(_sbs, 0, wx.EXPAND|wx.ALL, 5)

        return hs

    
	def _populate_models(self, carrier=None, brand=None):

        self._models_lb.Clear()

        for e in phones.phoneslist(brand, carrier):

            self._models_lb.Append(e)

    
	def _populate(self):

        self._carriers_lb.Clear()

        self._manuf_lb.Clear()

        self._models_lb.Clear()

        for e in ['All']+phones.phonecarriers:

            self._carriers_lb.Append(e)

        for e in ['All']+phones.phonemanufacturers:

            self._manuf_lb.Append(e)

        self._carriers_lb.SetSelection(0)

        self._manuf_lb.SetSelection(0)

        self._populate_models()

    
	def ok(self):

        return self._models_lb.GetSelection()!=wx.NOT_FOUND

    
	def get(self, data):

        data['phone']=self._models_lb.GetStringSelection()

    
	def OnCarriersLB(self, evt):

        _s=self._carriers_lb.GetStringSelection()

        if not _s or _s=='All':

            _carrier=None

        else:

            _carrier=_s

        _s=self._manuf_lb.GetStringSelection()

        if not _s or _s=='All':

            _brand=None

        else:

            _brand=_s

        self._populate_models(_carrier, _brand)

    
	def OnModelsLB(self, evt):

        _model=evt.GetString()

        self._carriers_lb.SetStringSelection(phones.carrier(_model))

        self._manuf_lb.SetStringSelection(phones.manufacturer(_model))



class  SummaryPage (MyPage) :
	def __init__(self, parent):

        super(SummaryPage, self).__init__(parent, 'Summary')

    
	def GetMyControls(self):

        vs=wx.BoxSizer(wx.VERTICAL)

        _sbs=wx.StaticBoxSizer(wx.StaticBox(self, -1, 'User Selection'),
                               wx.VERTICAL)

        _fgs=wx.FlexGridSizer(0, 2, 5, 5)

        _fgs.Add(wx.StaticText(self, -1, 'Phone Model:'),
                 0, wx.EXPAND|wx.ALL, 0)

        self._model=wx.StaticText(self, -1, '')

        _fgs.Add(self._model, 0, wx.EXPAND|wx.ALL, 0)

        _fgs.Add(wx.StaticText(self, -1, 'Port:'),
                 0, wx.EXPAND|wx.ALL, 0)

        self._port=wx.StaticText(self, -1, '')

        _fgs.Add(self._port, 0, wx.EXPAND|wx.ALL, 0)

        _fgs.Add(wx.StaticText(self, -1, 'Detection Status:'),
                 0, wx.EXPAND|wx.ALL, 0)

        self._status=wx.StaticText(self, -1, '')

        _fgs.Add(self._status, 0, wx.EXPAND|wx.ALL, 0)

        _sbs.Add(_fgs, 1, wx.EXPAND, 0)

        vs.Add(_sbs, 0, wx.EXPAND|wx.ALL, 5)

        self._det_btn=wx.Button(self, -1, 'Detect Phone')

        vs.Add(self._det_btn, 0, wx.ALL, 5)

        wx.EVT_BUTTON(self, self._det_btn.GetId(), self.OnDetect)

        return vs

    
	def set(self, data):

        self._model_name=data.get('phone', '')

        self._model.SetLabel(self._model_name)

        self._com_port=data.get('com', '')

        self._port.SetLabel(self._com_port)

        _module=common.importas(phones.module(self._model_name))

        self._det_btn.Enable(bool(self._model_name and \
                                  hasattr(_module.Phone,
                                         'detectphone'))) 

    
	def OnDetect(self, _):

        if self._com_port=='auto':

            _port_name=None

        else:

            _port_name=str(self._com_port)

        _res=phone_detect.DetectPhone().detect(using_port=_port_name,
                                               using_model=self._model_name)

        _status='FAILED'

        if _res and _res.get('phone_name', '')==self._model_name:

            _status='PASSED'

        self._status.SetLabel(_status)



class  SetPhoneWizard (wiz.Wizard) :
	def __init__(self, parent):

        super(SetPhoneWizard, self).__init__(parent, -1,
                                             'Phone Setting Wizard')

        self._data={}

        commport_page=CommPortPage(self)

        phonemodel_page=PhoneModelPage(self)

        summary_page=SummaryPage(self)

        wiz.WizardPageSimple_Chain(commport_page, phonemodel_page)

        wiz.WizardPageSimple_Chain(phonemodel_page, summary_page)

        self.first_page=commport_page

        self.GetPageAreaSizer().Add(commport_page, 1, wx.EXPAND|wx.ALL, 5)

        wiz.EVT_WIZARD_PAGE_CHANGING(self, self.GetId(), self.OnPageChanging)

        wiz.EVT_WIZARD_PAGE_CHANGED(self, self.GetId(), self.OnPageChanged)

    
	def RunWizard(self, firstPage=None):

        return super(SetPhoneWizard, self).RunWizard(firstPage or self.first_page)

    
	def OnPageChanging(self, evt):

        pg=evt.GetPage()

        if not evt.GetDirection() or pg.ok():

            pg.get(self._data)

        else:

            evt.Veto()

    
	def OnPageChanged(self, evt):

        evt.GetPage().set(self._data)

    
	def get(self):

        return self._data



if __name__=="__main__":

    app=wx.PySimpleApp()

    f=wx.Frame(None, title='setphone_wizard')

    w=SetPhoneWizard(f)

    print w.RunWizard()

    print w._data

    w.Destroy()
Exemplo n.º 12
0
    def detect(self, using_port=None, using_model=None):
        # start the detection process
        # 1st, get the list of available ports
        coms=comscan.comscan()+usbscan.usbscan()
        self.log('coms:'+str(coms))
        available_modem_coms=[x['name'] for x in coms if x['available'] \
                              and x.get('class', None)=='modem']
        if not using_port:
            available_coms=[x['name'] for x in coms if x['available']]
        else:
            available_coms=[using_port]
            available_modem_coms=[x for x in available_coms if x in available_modem_coms]
        # loop through each port and gather data
        self.log('Available ports: '+str(available_coms))
        self.log('Available modem ports: '+str(available_modem_coms))
        # only try those AT commands on modem ports
        # using threads
        self.__q_on=True
        threads=[threading.Thread(target=self.do_get_data, args=(e,)) \
                 for e in available_modem_coms]
        for t in threads:
            t.start()
        for t in threads:
            t.join()
        self.__q_on=False
        while not self.__q_log.empty():
            q=self.__q_log.get_nowait()
            if isinstance(q, (list, tuple)):
                self.logdata(*q)
            else:
                self.log(q)
        # non-thread version
##        for e in available_modem_coms:
##            self.do_get_data(e)
        # go through each phone and ask it
##        pm=phones.phonemodels
        if using_model:
            models=[using_model]
        else:
            models=phones.phonemodels
        found_port=found_model=None
        for model in models:
            self.log('Checking for model: '+model)
            module=common.importas(phones.module(model))
            # check for detectphone in module.Phone or
            # phone_model and phone_manufacturer in module.Profile
            if hasattr(module.Phone, 'detectphone'):
                if using_port is None:
                    likely_ports=[x['name'] for x in coms if \
                                  x['available'] and \
                                  comdiagnose.islikelyport(x, module)]
                else:
                    likely_ports=[using_port]
                self.log('Likely ports:'+str(likely_ports))
                found_port=getattr(module.Phone, 'detectphone')(coms,
                                                                likely_ports,
                                                                self.__data,
                                                                module,
                                                                self)
                self.log('Detect Phone result: '+`self.__data`)
                if found_port is not None:
                    self.log('Phone '+model+' returned port:'+`found_port`)
                    # found it
                    found_model=model
                    break
            found_port=self.__check_profile(module.Profile)
            if found_port is not None:
                found_model=model
                break
        if found_port is None and using_port is None and using_model is None:
            # if we're not looking for a specific model on a specific port,
            # scan for other CDMA phone
            found_port, found_model=self.__check_for_other_cdma()
        if found_port is not None and found_model is not None:
            self.log('Found phone:'+found_model+' port:'+`found_port`)
            return { 'port': found_port, 'phone_name': found_model,
                     'phone_module': phones.module(found_model),
                     'phone_esn': self.__data[found_port]['esn'] }
	def exp_scan(self, context):

        if usb is None:

            return comscan.comscan()

        else:

            return usbscan.usbscan()+comscan.comscan()

	def exp_getversion(self, context):

        return version.description

	def exp_deviceopen(self, port, baud, timeout, hardwareflow, softwareflow, context):

        return self.stashhandle(context, commport.CommConnection(None, port, baud, timeout,
                                                                 hardwareflow, softwareflow))

	def exp_deviceclose(self, handle, context):

        comm=self.gethandle(context, handle)

        comm.close()

        del self.handles[handle]

        return True

	def exp_devicesetbaudrate(self, handle, rate, context):

        return self.gethandle(context, handle).setbaudrate(rate)

	def exp_devicesetdtr(self, handle, dtr, context):

        return self.gethandle(context, handle).setdtr(dtr)

	def exp_devicesetrts(self, handle, rts, context):

        return self.gethandle(context, handle).setrts(rts)

	def exp_devicewrite(self, handle, data, context):

        self.gethandle(context, handle).write(data.data)

        return len(data.data)

	def exp_devicesendatcommand(self, handle, atcommand, ignoreerror, context):

        "Special handling for empty lists and exceptions"

        try:

            res=self.gethandle(context, handle).sendatcommand(atcommand.data, ignoreerror=ignoreerror)

            if len(res)==0:

                res=1

        except:

            res=0

        return res

	def exp_devicereaduntil(self, handle, char, numfailures, context):

        return Binary(self.gethandle(context, handle).readuntil(char.data, numfailures=numfailures))

	def exp_deviceread(self, handle, numchars, context):

        return Binary(self.gethandle(context, handle).read(numchars))

	def exp_devicereadsome(self, handle, numchars, context):

        if numchars==-1:

            numchars=None

        return Binary(self.gethandle(context, handle).readsome(log=True,numchars=numchars))

	def exp_devicewritethenreaduntil(self, handle, data, char, numfailures, context):

        return Binary(self.gethandle(context, handle).writethenreaduntil(data.data, False, char.data, False, False, numfailures))


def run(args):

    theApp=wx.PySimpleApp()

    menu=wx.Menu()

    menu.Append(ID_EXIT, "Exit")

    mw=MainWindow(None, -1, "BitFling")

    taskwin=MyTaskBarIcon(mw, menu)

    mw.taskwin=taskwin

    theApp.MainLoop()

if __name__ == '__main__':

    run()


try:

    import native.usb as usb

except ImportError:

    usb=None


if guihelper.IsMSWindows(): parentclass=wx.TaskBarIcon

else: parentclass=wx.Frame


if __name__ == '__main__':

    run()