Beispiel #1
0
 def compile(self):
   code = self.code_textedit.toPlainText()
   if code == "": return
   compilation_failed_last_time = self.executed_footprint == []
   self.executed_footprint = []
   (error_txt, status_txt, interim) = pycoffee.compile_coffee(code)
   if interim != None:
     self.executed_footprint = interim
     self.result_textedit.setPlainText(str(interim))
     if self.auto_zoom.isChecked():
       (dx, dy, x1, y1, x2, y2) = inter.size(interim)
       self.update_zoom(dx, dy, x1, y1, x2, y2)
     filter_out = []
     if not self.display_docu: filter_out.append('docu')
     if not self.display_restrict: filter_out.append('restrict')
     if not self.display_stop: filter_out.append('stop')
     if not self.display_keepout: filter_out.append('keepout')
     self.glw.set_shapes(inter.prepare_for_display(interim, filter_out))
     if not self.explorer.active_footprint.readonly:
       with open(self.explorer.active_footprint_file(), "w+") as f:
         f.write(code)
     if compilation_failed_last_time:
       self.status("Compilation successful.")
     [s1, s2] = self.lsplitter.sizes()
     self.lsplitter.setSizes([s1+s2, 0])
   else:
     self.executed_footprint = []
     self.result_textedit.setPlainText(error_txt)
     self.status(status_txt)
     [s1, s2] = self.lsplitter.sizes()
     self.lsplitter.setSizes([s1+s2-150, 150])
Beispiel #2
0
 def zoom(self):
   self.glw.zoomfactor = int(self.zoom_selector.text())
   self.glw.zoom_changed = True
   self.glw.auto_zoom = self.auto_zoom.isChecked()
   if self.glw.auto_zoom:
     (dx, dy, x1, y1, x2, y2) = inter.size(self.executed_footprint)
     self.update_zoom(dx, dy, x1, y1, x2, y2, True)
   self.glw.updateGL()
Beispiel #3
0
 def compile(self):
   code = self.te1.toPlainText()
   compilation_failed_last_time = self.executed_footprint == []
   self.executed_footprint = []
   try:
     interim = pycoffee.eval_coffee_footprint(code)
     if interim != None:
       interim = inter.cleanup_js(interim)
       interim = inter.add_names(interim)
     self.executed_footprint = interim
     self.te2.setPlainText(str(interim))
     if self.auto_zoom.isChecked():
       (dx, dy, x1, y1, x2, y2) = inter.size(interim)
       self.update_zoom(dx, dy, x1, y1, x2, y2)
     filter_out = []
     if not self.display_docu: filter_out.append('docu')
     if not self.display_restrict: filter_out.append('restrict')
     self.glw.set_shapes(inter.prepare_for_display(interim, filter_out))
     if not self.is_fresh_from_file:
       with open(self.active_footprint_file(), "w+") as f:
         f.write(code)
     if compilation_failed_last_time:
       self.status("Compilation successful.")
     [s1, s2] = self.lsplitter.sizes()
     self.lsplitter.setSizes([s1+s2, 0])
   # TODO: get rid of exception handling code duplication
   except pycoffee.JSError as ex:
     self.executed_footprint = []
     s = str(ex)
     s = s.replace('JSError: Error: ', '')
     self.te2.setPlainText('coffee error:\n' + s)
     self.status(s)
     [s1, s2] = self.lsplitter.sizes()
     self.lsplitter.setSizes([s1+s2-150, 150])
   except (ReferenceError, IndexError, AttributeError, SyntaxError, TypeError, NotImplementedError) as ex:
     self.executed_footprint = []
     self.te2.setPlainText('coffee error:\n' + str(ex))
     print traceback.format_exc()
     self.status(str(ex))
     [s1, s2] = self.lsplitter.sizes()
     self.lsplitter.setSizes([s1+s2-150, 150])
   except RuntimeError as ex:
     if str(ex) == 'maximum recursion depth exceeded while calling a Python object':
       msg = 'Error: please make sure your coffeescript does not contain self-referencing recursive elements because those can\'t be compiled into a result at the moment'
     else:
       tb = traceback.format_exc()
       msg = str(ex) + "\n"+tb
     self.executed_footprint = []
     self.te2.setPlainText(msg)
     [s1, s2] = self.lsplitter.sizes()
     self.lsplitter.setSizes([s1+s2-150, 150])
   except Exception as ex:
     self.executed_footprint = []
     tb = traceback.format_exc()
     self.te2.setPlainText('other error:\n' + str(ex) + "\n"+tb)
     self.status(str(ex))
     [s1, s2] = self.lsplitter.sizes()
     self.lsplitter.setSizes([s1+s2-150, 150])