mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	Use the new macresource module to open the accompanying resource file (if needed).
This commit is contained in:
		
							parent
							
								
									a5d7da528b
								
							
						
					
					
						commit
						3c06b9a7d4
					
				
					 13 changed files with 37 additions and 102 deletions
				
			
		|  | @ -10,6 +10,7 @@ | ||||||
| import sys | import sys | ||||||
| import struct | import struct | ||||||
| from Carbon import Icn | from Carbon import Icn | ||||||
|  | import macresource | ||||||
| 
 | 
 | ||||||
| # | # | ||||||
| # Resource definitions | # Resource definitions | ||||||
|  | @ -26,14 +27,7 @@ | ||||||
| MAXHEIGHT=320 | MAXHEIGHT=320 | ||||||
| 
 | 
 | ||||||
| def main(): | def main(): | ||||||
| 	try: | 	macresource.need('DLOG', ID_MAIN, "PICTbrowse.rsrc") | ||||||
| 		dummy = Res.GetResource('DLOG', ID_MAIN) |  | ||||||
| 	except Res.Error: |  | ||||||
| 		try: |  | ||||||
| 			Res.FSpOpenResFile("PICTbrowse.rsrc", 1) |  | ||||||
| 		except Res.Error, arg: |  | ||||||
| 			EasyDialogs.Message("Cannot open PICTbrowse.rsrc: "+arg[1]) |  | ||||||
| 			sys.exit(1)	 |  | ||||||
| 	ICONbrowse() | 	ICONbrowse() | ||||||
| 
 | 
 | ||||||
| class ICONbrowse(FrameWork.Application): | class ICONbrowse(FrameWork.Application): | ||||||
|  |  | ||||||
|  | @ -9,6 +9,7 @@ | ||||||
| from Carbon import List | from Carbon import List | ||||||
| import sys | import sys | ||||||
| import struct | import struct | ||||||
|  | import macresource | ||||||
| 
 | 
 | ||||||
| # | # | ||||||
| # Resource definitions | # Resource definitions | ||||||
|  | @ -21,14 +22,7 @@ | ||||||
| TOP=64 | TOP=64 | ||||||
| 
 | 
 | ||||||
| def main(): | def main(): | ||||||
| 	try: | 	macresource.need('DLOG', ID_MAIN, "PICTbrowse.rsrc") | ||||||
| 		dummy = Res.GetResource('DLOG', ID_MAIN) |  | ||||||
| 	except Res.Error: |  | ||||||
| 		try: |  | ||||||
| 			Res.FSpOpenResFile("PICTbrowse.rsrc", 1) |  | ||||||
| 		except Res.Error, arg: |  | ||||||
| 			EasyDialogs.Message("Cannot open PICTbrowse.rsrc: "+arg[1]) |  | ||||||
| 			sys.exit(1)	 |  | ||||||
| 	PICTbrowse() | 	PICTbrowse() | ||||||
| 
 | 
 | ||||||
| class PICTbrowse(FrameWork.Application): | class PICTbrowse(FrameWork.Application): | ||||||
|  |  | ||||||
|  | @ -9,6 +9,7 @@ | ||||||
| from Carbon import List | from Carbon import List | ||||||
| import sys | import sys | ||||||
| import struct | import struct | ||||||
|  | import macresource | ||||||
| 
 | 
 | ||||||
| # | # | ||||||
| # Resource definitions | # Resource definitions | ||||||
|  | @ -25,14 +26,7 @@ | ||||||
| MAXHEIGHT=320 | MAXHEIGHT=320 | ||||||
| 
 | 
 | ||||||
| def main(): | def main(): | ||||||
| 	try: | 	macresource.need('DLOG', ID_MAIN, "PICTbrowse.rsrc") | ||||||
| 		dummy = Res.GetResource('DLOG', ID_MAIN) |  | ||||||
| 	except Res.Error: |  | ||||||
| 		try: |  | ||||||
| 			Res.FSpOpenResFile("PICTbrowse.rsrc", 1) |  | ||||||
| 		except Res.Error, arg: |  | ||||||
| 			EasyDialogs.Message("Cannot open PICTbrowse.rsrc: "+arg[1]) |  | ||||||
| 			sys.exit(1)	 |  | ||||||
| 	PICTbrowse() | 	PICTbrowse() | ||||||
| 
 | 
 | ||||||
