50824cceb618 — cedricbonhomme 11 years ago
The local time is the name of the file containing the saved conversation.
1 files changed, 26 insertions(+), 43 deletions(-)

M source/simpleGui.py
M source/simpleGui.py +26 -43
@@ 123,7 123,7 @@ class SimpleGui(object):
         self.barreM.config(command = self.message_to_send.yview)
         self.barreM.grid(column = 3, row = 2, sticky = S + N)
         self.message_to_send.config(state = NORMAL, yscrollcommand = self.barreM)
-        self.message_to_send.grid(row = 2, columnspan = 3)
+        self.message_to_send.grid(row = 2, columnspan = 3, pady = 5)
 
         # Send button
         self.send = Button(self.master, text = 'Send', command = self.send_message)

          
@@ 175,8 175,8 @@ class SimpleGui(object):
         # Edit menu
         editmenu = Menu(self.menu, tearoff = 0)
         self.menu.add_cascade(label = "Edit", menu = editmenu)
+        editmenu.add_command(label = "Save conversation", command = self.save_conversation)
         editmenu.add_command(label = "Clear conversation zone", command = self.clear_window)
-        editmenu.add_command(label = "Save conversation", command = self.save_conversation)
 
         # Management of interlocutors menu
         managementmenu = Menu(self.menu, tearoff = 0)

          
@@ 274,14 274,7 @@ class SimpleGui(object):
         Button(msg, text="OK", \
             command = execute).grid(row = 3, columnspan = 2, pady = 2)
 
-        ## sets the focus window (for Windows)
-        msg.focus_set()
-        ## force events to go to this window
-        msg.grab_set()
-        ## window remains above its parent window
-        msg.transient(self.master)
-        ## displays the window and waits for its closure
-        msg.wait_window(msg)
+        self.set_top_level_window(msg)
 
 
     def disconnect_from_platform(self):

          
@@ 377,14 370,7 @@ class SimpleGui(object):
         Button(msg, text="OK", \
             command = execute).grid(row = 5, columnspan = 2, pady = 2)
 
-        ## sets the focus window (for Windows)
-        msg.focus_set()
-        ## force events to go to this window
-        msg.grab_set()
-        ## window remains above its parent window
-        msg.transient(self.master)
-        ## displays the window and waits for its closure
-        msg.wait_window(msg)
+        self.set_top_level_window(msg)
 
     def signout(self):
         """

          
@@ 429,14 415,7 @@ class SimpleGui(object):
         Button(msg, text="OK", \
             command = execute).grid(row = 5, columnspan = 2, pady = 2)
 
-        ## sets the focus window (for Windows)
-        msg.focus_set()
-        ## force events to go to this window
-        msg.grab_set()
-        ## window remains above its parent window
-        msg.transient(self.master)
-        ## displays the window and waits for its closure
-        msg.wait_window(msg)
+        self.set_top_level_window(msg)
 
     def authentication_success(self):
         """

          
@@ 491,14 470,7 @@ class SimpleGui(object):
         Button(msg, text = 'OK', command = msg.destroy). \
                     grid(row = 5, columnspan = 2, pady=5, padx=5)
 
-        ## sets the focus window (for Windows)
-        msg.focus_set()
-        ## force events to go to this window
-        msg.grab_set()
-        ## window remains above its parent window
-        msg.transient(self.master)
-        ## displays the window and waits for its closure
-        msg.wait_window(msg)
+        self.set_top_level_window(msg)
 
 
     def block_sender(self, event = None):

          
@@ 687,13 659,19 @@ class SimpleGui(object):
         """
         Save the conversation in a file.
         """
+        if len(self.conversation_zone.get(1.0, END)) <= 1:
+            self.show_info("There is no conversation.")
+            return
+
         formats = [ \
         ('Format', '*.txt'), \
         ('All', '*.*') \
         ]
 
+        local_time = time.strftime("%y-%m-%d_%H:%M:%S", time.localtime())
+
         text_file = tkFileDialog.asksaveasfile(parent = self.master, \
-            filetypes = formats, title = "Save the conversation", mode='w')
+            filetypes = formats, title = "Save the conversation", mode='w', initialfile=local_time)
         if text_file != None:
             text = str(self.conversation_zone.get(1.0, END).encode('utf-8'))
             try:

          
@@ 721,6 699,18 @@ class SimpleGui(object):
         finally:
             self.master.destroy()
 
+    def set_top_level_window(self, window):
+        """
+        """
+        ## Sets the focus to the window (required for Windows)
+        window.focus_set()
+        ## Force events going on this window
+        window.grab_set()
+        ## For the window remains above its parent window
+        window.transient(self.master)
+        ## Displays the window and waits for closure
+        window.wait_window(window)
+
     def about(self):
         """
         About message.

          
@@ 735,14 725,7 @@ class SimpleGui(object):
         Message(msg, width = 300, aspect = 100, justify = CENTER, \
         text = message).pack(padx = 10, pady = 10)
 
-        ## Sets the focus to the window (required for Windows)
-        msg.focus_set()
-        ## Force events going on this window
-        msg.grab_set()
-        ## For the window remains above its parent window
-        msg.transient(self.master)
-        ## Displays the window and waits for closure
-        msg.wait_window(msg)
+        self.set_top_level_window(msg)