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
95
mjacob/old/MMP/MMPProtocol.py
Executable file
95
mjacob/old/MMP/MMPProtocol.py
Executable file
|
@ -0,0 +1,95 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Licensed under the MIT license
|
||||
# http://opensource.org/licenses/mit-license.php
|
||||
|
||||
# <C> Copyright 2007, Manuel Jacob
|
||||
|
||||
from twisted.protocols import basic
|
||||
|
||||
|
||||
def convert_lines(lines):
|
||||
"""convert list of lines to vars, method (mc) and text"""
|
||||
_is_text = False
|
||||
dict = {}
|
||||
mc = None
|
||||
textlines = []
|
||||
for i in lines:
|
||||
tmp = i.split('\t')
|
||||
|
||||
if _is_text:
|
||||
textlines.append(i)
|
||||
|
||||
elif tmp[0] == ':': # second or later item in the list
|
||||
dict[_list].append(tmp[1])
|
||||
|
||||
elif i[0] in (':', '='):
|
||||
if tmp[0][1:6] == '_list':
|
||||
_list = tmp[0][1:]
|
||||
dict[_list] = [tmp[1]]
|
||||
else: dict[tmp[0][1:]] = tmp[1]
|
||||
|
||||
elif i[0] == '_':
|
||||
mc = i
|
||||
_is_text = True
|
||||
|
||||
text = '\n'.join(textlines)
|
||||
return dict, mc, text
|
||||
|
||||
|
||||
class MMPProtocol(basic.LineReceiver):
|
||||
def __init__(self, callback):
|
||||
self.msg = callback
|
||||
self.delimiter = '\n'
|
||||
self.initialized = False
|
||||
self.charset = 'UTF-8'
|
||||
self.reset()
|
||||
|
||||
def reset(self):
|
||||
self.lines = []
|
||||
self._reset()
|
||||
|
||||
def _reset(self):
|
||||
raise NotImplementedError('Implement in Subclass.')
|
||||
|
||||
def lineReceived(self, line):
|
||||
if not self.initialized:
|
||||
assert line == '.', 'first line is not ".", line is "%s"' % line
|
||||
self.initialized = True
|
||||
return
|
||||
|
||||
if line == '.': # packet ends
|
||||
self.recv_packet()
|
||||
else:
|
||||
self.lines.append(line)
|
||||
|
||||
def recv_packet(self):
|
||||
h2b = self.lines.index('') # head to body delimiter
|
||||
mmp = self.lines[:h2b]
|
||||
data = self.lines[h2b+1:]
|
||||
mmpvars = convert_lines(mmp)[0]
|
||||
if '_length' in mmpvars:
|
||||
bodylength = mmpvars['_length']
|
||||
else:
|
||||
bodylength = len(data)
|
||||
|
||||
if len(data) == bodylength:
|
||||
self._recv_packet(mmpvars, data)
|
||||
self.reset()
|
||||
|
||||
def _recv_packet(self, mmpvars, data):
|
||||
raise NotImplementedError('Implement in Subclass.')
|
||||
|
||||
def _send_packet(self, mmpvars, data):
|
||||
mmpstring = ''
|
||||
if mmpvars:
|
||||
for key, value in mmpvars.items():
|
||||
mmpstring += "=%s\t%s\n" % (key, value)
|
||||
|
||||
if not data:
|
||||
data = ''
|
||||
|
||||
send = "%s%s.\n" % (mmpstring, data)
|
||||
#print ('send', send.encode(self.charset))
|
||||
self.transport.write(send.encode(self.charset))
|
0
mjacob/old/MMP/__init__.py
Normal file
0
mjacob/old/MMP/__init__.py
Normal file
14
mjacob/old/PSYC/PSYCPacket.py
Executable file
14
mjacob/old/PSYC/PSYCPacket.py
Executable file
|
@ -0,0 +1,14 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
class PSYCPacket:
|
||||
def __init__(self, mmpvars = {}, psycvars = {}, mc = None, text = ''):
|
||||
self.mmpvars = mmpvars
|
||||
self.psycvars = psycvars
|
||||
self.vars = mmpvars.copy()
|
||||
self.vars.update(psycvars)
|
||||
self.mc = mc
|
||||
self.text = text
|
||||
|
||||
def __repr__(self):
|
||||
return 'vars: %s, mc: %s, text: %s' % (self.vars, self.mc, self.text)
|
98
mjacob/old/PSYC/PSYCProtocol.py
Executable file
98
mjacob/old/PSYC/PSYCProtocol.py
Executable file
|
@ -0,0 +1,98 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Licensed under the MIT license
|
||||
# http://opensource.org/licenses/mit-license.php
|
||||
|
||||
# <C> Copyright 2007, Manuel Jacob
|
||||
|
||||
|
||||
from MMP.MMPProtocol import MMPProtocol, convert_lines
|
||||
from PSYC.PSYCPacket import PSYCPacket
|
||||
|
||||
class PSYCProtocol(MMPProtocol):
|
||||
mmpvars = (
|
||||
'_source', '_source_identification', '_source_location', '_source_relay',
|
||||
'_target', '_context', '_counter', '_length', '_initialize', '_fragment',
|
||||
'_encoding', '_amount_fragments', '_list_using_modules',
|
||||
'_list_require_modules', '_list_understand_modules', '_list_using_encoding',
|
||||
'_list_require_encoding', '_list_understand_encoding',
|
||||
'_list_using_protocols', '_list_require_protocols',
|
||||
'_list_understand_protocols', '_trace', '_tag', '_tag_relay', '_relay')
|
||||
|
||||
def _reset(self):
|
||||
pass
|
||||
|
||||
def __init__(self, callback):
|
||||
MMPProtocol.__init__(self, callback)
|
||||
|
||||
def _recv_packet(self, mmpvars, data):
|
||||
#print 'recv'
|
||||
psycvars, mc, text = convert_lines(data)
|
||||
packet = PSYCPacket(mmpvars, psycvars, mc, text)
|
||||
|
||||
func = getattr(self, "handle_%s" % packet.mc[1:], None)
|
||||
|
||||
not_call_msg = False
|
||||
|
||||
if func:
|
||||
not_call_msg = func(packet)
|
||||
|
||||
if not not_call_msg:
|
||||
self.msg(packet)
|
||||
|
||||
def handle_status_circuit(self, packet):
|
||||
self._send_packet(None, None) # send an empty mmp packet (single dot)
|
||||
self.send_packet(PSYCPacket(mmpvars =
|
||||
{'_target': self.factory.config.uni}, mc = '_request_link'))
|
||||
|
||||
self.charset = packet.vars['_using_characters']
|
||||
|
||||
def send_packet(self, packet):
|
||||
self.factory.ui.outpacketcount += 1
|
||||
self.factory.ui.pre_send(packet)
|
||||
data = ''
|
||||
|
||||
if packet.psycvars:
|
||||
data += '\n'
|
||||
for key, value in packet.psycvars.items():
|
||||
data += ":%s\t%s\n" % (key, value)
|
||||
|
||||
if packet.mc:
|
||||
data += packet.mc + '\n'
|
||||
|
||||
if packet.text:
|
||||
data += packet.text + '\n'
|
||||
|
||||
self._send_packet(packet.mmpvars, data)
|
||||
|
||||
################################
|
||||
# implementation of the PSYC API
|
||||
################################
|
||||
|
||||
def msg(self, packet):
|
||||
raise NotImplementedError
|
||||
|
||||
def sendmsg(self, target, mc, data, vars):
|
||||
mmpvars = {'_target': target}
|
||||
psycvars = {}
|
||||
for key, value in vars.items():
|
||||
if i in self.mmpvars:
|
||||
mmpvars[key] = value
|
||||
else:
|
||||
psycvars[key] = value
|
||||
|
||||
packet = PSYCPacket(mmpvars, psycvars, mc, data)
|
||||
self.send_packet(packet)
|
||||
|
||||
def castmsg(self, source, mc, data, vars):
|
||||
mmpvars = {'_context': source}
|
||||
psycvars = {}
|
||||
for key, value in vars.items():
|
||||
if i in self.mmpvars:
|
||||
mmpvars[key] = value
|
||||
else:
|
||||
psycvars[key] = value
|
||||
|
||||
packet = PSYCPacket(mmpvars, psycvars, mc, data)
|
||||
self.send_packet(packet)
|
0
mjacob/old/PSYC/__init__.py
Normal file
0
mjacob/old/PSYC/__init__.py
Normal file
0
mjacob/old/UI/__init__.py
Normal file
0
mjacob/old/UI/__init__.py
Normal file
107
mjacob/old/UI/base.py
Executable file
107
mjacob/old/UI/base.py
Executable file
|
@ -0,0 +1,107 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Licensed under the MIT license
|
||||
# http://opensource.org/licenses/mit-license.php
|
||||
|
||||
# <C> Copyright 2007, Manuel Jacob
|
||||
|
||||
import re
|
||||
|
||||
from twisted.internet import reactor
|
||||
|
||||
from PSYC.PSYCPacket import PSYCPacket
|
||||
|
||||
re_var = re.compile('\[_.[^\[]+\]')
|
||||
|
||||
class BaseUI:
|
||||
ignored_mcs = []
|
||||
ignored_users = []
|
||||
mc_prefixes = ('_notice', '_error', '_info', '_status')
|
||||
inpacketcount = 0
|
||||
outpacketcount = 0
|
||||
connected = False
|
||||
|
||||
def recv(self, packet):
|
||||
self.inpacketcount += 1
|
||||
if packet.mc in self.ignored_mcs:
|
||||
return
|
||||
|
||||
#if packet.vars['_source'] in self.ignored_users:
|
||||
# return
|
||||
|
||||
self.pre_print(packet)
|
||||
self._insert_vars(packet)
|
||||
self.print_(packet)
|
||||
|
||||
def _insert_vars(self, packet):
|
||||
while True:
|
||||
x = re_var.search(packet.text)
|
||||
if not x:
|
||||
break
|
||||
tmp = x.group()
|
||||
if tmp[1:-1] in packet.vars:
|
||||
packet.text = packet.text.replace(tmp, packet.vars[tmp[1:-1]])
|
||||
|
||||
def print_(self, packet):
|
||||
func = None
|
||||
for i in self.mc_prefixes:
|
||||
if packet.mc.startswith(i):
|
||||
func = getattr(self, 'handle_%s_' % i[1:], None)
|
||||
|
||||
tmp = getattr(self, 'handle_%s' % packet.mc[1:], None)
|
||||
|
||||
if tmp:
|
||||
func = tmp
|
||||
|
||||
if func:
|
||||
func(packet)
|
||||
|
||||
else:
|
||||
self._print('Server', 'unhandled packetmc (Packet %s)'
|
||||
% self.inpacketcount)
|
||||
|
||||
def handle_notice_(self, packet):
|
||||
self._print('Server', "%s: %s" % (packet.mc, packet.text))
|
||||
|
||||
def handle_error_(self, packet):
|
||||
self._print('Server', "%s: %s" % (packet.mc, packet.text))
|
||||
|
||||
def handle_info_(self, packet):
|
||||
self._print('Server', "%s: %s" % (packet.mc, packet.text))
|
||||
|
||||
def handle_status_(self, packet):
|
||||
self._print('Server', "%s: %s" % (packet.mc, packet.text))
|
||||
|
||||
def handle_message_public(self, packet):
|
||||
self._print(packet.vars['_context'], '%s says: %s'
|
||||
% (packet.vars['_nick'], packet.text))
|
||||
|
||||
def handle_status_place_topic_official(self, packet):
|
||||
pass
|
||||
|
||||
def handle_echo_logoff(self, packet):
|
||||
reactor.stop()
|
||||
|
||||
def server_command(self, command, target):
|
||||
if target == 'Server':
|
||||
target = 'psyc://%s/' % self.factory.config.host
|
||||
|
||||
if command.startswith('/go'):
|
||||
self.factory.sc.send_packet(PSYCPacket(mmpvars = {'_target': command[4:]}, psycvars = {'_nick': self.factory.config.username}, mc = '_request_enter'))
|
||||
|
||||
elif command.startswith('/join'):
|
||||
self.factory.sc.send_packet(PSYCPacket(mmpvars = {'_target': command[6:]}, psycvars = {'_nick': self.factory.config.username}, mc = '_request_enter'))
|
||||
|
||||
elif command.startswith('/quit'):
|
||||
self.factory.sc.send_packet(PSYCPacket(mmpvars = {'_target': self.factory.config.uni, '_source_identification': self.factory.config.uni}, mc = '_request_execute', text = 'bye'))
|
||||
|
||||
|
||||
else:
|
||||
self.factory.sc.send_packet(PSYCPacket(mmpvars = {'_target': self.factory.config.uni, '_source_identification': self.factory.config.uni}, mc = '_request_input', text = command))
|
||||
|
||||
#if command.startswith('/quit'):
|
||||
# reactor.stop()
|
||||
|
||||
#if command.startwith('/part'):
|
||||
# self.factory.sc.send_packet(PSYCPacket())
|
18
mjacob/old/UI/text/Interface.py
Executable file
18
mjacob/old/UI/text/Interface.py
Executable file
|
@ -0,0 +1,18 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Licensed under the MIT license
|
||||
# http://opensource.org/licenses/mit-license.php
|
||||
|
||||
# <C> Copyright 2007, Manuel Jacob
|
||||
|
||||
from UI import base
|
||||
|
||||
class Interface(base.BaseUI):
|
||||
def __init__(self, factory):
|
||||
self.factory = factory
|
||||
self.factory.connect()
|
||||
#BaseUI.__init__(self)
|
||||
|
||||
def _print(self, window, text):
|
||||
print '%s: %s' % (window, text)
|
0
mjacob/old/UI/text/__init__.py
Normal file
0
mjacob/old/UI/text/__init__.py
Normal file
366
mjacob/old/UI/wx/Interface.py
Executable file
366
mjacob/old/UI/wx/Interface.py
Executable file
|
@ -0,0 +1,366 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Licensed under the MIT license
|
||||
# http://opensource.org/licenses/mit-license.php
|
||||
|
||||
# <C> Copyright 2007, Manuel Jacob
|
||||
|
||||
import wx
|
||||
|
||||
from twisted.internet import reactor
|
||||
|
||||
from UI import base
|
||||
from PSYC.PSYCPacket import PSYCPacket
|
||||
|
||||
class Tab(wx.Panel):
|
||||
def __init__(self, parent, name):
|
||||
self.name = name
|
||||
wx.Panel.__init__(self, parent, -1)
|
||||
self.textctrl = wx.TextCtrl(self, -1, style = wx.TE_MULTILINE|wx.TE_READONLY)
|
||||
self.users = []
|
||||
|
||||
def OnResize(event):
|
||||
self.textctrl.SetSize(event.GetSize())
|
||||
self.Bind(wx.EVT_SIZE, OnResize, self)
|
||||
|
||||
|
||||
class MainWindow(wx.Frame):
|
||||
def __init__(self, ui):
|
||||
wx.Frame.__init__(self, None, -1, size = (800, 600))
|
||||
|
||||
self.Bind(wx.EVT_CLOSE, self.OnClose, self)
|
||||
|
||||
self.ui = ui
|
||||
self.factory = self.ui.factory
|
||||
|
||||
self.tabs = {}
|
||||
splitter = wx.SplitterWindow(self, -1)
|
||||
|
||||
self.pl = wx.Panel(splitter, -1)
|
||||
sizer = wx.GridBagSizer(0, 0)
|
||||
|
||||
self.nb = wx.Notebook(self.pl, -1, style = wx.NB_TOP)
|
||||
sizer.Add(self.nb, (0, 0), (1, 1), wx.EXPAND)
|
||||
sizer.AddGrowableCol(0)
|
||||
sizer.AddGrowableRow(0)
|
||||
|
||||
self.input = wx.TextCtrl(self.pl, -1)
|
||||
sizer.Add(self.input, (1, 0), (1, 1), wx.EXPAND)
|
||||
self.pl.SetSizerAndFit(sizer)
|
||||
self.add_tab('Server')
|
||||
|
||||
self.pr = wx.Panel(splitter, -1) # right panel
|
||||
self.userlist = wx.ListBox(self.pr, -1, (0, 5), style = wx.SUNKEN_BORDER)
|
||||
|
||||
self.nb.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnChangeTab, self.nb)
|
||||
|
||||
def OnResize(event):
|
||||
size = event.GetSize()
|
||||
self.userlist.SetSize((size[0], size[1] - 10))
|
||||
self.pr.Bind(wx.EVT_SIZE, OnResize, self.pr)
|
||||
|
||||
splitter.SplitVertically(self.pl, self.pr, self.GetSize()[0] * 0.7)
|
||||
splitter.SetSashGravity(1)
|
||||
|
||||
mainmenu = wx.Menu()
|
||||
|
||||
menuitem = mainmenu.Append(-1, '&Connect', 'Connect to the server')
|
||||
self.Bind(wx.EVT_MENU, self.OnConnect, menuitem)
|
||||
|
||||
menuitem = mainmenu.Append(-1, '&Debug window',
|
||||
'Open or close debug window')
|
||||
self.Bind(wx.EVT_MENU, self.OnOpenDebugWindow, menuitem)
|
||||
|
||||
mainmenu.AppendSeparator()
|
||||
|
||||
menuitem = mainmenu.Append(-1, '&Exit', 'Exit pyPSYC')
|
||||
self.Bind(wx.EVT_MENU, self.OnClose, menuitem)
|
||||
|
||||
menubar = wx.MenuBar()
|
||||
menubar.Append(mainmenu, '&pyPSYC')
|
||||
|
||||
self.SetMenuBar(menubar)
|
||||
|
||||
self.input.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
|
||||
|
||||
self.Show(True)
|
||||
|
||||
def OnKeyDown(self, event):
|
||||
if event.GetKeyCode() in (wx.WXK_RETURN, wx.WXK_NUMPAD_ENTER):
|
||||
pagename = self.nb.GetCurrentPage().name
|
||||
value = self.input.GetValue()
|
||||
if value:
|
||||
if pagename == 'Server' or value.startswith('/'):
|
||||
self.ui.server_command(value, self.nb.GetCurrentPage().name)
|
||||
|
||||
elif '@' in pagename:
|
||||
self.factory.sc.castmsg(pagename, '_message_public',
|
||||
value, {})
|
||||
|
||||
elif '~' in pagename:
|
||||
self.factory.sc.sendmsg(pagename, '_message_private',
|
||||
value, {})
|
||||
|
||||
self.input.SetValue('')
|
||||
|
||||
event.Skip()
|
||||
|
||||
def OnChangeTab(self, event):
|
||||
self.userlist.Set(self.nb.GetCurrentPage().users)
|
||||
|
||||
def OnConnect(self, event):
|
||||
self.factory.connect()
|
||||
self.ui.connected = True
|
||||
|
||||
def OnOpenDebugWindow(self, event):
|
||||
# open or close window:
|
||||
if not self.ui.debugwindow.Show(True): self.ui.debugwindow.Show(False)
|
||||
|
||||
def OnClose(self, event):
|
||||
if self.ui.connected:
|
||||
self.ui.server_command('/quit', None)
|
||||
else:
|
||||
reactor.stop()
|
||||
|
||||
def add_tab(self, name):
|
||||
self.tabs[name] = Tab(self.nb, name)
|
||||
self.nb.AddPage(self.tabs[name], name)
|
||||
|
||||
|
||||
class DebugWindow(wx.Frame):
|
||||
def __init__(self, factory):
|
||||
wx.Frame.__init__(self, parent = None, id = -1,
|
||||
title = 'pyPSYC debug window', size = (800, 600),
|
||||
style = wx.DEFAULT_FRAME_STYLE|
|
||||
wx.NO_FULL_REPAINT_ON_RESIZE)
|
||||
self.Bind(wx.EVT_CLOSE, self.OnClose, self)
|
||||
|
||||
self.tree = wx.TreeCtrl(self, -1, wx.DefaultPosition, (-1,-1),
|
||||
wx.TR_HIDE_ROOT|wx.TR_HAS_BUTTONS)
|
||||
self.treeroot = self.tree.AddRoot('Programmer')
|
||||
|
||||
def OnClose(self, event):
|
||||
self.Show(False)
|
||||
|
||||
|
||||
class Interface(base.BaseUI):
|
||||
def __init__(self, factory):
|
||||
self.factory = factory
|
||||
self.gui = wx.PySimpleApp()
|
||||
self.mainwindow = MainWindow(self)
|
||||
self.debugwindow = DebugWindow(self)
|
||||
|
||||
def _print(self, window, text):
|
||||
if window not in self.mainwindow.tabs:
|
||||
self.mainwindow.add_tab(window)
|
||||
self.mainwindow.tabs[window].textctrl.AppendText(text + '\n')
|
||||
|
||||
def pre_print(self, packet):
|
||||
print ('recv', packet)
|
||||
tmp = self.debugwindow.tree.AppendItem(self.debugwindow.treeroot,
|
||||
'Incoming Packet %s'
|
||||
% self.inpacketcount)
|
||||
self.debugwindow.tree.AppendItem(tmp, "MMPVars: %s" % packet.mmpvars)
|
||||
self.debugwindow.tree.AppendItem(tmp, "PSYCVars: %s" % packet.psycvars)
|
||||
self.debugwindow.tree.AppendItem(tmp, "Method: %s" % packet.mc)
|
||||
self.debugwindow.tree.AppendItem(tmp, "Text: %s" % packet.text)
|
||||
|
||||
def pre_send(self, packet):
|
||||
print ('send', packet)
|
||||
tmp = self.debugwindow.tree.AppendItem(self.debugwindow.treeroot,
|
||||
'Outgoing Packet %s'
|
||||
% self.outpacketcount)
|
||||
self.debugwindow.tree.AppendItem(tmp, "MMPVars: %s" % packet.mmpvars)
|
||||
self.debugwindow.tree.AppendItem(tmp, "PSYCVars: %s" % packet.psycvars)
|
||||
self.debugwindow.tree.AppendItem(tmp, "Method: %s" % packet.mc)
|
||||
self.debugwindow.tree.AppendItem(tmp, "Text: %s" % packet.text)
|
||||
|
||||
def handle_echo_place_enter_login(self, packet):
|
||||
self._print(packet.vars['_source_relay'], packet.text)
|
||||
self.mainwindow.tabs[packet.vars['_source_relay']].users = packet.vars['_list_members']
|
||||
|
||||
def handle_echo_place_enter(self, packet):
|
||||
self._print(packet.vars['_nick_place'], packet.text)
|
||||
self.mainwindow.tabs[packet.vars['_nick_place']].users = packet.vars['_list_members']
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = wx.PySimpleApp()
|
||||
MainWindow()
|
||||
app.MainLoop()
|
||||
|
||||
##class Tab(wx.Panel):
|
||||
## def __init__(self, name, main):
|
||||
## self.name = name
|
||||
## self.main = main
|
||||
## self.ui = self.main.ui
|
||||
## self.factory = self.ui.factory
|
||||
## wx.Panel.__init__(self, main.nb, -1)
|
||||
## self.textbox = wx.TextCtrl(self, -1, style = wx.TE_MULTILINE|
|
||||
## wx.TE_READONLY,)
|
||||
## self.input = wx.TextCtrl(self, -1)
|
||||
## #self.input.SetFocus()
|
||||
## self.input.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
|
||||
##
|
||||
## def OnKeyDown(self, event):
|
||||
## if event.GetKeyCode() in (wx.WXK_RETURN, wx.WXK_NUMPAD_ENTER):
|
||||
## if self.input.GetValue():
|
||||
## self.factory.sc.castmsg(self.name, '_message_public',
|
||||
## self.input.GetValue(), {})
|
||||
## self.input.SetValue('')
|
||||
##
|
||||
## event.Skip()
|
||||
#
|
||||
#
|
||||
#class Tab(wx.Panel):
|
||||
# def __init__(self, name, main):
|
||||
# self.name = name
|
||||
# self.main = main
|
||||
# self.ui = self.main.ui
|
||||
# if hasattr(self.ui, 'factory'):
|
||||
# self.factory = self.ui.factory
|
||||
# wx.Panel.__init__(self, main.nb, -1, size = wx.DefaultSize)
|
||||
# #wx.Frame.__init__(self, None, -1, size = wx.DefaultSize)
|
||||
#
|
||||
# #splitter = wx.SplitterWindow(self, -1)
|
||||
# #pl = wx.Panel(splitter, -1, size = wx.DefaultSize) # panel left
|
||||
# ##pls = wx.BoxSizer(wx.VERTICAL)
|
||||
# #wx.TextCtrl(pl, -1, style = wx.TE_MULTILINE|wx.TE_READONLY, size = wx.DefaultSize)
|
||||
#
|
||||
# #pr = wx.Panel(splitter, -1, size = wx.DefaultSize) # panel right
|
||||
# #wx.ListCtrl(pr, -1, size = wx.DefaultSize)
|
||||
#
|
||||
# #splitter.SplitVertically(pl, pr)
|
||||
#
|
||||
# splitter = wx.SplitterWindow(self, -1)
|
||||
# panel1 = wx.Panel(splitter, -1)
|
||||
# wx.StaticText(panel1, -1,
|
||||
# "Whether you think that you can, or that you can't, you are usually right."
|
||||
# "\n\n Henry Ford",
|
||||
# (100,100), style=wx.ALIGN_CENTRE)
|
||||
# panel1.SetBackgroundColour(wx.LIGHT_GREY)
|
||||
# panel2 = wx.Panel(splitter, -1)
|
||||
# panel2.SetBackgroundColour(wx.WHITE)
|
||||
# splitter.SplitVertically(panel1, panel2)
|
||||
# self.Centre()
|
||||
#
|
||||
#
|
||||
#class MainWindow(wx.Frame):
|
||||
# def __init__(self, ui):
|
||||
# wx.Frame.__init__(self, parent = None, id = -1, title = 'pyPSYC',
|
||||
# size = (800, 600),
|
||||
# style = wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE)
|
||||
#
|
||||
# self.Bind(wx.EVT_CLOSE, self.OnClose, self)
|
||||
#
|
||||
# self.ui = ui
|
||||
# if hasattr(self.ui, 'factory'):
|
||||
# self.factory = self.ui.factory
|
||||
#
|
||||
# self.CreateStatusBar()
|
||||
#
|
||||
# # Set up and create the menu
|
||||
# mainmenu = wx.Menu()
|
||||
#
|
||||
# menuitem = mainmenu.Append(-1, '&Connect', 'Connect to the server')
|
||||
# self.Bind(wx.EVT_MENU, self.OnConnect, menuitem)
|
||||
#
|
||||
# menuitem = mainmenu.Append(-1, '&Debug window',
|
||||
# 'Open or close debug window')
|
||||
# self.Bind(wx.EVT_MENU, self.OnOpenDebugWindow, menuitem)
|
||||
#
|
||||
# mainmenu.AppendSeparator()
|
||||
#
|
||||
# menuitem = mainmenu.Append(-1, '&Exit', 'Exit pyPSYC')
|
||||
# self.Bind(wx.EVT_MENU, self.OnClose, menuitem)
|
||||
#
|
||||
# menubar = wx.MenuBar()
|
||||
# menubar.Append(mainmenu, '&pyPSYC')
|
||||
# self.SetMenuBar(menubar)
|
||||
#
|
||||
# self.nb = wx.Notebook(self, -1, style=wx.NB_BOTTOM)
|
||||
#
|
||||
# self.tabs = {}
|
||||
#
|
||||
# self.Show(True)
|
||||
#
|
||||
# def OnConnect(self, event):
|
||||
# self.factory.connect()
|
||||
#
|
||||
# def OnOpenDebugWindow(self, event):
|
||||
# # open or close window:
|
||||
# if not self.ui.debugwindow.Show(True): self.ui.debugwindow.Show(False)
|
||||
#
|
||||
# def OnClose(self, event):
|
||||
# reactor.stop()
|
||||
#
|
||||
#
|
||||
#class DebugWindow(wx.Frame):
|
||||
# def __init__(self, factory):
|
||||
# wx.Frame.__init__(self, parent = None, id = -1,
|
||||
# title = 'pyPSYC debug window', size = (800, 600),
|
||||
# style = wx.DEFAULT_FRAME_STYLE|
|
||||
# wx.NO_FULL_REPAINT_ON_RESIZE)
|
||||
# self.Bind(wx.EVT_CLOSE, self.OnClose, self)
|
||||
#
|
||||
# self.tree = wx.TreeCtrl(self, -1, wx.DefaultPosition, (-1,-1),
|
||||
# wx.TR_HIDE_ROOT|wx.TR_HAS_BUTTONS)
|
||||
# self.treeroot = self.tree.AddRoot('Programmer')
|
||||
#
|
||||
# def OnClose(self, event):
|
||||
# self.Show(False)
|
||||
#
|
||||
#
|
||||
#class Interface:#(base.BaseUI):
|
||||
# def __init__(self, factory):
|
||||
# self.gui = wx.PySimpleApp()
|
||||
# if factory:
|
||||
# self.factory = factory
|
||||
# reactor.registerWxApp(self.gui)
|
||||
# self.mainwindow = MainWindow(self)
|
||||
# self.debugwindow = DebugWindow(self)
|
||||
# window = 'Server'
|
||||
# self.mainwindow.tabs[window] = Tab(window, self.mainwindow)
|
||||
# self.mainwindow.nb.AddPage(self.mainwindow.tabs[window], window)
|
||||
#
|
||||
# def _print(self, window, text):
|
||||
# if window not in self.mainwindow.tabs:
|
||||
# self.mainwindow.tabs[window] = Tab(window, self.mainwindow)
|
||||
#
|
||||
# #def OnOvrSize(event, tab=self.mainwindow.tabs[window]):
|
||||
# # size = event.GetSize()
|
||||
# # textboxsize = (size[0], size[1] - 24)
|
||||
# # inputpos = (0, size[1] - 24)
|
||||
# # tab.textbox.SetSize(textboxsize)
|
||||
# # tab.input.SetPosition(inputpos)
|
||||
# # tab.input.SetSize((size[0], 21))
|
||||
#
|
||||
# #wx.EVT_SIZE(self.mainwindow.tabs[window], OnOvrSize)
|
||||
#
|
||||
# self.mainwindow.nb.AddPage(self.mainwindow.tabs[window], window)
|
||||
#
|
||||
# self.mainwindow.tabs[window].textbox.AppendText(text)
|
||||
#
|
||||
#
|
||||
# def pre_print(self, packet):
|
||||
# tmp = self.debugwindow.tree.AppendItem(self.debugwindow.treeroot,
|
||||
# 'Incoming Packet %s'
|
||||
# % self.inpacketcount)
|
||||
# self.debugwindow.tree.AppendItem(tmp, "MMPVars: %s" % packet.mmpvars)
|
||||
# self.debugwindow.tree.AppendItem(tmp, "PSYCVars: %s" % packet.psycvars)
|
||||
# self.debugwindow.tree.AppendItem(tmp, "Method: %s" % packet.mc)
|
||||
# self.debugwindow.tree.AppendItem(tmp, "Text: %s" % packet.text)
|
||||
#
|
||||
# def pre_send(self, packet):
|
||||
# tmp = self.debugwindow.tree.AppendItem(self.debugwindow.treeroot,
|
||||
# 'Outgoing Packet %s'
|
||||
# % self.outpacketcount)
|
||||
# self.debugwindow.tree.AppendItem(tmp, "MMPVars: %s" % packet.mmpvars)
|
||||
# self.debugwindow.tree.AppendItem(tmp, "PSYCVars: %s" % packet.psycvars)
|
||||
# self.debugwindow.tree.AppendItem(tmp, "Method: %s" % packet.mc)
|
||||
# self.debugwindow.tree.AppendItem(tmp, "Text: %s" % packet.text)
|
||||
#
|
||||
#if __name__ == '__main__':
|
||||
# interface = Interface(None)
|
||||
# interface.gui.MainLoop()
|
0
mjacob/old/UI/wx/__init__.py
Normal file
0
mjacob/old/UI/wx/__init__.py
Normal file
36
mjacob/old/__init__.py
Executable file
36
mjacob/old/__init__.py
Executable file
|
@ -0,0 +1,36 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Licensed under the MIT license
|
||||
# http://opensource.org/licenses/mit-license.php
|
||||
|
||||
# <C> Copyright 2007, Manuel Jacob
|
||||
|
||||
import re
|
||||
|
||||
# the following two functions are from the 'original' pypsyc
|
||||
# (and slightly modified)
|
||||
|
||||
def get_host(uni):
|
||||
m = re.match("^psyc:\/\/(.+)?\/~(.+)?\/?$", uni)
|
||||
if m: return m.group(1)
|
||||
|
||||
m = re.match("^psyc:\/\/([^\/@]+)\@(.+?)\/?$", uni)
|
||||
if m: return m.group(2)
|
||||
|
||||
m = re.match("^psyc:\/\/(.+)?\/\@(.+)?\/?$", uni)
|
||||
if m: return m.group(1)
|
||||
|
||||
m = re.match("^psyc:\/\/(.+)$", uni)
|
||||
if m: return m.group(1)
|
||||
|
||||
raise "invalid uni"
|
||||
|
||||
def get_user(uni):
|
||||
m = re.match("^psyc:\/\/(.+)?\/~(.+)?\/?$", uni)
|
||||
if m: return m.group(2)
|
||||
|
||||
m = re.match("^psyc:\/\/([^\/@]+)\@(.+?)\/?$", uni)
|
||||
if m: return m.group(1)
|
||||
|
||||
raise "invalid uni"
|
94
mjacob/old/pypsyc-twisted.py
Executable file
94
mjacob/old/pypsyc-twisted.py
Executable file
|
@ -0,0 +1,94 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Licensed under the GPLv2 license
|
||||
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
|
||||
# <C> Copyright 2007, Manuel Jacob
|
||||
|
||||
import os
|
||||
|
||||
from __init__ import get_host, get_user
|
||||
from PSYC.PSYCProtocol import PSYCProtocol
|
||||
from PSYC.PSYCPacket import PSYCPacket
|
||||
|
||||
try:
|
||||
from twisted.internet import wxreactor
|
||||
wxreactor.install()
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
from twisted.internet import reactor, protocol
|
||||
|
||||
class Config:
|
||||
def __init__(self, factory):
|
||||
self.factory = factory
|
||||
self.settings_folder = self.get_settings_folder()
|
||||
|
||||
self.uni_file = os.path.join(self.settings_folder, 'me')
|
||||
self.clientconfig_file = os.path.join(self.settings_folder, 'pypsyc', 'config')
|
||||
|
||||
self.uni = self.get_uni()
|
||||
#self.uni = 'psyc://beta.ve.symlynX.com/~pypsyctest'
|
||||
#self.uni = raw_input('uni?: ')
|
||||
self.host = get_host(self.uni)
|
||||
self.username = get_user(self.uni)
|
||||
|
||||
self.configfile = self.open_configfile()
|
||||
|
||||
self.ui = 'wx'
|
||||
|
||||
def get_settings_folder(self):
|
||||
# resolve settings folder
|
||||
if os.name == 'posix':
|
||||
folder = os.path.join(os.environ.get('HOME'), ".psyc")
|
||||
elif os.name == 'nt':
|
||||
folder = os.path.join(os.environ.get('APPDATA'), 'psyc')
|
||||
else:
|
||||
folder = os.path.join(os.getcwd(), 'psyc')
|
||||
|
||||
# create settings folder if necessary
|
||||
try:
|
||||
os.mkdir(folder)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
return folder
|
||||
|
||||
def get_uni(self):
|
||||
f = file(self.uni_file)
|
||||
uni = f.read().strip()
|
||||
f.close()
|
||||
return uni
|
||||
|
||||
def open_configfile(self):
|
||||
return None
|
||||
|
||||
|
||||
class App(protocol.ClientFactory):
|
||||
def __init__(self):
|
||||
self.config = Config(self)
|
||||
self.protocol = PSYCProtocol
|
||||
self.connections = {}
|
||||
|
||||
#Interface = __import__('UI.%s.Interface' % self.config.ui, [], [], ['Interface'])
|
||||
exec("from UI.%s.Interface import Interface" % self.config.ui)
|
||||
self.ui = Interface(self)
|
||||
|
||||
self.callback_on_recv = self.ui.recv
|
||||
|
||||
def connect(self):
|
||||
reactor.connectTCP(self.config.host, 4404, self, timeout = 20)
|
||||
|
||||
def buildProtocol(self, addr):
|
||||
p = self.protocol(self.callback_on_recv)
|
||||
p.factory = self
|
||||
self.callback_on_recv
|
||||
self.connections[addr.host] = p
|
||||
if len(self.connections) == 1:
|
||||
self.sc = p # sc = server connection
|
||||
return p
|
||||
|
||||
|
||||
factory = App()
|
||||
reactor.run()
|
4
mjacob/old/pypsyc.conf
Normal file
4
mjacob/old/pypsyc.conf
Normal file
|
@ -0,0 +1,4 @@
|
|||
[server1]
|
||||
host = beta.ve.symlynX.com
|
||||
port = 4404
|
||||
username = l
|
Loading…
Add table
Add a link
Reference in a new issue