| class PICTbrowse(FrameWork.Application): | class PICTbrowse(FrameWork.Application): | ||||||
|  |  | ||||||
|  | @ -10,6 +10,7 @@ | ||||||
| import sys | import sys | ||||||
| import struct | import struct | ||||||
| from Carbon import Icn | from Carbon import Icn | ||||||
|  | import macresource | ||||||
| 
 | 
 | ||||||
| # | # | ||||||
| # Resource definitions | # Resource definitions | ||||||
|  | @ -26,14 +27,7 @@ | ||||||
| MAXHEIGHT=320 | MAXHEIGHT=320 | ||||||
| 
 | 
 | ||||||
| def main(): | def main(): | ||||||
| 	try: | 	macresource.need('DLOG', ID_MAIN, "PICTbrowse.rsrc") | ||||||
| 		dummy = Res.GetResource('DLOG', ID_MAIN) |  | ||||||
| 	except Res.Error: |  | ||||||
| 		try: |  | ||||||
| 			Res.FSpOpenResFile("PICTbrowse.rsrc", 1) |  | ||||||
| 		except Res.Error, arg: |  | ||||||
| 			EasyDialogs.Message("Cannot open PICTbrowse.rsrc: "+arg[1]) |  | ||||||
| 			sys.exit(1)	 |  | ||||||
| 	CIconbrowse() | 	CIconbrowse() | ||||||
| 
 | 
 | ||||||
| class CIconbrowse(FrameWork.Application): | class CIconbrowse(FrameWork.Application): | ||||||
|  | @ -119,9 +113,9 @@ class MyDialog(FrameWork.DialogWindow): | ||||||
| 	def open(self, id, contents): | 	def open(self, id, contents): | ||||||
| 		self.id = id | 		self.id = id | ||||||
| 		FrameWork.DialogWindow.open(self, ID_MAIN) | 		FrameWork.DialogWindow.open(self, ID_MAIN) | ||||||
| 		self.wid.SetDialogDefaultItem(MAIN_SHOW) | 		self.dlg.SetDialogDefaultItem(MAIN_SHOW) | ||||||
| 		self.contents = contents | 		self.contents = contents | ||||||
| 		self.ctl = self.wid.GetDialogItemAsControl(MAIN_LIST) | 		self.ctl = self.dlg.GetDialogItemAsControl(MAIN_LIST) | ||||||
| 		h = self.ctl.GetControlData_Handle(Controls.kControlListBoxPart,  | 		h = self.ctl.GetControlData_Handle(Controls.kControlListBoxPart,  | ||||||
| 				Controls.kControlListBoxListHandleTag) | 				Controls.kControlListBoxListHandleTag) | ||||||
| 		self.list = List.as_List(h) | 		self.list = List.as_List(h) | ||||||
|  |  | ||||||
|  | @ -8,6 +8,7 @@ | ||||||
| from Carbon import List | from Carbon import List | ||||||
| import sys | import sys | ||||||
| import struct | import struct | ||||||
|  | import macresource | ||||||
| 
 | 
 | ||||||
| # | # | ||||||
| # Resource definitions | # Resource definitions | ||||||
|  | @ -20,14 +21,7 @@ | ||||||
| TOP=64 | TOP=64 | ||||||
| 
 | 
 | ||||||
| def main(): | def main(): | ||||||
| 	try: | 	macresource.need('DLOG', ID_MAIN, "oldPICTbrowse.rsrc") | ||||||
| 		dummy = Res.GetResource('DLOG', ID_MAIN) |  | ||||||
| 	except Res.Error: |  | ||||||
| 		try: |  | ||||||
| 			Res.FSpOpenResFile("oldPICTbrowse.rsrc", 0) |  | ||||||
| 		except Res.Error, arg: |  | ||||||
| 			EasyDialogs.Message("Cannot open PICTbrowse.rsrc: "+arg[1]) |  | ||||||
| 			sys.exit(1)	 |  | ||||||
| 	PICTbrowse() | 	PICTbrowse() | ||||||
| 
 | 
 | ||||||
