mirror of
git://git.psyced.org/git/pypsyc
synced 2024-08-15 03:20:04 +00:00
last state we had in cvs
This commit is contained in:
commit
0f02e9cd76
128 changed files with 9224 additions and 0 deletions
29
GUI/Abstract/Gui.py
Normal file
29
GUI/Abstract/Gui.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
"""Abstract Gui Module - serves as interface reference"""
|
||||
import sys
|
||||
|
||||
class UserGui:
|
||||
def __init__(self):
|
||||
if self.__class__ == UserGui:
|
||||
raise "class UserGui is abstract!"
|
||||
def set_model(self, model): self.model = model
|
||||
|
||||
|
||||
class RoomGui:
|
||||
def __init___(self):
|
||||
if self.__class__ == RoomGui:
|
||||
raise "class RoomGui is abstract!"
|
||||
def set_model(self, model): self.model = model
|
||||
|
||||
|
||||
class MainGui:
|
||||
def __init__(self, argv):
|
||||
if self.__class__ == MainGui:
|
||||
raise "class MainGui is abstract!"
|
||||
self.center = None
|
||||
def run(self):
|
||||
pass
|
||||
def quit(self):
|
||||
self.center.quit()
|
||||
sys.exit(0)
|
||||
def connect(self):
|
||||
pass
|
BIN
GUI/Abstract/Gui.pyc
Normal file
BIN
GUI/Abstract/Gui.pyc
Normal file
Binary file not shown.
1
GUI/Abstract/__init__.py
Normal file
1
GUI/Abstract/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
# different user interfaces for pyPSYC
|
BIN
GUI/Abstract/__init__.pyc
Normal file
BIN
GUI/Abstract/__init__.pyc
Normal file
Binary file not shown.
448
GUI/Tkinter/Gui.py
Normal file
448
GUI/Tkinter/Gui.py
Normal file
|
@ -0,0 +1,448 @@
|
|||
import GUI.Abstract.Gui as AbstractGui
|
||||
import Tkinter, asyncore, sys
|
||||
|
||||
from pypsyc.PSYC.PSYCRoom import PSYCPackage
|
||||
class FriendList(Tkinter.Listbox):
|
||||
def __init__(self):
|
||||
self.packagename = "Friends gui"
|
||||
|
||||
root = Tkinter.Toplevel(height=480, width=150)
|
||||
root.title("friends online:")
|
||||
|
||||
self.mapping = {}
|
||||
self.model = None
|
||||
|
||||
Tkinter.Listbox.__init__(self, root)
|
||||
self.grid(row = 0, column = 0, sticky=Tkinter.E + Tkinter.W + Tkinter.N + Tkinter.S)
|
||||
|
||||
self.bind("<Double-Button-1>", self.on_leftclick)
|
||||
self.bind("<Double-Button-3>", self.on_rightclick)
|
||||
|
||||
bframe = Tkinter.Frame(root)
|
||||
bframe.grid(row=1, column = 0, sticky = Tkinter.W + Tkinter.E)
|
||||
self.linklabel = Tkinter.Label(bframe, text="unlinked")
|
||||
self.linklabel.grid(row=0, column = 0, sticky = Tkinter.W)
|
||||
#u = Tkinter.Button(bframe, text="update", command=self.update_friends)
|
||||
#u.grid(row=0, column = 1, sticky=Tkinter.E)
|
||||
|
||||
def set_model(self, model): self.model = model
|
||||
|
||||
def set_status(self, status):
|
||||
if status == "_notice_link":
|
||||
self.linklabel["text"] = "link"
|
||||
elif status == "_notice_unlink":
|
||||
self.linklabel["text"] = "unlink"
|
||||
|
||||
def on_leftclick(self, event):
|
||||
if self.selection_get():
|
||||
self.model.set_target(self.selection_get())
|
||||
self.model.set_mc("_internal_message_private_window_popup")
|
||||
self.model.castmsg()
|
||||
|
||||
def on_rightclick(self, event):
|
||||
if self.selection_get():
|
||||
#print "we should pop up a context menu for", self.selection_get()
|
||||
self.model.set_target(self.selection_get())
|
||||
self.model.set_mc("_request_examine")
|
||||
self.model.send()
|
||||
def received(self, source, mc, mmp, psyc):
|
||||
# das print-zeugs is doch nicht ganz so nutzlos!
|
||||
# muss es aber werden, oder?
|
||||
if mc == "_notice_friend_present":
|
||||
self.present(mmp.get_source())
|
||||
elif mc == "_notice_friend_absent":
|
||||
self.absent(mmp.get_source())
|
||||
elif mc == "_print_notice_friend_present":
|
||||
#print "friend present", psyc._query("_friends")
|
||||
pass
|
||||
elif mc == "_print_notice_friend_absent":
|
||||
#print "friend absent", psyc._query("_friends")
|
||||
pass
|
||||
elif mc == "_print_list_friends_present":
|
||||
#print "friends present", psyc._query("_friends")
|
||||
#print psyc.get_text()
|
||||
for friend in psyc._query("_friends").split(" "):
|
||||
print friend
|
||||
print "friends:", psyc.get_text()
|
||||
elif mc == "_notice_link" or mc == "_notice_unlink":
|
||||
self.set_status(mc)
|
||||
|
||||
def present(self, nick):
|
||||
if not self.mapping.has_key(nick):
|
||||
self.mapping[nick] = self.size() # where we insert it
|
||||
self.insert(self.size(), nick)
|
||||
|
||||
def absent(self, nick):
|
||||
if self.mapping.has_key(nick):
|
||||
self.delete(self.mapping[nick])
|
||||
|
||||
|
||||
from pypsyc.PSYC import parsetext, get_user
|
||||
class UserGui(AbstractGui.UserGui):
|
||||
def __init__(self):
|
||||
AbstractGui.UserGui.__init__(self)
|
||||
self.model = None
|
||||
self.windows = {}
|
||||
|
||||
def makewindow(self, source):
|
||||
# better check it again...
|
||||
if self.windows.has_key(source):
|
||||
return
|
||||
|
||||
win = Tkinter.Toplevel()
|
||||
win.title("Dialog with " + source)
|
||||
win.protocol("WM_DELETE_WINDOW", lambda: self.deletewindow(source))
|
||||
dframe = Tkinter.Frame(win)
|
||||
displayfield = Tkinter.Text(dframe, width=50, height=15,
|
||||
state=Tkinter.DISABLED,
|
||||
wrap=Tkinter.WORD)
|
||||
displayfield.grid(row=0, column=0)
|
||||
scrollbar = Tkinter.Scrollbar(dframe,
|
||||
command=displayfield.yview)
|
||||
scrollbar.grid(row=0, column=1, sticky = Tkinter.N + Tkinter.S)
|
||||
displayfield.config(yscrollcommand=scrollbar.set)
|
||||
dframe.pack()
|
||||
|
||||
entryfield = Tkinter.Text(win, width=54, height=5)
|
||||
entryfield.pack()
|
||||
frame = Tkinter.Frame(win)
|
||||
entrybutton = Tkinter.Button(frame, text="send",
|
||||
command=lambda: self.say(source))
|
||||
|
||||
entrybutton.grid(row = 0, column = 0)
|
||||
frame.pack()
|
||||
self.windows[source] = {"window" : win,
|
||||
"displayfield" : displayfield,
|
||||
"entryfield" : entryfield,
|
||||
"button" : entrybutton}
|
||||
|
||||
def deletewindow(self, source):
|
||||
self.windows[source]["window"].destroy()
|
||||
del self.windows[source]
|
||||
|
||||
def append_text(self, displayfield, text, encoding="iso-8859-1"):
|
||||
displayfield["state"] = Tkinter.NORMAL
|
||||
displayfield.insert(Tkinter.END,
|
||||
text.strip().decode(encoding) + '\n')
|
||||
displayfield["state"] = Tkinter.DISABLED
|
||||
displayfield.yview(Tkinter.END)
|
||||
|
||||
def get_input(self, entryfield, encoding="iso-8859-1"):
|
||||
text = entryfield.get(0.0, Tkinter.END).encode(encoding)
|
||||
entryfield.delete(0.0, Tkinter.END)
|
||||
return text
|
||||
|
||||
def say(self, source):
|
||||
self.model.set_target(source)
|
||||
self.model.set_mc("_message_private")
|
||||
|
||||
self.model.psyc._assign("_nick", get_user(self.model.center.ME()))
|
||||
|
||||
text = self.get_input(self.windows[source]["entryfield"])
|
||||
self.model.set_text(text.strip())
|
||||
|
||||
self.append_text(self.windows[source]["displayfield"], "Du sagst: " + text)
|
||||
self.model.send()
|
||||
|
||||
def received(self, source, mc, mmp, psyc):
|
||||
if mc == "_message_private":
|
||||
source = mmp.get_source()
|
||||
if not self.windows.has_key(source):
|
||||
self.makewindow(source)
|
||||
self.append_text(self.windows[source]["displayfield"],
|
||||
get_user(source)+":"+parsetext(mmp, psyc))
|
||||
elif mc == "_internal_message_private_window_popup":
|
||||
target = mmp._query("_target")
|
||||
print "target:", target
|
||||
if not self.windows.has_key(target):
|
||||
self.makewindow(target)
|
||||
|
||||
|
||||
from pypsyc.PSYC import parsetext
|
||||
class RoomGui(AbstractGui.RoomGui, Tkinter.Toplevel):
|
||||
def __init__(self):
|
||||
Tkinter.Toplevel.__init__(self)
|
||||
self.model = None
|
||||
|
||||
self.buffers = {}
|
||||
self.topics = {}
|
||||
|
||||
## self.menu = Tkinter.Menu(self)
|
||||
## self.config(menu=self.menu)
|
||||
|
||||
## options = Tkinter.Menu(self.menu)
|
||||
## options.add_command(label="show nicklist",
|
||||
## command=self.show_nicklist)
|
||||
## options.add_command(label="hide nicklist",
|
||||
## command=self.hide_nicklist)
|
||||
## self.menu.add_cascade(label ="Options", menu=options)
|
||||
|
||||
self.topiclabel = Tkinter.Label(self, text="dummy topic")
|
||||
|
||||
mainframe = Tkinter.Frame(self)
|
||||
|
||||
self.textfield = Tkinter.Text(mainframe,
|
||||
wrap=Tkinter.WORD)
|
||||
self.textfield.config(state=Tkinter.DISABLED)
|
||||
self.textfield.grid(row=0, column=0,
|
||||
sticky=Tkinter.W + Tkinter.N + Tkinter.S)
|
||||
|
||||
scrollbar = Tkinter.Scrollbar(mainframe,
|
||||
command = self.textfield.yview)
|
||||
scrollbar.grid(row=0, column=1, sticky = Tkinter.N + Tkinter.S)
|
||||
|
||||
self.textfield.config(yscrollcommand=scrollbar.set)
|
||||
|
||||
self.nicklist = Tkinter.Listbox(mainframe)
|
||||
|
||||
entryframe = Tkinter.Frame(self)
|
||||
self.entryfield = Tkinter.Entry(entryframe)
|
||||
self.entryfield.grid(sticky = Tkinter.E + Tkinter.W)
|
||||
|
||||
self.bleiste = Tkinter.Frame(self)
|
||||
self.placebuttons = {}
|
||||
|
||||
l = Tkinter.Label(self.bleiste,
|
||||
text="|")
|
||||
l.grid(row = 0, column = 0, sticky = Tkinter.W)
|
||||
|
||||
self.topiclabel.grid(row=0, sticky = Tkinter.W)
|
||||
mainframe.grid(row=1, sticky = Tkinter.W)
|
||||
entryframe.grid(row=2, sticky = Tkinter.W)
|
||||
self.bleiste.grid(row=3, sticky = Tkinter.W)
|
||||
|
||||
self.bind("<Return>", self.say)
|
||||
|
||||
def append_text(self, text, encoding="iso-8859-1"):
|
||||
self.textfield["state"] = Tkinter.NORMAL
|
||||
self.textfield.insert(Tkinter.END,
|
||||
text.decode(encoding) + '\n')
|
||||
self.textfield["state"] = Tkinter.DISABLED
|
||||
self.textfield.yview(Tkinter.END)
|
||||
|
||||
def received(self, source, mc, mmp, psyc):
|
||||
## evil
|
||||
try:
|
||||
context = mmp._query("_context").lower()
|
||||
## print context
|
||||
if mc.startswith("_notice_place_enter"):
|
||||
## if _source == ME eigentlich...
|
||||
if not self.placebuttons.has_key(context):
|
||||
self.add_room(context)
|
||||
if not self.buffers.has_key(context):
|
||||
self.buffers[context] = ""
|
||||
self.buffers[context] += parsetext(mmp, psyc) + '\n'
|
||||
if self.model.get_context() == context:
|
||||
self.append_text(parsetext(mmp, psyc))
|
||||
elif mc.startswith("_notice_place_leave"):
|
||||
self.buffers[context] += parsetext(mmp, psyc) + '\n'
|
||||
if self.model.get_context() == context:
|
||||
self.append_text(parsetext(mmp, psyc))
|
||||
elif mc == '_message_public':
|
||||
text = psyc._query("_nick")
|
||||
if psyc._query("_action") != "":
|
||||
text += " " + psyc._query("_action")
|
||||
text += ": " + parsetext(mmp, psyc)
|
||||
if self.model.get_context() == context:
|
||||
self.append_text(text)
|
||||
self.buffers[context] += text + '\n'
|
||||
elif mc == "_status_place_topic":
|
||||
self.topics[mmp.get_source().lower()] = parsetext(mmp, psyc)
|
||||
## evil
|
||||
except KeyError:
|
||||
print "KeyError:", context
|
||||
|
||||
def get_input(self, encoding="iso-8859-1"):
|
||||
text = self.entryfield.get().encode(encoding)
|
||||
self.entryfield.delete(0, Tkinter.END)
|
||||
return text
|
||||
|
||||
def say(self, event):
|
||||
text = self.get_input()
|
||||
if text and text[0] == '/':
|
||||
# we have a command
|
||||
# if we know the command, we set the appropiate mc
|
||||
# else we do _request_execute
|
||||
if text.startswith("/join") and text.__len__() > 16:
|
||||
# 16 == len(/join psyc://h/@r)
|
||||
self.model.set_mc("_request_enter")
|
||||
self.model.set_target(text.split(" ")[1])
|
||||
self.model.send()
|
||||
elif text.startswith("/part"):
|
||||
# wie waers mit /part_logout, part_home, part_type, ...
|
||||
self.model.set_mc("_request_leave")
|
||||
self.model.set_target(self.model.get_context())
|
||||
self.model.send()
|
||||
|
||||
elif text.startswith("/quit"):
|
||||
self.model.set_mc("_request_execute")
|
||||
self.model.set_target(self.model.center.ME())
|
||||
self.model.set_text("/quit")
|
||||
self.model.send()
|
||||
elif text.startswith("/connect"):
|
||||
foo = len(text.split(" "))
|
||||
if foo == 2:
|
||||
self.model.center.connect(text.split(" ")[1])
|
||||
elif foo == 3:
|
||||
self.model.center.connect(text.split(" ")[1], text.split(" ")[2])
|
||||
else:
|
||||
self.model.set_target(self.model.center.ME())
|
||||
self.model.set_mc("_request_execute")
|
||||
self.model.set_text(text)
|
||||
self.model.send()
|
||||
elif text and text[0] == "#":
|
||||
self.model.set_target(self.model.center.ME())
|
||||
self.model.set_mc("_request_execute")
|
||||
self.model.set_text("/" + text[1:])
|
||||
self.model.send()
|
||||
elif text and text[0] == "!":
|
||||
self.model.set_target(self.model.get_context())
|
||||
self.model.set_mc("_request_execute")
|
||||
self.model.set_text(text)
|
||||
self.model.send()
|
||||
elif text:
|
||||
## print "msg to", self.model.get_context()
|
||||
self.model.set_target(self.model.get_context())
|
||||
self.model.set_mc("_message_public")
|
||||
self.model.set_text(text)
|
||||
self.model.send()
|
||||
|
||||
def get_topic(self, context = None):
|
||||
if not context: context = self.model.get_context()
|
||||
if self.topics.has_key(context):
|
||||
return self.topics[context]
|
||||
else: return ""
|
||||
|
||||
def change_room(self, room):
|
||||
# gucken ob wir nicklist hatten, u.u. loeschen
|
||||
|
||||
# dieses ding sollte eigentlich ne eigene Klasse haben...
|
||||
a = self.model.get_context()
|
||||
if a and self.placebuttons.has_key(a):
|
||||
self.placebuttons[a]["relief"] = Tkinter.RAISED
|
||||
self.placebuttons[room]["relief"] = Tkinter.SUNKEN
|
||||
self.model.set_context(room)
|
||||
self.title("on " + room)
|
||||
short = room[room.rfind("@"):] # kurzform fuer raum... nicht ideal?
|
||||
self.topiclabel["text"] = short + ":" + self.get_topic()
|
||||
|
||||
self.textfield.config(state=Tkinter.NORMAL)
|
||||
self.textfield.delete(1.0, Tkinter.END)
|
||||
self.textfield.insert(Tkinter.END, self.buffers[room])
|
||||
self.textfield.config(state=Tkinter.DISABLED)
|
||||
self.textfield.yview(Tkinter.END)
|
||||
|
||||
def add_room(self, room):
|
||||
short = room[room.rfind("@"):]
|
||||
button = Tkinter.Button(self.bleiste, text=short,
|
||||
command=lambda: self.change_room(room))
|
||||
self.placebuttons[room] = button
|
||||
button.grid(row=0, column = len(self.placebuttons) - 1,
|
||||
sticky = Tkinter.W)
|
||||
|
||||
def delete_room(self, roomname):
|
||||
# delete the button?
|
||||
pass
|
||||
|
||||
## def hide_nicklist(self):
|
||||
## self.nicklist.grid_forget()
|
||||
|
||||
## def show_nicklist(self):
|
||||
## self.nicklist.grid(row=0, column=2,
|
||||
## sticky = Tkinter.E + Tkinter.N + Tkinter.S)
|
||||
|
||||
|
||||
|
||||
from pypsyc.MMP.MMPState import MMPState
|
||||
from pypsyc.PSYC.PSYCState import PSYCState
|
||||
from pypsyc.MMP import _isModifier
|
||||
class MainWindow(Tkinter.Tk):
|
||||
def __init__(self, center = None):
|
||||
Tkinter.Tk.__init__(self)
|
||||
self.center = center
|
||||
|
||||
self.title("pyPSYCgui - simple psyc client - see http://www.psyc.eu")
|
||||
|
||||
self.menu = Tkinter.Menu(self)
|
||||
self.config(menu=self.menu)
|
||||
|
||||
filemenu = Tkinter.Menu(self.menu)
|
||||
filemenu.add_command(label="Quit", command=self.quit)
|
||||
self.menu.add_cascade(label ="File", menu=filemenu)
|
||||
|
||||
connectionmenu = Tkinter.Menu(self.menu)
|
||||
connectionmenu.add_command(label="connect", command=self.connect)
|
||||
self.menu.add_cascade(label="Connections", menu=connectionmenu)
|
||||
frame = Tkinter.Frame(self)
|
||||
self.displayField = Tkinter.Text(frame, height=20, width=60, state=Tkinter.DISABLED)
|
||||
self.displayField.grid(row=0, column=0)
|
||||
scrollbar = Tkinter.Scrollbar
|
||||
scrollbar = Tkinter.Scrollbar(frame,
|
||||
command = self.displayField.yview)
|
||||
scrollbar.grid(row=0, column=1, sticky = Tkinter.N + Tkinter.S)
|
||||
self.displayField.config(yscrollcommand=scrollbar.set)
|
||||
frame.pack()
|
||||
# funzt eh net
|
||||
## self.scrollbar = Tkinter.Scrollbar(self)
|
||||
## self.scrollbar.pack(side=Tkinter.RIGHT, fill=Tkinter.Y)
|
||||
## self.scrollbar.config(command=self.displayField.yview)
|
||||
self.inputField = Tkinter.Text(self, height=5, width=60)
|
||||
self.inputField.pack()
|
||||
Tkinter.Button(self, text="send", command=self.input).pack(
|
||||
side=Tkinter.LEFT)
|
||||
|
||||
def connect(self, host = ''):
|
||||
self.center.connect(host)
|
||||
|
||||
def write(self, string):
|
||||
self.displayField.config(state=Tkinter.NORMAL)
|
||||
self.displayField.insert(Tkinter.END, string)
|
||||
self.displayField.config(state = Tkinter.DISABLED)
|
||||
|
||||
def input(self):
|
||||
## print "TkinterGui::MainWindow::input"
|
||||
cmd = self.inputField.get(1.0, Tkinter.END)
|
||||
self.inputField.delete(1.0, Tkinter.END)
|
||||
state = 'mmp'
|
||||
mmp = MMPState()
|
||||
psyc = PSYCState()
|
||||
for line in cmd.split('\n'):
|
||||
if line == ".":
|
||||
#end of packet
|
||||
break
|
||||
if line == "" or (not _isModifier(line)
|
||||
and state == 'mmp'):
|
||||
state = 'psyc'
|
||||
|
||||
if state == 'mmp':
|
||||
mmp.set_state(line)
|
||||
continue
|
||||
if state == 'psyc':
|
||||
if _isModifier(line):
|
||||
psyc.set_state(line)
|
||||
elif line.__len__() and line[0] == '_':
|
||||
psyc.set_mc(line)
|
||||
else:
|
||||
psyc.append_text(line)
|
||||
|
||||
self.center.send(mmp, psyc)
|
||||
|
||||
|
||||
class Application(AbstractGui.MainGui):
|
||||
def __init__(self, argv, center):
|
||||
AbstractGui.MainGui.__init__(self, argv)
|
||||
|
||||
self.mainWindow = MainWindow(center)
|
||||
|
||||
## nah... das is eigentlich auch evil ;)
|
||||
sys.stdout = self.mainWindow
|
||||
|
||||
def socket_check(self):
|
||||
asyncore.poll(timeout=0.0)
|
||||
# das hier is auch noch doof...
|
||||
self.mainWindow.after(100, self.socket_check)
|
||||
def run(self):
|
||||
self.socket_check()
|
||||
Tkinter.mainloop()
|
||||
|
||||
|
1
GUI/Tkinter/__init__.py
Normal file
1
GUI/Tkinter/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
# different user interfaces for pyPSYC
|
1
GUI/__init__.py
Normal file
1
GUI/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
# different user interfaces for pyPSYC
|
BIN
GUI/__init__.pyc
Normal file
BIN
GUI/__init__.pyc
Normal file
Binary file not shown.
332
GUI/wx/Gui.py
Normal file
332
GUI/wx/Gui.py
Normal file
|
@ -0,0 +1,332 @@
|
|||
# ask fippo if we need all this
|
||||
#import pypsyc.GUI.Abstract.Gui as AbstractGui
|
||||
import sys
|
||||
#from pypsyc.PSYC.PSYCRoom import PSYCPackage
|
||||
|
||||
# we need this
|
||||
from wxPython.wx import *
|
||||
from wxPython.lib.rcsizer import RowColSizer
|
||||
from wxPython.lib.grids import wxFlexGridSizer
|
||||
#from wxPython.lib.mixins.listctrl import wxColumnSorterMixin, wxListCtrlAutoWidthMixin
|
||||
# have to read about Create_Id() so we don't have to bother with the numbers
|
||||
ID_ABOUT = 1002
|
||||
ID_CONNECT = 1001
|
||||
ID_DISCONNECT = 10011
|
||||
ID_STATUS = 9901
|
||||
ID_MENU = 9902
|
||||
ID_BUDDY_LIST = 9903
|
||||
ID_BUDDY_LIST_DK = 990301
|
||||
ID_EXIT = 1099
|
||||
ID_CLOSECHATNOTEBOOK = 2099
|
||||
ID_CLOSECHATNOTE = 2098
|
||||
|
||||
|
||||
class Friend:
|
||||
""" a user object """
|
||||
def __init__(self, uni, unl='255.255.255.255'):
|
||||
self.uni = str(uni)
|
||||
self.unl = str(unl)
|
||||
self.chatting = 0
|
||||
self.tab = None
|
||||
|
||||
def chat(self, inst):
|
||||
# das hier sollte zu dem schon bestehenden fenster extrawin(was direkt beim
|
||||
# starten des cients erzeugt wird und beim connecten sichtbar wird
|
||||
# ein tab hinzufügen
|
||||
if self.chatting == 1:
|
||||
inst.notebook.Show(True)
|
||||
# focus the window where the chat is taking place
|
||||
# still a bit buggy
|
||||
# if you close a tab self.tab is wrong
|
||||
inst.notebook.SetSelection(self.tab)
|
||||
|
||||
else:
|
||||
panel = wxPanel(inst.notebook, -1)
|
||||
|
||||
button = wxButton(panel, ID_CLOSECHATNOTE, "close chat")
|
||||
button2 = wxButton(panel, ID_STATUS, "online")
|
||||
nick_box = wxTextCtrl(panel, -1, style=wxTE_READONLY)
|
||||
box = wxBoxSizer(wxHORIZONTAL)
|
||||
box.Add(nick_box, 1,wxEXPAND)
|
||||
box.Add(button2,0,wxEXPAND)
|
||||
box.Add(button,0,wxEXPAND)
|
||||
|
||||
text_box = wxTextCtrl(panel, -1, style=wxTE_MULTILINE|wxTE_READONLY)
|
||||
entry_box = wxTextCtrl(panel, -1, style=wxTE_MULTILINE, size=wxDefaultSize)
|
||||
|
||||
sizer = RowColSizer()
|
||||
#sizer.Add(button, pos=(1,1))
|
||||
#sizer.Add(nick_box, pos=(1,2), flag=wxEXPAND)
|
||||
#sizer.Add(button2, pos=(1,3))
|
||||
sizer.Add(box, pos=(1,1), colspan=3,flag=wxEXPAND)
|
||||
sizer.Add(text_box, pos=(2,1),flag=wxEXPAND, colspan=3)
|
||||
sizer.Add(entry_box, pos=(3,1),flag=wxEXPAND, colspan=2)
|
||||
sizer.AddGrowableCol(1)
|
||||
#sizer.AddGrowableCol(2)
|
||||
sizer.AddGrowableRow(2)
|
||||
panel.SetSizer(sizer)
|
||||
inst.notebook.AddPage(panel, self.uni, select=1)
|
||||
self.tab = inst.notebook.GetSelection()
|
||||
self.chatting = 1
|
||||
|
||||
def getStatus(self):
|
||||
return 'On'
|
||||
|
||||
def stop_chat(self):
|
||||
self.chatting = 0
|
||||
self.tab = None
|
||||
# do whatever has to be done
|
||||
|
||||
|
||||
|
||||
|
||||
class TabBook(wxFrame):
|
||||
""" do the actual displaying """
|
||||
def __init__(self, parent, ID, title, pos=wxDefaultPosition, size=wxDefaultSize, style=wxDEFAULT_FRAME_STYLE):
|
||||
wxFrame.__init__(self, parent, ID, title, pos, size, style)
|
||||
menu = wxMenu()
|
||||
menu.Append(ID_DISCONNECT, "&Disconnect", "bye-bye")
|
||||
menu.Append(ID_ABOUT, "&About", "tritratrullala")
|
||||
menu.AppendSeparator()
|
||||
menu.Append(ID_EXIT, "&Exit", "leave us")
|
||||
menuBar = wxMenuBar()
|
||||
menuBar.Append(menu, "&File");
|
||||
self.SetMenuBar(menuBar)
|
||||
self.notebook = wxNotebook(self, -1)
|
||||
|
||||
status_panel = wxPanel(self.notebook, -1)
|
||||
button = wxButton(status_panel, ID_CLOSECHATNOTEBOOK, "close status win")
|
||||
self.notebook.AddPage(status_panel, 'status')
|
||||
|
||||
# event handling
|
||||
EVT_BUTTON(self, ID_CLOSECHATNOTEBOOK, self.OnCloseMe)
|
||||
#EVT_BUTTON(self, ID_CLOSECHATNOTE, self.OnCloseChat)
|
||||
EVT_CLOSE(self, self.OnCloseWindow)
|
||||
|
||||
def newChat(self, who):
|
||||
#todo: check if there is already a 'chat' with that who, make a nice panel, nicklist option?
|
||||
panel = wxPanel(self.notebook, -1)
|
||||
button = wxButton(panel, ID_CLOSECHATNOTE, "close chat")
|
||||
self.notebook.AddPage(panel, who, select =1)
|
||||
|
||||
# event methods
|
||||
def OnCloseChat(self, event):
|
||||
where = self.notebook.GetSelection()
|
||||
t = self.notebook.GetPageText(where)
|
||||
self.notebook.DeletePage(where)
|
||||
self.notebook.Show(True)
|
||||
event.Skip()
|
||||
return t
|
||||
|
||||
def OnCloseMe(self, event):
|
||||
self.Show(False)
|
||||
#self.Close(true)
|
||||
event.Skip()
|
||||
|
||||
def OnCloseWindow(self, event):
|
||||
self.Show(False)
|
||||
#self.Destroy()
|
||||
event.Skip()
|
||||
|
||||
|
||||
|
||||
|
||||
class UserGui(wxFrame):
|
||||
""" handle the "querys" / chats with a single user """
|
||||
def __init__(self, parent, ID, title, pos=wxDefaultPosition, size=wxDefaultSize, style=wxDEFAULT_FRAME_STYLE):
|
||||
wxFrame.__init__(self, parent, ID, title, pos, size, style)
|
||||
menu = wxMenu()
|
||||
menu.Append(ID_DISCONNECT, "&Disconnect", "bye-bye")
|
||||
menu.Append(ID_ABOUT, "&About", "tritratrullala")
|
||||
menu.AppendSeparator()
|
||||
menu.Append(ID_EXIT, "&Exit", "leave us")
|
||||
menuBar = wxMenuBar()
|
||||
menuBar.Append(menu, "&File");
|
||||
self.SetMenuBar(menuBar)
|
||||
self.notebook = wxNotebook(self, -1)
|
||||
|
||||
status_panel = wxPanel(self.notebook, -1)
|
||||
button = wxButton(status_panel, ID_CLOSECHATNOTEBOOK, "close status win")
|
||||
self.notebook.AddPage(status_panel, 'status')
|
||||
|
||||
# event handling
|
||||
EVT_BUTTON(self, ID_CLOSECHATNOTEBOOK, self.OnCloseMe)
|
||||
#EVT_BUTTON(self, ID_CLOSECHATNOTE, self.OnCloseChat)
|
||||
EVT_CLOSE(self, self.OnCloseWindow)
|
||||
|
||||
def newChat(self, who):
|
||||
#todo: check if there is already a 'chat' with that who, make a nice panel, nicklist option?
|
||||
panel = wxPanel(self.notebook, -1)
|
||||
button = wxButton(panel, ID_CLOSECHATNOTE, "close chat")
|
||||
self.notebook.AddPage(panel, who, select =1)
|
||||
|
||||
# event methods
|
||||
def OnCloseChat(self, event):
|
||||
where = self.notebook.GetSelection()
|
||||
t = self.notebook.GetPageText(where)
|
||||
self.notebook.DeletePage(where)
|
||||
self.notebook.Show(True)
|
||||
event.Skip()
|
||||
return t
|
||||
|
||||
def OnCloseMe(self, event):
|
||||
self.Show(False)
|
||||
#self.Close(true)
|
||||
event.Skip()
|
||||
|
||||
def OnCloseWindow(self, event):
|
||||
self.Show(False)
|
||||
#self.Destroy()
|
||||
event.Skip()
|
||||
|
||||
|
||||
class FriendList(wxFrame):
|
||||
""" buddy list and other stuff """
|
||||
def __init__(self, parent, ID, title, pos=wxDefaultPosition, size=wxSize(190, 400), style=wxDEFAULT_FRAME_STYLE):
|
||||
wxFrame.__init__(self, parent, ID, title, pos , size, style)
|
||||
|
||||
# menubar, statusbar et al
|
||||
self.CreateStatusBar()
|
||||
self.SetStatusText("welcome to pyPSYC")
|
||||
menu = wxMenu()
|
||||
menu.Append(ID_CONNECT, "&Connect", "connect to the net")
|
||||
menu.Append(ID_ABOUT, "&About", "tritratrullala")
|
||||
menu.AppendSeparator()
|
||||
menu.Append(ID_EXIT, "&Exit", "leave us")
|
||||
menuBar = wxMenuBar()
|
||||
menuBar.Append(menu, "&File");
|
||||
self.SetMenuBar(menuBar)
|
||||
|
||||
|
||||
##'buddy' list, perhaps ;]]
|
||||
self.SampleList= []
|
||||
self.buddylist_dict ={}
|
||||
#self.BuddyList = wxListBox(self , ID_BUDDY_LIST,style=wxLB_NEEDED_SB|wxLB_SINGLE, choices=self.SampleList)
|
||||
self.BuddyList = wxListCtrl(self, ID_BUDDY_LIST, style=wxLC_REPORT|wxLC_SINGLE_SEL|wxSUNKEN_BORDER)
|
||||
self.BuddyList.InsertColumn(0, "ST")
|
||||
self.BuddyList.InsertColumn(1, "Nick")# , wxLIST_FORMAT_RIGHT)
|
||||
self.BuddyList.SetColumnWidth(0, 20)
|
||||
##end buddy list
|
||||
|
||||
# define the buttons and so on at the bottom of the window
|
||||
self.status = wxComboBox(self, ID_STATUS, "", choices=["", "This", "is a", "Place", "to put commands"], size=(150,-1), style=wxCB_DROPDOWN)
|
||||
self.menu_button = wxButton( self, ID_MENU, 'pyPSYC')
|
||||
self.exit_button = wxButton( self, ID_EXIT, 'exit')
|
||||
self.con_menu = wxBoxSizer(wxHORIZONTAL)
|
||||
self.con_menu.Add(self.menu_button, 1, wxALIGN_BOTTOM)
|
||||
self.con_menu.Add(self.exit_button, 1, wxALIGN_BOTTOM)
|
||||
|
||||
sizer = wxFlexGridSizer(3, 0 , 0,0)
|
||||
sizer.Add(self.BuddyList, 1, wxGROW)
|
||||
sizer.Add(self.con_menu, 1,wxGROW)
|
||||
sizer.Add(self.status, 1,wxGROW)
|
||||
sizer.AddGrowableRow(0)
|
||||
sizer.AddGrowableCol(0)
|
||||
# do somethign so that the buttons don't vanish in a too small window
|
||||
# this is h4x0r-style but does the job at the moment
|
||||
sizer.SetItemMinSize(self.BuddyList, 30, 10)
|
||||
sizer.SetMinSize(wxSize(200,280))
|
||||
self.SetSizer(sizer)
|
||||
self.SetAutoLayout(true)
|
||||
##dunno where to put it at the moment,but believe it shouldn't be here
|
||||
# wir machen uns ne instanz von dem fenster wo alle chats rein kommen sollen
|
||||
self.extrawin = TabBook(self, -1, "blah blubb", size=(800, 400), style = wxDEFAULT_FRAME_STYLE)
|
||||
# für buddy auswahl
|
||||
self.currentBuddy = 0
|
||||
|
||||
# event handling
|
||||
EVT_BUTTON( self, ID_EXIT, self.onExit )
|
||||
EVT_BUTTON(self, ID_CONNECT, self.doConnect)
|
||||
EVT_BUTTON(self, ID_CLOSECHATNOTE, self.closeChat)
|
||||
EVT_MENU( self, ID_EXIT, self.onExit)
|
||||
EVT_MENU(self, ID_CONNECT, self.doConnect)
|
||||
##EVT_LEFT_DCLICK(self.BuddyList, self.onFriend)
|
||||
EVT_LIST_ITEM_SELECTED(self, ID_BUDDY_LIST, self.OnBuddySelected)
|
||||
# ect_activated muß weg sosnt wird zweimal nen chat geöffnet ;]]
|
||||
EVT_LIST_ITEM_ACTIVATED(self, ID_BUDDY_LIST, self.onFriend)
|
||||
|
||||
def PopulateBuddyList(self):
|
||||
items = self.buddylist_dict.items()
|
||||
for x in range(len(items)):
|
||||
nick, obj = items[x]
|
||||
self.BuddyList.InsertStringItem(x ,obj.getStatus())
|
||||
self.BuddyList.SetStringItem(x, 1,str(nick))
|
||||
|
||||
self.BuddyList.SetColumnWidth(0, wxLIST_AUTOSIZE)
|
||||
self.BuddyList.SetColumnWidth(1, wxLIST_AUTOSIZE)
|
||||
|
||||
def getColumnText(self, index, col):
|
||||
item = self.BuddyList.GetItem(index, col)
|
||||
return item.GetText()
|
||||
|
||||
|
||||
def onExit(self, event):
|
||||
"""do magic stuff before closing"""
|
||||
#disconnect() oder sowas
|
||||
self.Close(TRUE)
|
||||
|
||||
def doConnect(self , event):
|
||||
#todo: all the socket stuff, way to much
|
||||
"""do even more fippo(psyc-proto) magic"""
|
||||
# this list is created by some network magic
|
||||
self.current_buddys = ['tim', 'tom', 'foo', 'neo', 'fippo', 'garrit', 'marder', 'troete', 'bar', '23', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen']
|
||||
|
||||
for user in self.current_buddys:
|
||||
tt = Friend(user)
|
||||
self.buddylist_dict[user] = tt
|
||||
|
||||
#print self.buddylist_dict
|
||||
#print '----\n'
|
||||
##self.extrawin = TabBook(self, -1, "blah blubb", size=(800, 400), style = wxDEFAULT_FRAME_STYLE)
|
||||
##self.otherWin = self.extrawin
|
||||
self.PopulateBuddyList()
|
||||
event.Skip()
|
||||
|
||||
def OnBuddySelected(self, event):
|
||||
self.currentBuddy = event.m_itemIndex
|
||||
#print str(self.currentBuddy) +'--'
|
||||
|
||||
def onFriend(self, event):
|
||||
#todo: catch the case that there is no extrawin(we aren't connected)
|
||||
"""open a new tab in the usergui"""
|
||||
tt = str(self.getColumnText(self.currentBuddy, 1))
|
||||
t = self.buddylist_dict[tt]
|
||||
t.chat(self.extrawin)
|
||||
self.extrawin.Show(True)
|
||||
#print self.getColumnText(self.currentBuddy, 1)
|
||||
event.Skip()
|
||||
|
||||
def closeChat(self, event):
|
||||
t = self.extrawin.OnCloseChat(event)
|
||||
buddy = self.buddylist_dict[t]
|
||||
buddy.stop_chat()
|
||||
event.Skip()
|
||||
|
||||
|
||||
class Application(wxApp):
|
||||
def OnInit(self):
|
||||
frame = FriendList(NULL, -1, "pyPSYC 0.0.0.0.0.1")
|
||||
frame.Show(true)
|
||||
self.SetTopWindow(frame)
|
||||
#self.timer = wxTimer()
|
||||
#self.timer.SetOwner(self.socket_check, 6666)
|
||||
#self.timer.Start(5000) # alle 100 ms / 5 secs
|
||||
#self.timer = wxPyTimer(self.socket_check)
|
||||
#self.timer.Start(500) # alle 500 ms
|
||||
return true
|
||||
|
||||
def run(self):
|
||||
# blah mainloop
|
||||
from twisted.internet import wxsupport, reactor
|
||||
wxsupport.install(self)
|
||||
print "running reactor..."
|
||||
reactor.run()
|
||||
|
||||
## self.MainLoop()
|
||||
|
||||
|
||||
## this has to change i guess
|
||||
#app = PsycApp(0)
|
||||
#app.MainLoop()
|
||||
|
||||
##EOF
|
1
GUI/wx/__init__.py
Normal file
1
GUI/wx/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
# different user interfaces for pyPSYC
|
BIN
GUI/wx/__init__.pyc
Normal file
BIN
GUI/wx/__init__.pyc
Normal file
Binary file not shown.
696
GUI/wx/devGui.py
Normal file
696
GUI/wx/devGui.py
Normal file
|
@ -0,0 +1,696 @@
|
|||
# be warned this is the _dev_ version of the wx gui
|
||||
# perhaps it will work, perhaps it's all borked up,
|
||||
# this is a plazground shouldn't be used on a day to
|
||||
# day basis
|
||||
import GUI.Abstract.Gui as AbstractGui
|
||||
import asyncore, sys, os
|
||||
import ConfigParser
|
||||
from string import split, rfind, strip
|
||||
|
||||
from pypsyc.PSYC.PSYCRoom import PSYCPackage
|
||||
from pypsyc.PSYC.PSYCRoom import Friends as FriendsPackage
|
||||
from pypsyc.PSYC import parsetext, get_user
|
||||
|
||||
from wxPython.wx import *
|
||||
from wxPython.stc import *
|
||||
|
||||
|
||||
from wxPython.lib.rcsizer import RowColSizer
|
||||
from wxPython.lib.grids import wxFlexGridSizer
|
||||
|
||||
VERSION = 'pyPSYC-wx 0.0.1'
|
||||
|
||||
# for linux/posix this should work
|
||||
CONFIG_FILE = os.getenv("HOME") + "/.pypsyc/wx-config"
|
||||
|
||||
# windows users should uncomment the next line and comment out the line above
|
||||
# CONFIG_FILE = 'wx-config'
|
||||
|
||||
ID_ABOUT = 1002
|
||||
ID_CONNECT = 1001
|
||||
ID_DISCONNECT = 10011
|
||||
ID_SAY = 3300
|
||||
ID_NOTEBOOK = 3301
|
||||
ID_STATUS = 9901
|
||||
ID_MENU = 9902
|
||||
ID_BUDDY_LIST = 9903
|
||||
ID_BUDDY_LIST_DK = 990301
|
||||
ID_EXIT = 1099
|
||||
ID_CLOSECHATNOTEBOOK = 2099
|
||||
ID_CLOSECHATNOTE = 2098
|
||||
|
||||
def opj(path):
|
||||
"""Convert paths to the platform-specific separator"""
|
||||
return apply(os.path.join, tuple(path.split('/')))
|
||||
|
||||
class Tab(wxPanel):
|
||||
def __init__(self, context, notebook):
|
||||
self.notebook = notebook
|
||||
wxPanel.__init__(self, self.notebook, -1)
|
||||
#panel = wxPanel(self.notebook, -1)
|
||||
button = wxButton(self, ID_CLOSECHATNOTE, "close chat")
|
||||
#button2 = wxButton(self, ID_STATUS, "NOOP")
|
||||
self.nick_box = wxTextCtrl(self, -1, style=wxTE_READONLY)
|
||||
box = wxBoxSizer(wxHORIZONTAL)
|
||||
box.Add(self.nick_box, 1,wxEXPAND)
|
||||
#box.Add(button2,0,wxEXPAND)
|
||||
box.Add(button,0,wxEXPAND)
|
||||
|
||||
#scroller = wxScrolledWindow(self, -1, size=(-1,-1))
|
||||
self.text_box = wxTextCtrl(self, -1, style=wxTE_MULTILINE|wxTE_RICH2|wxTE_READONLY|wxTE_AUTO_URL, size=wxDefaultSize)
|
||||
self.entry_box = wxTextCtrl(self, ID_SAY, style=wxTE_PROCESS_ENTER|wxTE_PROCESS_TAB, size=wxDefaultSize)
|
||||
|
||||
sizer = RowColSizer()
|
||||
sizer.Add(box, pos=(1,1), colspan=3,flag=wxEXPAND)
|
||||
sizer.Add(self.text_box, pos=(2,1),flag=wxEXPAND, colspan=3)
|
||||
#sizer.Add(scroller, pos=(2,1),flag=wxEXPAND, colspan=3)
|
||||
sizer.Add(self.entry_box, pos=(3,1),flag=wxEXPAND, colspan=2)
|
||||
sizer.AddGrowableCol(1)
|
||||
sizer.AddGrowableRow(2)
|
||||
self.SetSizer(sizer)
|
||||
|
||||
def append_text(self, text):
|
||||
#text = text.decode('iso-8859-1')
|
||||
if os.name == 'posix':
|
||||
#self.text_box.SetEditable(True)
|
||||
#ende = self.text_box.GetInsertionPoint()
|
||||
#self.text_box.ShowPosition(ende+len(text))
|
||||
self.text_box.AppendText(text)
|
||||
#self.text_box.SetInsertionPointEnd()
|
||||
#ende = self.text_box.GetInsertionPoint()
|
||||
#self.text_box.ShowPosition(ende+len(text))
|
||||
self.text_box.ScrollLines(2)
|
||||
#self.text_box.SetEditable(False)
|
||||
else:
|
||||
self.text_box.WriteText(text)
|
||||
self.text_box.ScrollLines(2)
|
||||
|
||||
def clear_entry(self):
|
||||
self.entry_box.Clear()
|
||||
self.entry_box.SetInsertionPoint(0)
|
||||
|
||||
def append_entry(self, text):
|
||||
self.entry_box.AppendText(text)
|
||||
|
||||
def set_topic(self, text):
|
||||
self.nick_box.Clear()
|
||||
self.nick_box.AppendText(text)
|
||||
|
||||
def get_text(self):
|
||||
return self.entry_box.GetValue()
|
||||
|
||||
class FriendList(wxFrame, PSYCPackage):
|
||||
def __init__(self, parent=None, ID=0, title='pyPSYC', center=None, config=None, pos=wxDefaultPosition, size=wxSize(190, 400), style=wxDEFAULT_FRAME_STYLE):
|
||||
# bei mir is friendlist, firendlist und maingui in einem
|
||||
# zumindestens sollte es das sein ob es so klappt weiss ich noch nicht
|
||||
self.global_config = config
|
||||
self.config = ConfigParser.ConfigParser()
|
||||
self.config.read(CONFIG_FILE)
|
||||
|
||||
if self.config:
|
||||
pos = split(self.config.get('gui', 'wx_friend_pos'), ',')
|
||||
size = split(self.config.get('gui', 'wx_friend_size'), ',')
|
||||
|
||||
wxFrame.__init__(self, parent, ID, title, wxPoint(int(pos[0]), int(pos[1])) , wxSize(int(size[0]), int(size[1])), style)
|
||||
PSYCPackage.__init__(self)
|
||||
self.currentBuddy = None
|
||||
self.center = center
|
||||
self.model = None
|
||||
self.packagename = "Friends gui"
|
||||
# we have to register by ourselves
|
||||
# perhaps it's not the way to do it but it works
|
||||
# no.. it's not working.. --lynX
|
||||
# self.center.register(FriendsPackage(self))
|
||||
|
||||
# menubar, statusbar et al
|
||||
self.CreateStatusBar()
|
||||
self.SetStatusText("welcome to pyPSYC")
|
||||
menu = wxMenu()
|
||||
menu.Append(ID_CONNECT, "&Connect", "connect to the net")
|
||||
menu.Append(ID_ABOUT, "&About", "tritratrullala")
|
||||
menu.AppendSeparator()
|
||||
menu.Append(ID_EXIT, "&Exit", "leave us")
|
||||
menuBar = wxMenuBar()
|
||||
menuBar.Append(menu, "&File");
|
||||
self.SetMenuBar(menuBar)
|
||||
|
||||
##'buddy' list, perhaps ;]]
|
||||
self.BuddyList = wxListCtrl(self, ID_BUDDY_LIST, style=wxLC_REPORT|wxLC_SINGLE_SEL|wxSUNKEN_BORDER)
|
||||
self.BuddyList.InsertColumn(0, "ST")
|
||||
self.BuddyList.InsertColumn(1, "Nick")# , wxLIST_FORMAT_RIGHT)
|
||||
self.BuddyList.SetColumnWidth(0, 20)
|
||||
##end buddy list
|
||||
|
||||
# define the buttons and so on at the bottom of the window
|
||||
self.status = wxComboBox(self, ID_STATUS, "", choices=["", "This", "is a", "Place", "to put commands"], size=(150,-1), style=wxCB_DROPDOWN)
|
||||
self.menu_button = wxButton( self, ID_MENU, 'pyPSYC')
|
||||
self.exit_button = wxButton( self, ID_EXIT, 'exit')
|
||||
self.con_menu = wxBoxSizer(wxHORIZONTAL)
|
||||
self.con_menu.Add(self.menu_button, 1, wxALIGN_BOTTOM)
|
||||
self.con_menu.Add(self.exit_button, 1, wxALIGN_BOTTOM)
|
||||
|
||||
sizer = wxFlexGridSizer(3, 0 , 0,0)
|
||||
sizer.Add(self.BuddyList, 1, wxGROW)
|
||||
sizer.Add(self.con_menu, 1,wxGROW)
|
||||
sizer.Add(self.status, 1,wxGROW)
|
||||
sizer.AddGrowableRow(0)
|
||||
sizer.AddGrowableCol(0)
|
||||
# do something so that the buttons don't vanish in a too small window
|
||||
# this is h4x0r-style but does the job at the moment
|
||||
sizer.SetItemMinSize(self.BuddyList, 30, 10)
|
||||
sizer.SetMinSize(wxSize(200,280))
|
||||
self.SetSizer(sizer)
|
||||
self.SetAutoLayout(true)
|
||||
|
||||
# event handling
|
||||
EVT_BUTTON( self, ID_EXIT, self.onExit )
|
||||
EVT_BUTTON( self, ID_MENU, self.doConnect )
|
||||
#EVT_BUTTON(self, ID_CONNECT, self.doConnect)
|
||||
#EVT_BUTTON(self, ID_CLOSECHATNOTE, self.closeChat)
|
||||
EVT_MENU( self, ID_EXIT, self.onExit)
|
||||
EVT_MENU(self, ID_CONNECT, self.doConnect)
|
||||
#EVT_LEFT_DCLICK(self.BuddyList, self.onFriend)
|
||||
#EVT_LIST_ITEM_SELECTED(self, ID_BUDDY_LIST, self.OnBuddySelected)
|
||||
# ect_activated muss weg sonst wird zweimal nen chat geoeffnet ;]]
|
||||
##EVT_LIST_ITEM_ACTIVATED(self, ID_BUDDY_LIST, self.onFriend)
|
||||
|
||||
def received(self, source, mc, mmp, psyc):
|
||||
# muss ueberall sein, warum weiss ich noch nicht so genau
|
||||
# .._present .._absent versteh ich also is es da;]
|
||||
if mc == "_notice_friend_present":
|
||||
self.present(mmp.get_source())
|
||||
elif mc == "_notice_friend_absent":
|
||||
self.absent(mmp.get_source())
|
||||
elif mc == "_notice_link" or mc == "_notice_unlink" or mc == "_status_linked":
|
||||
self.set_status(mc)
|
||||
|
||||
def set_model(self, model):
|
||||
self.model = model
|
||||
|
||||
def present(self, nick):
|
||||
""" do what has to be done if a friend turns up """
|
||||
# at the moment:
|
||||
pass
|
||||
#fuer das x muesste man wissen wie lang die buddy list bisher ist
|
||||
#sprich vllt doch wieder nen dict dafuer bauen or so
|
||||
#self.BuddyList.InsertStringItem(x ,'on')
|
||||
#self.BuddyList.SetStringItem(x, 1, nick)
|
||||
|
||||
def absent(self, nick):
|
||||
""" do what has to be done if a friend leaves us """
|
||||
# at the moment also:
|
||||
pass
|
||||
|
||||
def set_status(self, status):
|
||||
""" we should tell the user if the status changes """
|
||||
#print 'link status: ' + str(status)
|
||||
|
||||
def OnBuddySelected(self, event):
|
||||
self.currentBuddy = event.m_itemIndex
|
||||
event.Skip()
|
||||
|
||||
def doConnect(self, event, host = ''):
|
||||
self.center.connect(host)
|
||||
#print 'connecting...'
|
||||
event.Skip()
|
||||
|
||||
def onExit(self, event):
|
||||
""" do stuff we have to do before exiting """
|
||||
#print 'exiting...'
|
||||
pos = str(self.GetPositionTuple()[0]) + ', ' + str(self.GetPositionTuple()[1])
|
||||
size = str(self.GetSizeTuple()[0]) + ', ' + str(self.GetSizeTuple()[1])
|
||||
self.config.set('gui', 'wx_friend_pos', pos)
|
||||
self.config.set('gui', 'wx_friend_size', size)
|
||||
config_file = file(CONFIG_FILE, 'w')
|
||||
self.config.write(config_file)
|
||||
config_file.close()
|
||||
|
||||
self.model.set_mc("_request_execute")
|
||||
self.model.set_target(self.model.center.ME())
|
||||
self.model.set_text("/quit")
|
||||
self.model.send()
|
||||
self.Close(TRUE)
|
||||
#sys.exit(0)
|
||||
event.Skip()
|
||||
|
||||
class UeberGui(wxFrame):
|
||||
def __init__(self, parent=NULL, ID=-1, title='uebergui teil', status_tab = 1, pos=wxDefaultPosition, size=wxDefaultSize, style=wxDEFAULT_FRAME_STYLE):
|
||||
self.config = ConfigParser.ConfigParser()
|
||||
self.config.read(CONFIG_FILE)
|
||||
|
||||
if self.config:
|
||||
pos = split(self.config.get('gui', 'wx_room_pos'), ',')
|
||||
size = split(self.config.get('gui', 'wx_room_size'), ',')
|
||||
wxFrame.__init__(self, parent, ID, title, wxPoint(int(pos[0]), int(pos[1])) , wxSize(int(size[0]), int(size[1])), style)
|
||||
#PSYCPackage.__init__(self)
|
||||
self.notebook = wxNotebook(self, ID_NOTEBOOK)
|
||||
|
||||
self.tabs = [] # ein nummer zu context mapping
|
||||
self.querys = []
|
||||
self.buffers = {} # context : "chatter going on in this context"
|
||||
self.tab_inst = {} # context : tab instanz
|
||||
self.query_inst = {} # context : tab instanz
|
||||
self.members = {} # dictionary a la { 'PSYC' : ['fippo', 'lethe', ...]}
|
||||
|
||||
if status_tab == 1:
|
||||
self.addTab('status')
|
||||
EVT_TEXT_ENTER(self, ID_SAY, self.say)
|
||||
EVT_NOTEBOOK_PAGE_CHANGED(self, ID_NOTEBOOK, self.OnTabChange)
|
||||
EVT_CLOSE(self, self.onClose )
|
||||
EVT_TEXT(self, ID_SAY, self.EvtText)
|
||||
|
||||
def EvtText(self, event):
|
||||
#print 'EvtText: %s' % event.GetString()
|
||||
event.Skip()
|
||||
|
||||
def find_nick(self, wiesel):
|
||||
positve_members= []
|
||||
members = self.members[self.model.get_context()]
|
||||
for member in members:
|
||||
member = strip(member)
|
||||
if member.startswith(wiesel):
|
||||
positve_members.append(member)
|
||||
return positve_members
|
||||
|
||||
def EvtChar(self, event):
|
||||
#print 'EvtChar: ' + str(event.GetKeyCode())
|
||||
if event.GetKeyCode() == 9:
|
||||
# hier muessen wir nick raten und so weiter
|
||||
wiesel = self.tab_inst[self.model.get_context()].get_text()
|
||||
wiesel2 = wiesel
|
||||
wiesel = split(wiesel, ' ')
|
||||
marder = self.find_nick(wiesel[-1])
|
||||
if len(marder) > 1:
|
||||
print 't1'
|
||||
self.tab_inst[self.model.get_context()].append_text(str(marder) + '\n')
|
||||
elif len(marder) == 1:
|
||||
print 't2'
|
||||
nick = marder[0]
|
||||
text = wiesel2
|
||||
pos = - len(wiesel[-1])
|
||||
text = text[:pos] + nick
|
||||
self.tab_inst[self.model.get_context()].clear_entry()
|
||||
self.tab_inst[self.model.get_context()].append_entry(text)
|
||||
else:
|
||||
print 't3'
|
||||
else:
|
||||
# hier passen wir einfach und reset'en den coutner
|
||||
self.dep_count = 0
|
||||
event.Skip()
|
||||
|
||||
def onClose(self,event):
|
||||
print 'UeberGui.onCLose() worked'
|
||||
|
||||
def say(self, event):
|
||||
""" wird gerufen wenn jmd enter drückt """
|
||||
text = event.GetString()
|
||||
#text = text.encode('iso-8859-1')
|
||||
if text != '' and text[0] == '/':
|
||||
# we have a command
|
||||
# if we know the command, we set the appropiate mc
|
||||
# else we do _request_execute
|
||||
if text.startswith("/join") and text.__len__() > 16:
|
||||
# 16 == len(/join psyc://h/@r)
|
||||
self.model.set_mc("_request_enter")
|
||||
self.model.set_target(text.split(" ")[1])
|
||||
self.model.send()
|
||||
elif text.startswith("/part"):
|
||||
# wie waers mit /part_logout, part_home, part_type, ...
|
||||
self.model.set_mc("_request_leave")
|
||||
self.model.set_target(self.model.get_context())
|
||||
self.model.send()
|
||||
|
||||
elif text.startswith("/quit"):
|
||||
self.model.set_mc("_request_execute")
|
||||
self.model.set_target(self.model.center.ME())
|
||||
self.model.set_text("/quit")
|
||||
self.model.send()
|
||||
|
||||
elif text.startswith('/me') and text[3] == ' ':
|
||||
self.model.set_target(self.model.get_context())
|
||||
self.model.set_mc('_message_public')
|
||||
self.model.set_psycvar('_action', text[4:])
|
||||
self.model.set_text('')
|
||||
self.model.send()
|
||||
|
||||
elif text.startswith('/names'):
|
||||
self.model.set_target(self.model.get_context())
|
||||
self.model.set_mc('_request_members')
|
||||
self.model.set_text('')
|
||||
self.model.send()
|
||||
|
||||
#elif text.startswith('/lnames'):
|
||||
# context = self.model.get_context()
|
||||
# self.tab_inst[context].append_text(self.members[context][0] + '\n')
|
||||
|
||||
elif text.startswith("/connect"):
|
||||
foo = len(text.split(" "))
|
||||
if foo == 2:
|
||||
self.model.center.connect(text.split(" ")[1])
|
||||
elif foo == 3:
|
||||
self.model.center.connect(text.split(" ")[1], text.split(" ")[2])
|
||||
else:
|
||||
self.model.set_target(self.model.center.ME())
|
||||
self.model.set_mc("_request_execute")
|
||||
self.model.set_text(text)
|
||||
self.model.send()
|
||||
elif text != '' and text[0] == "#":
|
||||
self.model.set_target(self.model.center.ME())
|
||||
self.model.set_mc("_request_execute")
|
||||
self.model.set_text("/" + text[1:])
|
||||
self.model.send()
|
||||
elif text != '' and text[0] == "!":
|
||||
self.model.set_target(self.model.get_context())
|
||||
self.model.set_mc("_request_execute")
|
||||
self.model.set_text(text)
|
||||
self.model.send()
|
||||
elif text != '' and text[-1] == '?':
|
||||
self.model.set_target(self.model.get_context())
|
||||
self.model.set_mc("_message_public")
|
||||
self.model.set_text(text)
|
||||
self.model.send()
|
||||
elif text != '':
|
||||
#print "msg to", self.model.get_context()
|
||||
self.model.set_target(self.model.get_context())
|
||||
self.model.set_mc("_message_public")
|
||||
self.model.set_text(text)
|
||||
self.model.set_psycvar('_action', 'testet')
|
||||
self.model.send()
|
||||
self.tab_inst[self.model.context].clear_entry()
|
||||
event.Skip()
|
||||
|
||||
def addTab(self, title):
|
||||
panel = Tab(title, self.notebook)
|
||||
if title != 'status':
|
||||
short_title= title[rfind(title, '@'):]
|
||||
self.model.set_context(title)
|
||||
panel.append_text('heading over to ' + title + '\n')
|
||||
self.model.set_target(self.model.get_context())
|
||||
self.model.set_mc("_request_members")
|
||||
self.model.set_text('')
|
||||
self.model.send()
|
||||
|
||||
else:
|
||||
short_title = title
|
||||
self.notebook.AddPage(panel, short_title, select = 1)
|
||||
|
||||
self.tab_inst[title] = panel
|
||||
self.SetTitle(title)
|
||||
EVT_CHAR(panel.entry_box, self.EvtChar)
|
||||
|
||||
if title == 'status':
|
||||
motd = 'Welcome to ' + VERSION + '\n for Q&A go to psyc://ve.symlynx.com/@PSYC \n or contact tim@trash-media.de for GUI problems \n for all the other problems go and talk to fippo!'
|
||||
panel.append_text(motd)
|
||||
|
||||
self.tabs.append(title)
|
||||
#self.buffers[title] = ''
|
||||
|
||||
def addQuery(self, title):
|
||||
panel = Tab(title, self.notebook)
|
||||
if title != 'status':
|
||||
short_title= title[rfind(title, '~'):]
|
||||
#self.model.set_context(title)
|
||||
print dir(self.model)
|
||||
panel.append_text('talking to ' + short_title + '\n')
|
||||
#self.model.set_target(self.model.get_context())
|
||||
#self.model.set_mc("_request_members")
|
||||
#self.model.set_text('')
|
||||
#self.model.send()
|
||||
else:
|
||||
short_title = title
|
||||
self.notebook.AddPage(panel, short_title, select = 1)
|
||||
|
||||
self.query_inst[title] = panel
|
||||
self.SetTitle(title)
|
||||
if title == 'status':
|
||||
motd = 'Welcome to ' + VERSION + '\n for Q&A go to psyc://ve.symlynx.com/@PSYC \n or contact tim@trash-media.de for GUI problems \n for all the other problems go and talk to fippo!'
|
||||
panel.append_text(motd)
|
||||
|
||||
self.querys.append(title)
|
||||
self.source = self.querys[-1]
|
||||
#print (self.querys)
|
||||
#print '<<<<<<<<<<<<<<'
|
||||
#self.buffers[title] = ''
|
||||
|
||||
def OnTabChange(self, event):
|
||||
old = event.GetOldSelection()
|
||||
new = event.GetSelection()
|
||||
self.SetTitle(self.tabs[new])
|
||||
self.model.set_context(self.tabs[new])
|
||||
#if self.buffers[self.model.context] != '':
|
||||
# self.tab_inst[self.model.context].append_text(self.buffers[self.model.context])
|
||||
# self.buffers[self.model.context] = ''
|
||||
event.Skip()
|
||||
|
||||
def msg(self, text):
|
||||
""" mehr text! """
|
||||
|
||||
class UserGui(UeberGui, AbstractGui.UserGui, PSYCPackage):
|
||||
def __init__(self):
|
||||
""" das hier is fuer querys """
|
||||
PSYCPackage.__init__(self)
|
||||
UeberGui.__init__(self, status_tab = 0)
|
||||
self.model = None
|
||||
self.source = ''
|
||||
#pass
|
||||
|
||||
def say(self, event):
|
||||
text = event.GetString()
|
||||
#source self.tabs[]
|
||||
source = self.source
|
||||
self.model.set_target(source)
|
||||
self.model.set_mc("_message_private")
|
||||
self.model.psyc._assign("_nick", get_user(self.model.center.ME()))
|
||||
|
||||
#text = self.get_input(self.windows[source]["entryfield"])
|
||||
self.model.set_text(text.strip())
|
||||
#self.append_text(self.windows[source]["displayfield"], "Du sagst: " + text)
|
||||
self.model.send()
|
||||
self.query_inst[source].append_text('Du> ' + text + '\n')
|
||||
self.query_inst[source].clear_entry()
|
||||
event.Skip()
|
||||
|
||||
|
||||
def received(self, source, mc, mmp, psyc):
|
||||
context = 'status'
|
||||
if mmp._query("_source") != None:
|
||||
context = mmp._query("_source").lower()
|
||||
else:
|
||||
context = source.lower()
|
||||
|
||||
if mc == "_internal_message_private_window_popup":
|
||||
# open a new tab
|
||||
self.Show(True)
|
||||
self.addQuery('test')
|
||||
|
||||
elif mc == "_message_echo_private":
|
||||
self.Show(True)
|
||||
text = ''
|
||||
text += 'Du>'
|
||||
if context not in self.querys:
|
||||
self.addQuery(context)
|
||||
text += ' ' + parsetext(mmp, psyc)
|
||||
self.query_inst[context].append_text(text + '\n')
|
||||
|
||||
elif mc =='_message_private':
|
||||
self.Show(True)
|
||||
text = ''
|
||||
text += 'Anderer_Nick>'
|
||||
if context not in self.querys:
|
||||
self.addQuery(context)
|
||||
text += ' ' + parsetext(mmp, psyc)
|
||||
self.query_inst[context].append_text(text + '\n')
|
||||
|
||||
def set_model(self, model):
|
||||
self.model = model
|
||||
|
||||
def OnTabChange(self, event):
|
||||
old = event.GetOldSelection()
|
||||
new = event.GetSelection()
|
||||
self.SetTitle(self.querys[new])
|
||||
self.source = self.querys[new]
|
||||
#self.model.set_context(self.tabs[new])
|
||||
#if self.buffers[self.model.context] != '':
|
||||
# self.tab_inst[self.model.context].append_text(self.buffers[self.model.context])
|
||||
# self.buffers[self.model.context] = ''
|
||||
event.Skip()
|
||||
|
||||
|
||||
|
||||
class RoomGui(UeberGui, AbstractGui.RoomGui, PSYCPackage):
|
||||
def __init___(self):
|
||||
""" das hier is fuer raeume """
|
||||
PSYCPackage.__init__(self)
|
||||
UeberGui.__init__(self,pos=pos, size=size)
|
||||
self.model = None
|
||||
|
||||
EVT_CLOSE(self, self.onClose)
|
||||
|
||||
def onClose(self,event):
|
||||
#print 'RoomGui.onClose() worked'
|
||||
pos = str(self.GetPositionTuple()[0]) + ', ' + str(self.GetPositionTuple()[1])
|
||||
size = str(self.GetSizeTuple()[0]) + ', ' + str(self.GetSizeTuple()[1])
|
||||
self.config.set('gui', 'wx_room_pos', pos)
|
||||
self.config.set('gui', 'wx_room_size', size)
|
||||
config_file = file(CONFIG_FILE, 'w')
|
||||
self.config.write(config_file)
|
||||
config_file.close()
|
||||
#self.Show(False)
|
||||
event.Skip()
|
||||
|
||||
def set_model(self, model):
|
||||
self.model = model
|
||||
|
||||
def received(self, source, mc, mmp, psyc):
|
||||
context = 'status'
|
||||
if mmp._query("_context") != None:
|
||||
context = mmp._query("_context").lower()
|
||||
else:
|
||||
context = source.lower()
|
||||
#if psyc._query('_nick_place') != None:
|
||||
# context = 'psyc://ve.symlynx.com/@' + psyc._query('_nick_place').lower()
|
||||
#context = source.lower()
|
||||
if mc.startswith('_notice_place_leave'):
|
||||
if context not in self.tabs:
|
||||
self.addTab(context)
|
||||
text = parsetext(mmp, psyc)
|
||||
self.tab_inst[context].append_text(text + '\n')
|
||||
if self.members.has_key(context):
|
||||
nick = psyc._query('_nick')
|
||||
self.members[context].remove(nick)
|
||||
|
||||
if mc.startswith('_notice_place_enter'):
|
||||
self.Show(true)
|
||||
if context not in self.tabs:
|
||||
self.addTab(context)
|
||||
text = parsetext(mmp, psyc)
|
||||
self.tab_inst[context].append_text(text + '\n')
|
||||
if self.members.has_key(context):
|
||||
nick = psyc._query('_nick')
|
||||
if nick not in self.members[context]:
|
||||
self.members[context].append(nick)
|
||||
|
||||
elif mc == '_message_public_question':
|
||||
text = ''
|
||||
text += str(psyc._query("_nick"))
|
||||
if context not in self.tabs:
|
||||
self.addTab(context)
|
||||
text += ' fragt ' + parsetext(mmp, psyc)
|
||||
self.tab_inst[context].append_text(text + '\n')
|
||||
|
||||
elif mc.startswith('_status_place_topic') or mc.startswith('_notice_place_topic'):
|
||||
topic = psyc._query('_topic')
|
||||
context = source.lower()
|
||||
if context not in self.tabs:
|
||||
self.addTab(context)
|
||||
self.tab_inst[context].set_topic(topic)
|
||||
|
||||
elif mc == '_message_public':
|
||||
text = ''
|
||||
text += str(psyc._query("_nick"))
|
||||
if context not in self.tabs:
|
||||
self.addTab(context)
|
||||
if psyc._query("_action"):
|
||||
ptext = parsetext(mmp, psyc)
|
||||
if ptext == '':
|
||||
text += " " + psyc._query("_action")
|
||||
else:
|
||||
text += " " + psyc._query("_action") + '> ' + ptext
|
||||
else:
|
||||
text += "> " + parsetext(mmp, psyc)
|
||||
#text = text.encode('iso-8859-1')
|
||||
self.tab_inst[context].append_text(text + '\n')
|
||||
#print '!!' + context + ': ' + text
|
||||
|
||||
elif mc == '_status_place_members':
|
||||
text = parsetext(mmp, psyc)
|
||||
if context not in self.tabs:
|
||||
self.addTab(context)
|
||||
members = split(psyc._query('_members'), ', ')
|
||||
self.members[context] = members
|
||||
self.tab_inst[context].append_text(text + '\n')
|
||||
|
||||
else:
|
||||
# everything we don't know goes into the status tab
|
||||
# hopefully parsetext doesn't crash with' bogus' pakets
|
||||
text = source.lower() + ' >>> '
|
||||
text += parsetext(mmp, psyc)
|
||||
self.tab_inst['status'].append_text(text + '\n')
|
||||
|
||||
|
||||
|
||||
class MainWindow(PSYCPackage):
|
||||
# eigentlich brauch das kein schwein oder???
|
||||
def __init__(self, argv):
|
||||
""" was ich hiermit mache weiss ich noch net genau, eigentlich brauch
|
||||
ich es net im moment lebt es für den devel handler"""
|
||||
self.center = None
|
||||
PSYCPackage.__init__(self)
|
||||
|
||||
def title(self, text):
|
||||
pass
|
||||
|
||||
def run(self):
|
||||
pass
|
||||
|
||||
def quit(self):
|
||||
self.center.quit()
|
||||
sys.exit(0)
|
||||
|
||||
def connect(self):
|
||||
pass
|
||||
|
||||
def write(self, text):
|
||||
#print text
|
||||
pass
|
||||
|
||||
class MySplashScreen(wxSplashScreen):
|
||||
def __init__(self, argv, center, config):
|
||||
self.center = center
|
||||
self.argv = argv
|
||||
self.config = config
|
||||
bmp = wxImage(opj("GUI/wx/psych2o.jpg")).ConvertToBitmap()
|
||||
wxSplashScreen.__init__(self, bmp,
|
||||
wxSPLASH_CENTRE_ON_SCREEN|wxSPLASH_TIMEOUT,
|
||||
4000, None, -1,
|
||||
style = wxFRAME_NO_TASKBAR|wxSTAY_ON_TOP)
|
||||
EVT_CLOSE(self, self.OnClose)
|
||||
|
||||
def OnClose(self, evt):
|
||||
frame = FriendList(NULL, -1, "pyPSYC 0.0.0.0.0.1", center=self.center, config=self.config)
|
||||
frame.Show()
|
||||
evt.Skip()
|
||||
|
||||
class Application(wxApp):
|
||||
def __init__(self, argv, center, config):
|
||||
self.center = center
|
||||
self.argv = argv
|
||||
self.config = config
|
||||
wxApp.__init__(self,0)
|
||||
#print 'tt'
|
||||
|
||||
def OnInit(self):
|
||||
#self.frame = FriendList(NULL, -1, "pyPSYC 0.0.0.0.0.1", center=self.center, config=self.config)
|
||||
#self.frame.Show(true)
|
||||
#sys.stdout = self.frame
|
||||
wxInitAllImageHandlers()
|
||||
splash = MySplashScreen(self.argv, self.center, self.config)
|
||||
self.SetTopWindow(splash)
|
||||
splash.Show()
|
||||
return True
|
||||
##
|
||||
## self.timer = wxPyTimer(self.socket_check)
|
||||
## self.timer.Start(100) # alle 100 ms
|
||||
## #print 'ttt'
|
||||
##
|
||||
## def socket_check(self):
|
||||
## asyncore.poll(timeout=0.0)
|
||||
##
|
||||
def run(self):
|
||||
# blah mainloop
|
||||
#print 'tttt'
|
||||
|
||||
from twisted.internet import wxsupport, reactor
|
||||
wxsupport.install(self)
|
||||
print "running reactor..."
|
||||
reactor.run()
|
BIN
GUI/wx/devGui.pyc
Normal file
BIN
GUI/wx/devGui.pyc
Normal file
Binary file not shown.
BIN
GUI/wx/psych2o.jpg
Normal file
BIN
GUI/wx/psych2o.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 78 KiB |
7
GUI/wx/test.py
Normal file
7
GUI/wx/test.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
## some sort of testing thingie
|
||||
## damit man es sieht wies geht udn die Gui.py auch sonst importieren kann
|
||||
|
||||
import Gui
|
||||
|
||||
app = Gui.Application(0)
|
||||
app.MainLoop()
|
Loading…
Add table
Add a link
Reference in a new issue