The FrameWork
module contains classes that together provide a frameworkfor an interactive Macintosh application. The programmer builds an applicationby creating subclasses that override various methods of the bases classes,thereby implementing the functionality wanted. Overriding functionality canoften be done on various different levels, i.e. to handle clicks in a singledialog window in a non-standard way it is not necessary to override the completeevent handling.
Work on the FrameWork
has pretty much stopped, now that PyObjC
isavailable for full Cocoa access from Python, and the documentation describesonly the most important functionality, and not in the most logical manner atthat. Examine the source or the examples for more details. The following aresome comments posted on the MacPython newsgroup about the strengths andlimitations of FrameWork
:
Aug 10, 2012 Apple Footer. This site contains user submitted content, comments and opinions and is for informational purposes only. Apple may provide or recommend responses as a possible solution based on the information provided; every potential issue may involve several factors not detailed in the conversations captured in an electronic forum and Apple can therefore provide no guarantee as to the. What if there is no Python.framework in /Library/Frameworks/, but there is a folder named python in /Library? Can I remove this folder? – Eden Harder Nov 6 '16 at 20:02.
The strong point of FrameWork
is that it allows you to break into thecontrol-flow at many different places. W
, for instance, uses a differentway to enable/disable menus and that plugs right in leaving the rest intact.The weak points of FrameWork
are that it has no abstract commandinterface (but that shouldn’t be difficult), that its dialog support is minimaland that its control/toolbar support is non-existent.
The FrameWork
module defines the following functions:
FrameWork.
Application
()¶An object representing the complete application. See below for a description ofthe methods. The default __init__()
routine creates an empty windowdictionary and a menu bar with an apple menu.
FrameWork.
MenuBar
()¶An object representing the menubar. This object is usually not created by theuser.
FrameWork.
Menu
(bar, title[, after])¶An object representing a menu. Upon creation you pass the MenuBar
the menuappears in, the title string and a position (1-based) after where the menushould appear (default: at the end).
FrameWork.
MenuItem
(menu, title[, shortcut, callback])¶Create a menu item object. The arguments are the menu to create, the item titlestring and optionally the keyboard shortcut and a callback routine. The callbackis called with the arguments menu-id, item number within menu (1-based), currentfront window and the event record.
Instead of a callable object the callback can also be a string. In this casemenu selection causes the lookup of a method in the topmost window and theapplication. The method name is the callback string with 'domenu_'
prepended.
Calling the MenuBar
fixmenudimstate()
method sets the correct dimmingfor all menu items based on the current front window.
FrameWork.
Separator
(menu)¶Add a separator to the end of a menu.
FrameWork.
SubMenu
(menu, label)¶Create a submenu named label under menu menu. The menu object is returned.
FrameWork.
Window
(parent)¶Creates a (modeless) window. Parent is the application object to which thewindow belongs. The window is not displayed until later.
FrameWork.
DialogWindow
(parent)¶Creates a modeless dialog window.
FrameWork.
windowbounds
(width, height)¶Return a (left,top,right,bottom)
tuple suitable for creation of a windowof given width and height. The window will be staggered with respect to previouswindows, and an attempt is made to keep the whole window on-screen. However, thewindow will however always be the exact size given, so parts may be offscreen.
FrameWork.
setwatchcursor
()¶Set the mouse cursor to a watch.
FrameWork.
setarrowcursor
()¶Set the mouse cursor to an arrow.
Application objects have the following methods, among others:
Application.
makeusermenus
()¶Override this method if you need menus in your application. Append the menus tothe attribute menubar
.
Application.
getabouttext
()¶Override this method to return a text string describing your application.Alternatively, override the do_about()
method for more elaborate “about”messages.
Application.
mainloop
([mask[, wait]])¶This routine is the main event loop, call it to set your application rolling.Mask is the mask of events you want to handle, wait is the number of ticksyou want to leave to other concurrent application (default 0, which is probablynot a good idea). While raising self to exit the mainloop is still supportedit is not recommended: call self._quit()
instead.
The event loop is split into many small parts, each of which can be overridden.The default methods take care of dispatching events to windows and dialogs,handling drags and resizes, Apple Events, events for non-FrameWork windows, etc.
In general, all event handlers should return 1
if the event is fully handledand 0
otherwise (because the front window was not a FrameWork window, forinstance). This is needed so that update events and such can be passed on toother windows like the Sioux console window. Calling MacOS.HandleEvent()
is not allowed within our_dispatch or its callees, since this may result in aninfinite loop if the code is called through the Python inner-loop event handler.
Same here: $ pythonPython 3.5.2 Continuum Analytics, Inc. (default, Jul 2 2016, 17:53:06)GCC 4.4.7 20120313 (Red Hat 4.4.7-1) on linuxType 'help', 'copyright', 'credits' or 'license' for more information. The tensorflow library wasn't compiled to use sse4.1 instructions mac youtube. I have the same issue.
Application.
asyncevents
(onoff)¶Call this method with a nonzero parameter to enable asynchronous event handling.This will tell the inner interpreter loop to call the application event handlerasync_dispatch whenever events are available. This will cause FrameWork windowupdates and the user interface to remain working during long computations, butwill slow the interpreter down and may cause surprising results in non-reentrantcode (such as FrameWork itself). By default async_dispatch will immediatelycall our_dispatch but you may override this to handle only certain eventsasynchronously. Events you do not handle will be passed to Sioux and such.
The old on/off value is returned.
Application.
_quit
()¶Terminate the running mainloop()
call at the next convenient moment.
Application.
do_char
(c, event)¶The user typed character c. The complete details of the event can be found inthe event structure. This method can also be provided in a Window
object,which overrides the application-wide handler if the window is frontmost.
Application.
do_dialogevent
(event)¶Called early in the event loop to handle modeless dialog events. The defaultmethod simply dispatches the event to the relevant dialog (not through theDialogWindow
object involved). Override if you need special handling ofdialog events (keyboard shortcuts, etc).
Application.
idle
(event)¶Called by the main event loop when no events are available. The null-event ispassed (so you can look at mouse position, etc).
Window objects have the following methods, among others:
Window.
open
()¶Override this method to open a window. Store the Mac OS window-id inself.wid
and call the do_postopen()
method to register the windowwith the parent application.
Window.
close
()¶Override this method to do any special processing on window close. Call thedo_postclose()
method to cleanup the parent state.
Window.
do_postresize
(width, height, macoswindowid)¶Called after the window is resized. Override if more needs to be done thancalling InvalRect
.
Window.
do_contentclick
(local, modifiers, event)¶The user clicked in the content part of a window. The arguments are thecoordinates (window-relative), the key modifiers and the raw event.
Window.
do_update
(macoswindowid, event)¶An update event for the window was received. Redraw the window.
Window.
do_activate
(activate, event)¶The window was activated (activate1
) or deactivated (activate0
).Handle things like focus highlighting, etc.
ControlsWindow objects have the following methods besides those of Window
objects:
ControlsWindow.
do_controlhit
(window, control, pcode, event)¶Part pcode of control control was hit by the user. Tracking and such hasalready been taken care of.
ScrolledWindow objects are ControlsWindow objects with the following extramethods:
ScrolledWindow.
scrollbars
([wantx[, wanty]])¶Create (or destroy) horizontal and vertical scrollbars. The arguments specifywhich you want (default: both). The scrollbars always have minimum 0
andmaximum 32767
.
ScrolledWindow.
getscrollbarvalues
()¶You must supply this method. It should return a tuple (x,y)
giving thecurrent position of the scrollbars (between 0
and 32767
). You can returnNone
for either to indicate the whole document is visible in that direction.
ScrolledWindow.
updatescrollbars
()¶Call this method when the document has changed. It will callgetscrollbarvalues()
and update the scrollbars.
ScrolledWindow.
scrollbar_callback
(which, what, value)¶Supplied by you and called after user interaction. which will be 'x'
or'y'
, what will be '-'
, '--'
, 'set'
, '++'
or '+'
. For'set'
, value will contain the new scrollbar position.
ScrolledWindow.
scalebarvalues
(absmin, absmax, curmin, curmax)¶Auxiliary method to help you calculate values to return fromgetscrollbarvalues()
. You pass document minimum and maximum value andtopmost (leftmost) and bottommost (rightmost) visible values and it returns thecorrect number or None
.
ScrolledWindow.
do_activate
(onoff, event)¶Takes care of dimming/highlighting scrollbars when a window becomes frontmost.If you override this method, call this one at the end of your method.
ScrolledWindow.
do_postresize
(width, height, window)¶Moves scrollbars to the correct position. Call this method initially if youoverride it.
ScrolledWindow.
do_controlhit
(window, control, pcode, event)¶Handles scrollbar interaction. If you override it call this method first, anonzero return value indicates the hit was in the scrollbars and has beenhandled.
DialogWindow objects have the following methods besides those of Window
objects:
DialogWindow.
open
(resid)¶Create the dialog window, from the DLOG resource with id resid. The dialogobject is stored in self.wid
.
DialogWindow.
do_itemhit
(item, event)¶Item number item was hit. You are responsible for redrawing toggle buttons,etc.
Bob Savage <bobsavage@mac.com>
Python on a Macintosh running Mac OS X is in principle very similar to Python onany other Unix platform, but there are a number of additional features such asthe IDE and the Package Manager that are worth pointing out.
Mac OS X 10.8 comes with Python 2.7 pre-installed by Apple. If you wish, youare invited to install the most recent version of Python 3 from the Pythonwebsite (https://www.python.org). A current “universal binary” build of Python,which runs natively on the Mac’s new Intel and legacy PPC CPU’s, is availablethere.
Since Mac OS X 10.7 the Library folder is not displayed in the Finder anymore. To navigate to the Preferences folder please follow these steps: 1. Open the 'Go to Folder' menu. Open the Finder; Go to the Menu Bar and open the 'Go' menu. System preferences on mac. Does InqScribe work with Mac OSX Lion (10.7)? Does InqScribe work with Mac OSX Mountain Lion (10.8)? How can I send a bug report from InqScribe? How do I access the /Library folder in Mac OSX Lion (10.7) or later? How do I find my preferences file? I'm getting an error: 'QTCF.dll is missing'. How can I fix that? InqScribe is crashing. May 23, 2013 Is this two questions? Subject and body say different things. The preference file can be accessed h olding down the option key while using the Finder “ Go To Folder ” command. Enter /Library/Preferences. If you prefer to make your user library permanently visible, use the Terminal command found below. Jan 12, 2020 The Library folder contains many of the resources that installed applications need to use, including application preferences, application support documents, plug-in folders, and ever since OS X Lion, the files that describe the saved state of applications. May 30, 2019 Despite the fact that Apple keeps the Mac Library folder hidden from users, it’s good to learn how to show the Library folder on Mac. You may need to access the Library folder when you need to clear cache, remove the app’s leftovers, edit preference files manually, etc.
What you get after installing is a number of things:
A Python3.8
folder in your Applications
folder. In hereyou find IDLE, the development environment that is a standard part of officialPython distributions; PythonLauncher, which handles double-clicking Pythonscripts from the Finder; and the “Build Applet” tool, which allows you topackage Python scripts as standalone applications on your system.
A framework /Library/Frameworks/Python.framework
, which includes thePython executable and libraries. The installer adds this location to your shellpath. To uninstall MacPython, you can simply remove these three things. Asymlink to the Python executable is placed in /usr/local/bin/.
The Apple-provided build of Python is installed in/System/Library/Frameworks/Python.framework
and /usr/bin/python
,respectively. You should never modify or delete these, as they areApple-controlled and are used by Apple- or third-party software. Remember thatif you choose to install a newer Python version from python.org, you will havetwo different but functional Python installations on your computer, so it willbe important that your paths and usages are consistent with what you want to do.
IDLE includes a help menu that allows you to access Python documentation. If youare completely new to Python you should start reading the tutorial introductionin that document.
If you are familiar with Python on other Unix platforms you should read thesection on running Python scripts from the Unix shell.
Your best way to get started with Python on Mac OS X is through the IDLEintegrated development environment, see section The IDE and use the Help menuwhen the IDE is running.
If you want to run Python scripts from the Terminal window command line or fromthe Finder you first need an editor to create your script. Mac OS X comes with anumber of standard Unix command line editors, vim andemacs among them. If you want a more Mac-like editor,BBEdit or TextWrangler from Bare Bones Software (seehttp://www.barebones.com/products/bbedit/index.html) are good choices, as isTextMate (see https://macromates.com/). Other editors includeGvim (http://macvim-dev.github.io/macvim/) and Aquamacs(http://aquamacs.org/).
To run your script from the Terminal window you must make sure that/usr/local/bin
is in your shell search path.
To run your script from the Finder you have two options:
Drag it to PythonLauncher
Select PythonLauncher as the default application to open yourscript (or any .py script) through the finder Info window and double-click it.PythonLauncher has various preferences to control how your script islaunched. Option-dragging allows you to change these for one invocation, or useits Preferences menu to change things globally.
With older versions of Python, there is one Mac OS X quirk that you need to beaware of: programs that talk to the Aqua window manager (in other words,anything that has a GUI) need to be run in a special way. Use pythonwinstead of python to start such scripts.
With Python 3.8, you can use either python or pythonw.
Python on OS X honors all standard Unix environment variables such asPYTHONPATH
, but setting these variables for programs started from theFinder is non-standard as the Finder does not read your .profile
or.cshrc
at startup. You need to create a file~/.MacOSX/environment.plist
. See Apple’s Technical Document QA1067 fordetails.
For more information on installation Python packages in MacPython, see sectionInstalling Additional Python Packages.
MacPython ships with the standard IDLE development environment. A goodintroduction to using IDLE can be found athttp://www.hashcollision.org/hkn/python/idle_intro/index.html.
There are several methods to install additional Python packages:
Packages can be installed via the standard Python distutils mode (pythonsetup.pyinstall
).
Many packages can also be installed via the setuptools extensionor pip wrapper, see https://pip.pypa.io/.
There are several options for building GUI applications on the Mac with Python.
PyObjC is a Python binding to Apple’s Objective-C/Cocoa framework, which isthe foundation of most modern Mac development. Information on PyObjC isavailable from https://pypi.org/project/pyobjc/.
The standard Python GUI toolkit is tkinter
, based on the cross-platformTk toolkit (https://www.tcl.tk). An Aqua-native version of Tk is bundled with OSX by Apple, and the latest version can be downloaded and installed fromhttps://www.activestate.com; it can also be built from source.
wxPython is another popular cross-platform GUI toolkit that runs natively onMac OS X. Packages and documentation are available from https://www.wxpython.org.
PyQt is another popular cross-platform GUI toolkit that runs natively on MacOS X. More information can be found athttps://riverbankcomputing.com/software/pyqt/intro.
The “Build Applet” tool that is placed in the MacPython 3.6 folder is fine forpackaging small Python scripts on your own machine to run as a standard Macapplication. This tool, however, is not robust enough to distribute Pythonapplications to other users.
The standard tool for deploying standalone Python applications on the Mac ispy2app. More information on installing and using py2app can be foundat http://undefined.org/python/#py2app.
The MacPython mailing list is an excellent support resource for Python users anddevelopers on the Mac:
Another useful resource is the MacPython wiki: