Filed in archive
Hacks
by Michael Hammer on August 29, 2006
There is one feature that I really like in Windows XP (although it is generally implemented in an incomprehensible manner), and that is the web-styled interface. Not the implementation mind you, but the idea.
While I have been a user for a long time, and am used to hierarchical style GUI interfaces, I have noticed that many users prefer the XP style web-look interfaces, with their somewhat looser context dependance.
I was playing with wxPython and it's wxHtmlWindow widget in an attempt to mimic the XP interface, and succeeded almost immediately. It is now a simple manner to generate a web interface that can still call internal procedures with ease, and is easily skinnable through external HTML files.....
Source code is at the bottom...
Methodology is really simple on this one folks. We build a new App with a notebook control that contains (for now) just a single wxHtmlWindow widget. The wxHtmlWindow is a new class that has an onLinkClicked event overridden. The system checks to see if the link is pointed at the "command" target like so:
command
When this is the case, the url is broken down into a python object and method as per the url, and executed with eval (commandConstructedFromURL).
Obviously you have to be careful, since this method of building an interface opens you up to the possibility of XSS inside of your desktop app.
Advantages:
Extremely fast interface buildup
Standardized scripting language and stable API (not JSCRIPT or ECMASCRIPT)
Easily themable
Truly cross platform (not IE ActiveX)
Easy to Implement (not importing the whole Gecko browser)
Fast (again, no mozilla dependencies)
Drawbacks:
Limited scriptability (not a real browser)
No CSS (oh god! the dark ages (1997) again)
XSS vulnerable (unless you disable real hrefs entirely)
No plugins (SWF,MOV,AVI,WMV,JAVA)
Source Code:
#!/usr/bin/python
from wxPython.wx import *
from wxPython.html import *
import string
import urlparse
import urlparse
import urllib
ID_ABOUT = 101
ID_EXIT = 102
class TryAppFrame(wxFrame):
myIcon=None
myStreamList=None
urlList=None
jackerList={}
updateTimer=None
def __init__(self, parent, ID, title):
wxFrame.__init__(self, parent, ID, title,
wxDefaultPosition)
menu = wxMenu()
menu.Append(ID_ABOUT, "&About",
"More information about this program")
menu.AppendSeparator()
menu.Append(ID_EXIT, "E&xit", "Terminate the program")
#Create the menu bar here...
menuBar = wxMenuBar()
#Just so that we can have the menu accessible for changes later.
self.menu=menu
menuBar.Append(menu, "&File")
self.SetMenuBar(menuBar)
EVT_MENU(self, ID_ABOUT, self.OnAbout)
EVT_MENU(self, ID_EXIT, self.TimeToQuit)
#Now we add the tabbed windows
#Create a notebook sizer to have multiple config pages.
self.nbook=wxNotebook(self,-1)
self.nbookSzr=wxNotebookSizer(self.nbook)
#Status page. Much like the Kazaa start page
self.statusHtmlWindow=HtmlInterfaceWindow (self.nbook,-1,)
#Give it some content
self.statusHtmlWindow.LoadPage("tmpl/main.html");
#Add it.
self.nbook.AddPage(self.statusHtmlWindow,"Status")
def OnAbout(self, event):
dlg = wxMessageDialog(self,
"(c)2003 Derek Anderson.\nhttp://enki.cthuugle.com/\n\n"+
"This program is released under the\n"+
"Gnu Public License. Please play fair!\nhttp://www.gnu.org/\n"
"Enjoy!",
"About DIRT", wxOK | wxICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
def TimeToQuit(self, event):
self.Close(true)
class HtmlInterfaceWindow (wxHtmlWindow):
def OnLinkClicked (self,link):
self.linkHandler(link)
def test (self,val1):
print "testing",val1
def linkHandler (self,link):
if link.GetTarget()=="command":
print "Link: ",link.GetHref()," Target: ",link.GetTarget()," parameters: "+
",urlparse.urlparse(link.GetHref())[4]," from cell: ",link.GetHtmlCell()
#print "I will execute..."
commandTuple=urlparse.urlparse(link.GetHref())
#print "Xommand tuple: ",commandTuple
command=commandTuple[1]+"."+commandTuple[2][1:]+"("
for value in commandTuple[4].split("&"):
command=command+urllib.unquote(value.split("=")[1])+","
command=command[:len(command)-1]+")"
try:
eval(command)
except:
print "Error evaluating command url:",command
#else:
#self.base_OnLinkClicked(link)
class TryApp(wxApp):
mainframe=None
def OnInit(self):
self.mainframe = TryAppFrame(NULL, -1, "TRY 0.01b")
self.mainframe.Show(true)
self.SetTopWindow(self.mainframe)
return true
app = TryApp(0)
app.MainLoop()
While I have been a user for a long time, and am used to hierarchical style GUI interfaces, I have noticed that many users prefer the XP style web-look interfaces, with their somewhat looser context dependance.
I was playing with wxPython and it's wxHtmlWindow widget in an attempt to mimic the XP interface, and succeeded almost immediately. It is now a simple manner to generate a web interface that can still call internal procedures with ease, and is easily skinnable through external HTML files.....
Source code is at the bottom...
Methodology is really simple on this one folks. We build a new App with a notebook control that contains (for now) just a single wxHtmlWindow widget. The wxHtmlWindow is a new class that has an onLinkClicked event overridden. The system checks to see if the link is pointed at the "command" target like so:
command
When this is the case, the url is broken down into a python object and method as per the url, and executed with eval (commandConstructedFromURL).
Obviously you have to be careful, since this method of building an interface opens you up to the possibility of XSS inside of your desktop app.
Advantages:
Extremely fast interface buildup
Standardized scripting language and stable API (not JSCRIPT or ECMASCRIPT)
Easily themable
Truly cross platform (not IE ActiveX)
Easy to Implement (not importing the whole Gecko browser)
Fast (again, no mozilla dependencies)
Drawbacks:
Limited scriptability (not a real browser)
No CSS (oh god! the dark ages (1997) again)
XSS vulnerable (unless you disable real hrefs entirely)
No plugins (SWF,MOV,AVI,WMV,JAVA)
Source Code:
#!/usr/bin/python
from wxPython.wx import *
from wxPython.html import *
import string
import urlparse
import urlparse
import urllib
ID_ABOUT = 101
ID_EXIT = 102
class TryAppFrame(wxFrame):
myIcon=None
myStreamList=None
urlList=None
jackerList={}
updateTimer=None
def __init__(self, parent, ID, title):
wxFrame.__init__(self, parent, ID, title,
wxDefaultPosition)
menu = wxMenu()
menu.Append(ID_ABOUT, "&About",
"More information about this program")
menu.AppendSeparator()
menu.Append(ID_EXIT, "E&xit", "Terminate the program")
#Create the menu bar here...
menuBar = wxMenuBar()
#Just so that we can have the menu accessible for changes later.
self.menu=menu
menuBar.Append(menu, "&File")
self.SetMenuBar(menuBar)
EVT_MENU(self, ID_ABOUT, self.OnAbout)
EVT_MENU(self, ID_EXIT, self.TimeToQuit)
#Now we add the tabbed windows
#Create a notebook sizer to have multiple config pages.
self.nbook=wxNotebook(self,-1)
self.nbookSzr=wxNotebookSizer(self.nbook)
#Status page. Much like the Kazaa start page
self.statusHtmlWindow=HtmlInterfaceWindow (self.nbook,-1,)
#Give it some content
self.statusHtmlWindow.LoadPage("tmpl/main.html");
#Add it.
self.nbook.AddPage(self.statusHtmlWindow,"Status")
def OnAbout(self, event):
dlg = wxMessageDialog(self,
"(c)2003 Derek Anderson.\nhttp://enki.cthuugle.com/\n\n"+
"This program is released under the\n"+
"Gnu Public License. Please play fair!\nhttp://www.gnu.org/\n"
"Enjoy!",
"About DIRT", wxOK | wxICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
def TimeToQuit(self, event):
self.Close(true)
class HtmlInterfaceWindow (wxHtmlWindow):
def OnLinkClicked (self,link):
self.linkHandler(link)
def test (self,val1):
print "testing",val1
def linkHandler (self,link):
if link.GetTarget()=="command":
print "Link: ",link.GetHref()," Target: ",link.GetTarget()," parameters: "+
",urlparse.urlparse(link.GetHref())[4]," from cell: ",link.GetHtmlCell()
#print "I will execute..."
commandTuple=urlparse.urlparse(link.GetHref())
#print "Xommand tuple: ",commandTuple
command=commandTuple[1]+"."+commandTuple[2][1:]+"("
for value in commandTuple[4].split("&"):
command=command+urllib.unquote(value.split("=")[1])+","
command=command[:len(command)-1]+")"
try:
eval(command)
except:
print "Error evaluating command url:",command
#else:
#self.base_OnLinkClicked(link)
class TryApp(wxApp):
mainframe=None
def OnInit(self):
self.mainframe = TryAppFrame(NULL, -1, "TRY 0.01b")
self.mainframe.Show(true)
self.SetTopWindow(self.mainframe)
return true
app = TryApp(0)
app.MainLoop()
Trackback: http://publish.creative-weblogging.com/publish/mt-tb.pl/34699
Mr Wong
Vote for wxPython Cross Platform XP/Web Style Interfaces:
|
Rating: 8.00 out of 2 vote(s) cast.
|
Subscribe
Use the search to look for other interesting posts
| RSS | See all blog subscribe options |
|
What is RSS? | |
| Yahoo! |
|
| Addthis |
|
| Bloglines |
|
| Newsletter | |
| Follow us on Twitter! |










