Auch wenns ein altes thema is fehlen dazu die guten Docus und ich hab im moment ungefair das selbe problem. Was ich persönlich nicht verstehe wie man twisted und wxpython über wxreactor zum miteinander reden bekommt.
so das man ordentlich daten von a nach b und b nach a verschieben kann.
Code: Alles auswählen
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import sys,time
from twisted.internet import wxreactor
if sys.modules.has_key('twisted.internet.reactor'):del sys.modules['twisted.internet.reactor']
wxreactor.install()
import wx
wx.SetDefaultPyEncoding("UTF-8")
from twisted.words.protocols import irc
from twisted.internet import reactor
from twisted.internet import protocol
from twisted.python import threadable
class MainFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, title="pyChat", size=(800,600))
self.CreateStatusBar()
self.MakeMenuBar()
self.splitter = wx.SplitterWindow(self, -1, style=wx.SP_LIVE_UPDATE)
self.splitter.SetMinimumPaneSize(125) #fix my position
self.panel_left = wx.Panel(self.splitter, style=wx.SUNKEN_BORDER)
self.panel_right = wx.Panel(self.splitter, style=wx.SUNKEN_BORDER)
self.splitter.SplitVertically(self.panel_left, self.panel_right, sashPosition=125)
self.tree = wx.TreeCtrl(self.panel_left, -1, style=wx.TR_HAS_BUTTONS|wx.TR_DEFAULT_STYLE|wx.SUNKEN_BORDER)
self.workspace = wx.TextCtrl(self.panel_right, -1, "", style=wx.TE_MULTILINE|wx.TE_READONLY)
self.chatbox = wx.TextCtrl(self.panel_right,-1,"",style = wx.TE_PROCESS_ENTER)
self.__set_layout()
self.chatbox.Bind(wx.EVT_TEXT_ENTER, self.ChatBox,)
self.workspace.write(u"Welcome to PyChat Alpha\n")
def __set_layout(self):
self.splitter_sizer = wx.BoxSizer(wx.HORIZONTAL)
self.splitter_sizer.Add(self.splitter, 1, wx.ALL|wx.EXPAND, 0)
self.SetSizer(self.splitter_sizer)
self.splitter_sizer.Fit(self)
self.splitter_sizer.SetSizeHints(self)
self.panel_left_sizer = wx.BoxSizer(wx.HORIZONTAL)
self.panel_left_sizer.Add(self.tree, 1, wx.ALL|wx.EXPAND, 0) #tree window
self.panel_left.SetSizer(self.panel_left_sizer)
self.panel_left.Fit()
self.panel_right_sizer = wx.BoxSizer(wx.VERTICAL)
self.panel_right_sizer.Add(self.workspace, 1, wx.ALL|wx.EXPAND, 0) #main output
self.panel_right_sizer.Add(self.chatbox,0,wx.ALIGN_BOTTOM|wx.EXPAND,0) #chatbox
self.panel_right.SetSizer(self.panel_right_sizer)
self.panel_right.Fit()
self.SetAutoLayout(True)
self.Layout()
def MakeMenuBar(self):
menu = wx.Menu()
menu.Append(5000,"&Connect")
menu.Append(5001,"&Disconnect")
menu.Append(5002,"E&xit")
menubar = wx.MenuBar()
menubar.Append(menu,"&File")
self.SetMenuBar(menubar)
self.Bind(wx.EVT_MENU,self.OnConnect,id=5000)
self.Bind(wx.EVT_MENU,self.OnDisconnect,id=5001)
self.Bind(wx.EVT_MENU,self.OnExit,id=5002)
def OnExit(self, evt):
self.Close()
def OnConnect(self,evt):
firc = ConnectionFactory()
reactor.connectTCP("localhost",6667,firc)
def OnDisconnect(self,evt):
reactor.stop()
def ChatBox(self,evt):
unicodes = self.chatbox.GetValue()
self.workspace.write(unicodes+"\n") #add to window
self.chatbox.Clear()
class ircCore(irc.IRCClient):
nickname = "changemeplz"
channel = "#testchan"
def connectionMade(self):
irc.IRCClient.connectionMade(self) #call me once
print "[connected at %s]" % time.asctime(time.localtime(time.time()))
def signedOn(self):
self.join(self.channel)
def joined(self,channel):
print "[joined %s]" % channel
class ConnectionFactory(protocol.ClientFactory):
protocol = ircCore
def clientConnectionLost(self,connector,reason):
print "Connection Lost:",reason
connector.connect()
def clientConnectionFailed(self,connector,reason):
print "Connection Failed:",reason
reactor.stop()
class MyApp(wx.App):
def OnInit(self):
frame = MainFrame()
frame.SetSize((800,600))
frame.Show(True)
return True
if __name__ == '__main__':
app = MyApp()
reactor.registerWxApp(app)
reactor.run()
wenn jemand ahnung davon hat wo muss man etwas einfügen damit die kommunikation klappt is im moment ein wenig zu hoch für mich