#1
  1. Only the strong survives!!.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Feb 2003
    Location
    A World of wonders.
    Posts
    5,583
    Rep Power
    407

    Text in wxPython Programs


    Im tring to find a function in wxPython that will allow me to add text, images on the frame.. i have been looking for something like this for a few days, but havent found anything yet.. i need something like TextCtrl ( ) but that only allows text ( like for editors etc ) anyone has a better idea?... something that i can output data like if i was to connect to a website then i would ouput the websites data on the frame in the center or something
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    London, England
    Posts
    1,585
    Rep Power
    1373
    I think wxHtmlWindow is what you want. it will render HTML including graphics into a window.

    You can also embed other widgets in it - see the wxPython demo for examples.

    Dave - The Developers' Coach
  4. #3
  5. Only the strong survives!!.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Feb 2003
    Location
    A World of wonders.
    Posts
    5,583
    Rep Power
    407
    Ok i used SetPage( ) to set text to the htmlwindow.. but one more question.. why doesnt this want to bring up my program when i add the while loop

    Code:
    class HtmlWindows ( wxHtmlWindow ):
        def __init__ ( self, Parant, ID, frame ):
            wxHtmlWindow.__init__ ( self, Parant, ID )
    
            Socket  = socket ( AF_INET, SOCK_STREAM )
    
            try:
                
                Socket.connect (( HOST, int ( PORT )))
                Receive = Socket.recv ( 1025 )
    
                while Socket.recv ( 1025 ):
                    self.SetPage( '<font color=red>' + Receive + '</font>' )
                    
                Socket.close ( )
    
            finally:
                
                dlg  = wxMessageDialog ( self, -1, 'Connection Lost', 'Error',
                                         wxOK | wxICON_WARNING )
                dlg.ShowModal ( )
                dlg.Destroy ( )
                Socket.close ( )
                
            self.SetBackgroundColour ( 'Black' )
        
    
    class MyPanel ( wxPanel ):
        def __init__ ( self, Parant, ID, frame ):
            wxPanel.__init__ ( self, Parant, ID )
    
            self.frame  = frame
    
            self.html   = HtmlWindows ( self, -1, self.frame )
                        
            
            sizer   = wxBoxSizer ( wxVERTICAL )
            sizer.Add ( self.html, 1, wxGROW )
    
            subsizer     = wxBoxSizer ( wxHORIZONTAL )
            staticText   = wxStaticText ( self, -1, "Testing" )
            textCtrl     = wxTextCtrl ( self, -1, " " )
            
            subsizer.Add ( staticText, 0, wxGROW | wxALL, 1 )
            subsizer.Add ( textCtrl,   1, wxGROW | wxALL, 1 )
            
            sizer.Add ( subsizer, 0, wxGROW )
            
            self.SetSizer ( sizer )
            self.SetAutoLayout ( True )
    everything else works fine, exept for when i add that while loop then the program wont even load
    Last edited by xlordt; May 22nd, 2004 at 04:29 AM.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    London, England
    Posts
    1,585
    Rep Power
    1373
    What happens when you try to run it? Does it throw an exception, and if so then what?

    The while loop is wrong. You read in a block of 1025 bytes once with the call to socket.recv() outside of the loop, then the loop itself reads in another 1025 bytes, throws it away since you do not assign it to anything, and displays the original block you have stored in Receive. It will repeatedly show the same block, reading in the successive blocks and throwing them away. Of course if there is less than 1026 bytes of data to read in, then it will display nothing since the loop body will be skipped.

    Also note that the SetPage method replaces the previous page being shown rather than appends to it.

    If you are reading an HTML page from the web then it is better to use urllib instead of trying to use sockets directly, or call LoadPage instead of SetPage. Python has a lot of libraries for handling different TCP/IP protocols so that you don't have to.

    Dave - The Developers' Coach
  8. #5
  9. Only the strong survives!!.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Feb 2003
    Location
    A World of wonders.
    Posts
    5,583
    Rep Power
    407
    is there another alternitave to SetPage ( ) cause i need the loop to keep looping so it can get all the data from the server... Im not getting an html page from any site.. its just server info that im getting I.E irc server
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    London, England
    Posts
    1,585
    Rep Power
    1373
    Try AppendToPage(string)

    Dave - The Developers' Coach

IMN logo majestic logo threadwatch logo seochat tools logo