| class PICTbrowse(FrameWork.Application): | class PICTbrowse(FrameWork.Application): | ||||||
|  |  | ||||||
|  | @ -7,6 +7,7 @@ | ||||||
| import sys | import sys | ||||||
| import socket | import socket | ||||||
| import string | import string | ||||||
|  | import macresource | ||||||
| # | # | ||||||
| # Definitions for our resources | # Definitions for our resources | ||||||
| ID_MAIN=512 | ID_MAIN=512 | ||||||
|  | @ -16,14 +17,9 @@ | ||||||
| ITEM_LOOKUP_BUTTON=3 | ITEM_LOOKUP_BUTTON=3 | ||||||
| ITEM_QUIT_BUTTON=4 | ITEM_QUIT_BUTTON=4 | ||||||
| 
 | 
 | ||||||
|              |  | ||||||
| def main(): | def main(): | ||||||
|     """Main routine: open resource file, call dialog handler""" |     """Main routine: open resource file, call dialog handler""" | ||||||
|     try: |     macresource.need("DLOG", ID_MAIN, "dnslookup-1.rsrc") | ||||||
|         Res.FSpOpenResFile("dnslookup-1.rsrc", 1) |  | ||||||
|     except Res.Error: |  | ||||||
|         EasyDialogs.Message("Cannot open dnslookup-1.rsrc") |  | ||||||
|         sys.exit(1)  |  | ||||||
|     do_dialog() |     do_dialog() | ||||||
| 
 | 
 | ||||||
| def do_dialog(): | def do_dialog(): | ||||||
|  |  | ||||||
|  | @ -5,6 +5,7 @@ | ||||||
| import sys | import sys | ||||||
| import socket | import socket | ||||||
| import string | import string | ||||||
|  | import macresource | ||||||
| # | # | ||||||
| # Definitions for our resources | # Definitions for our resources | ||||||
| ID_MAIN=512 | ID_MAIN=512 | ||||||
|  | @ -15,14 +16,7 @@ | ||||||
| ITEM_LOOKUP_BUTTON=3 | ITEM_LOOKUP_BUTTON=3 | ||||||
| 
 | 
 | ||||||
| def main(): | def main(): | ||||||
|     try: |     macresource.need("DLOG", ID_MAIN, "dnslookup-2.rsrc") | ||||||
|         dummy = Res.GetResource('DLOG', ID_MAIN) |  | ||||||
|     except Res.Error: |  | ||||||
|         try: |  | ||||||
|             Res.FSpOpenResFile("dnslookup-2.rsrc", 1) |  | ||||||
|         except Res.Error: |  | ||||||
|             EasyDialogs.Message("Cannot open dnslookup-2.rsrc") |  | ||||||
|             sys.exit(1)  |  | ||||||
|     DNSLookup() |     DNSLookup() | ||||||
|      |      | ||||||
| class DNSLookup(FrameWork.Application): | class DNSLookup(FrameWork.Application): | ||||||
|  |  | ||||||
|  | @ -13,25 +13,17 @@ def init(): | ||||||
| 	from Carbon import Qd, QuickDraw | 	from Carbon import Qd, QuickDraw | ||||||
| 	Qd.SetCursor(Qd.GetCursor(QuickDraw.watchCursor).data) | 	Qd.SetCursor(Qd.GetCursor(QuickDraw.watchCursor).data) | ||||||
| 	 | 	 | ||||||
| 	from Carbon import Res | 	import macresource | ||||||
| 	import sys, os | 	import sys, os | ||||||
| 	try: | 	macresource.need('DITL', 468, "PythonIDE.rsrc") | ||||||
| 		Res.GetResource('DITL', 468) | 	widgetresfile = os.path.join(sys.exec_prefix, ":Mac:Tools:IDE:Widgets.rsrc") | ||||||
| 	except Res.Error: | 	refno = macresource.need('CURS', 468, widgetresfile) | ||||||
| 		# we're not an applet | 	if refno: | ||||||
| 		Res.FSpOpenResFile(os.path.join(sys.exec_prefix, ":Mac:Tools:IDE:PythonIDE.rsrc"), 1) | 		# We're not a fullblown application | ||||||
| 		Res.FSpOpenResFile(os.path.join(sys.exec_prefix, ":Mac:Tools:IDE:Widgets.rsrc"), 1) |  | ||||||
| 		ide_path = os.path.join(sys.exec_prefix, ":Mac:Tools:IDE") | 		ide_path = os.path.join(sys.exec_prefix, ":Mac:Tools:IDE") | ||||||
| 	else: | 	else: | ||||||
| 		# we're an applet | 		# We are a fully frozen application | ||||||
| 		try: | 		ide_path = sys.argv[0] | ||||||
| 			Res.GetResource('CURS', 468) |  | ||||||
| 		except Res.Error: |  | ||||||
| 			Res.FSpOpenResFile(os.path.join(sys.exec_prefix, ":Mac:Tools:IDE:Widgets.rsrc"), 1) |  | ||||||
| 			ide_path = os.path.join(sys.exec_prefix, ":Mac:Tools:IDE") |  | ||||||
| 		else: |  | ||||||
| 			# we're a full blown applet |  | ||||||
| 			ide_path = sys.argv[0] |  | ||||||
| 	if ide_path not in sys.path: | 	if ide_path not in sys.path: | ||||||
| 		sys.path.insert(0, ide_path) | 		sys.path.insert(0, ide_path) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -6,6 +6,7 @@ | ||||||
| import os | import os | ||||||
| import string | import string | ||||||
| from Carbon import Res | from Carbon import Res | ||||||
|  | import macresource | ||||||
| 
 | 
 | ||||||
