def init(): if not (MacOS.WMAvailable() or WMEnable()): raise ImportError( "Can not access the window manager. Use py2app or execute with the pythonw script." ) if not NSApp(): # running outside of a bundle install() # running inside a bundle, change dir if (os.getcwd() == '/') and len(sys.argv) > 1: os.chdir(os.path.dirname(sys.argv[0])) return True
def new_figure_manager(num, *args, **kwargs): """ Create a new figure manager instance """ if not MacOS.WMAvailable(): import warnings warnings.warn( "Python is not installed as a framework. The MacOSX backend may not work correctly if Python is not installed as a framework. Please see the Python documentation for more information on installing Python as a framework on Mac OS X" ) FigureClass = kwargs.pop('FigureClass', Figure) figure = FigureClass(*args, **kwargs) canvas = FigureCanvasMac(figure) manager = FigureManagerMac(canvas, num) return manager
def pre_video_init(): """Do a bunch of OSX display initialisation magic. """ if MacOS and not MacOS.WMAvailable(): errstr = sdlmain_osx.WMEnable() if errstr != ffi.NULL: raise Exception(ffi.string(errstr)) if not sdlmain_osx.RunningFromBundleWithNSApplication(): # TODO: default icon thing. sdlmain_osx.InstallNSApplication() if (os.getcwd() == '/') and len(sys.argv) > 1: os.chdir(os.path.dirname(sys.argv[0]))
def Video_AutoInit(): """This is a function that's called from the c extension code just before the display module is initialized""" if MacOS and not MacOS.WMAvailable(): if not sdlmain_osx.WMEnable(): raise ImportError( "Can not access the window manager. Use py2app or execute with the pythonw script." ) if not sdlmain_osx.RunningFromBundleWithNSApplication(): try: default_icon_data = getResource('pygame_icon.tiff').read() except IOError: default_icon_data = None sdlmain_osx.InstallNSApplication(default_icon_data) if (os.getcwd() == '/') and len(sys.argv) > 1: os.chdir(os.path.dirname(sys.argv[0])) return True
def getappterminology(fullname, verbose=None): if not MacOS.WMAvailable(): raise RuntimeError, 'Cannot send AppleEvents, no access to window manager' import Carbon.Evt Carbon.Evt.WaitNextEvent(0, 0) if os.path.isdir(fullname): pkginfo = os.path.join(fullname, 'Contents', 'PkgInfo') if not os.path.exists(pkginfo): raise RuntimeError, 'No PkgInfo file found' tp_cr = open(pkginfo, 'rb').read() cr = tp_cr[4:8] else: cr, tp = MacOS.GetCreatorAndType(fullname) talker = aetools.TalkTo(cr) try: talker._start() except (MacOS.Error, aetools.Error) as arg: if verbose: print >> verbose, 'Warning: start() failed, continuing anyway:', arg reply = talker.send('ascr', 'gdte') return (reply[1]['----'], cr)
class GraphicsConfigurationWindow(Tkinter.Frame): """Graphics Configuration Window""" def __init__(self,master=None,**cnf): VisionEgg.config._Tkinter_used = True Tkinter.Frame.__init__(self,master,**cnf) self.winfo_toplevel().title('Vision Egg - Graphics configuration') self.pack() self.clicked_ok = 0 # So we can distinguish between clicking OK and closing the window row = 0 Tkinter.Label(self, text="Vision Egg - Graphics configuration", font=("Helvetica",14,"bold")).grid(row=row,columnspan=2) row += 1 ################## begin topframe ############################## topframe = Tkinter.Frame(self) topframe.grid(row=row,column=0,columnspan=2) topframe_row = 0 Tkinter.Label(topframe, text=self.format_string("The default value for these variables and the presence of this dialog window can be controlled via the Vision Egg config file. If this file exists in the Vision Egg user directory, that file is used. Otherwise, the configuration file found in the Vision Egg system directory is used."), ).grid(row=topframe_row,column=1,columnspan=2,sticky=Tkinter.W) topframe_row += 1 try: import _imaging, _imagingtk import ImageFile, ImageFileIO, BmpImagePlugin, JpegImagePlugin import Image,ImageTk im = Image.open(os.path.join(VisionEgg.config.VISIONEGG_SYSTEM_DIR,'data','visionegg.bmp')) self.tk_im=ImageTk.PhotoImage(im) Tkinter.Label(topframe,image=self.tk_im).grid(row=0,rowspan=topframe_row,column=0) except Exception,x: logger = logging.getLogger('VisionEgg.GUI') logger.info("No Vision Egg logo :( because of error while " "trying to display image in " "GUI.GraphicsConfigurationWindow: %s: " "%s"%(str(x.__class__),str(x))) ################## end topframe ############################## row += 1 ################## begin file_frame ############################## file_frame = Tkinter.Frame(self) file_frame.grid(row=row,columnspan=2,sticky=Tkinter.W+Tkinter.E,pady=5) # Script name and location file_row = 0 Tkinter.Label(file_frame, text="This script:").grid(row=file_row,column=0,sticky=Tkinter.E) Tkinter.Label(file_frame, text="%s"%(os.path.abspath(sys.argv[0]),)).grid(row=file_row,column=1,sticky=Tkinter.W) file_row += 1 # Vision Egg system dir Tkinter.Label(file_frame, text="Vision Egg system directory:").grid(row=file_row,column=0,sticky=Tkinter.E) Tkinter.Label(file_frame, text="%s"%(os.path.abspath(VisionEgg.config.VISIONEGG_SYSTEM_DIR),)).grid(row=file_row,column=1,sticky=Tkinter.W) file_row += 1 # Vision Egg user dir Tkinter.Label(file_frame, text="Vision Egg user directory:").grid(row=file_row,column=0,sticky=Tkinter.E) Tkinter.Label(file_frame, text="%s"%(os.path.abspath(VisionEgg.config.VISIONEGG_USER_DIR),)).grid(row=file_row,column=1,sticky=Tkinter.W) file_row += 1 # Config file Tkinter.Label(file_frame, text="Config file location:").grid(row=file_row,column=0,sticky=Tkinter.E) if VisionEgg.config.VISIONEGG_CONFIG_FILE: Tkinter.Label(file_frame, text="%s"%(os.path.abspath(VisionEgg.config.VISIONEGG_CONFIG_FILE),)).grid(row=file_row,column=1,sticky=Tkinter.W) else: Tkinter.Label(file_frame, text="(None)").grid(row=file_row,column=1,sticky=Tkinter.W) file_row += 1 # Log file location Tkinter.Label(file_frame, text="Log file location:").grid(row=file_row,column=0,sticky=Tkinter.E) if VisionEgg.config.VISIONEGG_LOG_FILE: Tkinter.Label(file_frame, text="%s"%(os.path.abspath(VisionEgg.config.VISIONEGG_LOG_FILE),)).grid(row=file_row,column=1,sticky=Tkinter.W) else: Tkinter.Label(file_frame, text="(stderr console)").grid(row=file_row,column=1,sticky=Tkinter.W) ################## end file_frame ############################## row += 1 ################## begin cf ############################## cf = Tkinter.Frame(self) cf.grid(row=row,column=0,padx=10) cf_row = 0 # Fullscreen self.fullscreen = Tkinter.BooleanVar() self.fullscreen.set(VisionEgg.config.VISIONEGG_FULLSCREEN) Tkinter.Checkbutton(cf, text='Fullscreen', variable=self.fullscreen, relief=Tkinter.FLAT).grid(row=cf_row,column=0,sticky=Tkinter.W) cf_row += 1 self.synclync_present = Tkinter.BooleanVar() self.synclync_present.set(VisionEgg.config.SYNCLYNC_PRESENT) try: import synclync self.show_synclync_option = 1 except: self.show_synclync_option = 0 if self.show_synclync_option: Tkinter.Checkbutton(cf, text='SyncLync device present', variable=self.synclync_present, relief=Tkinter.FLAT).grid(row=cf_row,column=0,sticky=Tkinter.W) cf_row += 1 # Maximum priority self.maxpriority = Tkinter.BooleanVar() self.maxpriority.set(VisionEgg.config.VISIONEGG_MAXPRIORITY) Tkinter.Checkbutton(cf, text='Maximum priority (use with caution)', variable=self.maxpriority, relief=Tkinter.FLAT).grid(row=cf_row,column=0,sticky=Tkinter.W) cf_row += 1 if sys.platform=='darwin': # Only used on darwin platform self.darwin_conventional = Tkinter.IntVar() self.darwin_conventional.set(VisionEgg.config.VISIONEGG_DARWIN_MAXPRIORITY_CONVENTIONAL_NOT_REALTIME) self.darwin_priority = Tkinter.StringVar() self.darwin_priority.set(str(VisionEgg.config.VISIONEGG_DARWIN_CONVENTIONAL_PRIORITY)) self.darwin_realtime_period_denom = Tkinter.StringVar() self.darwin_realtime_period_denom.set(str(VisionEgg.config.VISIONEGG_DARWIN_REALTIME_PERIOD_DENOM)) self.darwin_realtime_computation_denom = Tkinter.StringVar() self.darwin_realtime_computation_denom.set(str(VisionEgg.config.VISIONEGG_DARWIN_REALTIME_COMPUTATION_DENOM)) self.darwin_realtime_constraint_denom = Tkinter.StringVar() self.darwin_realtime_constraint_denom.set(str(VisionEgg.config.VISIONEGG_DARWIN_REALTIME_CONSTRAINT_DENOM)) self.darwin_realtime_preemptible = Tkinter.BooleanVar() self.darwin_realtime_preemptible.set(not VisionEgg.config.VISIONEGG_DARWIN_REALTIME_PREEMPTIBLE) Tkinter.Button(cf,text="Maximum priority options...", command=self.darwin_maxpriority_tune).grid(row=cf_row,column=0) cf_row += 1 # Sync swap self.sync_swap = Tkinter.BooleanVar() self.sync_swap.set(VisionEgg.config.VISIONEGG_SYNC_SWAP) Tkinter.Checkbutton(cf, text='Attempt vsync', variable=self.sync_swap, relief=Tkinter.FLAT).grid(row=cf_row,column=0,sticky=Tkinter.W) cf_row += 1 # Frameless window self.frameless = Tkinter.BooleanVar() self.frameless.set(VisionEgg.config.VISIONEGG_FRAMELESS_WINDOW) Tkinter.Checkbutton(cf, text='No frame around window', variable=self.frameless, relief=Tkinter.FLAT).grid(row=cf_row,column=0,sticky=Tkinter.W) cf_row += 1 # Hide mouse self.mouse_visible = Tkinter.BooleanVar() self.mouse_visible.set(not VisionEgg.config.VISIONEGG_HIDE_MOUSE) Tkinter.Checkbutton(cf, text='Mouse cursor visible', variable=self.mouse_visible, relief=Tkinter.FLAT).grid(row=cf_row,column=0,sticky=Tkinter.W) cf_row += 1 # Stereo self.stereo = Tkinter.BooleanVar() self.stereo.set(VisionEgg.config.VISIONEGG_REQUEST_STEREO) Tkinter.Checkbutton(cf, text='Stereo', variable=self.stereo, relief=Tkinter.FLAT).grid(row=cf_row,column=0,sticky=Tkinter.W) cf_row += 1 if sys.platform == 'darwin': if sys.version == '2.2 (#11, Jan 6 2002, 01:00:42) \n[GCC 2.95.2 19991024 (release)]': if Tkinter.TkVersion == 8.4: # The Tk in Bob Ippolito's kitchensink distro had # a bug in Checkbutton Tkinter.Label(cf,text="If you want to check any buttons\n(Mac OS X Tk 8.4a4 bug workaround):").grid(row=cf_row,column=0) cf_row += 1 Tkinter.Button(cf,text="PRESS ME FIRST").grid(row=cf_row,column=0) cf_row += 1 ################## end cf ############################## ################## begin entry_frame ################### entry_frame = Tkinter.Frame(self) entry_frame.grid(row=row,column=1,padx=10,sticky="n") row += 1 ef_row = 0 # frame rate Tkinter.Label(entry_frame,text="What will your monitor refresh's rate be (Hz):").grid(row=ef_row,column=0,sticky=Tkinter.E) self.frame_rate = Tkinter.StringVar() self.frame_rate.set("%s"%str(VisionEgg.config.VISIONEGG_MONITOR_REFRESH_HZ)) Tkinter.Entry(entry_frame,textvariable=self.frame_rate).grid(row=ef_row,column=1,sticky=Tkinter.W) ef_row += 1 # width Tkinter.Label(entry_frame,text="Window width (pixels):").grid(row=ef_row,column=0,sticky=Tkinter.E) self.width = Tkinter.StringVar() self.width.set("%s"%str(VisionEgg.config.VISIONEGG_SCREEN_W)) Tkinter.Entry(entry_frame,textvariable=self.width).grid(row=ef_row,column=1,sticky=Tkinter.W) ef_row += 1 # height Tkinter.Label(entry_frame,text="Window height (pixels):").grid(row=ef_row,column=0,sticky=Tkinter.E) self.height = Tkinter.StringVar() self.height.set("%s"%str(VisionEgg.config.VISIONEGG_SCREEN_H)) Tkinter.Entry(entry_frame,textvariable=self.height).grid(row=ef_row,column=1,sticky=Tkinter.W) ef_row += 1 # color depth Tkinter.Label(entry_frame,text="Requested total color depth (bits per pixel):").grid(row=ef_row,column=0,sticky=Tkinter.E) self.color_depth = Tkinter.StringVar() self.color_depth.set(str(VisionEgg.config.VISIONEGG_PREFERRED_BPP)) Tkinter.Entry(entry_frame,textvariable=self.color_depth).grid(row=ef_row,column=1,sticky=Tkinter.W) ef_row += 1 # red depth Tkinter.Label(entry_frame,text="Requested red bits per pixel:").grid(row=ef_row,column=0,sticky=Tkinter.E) self.red_depth = Tkinter.StringVar() self.red_depth.set(str(VisionEgg.config.VISIONEGG_REQUEST_RED_BITS)) Tkinter.Entry(entry_frame,textvariable=self.red_depth).grid(row=ef_row,column=1,sticky=Tkinter.W) ef_row += 1 # green depth Tkinter.Label(entry_frame,text="Requested green bits per pixel:").grid(row=ef_row,column=0,sticky=Tkinter.E) self.green_depth = Tkinter.StringVar() self.green_depth.set(str(VisionEgg.config.VISIONEGG_REQUEST_GREEN_BITS)) Tkinter.Entry(entry_frame,textvariable=self.green_depth).grid(row=ef_row,column=1,sticky=Tkinter.W) ef_row += 1 # blue depth Tkinter.Label(entry_frame,text="Requested blue bits per pixel:").grid(row=ef_row,column=0,sticky=Tkinter.E) self.blue_depth = Tkinter.StringVar() self.blue_depth.set(str(VisionEgg.config.VISIONEGG_REQUEST_BLUE_BITS)) Tkinter.Entry(entry_frame,textvariable=self.blue_depth).grid(row=ef_row,column=1,sticky=Tkinter.W) ef_row += 1 # alpha depth Tkinter.Label(entry_frame,text="Requested alpha bits per pixel:").grid(row=ef_row,column=0,sticky=Tkinter.E) self.alpha_depth = Tkinter.StringVar() self.alpha_depth.set(str(VisionEgg.config.VISIONEGG_REQUEST_ALPHA_BITS)) Tkinter.Entry(entry_frame,textvariable=self.alpha_depth).grid(row=ef_row,column=1,sticky=Tkinter.W) ef_row += 1 ################## end entry_frame ################### ################## gamma_frame ################### # gamma stuff row += 1 gamma_frame = Tkinter.Frame(self) gamma_frame.grid(row=row,columnspan=2,sticky="we") self.gamma_source = Tkinter.StringVar() self.gamma_source.set(str(VisionEgg.config.VISIONEGG_GAMMA_SOURCE).lower()) # can be 'none', 'invert', or 'file' Tkinter.Label(gamma_frame, text="Gamma:").grid(row=0,column=0) Tkinter.Radiobutton(gamma_frame, text="Native", value="none", variable = self.gamma_source).grid(row=0,column=1,padx=1) Tkinter.Radiobutton(gamma_frame, text="Quick", value="invert", variable = self.gamma_source).grid(row=0,column=2) Tkinter.Label(gamma_frame, text="R:").grid(row=0,column=3) self.gamma_invert_red = Tkinter.DoubleVar() self.gamma_invert_red.set( VisionEgg.config.VISIONEGG_GAMMA_INVERT_RED ) Tkinter.Entry(gamma_frame, textvariable=self.gamma_invert_red, width=3).grid(row=0,column=4) Tkinter.Label(gamma_frame, text="G:").grid(row=0,column=5) self.gamma_invert_green = Tkinter.DoubleVar() self.gamma_invert_green.set( VisionEgg.config.VISIONEGG_GAMMA_INVERT_GREEN ) Tkinter.Entry(gamma_frame, textvariable=self.gamma_invert_green, width=3).grid(row=0,column=6) Tkinter.Label(gamma_frame, text="B:").grid(row=0,column=7) self.gamma_invert_blue = Tkinter.DoubleVar() self.gamma_invert_blue.set( VisionEgg.config.VISIONEGG_GAMMA_INVERT_BLUE ) Tkinter.Entry(gamma_frame, textvariable=self.gamma_invert_blue, width=3).grid(row=0,column=8) Tkinter.Radiobutton(gamma_frame, text="Custom:", value="file", variable = self.gamma_source).grid(row=0,column=9) self.gamma_file = Tkinter.StringVar() if os.path.isfile(VisionEgg.config.VISIONEGG_GAMMA_FILE): self.gamma_file.set( VisionEgg.config.VISIONEGG_GAMMA_FILE ) else: self.gamma_file.set("") Tkinter.Entry(gamma_frame, textvariable=self.gamma_file, width=15).grid(row=0,column=10) Tkinter.Button(gamma_frame, command=self.set_gamma_file, text="Set...").grid(row=0,column=11) ################## end gamma_frame ################### row += 1 bf = Tkinter.Frame(self) bf.grid(row=row,columnspan=2,sticky=Tkinter.W+Tkinter.E) # Save settings to config file b = Tkinter.Button(bf,text="Save current settings to config file",command=self.save) b.grid(row=0,column=0,padx=20) b.bind('<Return>',self.start) # Start button b2 = Tkinter.Button(bf,text="ok",command=self.start) b2.grid(row=0,column=1,padx=20) b2.focus_force() b2.bind('<Return>',self.start) # Raise our application on darwin if sys.platform == 'darwin': try: # from Jack Jansen email 20 April 2003 # WMAvailable() returns true if you can use the window # manager, and as a side #effect it raises the # application to the foreground. import MacOS if not MacOS.WMAvailable(): raise "Cannot reach the window manager" except: pass
def __init__(self, redirect=_defRedirect, filename=None, useBestVisual=False, clearSigInt=True): """ Construct a ``wx.App`` object. :param redirect: Should ``sys.stdout`` and ``sys.stderr`` be redirected? Defaults to True on Windows and Mac, False otherwise. If `filename` is None then output will be redirected to a window that pops up as needed. (You can control what kind of window is created for the output by resetting the class variable ``outputWindowClass`` to a class of your choosing.) :param filename: The name of a file to redirect output to, if redirect is True. :param useBestVisual: Should the app try to use the best available visual provided by the system (only relevant on systems that have more than one visual.) This parameter must be used instead of calling `SetUseBestVisual` later on because it must be set before the underlying GUI toolkit is initialized. :param clearSigInt: Should SIGINT be cleared? This allows the app to terminate upon a Ctrl-C in the console like other GUI apps will. :note: You should override OnInit to do applicaition initialization to ensure that the system, toolkit and wxWidgets are fully initialized. """ wx.PyApp.__init__(self) if wx.Platform == "__WXMAC__": try: import MacOS if not MacOS.WMAvailable(): print """\ This program needs access to the screen. Please run with 'pythonw', not 'python', and only when you are logged in on the main display of your Mac.""" _sys.exit(1) except SystemExit: raise except: pass # This has to be done before OnInit self.SetUseBestVisual(useBestVisual) # Set the default handler for SIGINT. This fixes a problem # where if Ctrl-C is pressed in the console that started this # app then it will not appear to do anything, (not even send # KeyboardInterrupt???) but will later segfault on exit. By # setting the default handler then the app will exit, as # expected (depending on platform.) if clearSigInt: try: import signal signal.signal(signal.SIGINT, signal.SIG_DFL) except: pass # Save and redirect the stdio to a window? self.stdioWin = None self.saveStdio = (_sys.stdout, _sys.stderr) if redirect: self.RedirectStdio(filename) # Use Python's install prefix as the default wx.StandardPaths.Get().SetInstallPrefix(_sys.prefix) # This finishes the initialization of wxWindows and then calls # the OnInit that should be present in the derived class self._BootstrapApp()
def __ensure_WMAvailable(klass): if klass.__eventloop_initialized: return 1 if not MacOS.WMAvailable(): return 0 Evt.WaitNextEvent(0, 0)
__version__ = "$Id$" # # Mac GRiNS Player wrapper # DEBUG = 0 import sys import os import MacOS if not MacOS.WMAvailable(): raise 'No access to the window manager' progdir = os.path.split(sys.argv[0])[0] # This is cmif:build:macosx if not progdir: progdir = os.getcwd() ID_SPLASH_DIALOG = 513 # Assure the resource file is available from Carbon import Res try: Res.GetResource('DLOG', ID_SPLASH_DIALOG) except: import macresource macdir = os.path.join(os.path.split(progdir)[0], 'mac') macresource.open_pathname(os.path.join(macdir, 'player.rsrc'), 1) macresource.open_pathname(os.path.join(macdir, 'playercontrols.rsrc'), 1) macresource.open_pathname(os.path.join(macdir, 'common.rsrc'), 1) Res.GetResource('DLOG', ID_SPLASH_DIALOG)