Changeset 391 for python/trunk/Mac/Modules/ibcarbon
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Mac/Modules/ibcarbon/_IBCarbon.c
r2 r391 24 24 25 25 typedef struct IBNibRefObject { 26 27 26 PyObject_HEAD 27 IBNibRef ob_itself; 28 28 } IBNibRefObject; 29 29 30 30 PyObject *IBNibRefObj_New(IBNibRef itself) 31 31 { 32 33 34 35 36 32 IBNibRefObject *it; 33 it = PyObject_NEW(IBNibRefObject, &IBNibRef_Type); 34 if (it == NULL) return NULL; 35 it->ob_itself = itself; 36 return (PyObject *)it; 37 37 } 38 38 39 39 int IBNibRefObj_Convert(PyObject *v, IBNibRef *p_itself) 40 40 { 41 42 43 44 45 46 47 41 if (!IBNibRefObj_Check(v)) 42 { 43 PyErr_SetString(PyExc_TypeError, "IBNibRef required"); 44 return 0; 45 } 46 *p_itself = ((IBNibRefObject *)v)->ob_itself; 47 return 1; 48 48 } 49 49 50 50 static void IBNibRefObj_dealloc(IBNibRefObject *self) 51 51 { 52 53 52 DisposeNibReference(self->ob_itself); 53 self->ob_type->tp_free((PyObject *)self); 54 54 } 55 55 56 56 static PyObject *IBNibRefObj_CreateWindowFromNib(IBNibRefObject *_self, PyObject *_args) 57 57 { 58 59 60 61 62 63 64 65 66 67 68 69 70 71 58 PyObject *_res = NULL; 59 OSStatus _err; 60 CFStringRef inName; 61 WindowPtr outWindow; 62 if (!PyArg_ParseTuple(_args, "O&", 63 CFStringRefObj_Convert, &inName)) 64 return NULL; 65 _err = CreateWindowFromNib(_self->ob_itself, 66 inName, 67 &outWindow); 68 if (_err != noErr) return PyMac_Error(_err); 69 _res = Py_BuildValue("O&", 70 WinObj_New, outWindow); 71 return _res; 72 72 } 73 73 74 74 static PyObject *IBNibRefObj_CreateMenuFromNib(IBNibRefObject *_self, PyObject *_args) 75 75 { 76 77 78 79 80 81 82 83 84 85 86 87 88 89 76 PyObject *_res = NULL; 77 OSStatus _err; 78 CFStringRef inName; 79 MenuHandle outMenuRef; 80 if (!PyArg_ParseTuple(_args, "O&", 81 CFStringRefObj_Convert, &inName)) 82 return NULL; 83 _err = CreateMenuFromNib(_self->ob_itself, 84 inName, 85 &outMenuRef); 86 if (_err != noErr) return PyMac_Error(_err); 87 _res = Py_BuildValue("O&", 88 MenuObj_New, outMenuRef); 89 return _res; 90 90 } 91 91 92 92 static PyObject *IBNibRefObj_CreateMenuBarFromNib(IBNibRefObject *_self, PyObject *_args) 93 93 { 94 95 96 97 98 99 100 101 102 103 104 105 106 107 94 PyObject *_res = NULL; 95 OSStatus _err; 96 CFStringRef inName; 97 Handle outMenuBar; 98 if (!PyArg_ParseTuple(_args, "O&", 99 CFStringRefObj_Convert, &inName)) 100 return NULL; 101 _err = CreateMenuBarFromNib(_self->ob_itself, 102 inName, 103 &outMenuBar); 104 if (_err != noErr) return PyMac_Error(_err); 105 _res = Py_BuildValue("O&", 106 ResObj_New, outMenuBar); 107 return _res; 108 108 } 109 109 110 110 static PyObject *IBNibRefObj_SetMenuBarFromNib(IBNibRefObject *_self, PyObject *_args) 111 111 { 112 113 114 115 116 117 118 119 120 121 122 123 112 PyObject *_res = NULL; 113 OSStatus _err; 114 CFStringRef inName; 115 if (!PyArg_ParseTuple(_args, "O&", 116 CFStringRefObj_Convert, &inName)) 117 return NULL; 118 _err = SetMenuBarFromNib(_self->ob_itself, 119 inName); 120 if (_err != noErr) return PyMac_Error(_err); 121 Py_INCREF(Py_None); 122 _res = Py_None; 123 return _res; 124 124 } 125 125 126 126 static PyMethodDef IBNibRefObj_methods[] = { 127 128 129 130 131 132 133 134 135 127 {"CreateWindowFromNib", (PyCFunction)IBNibRefObj_CreateWindowFromNib, 1, 128 PyDoc_STR("(CFStringRef inName) -> (WindowPtr outWindow)")}, 129 {"CreateMenuFromNib", (PyCFunction)IBNibRefObj_CreateMenuFromNib, 1, 130 PyDoc_STR("(CFStringRef inName) -> (MenuHandle outMenuRef)")}, 131 {"CreateMenuBarFromNib", (PyCFunction)IBNibRefObj_CreateMenuBarFromNib, 1, 132 PyDoc_STR("(CFStringRef inName) -> (Handle outMenuBar)")}, 133 {"SetMenuBarFromNib", (PyCFunction)IBNibRefObj_SetMenuBarFromNib, 1, 134 PyDoc_STR("(CFStringRef inName) -> None")}, 135 {NULL, NULL, 0} 136 136 }; 137 137 … … 150 150 static PyObject *IBNibRefObj_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds) 151 151 { 152 153 154 155 156 157 158 159 152 PyObject *_self; 153 IBNibRef itself; 154 char *kw[] = {"itself", 0}; 155 156 if (!PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, IBNibRefObj_Convert, &itself)) return NULL; 157 if ((_self = type->tp_alloc(type, 0)) == NULL) return NULL; 158 ((IBNibRefObject *)_self)->ob_itself = itself; 159 return _self; 160 160 } 161 161 … … 164 164 165 165 PyTypeObject IBNibRef_Type = { 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 166 PyObject_HEAD_INIT(NULL) 167 0, /*ob_size*/ 168 "_IBCarbon.IBNibRef", /*tp_name*/ 169 sizeof(IBNibRefObject), /*tp_basicsize*/ 170 0, /*tp_itemsize*/ 171 /* methods */ 172 (destructor) IBNibRefObj_dealloc, /*tp_dealloc*/ 173 0, /*tp_print*/ 174 (getattrfunc)0, /*tp_getattr*/ 175 (setattrfunc)0, /*tp_setattr*/ 176 (cmpfunc) IBNibRefObj_compare, /*tp_compare*/ 177 (reprfunc) IBNibRefObj_repr, /*tp_repr*/ 178 (PyNumberMethods *)0, /* tp_as_number */ 179 (PySequenceMethods *)0, /* tp_as_sequence */ 180 (PyMappingMethods *)0, /* tp_as_mapping */ 181 (hashfunc) IBNibRefObj_hash, /*tp_hash*/ 182 0, /*tp_call*/ 183 0, /*tp_str*/ 184 PyObject_GenericGetAttr, /*tp_getattro*/ 185 PyObject_GenericSetAttr, /*tp_setattro */ 186 0, /*tp_as_buffer*/ 187 Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */ 188 0, /*tp_doc*/ 189 0, /*tp_traverse*/ 190 0, /*tp_clear*/ 191 0, /*tp_richcompare*/ 192 0, /*tp_weaklistoffset*/ 193 0, /*tp_iter*/ 194 0, /*tp_iternext*/ 195 IBNibRefObj_methods, /* tp_methods */ 196 0, /*tp_members*/ 197 IBNibRefObj_getsetlist, /*tp_getset*/ 198 0, /*tp_base*/ 199 0, /*tp_dict*/ 200 0, /*tp_descr_get*/ 201 0, /*tp_descr_set*/ 202 0, /*tp_dictoffset*/ 203 IBNibRefObj_tp_init, /* tp_init */ 204 IBNibRefObj_tp_alloc, /* tp_alloc */ 205 IBNibRefObj_tp_new, /* tp_new */ 206 IBNibRefObj_tp_free, /* tp_free */ 207 207 }; 208 208 … … 212 212 static PyObject *IBCarbon_CreateNibReference(PyObject *_self, PyObject *_args) 213 213 { 214 215 216 217 218 219 220 221 222 223 224 225 226 214 PyObject *_res = NULL; 215 OSStatus _err; 216 CFStringRef inNibName; 217 IBNibRef outNibRef; 218 if (!PyArg_ParseTuple(_args, "O&", 219 CFStringRefObj_Convert, &inNibName)) 220 return NULL; 221 _err = CreateNibReference(inNibName, 222 &outNibRef); 223 if (_err != noErr) return PyMac_Error(_err); 224 _res = Py_BuildValue("O&", 225 IBNibRefObj_New, outNibRef); 226 return _res; 227 227 } 228 228 #endif /* __LP64__ */ … … 230 230 static PyMethodDef IBCarbon_methods[] = { 231 231 #ifndef __LP64__ 232 233 234 #endif /* __LP64__ */ 235 232 {"CreateNibReference", (PyCFunction)IBCarbon_CreateNibReference, 1, 233 PyDoc_STR("(CFStringRef inNibName) -> (IBNibRef outNibRef)")}, 234 #endif /* __LP64__ */ 235 {NULL, NULL, 0} 236 236 }; 237 237 … … 241 241 void init_IBCarbon(void) 242 242 { 243 244 #ifndef __LP64__ 245 246 #endif /* __LP64__ */ 247 248 249 250 251 252 253 #ifndef __LP64__ 254 255 256 257 258 259 260 261 262 263 264 265 243 PyObject *m; 244 #ifndef __LP64__ 245 PyObject *d; 246 #endif /* __LP64__ */ 247 248 249 250 251 252 m = Py_InitModule("_IBCarbon", IBCarbon_methods); 253 #ifndef __LP64__ 254 d = PyModule_GetDict(m); 255 IBCarbon_Error = PyMac_GetOSErrException(); 256 if (IBCarbon_Error == NULL || 257 PyDict_SetItemString(d, "Error", IBCarbon_Error) != 0) 258 return; 259 IBNibRef_Type.ob_type = &PyType_Type; 260 if (PyType_Ready(&IBNibRef_Type) < 0) return; 261 Py_INCREF(&IBNibRef_Type); 262 PyModule_AddObject(m, "IBNibRef", (PyObject *)&IBNibRef_Type); 263 /* Backward-compatible name */ 264 Py_INCREF(&IBNibRef_Type); 265 PyModule_AddObject(m, "IBNibRefType", (PyObject *)&IBNibRef_Type); 266 266 #endif /* __LP64__ */ 267 267 }
Note:
See TracChangeset
for help on using the changeset viewer.