| ID_MAINDIALOG=512 | ID_MAINDIALOG=512 | ||||||
| 
 | 
 | ||||||
|  | @ -54,17 +55,8 @@ def dialog(script=None): | ||||||
| 	dirname = os.path.join(dirname, 'build.'+basebase) | 	dirname = os.path.join(dirname, 'build.'+basebase) | ||||||
| 	 | 	 | ||||||
| 	# Get the dialog, possibly opening the resource file (if needed) | 	# Get the dialog, possibly opening the resource file (if needed) | ||||||
| 	try: | 	macresource.need('DLOG', ID_MAINDIALOG, 'macfreeze.rsrc') | ||||||
| 		d = Dlg.GetNewDialog(ID_MAINDIALOG, -1) | 	d = Dlg.GetNewDialog(ID_MAINDIALOG, -1) | ||||||
| 	except Dlg.Error: |  | ||||||
| 		d = None |  | ||||||
| 	if d == None: |  | ||||||
| 		try: |  | ||||||
| 			Res.FSpOpenResFile('macfreeze.rsrc', 1) |  | ||||||
| 		except Res.Error: |  | ||||||
| 			d = None |  | ||||||
| 		else: |  | ||||||
| 			d = Dlg.GetNewDialog(ID_MAINDIALOG, -1) |  | ||||||
| 	if d == None: | 	if d == None: | ||||||
| 		EasyDialogs.Message("Dialog resource not found or faulty") | 		EasyDialogs.Message("Dialog resource not found or faulty") | ||||||
| 		sys.exit(1) | 		sys.exit(1) | ||||||
|  |  | ||||||
|  | @ -18,6 +18,7 @@ | ||||||
| from Carbon import Dlg | from Carbon import Dlg | ||||||
| import EasyDialogs | import EasyDialogs | ||||||
| import buildtools | import buildtools | ||||||
|  | import macresource | ||||||
| 
 | 
 | ||||||
| # Hmmm... | # Hmmm... | ||||||
| MACFREEZEPATH = os.path.join(sys.prefix, ":Mac:Tools:macfreeze") | MACFREEZEPATH = os.path.join(sys.prefix, ":Mac:Tools:macfreeze") | ||||||
|  | @ -38,13 +39,7 @@ | ||||||
| PPC_ONLY=1 | PPC_ONLY=1 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| try: | macresource.need('DITL', DLG_ID, "BuildApplication.rsrc") | ||||||
| 	Res.GetResource('DITL', DLG_ID) |  | ||||||
| except Res.Error: |  | ||||||
| 	Res.FSpOpenResFile("BuildApplication.rsrc", 1) |  | ||||||
| else: |  | ||||||
| 	pass # we're an applet |  | ||||||
| 
 |  | ||||||
| 
 | 
 | ||||||
