Skip to content

Commit bca1f92

Browse files
Added dynamic library support & menu stuff
- Added a new class that does the actual generation of the new library descriptor file - Added upgraded menu - Updated PropCCompiler library with the updated library paths
1 parent c6f2f50 commit bca1f92

File tree

3 files changed

+149
-16
lines changed

3 files changed

+149
-16
lines changed

BlocklyPropClient.py

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import os
1212
import ip
1313
import BlocklyServer
14+
from PropC_library_finder import propc_library_finder
1415

1516
PORT = 6009
1617
VERSION = 0.2
@@ -42,23 +43,13 @@ def __init__(self, *args, **kwargs):
4243
pass
4344

4445
self.initialize()
46+
self.initialize_menu()
4547

4648
def set_version(self, version):
4749
self.version = version
4850

4951
def initialize(self):
5052
self.grid()
51-
52-
self.menubar = tk.Menu()
53-
54-
self.about_menu = tk.Menu( self.menubar, tearoff=0 )
55-
56-
self.about_menu.add_command( label="BlocklyPropClient Source Code", command=self.handle_client_code_browser )
57-
self.about_menu.add_command( label="BlocklyProp Source Code", command=self.handle_code_browser )
58-
self.about_menu.add_separator()
59-
self.about_menu.add_command( label="About", command=self.about_info )
60-
61-
self.menubar.add_cascade( label="About", menu=self.about_menu)
6253

6354
self.lbl_ip_address = tk.Label(self, anchor=tk.E, text='IP Address :')
6455
self.lbl_ip_address.grid(column=0, row=0, sticky='nesw')
@@ -99,7 +90,6 @@ def initialize(self):
9990
self.grid_rowconfigure(4, weight=1)
10091
self.resizable(True, True)
10192
self.minsize(250, 200)
102-
self.config( menu=self.menubar )
10393

10494
self.protocol("WM_DELETE_WINDOW", self.handle_close)
10595

@@ -112,6 +102,32 @@ def initialize(self):
112102
monitor = threading.Thread(target=self.text_catcher)
113103
monitor.daemon = True
114104
monitor.start()
105+
106+
def initialize_menu( self ):
107+
menubar = tk.Menu( self )
108+
109+
file_menu = tk.Menu( menubar, tearoff=0 )
110+
file_menu.add_command( label="Save" )
111+
file_menu.add_command( label="Save As..." )
112+
file_menu.add_command( label="Open" )
113+
menubar.add_cascade( label="File", menu=file_menu )
114+
115+
about_menu = tk.Menu( menubar, tearoff=0 )
116+
about_menu.add_command( label="BlocklyPropClient Source Code", command=self.handle_client_code_browser )
117+
about_menu.add_command( label="BlocklyProp Source Code", command=self.handle_code_browser )
118+
about_menu.add_separator()
119+
about_menu.add_command( label="About", command=self.about_info )
120+
menubar.add_cascade( label="About", menu=about_menu)
121+
122+
options_menu = tk.Menu( menubar, tearoff=0 )
123+
options_menu.add_command( label="Set Library Location", command=self.handle_library_location )
124+
menubar.add_cascade( label="Options", menu=options_menu )
125+
126+
help_menu = tk.Menu( menubar, tearoff=0 )
127+
help_menu.add_command( label="Help" )
128+
menubar.add_cascade( label="Help", menu=help_menu )
129+
130+
self.config( menu=menubar )
115131

116132
def handle_connect(self):
117133
if self.connected:
@@ -137,6 +153,11 @@ def handle_code_browser( self ):
137153
def handle_client_code_browser( self ):
138154
webbrowser.open_new( 'http://github.com/parallaxinc/BlocklyPropClient' )
139155

156+
def handle_library_location( self ):
157+
library_finder = propc_library_finder()
158+
159+
tkMessageBox.showinfo( "Info", "Library Location Set To: " + library_finder.get_directory() )
160+
140161
def about_info( self ):
141162
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" )
142163

PropCCompiler.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ def compile(self, action, code):
9191

9292
def get_includes(self, includes):
9393
global lib_descriptor
94+
95+
lib_descriptor = json.load(open(os.getcwd() + "/lib-descriptor.json"))
96+
9497
descriptors = []
9598
for include in includes:
9699
for descriptor in lib_descriptor:
@@ -112,14 +115,13 @@ def parse_includes(self, c_file):
112115

113116
def create_executing_data(self, c_file, binary_file, descriptors):
114117
executable = self.compiler_executables[platform.system()]
115-
lib_directory = self.appdir + "/propeller-c-lib/"
116118

117119
executing_data = [executable]
118120
for descriptor in descriptors:
119121
executing_data.append("-I")
120-
executing_data.append(lib_directory + descriptor["libdir"])
122+
executing_data.append(descriptor["libdir"])
121123
executing_data.append("-L")
122-
executing_data.append(lib_directory + descriptor["memorymodel"]["cmm"])
124+
executing_data.append(descriptor["memorymodel"]["cmm"])
123125
executing_data.append("-Os")
124126
executing_data.append("-mcmm")
125127
executing_data.append("-m32bit-doubles")
@@ -137,4 +139,7 @@ def create_executing_data(self, c_file, binary_file, descriptors):
137139
return executing_data
138140

139141

140-
lib_descriptor = json.load(open(os.getcwd() + "/propeller-c-lib/lib-descriptor.json"))
142+
try:
143+
lib_descriptor = json.load(open(os.getcwd() + "/propeller-c-lib/lib-descriptor.json"))
144+
except:
145+
lib_descriptor = json.load(open(os.getcwd() + "/lib-descriptor.json"))

PropC_library_finder.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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 = "[\n"
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 += '\t{\n\t\t'
64+
output += '"name": "' + sub_directory_name + '",\n\t\t'
65+
output += '"libdir": "' + sub_directory_path + '",\n\t\t'
66+
output += '"include": [\n\t\t\t' + '"' + sub_directory_name + '"'
67+
output += '\n\t\t],\n\t\t'
68+
output += '"memorymodel": {\n\t\t\t"cmm": "' + sub_directory_path + '/cmm/"' + '\n\t\t}\n\t},\n'
69+
except:
70+
pass
71+
72+
output = output[:len(output) - 2]
73+
output += '\n]'
74+
75+
return output
76+
77+
def create_json_file( self, data, file_name ):
78+
file = open( file_name, 'w' )
79+
file.write( data )
80+
file.close()
81+
82+
#json.dump( unicode( data ), file_name )
83+
print json.load(open(os.getcwd() + "/lib-descriptor.json"))
84+
85+
def askdirectory(self, **options):
86+
"Ask for a directory name"
87+
88+
return apply(self.Chooser, (), options).show()
89+
90+
class Chooser(Dialog):
91+
92+
command = "tk_chooseDirectory"
93+
94+
def _fixresult(self, widget, result):
95+
if result:
96+
# keep directory until next time
97+
self.options["initialdir"] = result
98+
self.directory = result # compatibility
99+
return result
100+
101+
#
102+
# convenience stuff
103+
104+
if __name__ == '__main__':
105+
tkMessageBox.showinfo( "ERROR", "This program cannot be run as a standalone application" )
106+
107+
#library_finder_test = propc_library_finder()

0 commit comments

Comments
 (0)