June 23rd, 2004, 09:55 AM
Text and html window
Is taking a text box content and the directly feed it to html window a good idea? .. let see how can I explaine this, I have 1 text box(for input) and I html window in a frame, what I want to do is accept input from user, the take the input and feed it to the html window, so every time the user type something the value will be passed to a function and the feeded to the html window:
is this a good idea or not? also I'm thinking of using file instead but writing and reading file will slow down the program.
def event(self, event):#this function is triggered everytime user type anything in the textBox
page = self.textBox.GetValue()
June 23rd, 2004, 11:39 AM
Its a nice idea, an interesting one at least though im not exactly sure of the purpose.. i'm assuming you are building an application with a sort of editor that lets the user preview there page as is currently in the editor window.
It also kinda sounds like you want to gather user input and insert it into the html page via a function call.
Am i anywhere close here?
June 23rd, 2004, 12:10 PM
Are you talking about a wxWindows program? This is not clear from your post, but looking at the code I guess it is.
I don't see any problem with what you are doing, except that you will probably want to convert the string to handle HTML characters correctly, unless you expect the user to to type raw HTML into the text box. For example if the user types in something like:
if a < b:
then the HTML parser will think that <b is the start of a bold tag, and will totally screw up the page.
To do the conversion use either cgi.escape or xml.sax.saxutils.quoteattr. These will both convert things like < into > so that they are displayed correctly in HTML
Dave - The Developers' Coach
June 23rd, 2004, 12:17 PM
Another point to note is that HTML ignores whitespace, including carriage returns/line feeds. You may want to replace '\n' with '<br>' in your string.
Dave - The Developers' Coach
June 28th, 2004, 07:05 AM
Inspired by Hyperedit, what I'm tying to do is set up split window, 1 with text area(for editing), and the other one with html window, so user can write html code in the text area and the html window will render the code instantly as user type, voila!!! live preview. I've tried it before and it does works, but I'm asking it here beacause I'm a bit anxious with memory consumption, will it crash etc.
Originally Posted by netytan
June 28th, 2004, 07:18 AM
I used the approach you described for my first wxPython program (Hissing Sid)
Not the best code in the world but you can find it's source here.
June 28th, 2004, 07:21 AM
Well we know its possible because HTML editors like DreamWeaver do this and have been doing this for a long time .
I dout there are any errors spacifically linked to this type of application i.e. you mentioned 'crashing'. But obviously, if the program is writen well, there should be no crashing .
One thing i might suggest though would be have a button to update the view otherwise the page will get pretty much distroyed as you for example start to create a new table since the HTML will be not be valid while your doing this .
Sure there are ways to work around all this though. I think Pythons up to the challenge! Looking forward to seeing this in action!