#!/usr/bin/env python
from iup import *
from dictclient import *
selected_server = ''
about_msg="""This is a Demo
of the IUP GUI Binding
for Python"""
def btnAbout_Clicked(sender):
IupMessage("ABOUT",about_msg)
return IUP_DEFAULT
def btnExit_Clicked(sender):
return IUP_CLOSE
def btnClear_Clicked(sender):
IupSetAttribute(serverList,"1",None)
IupSetAttribute(text,"VALUE",None)
IupSetAttribute(entry,"VALUE",None)
return IUP_DEFAULT
def btnFetch_Clicked(sender):
try:
s = Connection(selected_server)
dbs = s.getdbdescs()
for db in dbs:
IupSetAttribute(serverList, "APPENDITEM", db + " \t\t\t" + dbs[db])
except socket.error:
IupMessage("Connection Error","Unable to Connect")
return IUP_DEFAULT
def btnSearch_Clicked(sender):
result = ''
search_word = str(IupGetAttribute(entry,"VALUE"))
chkAll_State = str(IupGetAttribute(chkAll,"VALUE"))
if search_word:
s = Connection(selected_server)
if chkAll_State == "ON":
retval = s.match('*',"word",search_word)
else:
pass
for item in retval:
result += item.getdefstr()
IupSetAttribute(text,"VALUE",result)
else:
IupMessage("Missing Search Term", "No Search Term Specified")
return IUP_DEFAULT
def serverCombo_Selection(sender, text, item, state):
global selected_server
if state:
selected_server = str(text)
return IUP_DEFAULT
# Initialize IUP
IupOpen(None, None)
# CREATE FORM OBJECTS
btnFetch = IupSetAttributes(IupButton('Fetch', None),'SIZE=50x')
serverCombo = IupSetAttributes(IupList(None),'DROPDOWN=YES, SIZE=120x, EXPAND=HORIZONTAL, VALUE=1')
btnAbout = IupSetAttributes(IupButton('About',None),'SIZE=50x')
btnClear = IupSetAttributes(IupButton('Clear',None),'SIZE=50x')
btnExit = IupSetAttributes(IupButton('Exit',None),'SIZE=50x')
entry = IupSetAttributes(IupText(None),'EXPAND=HORIZONTAL')
btnSearch = IupSetAttributes(IupButton('Search',None), 'SIZE=50x')
chkAll = IupSetAttributes(IupToggle('ALL',None), 'SIZE=20x14, VALUE=ON')
chkUTF = IupSetAttributes(IupToggle('UTF',None), 'SIZE=20x14')
serverList = IupSetAttributes(IupList(None),'EXPAND=YES, VISIBLELINES=1')
text = IupSetAttributes(IupText(None),'MULTILINE=YES, EXPAND=YES, READONLY=YES')
# END FORM OBJECTS
# CREATE CONTAINER OBJECTS
topbox = IupHbox(IupSetAttributes(IupFrame(IupHbox(serverCombo, btnFetch, None)),'TITLE=Servers, EXPAND=YES'),
IupSetAttributes(IupFrame(IupSetAttributes(IupHbox(btnAbout,btnClear,btnExit,None),'GAP=5')), 'TITLE=Controls'),
None)
dictFrame = IupSetAttributes(IupFrame(serverList),'TITLE=Dictionaries')
transFrame = IupSetAttributes(IupFrame(text),'TITLE=Translation')
bottomBox = IupSetAttributes(IupHbox(entry,btnSearch,chkAll,None),'GAP=10x10')
# END CONTAINER OBJECTS
# CREATE CALLBACK REFERENCES
FetchFunc = Icallback(btnFetch_Clicked)
ComboFunc = LIST_CB(serverCombo_Selection)
ClearFunc = Icallback(btnClear_Clicked)
ExitFunc = Icallback(btnExit_Clicked)
SearchFunc = Icallback(btnSearch_Clicked)
AboutFunc = Icallback(btnAbout_Clicked)
# END CALLBACK REFERENCES
# CONNECT CALLBACKS
IupSetCallback(btnExit,"ACTION",ExitFunc)
IupSetCallback(btnFetch, "ACTION", FetchFunc)
IupSetCallback(serverCombo,"ACTION", ComboFunc)
IupSetCallback(btnClear,"ACTION", ClearFunc)
IupSetCallback(btnSearch,"ACTION",SearchFunc)
IupSetCallback(btnAbout,"ACTION",AboutFunc)
# END CONNECT CALLBACKS
# CREATE MAIN WINDOW
win = IupSetAttributes(IupDialog(IupSetAttributes(IupVbox(topbox,dictFrame,transFrame,bottomBox,None),'MARGIN=10x10')),
'TITLE=Thesaurus, SIZE=420x300')
IupShow(win)
# POPULATE COMBOBOX
for server in ('www.dict.org','dict1.us.dict.org','all.dict.org'):
IupSetAttribute(serverCombo,'APPENDITEM',server)
# RUN MAIN LOOP
IupMainLoop()
# SHUTDOWN IUP
IupClose()
I have also been busy with the ScriptBasic version of the IUP binding. (
Bookmarks