def play(): """Play the current file. This only does something if the current file is a pyFormex script. """ if GD.canPlay: draw.play(GD.cfg['curfile'])
def runApp(args): """Create and run the qt application.""" GD.app = QtGui.QApplication(args) QtCore.QObject.connect(GD.app, QtCore.SIGNAL("lastWindowClosed()"), GD.app, QtCore.SLOT("quit()")) # Set some globals GD.image_formats_qt = map(str, QtGui.QImageWriter.supportedImageFormats()) GD.image_formats_qtr = map(str, QtGui.QImageReader.supportedImageFormats()) if GD.cfg.get("imagesfromeps", False): GD.image_formats_qt = [] if GD.options.debug: print "Qt image types for saving: ", GD.image_formats_qt print "Qt image types for input: ", GD.image_formats_qtr print "gl2ps image types:", GD.image_formats_gl2ps print "image types converted from EPS:", GD.image_formats_fromeps # create GUI, show it, run it windowname = GD.Version count = 0 while windowExists(windowname): if count > 255: print "Can not open the main window --- bailing out" return 1 count += 1 windowname = "%s (%s)" % (GD.Version, count) if GD.cfg.has_key("gui/fontsize"): setFontSize() GD.gui = GUI(windowname, GD.cfg["gui/size"], GD.cfg["gui/pos"]) GD.gui.setcurfile() GD.board = GD.gui.board GD.canvas = GD.gui.canvas GD.gui.show() # Create additional menus (put them in a list to save) menus = [] # History history = GD.cfg["history"] if type(history) == list: m = scriptsMenu.ScriptsMenu("History", files=history, max=10) GD.gui.insertMenu(m) menus.append(m) GD.gui.history = m # Create a menu with pyFormex examples # and insert it before the help menu for title, dir in GD.cfg["scriptdirs"]: m = scriptsMenu.ScriptsMenu(title, dir, autoplay=True) GD.gui.insertMenu(m) menus.append(m) GD.board.write(GD.Version + " (C) B. Verhegghe") # remaining args are interpreted as scripts for arg in args: if os.path.exists(arg): draw.play(arg) GD.app_started = True GD.debug("Using window name %s" % GD.gui.windowTitle()) GD.app.exec_() # store the main window size/pos GD.cfg["history"] = GD.gui.history.files GD.cfg.update({"size": GD.gui.Size(), "pos": GD.gui.Pos()}, name="gui") return 0
def runScript(self,filename): """Run the specified script.""" self.current = filename selected = self.fileName(filename) GD.debug("Playing script %s" % selected) GD.gui.setcurfile(selected) if self.autoplay: draw.play()
def runScript(self,filename): """Run the specified script.""" self.current = filename selected = self.fileName(filename) GD.debug("Playing script %s" % selected) GD.GUI.setcurfile(selected) if self.autoplay: GD.debug("Drawing Options: %s" % GD.canvas.options) draw.reset() draw.play()
def runScript(self,filename): """Run the specified script.""" self.current = filename if self.dir: selected = os.path.join(self.dir,filename+'.py') else: selected = filename GD.debug("Playing script %s" % selected) GD.gui.setcurfile(selected) if self.autoplay: draw.play()
def runApp(args): """Create and run the qt application.""" GD.app = QtGui.QApplication(args) QtCore.QObject.connect(GD.app,QtCore.SIGNAL("lastWindowClosed()"),GD.app,QtCore.SLOT("quit()")) # Set some globals GD.image_formats_qt = map(str,QtGui.QImageWriter.supportedImageFormats()) GD.image_formats_qtr = map(str,QtGui.QImageReader.supportedImageFormats()) if GD.cfg.get('imagesfromeps',False): print "REMOVING qt image saving" GD.image_formats_qt = [] print GD.image_formats_qt print GD.image_formats_gl2ps print GD.image_formats_fromeps if GD.options.debug: print "Image types for saving: ",GD.image_formats_qt print "Image types for input: ",GD.image_formats_qtr # create GUI, show it, run it if GD.cfg.has_key('gui/fontsize'): setFontSize() GD.gui = GUI(GD.cfg['gui/size'],GD.cfg['gui/pos']) GD.gui.setcurfile() GD.board = GD.gui.board GD.canvas = GD.gui.canvas #print "Canvas Created" GD.gui.main.show() # This creates the X Error ### #print "GUI available" GD.board.add(GD.Version+" (C) B. Verhegghe") # remaining args are interpreted as scripts for arg in args: if os.path.exists(arg): draw.play(arg) GD.app_started = True GD.app.exec_() # store the main window size/pos GD.cfg.update({'size':GD.gui.size(),'pos':GD.gui.pos()},name='gui')
def runApp(args): """Create and run the qt application.""" GD.app = QtGui.QApplication(args) QtCore.QObject.connect(GD.app,QtCore.SIGNAL("lastWindowClosed()"),GD.app,QtCore.SLOT("quit()")) QtCore.QObject.connect(GD.app,QtCore.SIGNAL("aboutToQuit()"),quit) # Set some globals GD.image_formats_qt = map(str,QtGui.QImageWriter.supportedImageFormats()) GD.image_formats_qtr = map(str,QtGui.QImageReader.supportedImageFormats()) if GD.cfg.get('imagesfromeps',False): GD.image_formats_qt = [] if GD.options.debug: print "Qt image types for saving: ",GD.image_formats_qt print "Qt image types for input: ",GD.image_formats_qtr print "gl2ps image types:",GD.image_formats_gl2ps print "image types converted from EPS:",GD.image_formats_fromeps # create GUI, show it, run it windowname = GD.Version count = 0 while windowExists(windowname): if count > 255: print "Can not open the main window --- bailing out" return 1 count += 1 windowname = '%s (%s)' % (GD.Version,count) GD.gui = GUI(windowname, GD.cfg.get('gui/size',(800,600)), GD.cfg.get('gui/pos',(0,0)), GD.cfg.get('gui/bdsize',(800,600)) ) # set the appearence GD.gui.setStyle(GD.cfg.get('gui/style','Plastique')) font = GD.cfg.get('gui/font',None) if font: GD.gui.setFont(font) else: fontfamily = GD.cfg.get('gui/fontfamily',None) if fontfamily: GD.gui.setFontFamily(fontfamily) fontsize = GD.cfg.get('gui/fontsize',None) if fontsize: GD.gui.setFontSize(fontsize) GD.gui.viewports.addView(0,0) GD.board = GD.gui.board GD.board.write("""%s (C) B. Verhegghe pyFormex comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. See Help->License or the file COPYING for details. """ % GD.Version) GD.gui.show() # Create additional menus (put them in a list to save) # History Menu history = GD.cfg.get('history',None) if type(history) == list: GD.gui.history = scriptsMenu.ScriptsMenu('History',files=history,max=20) if GD.cfg.get('gui/history_in_main_menu',False): before = GD.gui.menu.item('help').menuAction() GD.gui.menu.insertMenu(before,GD.gui.history) else: filemenu = GD.gui.menu.item('file') before = filemenu.item('---1') filemenu.insertMenu(before,GD.gui.history) # Create a menu with pyFormex examples # and insert it before the help menu menus = [] scriptdirs = GD.cfg['scriptdirs'] knownscriptdirs = { 'examples': GD.cfg['examplesdir'] } #print "KNOWN", knownscriptdirs if GD.cfg.get('gui/separate_script_dirs',False): # This will create seperate menus for all scriptdirs pass else: # The default is to collect all scriptdirs in a single main menu if len(scriptdirs) > 1: scriptsmenu = widgets.Menu('Scripts',GD.gui.menu) before = GD.gui.menu.item('help').menuAction() GD.gui.menu.insertMenu(before,scriptsmenu) before = None else: scriptsmenu = GD.gui.menu before = scriptsmenu.itemAction('help') for title,dirname in scriptdirs: GD.debug("Loading script dir %s" % dirname) if not dirname: dirname = knownscriptdirs[title.lower()] if os.path.exists(dirname): m = scriptsMenu.ScriptsMenu(title,dirname,autoplay=True) scriptsmenu.insert_menu(m,before) menus.append(m) # Needed to keep m linked to a name, # else the menu is destroyed! # Set interaction functions GD.message = draw.message GD.warning = draw.warning draw.reset() # Load plugins import plugins for p in GD.cfg.get('gui/plugins',[]): m = getattr(plugins,p) if hasattr(m,'show_menu'): m.show_menu() GD.gui.update() # remaining args are interpreted as scripts for arg in args: if os.path.exists(arg): draw.play(arg) GD.app_started = True GD.debug("Using window name %s" % GD.gui.windowTitle()) GD.app.exec_() # Cleanup draw.drawrelease() # store the main window size/pos GD.cfg['history'] = GD.gui.history.files GD.cfg.update({'size':Size(GD.gui), 'pos':Pos(GD.gui), 'bdsize':Size(GD.gui.board), },name='gui') return 0
def runApp(args): """Create and run the qt application.""" GD.app = QtGui.QApplication(args) QtCore.QObject.connect(GD.app,QtCore.SIGNAL("lastWindowClosed()"),GD.app,QtCore.SLOT("quit()")) QtCore.QObject.connect(GD.app,QtCore.SIGNAL("aboutToQuit()"),quit) # Set some globals GD.image_formats_qt = map(str,QtGui.QImageWriter.supportedImageFormats()) GD.image_formats_qtr = map(str,QtGui.QImageReader.supportedImageFormats()) if GD.cfg.get('imagesfromeps',False): GD.image_formats_qt = [] if GD.options.debug: print "Qt image types for saving: ",GD.image_formats_qt print "Qt image types for input: ",GD.image_formats_qtr print "gl2ps image types:",GD.image_formats_gl2ps print "image types converted from EPS:",GD.image_formats_fromeps # Load the splash image splash = None if os.path.exists(GD.cfg['gui/splash']): GD.debug('Loading splash %s' % GD.cfg['gui/splash']) splashimage = QtGui.QPixmap(GD.cfg['gui/splash']) splash = QtGui.QSplashScreen(splashimage) splash.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) splash.setFont(QtGui.QFont("Helvetica",24)) splash.showMessage(GD.Version,QtCore.Qt.AlignHCenter,QtCore.Qt.red) splash.show() # create GUI, show it, run it viewport.setOpenGLFormat() dri = viewport.opengl_format.directRendering() windowname = GD.Version count = 0 while windowExists(windowname): if count > 255: print "Can not open the main window --- bailing out" return 1 count += 1 windowname = '%s (%s)' % (GD.Version,count) if count > 0: warning = """ Another instance of pyFormex is already running on this screen. This may be a leftover from a previously crashed program. In that case you should bail out now and first kill the crashed program. On the other hand, if you really want to run another pyFormex in parallel, you can just continue now. """ actions = ['Really Continue','Bail out and fix the problem'] if dri: answer = draw.ask(warning,actions) if not dri: warning += """ I have detected that the Direct Rendering Infrastructure is not activated on your system. Continuing with a second instance of pyFormex may crash you XWindow system. You should seriously consider to bail out now!!! """ answer = draw.warning(warning,actions) if answer != 'Really Continue': return 1 GD.gui = GUI(windowname, GD.cfg.get('gui/size',(800,600)), GD.cfg.get('gui/pos',(0,0)), GD.cfg.get('gui/bdsize',(800,600)) ) # set the appearence GD.gui.setStyle(GD.cfg.get('gui/style','Plastique')) font = GD.cfg.get('gui/font',None) if font: GD.gui.setFont(font) else: fontfamily = GD.cfg.get('gui/fontfamily',None) if fontfamily: GD.gui.setFontFamily(fontfamily) fontsize = GD.cfg.get('gui/fontsize',None) if fontsize: GD.gui.setFontSize(fontsize) GD.gui.viewports.changeLayout(1) GD.gui.viewports.setCurrent(0) GD.board = GD.gui.board GD.board.write("""%s (C) B. Verhegghe pyFormex comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. See Help->License or the file COPYING for details. """ % GD.Version) GD.gui.show() GD.debug("Using window name %s" % GD.gui.windowTitle()) # Create additional menus (put them in a list to save) # History Menu history = GD.cfg.get('history',None) if type(history) == list: GD.gui.history = scriptsMenu.ScriptsMenu('History',files=history,max=20) if GD.cfg.get('gui/history_in_main_menu',False): before = GD.gui.menu.item('help').menuAction() GD.gui.menu.insertMenu(before,GD.gui.history) else: filemenu = GD.gui.menu.item('file') before = filemenu.item('---1') filemenu.insertMenu(before,GD.gui.history) # Create a menu with pyFormex examples # and insert it before the help menu menus = [] scriptdirs = GD.cfg['scriptdirs'] knownscriptdirs = { 'examples': GD.cfg['examplesdir'] } if GD.cfg.get('gui/separate_script_dirs',False): # This will create separate menus for all scriptdirs pass else: # The default is to collect all scriptdirs in a single main menu if len(scriptdirs) > 1: scriptsmenu = widgets.Menu('Scripts',GD.gui.menu) before = GD.gui.menu.item('help').menuAction() GD.gui.menu.insertMenu(before,scriptsmenu) before = None else: scriptsmenu = GD.gui.menu before = scriptsmenu.itemAction('help') for title,dirname in scriptdirs: GD.debug("Loading script dir %s" % dirname) if not dirname: dirname = knownscriptdirs[title.lower()] if os.path.exists(dirname): m = scriptsMenu.ScriptsMenu(title,dirname,autoplay=True) scriptsmenu.insert_menu(m,before) menus.append(m) # Needed to keep m linked to a name, # else the menu is destroyed! # Set interaction functions GD.message = draw.message GD.warning = draw.warning draw.reset() # Load plugins, ignore if not found import plugins for p in GD.cfg.get('gui/plugins',[]): try: m = getattr(plugins,p) if hasattr(m,'show_menu'): m.show_menu() except: GD.debug('ERROR while loading plugin %s' % p) GD.gui.setBusy(False) GD.gui.update() # remove the splash window if splash is not None: splash.finish(GD.gui) # Add the autorun script to the remaining args if GD.gui.easter_egg: draw.playScript(utils.mergeme(*GD.gui.easter_egg)) ar = GD.cfg.get('autorun','') if ar: if type(ar) == str: ar = [ar] args = ar + args # remaining args are interpreted as scripts for arg in args: if os.path.exists(arg): draw.play(arg) GD.gui.setBusy(False) GD.gui.update() if os.path.isdir(GD.cfg['workdir']): # Make the workdir the current dir os.chdir(GD.cfg['workdir']) else: # Save the current dir as workdir GD.cfg['workdir'] = os.getcwd() GD.app_started = True GD.app.exec_() # Cleanup draw.drawrelease() GD.gui.setBusy(False) # store the history and main window size/pos GD.cfg['history'] = GD.gui.history.files # Sometimes, a negative value is stored, making restart partially obscured x,y = Pos(GD.gui) if x < 0: x = 0 if y < 0: y = 0 GD.cfg.update({'size':Size(GD.gui), 'pos':(x,y), 'bdsize':Size(GD.gui.board), },name='gui') return 0
def stl_menu(): draw.play(os.path.join(GD.cfg['pyformexdir'],'plugins','stl_menu.py'))
def runApp(args): """Create and run the qt application.""" GD.app = QtGui.QApplication(args) QtCore.QObject.connect(GD.app,QtCore.SIGNAL("lastWindowClosed()"),GD.app,QtCore.SLOT("quit()")) QtCore.QObject.connect(GD.app,QtCore.SIGNAL("aboutToQuit()"),quit) # Set some globals GD.image_formats_qt = map(str,QtGui.QImageWriter.supportedImageFormats()) GD.image_formats_qtr = map(str,QtGui.QImageReader.supportedImageFormats()) if GD.cfg.get('imagesfromeps',False): GD.image_formats_qt = [] if GD.options.debug: print "Qt image types for saving: ",GD.image_formats_qt print "Qt image types for input: ",GD.image_formats_qtr print "gl2ps image types:",GD.image_formats_gl2ps print "image types converted from EPS:",GD.image_formats_fromeps # create GUI, show it, run it windowname = GD.Version count = 0 while windowExists(windowname): if count > 255: print "Can not open the main window --- bailing out" return 1 count += 1 windowname = '%s (%s)' % (GD.Version,count) if GD.cfg.has_key('gui/fontsize'): setFontSize() GD.gui = GUI(windowname, GD.cfg.get('gui/size',(800,600)), GD.cfg.get('gui/pos',(0,0)), GD.cfg.get('gui/bdsize',(800,600)) ) GD.gui.viewports.addView(0,0) GD.gui.setcurfile() GD.board = GD.gui.board GD.board.write(GD.Version+" (C) B. Verhegghe") GD.gui.show() # Create additional menus (put them in a list to save) menus = [] # History history = GD.cfg.get('history',None) if type(history) == list: m = scriptsMenu.ScriptsMenu('History',files=history,max=10) GD.gui.menu.insertMenu(m) #menus.append(m) GD.gui.history = m # Create a menu with pyFormex examples # and insert it before the help menu for title,dir in GD.cfg['scriptdirs']: GD.debug("Loading script dir %s" % dir) if os.path.exists(dir): m = scriptsMenu.ScriptsMenu(title,dir,autoplay=True) GD.gui.menu.insertMenu(m) menus.append(m) # Needed to keep m linked to a name, # else the menu is destroyed! GD.message = draw.message draw.reset() # Load plugins # This should be replaced with a plugin registering function # in the plugin __init__ ? for p in GD.cfg.get('gui/plugins',[]): print "loading plugin: %s" % p if p == 'stl': from plugins import stl_menu stl_menu.show_menu() elif p == 'formex': from plugins import formex_menu formex_menu.show_menu() GD.gui.update() # remaining args are interpreted as scripts for arg in args: if os.path.exists(arg): draw.play(arg) GD.app_started = True GD.debug("Using window name %s" % GD.gui.windowTitle()) GD.app.exec_() # Cleanup draw.drawrelease() # store the main window size/pos GD.cfg['history'] = GD.gui.history.files GD.cfg.update({'size':Size(GD.gui), 'pos':Pos(GD.gui), 'bdsize':Size(GD.gui.board), },name='gui') return 0
def runApp(args): """Create and run the qt application.""" # # FIX FOR A BUG IN NUMPY (It's always sane anyway) # import locale GD.debug("LC_NUMERIC = %s" % locale.setlocale(locale.LC_NUMERIC)) # GD.app = QtGui.QApplication(args) # GD.debug("LC_NUMERIC = %s" % locale.setlocale(locale.LC_NUMERIC)) locale.setlocale(locale.LC_NUMERIC, 'C') GD.debug("LC_NUMERIC = %s" % locale.setlocale(locale.LC_NUMERIC)) # # # QtCore.QObject.connect(GD.app,QtCore.SIGNAL("lastWindowClosed()"),GD.app,QtCore.SLOT("quit()")) QtCore.QObject.connect(GD.app,QtCore.SIGNAL("aboutToQuit()"),quit) # Load the splash image splash = None if os.path.exists(GD.cfg['gui/splash']): GD.debug('Loading splash %s' % GD.cfg['gui/splash']) splashimage = QtGui.QPixmap(GD.cfg['gui/splash']) splash = QtGui.QSplashScreen(splashimage) splash.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) splash.setFont(QtGui.QFont("Helvetica",24)) splash.showMessage(GD.Version,QtCore.Qt.AlignHCenter,QtCore.Qt.red) splash.show() # create GUI, show it, run it viewport.setOpenGLFormat() dri = viewport.opengl_format.directRendering() windowname = GD.Version count = 0 while windowExists(windowname): if count > 255: print "Can not open the main window --- bailing out" return 1 count += 1 windowname = '%s (%s)' % (GD.Version,count) if count > 0: warning = """ Another instance of pyFormex is already running on this screen. This may be a leftover from a previously crashed program. In that case you should bail out now and first kill the crashed program. On the other hand, if you really want to run another pyFormex in parallel, you can just continue now. """ actions = ['Really Continue','Bail out and fix the problem'] if dri: answer = draw.ask(warning,actions) if not dri: warning += """ I have detected that the Direct Rendering Infrastructure is not activated on your system. Continuing with a second instance of pyFormex may crash you XWindow system. You should seriously consider to bail out now!!! """ answer = draw.warning(warning,actions) if answer != 'Really Continue': return 1 GD.gui = GUI(windowname, GD.cfg.get('gui/size',(800,600)), GD.cfg.get('gui/pos',(0,0)), GD.cfg.get('gui/bdsize',(800,600)) ) # set the appearence GD.gui.setStyle(GD.cfg.get('gui/style','Plastique')) font = GD.cfg.get('gui/font',None) if font: GD.gui.setFont(font) else: fontfamily = GD.cfg.get('gui/fontfamily',None) if fontfamily: GD.gui.setFontFamily(fontfamily) fontsize = GD.cfg.get('gui/fontsize',None) if fontsize: GD.gui.setFontSize(fontsize) GD.gui.viewports.changeLayout(1) GD.gui.viewports.setCurrent(0) GD.board = GD.gui.board GD.board.write("""%s (C) B. Verhegghe pyFormex comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. See Help->License or the file COPYING for details. """ % GD.Version) GD.gui.show() GD.debug("Using window name %s" % GD.gui.windowTitle()) # Create additional menus (put them in a list to save) # History Menu history = GD.cfg.get('history',None) if type(history) == list: GD.gui.history = scriptsMenu.ScriptsMenu('History',files=history,max=20) if GD.cfg.get('gui/history_in_main_menu',False): before = GD.gui.menu.item('help').menuAction() GD.gui.menu.insertMenu(before,GD.gui.history) else: filemenu = GD.gui.menu.item('file') before = filemenu.item('---1') filemenu.insertMenu(before,GD.gui.history) # Script menu scriptmenu = createScriptMenu() # Set interaction functions GD.message = draw.message GD.warning = draw.warning draw.reset() # Load plugins, ignore if not found import plugins for p in GD.cfg.get('gui/plugins',[]): try: m = getattr(plugins,p) if hasattr(m,'show_menu'): m.show_menu() except: GD.debug('ERROR while loading plugin %s' % p) GD.gui.setBusy(False) GD.gui.update() GD.gui.addStatusBarButtons() # remove the splash window if splash is not None: splash.finish(GD.gui) # Add the autorun script to the remaining args if GD.gui.easter_egg: draw.playScript(utils.mergeme(*GD.gui.easter_egg)) ar = GD.cfg.get('autorun','') if ar: if type(ar) == str: ar = [ar] args = ar + args # remaining args are interpreted as scripts for arg in args: if os.path.exists(arg): draw.play(arg) GD.gui.setBusy(False) GD.gui.update() if os.path.isdir(GD.cfg['workdir']): # Make the workdir the current dir os.chdir(GD.cfg['workdir']) else: # Save the current dir as workdir GD.cfg['workdir'] = os.getcwd() GD.app_started = True GD.debug("Start main loop") GD.app.exec_() GD.debug("Exit main loop") return 0