Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3ec804a

Browse files
committed
- Added PyMac_GetDirectory call which asks the user to select a
directory. - No __main__ resource found message is now a dialog - Fixes wrt stdio window handling in applets. NB: these fixes require a new resource file.
1 parent 77b5828 commit 3ec804a

2 files changed

Lines changed: 81 additions & 20 deletions

File tree

Mac/Include/macglue.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ char *PyMac_GetPythonDir(); /* Return the name of the python dir */
5959
int PyMac_FindResourceModule(char *, char *); /* Test for 'PYC ' resource in a file */
6060
PyObject * PyMac_LoadResourceModule(char *, char *); /* Load 'PYC ' resource from file */
6161

62+
int PyMac_GetDirectory(FSSpec *dirfss); /* Ask user for a directory */
63+
6264
int PyMac_GetOSType(PyObject *, OSType *); /* argument parser for OSType */
6365
PyObject *PyMac_BuildOSType(OSType); /* Convert OSType to PyObject */
6466

Mac/Python/macglue.c

Lines changed: 79 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,19 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
5353
#include <signal.h>
5454
#include <stdio.h>
5555

56+
/* The alert for "No Python directory, where is it?" */
5657
#define NOPYTHON_ALERT 128
5758
#define YES_ITEM 1
5859
#define NO_ITEM 2
5960
#define CURWD_ITEM 3
6061

62+
/* The alert for "this is an applet template" */
63+
#define NOPYC_ALERT 129
64+
65+
/* The dialog for our GetDirectory call */
66+
#define GETDIR_ID 130 /* Resource ID for our "get directory" */
67+
#define SELECTCUR_ITEM 10 /* "Select current directory" button */
68+
6169
#ifdef __MWERKS__
6270
/*
6371
** With MW we can pass the event off to the console window, so
@@ -390,7 +398,6 @@ PyMac_GetPythonDir()
390398
FSSpec dirspec;
391399
int ok = 0, exists = 0;
392400
Boolean modified = 0, cannotmodify = 0;
393-
StandardFileReply sfreply;
394401
short oldrh, prefrh;
395402
short prefdirRefNum;
396403
long prefdirDirID;
@@ -433,21 +440,9 @@ PyMac_GetPythonDir()
433440
item = Alert(NOPYTHON_ALERT, NULL);
434441
if ( item == YES_ITEM ) {
435442
/* The user wants to point us to a directory. Let her do so */
436-
StandardGetFile(NULL, 0, NULL, &sfreply);
437-
if ( sfreply.sfGood ) {
438-
if ( sfreply.sfIsFolder ) {
439-
dirspec = sfreply.sfFile;
440-
ok = 1;
441-
modified = 1;
442-
} else {
443-
/* User selected a file. Use folder containing it */
444-
if (FSMakeFSSpec(sfreply.sfFile.vRefNum,
445-
sfreply.sfFile.parID, "\p", &dirspec) == 0) {
446-
ok = 1;
447-
modified = 1;
448-
}
449-
}
450-
}
443+
ok = PyMac_GetDirectory(&dirspec);
444+
if ( ok )
445+
modified = 1;
451446
} else if ( item == CURWD_ITEM ) {
452447
/* The user told us the current directory is fine. Build an FSSpec for it */
453448
if ( getwd(name) ) {
@@ -593,6 +588,49 @@ char *filename;
593588
return NULL;
594589
}
595590
}
591+
/*
592+
** Helper routine for GetDirectory
593+
*/
594+
static int
595+
myhook_proc(item, theDialog, dataptr)
596+
short item;
597+
DialogPtr theDialog;
598+
void *dataptr;
599+
{
600+
if ( item == SELECTCUR_ITEM ) {
601+
item = sfItemCancelButton;
602+
* (int *)dataptr = 1;
603+
}
604+
return item;
605+
}
606+
607+
/*
608+
** Ask the user for a directory. I still can't understand
609+
** why Apple doesn't provide a standard solution for this...
610+
*/
611+
int
612+
PyMac_GetDirectory(dirfss)
613+
FSSpec *dirfss;
614+
{
615+
static SFTypeList list = {'fldr', 0, 0, 0};
616+
static Point where = {-1, -1};
617+
static DlgHookYDUPP myhook_upp;
618+
static int upp_inited = 0;
619+
StandardFileReply reply;
620+
int select_clicked = 0;
621+
622+
if ( !upp_inited ) {
623+
myhook_upp = NewDlgHookYDProc(myhook_proc);
624+
upp_inited = 1;
625+
}
626+
CustomGetFile((FileFilterUPP)0, 1, list, &reply, GETDIR_ID, where, myhook_upp,
627+
NULL, NULL, NULL, (void *)&select_clicked);
628+
629+
reply.sfFile.name[0] = 0;
630+
if( FSMakeFSSpec(reply.sfFile.vRefNum, reply.sfFile.parID, reply.sfFile.name, dirfss) )
631+
return 0;
632+
return select_clicked;
633+
}
596634

597635
/* Convert a 4-char string object argument to an OSType value */
598636
int
@@ -659,7 +697,7 @@ PyMac_GetFSSpec(PyObject *v, FSSpec *fs)
659697
/* first check whether it already is an FSSpec */
660698
fs2 = mfs_GetFSSpecFSSpec(v);
661699
if ( fs2 ) {
662-
fs = fs2;
700+
(void)FSMakeFSSpec(fs2->vRefNum, fs2->parID, fs2->name, fs);
663701
return 1;
664702
}
665703
if ( PyString_Check(v) ) {
@@ -762,7 +800,7 @@ run_main_resource()
762800

763801
h = GetNamedResource('PYC ', "\p__main__");
764802
if (h == NULL) {
765-
fprintf(stderr, "No 'PYC ' resource named __main__ found\n");
803+
Alert(NOPYC_ALERT, NULL);
766804
return 1;
767805
}
768806
size = GetResourceSizeOnDisk(h);
@@ -790,12 +828,33 @@ PyMac_InitApplet()
790828
{
791829
int argc;
792830
char **argv;
793-
831+
832+
#ifdef __MWERKS__
833+
/*
834+
** Guido: you should fix this. You should arrange to have the
835+
** __sinit routine from macshlglue.c called so you can stuff
836+
** resources into the lib file.
837+
*/
838+
PyMac_AddLibResources();
839+
#else
840+
KABOO! KABOO!
841+
#endif
842+
#ifdef __MWERKS__
843+
SIOUXSettings.asktosaveonclose = 0;
844+
SIOUXSettings.showstatusline = 0;
845+
SIOUXSettings.tabspaces = 4;
846+
#endif
794847
argc = PyMac_GetArgv(&argv);
795848
Py_Initialize();
796849
PySys_SetArgv(argc, argv);
797-
run_main_resource();
850+
err = run_main_resource();
798851
fflush(stderr);
799852
fflush(stdout);
853+
#ifdef __MWERKS__
854+
if (!err)
855+
SIOUXSettings.autocloseonquit = 1;
856+
else
857+
SIOUXSettings.showstatusline = 1;
858+
#endif
800859
/* XXX Should we bother to Py_Exit(sts)? */
801860
}

0 commit comments

Comments
 (0)