3
3
import Tkinter as tk
4
4
import ttk as ttk
5
5
import tkMessageBox
6
+ import tkFileDialog
6
7
import ScrolledText
7
8
import multiprocessing
8
9
from datetime import datetime
9
10
import threading
10
11
import webbrowser
11
12
import os
12
13
import ip
14
+ import time
13
15
import BlocklyServer
14
16
from PropC_library_finder import propc_library_finder
15
17
@@ -51,7 +53,7 @@ def set_version(self, version):
51
53
def initialize (self ):
52
54
self .grid ()
53
55
54
- self .lbl_ip_address = tk .Label (self , anchor = tk .E , text = 'IP Address :' )
56
+ self .lbl_ip_address = ttk .Label (self , anchor = tk .E , text = 'IP Address :' )
55
57
self .lbl_ip_address .grid (column = 0 , row = 0 , sticky = 'nesw' )
56
58
57
59
self .ent_ip_address = ttk .Entry (self , state = 'readonly' , textvariable = self .ip_address )
@@ -68,6 +70,12 @@ def initialize(self):
68
70
69
71
self .btn_connect = ttk .Button (self , text = 'Connect' , command = self .handle_connect )
70
72
self .btn_connect .grid (column = 1 , row = 2 , sticky = 'nesw' , padx = 3 , pady = 3 )
73
+
74
+ self .lbl_current_code = ttk .Label ( self , anchor = tk .E , text = 'Code most recently compiled :' )
75
+ self .lbl_current_code .grid (column = 0 , row = 5 , sticky = 'nesw' , padx = 3 , pady = 3 )
76
+
77
+ self .current_code = ScrolledText .ScrolledText ( self , state = 'disabled' )
78
+ self .current_code .grid (column = 0 , row = 6 , columnspan = 2 , sticky = 'nesw' , padx = 3 , pady = 3 )
71
79
72
80
self .lbl_log = ttk .Label (self , anchor = tk .W , text = 'Log :' )
73
81
self .lbl_log .grid (column = 0 , row = 3 , sticky = 'nesw' , padx = 3 , pady = 3 )
@@ -103,12 +111,16 @@ def initialize(self):
103
111
monitor .daemon = True
104
112
monitor .start ()
105
113
114
+ code_monitor = threading .Thread ( target = self .code_catcher )
115
+ code_monitor .daemon = True
116
+ code_monitor .start ()
117
+
106
118
def initialize_menu ( self ):
107
119
menubar = tk .Menu ( self )
108
120
109
121
file_menu = tk .Menu ( menubar , tearoff = 0 )
110
122
file_menu .add_command ( label = "Save" )
111
- file_menu .add_command ( label = "Save As..." )
123
+ file_menu .add_command ( label = "Save As..." , command = self . handle_save_as )
112
124
file_menu .add_command ( label = "Open" )
113
125
menubar .add_cascade ( label = "File" , menu = file_menu )
114
126
@@ -144,6 +156,15 @@ def handle_connect(self):
144
156
self .connected = True
145
157
self .btn_connect ['text' ] = "Disconnect"
146
158
159
+ def handle_save_as ( self ):
160
+ file = tkFileDialog .asksaveasfile ( mode = 'w' )
161
+ code = open ( "c_code_file" , 'r' ).read ()
162
+
163
+ file .write ( code )
164
+ file .close ()
165
+
166
+ tkMessageBox .showinfo ( "Info" , "The most recently compiled code has been saved to a file successfully" )
167
+
147
168
def handle_browser (self ):
148
169
webbrowser .open_new ( 'http://blocklyprop.creatingfuture.eu' )
149
170
@@ -169,6 +190,20 @@ def handle_close(self):
169
190
self .server_process .terminate ()
170
191
self .quit ()
171
192
193
+ def code_catcher ( self ):
194
+ while 1 :
195
+ try :
196
+ code = open ( "c_code_file" , 'r' ).read ()
197
+ except :
198
+ code = ""
199
+
200
+ self .current_code ['state' ] = 'normal'
201
+ self .current_code .delete ( "1.0" , tk .END )
202
+ self .current_code .insert ( "1.0" , code )
203
+ self .current_code ['state' ] = 'disabled'
204
+
205
+ time .sleep ( 2 )
206
+
172
207
def text_catcher (self ):
173
208
while 1 :
174
209
(level , level_name , message ) = self .q .get ()
0 commit comments