Thanks for the explanation. But after looking at the code a bit, it
seems to be too tightly coupled to Leo to be useful to me. Then
again, I don't really have a firm grasp of how things fit together so
I could be wrong.
> One of my favorite sayings is that reusing designs
> makes sense; reusing code often does not.
Yes, I think I agree. I suppose the obvious exception is libraries --
code that is designed to be reused...
What do you think about abstracting some of the Leo stuff into a
general cross-gui library?
Something along these lines:
---------
TestGuis.py
---------
import QtGui, WxGui
for gui in [WxGui, QtGui]:
app = gui.App()
frame = gui.Frame()
frame.show()
def show_dialog():
gui.Dialog(frame).show()
timer = gui.create_timer(show_dialog, ms=1000, one_shot=True)
app.launch()
---------
WxGui.py
---------
import wx
class App(wx.App):
def launch(self):
self.MainLoop()
class Frame(wx.Frame):
def __init__(self, parent=None, width=600, height=600):
wx.Frame.__init__(self, parent=parent, size=(width, height))
def show(self):
self.Show()
class Dialog(wx.Dialog):
def show(self):
self.ShowModal()
def create_timer(method, ms=100, one_shot=False):
class Timer(wx.EvtHandler):
""" The extending class should have an on_timer method. """
def __init__(self, ms=100, one_shot=False):
""" ms is short for milliseconds """
wx.EvtHandler.__init__(self)
self.Bind(wx.EVT_TIMER, self.on_timer)
self.timer = wx.Timer(self)
self.timer.Start(ms, one_shot)
def on_timer(self, e):
method()
return Timer(ms, one_shot)
-------
QtGui.py
-------
import sys
from PyQt4.Qt import *
class App(QApplication):
def __init__(self):
QApplication.__init__(self, sys.argv)
def launch(self):
self.exec_()
class Frame(QMainWindow):
def __init__(self, width=600, height=600):
QMainWindow.__init__(self, None)
self.resize(width, height)
class Dialog(QDialog):
pass
def create_timer(method, ms=100, one_shot=False):
class Timer(QObject):
def __init__(self, ms=100, one_shot=False):
QObject.__init__(self)
self.one_shot = one_shot
timer = QTimer(self)
timer.setSingleShot(one_shot)
self.connect(timer, SIGNAL("timeout()"), self.on_timer)
timer.start(ms)
def on_timer(self):
method()
return Timer(ms, one_shot)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/leo-editor?hl=en
-~----------~----~----~----~------~----~------~--~---