Results 1 to 10 of 22

Thread: learning python?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #20
    Allow me to move this forward a bit and show an experimental IUP binding for Python that AIR is working on. (stay tuned for an official announcement)

    #!/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. (more ...)
    Attached Images Attached Images
    Last edited by John Spikowski; 04-12-2011 at 23:36.
    ScriptBasic Project Manager
    Project Site
    support@scriptbasic.org

Similar Threads

  1. Replies: 13
    Last Post: 29-06-2011, 22:57
  2. Python Sets
    By danbaron in forum Scripting
    Replies: 5
    Last Post: 24-10-2010, 06:10
  3. Python 3 --> Ackermann Function
    By danbaron in forum Scripting
    Replies: 5
    Last Post: 17-06-2010, 22:48
  4. Asimo's Learning Capabilities
    By Charles Pegge in forum Shout Box Area
    Replies: 12
    Last Post: 28-04-2010, 18:22
  5. Learning Oxygen and discussion of ideas for projects
    By kryton9 in forum O2 JIT Compiler / Assembler / Oxygen project
    Replies: 187
    Last Post: 31-07-2009, 09:10

Members who have read this thread: 0

There are no members to list at the moment.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •