2323import traceback
2424from ctypes import c_uint
2525
26+ import logging
27+
28+ LOG = logging .getLogger (__name__ )
29+
2630"""
2731Dev Notes:
2832- Chad Still does not understand why the stat mixin is needed? Seems it only populates a status object which we instatiate here?
@@ -89,7 +93,7 @@ def draw_lines(self, lines, for_selection, j=0, geometry=None):
8993 """
9094 out_list = []
9195 if len (lines ) < 0 :
92- print ("No lines to draw, returning empty list." )
96+ LOG . info ("No lines to draw, returning empty list." )
9397 return None
9498 for line in lines :
9599 out_list .append (line [1 ][0 ])
@@ -108,7 +112,7 @@ def draw_dwells(self, dwells, alpha, for_selection, j0=0):
108112 """
109113 out_list = []
110114 if len (dwells ) < 0 :
111- print ("No dwells to draw, returning empty list." )
115+ LOG . info ("No dwells to draw, returning empty list." )
112116 return None
113117 for dwell in dwells :
114118 out_list .append (dwell [0 ][0 ])
@@ -126,7 +130,7 @@ def highlight(self, lineno, geometry):
126130 """
127131 out_list = []
128132 if lineno < 0 or lineno >= len (self .feed ):
129- print (f"Invalid line number { lineno } , returning empty list." )
133+ LOG . info (f"Invalid line number { lineno } , returning empty list." )
130134 return None
131135 line = self .feed [lineno ]
132136 out_list .append (line [1 ][0 ])
@@ -187,15 +191,15 @@ def load_ini_settings(self):
187191 try :
188192 test = temp % 1.234
189193 except :
190- print ("Error: invalid [DISPLAY] DRO_FORMAT_IN in INI file" )
194+ LOG . warning ("Error: invalid [DISPLAY] DRO_FORMAT_IN in INI file" )
191195 else :
192196 self .dro_in = temp
193197 if self .inifile .find ("DISPLAY" , "DRO_FORMAT_MM" ):
194198 temp = self .inifile .find ("DISPLAY" , "DRO_FORMAT_MM" )
195199 try :
196200 test = temp % 1.234
197201 except :
198- print ("Error: invalid [DISPLAY] DRO_FORMAT_MM in INI file" )
202+ LOG . warning ("Error: invalid [DISPLAY] DRO_FORMAT_MM in INI file" )
199203 else :
200204 self .dro_mm = temp
201205 self .dro_in = temp
@@ -219,7 +223,8 @@ def init_gl(self):
219223
220224 if not glGetShaderiv (vertex_shader , GL_COMPILE_STATUS ):
221225 error = glGetShaderInfoLog (vertex_shader )
222- print (f"Vertex shader compilation failed: { error } " )
226+ LOG .error (f"Vertex shader compilation failed: { error } " )
227+ sys .exit (1 )
223228 return
224229
225230 fragment_shader = glCreateShader (GL_FRAGMENT_SHADER )
@@ -228,8 +233,8 @@ def init_gl(self):
228233
229234 if not glGetShaderiv (fragment_shader , GL_COMPILE_STATUS ):
230235 error = glGetShaderInfoLog (fragment_shader )
231- print (f"Fragment shader compilation failed: { error } " )
232- return
236+ LOG . error (f"Fragment shader compilation failed: { error } " )
237+ sys . exit ( 1 )
233238
234239 # Section 3: ============== SHADER PROGRAM =========================
235240 self .shader_program = glCreateProgram ()
@@ -238,9 +243,9 @@ def init_gl(self):
238243 glLinkProgram (self .shader_program )
239244
240245 if not glGetProgramiv (self .shader_program , GL_LINK_STATUS ):
241- print (glGetProgramInfoLog (self .shader_program ))
242- print (f"Shader program linking failed: { error } " )
243- return
246+ LOG . error (glGetProgramInfoLog (self .shader_program ))
247+ LOG . error (f"Shader program linking failed: { error } " )
248+ sys . exit ( 1 )
244249
245250 # Clean up shaders as they're linked into program now and no longer necessary
246251 glDetachShader (self .shader_program , vertex_shader )
@@ -385,7 +390,7 @@ def draw_bounding_box(self):
385390 Draw the bounding box around the G-code extents.
386391 """
387392 if self .canon is None :
388- print ("No canon set, cannot draw bounding box." )
393+ LOG . warning ("No canon set, cannot draw bounding box." )
389394 return
390395
391396 # Draw the triangle
@@ -417,7 +422,7 @@ def draw_machine_limits(self):
417422 Draw the machine limits as a cube.
418423 """
419424 if self .canon is None :
420- print ("No canon set, cannot draw machine limits." )
425+ LOG . warning ("No canon set, cannot draw machine limits." )
421426 return
422427
423428 # Draw the triangle
@@ -432,7 +437,7 @@ def gcode_render(self):
432437 Render the OpenGL scene.
433438 """
434439 if self .canon is None :
435- print ("No canon set, cannot render." )
440+ LOG . warning ("No canon set, cannot render." )
436441 return
437442 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT )
438443
@@ -443,10 +448,10 @@ def gcode_render(self):
443448 glBindBuffer (GL_ARRAY_BUFFER , self .VBO_FEED )
444449 self .vertices = self .canon .draw_lines (self .canon .feed , for_selection = False )
445450 if self .vertices is None :
446- print ("No vertices to render." )
451+ LOG . debug ("No Feeds to render." )
447452 return
448453
449- glBufferData (GL_ARRAY_BUFFER , len (self .vertices ) * 4 , self .vertices , GL_STATIC_DRAW )
454+ glBufferData (GL_ARRAY_BUFFER , len (self .vertices ) * 4 , self .vertices , GL_STREAM_DRAW )
450455 position_loc = glGetAttribLocation (self .shader_program , "position" )
451456 glVertexAttribPointer (position_loc , 3 , GL_FLOAT , GL_FALSE , 0 , None )
452457 glEnableVertexAttribArray (position_loc )
@@ -458,7 +463,7 @@ def gcode_render(self):
458463 f_colors .extend ((1 , 0.6 , 0 , 1.00 ))
459464 f_colors = (c_float * len (f_colors ))(* f_colors )
460465
461- glBufferData (GL_ARRAY_BUFFER , len (f_colors ) * 4 , f_colors , GL_STATIC_DRAW )
466+ glBufferData (GL_ARRAY_BUFFER , len (f_colors ) * 4 , f_colors , GL_STREAM_DRAW )
462467 color_loc = glGetAttribLocation (self .shader_program , "color" )
463468 glVertexAttribPointer (color_loc , 4 , GL_FLOAT , GL_FALSE , 0 , None )
464469 glEnableVertexAttribArray (color_loc )
@@ -469,9 +474,9 @@ def gcode_render(self):
469474 glBindBuffer (GL_ARRAY_BUFFER , self .VBO_ARC )
470475 self .vertices = self .canon .draw_lines (self .canon .arcfeed , for_selection = False )
471476 if self .vertices is None :
472- print ("No arc vertices to render." )
477+ LOG . debug ("No arc vertices to render." )
473478 return
474- glBufferData (GL_ARRAY_BUFFER , len (self .vertices ) * 4 , self .vertices , GL_STATIC_DRAW )
479+ glBufferData (GL_ARRAY_BUFFER , len (self .vertices ) * 4 , self .vertices , GL_STREAM_DRAW )
475480 position_loc = glGetAttribLocation (self .shader_program , "position" )
476481 glVertexAttribPointer (position_loc , 3 , GL_FLOAT , GL_FALSE , 0 , None )
477482 glEnableVertexAttribArray (position_loc )
@@ -483,7 +488,7 @@ def gcode_render(self):
483488 f_colors .extend ((1 , 0.6 , 0 , 1.00 ))
484489 f_colors = (c_float * len (f_colors ))(* f_colors )
485490
486- glBufferData (GL_ARRAY_BUFFER , len (f_colors ) * 4 , f_colors , GL_STATIC_DRAW )
491+ glBufferData (GL_ARRAY_BUFFER , len (f_colors ) * 4 , f_colors , GL_STREAM_DRAW )
487492 color_loc = glGetAttribLocation (self .shader_program , "color" )
488493 glVertexAttribPointer (color_loc , 4 , GL_FLOAT , GL_FALSE , 0 , None )
489494 glEnableVertexAttribArray (color_loc )
@@ -622,7 +627,7 @@ def load_file(self, filename):
622627 Load a G-code file and parse it.
623628 """
624629 if not os .path .exists (filename ):
625- print (f"File { filename } does not exist." )
630+ LOG . warning (f"File { filename } does not exist." )
626631 return
627632
628633 self .status .poll ()
@@ -635,7 +640,7 @@ def load_file(self, filename):
635640 # Classic GlCanon seems to have some issues with G92 and G54-G59
636641 self .canon .parameter_file = self .parrr
637642
638- print (f"Loading { self .filename } with parameters from { self .canon .parameter_file } " )
643+ LOG . debug (f"Loading { self .filename } with parameters from { self .canon .parameter_file } " )
639644
640645 # TODO: Unit Codes
641646 # TODO: This is a blocking function that blocks the UI.
@@ -646,7 +651,7 @@ def load_file(self, filename):
646651 if result <= gcode .MIN_ERROR :
647652 pass
648653 else :
649- print ("Error parsing G-code file." )
654+ LOG . error ("Error parsing G-code file." )
650655
651656 def mousePressEvent (self , e ):
652657
0 commit comments