| def main(): | def main(): | ||||||
| 	try: | 	try: | ||||||
|  |  | ||||||
|  | @ -15,6 +15,7 @@ | ||||||
| import sys | import sys | ||||||
| from Carbon import Res # For Res.Error | from Carbon import Res # For Res.Error | ||||||
| import pythonprefs | import pythonprefs | ||||||
|  | import macresource | ||||||
| import EasyDialogs | import EasyDialogs | ||||||
| try: | try: | ||||||
| 	from Carbon import Help | 	from Carbon import Help | ||||||
|  | @ -195,10 +196,7 @@ def edit_applet(name): | ||||||
| 		handler.save(result) | 		handler.save(result) | ||||||
| 
 | 
 | ||||||
| def main(): | def main(): | ||||||
| 	try: | 	macresource.need('DLOG', DIALOG_ID, 'EditPythonPrefs.rsrc') | ||||||
| 		h = FSpOpenResFile('EditPythonPrefs.rsrc', 1) |  | ||||||
| 	except Res.Error: |  | ||||||
| 		pass	# Assume we already have acces to our own resource |  | ||||||
| 	 | 	 | ||||||
| 	MacOS.SchedParams(1, 0) | 	MacOS.SchedParams(1, 0) | ||||||
| 	if len(sys.argv) <= 1: | 	if len(sys.argv) <= 1: | ||||||
|  |  | ||||||
|  | @ -23,6 +23,7 @@ | ||||||
| import macfs | import macfs | ||||||
| import os | import os | ||||||
| import sys | import sys | ||||||
|  | import macresource | ||||||
| 
 | 
 | ||||||
| # Resource IDs | # Resource IDs | ||||||
| ID_MAIN = 514 | ID_MAIN = 514 | ||||||
|  | @ -321,7 +322,7 @@ def GetType(): | ||||||
| 			 | 			 | ||||||
| def InitUI(): | def InitUI(): | ||||||
| 	"""Initialize stuff needed by UI (a resource file)""" | 	"""Initialize stuff needed by UI (a resource file)""" | ||||||
| 	Res.FSpOpenResFile('MkDistr.rsrc', 1) | 	macresource.need('DLOG', ID_MAIN, 'MkDistr.rsrc', modname=__name__) | ||||||
| 
 | 
 | ||||||
| class _testerhelp: | class _testerhelp: | ||||||
| 	def __init__(self, which): | 	def __init__(self, which): | ||||||
|  | @ -340,7 +341,7 @@ def delete(self, value): | ||||||
| class _test: | class _test: | ||||||
| 	def __init__(self): | 	def __init__(self): | ||||||
| 		import sys | 		import sys | ||||||
| 		Res.FSpOpenResFile('MkDistr.rsrc', 1) | 		InitUI() | ||||||
| 		self.inc = _testerhelp('include') | 		self.inc = _testerhelp('include') | ||||||
| 		self.exc = _testerhelp('exclude') | 		self.exc = _testerhelp('exclude') | ||||||
| 		self.ui = MkDistrUI(self) | 		self.ui = MkDistrUI(self) | ||||||
|  |  | ||||||
|  | @ -19,6 +19,7 @@ | ||||||
| import re | import re | ||||||
| import string | import string | ||||||
| import genpluginprojects | import genpluginprojects | ||||||
|  | import macresource | ||||||
| 
 | 
 | ||||||
| import aetools | import aetools | ||||||
| from Carbon import AppleEvents | from Carbon import AppleEvents | ||||||
|  | @ -369,11 +370,7 @@ def incbuildno(filename): | ||||||
| 	fp.close() | 	fp.close() | ||||||
| 				 | 				 | ||||||
| def main(): | def main(): | ||||||
| 	try: | 	macresource.need('DLOG', DIALOG_ID, 'fullbuild.rsrc') | ||||||
| 		h = Res.FSpOpenResFile('fullbuild.rsrc', 1) |  | ||||||
| 	except Res.Error: |  | ||||||
| 		pass	# Assume we already have acces to our own resource |  | ||||||
| 
 |  | ||||||
| 	dir, ok = macfs.GetDirectory('Python source folder:') | 	dir, ok = macfs.GetDirectory('Python source folder:') | ||||||
| 	if not ok: | 	if not ok: | ||||||
| 		sys.exit(0) | 		sys.exit(0) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Jack Jansen
						Jack Jansen