Mac OS X - cocoaui.py
Joshua Kifer <[email protected]> Fri, 22 Oct 2004 17:56:38 -0700
| Newsgroups | gmane.comp.games.mud.client.lyntin |
|---|---|
| Message-ID | <[email protected]> |
Some explanation about the source. Since this is kind of a 'native'
app, I've reversed the way the UI object is normally used. Due to
threading issues, the UI object just stores any mud data in a
threadsafe queue, and this object is polled by the native application.
The GUI calles 'read' on cocoaui to get mud data, and calls 'write' to
send commands to lyntin.
Kudos on the way lyntin was designed. It was incredibly easy to
implement the gui, and I had to make no changes to the internal lyntin
code, which is great because lyntin can grow completely separated from
the Cocoa gui. Cool!
I'll work on getting a distribution of the Cocoa app in the next week.
You know given the rather crappy selection of Mac OS X mud clients --
having leveraged lyntin, this one is already the best.
Here's the file:
cocoaui.py
----------------
import Queue
from lyntin import exported
from lyntin.ui import base
myui = None
def get_ui_instance():
global myui
if myui == None:
myui = CocoaUI()
return myui
class CocoaUI(base.BaseUI):
def __init__(self):
base.BaseUI.__init__(self)
self.queue = Queue.Queue()
exported.hook_register("to_user_hook", self.incoming)
def wantMainThread(self):
return 1
def incoming(self, args):
self.queue.put(args['message'])
def read(self):
output = ''
try:
while 1:
output += self.queue.get(0).data
except:
pass
return output
def write(self, value):
self.handleinput(value + '\n')
-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl