From: Stephane F. <f8...@fr...> - 2006-02-20 21:59:47
|
G'day the Python hackers, On Fri, Feb 10, 2006 at 12:16:09PM -0500, Martin, AA6E wrote: > Hi, Hamish, > > Glad to see there are at least two of us interested in Python apps. I > am just getting started with Python hamlib too. I haven't figured out > the 'foreach' function, but I don't think it's necessary. You may say > it's a hack, but I think it's a neat use of Python. Here's my little > program: > > import Hamlib > def isRIG_MODEL(s): > return s.startswith("RIG_MODEL") > rig_models = filter(isRIG_MODEL, dir(Hamlib)) > rig_codes = map(lambda x: Hamlib.__dict__[x], rig_models) > for i in range(len(rig_models)): > print rig_models[i], rig_codes[i] > > This gets you a complete list of the magic rig codes, and you can use > it to check the capabilities -- which are still a mystery to me! > Basically, Hamlib's own symbol dictionary has all the information you > want. That's a nice Python trick. And this does not even load the backends, so this is fast. Another trick is one from Rigtuner[1]/Hamlib-config[2]. [1] http://hamspot.com/ham/Rig_Tuner [2] http://hamspot.com/ham/Hamlib_Config Here is the code snippet: # loop through all possible models for i in range(2500): # redraw the display while gtk.events_pending(): gtk.mainiteration(FALSE) # if the user clicked cancel then give up right here if self.build_list_cancel is TRUE: break else: # try to load the module for this model try: rig = Hamlib.Rig(i) if rig.caps.rig_model: iter = self.radio_model_list.append() self.radio_model_list.set_value(iter, 0, i) self.radio_model_list.set_value(iter, 1, rig.caps.mfg_name) self.radio_model_list.set_value(iter, 2, rig.caps.model_name) except: continue ... Have a look at function build_radio_model_list in hamlib-config-1.0/hamlib-config-rpcrig.py Note: when writting a Hamlib application, get the list of all the supported rigs ONLY if the user requests it (during configuration phase, etc.). Otherwise, it's better for load time to provide an option processing (getopt on command line, preference file in GUI, etc.) which gets the immediate rig ID. > On 2/10/06, Hamish Moffatt <ha...@cl...> wrote: [..] > > Firstly I want to get a list of all the supported rigs so I can present > > it to the user. Looking at the API documentation, the riglist.h page > > says there is a function called foreach_opened_rig(), although it looks > > like that is not right. foreach_opened_rig() is an internal function (not prefixed by rig_ or rot_), and it works only on already *opened* rigs. > > The riglist.h source says there is a rig_list_foreach function which > > takes a pointer to a function to call. However I don't think this is > > usable from Python? I can't make Python happy with the definition of my > > callback. rig_list_foreach is the appropriate function, however the swig magic has never been completed to make it to work for any scripting language. If you find a way to do it, please let me know. Another solution could be to write swig magic that would return a vector of rig description objects. Anyway, feel free to share with us a link of your application, so it can be added to the http://hamlib.org/app.html page. Happy hacking, -- Stephane - F8CFE |