|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
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
__________________
IE QUOTE | PHP Manual | Google | C/C++ Compiler | Linux Tutorials | General Stuff Game Dev |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
||||
|
||||
|
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. |
|
#4
|
|||
|
|||
|
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 |
|
#5
|
||||
|
||||
|
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 |
|
#6
|
|||
|
|||
|
Try AppendToPage(string)
Dave - The Developers' Coach |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Text in wxPython Programs |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|