Added pm function, improved GUI.
authorMalte Bublitz <me@malte-bublitz.de>
Tue, 12 Feb 2013 21:40:53 +0000 (22:40 +0100)
committerMalte Bublitz <me@malte-bublitz.de>
Tue, 12 Feb 2013 21:40:53 +0000 (22:40 +0100)
client.py

index a0bb6c76e6bb6cde27eb14e3ae2c242194f4c289..72a96c2c3303a3538dd9a4ac0a1a52bfe479b113 100644 (file)
--- a/client.py
+++ b/client.py
@@ -5,6 +5,10 @@
 #
 
 import socket
+import threading
+import time
+import select, sys
+import wx
 
 class ChatClient(object):
        queue = []
@@ -41,23 +45,24 @@ class ChatClient(object):
                        return command
                else:
                        return False
-               
        
-import threading
-import time
-import select, sys
-import wx
-
 class SimpleChatFrame(wx.Frame):
        def __init__(self, *args, **kwds):
                wx.Frame.__init__(self, *args, **kwds)
-               # Menu Bar
-               self.frame_1_menubar = wx.MenuBar()
-               wxglade_tmp_menu = wx.Menu()
-               menu_quit = wxglade_tmp_menu.Append(wx.NewId(), "Quit", "", wx.ITEM_NORMAL)
-               self.Bind(wx.EVT_MENU, self.OnQuit, menu_quit)
-               self.frame_1_menubar.Append(wxglade_tmp_menu, "SimpleChat")
-               self.SetMenuBar(self.frame_1_menubar)
+               
+               # Menu bar
+               self.menubar = wx.MenuBar()
+               mainmenu     = wx.Menu()
+               menu_about   = mainmenu.Append(wx.ID_ABOUT, "Über...\tF1")
+               menu_quit    = mainmenu.Append(wx.ID_EXIT, "Beenden\tCtrl+Q")
+               chatmenu     = wx.Menu()
+               menu_pm      = chatmenu.Append(wx.ID_NEW, "Neue private Nachricht\tCtrl+P")
+               self.menubar.Append(mainmenu, "SimpleChat")
+               self.menubar.Append(chatmenu, "Chat")
+               self.SetMenuBar(self.menubar)
+               self.Bind(wx.EVT_MENU, self.OnAbout,   menu_about)
+               self.Bind(wx.EVT_MENU, self.OnQuit,    menu_quit)
+               self.Bind(wx.EVT_MENU, self.OnPrivMsg, menu_pm)
                # Menu Bar end
                self.text_ctrl_1 = wx.TextCtrl(self, -1, "", style=wx.TE_MULTILINE)
                self.text_ctrl_2 = wx.TextCtrl(self, -1, "")
@@ -92,6 +97,25 @@ class SimpleChatFrame(wx.Frame):
                self.chat.exit()
                self.Close()
                
+       def OnAbout(self, ev):
+               DEV_MALTE_BUBLITZ = "Malte Bublitz <kontakt@malte-bublitz.de>"
+               aboutInfo = wx.AboutDialogInfo()
+               aboutInfo.AddDeveloper(DEV_MALTE_BUBLITZ)
+               aboutInfo.SetCopyright("Copyright © 2013, Malte Bublitz (https://malte-bublitz.de)")
+               aboutInfo.SetName("SimpleChat")
+               aboutInfo.SetVersion("0.20130212")
+               aboutInfo.SetWebSite("https://github.com/malte70/simple-chat")
+               wx.AboutBox(aboutInfo)
+               
+       def OnPrivMsg(self, ev):
+               dlg = wx.TextEntryDialog(None, "An wen?", "Empfänger?")
+               if dlg.ShowModal() == wx.ID_OK:
+                       to = dlg.GetValue()
+                       dlg2 = wx.TextEntryDialog(None, "Die Nachricht?", "Nachricht")
+                       if dlg2.ShowModal() == wx.ID_OK:
+                               msg = dlg2.GetValue()
+                               self.chat.one(to, msg)
+
 class RecvThread(threading.Thread):
        def __init__(self, parent):
                threading.Thread.__init__(self)
@@ -115,13 +139,8 @@ class RetrieveThread(threading.Thread):
 #chat.exit()
 if __name__ == "__main__":
        app = wx.PySimpleApp(0)
-       wx.InitAllImageHandlers()
-       frame_1 = SimpleChatFrame(None, -1, "")
-       app.SetTopWindow(frame_1)
-       frame_1.Show()
-       #while True:
-       #       x = frame_1.chat.retrieve()
-       #       if x != False:
-       #               #self.parent.text_ctrl_1.AppendText(x+"\n")
-       #               print x
+       #wx.MessageBox('This software might crash...', 'Attention', wx.OK | wx.ICON_WARNING)
+       frame = SimpleChatFrame(None, -1, "")
+       app.SetTopWindow(frame)
+       frame.Show()
        app.MainLoop()