From 021d063776f1b71b37bca190d965ce478bdafd69 Mon Sep 17 00:00:00 2001
From: RaNaN <Mast3rRaNaN@hotmail.de>
Date: Mon, 1 Jun 2009 00:29:26 +0200
Subject: working event approach for socket transmission

---
 module/remote/ClientHandler.py | 11 +++++++----
 pyMainGui.py                   | 23 ++++++++++++++++++-----
 2 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/module/remote/ClientHandler.py b/module/remote/ClientHandler.py
index 3fcee3f79..cc06bd21a 100644
--- a/module/remote/ClientHandler.py
+++ b/module/remote/ClientHandler.py
@@ -7,7 +7,6 @@ this module handels the incoming requests
 
 """
 import hashlib
-import wx
 
 from Crypto.Cipher import Blowfish
 from RequestHandler import RequestHandler
@@ -20,6 +19,10 @@ class ClientHandler(RequestHandler):
 
     def proceed(self, data):
         obj = self.decrypt(data)
-	if obj.function == "get_downloads":
-	    self.client.show_links(obj.response)
-        return self.encrypt(obj)
+
+	self.client.data_arrived(obj)
+
+	#if obj.function == "get_downloads":
+	 #   self.client.show_links(obj.response)
+        
+	return self.encrypt(obj)
diff --git a/pyMainGui.py b/pyMainGui.py
index 86bfbe274..e672575d9 100755
--- a/pyMainGui.py
+++ b/pyMainGui.py
@@ -24,8 +24,11 @@ from os.path import dirname
 
 import wx
 import wx.lib.sized_controls as sized_control
+import  wx.lib.newevent
 from module.remote.ClientSocket import SocketThread
 
+(DataArrived, EVT_DATA_ARRIVED) = wx.lib.newevent.NewEvent()
+
 class _Download_Dialog(sized_control.SizedDialog):
     def __init__(self, parent, id):
         sized_control.SizedDialog.__init__(self, parent, id, "Downloads hinzufügen",
@@ -103,25 +106,35 @@ class Pyload_Main_Gui(wx.Frame):
         #   Binds
         self.Bind(wx.EVT_MENU, self.exit_button_clicked, submenu_exit)
         self.Bind(wx.EVT_TOOL, self.add_button_clicked, add)
-        
+	self.Bind(EVT_DATA_ARRIVED, self.onUpdate)        
+
         self.Centre()
         self.Show(True)
 
-	#test
-
-	self.thread.push_exec("get_downloads")
         
     def exit_button_clicked(self, event):
         self.Close()
         
     def add_button_clicked(self, event):
+	#test
+	self.thread.push_exec("get_downloads")
+
         adddownload = _Download_Dialog(None, -1)
         result = adddownload.ShowModal()
         adddownload.Destroy()
 
     def show_links(self, links):
 	for link in links:
-	    wx.MessageDialog(None, str(link), 'info', style=wx.OK).ShowModal()
+	    wx.CallAfter(wx.MessageDialog(self, str(link), 'info', style=wx.OK).ShowModal())
+
+    def data_arrived(self, rep):
+	evt = DataArrived(obj = rep)
+        wx.PostEvent(self, evt)
+
+    def onUpdate(self, data):
+
+	if data.obj.function == "get_downloads":
+	    self.show_links(data.obj.response)
                 
 app = wx.App()
 Pyload_Main_Gui(None,-1)
-- 
cgit v1.2.3