The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
Text in wxPython Programs
Discuss Text in wxPython Programs in the Python Programming forum on Dev Shed. Text in wxPython Programs Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

May 21st, 2004, 03:08 PM
|
 |
Only the strong survives!!.
|
|
Join Date: Feb 2003
Location: A World of wonders.
|
|
|
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
|

May 21st, 2004, 06:46 PM
|
|
Contributing User
|
|
Join Date: Feb 2004
Location: London, England
|
|
|
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
|

May 22nd, 2004, 01:14 AM
|
 |
Only the strong survives!!.
|
|
Join Date: Feb 2003
Location: A World of wonders.
|
|
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 03:29 AM.
|

May 22nd, 2004, 05:13 AM
|
|
Contributing User
|
|
Join Date: Feb 2004
Location: London, England
|
|
|
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
|

May 22nd, 2004, 01:26 PM
|
 |
Only the strong survives!!.
|
|
Join Date: Feb 2003
Location: A World of wonders.
|
|
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
|

May 22nd, 2004, 02:34 PM
|
|
Contributing User
|
|
Join Date: Feb 2004
Location: London, England
|
|
|
Try AppendToPage(string)
Dave - The Developers' Coach
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|