1818#import MaterialX as mx
1919
2020class MaterialXFlaskApp :
21+ '''
22+ @brief Base Flask application class for MaterialX GPUOpen server interactions.
23+ '''
2124 def __init__ (self , home ):
25+ '''
26+ Initialize the Flask application and SocketIO.
27+ @param home The home page template to render.
28+ '''
2229 self .home = home
2330
2431 # Initialize Flask and SocketIO
@@ -31,9 +38,9 @@ def __init__(self, home):
3138 self ._register_socket_events ()
3239
3340 def _register_routes (self ):
34- """
41+ '''
3542 Register HTTP routes.
36- """
43+ '''
3744 @self .app .route ('/' )
3845 def home ():
3946 """
@@ -49,17 +56,20 @@ def _setup_event_handler_map(self):
4956 raise NotImplementedError ("Subclasses must implement _setup_event_handler_map" )
5057
5158 def _register_socket_events (self ):
52- """
59+ '''
5360 Register SocketIO events.
54- """
61+ '''
5562 # Dynamically register event handlers
5663 for event_name , handler in self .event_handlers .items ():
5764 self .socketio .on_event (event_name , handler )
5865
5966 def run (self , host , port , debug = True ):
60- """
67+ '''
6168 Run the Flask server with SocketIO.
62- """
69+ @param host The host address to run the server on.
70+ @param port The port to run the server on.
71+ @param debug Whether to run the server in debug mode.
72+ '''
6373 self .socketio .run (self .app , host , port , debug = debug )
6474
6575
@@ -69,9 +79,10 @@ class MaterialXGPUOpenApp(MaterialXFlaskApp):
6979 and extracting of materials by regular expression.
7080 '''
7181 def __init__ (self , homePage ):
72- """
82+ '''
7383 Initialize the Flask application and the MaterialX loader.
74- """
84+ @param homePage The home page template to render.
85+ '''
7586 super ().__init__ (homePage )
7687
7788 # Material loader and associated attributes
@@ -81,16 +92,26 @@ def __init__(self, homePage):
8192 self .material_count = 0
8293
8394 def _emit_status_message (self , message ):
84- """
85- Emit a status message to the client.
86- """
95+ '''
96+ @brief Emit a status message to the client. The message emitted is of the form:
97+ { 'message': 'message string' }
98+
99+ @param message The status message to emit.
100+ '''
87101 emit ('materialx_status' , { 'message' : message }, broadcast = True )
88102 print ('Python:' , message )
89103
90104 def handle_download_materialx (self , data ):
91- """
92- Handle the 'download_materialx' event, initialize the loader, and send materials data to the client.
93- """
105+ '''
106+ @brief Handle the 'download_materialx' event, initialize the loader, and send materials data to the client.
107+ Data is of the form:
108+ { 'materialCount': int,
109+ 'materialNames': list of strings,
110+ 'materialsList': list of material data in JSON format
111+ }
112+ @param data The data received from the client (not used in this handler).
113+
114+ '''
94115 status_message = f'Downloaded materials...'
95116 self ._emit_status_message (status_message )
96117
@@ -116,9 +137,11 @@ def handle_download_materialx(self, data):
116137 }, broadcast = True )
117138
118139 def handle_extract_material (self , data ):
119- """
120- Handle the 'extract_material' event, extract material data, and send it back to the client.
121- """
140+ '''
141+ @brief Handle the 'extract_material' event, extract material data, and send it back to the client.
142+ @param data The data received from the client, expected to contain:
143+ { 'expression': string, 'update_materialx': bool }
144+ '''
122145 if self .loader is None :
123146 self ._emit_status_message ('Loader is not initialized. Download materials first.' )
124147 return
@@ -175,20 +198,27 @@ def handle_extract_material(self, data):
175198 emit ('materialx_extracted' , {'extractedData' : return_list }, broadcast = True )
176199
177200 def _setup_event_handler_map (self ):
178- """
201+ '''
179202 Set up dictionary of mapping event names to their handlers
180- """
203+ '''
181204 self .event_handlers = {
182205 'download_materialx' : self .handle_download_materialx ,
183206 'extract_material' : self .handle_extract_material ,
184207 }
185208
186209# Main entry point
187210def main ():
211+ '''
212+ @brief Main entry point for the application. Parses command-line arguments and starts the Flask server.
213+ @detail Argument parameters are:
214+ -h/--host: Host address to run the server on (default: 127.0.0.1)
215+ -po/--port: Port to run the server on (default: 8080)
216+ -ho/--home: Home page template (default: MaterialXGPUOpenApp.html)
217+ '''
188218 parser = argparse .ArgumentParser (description = "GPUOpen MaterialX Application" )
189- parser .add_argument ('--host' , type = str , default = '127.0.0.1' , help = "Host address to run the server on (default: 127.0.0.1)" )
190- parser .add_argument ('--port' , type = int , default = 8080 , help = "Port to run the server on (default: 8080)" )
191- parser .add_argument ('--home' , type = str , default = 'MaterialXGPUOpenApp.html' , help = "Home page." )
219+ parser .add_argument ('-hs' , '- -host' , type = str , default = '127.0.0.1' , help = "Host address to run the server on (default: 127.0.0.1)" )
220+ parser .add_argument ('-p' , '- -port' , type = int , default = 8080 , help = "Port to run the server on (default: 8080)" )
221+ parser .add_argument ('-ho' , '- -home' , type = str , default = 'MaterialXGPUOpenApp.html' , help = "Home page." )
192222
193223 args = parser .parse_args ()
194224
0 commit comments