Commits

Dan Villiom Podlaski Christiansen committed 416f5eb

remove cruft

  • Participants
  • Parent commits 9aee25c

Comments (0)

Files changed (44)

File sources/Applications.html

-<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
-   "http://www.w3.org/TR/html4/strict.dtd">
-
-<html>
-<head>
-  <title>Applications.py</title>
-  <meta http-equiv="content-type" content="text/html; charset=latin1">
-  <link rel="stylesheet" href="../code.css" type="text/css">
-</head>
-<body>
-<h2>Applications.py</h2>
-
-<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>
-
-
-
-
-
-
-
-
- 10
-
-
-
-
-
-
-
-
-
- 20
-
-
-
-
-
-
-
-
-
- 30
-
-
-
-
-
-
-
-
-
- 40
-
-
-
-
-
-
-
-
-
- 50
-
-
-
-
-
-
-
-
-
- 60
-
-
-
-
-
-
-
-
-
- 70
-
-
-
-
-
-
-
-
-
- 80
-
-
-
-
-
-
-
-
-
- 90
-
-
-
-
-
-
-
-
-
-100
-
-
-
-
-
-
-
-
-
-110
-
-
-
-
-
-
-
-
-
-120
-
-
-
-
-
-
-
-
-
-130
-
-
-
-
-
-
-
-
-
-140
-
-
-
-
-
-
-
-
-
-150
-
-
-
-
-
-
-
-
-
-160
-
-
-
-
-
-
-
-
-
-170
-
-
-
-
-
-
-
-
-
-180
-
-
-
-
-
-
-
-
-
-190
-
-
-
-
-
-
-
-
-
-200
-
-
-
-
-
-
-
-
-
-210
-
-
-
-
-
-
-
-
-
-220
-
-
-
-
-
-
-
-
-
-230
-
-
-
-
-
-
-
-
-
-240
-
-
-
-
-
-
-
-
-
-250
-
-
-
-
-
-
-
-
-
-260
-
-
-
-
-
-
-
-
-
-270
-
-
-
-
-
-
-
-
-
-280
-
-
-
-
-
-
-
-
-
-290
-
-
-
-
-
-
-
-
-
-300
-
-
-
-
-
-
-
-
-
-310
-
-
-
-
-
-
-
-
-
-320
-
-
-
-
-
-
-
-
-
-330
-
-
-
-
-
-
-
-
-
-340
-
-
-
-
-
-
-
-
-
-350
-
-
-
-
-
-
-
-
-
-360
-
-
-
-
-
-
-
-
-
-370
-
-
-
-
-
-
-
-
-
-380
-
-
-
-
-
-
-
-
-
-390
-
-
-
-
-
-
-
-
-
-400
-
-
-
-
-
-
-
-
-
-410
-
-
-
-
-
-
-
-
-
-420
-</pre></div></td><td class="code"><div class="highlight"><pre><span class="c">#------------------------------------------------------------------------------</span>
-<span class="c">#</span>
-<span class="c">#		Python GUI - Application class - PyObjC</span>
-<span class="c">#</span>
-<span class="c">#------------------------------------------------------------------------------</span>
-
-<span class="kn">import</span> <span class="nn">os</span><span class="o">,</span> <span class="nn">sys</span><span class="o">,</span> <span class="nn">traceback</span>
-<span class="kn">import</span> <span class="nn">objc</span>
-<span class="c">#from ExceptionHandling import \</span>
-<span class="c">#	NSExceptionHandler, NSLogUncaughtExceptionMask, NSLogAndHandleEveryExceptionMask</span>
-<span class="kn">from</span> <span class="nn">Foundation</span> <span class="kn">import</span> <span class="n">NSObject</span><span class="p">,</span> <span class="n">NSBundle</span><span class="p">,</span> <span class="n">NSDefaultRunLoopMode</span>
-<span class="kn">import</span> <span class="nn">AppKit</span>
-<span class="kn">from</span> <span class="nn">AppKit</span> <span class="kn">import</span> <span class="n">NSApplication</span><span class="p">,</span> <span class="n">NSResponder</span><span class="p">,</span> <span class="n">NSScreen</span><span class="p">,</span> <span class="n">NSMenu</span><span class="p">,</span> <span class="n">NSMenuItem</span><span class="p">,</span> \
-    <span class="n">NSKeyDown</span><span class="p">,</span> <span class="n">NSKeyUp</span><span class="p">,</span> <span class="n">NSMouseMoved</span><span class="p">,</span> <span class="n">NSLeftMouseDown</span><span class="p">,</span> <span class="n">NSSystemDefined</span><span class="p">,</span> \
-    <span class="n">NSCommandKeyMask</span><span class="p">,</span> <span class="n">NSPasteboard</span><span class="p">,</span> <span class="n">NSStringPboardType</span><span class="p">,</span> <span class="n">NSModalPanelRunLoopMode</span><span class="p">,</span> \
-    <span class="n">NSAnyEventMask</span>
-<span class="kn">import</span> <span class="nn">Globals</span>
-<span class="kn">import</span> <span class="nn">GApplications</span>
-<span class="kn">from</span> <span class="nn">Globals</span> <span class="kn">import</span> <span class="n">application</span>
-<span class="kn">from</span> <span class="nn">GApplications</span> <span class="kn">import</span> <span class="n">Application</span> <span class="k">as</span> <span class="n">GApplication</span>
-<span class="kn">from</span> <span class="nn">Events</span> <span class="kn">import</span> <span class="n">Event</span>
-<span class="c">#from Exceptions import Cancel, Quit</span>
-<span class="c">#from Menus import _ns_standard_actions</span>
-
-<span class="c">#------------------------------------------------------------------------------</span>
-
-<span class="n">Globals</span><span class="o">.</span><span class="n">ns_screen_height</span> <span class="o">=</span> <span class="bp">None</span>
-<span class="n">Globals</span><span class="o">.</span><span class="n">ns_last_mouse_moved_event</span> <span class="o">=</span> <span class="bp">None</span>
-<span class="n">ns_application</span> <span class="o">=</span> <span class="bp">None</span>
-
-<span class="c">#------------------------------------------------------------------------------</span>
-
-<span class="c">#def test_menus(app):</span>
-<span class="c">#	print &quot;Testing menus&quot;</span>
-<span class="c">#	foomenu = NSMenu.alloc().initWithTitle_(&quot;Foo&quot;)</span>
-<span class="c">#	foomenu.addItemWithTitle_action_keyEquivalent_(&quot;Blarg&quot;, None, &quot;B&quot;)</span>
-<span class="c">#	feemenu = NSMenu.alloc().initWithTitle_(&quot;Fee&quot;)</span>
-<span class="c">#	feemenu.addItemWithTitle_action_keyEquivalent_(&quot;Blork&quot;, None, &quot;K&quot;)</span>
-<span class="c">#	menubar = NSMenu.alloc().initWithTitle_(&quot;Main&quot;)</span>
-<span class="c">#	fooitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(&quot;Foo&quot;, &quot;&quot;, &quot;&quot;)</span>
-<span class="c">#	menubar.addItem_(fooitem)</span>
-<span class="c">#	menubar.setSubmenu_forItem_(foomenu, fooitem)</span>
-<span class="c">#	feeitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(&quot;Fee&quot;, &quot;&quot;, &quot;&quot;)</span>
-<span class="c">#	menubar.addItem_(feeitem)</span>
-<span class="c">#	menubar.setSubmenu_forItem_(feemenu, feeitem)</span>
-<span class="c">#	app.setMainMenu_(menubar)</span>
-<span class="c">#	app.setAppleMenu_(foomenu)</span>
-<span class="c">#	#app.run()</span>
-<span class="c">#	print &quot;Finished testing menus&quot;</span>
-
-<span class="c">#------------------------------------------------------------------------------</span>
-
-<span class="k">class</span> <span class="nc">Application</span><span class="p">(</span><span class="n">GApplication</span><span class="p">):</span>
-    <span class="c">#  _ns_app          _PyGui_NSApplication</span>
-    <span class="c">#  _ns_pasteboard   NSPasteboard</span>
-    <span class="c">#  _ns_key_window   Window</span>
-    
-    <span class="n">_ns_menubar_update_pending</span> <span class="o">=</span> <span class="bp">False</span>
-
-    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwds</span><span class="p">):</span>
-        <span class="c">#print &quot;Application.__init__: argv =&quot;, sys.argv ###</span>
-        <span class="n">create_ns_application</span><span class="p">()</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_ns_app</span> <span class="o">=</span> <span class="n">ns_application</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_ns_app</span><span class="o">.</span><span class="n">pygui_app</span> <span class="o">=</span> <span class="bp">self</span>
-        <span class="c">#self._ns_init_standard_menu_items()</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_ns_pasteboard</span> <span class="o">=</span> <span class="n">NSPasteboard</span><span class="o">.</span><span class="n">generalPasteboard</span><span class="p">()</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_ns_key_window</span> <span class="o">=</span> <span class="bp">None</span>
-        <span class="n">GApplication</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwds</span><span class="p">)</span>
-        <span class="n">ns_application</span><span class="o">.</span><span class="n">init_application_name</span><span class="p">()</span>
-    
-    <span class="k">def</span> <span class="nf">destroy</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
-        <span class="k">del</span> <span class="bp">self</span><span class="o">.</span><span class="n">menus</span><span class="p">[:]</span>
-        <span class="kn">import</span> <span class="nn">Windows</span>
-        <span class="n">Windows</span><span class="o">.</span><span class="n">_ns_zombie_window</span> <span class="o">=</span> <span class="bp">None</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_ns_app</span><span class="o">.</span><span class="n">pygui_app</span> <span class="o">=</span> <span class="bp">None</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_ns_app</span> <span class="o">=</span> <span class="bp">None</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_ns_pasteboard</span> <span class="o">=</span> <span class="bp">None</span>
-        <span class="n">GApplication</span><span class="o">.</span><span class="n">destroy</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
-    
-    <span class="k">def</span> <span class="nf">set_menus</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">menu_list</span><span class="p">):</span>
-        <span class="n">GApplication</span><span class="o">.</span><span class="n">set_menus</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">menu_list</span><span class="p">)</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_update_menubar</span><span class="p">()</span>
-    
-    <span class="k">def</span> <span class="nf">_update_menubar</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
-        <span class="n">ns_app</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ns_app</span>
-        <span class="n">ns_menubar</span> <span class="o">=</span> <span class="n">NSMenu</span><span class="o">.</span><span class="n">alloc</span><span class="p">()</span><span class="o">.</span><span class="n">initWithTitle_</span><span class="p">(</span><span class="s">&quot;&quot;</span><span class="p">)</span>
-        <span class="n">menu_list</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_effective_menus</span><span class="p">()</span>
-        <span class="k">for</span> <span class="n">menu</span> <span class="ow">in</span> <span class="n">menu_list</span><span class="p">:</span>
-            <span class="n">ns_item</span> <span class="o">=</span> <span class="n">NSMenuItem</span><span class="o">.</span><span class="n">alloc</span><span class="p">()</span>
-            <span class="n">ns_item</span><span class="o">.</span><span class="n">initWithTitle_action_keyEquivalent_</span><span class="p">(</span><span class="n">menu</span><span class="o">.</span><span class="n">title</span><span class="p">,</span> <span class="s">&#39;&#39;</span><span class="p">,</span> <span class="s">&quot;&quot;</span><span class="p">)</span>
-            <span class="n">ns_menubar</span><span class="o">.</span><span class="n">addItem_</span><span class="p">(</span><span class="n">ns_item</span><span class="p">)</span>
-            <span class="n">ns_menu</span> <span class="o">=</span> <span class="n">menu</span><span class="o">.</span><span class="n">_ns_menu</span>
-            <span class="c">#  An NSMenu can only be a submenu of one menu at a time, so</span>
-            <span class="c">#  remove it from the old menubar if necessary.</span>
-            <span class="n">old_supermenu</span> <span class="o">=</span> <span class="n">ns_menu</span><span class="o">.</span><span class="n">supermenu</span><span class="p">()</span>
-            <span class="k">if</span> <span class="n">old_supermenu</span><span class="p">:</span>
-                <span class="n">i</span> <span class="o">=</span> <span class="n">old_supermenu</span><span class="o">.</span><span class="n">indexOfItemWithSubmenu_</span><span class="p">(</span><span class="n">ns_menu</span><span class="p">)</span>
-                <span class="n">old_supermenu</span><span class="o">.</span><span class="n">removeItemAtIndex_</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
-            <span class="n">ns_menubar</span><span class="o">.</span><span class="n">setSubmenu_forItem_</span><span class="p">(</span><span class="n">ns_menu</span><span class="p">,</span> <span class="n">ns_item</span><span class="p">)</span>
-        <span class="c"># The menu you pass to setAppleMenu_ must *also* be a member of the</span>
-        <span class="c"># main menu.</span>
-        <span class="n">ns_app</span><span class="o">.</span><span class="n">setMainMenu_</span><span class="p">(</span><span class="n">ns_menubar</span><span class="p">)</span>
-        <span class="n">ns_app_menu</span> <span class="o">=</span> <span class="n">menu_list</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">_ns_menu</span>
-        <span class="n">ns_app</span><span class="o">.</span><span class="n">setAppleMenu_</span><span class="p">(</span><span class="n">ns_app_menu</span><span class="p">)</span>
-
-<span class="c">#	def handle_events(self):</span>
-<span class="c">#		#print &quot;Application.handle_events: entering NS run loop&quot; ###</span>
-<span class="c">#		#try:</span>
-<span class="c">#			self._ns_app.run()</span>
-<span class="c">#		#finally:</span>
-<span class="c">#			#print &quot;Application.handle_events: exiting NS run loop&quot; ###</span>
-
-    <span class="k">def</span> <span class="nf">handle_next_event</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">modal_window</span> <span class="o">=</span> <span class="bp">None</span><span class="p">):</span>
-        <span class="c">#print &quot;Application.handle_next_event&quot; ###</span>
-        <span class="n">ns_app</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ns_app</span>
-        <span class="k">if</span> <span class="n">modal_window</span><span class="p">:</span>
-            <span class="n">ns_mode</span> <span class="o">=</span> <span class="n">NSModalPanelRunLoopMode</span>
-            <span class="n">ns_modal_window</span> <span class="o">=</span> <span class="n">modal_window</span><span class="o">.</span><span class="n">_ns_window</span>
-        <span class="k">else</span><span class="p">:</span>
-            <span class="n">ns_mode</span> <span class="o">=</span> <span class="n">NSDefaultRunLoopMode</span>
-            <span class="n">ns_modal_window</span> <span class="o">=</span> <span class="bp">None</span>
-        <span class="n">ns_event</span> <span class="o">=</span> <span class="n">ns_app</span><span class="o">.</span><span class="n">nextEventMatchingMask_untilDate_inMode_dequeue_</span><span class="p">(</span>
-            <span class="n">NSAnyEventMask</span><span class="p">,</span> <span class="bp">None</span><span class="p">,</span> <span class="n">ns_mode</span><span class="p">,</span> <span class="bp">True</span><span class="p">)</span>
-        <span class="k">if</span> <span class="n">ns_event</span><span class="p">:</span>
-            <span class="n">ns_window</span> <span class="o">=</span> <span class="n">ns_event</span><span class="o">.</span><span class="n">window</span><span class="p">()</span>
-            <span class="k">if</span> <span class="ow">not</span> <span class="n">ns_window</span> <span class="ow">or</span> <span class="ow">not</span> <span class="n">ns_modal_window</span> <span class="ow">or</span> <span class="n">ns_window</span> <span class="o">==</span> <span class="n">ns_modal_window</span><span class="p">:</span>
-                <span class="n">ns_app</span><span class="o">.</span><span class="n">sendEvent_</span><span class="p">(</span><span class="n">ns_event</span><span class="p">)</span>
-    
-    <span class="k">def</span> <span class="nf">get_target_window</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
-        <span class="c">#  NSApplication.keyWindow() isn&#39;t reliable enough. We keep track</span>
-        <span class="c">#  of the key window ourselves.</span>
-        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ns_key_window</span>
-
-    <span class="k">def</span> <span class="nf">zero_windows_allowed</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
-        <span class="k">return</span> <span class="mi">1</span>
-    
-    <span class="k">def</span> <span class="nf">query_clipboard</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
-        <span class="n">pb</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ns_pasteboard</span>
-        <span class="n">pb_types</span> <span class="o">=</span> <span class="n">pb</span><span class="o">.</span><span class="n">types</span><span class="p">()</span>
-        <span class="k">return</span> <span class="n">NSStringPboardType</span> <span class="ow">in</span> <span class="n">pb_types</span>
-    
-    <span class="k">def</span> <span class="nf">get_clipboard</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
-        <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s">&quot;TODO: Application.get_clipboard&quot;</span><span class="p">)</span>
-    
-    <span class="k">def</span> <span class="nf">set_clipboard</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
-        <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s">&quot;TODO: Application.set_clipboard&quot;</span><span class="p">)</span>
-    
-<span class="c">#	def _ns_init_standard_menu_items(self):</span>
-<span class="c">#		self._ns_standard_menu_items = {}</span>
-<span class="c">#		for (cmd_name, ns_selector) in _ns_standard_actions.iteritems():</span>
-<span class="c">#			self._ns_standard_menu_items[cmd_name] = NSMenuItem.alloc().\</span>
-<span class="c">#					initWithTitle_action_keyEquivalent_(&quot;&quot;, ns_selector, &quot;&quot;)</span>
-
-<span class="c">#	def _dispatch_menu_setup(self, m):</span>
-<span class="c">#		GApplication._dispatch_menu_setup(self, m)</span>
-<span class="c">#		return ###</span>
-<span class="c">#		for (cmd_name, ns_menu_item) in self._ns_standard_menu_items.iteritems():</span>
-<span class="c">#			ns_selector = ns_menu_item.action()</span>
-<span class="c">#			target = self._ns_app.targetForAction_(ns_selector)</span>
-<span class="c">#			print &quot;Application._dispatch_menu_setup: target for&quot;, ns_selector, &quot;is&quot;, target.__class__.__name__ ###</span>
-<span class="c">#			if target and target.respondsToSelector_(&#39;validateMenuItem:&#39;):</span>
-<span class="c">#				if target.validateMenuItem_(ns_menu_item):</span>
-<span class="c">#					m[cmd_name].enabled = True</span>
-    
-    <span class="k">def</span> <span class="nf">setup_menus</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">m</span><span class="p">):</span>
-        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ns_app</span><span class="o">.</span><span class="n">modalWindow</span><span class="p">():</span>
-            <span class="n">GApplication</span><span class="o">.</span><span class="n">setup_menus</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">m</span><span class="p">)</span>
-    
-    <span class="k">def</span> <span class="nf">process_args</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">args</span><span class="p">):</span>
-        <span class="c">#  Note: When using py2app, argv_emulation should be disabled.</span>
-        <span class="k">if</span> <span class="n">args</span> <span class="ow">and</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s">&quot;-psn&quot;</span><span class="p">):</span>
-            <span class="c"># Launched from MacOSX Finder -- wait for file open/app launch messages</span>
-            <span class="k">pass</span>
-        <span class="k">else</span><span class="p">:</span>
-            <span class="c"># Not launched from Finder or using argv emulation</span>
-            <span class="bp">self</span><span class="o">.</span><span class="n">_ns_app</span><span class="o">.</span><span class="n">using_clargs</span> <span class="o">=</span> <span class="bp">True</span>
-            <span class="n">GApplication</span><span class="o">.</span><span class="n">process_args</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">args</span><span class="p">)</span>
-
-    <span class="k">def</span> <span class="nf">run</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">fast_exit</span> <span class="o">=</span> <span class="bp">True</span><span class="p">):</span>
-        <span class="c">#print &quot;Application.run&quot; ###</span>
-        <span class="k">try</span><span class="p">:</span>
-            <span class="n">GApplication</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
-        <span class="k">except</span> <span class="p">(</span><span class="ne">KeyboardInterrupt</span><span class="p">,</span> <span class="ne">SystemExit</span><span class="p">):</span>
-            <span class="k">pass</span>
-        <span class="k">except</span><span class="p">:</span>
-            <span class="n">traceback</span><span class="o">.</span><span class="n">print_exc</span><span class="p">()</span>
-        <span class="c">#  A py2app bundled application seems to crash on exit if we don&#39;t</span>
-        <span class="c">#  bail out really quickly here (Python 2.3, PyObjC 1.3.7, py2app 0.2.1,</span>
-        <span class="c">#  MacOSX 10.4.4)</span>
-        <span class="k">if</span> <span class="n">fast_exit</span><span class="p">:</span>
-            <span class="n">os</span><span class="o">.</span><span class="n">_exit</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
-
-    <span class="k">def</span> <span class="nf">event_loop</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
-        <span class="c">#print &quot;Application.event_loop&quot; ###</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_ns_app</span><span class="o">.</span><span class="n">run</span><span class="p">()</span>
-        <span class="c">#print &quot;Exit Application.event_loop&quot; ###</span>
-    
-<span class="c">#	def _exit_event_loop(self):</span>
-<span class="c">#		self._ns_app.stop_(self)</span>
-
-    <span class="k">def</span> <span class="nf">_quit</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
-        <span class="c">#print &quot;Application._quit&quot; ###</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_quit_flag</span> <span class="o">=</span> <span class="bp">True</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_ns_app</span><span class="o">.</span><span class="n">stop_</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_ns_app</span><span class="p">)</span>
-        <span class="c">#print &quot;Exit Application._quit&quot; ###</span>
-    
-    <span class="k">def</span> <span class="nf">setup_menus</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">m</span><span class="p">):</span>
-        <span class="n">m</span><span class="o">.</span><span class="n">hide_app_cmd</span><span class="o">.</span><span class="n">enabled</span> <span class="o">=</span> <span class="bp">True</span>
-        <span class="n">m</span><span class="o">.</span><span class="n">hide_other_apps_cmd</span><span class="o">.</span><span class="n">enabled</span> <span class="o">=</span> <span class="bp">True</span>
-        <span class="n">m</span><span class="o">.</span><span class="n">show_all_apps_cmd</span><span class="o">.</span><span class="n">enabled</span> <span class="o">=</span> <span class="bp">True</span>
-        <span class="n">GApplication</span><span class="o">.</span><span class="n">setup_menus</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">m</span><span class="p">)</span>
-
-    <span class="k">def</span> <span class="nf">hide_app_cmd</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_ns_app</span><span class="o">.</span><span class="n">hide_</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
-
-    <span class="k">def</span> <span class="nf">hide_other_apps_cmd</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_ns_app</span><span class="o">.</span><span class="n">hideOtherApplications_</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
-
-    <span class="k">def</span> <span class="nf">show_all_apps_cmd</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_ns_app</span><span class="o">.</span><span class="n">unhideAllApplications_</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
-
-<span class="c">#------------------------------------------------------------------------------</span>
-
-<span class="n">_ns_key_event_mask</span> <span class="o">=</span> <span class="n">AppKit</span><span class="o">.</span><span class="n">NSKeyDownMask</span> <span class="o">|</span> <span class="n">AppKit</span><span class="o">.</span><span class="n">NSKeyUpMask</span>
-
-<span class="c">#------------------------------------------------------------------------------</span>
-
-<span class="k">class</span> <span class="nc">_PyGui_NSApplication</span><span class="p">(</span><span class="n">NSApplication</span><span class="p">):</span>
-
-    <span class="n">pygui_app</span> <span class="o">=</span> <span class="bp">None</span>
-    <span class="n">files_opened</span> <span class="o">=</span> <span class="bp">False</span>
-    <span class="n">using_clargs</span> <span class="o">=</span> <span class="bp">False</span>
-    <span class="n">pygui_menus_updated</span> <span class="o">=</span> <span class="bp">False</span>
-
-    <span class="k">def</span> <span class="nf">sendEvent_</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ns_event</span><span class="p">):</span>
-        <span class="c">#  Perform special processing of key events.</span>
-        <span class="c">#  Perform menu setup when menu bar is clicked.</span>
-        <span class="c">#  Remember the most recent mouse-moved event to use as the</span>
-        <span class="c">#  location of event types which do not have a location themselves.</span>
-        <span class="k">if</span> <span class="n">pending_exception</span><span class="p">:</span>
-            <span class="n">raise_pending_exception</span><span class="p">()</span>
-        <span class="n">ns_type</span> <span class="o">=</span> <span class="n">ns_event</span><span class="o">.</span><span class="n">type</span><span class="p">()</span>
-        <span class="c">#print &quot;sendEvent_:&quot;, ns_event ###</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">pygui_menus_updated</span> <span class="o">=</span> <span class="bp">False</span>
-        <span class="k">if</span> <span class="p">(</span><span class="mi">1</span> <span class="o">&lt;&lt;</span> <span class="n">ns_type</span><span class="p">)</span> <span class="o">&amp;</span> <span class="n">_ns_key_event_mask</span><span class="p">:</span>
-            <span class="bp">self</span><span class="o">.</span><span class="n">process_key_event</span><span class="p">(</span><span class="n">ns_event</span><span class="p">)</span>
-        <span class="k">else</span><span class="p">:</span>
-            <span class="k">if</span> <span class="n">ns_type</span> <span class="o">==</span> <span class="n">NSMouseMoved</span><span class="p">:</span>
-                <span class="n">Globals</span><span class="o">.</span><span class="n">ns_last_mouse_moved_event</span> <span class="o">=</span> <span class="n">ns_event</span>
-                <span class="n">ns_window</span> <span class="o">=</span> <span class="n">ns_event</span><span class="o">.</span><span class="n">window</span><span class="p">()</span>
-                <span class="k">if</span> <span class="n">ns_window</span><span class="p">:</span>
-                    <span class="n">ns_view</span> <span class="o">=</span> <span class="n">ns_window</span><span class="o">.</span><span class="n">contentView</span><span class="p">()</span><span class="o">.</span><span class="n">hitTest_</span><span class="p">(</span><span class="n">ns_event</span><span class="o">.</span><span class="n">locationInWindow</span><span class="p">())</span>
-                    <span class="k">if</span> <span class="n">ns_view</span><span class="p">:</span>
-                        <span class="n">ns_view</span><span class="o">.</span><span class="n">mouseMoved_</span><span class="p">(</span><span class="n">ns_event</span><span class="p">)</span>
-            <span class="k">else</span><span class="p">:</span>
-                <span class="n">NSApplication</span><span class="o">.</span><span class="n">sendEvent_</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ns_event</span><span class="p">)</span>
-    
-    <span class="k">def</span> <span class="nf">process_key_event</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ns_event</span><span class="p">):</span>
-        <span class="c">#  Perform menu setup before command-key events.</span>
-        <span class="c">#  Send non-command key events to associated window if any,</span>
-        <span class="c">#  otherwise pass them to the pygui application. This is necessary</span>
-        <span class="c">#  because otherwise there is no way of receiving key events when</span>
-        <span class="c">#  there are no windows.</span>
-        <span class="c">#print &quot;_PyGui_NSApplication.process_key_event:&quot;, ns_event ###</span>
-        <span class="k">if</span> <span class="n">ns_event</span><span class="o">.</span><span class="n">modifierFlags</span><span class="p">()</span> <span class="o">&amp;</span> <span class="n">NSCommandKeyMask</span><span class="p">:</span>
-            <span class="c">#self.perform_menu_setup()</span>
-            <span class="n">NSApplication</span><span class="o">.</span><span class="n">sendEvent_</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ns_event</span><span class="p">)</span>
-        <span class="k">else</span><span class="p">:</span>
-            <span class="n">ns_window</span> <span class="o">=</span> <span class="n">ns_event</span><span class="o">.</span><span class="n">window</span><span class="p">()</span>
-            <span class="c">#print &quot;_PyGui_NSApplication.process_key_event: ns_window =&quot;, ns_window ###</span>
-            <span class="k">if</span> <span class="n">ns_window</span><span class="p">:</span>
-                <span class="n">ns_window</span><span class="o">.</span><span class="n">sendEvent_</span><span class="p">(</span><span class="n">ns_event</span><span class="p">)</span>
-            <span class="k">else</span><span class="p">:</span>
-                <span class="bp">self</span><span class="o">.</span><span class="n">pass_event_to_application</span><span class="p">(</span><span class="n">ns_event</span><span class="p">)</span>
-    
-    <span class="k">def</span> <span class="nf">menuNeedsUpdate_</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ns_menu</span><span class="p">):</span>
-        <span class="c">#print &quot;_PyGui_NSApplication.menuNeedsUpdate_:&quot;, object.__repr__(ns_menu) ###</span>
-        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">pygui_menus_updated</span><span class="p">:</span>
-            <span class="c">#print &quot;...updating menus&quot; ###</span>
-            <span class="bp">self</span><span class="o">.</span><span class="n">perform_menu_setup</span><span class="p">()</span>
-            <span class="bp">self</span><span class="o">.</span><span class="n">pygui_menus_updated</span> <span class="o">=</span> <span class="bp">True</span>
-
-    <span class="k">def</span> <span class="nf">perform_menu_setup</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
-        <span class="c">#print &quot;_PyGui_NSApplication.perform_menu_setup&quot; ###</span>
-        <span class="n">app</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">pygui_app</span>
-        <span class="k">if</span> <span class="n">app</span><span class="p">:</span>
-            <span class="n">app</span><span class="o">.</span><span class="n">_perform_menu_setup</span><span class="p">()</span>
-    
-    <span class="k">def</span> <span class="nf">pass_event_to_application</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ns_event</span><span class="p">):</span>
-        <span class="n">app</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">pygui_app</span>
-        <span class="k">if</span> <span class="n">app</span><span class="p">:</span>
-            <span class="n">event</span> <span class="o">=</span> <span class="n">Event</span><span class="p">(</span><span class="n">ns_event</span><span class="p">)</span>
-            <span class="n">app</span><span class="o">.</span><span class="n">handle</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">kind</span><span class="p">,</span> <span class="n">event</span><span class="p">)</span>
-
-<span class="c">#	def sendAction_to_from_(self, action, target, sender):</span>
-<span class="c">#		print &quot;_PyGui_NSApplication.sendAction_to_from_&quot;,  action, target, sender ###</span>
-<span class="c">#		return NSApplication.sendAction_to_from_(self, action, target, sender)</span>
-
-    <span class="k">def</span> <span class="nf">menuSelection_</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ns_menu_item</span><span class="p">):</span>
-        <span class="n">command</span> <span class="o">=</span> <span class="n">ns_menu_item</span><span class="o">.</span><span class="n">representedObject</span><span class="p">()</span>
-        <span class="n">index</span> <span class="o">=</span> <span class="n">ns_menu_item</span><span class="o">.</span><span class="n">tag</span><span class="p">()</span>
-        <span class="k">if</span> <span class="n">index</span> <span class="o">&gt;=</span> <span class="mi">0</span><span class="p">:</span>
-            <span class="bp">self</span><span class="o">.</span><span class="n">dispatch_to_app</span><span class="p">(</span><span class="n">command</span><span class="p">,</span> <span class="n">index</span><span class="p">)</span>
-        <span class="k">else</span><span class="p">:</span>
-            <span class="bp">self</span><span class="o">.</span><span class="n">dispatch_to_app</span><span class="p">(</span><span class="n">command</span><span class="p">)</span>
-    
-    <span class="k">def</span> <span class="nf">dispatch_to_app</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">):</span>
-        <span class="n">app</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">pygui_app</span>
-        <span class="k">if</span> <span class="n">app</span><span class="p">:</span>
-            <span class="n">app</span><span class="o">.</span><span class="n">dispatch</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">)</span>
-    
-    <span class="k">def</span> <span class="nf">validateMenuItem_</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">):</span>
-        <span class="k">return</span> <span class="bp">False</span>
-    
-    <span class="k">def</span> <span class="nf">undo_</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sender</span><span class="p">):</span>
-        <span class="k">print</span> <span class="s">&quot;_PyGui_NSApplication.undo_&quot;</span> <span class="c">###</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">dispatch_to_app</span><span class="p">(</span><span class="s">&#39;undo_cmd&#39;</span><span class="p">)</span>
-
-    <span class="k">def</span> <span class="nf">redo_</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sender</span><span class="p">):</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">dispatch_to_app</span><span class="p">(</span><span class="s">&#39;redo_cmd&#39;</span><span class="p">)</span>
-
-    <span class="k">def</span> <span class="nf">cut_</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sender</span><span class="p">):</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">dispatch_to_app</span><span class="p">(</span><span class="s">&#39;cut_cmd&#39;</span><span class="p">)</span>
-
-    <span class="k">def</span> <span class="nf">copy_</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sender</span><span class="p">):</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">dispatch_to_app</span><span class="p">(</span><span class="s">&#39;copy_cmd&#39;</span><span class="p">)</span>
-
-    <span class="k">def</span> <span class="nf">paste_</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sender</span><span class="p">):</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">dispatch_to_app</span><span class="p">(</span><span class="s">&#39;paste_cmd&#39;</span><span class="p">)</span>
-
-    <span class="k">def</span> <span class="nf">clear_</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sender</span><span class="p">):</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">dispatch_to_app</span><span class="p">(</span><span class="s">&#39;clear_cmd&#39;</span><span class="p">)</span>
-
-    <span class="k">def</span> <span class="nf">select_all_</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sender</span><span class="p">):</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">dispatch_to_app</span><span class="p">(</span><span class="s">&#39;select_all_cmd&#39;</span><span class="p">)</span>
-
-    <span class="k">def</span> <span class="nf">init_application_name</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
-        <span class="c">#  Arrange for the application name to be used as the title</span>
-        <span class="c">#  of the application menu.</span>
-        <span class="n">ns_bundle</span> <span class="o">=</span> <span class="n">NSBundle</span><span class="o">.</span><span class="n">mainBundle</span><span class="p">()</span>
-        <span class="k">if</span> <span class="n">ns_bundle</span><span class="p">:</span>
-            <span class="n">ns_info</span> <span class="o">=</span> <span class="n">ns_bundle</span><span class="o">.</span><span class="n">localizedInfoDictionary</span><span class="p">()</span>
-            <span class="k">if</span> <span class="n">ns_info</span><span class="p">:</span>
-                <span class="k">if</span> <span class="n">ns_info</span><span class="p">[</span><span class="s">&#39;CFBundleName&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;Python&quot;</span><span class="p">:</span>
-                    <span class="n">ns_info</span><span class="p">[</span><span class="s">&#39;CFBundleName&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">Globals</span><span class="o">.</span><span class="n">application_name</span>
-                <span class="k">return</span>
-        <span class="c">#raise RuntimeError(&quot;No bundle information found. &quot;</span>
-        <span class="c">#	&quot;Perhaps the application was not run with pythonw?&quot;)</span>
-    
-    <span class="k">def</span> <span class="nf">application_openFile_</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ns_app</span><span class="p">,</span> <span class="n">path</span><span class="p">):</span>
-        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">using_clargs</span><span class="p">:</span>
-            <span class="k">return</span> <span class="bp">True</span>
-        <span class="c">#print &quot;PyGUI_NSApplication.application_openFile_:&quot;, path ###</span>
-        <span class="c"># Bizarrely, argv[0] gets passed to application_openFile_ under</span>
-        <span class="c"># some circumstances. We don&#39;t want to try to open it!</span>
-        <span class="k">if</span> <span class="n">path</span> <span class="o">==</span> <span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mi">0</span><span class="p">]:</span>
-            <span class="k">return</span> <span class="bp">True</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">files_opened</span> <span class="o">=</span> <span class="bp">True</span>
-        <span class="k">try</span><span class="p">:</span>
-            <span class="bp">self</span><span class="o">.</span><span class="n">pygui_app</span><span class="o">.</span><span class="n">open_path</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
-            <span class="k">return</span> <span class="bp">True</span>
-        <span class="k">except</span> <span class="ne">Exception</span><span class="p">,</span> <span class="n">e</span><span class="p">:</span>
-            <span class="bp">self</span><span class="o">.</span><span class="n">pygui_app</span><span class="o">.</span><span class="n">report_error</span><span class="p">()</span>
-            <span class="k">return</span> <span class="bp">False</span>
-    
-    <span class="k">def</span> <span class="nf">applicationDidFinishLaunching_</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">notification</span><span class="p">):</span>
-        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">using_clargs</span><span class="p">:</span>
-            <span class="k">return</span>
-        <span class="c">#print &quot;PyGUI_NSApplication.applicationDidFinishLaunching_&quot;</span>
-        <span class="k">try</span><span class="p">:</span>
-            <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">files_opened</span><span class="p">:</span>
-                <span class="bp">self</span><span class="o">.</span><span class="n">pygui_app</span><span class="o">.</span><span class="n">open_app</span><span class="p">()</span>
-        <span class="k">except</span> <span class="ne">Exception</span><span class="p">,</span> <span class="n">e</span><span class="p">:</span>
-            <span class="bp">self</span><span class="o">.</span><span class="n">pygui_app</span><span class="o">.</span><span class="n">report_error</span><span class="p">()</span>
-            <span class="k">return</span> <span class="bp">False</span>
-
-<span class="c">#------------------------------------------------------------------------------</span>
-
-<span class="n">pending_exception</span> <span class="o">=</span> <span class="bp">None</span>
-
-<span class="k">def</span> <span class="nf">raise_pending_exception</span><span class="p">():</span>
-    <span class="k">global</span> <span class="n">pending_exception</span>
-    <span class="n">exc_type</span><span class="p">,</span> <span class="n">exc_value</span><span class="p">,</span> <span class="n">exc_tb</span> <span class="o">=</span> <span class="n">pending_exception</span>
-    <span class="n">pending_exception</span> <span class="o">=</span> <span class="bp">None</span>
-    <span class="k">raise</span> <span class="n">exc_type</span><span class="p">,</span> <span class="n">exc_value</span><span class="p">,</span> <span class="n">exc_tb</span>
-
-<span class="k">def</span> <span class="nf">create_ns_application</span><span class="p">():</span>
-    <span class="k">global</span> <span class="n">ns_application</span>
-    <span class="n">ns_application</span> <span class="o">=</span> <span class="n">_PyGui_NSApplication</span><span class="o">.</span><span class="n">sharedApplication</span><span class="p">()</span>
-    <span class="n">ns_application</span><span class="o">.</span><span class="n">setDelegate_</span><span class="p">(</span><span class="n">ns_application</span><span class="p">)</span>
-
-<span class="n">Globals</span><span class="o">.</span><span class="n">ns_screen_height</span> <span class="o">=</span> <span class="n">NSScreen</span><span class="o">.</span><span class="n">mainScreen</span><span class="p">()</span><span class="o">.</span><span class="n">frame</span><span class="p">()</span><span class="o">.</span><span class="n">size</span><span class="o">.</span><span class="n">height</span>
-
-<span class="c">#------------------------------------------------------------------------------</span>
-
-<span class="c"># Disable this for now, since MachSignals.signal segfaults. :-(</span>
-<span class="c">#</span>
-<span class="c">#def _install_sigint_handler():</span>
-<span class="c">#		print &quot;_install_sigint_handler&quot; ###</span>
-<span class="c">#		from Foundation import NSRunLoop</span>
-<span class="c">#		run_loop = NSRunLoop.currentRunLoop()</span>
-<span class="c">#		if not run_loop:</span>
-<span class="c">#			print &quot;...No current run loop&quot; ###</span>
-<span class="c">#			sys.exit(1) ###</span>
-<span class="c">#		MachSignals.signal(signal.SIGINT, _sigint_handler)</span>
-<span class="c">#		#from PyObjCTools.AppHelper import installMachInterrupt</span>
-<span class="c">#		#installMachInterrupt()</span>
-<span class="c">#		print &quot;...done&quot; ###</span>
-<span class="c">#</span>
-<span class="c">#def _sigint_handler(signum):</span>
-<span class="c">#	print &quot;_sigint_handler&quot; ###</span>
-<span class="c">#	raise KeyboardInterrupt</span>
-
-<span class="c">#def _install_sigint_handler():</span>
-<span class="c">#	import signal</span>
-<span class="c">#	signal.signal(signal.SIGINT, _raise_keyboard_interrupt)</span>
-<span class="c">#</span>
-<span class="c">#def _raise_keyboard_interrupt(signum, frame):</span>
-<span class="c">#	raise KeyboardInterrupt</span>
-
-<span class="c">#_install_sigint_handler()</span>
-</pre></div>
-</td></tr></table></body>
-</html>

File sources/BaseAlertFunctions.html

-<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
-   "http://www.w3.org/TR/html4/strict.dtd">
-
-<html>
-<head>
-  <title>BaseAlertFunctions.py</title>
-  <meta http-equiv="content-type" content="text/html; charset=latin1">
-  <link rel="stylesheet" href="../code.css" type="text/css">
-</head>
-<body>
-<h2>BaseAlertFunctions.py</h2>
-
-<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>
-
-
-
-
-
-
-
-
-10
-
-
-
-
-
-
-
-
-
-20
-
-
-
-
-
-
-
-
-</pre></div></td><td class="code"><div class="highlight"><pre><span class="c">#</span>
-<span class="c">#		Python GUI - Basic alert functions - Cocoa</span>
-<span class="c">#</span>
-
-<span class="kn">from</span> <span class="nn">AppKit</span> <span class="kn">import</span> \
-    <span class="n">NSRunAlertPanel</span><span class="p">,</span> <span class="n">NSRunCriticalAlertPanel</span><span class="p">,</span> <span class="n">NSRunInformationalAlertPanel</span>
-
-<span class="k">def</span> <span class="nf">alert</span><span class="p">(</span><span class="n">kind</span><span class="p">,</span> <span class="n">prompt</span><span class="p">,</span> <span class="n">ok_label</span><span class="p">,</span> <span class="o">**</span><span class="n">kwds</span><span class="p">):</span>
-    <span class="n">alert_n</span><span class="p">(</span><span class="n">kind</span><span class="p">,</span> <span class="n">prompt</span><span class="p">,</span> <span class="n">ok_label</span><span class="p">,</span> <span class="bp">None</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span>
-
-<span class="k">def</span> <span class="nf">alert2</span><span class="p">(</span><span class="n">kind</span><span class="p">,</span> <span class="n">prompt</span><span class="p">,</span> <span class="n">yes_label</span><span class="p">,</span> <span class="n">no_label</span><span class="p">,</span> <span class="o">**</span><span class="n">kwds</span><span class="p">):</span>
-    <span class="k">return</span> <span class="n">alert_n</span><span class="p">(</span><span class="n">kind</span><span class="p">,</span> <span class="n">prompt</span><span class="p">,</span> <span class="n">yes_label</span><span class="p">,</span> <span class="n">no_label</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span>
-
-<span class="k">def</span> <span class="nf">alert3</span><span class="p">(</span><span class="n">kind</span><span class="p">,</span> <span class="n">prompt</span><span class="p">,</span> <span class="n">yes_label</span><span class="p">,</span> <span class="n">no_label</span><span class="p">,</span> <span class="n">other_label</span><span class="p">,</span> <span class="o">**</span><span class="n">kwds</span><span class="p">):</span>
-    <span class="k">return</span> <span class="n">alert_n</span><span class="p">(</span><span class="n">kind</span><span class="p">,</span> <span class="n">prompt</span><span class="p">,</span> <span class="n">yes_label</span><span class="p">,</span> <span class="n">no_label</span><span class="p">,</span> <span class="n">other_label</span><span class="p">)</span>
-
-<span class="k">def</span> <span class="nf">alert_n</span><span class="p">(</span><span class="n">kind</span><span class="p">,</span> <span class="n">prompt</span><span class="p">,</span> <span class="n">label1</span><span class="p">,</span> <span class="n">label2</span><span class="p">,</span> <span class="n">label3</span><span class="p">):</span>
-    <span class="n">splat</span> <span class="o">=</span> <span class="n">prompt</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&quot;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
-    <span class="n">title</span> <span class="o">=</span> <span class="n">splat</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
-    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">splat</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
-        <span class="n">msg</span> <span class="o">=</span> <span class="n">splat</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
-    <span class="k">else</span><span class="p">:</span>
-        <span class="n">msg</span> <span class="o">=</span> <span class="s">&quot;&quot;</span>
-    <span class="k">if</span> <span class="n">kind</span> <span class="o">==</span> <span class="s">&#39;caution&#39;</span><span class="p">:</span>
-        <span class="k">return</span> <span class="n">NSRunCriticalAlertPanel</span><span class="p">(</span><span class="n">title</span><span class="p">,</span> <span class="n">msg</span><span class="p">,</span> <span class="n">label1</span><span class="p">,</span> <span class="n">label2</span><span class="p">,</span> <span class="n">label3</span><span class="p">)</span>
-    <span class="k">elif</span> <span class="n">kind</span> <span class="o">==</span> <span class="s">&#39;note&#39;</span><span class="p">:</span>
-        <span class="k">return</span> <span class="n">NSRunInformationalAlertPanel</span><span class="p">(</span><span class="n">title</span><span class="p">,</span> <span class="n">msg</span><span class="p">,</span> <span class="n">label1</span><span class="p">,</span> <span class="n">label2</span><span class="p">,</span> <span class="n">label3</span><span class="p">)</span>
-    <span class="k">else</span><span class="p">:</span>
-        <span class="k">return</span> <span class="n">NSRunAlertPanel</span><span class="p">(</span><span class="n">title</span><span class="p">,</span> <span class="n">msg</span><span class="p">,</span> <span class="n">label1</span><span class="p">,</span> <span class="n">label2</span><span class="p">,</span> <span class="n">label3</span><span class="p">)</span>
-</pre></div>
-</td></tr></table></body>
-</html>

File sources/BaseFileDialogs.html

-<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
-   "http://www.w3.org/TR/html4/strict.dtd">
-
-<html>
-<head>
-  <title>BaseFileDialogs.py</title>
-  <meta http-equiv="content-type" content="text/html; charset=latin1">
-  <link rel="stylesheet" href="../code.css" type="text/css">
-</head>
-<body>
-<h2>BaseFileDialogs.py</h2>
-
-<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>
-
-
-
-
-
-
-
-
-10
-
-
-
-
-
-
-
-
-
-20
-
-
-
-
-
-
-
-
-
-30
-
-
-
-
-
-
-
-
-
-40
-
-
-
-
-
-
-
-
-
-50
-
-
-
-
-
-
-
-
-
-60
-
-
-</pre></div></td><td class="code"><div class="highlight"><pre><span class="c">#</span>
-<span class="c">#   Python GUI - File selection dialogs - Cocoa</span>
-<span class="c">#</span>
-
-<span class="kn">from</span> <span class="nn">AppKit</span> <span class="kn">import</span> <span class="n">NSOpenPanel</span><span class="p">,</span> <span class="n">NSSavePanel</span><span class="p">,</span> <span class="n">NSOKButton</span>
-<span class="kn">from</span> <span class="nn">Files</span> <span class="kn">import</span> <span class="n">FileRef</span>
-<span class="kn">from</span> <span class="nn">Applications</span> <span class="kn">import</span> <span class="n">application</span>
-
-<span class="c">#------------------------------------------------------------------</span>
-
-<span class="k">def</span> <span class="nf">_request_old</span><span class="p">(</span><span class="n">prompt</span><span class="p">,</span> <span class="n">default_dir</span><span class="p">,</span> <span class="n">file_types</span><span class="p">,</span> <span class="nb">dir</span><span class="p">,</span> <span class="n">multiple</span><span class="p">):</span>
-    <span class="n">ns_panel</span> <span class="o">=</span> <span class="n">NSOpenPanel</span><span class="o">.</span><span class="n">openPanel</span><span class="p">()</span>
-    <span class="k">if</span> <span class="n">prompt</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s">&quot;:&quot;</span><span class="p">):</span>
-        <span class="n">prompt</span> <span class="o">=</span> <span class="n">prompt</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
-    <span class="n">ns_panel</span><span class="o">.</span><span class="n">setTitle_</span><span class="p">(</span><span class="n">prompt</span><span class="p">)</span>
-    <span class="n">ns_panel</span><span class="o">.</span><span class="n">setCanChooseFiles_</span><span class="p">(</span><span class="ow">not</span> <span class="nb">dir</span><span class="p">)</span>
-    <span class="n">ns_panel</span><span class="o">.</span><span class="n">setCanChooseDirectories_</span><span class="p">(</span><span class="nb">dir</span><span class="p">)</span>
-    <span class="n">ns_panel</span><span class="o">.</span><span class="n">setAllowsMultipleSelection_</span><span class="p">(</span><span class="n">multiple</span><span class="p">)</span>
-    <span class="k">if</span> <span class="n">default_dir</span><span class="p">:</span>
-        <span class="n">ns_dir</span> <span class="o">=</span> <span class="n">default_dir</span><span class="o">.</span><span class="n">path</span>
-    <span class="k">else</span><span class="p">:</span>
-        <span class="n">ns_dir</span> <span class="o">=</span> <span class="bp">None</span>
-    <span class="k">if</span> <span class="n">file_types</span><span class="p">:</span>
-        <span class="n">ns_types</span> <span class="o">=</span> <span class="p">[]</span>
-        <span class="k">for</span> <span class="nb">type</span> <span class="ow">in</span> <span class="n">file_types</span><span class="p">:</span>
-            <span class="n">ns_types</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="nb">type</span><span class="o">.</span><span class="n">_ns_file_types</span><span class="p">())</span>
-    <span class="k">else</span><span class="p">:</span>
-        <span class="n">ns_types</span> <span class="o">=</span> <span class="bp">None</span>
-    <span class="n">result</span> <span class="o">=</span> <span class="n">ns_panel</span><span class="o">.</span><span class="n">runModalForDirectory_file_types_</span><span class="p">(</span><span class="n">ns_dir</span><span class="p">,</span> <span class="bp">None</span><span class="p">,</span> <span class="n">ns_types</span><span class="p">)</span>
-    <span class="k">if</span> <span class="n">result</span> <span class="o">==</span> <span class="n">NSOKButton</span><span class="p">:</span>
-        <span class="k">if</span> <span class="n">multiple</span><span class="p">:</span>
-            <span class="k">return</span> <span class="p">[</span><span class="n">FileRef</span><span class="p">(</span><span class="n">path</span> <span class="o">=</span> <span class="n">path</span><span class="p">)</span> <span class="k">for</span> <span class="n">path</span> <span class="ow">in</span> <span class="n">ns_panel</span><span class="o">.</span><span class="n">filenames</span><span class="p">()]</span>
-        <span class="k">else</span><span class="p">:</span>
-            <span class="k">return</span> <span class="n">FileRef</span><span class="p">(</span><span class="n">path</span> <span class="o">=</span> <span class="n">ns_panel</span><span class="o">.</span><span class="n">filename</span><span class="p">())</span>
-    <span class="k">else</span><span class="p">:</span>
-        <span class="k">return</span> <span class="bp">None</span>
-
-<span class="c">#------------------------------------------------------------------</span>
-
-<span class="k">def</span> <span class="nf">_request_new</span><span class="p">(</span><span class="n">prompt</span><span class="p">,</span> <span class="n">default_dir</span><span class="p">,</span> <span class="n">default_name</span><span class="p">,</span> <span class="n">file_type</span><span class="p">,</span> <span class="nb">dir</span><span class="p">):</span>
-    <span class="n">ns_panel</span> <span class="o">=</span> <span class="n">NSSavePanel</span><span class="o">.</span><span class="n">savePanel</span><span class="p">()</span>
-    <span class="c">#if prompt.endswith(&quot;:&quot;):</span>
-    <span class="c">#	prompt = prompt[:-1]</span>
-    <span class="c">#if prompt.lower().endswith(&quot; as&quot;):</span>
-    <span class="c">#	prompt = prompt[:-3]</span>
-    <span class="c">#ns_panel.setTitle_(prompt)</span>
-    <span class="c">#print &quot;_request_new: setting label to&quot;, repr(prompt) ###</span>
-    <span class="n">ns_panel</span><span class="o">.</span><span class="n">setNameFieldLabel_</span><span class="p">(</span><span class="n">prompt</span><span class="p">)</span>
-    <span class="k">if</span> <span class="n">default_dir</span><span class="p">:</span>
-        <span class="n">ns_dir</span> <span class="o">=</span> <span class="n">default_dir</span><span class="o">.</span><span class="n">path</span>
-    <span class="k">else</span><span class="p">:</span>
-        <span class="n">ns_dir</span> <span class="o">=</span> <span class="bp">None</span>
-    <span class="k">if</span> <span class="n">file_type</span><span class="p">:</span>
-        <span class="n">suffix</span> <span class="o">=</span> <span class="n">file_type</span><span class="o">.</span><span class="n">suffix</span>
-        <span class="k">if</span> <span class="n">suffix</span><span class="p">:</span>
-            <span class="n">ns_panel</span><span class="o">.</span><span class="n">setCanSelectHiddenExtension_</span><span class="p">(</span><span class="bp">True</span><span class="p">)</span>
-            <span class="k">if</span> <span class="ow">not</span> <span class="n">file_type</span><span class="o">.</span><span class="n">mac_type</span> <span class="ow">or</span> <span class="n">file_type</span><span class="o">.</span><span class="n">mac_force_suffix</span><span class="p">:</span>
-                <span class="n">ns_panel</span><span class="o">.</span><span class="n">setRequiredFileType_</span><span class="p">(</span><span class="n">suffix</span><span class="p">)</span>
-    <span class="n">result</span> <span class="o">=</span> <span class="n">ns_panel</span><span class="o">.</span><span class="n">runModalForDirectory_file_</span><span class="p">(</span><span class="n">ns_dir</span><span class="p">,</span> <span class="n">default_name</span><span class="p">)</span>
-    <span class="k">if</span> <span class="n">result</span> <span class="o">==</span> <span class="n">NSOKButton</span><span class="p">:</span>
-        <span class="k">return</span> <span class="n">FileRef</span><span class="p">(</span><span class="n">path</span> <span class="o">=</span> <span class="n">ns_panel</span><span class="o">.</span><span class="n">filename</span><span class="p">())</span>
-    <span class="k">else</span><span class="p">:</span>
-        <span class="k">return</span> <span class="bp">None</span>
-</pre></div>
-</td></tr></table></body>
-</html>

File sources/ButtonBasedControls.html

-<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
-   "http://www.w3.org/TR/html4/strict.dtd">
-
-<html>
-<head>
-  <title>ButtonBasedControls.py</title>
-  <meta http-equiv="content-type" content="text/html; charset=latin1">
-  <link rel="stylesheet" href="../code.css" type="text/css">
-</head>
-<body>
-<h2>ButtonBasedControls.py</h2>
-
-<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>
-
-
-
-
-
-
-
-
-10
-
-
-
-
-
-
-
-
-
-20
-
-
-
-
-
-
-
-
-
-30
-
-
-
-
-
-
-
-
-
-40
-
-
-
-
-
-
-
-
-
-50
-
-
-
-
-
-
-
-
-
-60
-
-
-
-
-
-
-
-
-
-70
-
-
-
-
-
-
-
-
-
-80
-
-
-
-
-</pre></div></td><td class="code"><div class="highlight"><pre><span class="c">#------------------------------------------------------------------------------</span>
-<span class="c">#</span>
-<span class="c">#   Python GUI - PyObjC version</span>
-<span class="c">#</span>
-<span class="c">#   Mixin class for controls based on NSButton</span>
-<span class="c">#</span>
-<span class="c">#------------------------------------------------------------------------------</span>
-
-<span class="kn">from</span> <span class="nn">Foundation</span> <span class="kn">import</span> <span class="n">NSMutableDictionary</span><span class="p">,</span> <span class="n">NSAttributedString</span>
-<span class="kn">from</span> <span class="nn">AppKit</span> <span class="kn">import</span> <span class="n">NSMutableParagraphStyle</span><span class="p">,</span> <span class="n">NSFontAttributeName</span><span class="p">,</span> \
-    <span class="n">NSForegroundColorAttributeName</span><span class="p">,</span> <span class="n">NSParagraphStyleAttributeName</span><span class="p">,</span> \
-    <span class="n">NSButton</span>
-<span class="kn">from</span> <span class="nn">Utils</span> <span class="kn">import</span> <span class="n">NSMultiClass</span>
-<span class="kn">from</span> <span class="nn">Components</span> <span class="kn">import</span> <span class="n">ns_set_action</span><span class="p">,</span> <span class="n">PyGUI_NS_EventHandler</span>
-<span class="kn">from</span> <span class="nn">Controls</span> <span class="kn">import</span> <span class="n">Control</span><span class="p">,</span> <span class="n">ns_size_to_fit</span>
-<span class="kn">from</span> <span class="nn">StdColors</span> <span class="kn">import</span> <span class="n">black</span>
-
-<span class="c">#------------------------------------------------------------------------------</span>
-
-<span class="k">class</span> <span class="nc">ButtonBasedControl</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
-
-    <span class="n">_ns_handle_mouse</span> <span class="o">=</span> <span class="bp">True</span>
-
-    <span class="n">_color</span> <span class="o">=</span> <span class="bp">None</span>
-
-    <span class="k">def</span> <span class="nf">_create_ns_button</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">title</span><span class="p">,</span> <span class="n">font</span><span class="p">,</span> <span class="n">ns_button_type</span><span class="p">,</span> <span class="n">ns_bezel_style</span><span class="p">,</span>
-            <span class="n">padding</span> <span class="o">=</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)):</span>
-        <span class="n">ns_button</span> <span class="o">=</span> <span class="n">PyGUI_NSButton</span><span class="o">.</span><span class="n">alloc</span><span class="p">()</span><span class="o">.</span><span class="n">init</span><span class="p">()</span>
-        <span class="n">ns_button</span><span class="o">.</span><span class="n">pygui_component</span> <span class="o">=</span> <span class="bp">self</span>
-        <span class="n">ns_button</span><span class="o">.</span><span class="n">setButtonType_</span><span class="p">(</span><span class="n">ns_button_type</span><span class="p">)</span>
-        <span class="n">ns_button</span><span class="o">.</span><span class="n">setBezelStyle_</span><span class="p">(</span><span class="n">ns_bezel_style</span><span class="p">)</span>
-        <span class="n">ns_button</span><span class="o">.</span><span class="n">setTitle_</span><span class="p">(</span><span class="n">title</span><span class="p">)</span>
-        <span class="n">ns_button</span><span class="o">.</span><span class="n">setFont_</span><span class="p">(</span><span class="n">font</span><span class="o">.</span><span class="n">_ns_font</span><span class="p">)</span>
-        <span class="n">num_lines</span> <span class="o">=</span> <span class="n">title</span><span class="o">.</span><span class="n">count</span><span class="p">(</span><span class="s">&quot;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span>
-        <span class="n">ns_size_to_fit</span><span class="p">(</span><span class="n">ns_button</span><span class="p">,</span> <span class="n">padding</span> <span class="o">=</span> <span class="n">padding</span><span class="p">,</span>
-            <span class="n">height</span> <span class="o">=</span> <span class="n">font</span><span class="o">.</span><span class="n">line_height</span> <span class="o">*</span> <span class="n">num_lines</span> <span class="o">+</span> <span class="mi">5</span><span class="p">)</span>
-        <span class="n">ns_set_action</span><span class="p">(</span><span class="n">ns_button</span><span class="p">,</span> <span class="s">&#39;doAction:&#39;</span><span class="p">)</span>
-        <span class="k">return</span> <span class="n">ns_button</span>
-
-    <span class="k">def</span> <span class="nf">set_title</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">title</span><span class="p">):</span>
-        <span class="n">Control</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">title</span><span class="p">)</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_ns_update_attributed_title</span><span class="p">()</span>
-    
-    <span class="k">def</span> <span class="nf">set_font</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">font</span><span class="p">):</span>
-        <span class="n">Control</span><span class="o">.</span><span class="n">set_font</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">font</span><span class="p">)</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_ns_update_attributed_title</span><span class="p">()</span>
-    
-    <span class="k">def</span> <span class="nf">set_just</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">just</span><span class="p">):</span>
-        <span class="n">Control</span><span class="o">.</span><span class="n">set_just</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">just</span><span class="p">)</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_ns_update_attributed_title</span><span class="p">()</span>
-    
-    <span class="k">def</span> <span class="nf">get_color</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
-        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_color</span><span class="p">:</span>
-            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_color</span>
-        <span class="k">else</span><span class="p">:</span>
-            <span class="k">return</span> <span class="n">black</span>
-    
-    <span class="k">def</span> <span class="nf">set_color</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">color</span><span class="p">):</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_color</span> <span class="o">=</span> <span class="n">color</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_ns_update_attributed_title</span><span class="p">()</span>
-    
-    <span class="c">#  There is no direct way of setting the text colour of the title;</span>
-    <span class="c">#  it must be done using an attributed string. But when doing</span>
-    <span class="c">#  this, the attributes must include the font and alignment</span>
-    <span class="c">#  as well. So when using a custom color, we construct a new</span>
-    <span class="c">#  attributed string whenever the title, font, alignment or color</span>
-    <span class="c">#  is changed.</span>
-
-    <span class="k">def</span> <span class="nf">_ns_update_attributed_title</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
-        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_color</span><span class="p">:</span>
-            <span class="n">ns_button</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ns_view</span>
-            <span class="n">ns_attrs</span> <span class="o">=</span> <span class="n">NSMutableDictionary</span><span class="o">.</span><span class="n">alloc</span><span class="p">()</span><span class="o">.</span><span class="n">init</span><span class="p">()</span>
-            <span class="n">ns_attrs</span><span class="p">[</span><span class="n">NSFontAttributeName</span><span class="p">]</span> <span class="o">=</span> <span class="n">ns_button</span><span class="o">.</span><span class="n">font</span><span class="p">()</span>
-            <span class="n">ns_attrs</span><span class="p">[</span><span class="n">NSForegroundColorAttributeName</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_color</span><span class="o">.</span><span class="n">_ns_color</span>
-            <span class="n">ns_parstyle</span> <span class="o">=</span> <span class="n">NSMutableParagraphStyle</span><span class="o">.</span><span class="n">alloc</span><span class="p">()</span><span class="o">.</span><span class="n">init</span><span class="p">()</span>
-            <span class="n">ns_parstyle</span><span class="o">.</span><span class="n">setAlignment_</span><span class="p">(</span><span class="n">ns_button</span><span class="o">.</span><span class="n">alignment</span><span class="p">())</span>
-            <span class="n">ns_attrs</span><span class="p">[</span><span class="n">NSParagraphStyleAttributeName</span><span class="p">]</span> <span class="o">=</span> <span class="n">ns_parstyle</span>
-            <span class="n">ns_attstr</span> <span class="o">=</span> <span class="n">NSAttributedString</span><span class="o">.</span><span class="n">alloc</span><span class="p">()</span><span class="o">.</span><span class="n">initWithString_attributes_</span><span class="p">(</span>
-                <span class="n">ns_button</span><span class="o">.</span><span class="n">title</span><span class="p">(),</span> <span class="n">ns_attrs</span><span class="p">)</span>
-            <span class="n">ns_button</span><span class="o">.</span><span class="n">setAttributedTitle_</span><span class="p">(</span><span class="n">ns_attstr</span><span class="p">)</span>
-    
-<span class="c">#------------------------------------------------------------------------------</span>
-
-<span class="k">class</span> <span class="nc">PyGUI_NSButton</span><span class="p">(</span><span class="n">NSButton</span><span class="p">,</span> <span class="n">PyGUI_NS_EventHandler</span><span class="p">):</span>
-    <span class="n">__metaclass__</span> <span class="o">=</span> <span class="n">NSMultiClass</span>
-</pre></div>
-</td></tr></table></body>
-</html>

File sources/Buttons.html

-<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
-   "http://www.w3.org/TR/html4/strict.dtd">
-
-<html>
-<head>
-  <title>Buttons.py</title>
-  <meta http-equiv="content-type" content="text/html; charset=latin1">
-  <link rel="stylesheet" href="../code.css" type="text/css">
-</head>
-<body>
-<h2>Buttons.py</h2>
-
-<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>
-
-
-
-
-
-
-
-
-10
-
-
-
-
-
-
-
-
-
-20
-
-
-
-
-
-
-
-
-
-30
-
-
-
-
-
-
-
-
-
-40
-
-</pre></div></td><td class="code"><div class="highlight"><pre><span class="c">#</span>
-<span class="c">#   Python GUI - Buttons - PyObjC version</span>
-<span class="c">#</span>
-
-<span class="kn">import</span> <span class="nn">AppKit</span>
-<span class="kn">from</span> <span class="nn">StdFonts</span> <span class="kn">import</span> <span class="n">system_font</span>
-<span class="kn">from</span> <span class="nn">ButtonBasedControls</span> <span class="kn">import</span> <span class="n">ButtonBasedControl</span>
-<span class="kn">from</span> <span class="nn">GButtons</span> <span class="kn">import</span> <span class="n">Button</span> <span class="k">as</span> <span class="n">GButton</span>
-
-<span class="n">_style_to_ns_key_equivalent</span> <span class="o">=</span> <span class="p">{</span>
-    <span class="s">&#39;default&#39;</span><span class="p">:</span> <span class="s">&quot;</span><span class="se">\x0d</span><span class="s">&quot;</span><span class="p">,</span>
-    <span class="s">&#39;cancel&#39;</span><span class="p">:</span> <span class="s">&quot;</span><span class="se">\x1b</span><span class="s">&quot;</span><span class="p">,</span>
-<span class="p">}</span>
-
-<span class="n">_ns_key_equivalent_to_style</span> <span class="o">=</span> <span class="p">{</span>
-    <span class="s">&quot;</span><span class="se">\x0d</span><span class="s">&quot;</span><span class="p">:</span> <span class="s">&#39;default&#39;</span><span class="p">,</span>
-    <span class="s">&quot;</span><span class="se">\x1b</span><span class="s">&quot;</span><span class="p">:</span> <span class="s">&#39;cancel&#39;</span><span class="p">,</span>
-<span class="p">}</span>
-
-<span class="k">class</span> <span class="nc">Button</span><span class="p">(</span><span class="n">ButtonBasedControl</span><span class="p">,</span> <span class="n">GButton</span><span class="p">):</span>
-
-    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">title</span> <span class="o">=</span> <span class="s">&quot;New Button&quot;</span><span class="p">,</span> <span class="n">font</span> <span class="o">=</span> <span class="n">system_font</span><span class="p">,</span> <span class="o">**</span><span class="n">kwds</span><span class="p">):</span>
-        <span class="n">ns_button</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_create_ns_button</span><span class="p">(</span><span class="n">title</span> <span class="o">=</span> <span class="n">title</span><span class="p">,</span> <span class="n">font</span> <span class="o">=</span> <span class="n">font</span><span class="p">,</span>
-            <span class="n">ns_button_type</span> <span class="o">=</span> <span class="n">AppKit</span><span class="o">.</span><span class="n">NSMomentaryLight</span><span class="p">,</span>
-            <span class="n">ns_bezel_style</span> <span class="o">=</span> <span class="n">AppKit</span><span class="o">.</span><span class="n">NSRoundedBezelStyle</span><span class="p">,</span>
-            <span class="n">padding</span> <span class="o">=</span> <span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
-        <span class="p">)</span>
-        <span class="n">GButton</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">_ns_view</span> <span class="o">=</span> <span class="n">ns_button</span><span class="p">,</span> <span class="o">**</span><span class="n">kwds</span><span class="p">)</span>
-    
-    <span class="k">def</span> <span class="nf">get_style</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
-        <span class="n">ns_key</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ns_view</span><span class="o">.</span><span class="n">getKeyEquivalent</span><span class="p">()</span>
-        <span class="k">return</span> <span class="n">_ns_key_equivalent_to_style</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">ns_key</span><span class="p">,</span> <span class="s">&#39;normal&#39;</span><span class="p">)</span>
-    
-    <span class="k">def</span> <span class="nf">set_style</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">style</span><span class="p">):</span>
-        <span class="n">ns_key</span> <span class="o">=</span> <span class="n">_style_to_ns_key_equivalent</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">style</span><span class="p">,</span> <span class="s">&quot;&quot;</span><span class="p">)</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_ns_view</span><span class="o">.</span><span class="n">setKeyEquivalent_</span><span class="p">(</span><span class="n">ns_key</span><span class="p">)</span>
-
-    <span class="k">def</span> <span class="nf">activate</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_ns_view</span><span class="o">.</span><span class="n">performClick_</span><span class="p">(</span><span class="bp">None</span><span class="p">)</span>
-
-<span class="c">#	def key_down(self, e): ###</span>
-<span class="c">#		print &quot;Button.key_down:&quot;, e ###</span>
-</pre></div>
-</td></tr></table></body>
-</html>

File sources/Canvases.html

-<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
-   "http://www.w3.org/TR/html4/strict.dtd">
-
-<html>
-<head>
-  <title>Canvases.py</title>
-  <meta http-equiv="content-type" content="text/html; charset=latin1">
-  <link rel="stylesheet" href="../code.css" type="text/css">
-</head>
-<body>
-<h2>Canvases.py</h2>
-
-<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>
-
-
-
-
-
-
-
-
- 10
-
-
-
-
-
-
-
-
-
- 20
-
-
-
-
-
-
-
-
-
- 30
-
-
-
-
-
-
-
-
-
- 40
-
-
-
-
-
-
-
-
-
- 50
-
-
-
-
-
-
-
-
-
- 60
-
-
-
-
-
-
-
-
-
- 70
-
-
-
-
-
-
-
-
-
- 80
-
-
-
-
-
-
-
-
-
- 90
-
-
-
-
-
-
-
-
-
-100
-
-
-
-
-
-
-
-
-
-110
-
-
-
-
-
-
-
-
-
-120
-
-
-
-
-
-
-
-
-
-130
-
-
-
-
-
-
-
-
-
-140
-
-
-
-
-
-
-
-
-
-150
-
-
-
-
-
-
-
-
-
-160
-
-
-
-
-
-
-
-
-
-170
-
-
-
-
-
-
-
-
-
-180
-
-
-
-
-
-
-
-
-
-190
-
-
-
-
-
-
-
-
-
-200
-
-
-
-
-
-
-
-
-
-210
-
-
-
-
-
-
-
-
-
-220
-
-
-
-
-
-
-
-
-
-230
-
-
-
-
-
-
-
-
-
-240
-
-</pre></div></td><td class="code"><div class="highlight"><pre><span class="c">#</span>
-<span class="c">#   Python GUI - Drawing - PyObjC</span>
-<span class="c">#</span>
-
-<span class="kn">from</span> <span class="nn">Foundation</span> <span class="kn">import</span> <span class="n">NSPoint</span><span class="p">,</span> <span class="n">NSMakeRect</span><span class="p">,</span> <span class="n">NSString</span>
-<span class="kn">from</span> <span class="nn">AppKit</span> <span class="kn">import</span> <span class="n">NSGraphicsContext</span><span class="p">,</span> <span class="n">NSBezierPath</span><span class="p">,</span> <span class="n">NSEvenOddWindingRule</span><span class="p">,</span> \
-    <span class="n">NSFontAttributeName</span><span class="p">,</span> <span class="n">NSForegroundColorAttributeName</span><span class="p">,</span> \
-    <span class="n">NSCompositeCopy</span><span class="p">,</span> <span class="n">NSCompositeSourceOver</span>
-<span class="kn">from</span> <span class="nn">StdColors</span> <span class="kn">import</span> <span class="n">black</span><span class="p">,</span> <span class="n">white</span>
-<span class="kn">from</span> <span class="nn">GCanvases</span> <span class="kn">import</span> <span class="n">Canvas</span> <span class="k">as</span> <span class="n">GCanvas</span>
-
-<span class="k">class</span> <span class="nc">Canvas</span><span class="p">(</span><span class="n">GCanvas</span><span class="p">):</span>
-
-    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_ns_path</span> <span class="o">=</span> <span class="n">NSBezierPath</span><span class="o">.</span><span class="n">bezierPath</span><span class="p">()</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_ns_path</span><span class="o">.</span><span class="n">setWindingRule_</span><span class="p">(</span><span class="n">NSEvenOddWindingRule</span><span class="p">)</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_stack</span> <span class="o">=</span> <span class="p">[]</span>
-        <span class="n">ctx</span> <span class="o">=</span> <span class="n">NSGraphicsContext</span><span class="o">.</span><span class="n">currentContext</span><span class="p">()</span>
-        <span class="n">ctx</span><span class="o">.</span><span class="n">setCompositingOperation_</span><span class="p">(</span><span class="n">NSCompositeSourceOver</span><span class="p">)</span>
-        <span class="n">GCanvas</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">initgraphics</span><span class="p">()</span>
-    
-    <span class="k">def</span> <span class="nf">get_pencolor</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
-        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_pencolor</span>
-    
-    <span class="k">def</span> <span class="nf">set_pencolor</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">c</span><span class="p">):</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_pencolor</span> <span class="o">=</span> <span class="n">c</span>
-    
-    <span class="k">def</span> <span class="nf">get_fillcolor</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
-        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_fillcolor</span>
-    
-    <span class="k">def</span> <span class="nf">set_fillcolor</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">c</span><span class="p">):</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_fillcolor</span> <span class="o">=</span> <span class="n">c</span>
-    
-    <span class="k">def</span> <span class="nf">get_textcolor</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
-        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_textcolor</span>
-    
-    <span class="k">def</span> <span class="nf">set_textcolor</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">c</span><span class="p">):</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_textcolor</span> <span class="o">=</span> <span class="n">c</span>
-    
-    <span class="k">def</span> <span class="nf">get_backcolor</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
-        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_backcolor</span>
-    
-    <span class="k">def</span> <span class="nf">set_backcolor</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">c</span><span class="p">):</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_backcolor</span> <span class="o">=</span> <span class="n">c</span>
-    
-    <span class="k">def</span> <span class="nf">get_pensize</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
-        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_pensize</span>
-    
-    <span class="k">def</span> <span class="nf">set_pensize</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_pensize</span> <span class="o">=</span> <span class="n">d</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_ns_path</span><span class="o">.</span><span class="n">setLineWidth_</span><span class="p">(</span><span class="n">d</span><span class="p">)</span>
-    
-    <span class="k">def</span> <span class="nf">get_font</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
-        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_font</span>
-    
-    <span class="k">def</span> <span class="nf">set_font</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">f</span><span class="p">):</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_font</span> <span class="o">=</span> <span class="n">f</span>
-    
-    <span class="k">def</span> <span class="nf">get_current_point</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
-        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ns_path</span><span class="o">.</span><span class="n">currentPoint</span><span class="p">()</span>
-    
-    <span class="k">def</span> <span class="nf">newpath</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_ns_path</span><span class="o">.</span><span class="n">removeAllPoints</span><span class="p">()</span>
-    
-    <span class="k">def</span> <span class="nf">moveto</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">):</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_ns_path</span><span class="o">.</span><span class="n">moveToPoint_</span><span class="p">((</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">))</span>
-    
-    <span class="k">def</span> <span class="nf">rmoveto</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dx</span><span class="p">,</span> <span class="n">dy</span><span class="p">):</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_ns_path</span><span class="o">.</span><span class="n">relativeMoveToPoint_</span><span class="p">((</span><span class="n">dx</span><span class="p">,</span> <span class="n">dy</span><span class="p">))</span>
-
-    <span class="k">def</span> <span class="nf">lineto</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">):</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_ns_path</span><span class="o">.</span><span class="n">lineToPoint_</span><span class="p">((</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">))</span>
-
-    <span class="k">def</span> <span class="nf">rlineto</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dx</span><span class="p">,</span> <span class="n">dy</span><span class="p">):</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_ns_path</span><span class="o">.</span><span class="n">relativeLineToPoint_</span><span class="p">((</span><span class="n">dx</span><span class="p">,</span> <span class="n">dy</span><span class="p">))</span>
-    
-    <span class="k">def</span> <span class="nf">curveto</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cp1</span><span class="p">,</span> <span class="n">cp2</span><span class="p">,</span> <span class="n">ep</span><span class="p">):</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_ns_path</span><span class="o">.</span><span class="n">curveToPoint_controlPoint1_controlPoint2_</span><span class="p">(</span>
-            <span class="n">ep</span><span class="p">,</span> <span class="n">cp1</span><span class="p">,</span> <span class="o">*</span><span class="n">cp2</span><span class="p">)</span>
-    
-    <span class="k">def</span> <span class="nf">rcurveto</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cp1</span><span class="p">,</span> <span class="n">cp2</span><span class="p">,</span> <span class="n">ep</span><span class="p">):</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_ns_path</span><span class="o">.</span><span class="n">relativeCurveToPoint_controlPoint1_controlPoint2_</span><span class="p">(</span>
-            <span class="n">ep</span><span class="p">,</span> <span class="n">cp1</span><span class="p">,</span> <span class="n">cp2</span><span class="p">)</span>
-    
-    <span class="k">def</span> <span class="nf">arc</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">r</span><span class="p">,</span> <span class="n">a0</span><span class="p">,</span> <span class="n">a1</span><span class="p">):</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_ns_path</span><span class="o">.</span><span class="n">appendBezierPathWithArcWithCenter_radius_startAngle_endAngle_</span><span class="p">(</span>
-            <span class="n">c</span><span class="p">,</span> <span class="n">r</span><span class="p">,</span> <span class="n">a0</span><span class="p">,</span> <span class="n">a1</span><span class="p">)</span>
-    
-    <span class="k">def</span> <span class="nf">rect</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">rect</span><span class="p">):</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_ns_path</span><span class="o">.</span><span class="n">appendBezierPathWithRect_</span><span class="p">(</span><span class="n">_ns_rect</span><span class="p">(</span><span class="n">rect</span><span class="p">))</span>
-    
-    <span class="k">def</span> <span class="nf">oval</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">rect</span><span class="p">):</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_ns_path</span><span class="o">.</span><span class="n">appendBezierPathWithOvalInRect</span><span class="p">(</span><span class="n">_ns_rect</span><span class="p">(</span><span class="n">rect</span><span class="p">))</span>
-    
-    <span class="k">def</span> <span class="nf">lines</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">points</span><span class="p">):</span>
-        <span class="n">ns</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ns_path</span>
-        <span class="n">ns</span><span class="o">.</span><span class="n">moveToPoint_</span><span class="p">(</span><span class="n">points</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
-        <span class="n">ns</span><span class="o">.</span><span class="n">appendBezierPathWithPoints_count_</span><span class="p">(</span><span class="n">points</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">points</span><span class="p">))</span>
-    
-    <span class="k">def</span> <span class="nf">poly</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">points</span><span class="p">):</span>
-        <span class="n">ns</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ns_path</span>
-        <span class="n">ns</span><span class="o">.</span><span class="n">moveToPoint_</span><span class="p">(</span><span class="n">points</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
-        <span class="n">ns</span><span class="o">.</span><span class="n">appendBezierPathWithPoints_count_</span><span class="p">(</span><span class="n">points</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">points</span><span class="p">))</span>
-        <span class="n">ns</span><span class="o">.</span><span class="n">closePath</span><span class="p">()</span>
-
-    <span class="k">def</span> <span class="nf">closepath</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_ns_path</span><span class="o">.</span><span class="n">closePath</span><span class="p">()</span>
-
-    <span class="k">def</span> <span class="nf">clip</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
-        <span class="n">ns</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ns_path</span>
-        <span class="n">ns</span><span class="o">.</span><span class="n">addClip</span><span class="p">()</span>
-
-    <span class="k">def</span> <span class="nf">rectclip</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="p">(</span><span class="n">l</span><span class="p">,</span> <span class="n">t</span><span class="p">,</span> <span class="n">r</span><span class="p">,</span> <span class="n">b</span><span class="p">)):</span>
-        <span class="n">ns_rect</span> <span class="o">=</span> <span class="n">NSMakeRect</span><span class="p">(</span><span class="n">l</span><span class="p">,</span> <span class="n">t</span><span class="p">,</span> <span class="n">r</span> <span class="o">-</span> <span class="n">l</span><span class="p">,</span> <span class="n">b</span> <span class="o">-</span> <span class="n">t</span><span class="p">)</span>
-        <span class="n">NSBezierPath</span><span class="o">.</span><span class="n">clipRect_</span><span class="p">(</span><span class="n">ns_rect</span><span class="p">)</span>
-
-    <span class="k">def</span> <span class="nf">gsave</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_stack</span><span class="o">.</span><span class="n">append</span><span class="p">((</span>
-            <span class="bp">self</span><span class="o">.</span><span class="n">_pencolor</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_fillcolor</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_textcolor</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_backcolor</span><span class="p">,</span>
-            <span class="bp">self</span><span class="o">.</span><span class="n">_pensize</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_font</span><span class="p">))</span>
-        <span class="n">NSGraphicsContext</span><span class="o">.</span><span class="n">currentContext</span><span class="p">()</span><span class="o">.</span><span class="n">saveGraphicsState</span><span class="p">()</span>
-    
-    <span class="k">def</span> <span class="nf">grestore</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
-        <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_pencolor</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_fillcolor</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_textcolor</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_backcolor</span><span class="p">,</span>
-            <span class="bp">self</span><span class="o">.</span><span class="n">_pensize</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_font</span><span class="p">)</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_stack</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span>
-        <span class="n">NSGraphicsContext</span><span class="o">.</span><span class="n">currentContext</span><span class="p">()</span><span class="o">.</span><span class="n">restoreGraphicsState</span><span class="p">()</span>
-    
-    <span class="k">def</span> <span class="nf">stroke</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
-        <span class="n">ns</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ns_path</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_pencolor</span><span class="o">.</span><span class="n">_ns_color</span><span class="o">.</span><span class="n">set</span><span class="p">()</span>
-        <span class="n">ns</span><span class="o">.</span><span class="n">stroke</span><span class="p">()</span>
-
-    <span class="k">def</span> <span class="nf">fill</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
-        <span class="n">ns</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ns_path</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_fillcolor</span><span class="o">.</span><span class="n">_ns_color</span><span class="o">.</span><span class="n">set</span><span class="p">()</span>
-        <span class="n">ns</span><span class="o">.</span><span class="n">fill</span><span class="p">()</span>
-    
-    <span class="k">def</span> <span class="nf">erase</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
-        <span class="n">ns</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ns_path</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_backcolor</span><span class="o">.</span><span class="n">_ns_color</span><span class="o">.</span><span class="n">set</span><span class="p">()</span>
-        <span class="n">ctx</span> <span class="o">=</span> <span class="n">NSGraphicsContext</span><span class="o">.</span><span class="n">currentContext</span><span class="p">()</span>
-        <span class="n">ctx</span><span class="o">.</span><span class="n">setCompositingOperation_</span><span class="p">(</span><span class="n">NSCompositeCopy</span><span class="p">)</span>
-        <span class="n">ns</span><span class="o">.</span><span class="n">fill</span><span class="p">()</span>
-        <span class="n">ctx</span><span class="o">.</span><span class="n">setCompositingOperation_</span><span class="p">(</span><span class="n">NSCompositeSourceOver</span><span class="p">)</span>
-    
-    <span class="k">def</span> <span class="nf">fill_stroke</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
-        <span class="n">ns</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ns_path</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_pencolor</span><span class="o">.</span><span class="n">_ns_color</span><span class="o">.</span><span class="n">set</span><span class="p">()</span>
-        <span class="n">ns</span><span class="o">.</span><span class="n">stroke</span><span class="p">()</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_fillcolor</span><span class="o">.</span><span class="n">_ns_color</span><span class="o">.</span><span class="n">set</span><span class="p">()</span>
-        <span class="n">ns</span><span class="o">.</span><span class="n">fill</span><span class="p">()</span>
-    
-    <span class="k">def</span> <span class="nf">show_text</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">text</span><span class="p">):</span>
-        <span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ns_path</span><span class="o">.</span><span class="n">currentPoint</span><span class="p">()</span>
-        <span class="n">font</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_font</span>
-        <span class="n">ns_font</span> <span class="o">=</span> <span class="n">font</span><span class="o">.</span><span class="n">_ns_font</span>
-        <span class="n">ns_color</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_textcolor</span><span class="o">.</span><span class="n">_ns_color</span>
-        <span class="n">ns_string</span> <span class="o">=</span> <span class="n">NSString</span><span class="o">.</span><span class="n">stringWithString_</span><span class="p">(</span><span class="n">text</span><span class="p">)</span>
-        <span class="n">ns_attrs</span> <span class="o">=</span> <span class="p">{</span>
-            <span class="n">NSFontAttributeName</span><span class="p">:</span> <span class="n">ns_font</span><span class="p">,</span>
-            <span class="n">NSForegroundColorAttributeName</span><span class="p">:</span> <span class="n">ns_color</span><span class="p">,</span>
-        <span class="p">}</span>
-        <span class="c">#print &quot;Canvas.show_text:&quot;, repr(text) ###</span>
-        <span class="c">#print &quot;size:&quot;, ns_font.pointSize() ###</span>
-        <span class="c">#print &quot;ascender:&quot;, ns_font.ascender() ###</span>
-        <span class="c">#print &quot;descender:&quot;, ns_font.descender() ###</span>
-        <span class="c">#print &quot;capHeight:&quot;, ns_font.capHeight() ###</span>
-        <span class="c">#print &quot;defaultLineHeightForFont:&quot;, ns_font.defaultLineHeightForFont() ###</span>
-        <span class="n">h</span> <span class="o">=</span> <span class="n">ns_font</span><span class="o">.</span><span class="n">defaultLineHeightForFont</span><span class="p">()</span>
-        <span class="n">d</span> <span class="o">=</span> <span class="o">-</span><span class="n">ns_font</span><span class="o">.</span><span class="n">descender</span><span class="p">()</span>
-        <span class="n">ns_point</span> <span class="o">=</span> <span class="n">NSPoint</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">-</span> <span class="n">h</span> <span class="o">+</span> <span class="n">d</span><span class="p">)</span>
-        <span class="c">#print &quot;drawing at:&quot;, ns_point ###</span>
-        <span class="n">ns_string</span><span class="o">.</span><span class="n">drawAtPoint_withAttributes_</span><span class="p">(</span><span class="n">ns_point</span><span class="p">,</span> <span class="n">ns_attrs</span><span class="p">)</span>
-        <span class="n">dx</span> <span class="o">=</span> <span class="n">ns_font</span><span class="o">.</span><span class="n">widthOfString_</span><span class="p">(</span><span class="n">ns_string</span><span class="p">)</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_ns_path</span><span class="o">.</span><span class="n">relativeMoveToPoint_</span><span class="p">(</span><span class="n">NSPoint</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">dx</span><span class="p">,</span> <span class="n">y</span><span class="p">))</span>
-    
-    <span class="k">def</span> <span class="nf">_ns_frame_rect</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="p">(</span><span class="n">l</span><span class="p">,</span> <span class="n">t</span><span class="p">,</span> <span class="n">r</span><span class="p">,</span> <span class="n">b</span><span class="p">)):</span>
-        <span class="n">p</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_pensize</span>
-        <span class="n">q</span> <span class="o">=</span> <span class="mf">0.5</span> <span class="o">*</span> <span class="n">p</span>
-        <span class="k">return</span> <span class="n">NSMakeRect</span><span class="p">(</span><span class="n">l</span> <span class="o">+</span> <span class="n">q</span><span class="p">,</span> <span class="n">t</span> <span class="o">+</span> <span class="n">q</span><span class="p">,</span> <span class="n">r</span> <span class="o">-</span> <span class="n">l</span> <span class="o">-</span> <span class="n">p</span><span class="p">,</span> <span class="n">b</span> <span class="o">-</span> <span class="n">t</span> <span class="o">-</span> <span class="n">p</span><span class="p">)</span>
-
-    <span class="k">def</span> <span class="nf">stroke_rect</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">r</span><span class="p">):</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_pencolor</span><span class="o">.</span><span class="n">_ns_color</span><span class="o">.</span><span class="n">set</span><span class="p">()</span>
-        <span class="n">NSBezierPath</span><span class="o">.</span><span class="n">setDefaultLineWidth_</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_pensize</span><span class="p">)</span>
-        <span class="n">NSBezierPath</span><span class="o">.</span><span class="n">strokeRect_</span><span class="p">(</span><span class="n">_ns_rect</span><span class="p">(</span><span class="n">r</span><span class="p">))</span>
-
-    <span class="k">def</span> <span class="nf">frame_rect</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">r</span><span class="p">):</span>
-        <span class="bp">self</span><span class="o">.</span><span class="n">_pencolor</span><span class="o">.</span><span class="n">_ns_color</span><span class="o">.</span><span class="n">set</span><span class="p">()</span>
-        <span class="n">NSBezierPath</span><span class="o">.</span><span class="n">setDefaultLineWidth_</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_pensize</span><span class="p">)</span>
-        <span class="n">NSBezierPath</span><span class="o">.</span><span class="n">strokeRect_</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_ns_frame_rect</span><span class="p">(</span><span class="n">r</span><span class="p">))</span>
-