Skip to content

Commit a7329e7

Browse files
Merge pull request #19 from DarkmatterVale/master
Major client update
2 parents 81ddbea + fcb9b10 commit a7329e7

5 files changed

+204
-4
lines changed

BlocklyPropClient.py

+77
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
import Tkinter as tk
44
import ttk as ttk
55
import tkMessageBox
6+
import tkFileDialog
67
import ScrolledText
78
import multiprocessing
89
from datetime import datetime
910
import threading
1011
import webbrowser
1112
import os
1213
import ip
14+
import time
1315
import BlocklyServer
16+
from PropC_library_finder import propc_library_finder
1417

1518
PORT = 6009
1619
VERSION = 0.2
@@ -42,6 +45,7 @@ def __init__(self, *args, **kwargs):
4245
pass
4346

4447
self.initialize()
48+
self.initialize_menu()
4549

4650
def set_version(self, version):
4751
self.version = version
@@ -66,6 +70,12 @@ def initialize(self):
6670

6771
self.btn_connect = ttk.Button(self, text='Connect', command=self.handle_connect)
6872
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)
6979

7080
self.lbl_log = ttk.Label(self, anchor=tk.W, text='Log :')
7181
self.lbl_log.grid(column=0, row=3, sticky='nesw', padx=3, pady=3)
@@ -100,6 +110,36 @@ def initialize(self):
100110
monitor = threading.Thread(target=self.text_catcher)
101111
monitor.daemon = True
102112
monitor.start()
113+
114+
code_monitor = threading.Thread( target=self.code_catcher)
115+
code_monitor.daemon = True
116+
code_monitor.start()
117+
118+
def initialize_menu( self ):
119+
menubar = tk.Menu( self )
120+
121+
file_menu = tk.Menu( menubar, tearoff=0 )
122+
file_menu.add_command( label="Save" )
123+
file_menu.add_command( label="Save As...", command=self.handle_save_as )
124+
file_menu.add_command( label="Open" )
125+
menubar.add_cascade( label="File", menu=file_menu )
126+
127+
about_menu = tk.Menu( menubar, tearoff=0 )
128+
about_menu.add_command( label="BlocklyPropClient Source Code", command=self.handle_client_code_browser )
129+
about_menu.add_command( label="BlocklyProp Source Code", command=self.handle_code_browser )
130+
about_menu.add_separator()
131+
about_menu.add_command( label="About", command=self.about_info )
132+
menubar.add_cascade( label="About", menu=about_menu)
133+
134+
options_menu = tk.Menu( menubar, tearoff=0 )
135+
options_menu.add_command( label="Set Library Location", command=self.handle_library_location )
136+
menubar.add_cascade( label="Options", menu=options_menu )
137+
138+
help_menu = tk.Menu( menubar, tearoff=0 )
139+
help_menu.add_command( label="Help" )
140+
menubar.add_cascade( label="Help", menu=help_menu )
141+
142+
self.config( menu=menubar )
103143

104144
def handle_connect(self):
105145
if self.connected:
@@ -116,8 +156,31 @@ def handle_connect(self):
116156
self.connected = True
117157
self.btn_connect['text'] = "Disconnect"
118158

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+
119168
def handle_browser(self):
120169
webbrowser.open_new( 'http://blocklyprop.creatingfuture.eu' )
170+
171+
def handle_code_browser( self ):
172+
webbrowser.open_new( 'http://github.com/parallaxinc/BlocklyProp' )
173+
174+
def handle_client_code_browser( self ):
175+
webbrowser.open_new( 'http://github.com/parallaxinc/BlocklyPropClient' )
176+
177+
def handle_library_location( self ):
178+
library_finder = propc_library_finder()
179+
180+
tkMessageBox.showinfo( "Info", "Library Location Set To: " + library_finder.get_directory() )
181+
182+
def about_info( self ):
183+
tkMessageBox.showinfo( "About BlocklyProp", "CurrentVersion: v0.2.0\n\nAuthors: Vale Tolpegin & Michel Lampo\n\nRepository Source Code: http://github.com/parallaxinc/BlocklyPropClient\n\nCopyright 2015 Parallax Inc" )
121184

122185
def handle_close(self):
123186
if tkMessageBox.askokcancel("Quit?", "Are you sure you want to quit?"):
@@ -127,6 +190,20 @@ def handle_close(self):
127190
self.server_process.terminate()
128191
self.quit()
129192

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+
130207
def text_catcher(self):
131208
while 1:
132209
(level, level_name, message) = self.q.get()

BlocklyServer.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
from SpinCompiler import SpinCompiler
1010
from PropCCompiler import PropCCompiler
1111

12-
import sys
12+
import sys, os
13+
1314

1415
PORT = 6009
1516
VERSION = 0.2
@@ -49,7 +50,11 @@ def ports(self):
4950
@cherrypy.tools.allow(methods=['POST'])
5051
def compile(self, action, language, code, comport=None):
5152
cherrypy.response.headers['Access-Control-Allow-Origin'] = '*'
52-
53+
54+
file = open( "c_code_file", 'w' )
55+
file.write( code )
56+
file.close()
57+
5358
result = self.compiler[language].handle(action, code, comport)
5459
self.queue.put((10, 'INFO', 'Application compiled'+ ' (' + action + ' : ' + language + ')'))
5560
return result

PropCCompiler.py

+22-2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ def compile(self, action, code):
9191

9292
def get_includes(self, includes):
9393
global lib_descriptor
94+
global user_defined_libraries
95+
96+
try:
97+
lib_descriptor = json.load(open(os.getcwd() + "/lib-descriptor.json"))
98+
user_defined_libraries = 1
99+
except:
100+
lib_descriptor = json.load(open(os.getcwd() + "/propeller-c-lib/lib-descriptor.json" ))
101+
user_defined_libraries = 0
102+
94103
descriptors = []
95104
for include in includes:
96105
for descriptor in lib_descriptor:
@@ -111,9 +120,15 @@ def parse_includes(self, c_file):
111120
return includes
112121

113122
def create_executing_data(self, c_file, binary_file, descriptors):
123+
global user_defined_libraries
124+
114125
executable = self.compiler_executables[platform.system()]
115-
lib_directory = self.appdir + "/propeller-c-lib/"
116126

127+
if user_defined_libraries == 1:
128+
lib_directory = ""
129+
else:
130+
lib_directory = self.appdir + "/propeller-c-lib/"
131+
117132
executing_data = [executable]
118133
for descriptor in descriptors:
119134
executing_data.append("-I")
@@ -137,4 +152,9 @@ def create_executing_data(self, c_file, binary_file, descriptors):
137152
return executing_data
138153

139154

140-
lib_descriptor = json.load(open(os.getcwd() + "/propeller-c-lib/lib-descriptor.json"))
155+
try:
156+
lib_descriptor = json.load(open(os.getcwd() + "/lib-descriptor.json"))
157+
user_defined_libraries = 1
158+
except:
159+
lib_descriptor = json.load(open(os.getcwd() + "/propeller-c-lib/lib-descriptor.json"))
160+
user_defined_libraries = 0

PropC_library_finder.py

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
__author__ = 'Vale'
2+
3+
import platform
4+
import os
5+
import json
6+
import subprocess
7+
import re
8+
import tkMessageBox
9+
import tkFileDialog
10+
from tkCommonDialog import Dialog
11+
12+
class propc_library_finder:
13+
library_path = ""
14+
15+
def __init__( self, *args, **kwargs ):
16+
self.find_libraries()
17+
output = self.assemble_information()
18+
self.create_json_file( output, "lib-descriptor.json" )
19+
20+
def get_directory( self ):
21+
global library_path
22+
23+
return library_path
24+
25+
def find_libraries( self ):
26+
global library_path
27+
28+
file_path = self.askdirectory()
29+
30+
library_path = file_path
31+
32+
def get_subdirectories( self, path ):
33+
return os.listdir( path )
34+
35+
def get_files_in_directory( self, path ):
36+
files = []
37+
38+
for file in os.listdir( path ):
39+
if isfile( file ):
40+
files[ file ] = file
41+
42+
return files
43+
44+
def assemble_information( self ):
45+
global library_path
46+
output = {}
47+
48+
#get directories
49+
directories = self.get_subdirectories( library_path )
50+
51+
for directory in directories:
52+
directory_path = library_path + "/" + directory + "/"
53+
54+
#get subdirectories of that directory
55+
try:
56+
sub_directories = self.get_subdirectories( directory_path )
57+
58+
for sub_directory in sub_directories:
59+
if ( "." not in sub_directory ):
60+
sub_directory_name = re.sub( "lib", "", sub_directory )
61+
sub_directory_path = directory_path + sub_directory
62+
63+
output[ sub_directory_name ] = { "name" : sub_directory_name, "libdir" : sub_directory_path, "include" : sub_directory_name, "memorymode" : sub_directory_path + '/cmm/' }
64+
except:
65+
pass
66+
67+
return output
68+
69+
def create_json_file( self, data, file_name ):
70+
file = open( file_name, 'w' )
71+
json.dump( data, file )
72+
file.close()
73+
74+
print json.load(open(os.getcwd() + "/lib-descriptor.json"))
75+
76+
def askdirectory(self, **options):
77+
"Ask for a directory name"
78+
79+
return apply(self.Chooser, (), options).show()
80+
81+
class Chooser(Dialog):
82+
83+
command = "tk_chooseDirectory"
84+
85+
def _fixresult(self, widget, result):
86+
if result:
87+
# keep directory until next time
88+
self.options["initialdir"] = result
89+
self.directory = result # compatibility
90+
return result
91+
92+
#
93+
# convenience stuff
94+
95+
if __name__ == '__main__':
96+
tkMessageBox.showinfo( "ERROR", "This program cannot be run as a standalone application" )
97+
98+
#library_finder_test = propc_library_finder()

c_code_file

Whitespace-only changes.

0 commit comments

Comments
 (0)