SIP4 python bindings for TQt
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2320 lines
60KB

  1. // This is the SIP interface definition for TQObject.
  2. //
  3. // Copyright (c) 2007
  4. // Riverbank Computing Limited <info@riverbankcomputing.co.uk>
  5. //
  6. // This file is part of PyTQt.
  7. //
  8. // This copy of PyTQt is free software; you can redistribute it and/or modify it
  9. // under the terms of the GNU General Public License as published by the Free
  10. // Software Foundation; either version 2, or (at your option) any later
  11. // version.
  12. //
  13. // PyTQt is supplied in the hope that it will be useful, but WITHOUT ANY
  14. // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  15. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  16. // details.
  17. //
  18. // You should have received a copy of the GNU General Public License along with
  19. // PyTQt; see the file LICENSE. If not, write to the Free Software Foundation,
  20. // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. %ExportedDoc
  22. <Sect2><Title>TQObject</Title>
  23. <FuncSynopsis>
  24. <FuncDef>bool <Function>disconnect</Function></FuncDef>
  25. <ParamDef>const TQObject *<Parameter>receiver</Parameter></ParamDef>
  26. <ParamDef>const char *<Parameter>member</Parameter> = 0</ParamDef>
  27. </FuncSynopsis>
  28. <Para>
  29. Not yet implemented.
  30. </Para>
  31. <FuncSynopsis>
  32. <FuncDef>bool <Function>disconnect</Function></FuncDef>
  33. <ParamDef>const char *<Parameter>signal</Parameter> = 0</ParamDef>
  34. <ParamDef>const TQObject *<Parameter>receiver</Parameter> = 0</ParamDef>
  35. <ParamDef>const char *<Parameter>member</Parameter> = 0</ParamDef>
  36. </FuncSynopsis>
  37. <Para>
  38. Not yet implemented.
  39. </Para>
  40. <FuncSynopsis>
  41. <FuncDef>static bool <Function>disconnect</Function></FuncDef>
  42. <ParamDef>const TQObject *<Parameter>sender</Parameter></ParamDef>
  43. <ParamDef>const char *<Parameter>signal</Parameter></ParamDef>
  44. <ParamDef>const TQObject *<Parameter>receiver</Parameter></ParamDef>
  45. <ParamDef>const char *<Parameter>member</Parameter></ParamDef>
  46. </FuncSynopsis>
  47. <Para>
  48. At the moment PyTQt does not support the full behaviour of the corresponding TQt
  49. method. In particular, specifying None (ie. 0 in C++) for the
  50. <Literal>signal</Literal> and <Literal>receiver</Literal> parameters is not yet
  51. supported.
  52. </Para>
  53. </Sect2>
  54. %End
  55. %If (TQt_2_00 -)
  56. class TQObject : TQt
  57. {
  58. %TypeHeaderCode
  59. #include <qobject.h>
  60. #include <qapplication.h>
  61. %End
  62. public:
  63. TQObject(TQObject * /TransferThis/ = 0,const char * = 0);
  64. %ConvertToSubClassCode
  65. static struct class_graph {
  66. const char *name;
  67. sipWrapperType **type;
  68. int yes, no;
  69. } graph[] = {
  70. {sipName_TQWidget, &sipClass_TQWidget, 25, 1},
  71. #if QT_VERSION >= 0x030100 && defined(SIP_FEATURE_TQt_ASSISTANTCLIENT)
  72. {sipName_TQAssistantClient, &sipClass_TQAssistantClient, -1, 2},
  73. #else
  74. {NULL, NULL, -1, 2},
  75. #endif
  76. {sipName_TQSessionManager, &sipClass_TQSessionManager, -1, 3},
  77. {sipName_TQTranslator, &sipClass_TQTranslator, -1, 4},
  78. #if QT_VERSION >= 0x030000
  79. {sipName_TQProcess, &sipClass_TQProcess, -1, 5},
  80. #else
  81. {NULL, NULL, -1, 5},
  82. #endif
  83. {sipName_TQToolTipGroup, &sipClass_TQToolTipGroup, -1, 6},
  84. #if defined(SIP_FEATURE_TQt_FILEDIALOG)
  85. {sipName_TQFileIconProvider, &sipClass_TQFileIconProvider, -1, 7},
  86. #else
  87. {NULL, NULL, -1, 7},
  88. #endif
  89. #if QT_VERSION >= 220 && defined(SIP_FEATURE_TQt_ACTION)
  90. {sipName_TQAction, &sipClass_TQAction, 89, 8},
  91. #else
  92. {NULL, NULL, -1, 8},
  93. #endif
  94. #if QT_VERSION >= 0x030000
  95. {sipName_TQObjectCleanupHandler, &sipClass_TQObjectCleanupHandler, -1, 9},
  96. #else
  97. {NULL, NULL, -1, 9},
  98. #endif
  99. {sipName_TQTimer, &sipClass_TQTimer, -1, 10},
  100. {sipName_TQLayout, &sipClass_TQLayout, 90, 11},
  101. #if QT_VERSION >= 210 && defined(SIP_FEATURE_TQt_NETWORKPROTOCOL)
  102. {sipName_TQUrlOperator, &sipClass_TQUrlOperator, -1, 12},
  103. #else
  104. {NULL, NULL, -1, 12},
  105. #endif
  106. {sipName_TQStyleSheet, &sipClass_TQStyleSheet, -1, 13},
  107. {sipName_TQValidator, &sipClass_TQValidator, 94, 14},
  108. #if QT_VERSION >= 210 && defined(SIP_FEATURE_TQt_NETWORKPROTOCOL)
  109. {sipName_TQNetworkOperation, &sipClass_TQNetworkOperation, -1, 15},
  110. #else
  111. {NULL, NULL, -1, 15},
  112. #endif
  113. {sipName_TQAccel, &sipClass_TQAccel, -1, 16},
  114. #if QT_VERSION >= 0x030100
  115. {sipName_TQEventLoop, &sipClass_TQEventLoop, -1, 17},
  116. #else
  117. {NULL, NULL, -1, 17},
  118. #endif
  119. #if QT_VERSION >= 210 && defined(SIP_FEATURE_TQt_NETWORKPROTOCOL)
  120. {sipName_TQNetworkProtocol, &sipClass_TQNetworkProtocol, -1, 18},
  121. #else
  122. {NULL, NULL, -1, 18},
  123. #endif
  124. #if QT_VERSION >= 220 && defined(SIP_FEATURE_TQt_SOUND)
  125. {sipName_TQSound, &sipClass_TQSound, -1, 19},
  126. #else
  127. {NULL, NULL, -1, 19},
  128. #endif
  129. {sipName_TQApplication, &sipClass_TQApplication, -1, 20},
  130. {sipName_TQDragObject, &sipClass_TQDragObject, 97, 21},
  131. {sipName_TQSocketNotifier, &sipClass_TQSocketNotifier, -1, 22},
  132. {sipName_TQStyle, &sipClass_TQStyle, 103, 23},
  133. {sipName_TQSignalMapper, &sipClass_TQSignalMapper, -1, 24},
  134. #if defined(SIP_FEATURE_TQt_CLIPBOARD)
  135. {sipName_TQClipboard, &sipClass_TQClipboard, -1, -1},
  136. #else
  137. {NULL, NULL, -1, -1},
  138. #endif
  139. {sipName_TQStatusBar, &sipClass_TQStatusBar, -1, 26},
  140. #if defined(SIP_FEATURE_TQt_SIZEGRIP)
  141. {sipName_TQSizeGrip, &sipClass_TQSizeGrip, -1, 27},
  142. #else
  143. {NULL, NULL, -1, 27},
  144. #endif
  145. {sipName_TQTabWidget, &sipClass_TQTabWidget, -1, 28},
  146. #if QT_VERSION >= 0x030000
  147. {sipName_TQDateEdit, &sipClass_TQDateEdit, -1, 29},
  148. #else
  149. {NULL, NULL, -1, 29},
  150. #endif
  151. {sipName_TQMainWindow, &sipClass_TQMainWindow, -1, 30},
  152. #if QT_VERSION >= 0x030000
  153. {sipName_TQDateTimeEdit, &sipClass_TQDateTimeEdit, -1, 31},
  154. #else
  155. {NULL, NULL, -1, 31},
  156. #endif
  157. #if QT_VERSION >= 0x030000
  158. {sipName_TQTimeEdit, &sipClass_TQTimeEdit, -1, 32},
  159. #else
  160. {NULL, NULL, -1, 32},
  161. #endif
  162. {sipName_TQFrame, &sipClass_TQFrame, 46, 33},
  163. {sipName_TQScrollBar, &sipClass_TQScrollBar, -1, 34},
  164. #if QT_VERSION >= 220 && defined(SIP_FEATURE_TQt_DIAL)
  165. {sipName_TQDial, &sipClass_TQDial, -1, 35},
  166. #else
  167. {NULL, NULL, -1, 35},
  168. #endif
  169. {sipName_TQButton, &sipClass_TQButton, 75, 36},
  170. {sipName_TQTabBar, &sipClass_TQTabBar, -1, 37},
  171. {sipName_TQDialog, &sipClass_TQDialog, 79, 38},
  172. {sipName_TQComboBox, &sipClass_TQComboBox, -1, 39},
  173. {sipName_TQHeader, &sipClass_TQHeader, -1, 40},
  174. #if QT_VERSION >= 0x030000
  175. {sipName_TQDockArea, &sipClass_TQDockArea, -1, 41},
  176. #else
  177. {NULL, NULL, -1, 41},
  178. #endif
  179. #if QT_VERSION >= 0x030200
  180. {sipName_TQSplashScreen, &sipClass_TQSplashScreen, -1, 42},
  181. #else
  182. {NULL, NULL, -1, 42},
  183. #endif
  184. {sipName_TQSlider, &sipClass_TQSlider, -1, 43},
  185. {sipName_TQSpinBox, &sipClass_TQSpinBox, -1, 44},
  186. #if QT_VERSION >= 210 && defined(SIP_FEATURE_TQt_WORKSPACE)
  187. {sipName_TQWorkspace, &sipClass_TQWorkspace, -1, 45},
  188. #else
  189. {NULL, NULL, -1, 45},
  190. #endif
  191. #if QT_VERSION >= 0x030000
  192. {sipName_TQDesktopWidget, &sipClass_TQDesktopWidget, -1, -1},
  193. #else
  194. {NULL, NULL, -1, -1},
  195. #endif
  196. {sipName_TQGrid, &sipClass_TQGrid, -1, 47},
  197. {sipName_TQLineEdit, &sipClass_TQLineEdit, -1, 48},
  198. #if QT_VERSION >= 0x030200
  199. {sipName_TQToolBox, &sipClass_TQToolBox, -1, 49},
  200. #else
  201. {NULL, NULL, -1, 49},
  202. #endif
  203. {sipName_TQWidgetStack, &sipClass_TQWidgetStack, -1, 50},
  204. #if QT_VERSION >= 0x030000
  205. {sipName_TQDockWindow, &sipClass_TQDockWindow, 60, 51},
  206. #else
  207. {NULL, NULL, -1, 51},
  208. #endif
  209. {sipName_TQMenuBar, &sipClass_TQMenuBar, -1, 52},
  210. {sipName_TQLabel, &sipClass_TQLabel, -1, 53},
  211. {sipName_TQGroupBox, &sipClass_TQGroupBox, 61, 54},
  212. {sipName_TQPopupMenu, &sipClass_TQPopupMenu, -1, 55},
  213. #if defined(SIP_FEATURE_TQt_SPLITTER)
  214. {sipName_TQSplitter, &sipClass_TQSplitter, -1, 56},
  215. #else
  216. {NULL, NULL, -1, 56},
  217. #endif
  218. {sipName_TQProgressBar, &sipClass_TQProgressBar, -1, 57},
  219. {sipName_TQScrollView, &sipClass_TQScrollView, 66, 58},
  220. {sipName_TQHBox, &sipClass_TQHBox, 74, 59},
  221. {sipName_TQLCDNumber, &sipClass_TQLCDNumber, -1, -1},
  222. {sipName_TQToolBar, &sipClass_TQToolBar, -1, -1},
  223. {sipName_TQButtonGroup, &sipClass_TQButtonGroup, 64, 62},
  224. {sipName_TQHGroupBox, &sipClass_TQHGroupBox, -1, 63},
  225. {sipName_TQVGroupBox, &sipClass_TQVGroupBox, -1, -1},
  226. {sipName_TQVButtonGroup, &sipClass_TQVButtonGroup, -1, 65},
  227. {sipName_TQHButtonGroup, &sipClass_TQHButtonGroup, -1, -1},
  228. #if QT_VERSION >= 210 && defined(SIP_FEATURE_TQt_ICONVIEW)
  229. {sipName_TQIconView, &sipClass_TQIconView, -1, 67},
  230. #else
  231. {NULL, NULL, -1, 67},
  232. #endif
  233. {sipName_TQListView, &sipClass_TQListView, -1, 68},
  234. {sipName_TQListBox, &sipClass_TQListBox, -1, 69},
  235. #if QT_VERSION >= 0x030000
  236. {sipName_TQGridView, &sipClass_TQGridView, -1, 70},
  237. #else
  238. {NULL, NULL, -1, 70},
  239. #endif
  240. #if QT_VERSION >= 0x030000
  241. {sipName_TQTextEdit, &sipClass_TQTextEdit, 71, -1},
  242. #else
  243. {NULL, NULL, -1, -1},
  244. #endif
  245. {sipName_TQTextBrowser, &sipClass_TQTextBrowser, -1, 72},
  246. {sipName_TQMultiLineEdit, &sipClass_TQMultiLineEdit, -1, 73},
  247. {sipName_TQTextView, &sipClass_TQTextView, -1, -1},
  248. {sipName_TQVBox, &sipClass_TQVBox, -1, -1},
  249. {sipName_TQToolButton, &sipClass_TQToolButton, -1, 76},
  250. {sipName_TQRadioButton, &sipClass_TQRadioButton, -1, 77},
  251. {sipName_TQPushButton, &sipClass_TQPushButton, -1, 78},
  252. {sipName_TQCheckBox, &sipClass_TQCheckBox, -1, -1},
  253. #if defined(WS_X11) && defined(SIP_FEATURE_TQt_PRINTDIALOG)
  254. {sipName_TQPrintDialog, &sipClass_TQPrintDialog, -1, 80},
  255. #else
  256. {NULL, NULL, -1, 80},
  257. #endif
  258. #if QT_VERSION >= 0x030000
  259. {sipName_TQErrorMessage, &sipClass_TQErrorMessage, -1, 81},
  260. #else
  261. {NULL, NULL, -1, 81},
  262. #endif
  263. #if QT_VERSION >= 210 && defined(SIP_FEATURE_TQt_INPUTDIALOG)
  264. {sipName_TQInputDialog, &sipClass_TQInputDialog, -1, 82},
  265. #else
  266. {NULL, NULL, -1, 82},
  267. #endif
  268. #if defined(SIP_FEATURE_TQt_MESSAGEBOX)
  269. {sipName_TQMessageBox, &sipClass_TQMessageBox, -1, 83},
  270. #else
  271. {NULL, NULL, -1, 83},
  272. #endif
  273. #if defined(SIP_FEATURE_TQt_WIZARD)
  274. {sipName_TQWizard, &sipClass_TQWizard, -1, 84},
  275. #else
  276. {NULL, NULL, -1, 84},
  277. #endif
  278. #if defined(SIP_FEATURE_TQt_COLORDIALOG)
  279. {sipName_TQColorDialog, &sipClass_TQColorDialog, -1, 85},
  280. #else
  281. {NULL, NULL, -1, 85},
  282. #endif
  283. #if defined(SIP_FEATURE_TQt_FONTDIALOG)
  284. {sipName_TQFontDialog, &sipClass_TQFontDialog, -1, 86},
  285. #else
  286. {NULL, NULL, -1, 86},
  287. #endif
  288. #if defined(SIP_FEATURE_TQt_FILEDIALOG)
  289. {sipName_TQFileDialog, &sipClass_TQFileDialog, -1, 87},
  290. #else
  291. {NULL, NULL, -1, 87},
  292. #endif
  293. #if defined(SIP_FEATURE_TQt_PROGRESSDIALOG)
  294. {sipName_TQProgressDialog, &sipClass_TQProgressDialog, -1, 88},
  295. #else
  296. {NULL, NULL, -1, 88},
  297. #endif
  298. #if defined(SIP_FEATURE_TQt_TABDIALOG)
  299. {sipName_TQTabDialog, &sipClass_TQTabDialog, -1, -1},
  300. #else
  301. {NULL, NULL, -1, -1},
  302. #endif
  303. #if QT_VERSION >= 220 && defined(SIP_FEATURE_TQt_ACTION)
  304. {sipName_TQActionGroup, &sipClass_TQActionGroup, -1, -1},
  305. #else
  306. {NULL, NULL, -1, -1},
  307. #endif
  308. {sipName_TQGridLayout, &sipClass_TQGridLayout, -1, 91},
  309. {sipName_TQBoxLayout, &sipClass_TQBoxLayout, 92, -1},
  310. {sipName_TQHBoxLayout, &sipClass_TQHBoxLayout, -1, 93},
  311. {sipName_TQVBoxLayout, &sipClass_TQVBoxLayout, -1, -1},
  312. {sipName_TQDoubleValidator, &sipClass_TQDoubleValidator, -1, 95},
  313. {sipName_TQIntValidator, &sipClass_TQIntValidator, -1, 96},
  314. #if QT_VERSION >= 0x030000
  315. {sipName_TQRegExpValidator, &sipClass_TQRegExpValidator, -1, -1},
  316. #else
  317. {NULL, NULL, -1, -1},
  318. #endif
  319. {sipName_TQTextDrag, &sipClass_TQTextDrag, -1, 98},
  320. {sipName_TQStoredDrag, &sipClass_TQStoredDrag, 101, 99},
  321. #if QT_VERSION >= 210 && defined(SIP_FEATURE_TQt_ICONVIEW) && defined(SIP_FEATURE_TQt_DRAGANDDROP)
  322. {sipName_TQIconDrag, &sipClass_TQIconDrag, -1, 100},
  323. #else
  324. {NULL, NULL, -1, 100},
  325. #endif
  326. {sipName_TQImageDrag, &sipClass_TQImageDrag, -1, -1},
  327. #if QT_VERSION >= 210
  328. {sipName_TQColorDrag, &sipClass_TQColorDrag, -1, 102},
  329. #else
  330. {NULL, NULL, -1, 102},
  331. #endif
  332. {sipName_TQUriDrag, &sipClass_TQUriDrag, -1, -1},
  333. {sipName_TQCommonStyle, &sipClass_TQCommonStyle, 104, -1},
  334. #if defined(SIP_FEATURE_TQt_STYLE_WINDOWS)
  335. {sipName_TQWindowsStyle, &sipClass_TQWindowsStyle, 106, 105},
  336. #else
  337. {NULL, NULL, -1, 105},
  338. #endif
  339. #if defined(SIP_FEATURE_TQt_STYLE_MOTIF)
  340. {sipName_TQMotifStyle, &sipClass_TQMotifStyle, 107, -1},
  341. #else
  342. {NULL, NULL, -1, -1},
  343. #endif
  344. #if defined(SIP_FEATURE_TQt_STYLE_PLATINUM)
  345. {sipName_TQPlatinumStyle, &sipClass_TQPlatinumStyle, -1, 110},
  346. #else
  347. {NULL, NULL, -1, 110},
  348. #endif
  349. #if defined(SIP_FEATURE_TQt_STYLE_CDE)
  350. {sipName_TQCDEStyle, &sipClass_TQCDEStyle, -1, 108},
  351. #else
  352. {NULL, NULL, -1, 108},
  353. #endif
  354. #if QT_VERSION >= 220 && defined(SIP_FEATURE_TQt_STYLE_MOTIFPLUS)
  355. {sipName_TQMotifPlusStyle, &sipClass_TQMotifPlusStyle, -1, 109},
  356. #else
  357. {NULL, NULL, -1, 109},
  358. #endif
  359. #if QT_VERSION >= 220 && defined(SIP_FEATURE_TQt_STYLE_SGI)
  360. {sipName_TQSGIStyle, &sipClass_TQSGIStyle, -1, -1},
  361. #else
  362. {NULL, NULL, -1, -1},
  363. #endif
  364. #if defined(PYQT_STYLE_WINDOWSXP)
  365. {sipName_TQWindowsXPStyle, &sipClass_TQWindowsXPStyle, -1, -1},
  366. #else
  367. {NULL, NULL, -1, -1},
  368. #endif
  369. };
  370. int i = 0;
  371. sipClass = NULL;
  372. do
  373. {
  374. struct class_graph *cg = &graph[i];
  375. if (cg->name != NULL && sipCpp->inherits(cg->name))
  376. {
  377. sipClass = *cg->type;
  378. i = cg->yes;
  379. }
  380. else
  381. i = cg->no;
  382. }
  383. while (i >= 0);
  384. %End
  385. // This is really virtual. With the way we are implementing it doesn't
  386. // need to be and has the advantage that the C++ implementation can be
  387. // used in %ConvertToSubClassCode to get the C++ name for Python
  388. // sub-classes. However, it is also means that C++ plugins can't get
  389. // the true (Python) class name.
  390. SIP_PYOBJECT className() const;
  391. %MethodCode
  392. sipRes = sipClassName(sipSelf);
  393. %End
  394. %If (- TQt_3_0_0)
  395. static TQString tr(const char *) /AutoGen=TQt_TRANSLATION/;
  396. %End
  397. %If (TQt_2_2_0 - TQt_2_3_1)
  398. // There was an apparent bug in moc prior to TQt v2.3.1 where this
  399. // method wasn't automatically generated.
  400. static TQString tr(const char *,const char *);
  401. %End
  402. %If (TQt_2_3_1 - TQt_3_0_0)
  403. static TQString tr(const char *,const char *) /AutoGen=TQt_TRANSLATION/;
  404. %End
  405. %If (TQt_3_0_0 -)
  406. // Note that tr() and trUtf8() are really static methods. We pretend
  407. // they aren't so that we can use self to get hold of the class name.
  408. // We could mimic moc's behaviour more accurately by creating tr() and
  409. // trUtf8() methods for a Python sub-class instance in the sub-class's
  410. // ctor.
  411. TQString tr(const char *,const char * = 0);
  412. %MethodCode
  413. PyObject *nmobj;
  414. if ((nmobj = sipClassName(sipSelf)) == NULL)
  415. sipIsErr = 1;
  416. else
  417. {
  418. char *cname = PyString_AsString(nmobj);
  419. Py_BEGIN_ALLOW_THREADS
  420. if (cname && qApp)
  421. sipRes = new TQString(qApp -> translate(cname,a0,a1,TQApplication::DefaultCodec));
  422. else
  423. sipRes = new TQString(TQString::fromLatin1(a0));
  424. Py_END_ALLOW_THREADS
  425. Py_DECREF(nmobj);
  426. }
  427. %End
  428. TQString trUtf8(const char *,const char * = 0);
  429. %MethodCode
  430. PyObject *nmobj;
  431. if ((nmobj = sipClassName(sipSelf)) == NULL)
  432. sipIsErr = 1;
  433. else
  434. {
  435. char *cname = PyString_AsString(nmobj);
  436. Py_BEGIN_ALLOW_THREADS
  437. if (cname && qApp)
  438. sipRes = new TQString(qApp -> translate(cname,a0,a1,TQApplication::UnicodeUTF8));
  439. else
  440. sipRes = new TQString(TQString::fromUtf8(a0));
  441. Py_END_ALLOW_THREADS
  442. Py_DECREF(nmobj);
  443. }
  444. %End
  445. %End
  446. virtual TQMetaObject *metaObject() const /AutoGen/;
  447. virtual bool event(TQEvent *);
  448. virtual bool eventFilter(TQObject *,TQEvent *);
  449. bool isA(const char *) const;
  450. %MethodCode
  451. // The TQt implementation doesn't know anything about Python
  452. // sub-classes. For SIP v4 we use the Python type's name. For
  453. // SIP v3 we use the broken TQt behaviour as it's deprecated and
  454. // we want to keep things simple.
  455. #if SIP_VERSION >= 0x040000
  456. sipRes = (strcmp(sipSelf -> ob_type -> tp_name,a0) == 0);
  457. #else
  458. Py_BEGIN_ALLOW_THREADS
  459. sipRes = sipCpp -> TQObject::isA(a0);
  460. Py_END_ALLOW_THREADS
  461. #endif
  462. %End
  463. bool inherits(const char *) const;
  464. %MethodCode
  465. // The TQt implementation doesn't know anything about Python
  466. // sub-classes. For SIP v4 we use the Python type's MRO. For
  467. // SIP v3 we use the broken TQt behaviour as it's deprecated and
  468. // we want to keep things simple.
  469. #if SIP_VERSION >= 0x040000
  470. PyObject *mro = sipSelf -> ob_type -> tp_mro;
  471. sipRes = 0;
  472. for (int i = 0; i < PyTuple_GET_SIZE(mro); ++i)
  473. if (strcmp(((PyTypeObject *)PyTuple_GET_ITEM(mro,i)) -> tp_name,a0) == 0)
  474. {
  475. sipRes = 1;
  476. break;
  477. }
  478. #else
  479. Py_BEGIN_ALLOW_THREADS
  480. sipRes = sipCpp -> TQObject::inherits(a0);
  481. Py_END_ALLOW_THREADS
  482. #endif
  483. %End
  484. %If (- TQt_3_0_0)
  485. TQStringList superClasses(bool = 0) const;
  486. %End
  487. const char *name() const;
  488. const char *name(const char *) const;
  489. virtual void setName(const char *);
  490. bool isWidgetType() const;
  491. bool highPriority() const;
  492. bool signalsBlocked() const;
  493. void blockSignals(bool);
  494. int startTimer(int);
  495. void killTimer(int);
  496. void killTimers();
  497. %If (- TQt_3_0_0)
  498. TQObject *child(const char *,const char * = 0);
  499. %End
  500. %If (TQt_3_0_0 -)
  501. TQObject *child(const char *,const char * = 0,bool = 1);
  502. %End
  503. const TQObjectList *children() const;
  504. %If (TQt_2_1_0 -)
  505. static const TQObjectList *objectTrees();
  506. %End
  507. %If (- TQt_3_0_0)
  508. TQObjectList *queryList(char * = 0,char * = 0,bool = 1,bool = 1);
  509. %End
  510. %If (TQt_3_0_0 -)
  511. TQObjectList *queryList(char * = 0,char * = 0,bool = 1,bool = 1) const;
  512. %MethodCode
  513. // The TQt implementation doesn't know anything about Python
  514. // sub-classes. For SIP v4 we get all classes and then use the
  515. // Python type's MRO to weed out those we don't want. For SIP
  516. // v3 we use the broken TQt behaviour as it's deprecated and we
  517. // want to keep things simple.
  518. #if SIP_VERSION >= 0x040000
  519. sipRes = sipCpp -> TQObject::queryList(0, a1, a2, a3);
  520. if (a0 && sipRes)
  521. {
  522. TQObject *o = sipRes -> first();
  523. while (o)
  524. {
  525. bool remove = TRUE;
  526. PyObject *pyo = sipConvertFromInstance(o, sipClass_TQObject, 0);
  527. if (pyo)
  528. {
  529. PyObject *mro = pyo -> ob_type -> tp_mro;
  530. for (int i = 0; i < PyTuple_GET_SIZE(mro); ++i)
  531. if (strcmp(((PyTypeObject *)PyTuple_GET_ITEM(mro,i)) -> tp_name,a0) == 0)
  532. {
  533. remove = FALSE;
  534. break;
  535. }
  536. Py_DECREF(pyo);
  537. }
  538. if (remove)
  539. {
  540. sipRes -> remove();
  541. o = sipRes -> current();
  542. }
  543. else
  544. o = sipRes -> next();
  545. }
  546. }
  547. #else
  548. Py_BEGIN_ALLOW_THREADS
  549. sipRes = sipCpp -> TQObject::queryList(a0, a1, a2, a3);
  550. Py_END_ALLOW_THREADS
  551. #endif
  552. %End
  553. %End
  554. virtual void insertChild(TQObject * /Transfer/);
  555. virtual void removeChild(TQObject * /TransferBack/);
  556. void installEventFilter(const TQObject *);
  557. void removeEventFilter(const TQObject *);
  558. static SIP_PYOBJECT connect(SIP_QOBJECT,SIP_SIGNAL,SIP_QOBJECT,SIP_SLOT);
  559. %MethodCode
  560. sipRes = sipConnectRx(a0,a1,a2,a3,0);
  561. %End
  562. static SIP_PYOBJECT connect(SIP_QOBJECT,SIP_SIGNAL,SIP_PYCALLABLE);
  563. %MethodCode
  564. sipRes = sipConnectRx(a0,a1,a2,0,0);
  565. %End
  566. SIP_PYOBJECT connect(SIP_QOBJECT,SIP_SIGNAL,SIP_SLOT) const;
  567. %MethodCode
  568. sipRes = sipConnectRx(a0,a1,sipSelf,a2,0);
  569. %End
  570. static SIP_PYOBJECT disconnect(SIP_QOBJECT,SIP_SIGNAL,SIP_QOBJECT,SIP_SLOT);
  571. %MethodCode
  572. sipRes = sipDisconnectRx(a0,a1,a2,a3);
  573. %End
  574. static SIP_PYOBJECT disconnect(SIP_QOBJECT,SIP_SIGNAL,SIP_PYCALLABLE);
  575. %MethodCode
  576. sipRes = sipDisconnectRx(a0,a1,a2,0);
  577. %End
  578. // bool disconnect(const char * = 0,const TQObject * = 0,const char * = 0);
  579. // bool disconnect(const TQObject *,const char * = 0);
  580. void dumpObjectTree();
  581. void dumpObjectInfo();
  582. TQObject *parent() const;
  583. void emit(SIP_SIGNAL,SIP_PYTUPLE);
  584. %MethodCode
  585. if (pyqt3EmitSignal(sipSelf, a0, a1) < 0)
  586. sipIsErr = 1;
  587. %End
  588. %If (TQt_PROPERTIES)
  589. %If (TQt_2_1_0 - TQt_3_0_0)
  590. bool setProperty(const char *,const TQVariant &);
  591. TQVariant property(const char *) const;
  592. %End
  593. %If (TQt_3_0_0 -)
  594. virtual bool setProperty(const char *,const TQVariant &);
  595. virtual TQVariant property(const char *) const;
  596. %End
  597. %End
  598. signals:
  599. void destroyed();
  600. %If (TQt_3_0_0 -)
  601. void destroyed(TQObject *);
  602. %End
  603. public slots:
  604. %If (TQt_3_0_0 -)
  605. void deleteLater();
  606. %End
  607. public:
  608. // This is actually protected, but we never need to call the real
  609. // method.
  610. SIP_PYOBJECT sender();
  611. %MethodCode
  612. sipRes = pyqt3GetSender();
  613. %End
  614. protected:
  615. virtual void timerEvent(TQTimerEvent *);
  616. virtual void childEvent(TQChildEvent *);
  617. %If (TQt_3_0_0 -)
  618. virtual void customEvent(TQCustomEvent *);
  619. %End
  620. private:
  621. TQObject(const TQObject &);
  622. };
  623. SIP_PYOBJECT QT_TR_NOOP(SIP_PYOBJECT);
  624. %MethodCode
  625. Py_INCREF(a0);
  626. sipRes = a0;
  627. %End
  628. SIP_PYOBJECT QT_TRANSLATE_NOOP(SIP_PYOBJECT,SIP_PYOBJECT);
  629. %MethodCode
  630. Py_INCREF(a1);
  631. sipRes = a1;
  632. %End
  633. %End
  634. %If (- TQt_2_00)
  635. class TQObject
  636. {
  637. %TypeHeaderCode
  638. #include <qobject.h>
  639. %End
  640. public:
  641. TQObject(TQObject * /TransferThis/ = 0,const char * = 0);
  642. %ConvertToSubClassCode
  643. // The table of Python class objects indexed by their names. The table
  644. // must be sorted by name.
  645. static sipStringTypeClassMap map[] = {
  646. {sipName_TQAccel, &sipClass_TQAccel},
  647. {sipName_TQApplication, &sipClass_TQApplication},
  648. {sipName_TQBoxLayout, &sipClass_TQBoxLayout},
  649. {sipName_TQButton, &sipClass_TQButton},
  650. {sipName_TQButtonGroup, &sipClass_TQButtonGroup},
  651. {sipName_TQCheckBox, &sipClass_TQCheckBox},
  652. #if defined(SIP_FEATURE_TQt_CLIPBOARD)
  653. {sipName_TQClipboard, &sipClass_TQClipboard},
  654. #endif
  655. {sipName_TQComboBox, &sipClass_TQComboBox},
  656. {sipName_TQDialog, &sipClass_TQDialog},
  657. {sipName_TQDoubleValidator, &sipClass_TQDoubleValidator},
  658. {sipName_TQDragObject, &sipClass_TQDragObject},
  659. #if defined(SIP_FEATURE_TQt_FILEDIALOG)
  660. {sipName_TQFileDialog, &sipClass_TQFileDialog},
  661. {sipName_TQFileIconProvider, &sipClass_TQFileIconProvider},
  662. #endif
  663. {sipName_TQFrame, &sipClass_TQFrame},
  664. {sipName_TQGridLayout, &sipClass_TQGridLayout},
  665. {sipName_TQGroupBox, &sipClass_TQGroupBox},
  666. {sipName_TQHBoxLayout, &sipClass_TQHBoxLayout},
  667. {sipName_TQHeader, &sipClass_TQHeader},
  668. {sipName_TQImageDrag, &sipClass_TQImageDrag},
  669. {sipName_TQIntValidator, &sipClass_TQIntValidator},
  670. {sipName_TQLCDNumber, &sipClass_TQLCDNumber},
  671. {sipName_TQLabel, &sipClass_TQLabel},
  672. {sipName_TQLayout, &sipClass_TQLayout},
  673. {sipName_TQLineEdit, &sipClass_TQLineEdit},
  674. {sipName_TQListBox, &sipClass_TQListBox},
  675. {sipName_TQListView, &sipClass_TQListView},
  676. {sipName_TQMainWindow, &sipClass_TQMainWindow},
  677. {sipName_TQMenuBar, &sipClass_TQMenuBar},
  678. #if defined(SIP_FEATURE_TQt_MESSAGEBOX)
  679. {sipName_TQMessageBox, &sipClass_TQMessageBox},
  680. #endif
  681. {sipName_TQMultiLineEdit, &sipClass_TQMultiLineEdit},
  682. {sipName_TQPopupMenu, &sipClass_TQPopupMenu},
  683. #if defined(WS_X11) && defined(SIP_FEATURE_TQt_PRINTDIALOG)
  684. {sipName_TQPrintDialog, &sipClass_TQPrintDialog},
  685. #endif
  686. {sipName_TQProgressBar, &sipClass_TQProgressBar},
  687. #if defined(SIP_FEATURE_TQt_PROGRESSDIALOG)
  688. {sipName_TQProgressDialog, &sipClass_TQProgressDialog},
  689. #endif
  690. {sipName_TQPushButton, &sipClass_TQPushButton},
  691. {sipName_TQRadioButton, &sipClass_TQRadioButton},
  692. {sipName_TQScrollBar, &sipClass_TQScrollBar},
  693. {sipName_TQScrollView, &sipClass_TQScrollView},
  694. {sipName_TQSlider, &sipClass_TQSlider},
  695. {sipName_TQSocketNotifier, &sipClass_TQSocketNotifier},
  696. {sipName_TQSpinBox, &sipClass_TQSpinBox},
  697. #if defined(SIP_FEATURE_TQt_SPLITTER)
  698. {sipName_TQSplitter, &sipClass_TQSplitter},
  699. #endif
  700. {sipName_TQStatusBar, &sipClass_TQStatusBar},
  701. {sipName_TQStoredDrag, &sipClass_TQStoredDrag},
  702. {sipName_TQTabBar, &sipClass_TQTabBar},
  703. {sipName_TQTextDrag, &sipClass_TQTextDrag},
  704. {sipName_TQTimer, &sipClass_TQTimer},
  705. {sipName_TQToolBar, &sipClass_TQToolBar},
  706. {sipName_TQToolButton, &sipClass_TQToolButton},
  707. {sipName_TQToolTipGroup, &sipClass_TQToolTipGroup},
  708. {sipName_TQVBoxLayout, &sipClass_TQVBoxLayout},
  709. {sipName_TQValidator, &sipClass_TQValidator},
  710. {sipName_TQWidget, &sipClass_TQWidget},
  711. {sipName_TQWidgetStack, &sipClass_TQWidgetStack}
  712. };
  713. sipClass = sipMapStringToClass(sipCpp -> className(),map,sizeof (map)/sizeof (map[0]));
  714. %End
  715. static SIP_PYOBJECT connect(SIP_QOBJECT,SIP_SIGNAL,SIP_QOBJECT,SIP_SLOT);
  716. %MethodCode
  717. sipRes = sipConnectRx(a0,a1,a2,a3,0);
  718. %End
  719. static SIP_PYOBJECT connect(SIP_QOBJECT,SIP_SIGNAL,SIP_PYCALLABLE);
  720. %MethodCode
  721. sipRes = sipConnectRx(a0,a1,a2,0,0);
  722. %End
  723. static SIP_PYOBJECT disconnect(SIP_QOBJECT,SIP_SIGNAL,SIP_QOBJECT,SIP_SLOT);
  724. %MethodCode
  725. sipRes = sipDisconnectRx(a0,a1,a2,a3);
  726. %End
  727. static SIP_PYOBJECT disconnect(SIP_QOBJECT,SIP_SIGNAL,SIP_PYCALLABLE);
  728. %MethodCode
  729. sipRes = sipDisconnectRx(a0,a1,a2,0);
  730. %End
  731. virtual bool event(TQEvent *);
  732. virtual bool eventFilter(TQObject *,TQEvent *);
  733. const char *tr(const char *) const;
  734. virtual TQMetaObject *metaObject() const /AutoGen/;
  735. // This is actually virtual. However, with the way we are implementing
  736. // it we can ignore it.
  737. SIP_PYOBJECT className() const;
  738. %MethodCode
  739. sipRes = sipClassName(sipSelf);
  740. %End
  741. bool isA(const char *) const;
  742. bool inherits(const char *) const;
  743. const char *name() const;
  744. const char *name(const char *) const;
  745. void setName(const char *);
  746. bool isWidgetType() const;
  747. bool highPriority() const;
  748. bool signalsBlocked() const;
  749. void blockSignals(bool);
  750. int startTimer(int);
  751. void killTimer(int);
  752. void killTimers();
  753. const TQObjectList *children() const;
  754. TQObjectList *queryList(char * = 0,char * = 0,bool = 1,bool = 1);
  755. void insertChild(TQObject * /Transfer/);
  756. void removeChild(TQObject * /TransferBack/);
  757. void installEventFilter(const TQObject *);
  758. void removeEventFilter(const TQObject *);
  759. // bool connect(TQObject *,const char *,const char *);
  760. // bool disconnect(const char * = 0,const TQObject * = 0,const char * = 0);
  761. // bool disconnect(const TQObject *,const char * = 0);
  762. void dumpObjectTree();
  763. void dumpObjectInfo();
  764. TQObject *parent() const;
  765. void emit(SIP_SIGNAL,SIP_PYTUPLE);
  766. %MethodCode
  767. if (sipEmitSignal(sipSelf,a0,a1) < 0)
  768. sipIsErr = 1;
  769. %End
  770. signals:
  771. void destroyed();
  772. public:
  773. // This is actually protected, but we never need to call the real
  774. // method.
  775. SIP_PYOBJECT sender();
  776. %MethodCode
  777. sipRes = pyqt3GetSender();
  778. %End
  779. protected:
  780. virtual void timerEvent(TQTimerEvent *);
  781. private:
  782. TQObject(const TQObject &);
  783. };
  784. %End
  785. SIP_PYOBJECT SLOT(const char *);
  786. %MethodCode
  787. if (!a0)
  788. {
  789. PyErr_Format(PyExc_TypeError,"qt.SLOT() slot name cannot be None");
  790. sipIsErr = 1;
  791. }
  792. else
  793. {
  794. int len = strlen(a0);
  795. if ((sipRes = PyString_FromStringAndSize(NULL,1 + len)) == NULL)
  796. sipIsErr = 1;
  797. else
  798. {
  799. char *dp = PyString_AS_STRING(sipRes);
  800. *dp++ = '1';
  801. memcpy(dp,a0,len + 1);
  802. }
  803. }
  804. %End
  805. SIP_PYOBJECT SIGNAL(const char *);
  806. %MethodCode
  807. if (!a0)
  808. {
  809. PyErr_Format(PyExc_TypeError,"qt.SIGNAL() signal cannot be None");
  810. sipIsErr = 1;
  811. }
  812. else
  813. {
  814. int len = strlen(a0);
  815. if ((sipRes = PyString_FromStringAndSize(NULL,1 + len)) == NULL)
  816. sipIsErr = 1;
  817. else
  818. {
  819. char *dp = PyString_AS_STRING(sipRes);
  820. *dp++ = '2';
  821. memcpy(dp,a0,len + 1);
  822. }
  823. }
  824. %End
  825. SIP_PYOBJECT PYSIGNAL(const char *);
  826. %MethodCode
  827. if (!a0)
  828. {
  829. PyErr_Format(PyExc_TypeError,"qt.PYSIGNAL() signal cannot be None");
  830. sipIsErr = 1;
  831. }
  832. else
  833. {
  834. int len = strlen(a0);
  835. if ((sipRes = PyString_FromStringAndSize(NULL,1 + len)) == NULL)
  836. sipIsErr = 1;
  837. else
  838. {
  839. char *dp = PyString_AS_STRING(sipRes);
  840. *dp++ = '9';
  841. memcpy(dp,a0,len + 1);
  842. }
  843. }
  844. %End
  845. %ModuleHeaderCode
  846. int pyqt3EmitSignal(PyObject *self, const char *sig, PyObject *sigargs);
  847. PyObject *pyqt3GetSender();
  848. %End
  849. // This is the TQt support code for SIP v4.4 and later.
  850. %ModuleCode
  851. #include <string.h>
  852. #include <qobject.h>
  853. #include <qvariant.h>
  854. #include <qmetaobject.h>
  855. #include <private/qucom_p.h>
  856. #include <private/qucomextra_p.h>
  857. // These optional parts of the legacy TQt support API for SIP are implemented.
  858. #undef sipTQtEmitSignal
  859. #undef sipTQtConnectPySignal
  860. #undef sipTQtDisconnectPySignal
  861. // Declare explicit C linkage.
  862. extern "C"
  863. {
  864. static void *sipTQtCreateUniversalSlot(sipWrapper *, const char *,
  865. PyObject *, const char *, const char **, int);
  866. static void sipTQtDestroyUniversalSlot(void *);
  867. static void *sipTQtFindSlot(void *, const char *, PyObject *, const char *,
  868. const char **);
  869. static int sipTQtConnect(void *, const char *, void *, const char *, int);
  870. static int sipTQtDisconnect(void *, const char *, void *, const char *);
  871. static int sipTQtSameSignalSlotName(const char *, const char *);
  872. static sipSlot *sipTQtFindSipslot(void *, void **);
  873. static int sipTQtEmitSignal(PyObject *, const char *, PyObject *);
  874. static int sipTQtConnectPySignal(PyObject *, const char *, PyObject *,
  875. const char *);
  876. static void sipTQtDisconnectPySignal(PyObject *, const char *,
  877. PyObject *, const char *);
  878. }
  879. extern "C" {
  880. // The meta-type for PyTQt classes. It is just a marker type so that we can
  881. // safely cast to get access to PyTQt3-specific data structures.
  882. PyTypeObject pyqtWrapperType_Type = {
  883. PyObject_HEAD_INIT(NULL)
  884. 0, /* ob_size */
  885. "qt.pyqtWrapperType", /* tp_name */
  886. sizeof (sipWrapperType), /* tp_basicsize */
  887. 0, /* tp_itemsize */
  888. 0, /* tp_dealloc */
  889. 0, /* tp_print */
  890. 0, /* tp_getattr */
  891. 0, /* tp_setattr */
  892. 0, /* tp_compare */
  893. 0, /* tp_repr */
  894. 0, /* tp_as_number */
  895. 0, /* tp_as_sequence */
  896. 0, /* tp_as_mapping */
  897. 0, /* tp_hash */
  898. 0, /* tp_call */
  899. 0, /* tp_str */
  900. 0, /* tp_getattro */
  901. 0, /* tp_setattro */
  902. 0, /* tp_as_buffer */
  903. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
  904. 0, /* tp_doc */
  905. 0, /* tp_traverse */
  906. 0, /* tp_clear */
  907. 0, /* tp_richcompare */
  908. 0, /* tp_weaklistoffset */
  909. 0, /* tp_iter */
  910. 0, /* tp_iternext */
  911. 0, /* tp_methods */
  912. 0, /* tp_members */
  913. 0, /* tp_getset */
  914. 0, /* tp_base */
  915. 0, /* tp_dict */
  916. 0, /* tp_descr_get */
  917. 0, /* tp_descr_set */
  918. 0, /* tp_dictoffset */
  919. 0, /* tp_init */
  920. 0, /* tp_alloc */
  921. 0, /* tp_new */
  922. 0, /* tp_free */
  923. 0, /* tp_is_gc */
  924. 0, /* tp_bases */
  925. 0, /* tp_mro */
  926. 0, /* tp_cache */
  927. 0, /* tp_subclasses */
  928. 0, /* tp_weaklist */
  929. 0, /* tp_del */
  930. #if PY_VERSION_HEX >= 0x02060000
  931. 0, /* tp_version_tag */
  932. #endif
  933. };
  934. /*
  935. * An entry in a linked list of slots.
  936. */
  937. typedef struct _pyqt3SlotList {
  938. /* The receiver. */
  939. sipSlot rx;
  940. /* Next in the list. */
  941. struct _pyqt3SlotList *next;
  942. } pyqt3SlotList;
  943. /*
  944. * A Python signal.
  945. */
  946. typedef struct _pyqt3PySig {
  947. /* The name of the signal. */
  948. char *name;
  949. /* The list of receivers. */
  950. pyqt3SlotList *rxlist;
  951. /* Next in the list. */
  952. struct _pyqt3PySig *next;
  953. } pyqt3PySig;
  954. /*
  955. * The C++ wrapper object used by PyTQt3.
  956. */
  957. typedef struct _pyqtWrapper {
  958. /* The super-type. */
  959. sipWrapper super;
  960. /* The list of Python signals. */
  961. pyqt3PySig *pySigList;
  962. } pyqtWrapper;
  963. /*
  964. * Clear any slots connected to any Python signals.
  965. */
  966. static void clear_py_signals_slots(pyqtWrapper *pw)
  967. {
  968. pyqt3PySig *ps;
  969. for (ps = pw->pySigList; ps != NULL; ps = ps->next)
  970. {
  971. pyqt3SlotList *psrx;
  972. for (psrx = ps->rxlist; psrx != NULL; psrx = psrx->next)
  973. sipClearAnySlotReference(&psrx->rx);
  974. }
  975. }
  976. /*
  977. * Find the given Python signal.
  978. */
  979. static pyqt3PySig *find_py_signal(pyqtWrapper *pw, const char *sig)
  980. {
  981. pyqt3PySig *ps;
  982. for (ps = pw->pySigList; ps != NULL; ps = ps->next)
  983. if (sipTQtSameSignalSlotName(ps->name, sig))
  984. return ps;
  985. return 0;
  986. }
  987. /*
  988. * Free an slot list entry.
  989. */
  990. static void free_slot_list(pyqt3SlotList *sl)
  991. {
  992. sipFreeSipslot(&sl->rx);
  993. sipFree(sl);
  994. }
  995. /*
  996. * The instance clear slot.
  997. */
  998. static int pyqtWrapper_clear(pyqtWrapper *self)
  999. {
  1000. clear_py_signals_slots(self);
  1001. return sipWrapper_Type->tp_clear((PyObject *)self);
  1002. }
  1003. /*
  1004. * The instance dealloc slot.
  1005. */
  1006. static void pyqtWrapper_dealloc(pyqtWrapper *self)
  1007. {
  1008. clear_py_signals_slots(self);
  1009. while (self->pySigList != NULL)
  1010. {
  1011. pyqt3PySig *ps;
  1012. pyqt3SlotList *psrx;
  1013. /* Take this one out of the list. */
  1014. ps = self->pySigList;
  1015. self->pySigList = ps->next;
  1016. while ((psrx = ps->rxlist) != NULL)
  1017. {
  1018. ps->rxlist = psrx->next;
  1019. free_slot_list(psrx);
  1020. }
  1021. sipFree(ps->name);
  1022. sipFree(ps);
  1023. }
  1024. sipWrapper_Type->tp_dealloc((PyObject *)self);
  1025. }
  1026. /*
  1027. * The instance traverse slot.
  1028. */
  1029. static int pyqtWrapper_traverse(pyqtWrapper *self, visitproc visit, void *arg)
  1030. {
  1031. int vret;
  1032. pyqt3PySig *ps;
  1033. if ((vret = sipWrapper_Type->tp_traverse((PyObject *)self, visit, arg)) != 0)
  1034. return vret;
  1035. for (ps = self->pySigList; ps != NULL; ps = ps->next)
  1036. {
  1037. pyqt3SlotList *psrx;
  1038. for (psrx = ps->rxlist; psrx != NULL; psrx = psrx->next)
  1039. if ((vret = sipVisitSlot(&psrx->rx, visit, arg)) != 0)
  1040. return vret;
  1041. }
  1042. return 0;
  1043. }
  1044. static sipWrapperType pyqtWrapper_Type = {
  1045. #if !defined(STACKLESS)
  1046. {
  1047. #endif
  1048. {
  1049. PyObject_HEAD_INIT(&pyqtWrapperType_Type)
  1050. 0, /* ob_size */
  1051. "qt.pyqtWrapper", /* tp_name */
  1052. sizeof (pyqtWrapper), /* tp_basicsize */
  1053. 0, /* tp_itemsize */
  1054. (destructor)pyqtWrapper_dealloc, /* tp_dealloc */
  1055. 0, /* tp_print */
  1056. 0, /* tp_getattr */
  1057. 0, /* tp_setattr */
  1058. 0, /* tp_compare */
  1059. 0, /* tp_repr */
  1060. 0, /* tp_as_number */
  1061. 0, /* tp_as_sequence */
  1062. 0, /* tp_as_mapping */
  1063. 0, /* tp_hash */
  1064. 0, /* tp_call */
  1065. 0, /* tp_str */
  1066. 0, /* tp_getattro */
  1067. 0, /* tp_setattro */
  1068. 0, /* tp_as_buffer */
  1069. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */
  1070. 0, /* tp_doc */
  1071. (traverseproc)pyqtWrapper_traverse, /* tp_traverse */
  1072. (inquiry)pyqtWrapper_clear, /* tp_clear */
  1073. 0, /* tp_richcompare */
  1074. 0, /* tp_weaklistoffset */
  1075. 0, /* tp_iter */
  1076. 0, /* tp_iternext */
  1077. 0, /* tp_methods */
  1078. 0, /* tp_members */
  1079. 0, /* tp_getset */
  1080. 0, /* tp_base */
  1081. 0, /* tp_dict */
  1082. 0, /* tp_descr_get */
  1083. 0, /* tp_descr_set */
  1084. 0, /* tp_dictoffset */
  1085. 0, /* tp_init */
  1086. 0, /* tp_alloc */
  1087. 0, /* tp_new */
  1088. 0, /* tp_free */
  1089. 0, /* tp_is_gc */
  1090. 0, /* tp_bases */
  1091. 0, /* tp_mro */
  1092. 0, /* tp_cache */
  1093. 0, /* tp_subclasses */
  1094. 0, /* tp_weaklist */
  1095. 0, /* tp_del */
  1096. #if PY_VERSION_HEX >= 0x02060000
  1097. 0, /* tp_version_tag */
  1098. #endif
  1099. },
  1100. #if !defined(STACKLESS)
  1101. },
  1102. #endif
  1103. 0,
  1104. 0,
  1105. 0
  1106. };
  1107. };
  1108. // This enumerates the different dynamic signal argument types.
  1109. enum pyqt3SigArgType {
  1110. unknown_sat,
  1111. char_sat,
  1112. uchar_sat,
  1113. string_sat,
  1114. ustring_sat,
  1115. short_sat,
  1116. ushort_sat,
  1117. int_sat,
  1118. uint_sat,
  1119. long_sat,
  1120. ulong_sat,
  1121. longlong_sat,
  1122. ulonglong_sat,
  1123. float_sat,
  1124. double_sat,
  1125. enum_sat,
  1126. bool_sat,
  1127. void_sat,
  1128. class_sat,
  1129. classp_sat,
  1130. mtype_sat,
  1131. mtypep_sat,
  1132. qvariant_sat,
  1133. qvariantp_sat,
  1134. pyobject_sat,
  1135. schar_sat,
  1136. sstring_sat,
  1137. wchar_sat,
  1138. wstring_sat
  1139. };
  1140. // This defines a single dynamic signal argument type.
  1141. struct pyqt3SigArg
  1142. {
  1143. // The type.
  1144. pyqt3SigArgType atype;
  1145. union {
  1146. // The Python type for classes.
  1147. sipWrapperType *wt;
  1148. // The data for mapped types.
  1149. const sipTypeDef *mt;
  1150. // The Python type for named enums.
  1151. PyTypeObject *et;
  1152. } u;
  1153. };
  1154. // A parsed signal signature.
  1155. struct pyqt3Signature {
  1156. // The number of arguments.
  1157. int sg_nrargs;
  1158. // The parsed arguments (heap).
  1159. pyqt3SigArg *sg_args;
  1160. // The unparsed signature (heap).
  1161. char *sg_signature;
  1162. // The next in the list.
  1163. pyqt3Signature *sg_next;
  1164. };
  1165. // A connection to a universal slot.
  1166. struct pyqt3SlotConnection
  1167. {
  1168. // The transmitter TQObject.
  1169. void *sc_transmitter;
  1170. // The parsed signature.
  1171. const pyqt3Signature *sc_signature;
  1172. // The slot.
  1173. sipSlot sc_slot;
  1174. };
  1175. // This class is used as a slot on behalf of connections to a Python callable.
  1176. // It is derived from TQObject but is not run through moc. Instead the normal
  1177. // moc-generated methods are handwritten in order to implement a universal
  1178. // slot. This requires some knowledge of the internal implementation of
  1179. // signals and slots but it is likely that they will only change between major
  1180. // TQt versions.
  1181. class UniversalSlot : public TQObject
  1182. {
  1183. public:
  1184. UniversalSlot(TQObject *qtx, pyqt3SlotConnection *conn, const char **member);
  1185. ~UniversalSlot();
  1186. virtual TQMetaObject *metaObject() const
  1187. {
  1188. return staticMetaObject();
  1189. }
  1190. virtual bool qt_invoke(int, TQUObject *args);
  1191. static TQMetaObject *staticMetaObject();
  1192. static TQObject *lastSender;
  1193. static UniversalSlot *unislots;
  1194. UniversalSlot *nextus, *prevus;
  1195. pyqt3SlotConnection conn;
  1196. private:
  1197. static TQMetaObject *metaObj;
  1198. };
  1199. // Create a universal slot. Note that this will leak if there is no signal
  1200. // transmitter (ie. no parent) - TQTimer.singleShot() for example.
  1201. UniversalSlot::UniversalSlot(TQObject *qtx, pyqt3SlotConnection *connection, const char **member) : TQObject()
  1202. {
  1203. // Save the connection.
  1204. conn = *connection;
  1205. // Detect when the transmitter is destroyed.
  1206. if (qtx)
  1207. connect(qtx, SIGNAL(destroyed(TQObject *)), SLOT(deleteLater()));
  1208. // Return the slot to connect to.
  1209. *member = SLOT(unislot());
  1210. // Add this one to the global list.
  1211. nextus = unislots;
  1212. if (nextus)
  1213. nextus -> prevus = this;
  1214. prevus = 0;
  1215. unislots = this;
  1216. }
  1217. // Destroy a universal slot.
  1218. UniversalSlot::~UniversalSlot()
  1219. {
  1220. SIP_BLOCK_THREADS
  1221. sipFreeSipslot(&conn.sc_slot);
  1222. SIP_UNBLOCK_THREADS
  1223. // Remove this one from the global list.
  1224. if (nextus)
  1225. nextus -> prevus = prevus;
  1226. if (prevus)
  1227. prevus -> nextus = nextus;
  1228. else
  1229. unislots = nextus;
  1230. }
  1231. // The last Python signal sender.
  1232. static PyObject *py_sender = 0;
  1233. TQMetaObject *UniversalSlot::metaObj = 0;
  1234. #if QT_VERSION >= 0x030100
  1235. static TQMetaObjectCleanUp cleanUp_UniversalSlot("UniversalSlot", &UniversalSlot::staticMetaObject);
  1236. #else
  1237. static TQMetaObjectCleanUp cleanUp_UniversalSlot;
  1238. #endif
  1239. TQObject *UniversalSlot::lastSender = 0;
  1240. UniversalSlot *UniversalSlot::unislots = 0;
  1241. TQMetaObject *UniversalSlot::staticMetaObject()
  1242. {
  1243. if (metaObj)
  1244. return metaObj;
  1245. // Define a single slot that takes no arguments and so will accept any
  1246. // connection.
  1247. static const TQUMethod slot = {"unislot", 0, 0};
  1248. static const TQMetaData slot_tbl[] = {
  1249. {"unislot()", &slot, TQMetaData::Public}
  1250. };
  1251. metaObj = TQMetaObject::new_metaobject(
  1252. "UniversalSlot", TQObject::staticMetaObject(),
  1253. slot_tbl, 1,
  1254. 0, 0,
  1255. #ifndef QT_NO_PROPERTIES
  1256. 0, 0,
  1257. 0, 0,
  1258. #endif
  1259. 0, 0);
  1260. cleanUp_UniversalSlot.setMetaObject(metaObj);
  1261. return metaObj;
  1262. }
  1263. bool UniversalSlot::qt_invoke(int id, TQUObject *qargs)
  1264. {
  1265. if (id - staticMetaObject()->slotOffset() != 0)
  1266. return TQObject::qt_invoke(id, qargs);
  1267. bool ok = TRUE;
  1268. const pyqt3Signature *psig = conn.sc_signature;
  1269. TQVariant *qv;
  1270. // Save in case it is asked for later.
  1271. lastSender = const_cast<TQObject *>(sender());
  1272. // If the sender was a TQSignal then the single argument will be wrapped
  1273. // in a TQVariant instance. At the moment we handle int argument as
  1274. // that is all that is needed by PyTQt (and PyKDE).
  1275. if (lastSender->inherits("TQSignal"))
  1276. qv = &static_QUType_TQVariant.get(qargs + 1);
  1277. else
  1278. qv = 0;
  1279. #ifdef WITH_THREAD
  1280. PyGILState_STATE state = PyGILState_Ensure();
  1281. #endif
  1282. PyObject *argtup = PyTuple_New(psig->sg_nrargs);
  1283. if (!argtup)
  1284. ok = FALSE;
  1285. else
  1286. {
  1287. for (int a = 0; a < psig->sg_nrargs; ++a)
  1288. {
  1289. PyObject *arg;
  1290. ++qargs;
  1291. switch (psig->sg_args[a].atype)
  1292. {
  1293. case char_sat:
  1294. case schar_sat:
  1295. case uchar_sat:
  1296. arg = PyString_FromStringAndSize((char *)static_QUType_ptr.get(qargs), 1);
  1297. break;
  1298. case string_sat:
  1299. case sstring_sat:
  1300. case ustring_sat:
  1301. arg = PyString_FromString((char *)static_QUType_ptr.get(qargs));
  1302. break;
  1303. case short_sat:
  1304. arg = PyInt_FromLong(*(short *)static_QUType_ptr.get(qargs));
  1305. break;
  1306. case ushort_sat:
  1307. arg = PyLong_FromUnsignedLong(*(unsigned short *)static_QUType_ptr.get(qargs));
  1308. break;
  1309. case int_sat:
  1310. if (qv)
  1311. arg = PyInt_FromLong(qv -> asInt());
  1312. else
  1313. arg = PyInt_FromLong(static_QUType_int.get(qargs));
  1314. break;
  1315. case uint_sat:
  1316. arg = PyLong_FromUnsignedLong(*(unsigned *)static_QUType_ptr.get(qargs));
  1317. break;
  1318. case long_sat:
  1319. arg = PyLong_FromLong(*(long *)static_QUType_ptr.get(qargs));
  1320. break;
  1321. case ulong_sat:
  1322. arg = PyLong_FromUnsignedLong(*(unsigned long *)static_QUType_ptr.get(qargs));
  1323. break;
  1324. case longlong_sat:
  1325. arg = PyLong_FromLongLong(*(PY_LONG_LONG *)static_QUType_ptr.get(qargs));
  1326. break;
  1327. case ulonglong_sat:
  1328. arg = PyLong_FromUnsignedLongLong(*(unsigned PY_LONG_LONG *)static_QUType_ptr.get(qargs));
  1329. break;
  1330. case float_sat:
  1331. arg = PyFloat_FromDouble(*(float *)static_QUType_ptr.get(qargs));
  1332. break;
  1333. case double_sat:
  1334. arg = PyFloat_FromDouble(static_QUType_double.get(qargs));
  1335. break;
  1336. case enum_sat:
  1337. arg = sipConvertFromNamedEnum(*(int *)static_QUType_ptr.get(qargs), psig->sg_args[a].u.et);
  1338. break;
  1339. case bool_sat:
  1340. arg = PyInt_FromLong(static_QUType_bool.get(qargs));
  1341. break;
  1342. case void_sat:
  1343. arg = sipConvertFromVoidPtr((void *)static_QUType_ptr.get(qargs));
  1344. break;
  1345. case class_sat:
  1346. case classp_sat:
  1347. arg = sipConvertFromInstance((void *)static_QUType_ptr.get(qargs),psig->sg_args[a].u.wt,0);
  1348. break;
  1349. case mtype_sat:
  1350. case mtypep_sat:
  1351. arg = sipConvertFromMappedType((void *)static_QUType_ptr.get(qargs),psig->sg_args[a].u.mt,0);
  1352. break;
  1353. case qvariant_sat:
  1354. case qvariantp_sat:
  1355. arg = sipConvertFromInstance((void *)&static_QUType_TQVariant.get(qargs),sipClass_TQVariant,0);
  1356. break;
  1357. case pyobject_sat:
  1358. arg = (PyObject *)static_QUType_ptr.get(qargs);
  1359. break;
  1360. default:
  1361. arg = Py_NotImplemented;
  1362. Py_INCREF(Py_NotImplemented);
  1363. }
  1364. PyTuple_SET_ITEM(argtup, a, arg);
  1365. }
  1366. // Dispatch to the real slot.
  1367. if (ok)
  1368. {
  1369. PyObject *res = sipInvokeSlot(&conn.sc_slot, argtup);
  1370. if (res)
  1371. Py_DECREF(res);
  1372. else
  1373. ok = FALSE;
  1374. }
  1375. Py_DECREF(argtup);
  1376. }
  1377. if (!ok)
  1378. PyErr_Print();
  1379. #ifdef WITH_THREAD
  1380. PyGILState_Release(state);
  1381. #endif
  1382. return ok;
  1383. }
  1384. static pyqt3Signature *parseSignature(const char *sig);
  1385. static void parseType(const char *type, pyqt3SigArg *arg);
  1386. // Factory function to create a universal slot instance. Returns a pointer to
  1387. // the instance or 0 if there was an error.
  1388. static void *sipTQtCreateUniversalSlot(sipWrapper *tx, const char *sig,
  1389. PyObject *rxObj, const char *slot, const char **member, int)
  1390. {
  1391. pyqt3SlotConnection conn;
  1392. /* Initialise the connection. */
  1393. conn.sc_transmitter = (tx ? sipGetCppPtr((sipSimpleWrapper *)tx, 0) : 0);
  1394. /* Save the real slot. */
  1395. if (sipSaveSlot(&conn.sc_slot, rxObj, slot) < 0)
  1396. return 0;
  1397. /* Parse the signature and create the universal slot. */
  1398. if ((conn.sc_signature = parseSignature(sig)) == NULL)
  1399. {
  1400. sipFreeSipslot(&conn.sc_slot);
  1401. return 0;
  1402. }
  1403. TQObject *qtx = 0;
  1404. // See if the transmitter is a TQObject in which case we will connect
  1405. // to it's destroyed signal so that the universal slot can be destroyed
  1406. // at the same time. (Note that we used to do this by making the
  1407. // universal slot a child of the transmitter. This doesn't work as
  1408. // expected because TQWidget destroys its children before emitting the
  1409. // destroyed signal.)
  1410. if (tx && PyObject_TypeCheck((PyObject *)tx, (PyTypeObject *)sipClass_TQObject))
  1411. qtx = reinterpret_cast<TQObject *>(conn.sc_transmitter);
  1412. return new UniversalSlot(qtx, &conn, member);
  1413. }
  1414. // Parse the signal arguments for a connection.
  1415. static pyqt3Signature *parseSignature(const char *sig)
  1416. {
  1417. static pyqt3Signature *psig_list = NULL;
  1418. pyqt3Signature *psig;
  1419. const char *sp, *ep;
  1420. // First see if it has already been parsed. Note that both sides of a
  1421. // connection will probably be parsed twice because the function names will
  1422. // be different even though the signatures will probably be the same. We
  1423. // could be more clever, the most saving is when repeatedly emitting a
  1424. // signal for which this is sufficient.
  1425. for (psig = psig_list; psig != NULL; psig = psig->sg_next)
  1426. if (sipTQtSameSignalSlotName(psig->sg_signature, sig))
  1427. return psig;
  1428. // Create a new one including space for the copy of the signature.
  1429. if ((psig = (pyqt3Signature *)sipMalloc(sizeof (pyqt3Signature) + strlen(sig) + 1)) == NULL)
  1430. return NULL;
  1431. psig->sg_signature = (char *)&psig[1];
  1432. psig->sg_nrargs = 0;
  1433. psig->sg_args = 0;
  1434. // Find the start and end of the arguments.
  1435. sp = strchr(sig, '(');
  1436. ep = strrchr(sig, ')');
  1437. // If the signal isn't well formed we assume TQt will pick it up.
  1438. if (sp && ep && sp < ep)
  1439. {
  1440. // Copy the signature arguments while counting them and removing
  1441. // non-significant spaces. Each argument is left as a '\0' terminated
  1442. // string.
  1443. char *dp = psig->sg_signature;
  1444. int depth = 0, nrcommas = 0, argstart = TRUE;
  1445. for (;;)
  1446. {
  1447. char ch = *++sp;
  1448. if (strchr(",*&)<>", ch))
  1449. {
  1450. // Backup over any previous trailing space.
  1451. if (dp > psig->sg_signature && dp[-1] == ' ')
  1452. --dp;
  1453. if (sp == ep)
  1454. {
  1455. *dp = '\0';
  1456. break;
  1457. }
  1458. if (ch == ',' && depth == 0)
  1459. {
  1460. *dp++ = '\0';
  1461. ++nrcommas;
  1462. argstart = TRUE;
  1463. }
  1464. else
  1465. {
  1466. *dp++ = ch;
  1467. // Make sure commas in template arguments are ignored.
  1468. if (ch == '<')
  1469. ++depth;
  1470. else if (ch == '>')
  1471. --depth;
  1472. }
  1473. }
  1474. else if (ch == ' ')
  1475. {
  1476. // Ignore leading and multiple spaces.
  1477. if (!argstart && dp[-1] != ' ')
  1478. *dp++ = ch;
  1479. }
  1480. else
  1481. {
  1482. *dp++ = ch;
  1483. argstart = FALSE;
  1484. }
  1485. }
  1486. // Handle the arguments now they are in a normal form.
  1487. if (*psig->sg_signature)
  1488. {
  1489. char *arg = psig->sg_signature;
  1490. int a;
  1491. // Allocate the space.
  1492. psig->sg_nrargs = nrcommas + 1;
  1493. if ((psig->sg_args = (pyqt3SigArg *)sipMalloc(sizeof (pyqt3SigArg) * psig->sg_nrargs)) == NULL)
  1494. {
  1495. sipFree(psig);
  1496. return NULL;
  1497. }
  1498. for (a = 0; a < psig->sg_nrargs; ++a)
  1499. {
  1500. parseType(arg, &psig->sg_args[a]);
  1501. // Move to the start of the next argument.
  1502. arg += strlen(arg) + 1;
  1503. }
  1504. }
  1505. }
  1506. // Make a deep copy of the signal.
  1507. strcpy(psig->sg_signature, sig);
  1508. // Add it to the list so it can be re-used.
  1509. psig->sg_next = psig_list;
  1510. psig_list = psig;
  1511. return psig;
  1512. }
  1513. // Parse a single type.
  1514. static void parseType(const char *type, pyqt3SigArg *arg)
  1515. {
  1516. size_t btlen = 0;
  1517. int unsup, isref = FALSE, indir = 0;
  1518. const char *ep;
  1519. pyqt3SigArgType sat = unknown_sat;
  1520. // Find the start of the significant part of the type.
  1521. if (strncmp(type, "const ", 6) == 0)
  1522. type += 6;
  1523. // Find the length of the base type, the number of indirections and if it
  1524. // is a reference.
  1525. for (ep = type; *ep; ++ep)
  1526. if (*ep == '&')
  1527. isref = TRUE;
  1528. else if (*ep == '*')
  1529. ++indir;
  1530. else
  1531. ++btlen;
  1532. // Extract the base type as a separate string.
  1533. char type_str[btlen + 1];
  1534. strncpy(type_str, type, btlen);
  1535. type_str[btlen] = '\0';
  1536. // Resolve any typedef which may mean more indirection.
  1537. type = sipResolveTypedef(type_str);
  1538. // See if we need to make another copy.
  1539. bool copy = false;
  1540. if (type)
  1541. {
  1542. btlen = strlen(type);
  1543. // Remove any additional indirection.
  1544. while (btlen)
  1545. {
  1546. if (type[--btlen] == '*')
  1547. {
  1548. copy = true;
  1549. ++indir;
  1550. }
  1551. }
  1552. }
  1553. else
  1554. type = type_str;
  1555. // Make sure this doesn't go out of scope while it is being used.
  1556. char base_type_str[btlen + 1];
  1557. if (copy)
  1558. {
  1559. // Extract the base type again.
  1560. strncpy(base_type_str, type, btlen);
  1561. base_type_str[btlen] = '\0';
  1562. type = base_type_str;
  1563. }
  1564. // Assume that anything other than a base type is unsupported.
  1565. unsup = (isref || indir);
  1566. // Parse the base type.
  1567. switch (btlen)
  1568. {
  1569. case 3:
  1570. if (strcmp(type, "int") == 0)
  1571. sat = int_sat;
  1572. break;
  1573. case 4:
  1574. if (strcmp(type, "bool") == 0)
  1575. sat = bool_sat;
  1576. else if (strcmp(type, "long") == 0)
  1577. sat = long_sat;
  1578. else if (strcmp(type, "char") == 0)
  1579. {
  1580. sat = (indir ? string_sat : char_sat);
  1581. unsup = (isref || indir > 1);
  1582. }
  1583. else if (strcmp(type, "void") == 0)
  1584. {
  1585. sat = void_sat;
  1586. unsup = (isref || indir != 1);
  1587. }
  1588. break;
  1589. case 5:
  1590. if (strcmp(type, "float") == 0)
  1591. sat = float_sat;
  1592. else if (strcmp(type, "short") == 0)
  1593. sat = short_sat;
  1594. break;
  1595. case 6:
  1596. if (strcmp(type, "double") == 0)
  1597. sat = double_sat;
  1598. break;
  1599. case 7:
  1600. if (strcmp(type, "__int64") == 0)
  1601. sat = longlong_sat;
  1602. else if (strcmp(type, "wchar_t") == 0)
  1603. {
  1604. sat = (indir ? wstring_sat : wchar_sat);
  1605. unsup = (isref || indir > 1);
  1606. }
  1607. break;
  1608. case 8:
  1609. if (strcmp(type, "unsigned") == 0)
  1610. sat = uint_sat;
  1611. else if (strcmp(type, "TQVariant") == 0)
  1612. {
  1613. if (indir == 0)
  1614. {
  1615. sat = qvariant_sat;
  1616. unsup = FALSE;
  1617. }
  1618. else if (indir == 1)
  1619. {
  1620. sat = qvariantp_sat;
  1621. unsup = FALSE;
  1622. }
  1623. }
  1624. break;
  1625. case 9:
  1626. if (strcmp(type, "long long") == 0)
  1627. sat = longlong_sat;
  1628. break;
  1629. case 11:
  1630. if (strcmp(type, "signed char") == 0)
  1631. {
  1632. sat = (indir ? sstring_sat : schar_sat);
  1633. unsup = (isref || indir > 1);
  1634. }
  1635. break;
  1636. case 12:
  1637. if (strcmp(type, "unsigned int") == 0)
  1638. sat = uint_sat;
  1639. break;
  1640. case 13:
  1641. if (strcmp(type, "unsigned long") == 0)
  1642. sat = ulong_sat;
  1643. else if (strcmp(type, "unsigned char") == 0)
  1644. {
  1645. sat = (indir ? ustring_sat : uchar_sat);
  1646. unsup = (isref || indir > 1);
  1647. }
  1648. else if (strcmp(type, "PyTQt_PyObject") == 0 && indir == 0)
  1649. {
  1650. sat = pyobject_sat;
  1651. unsup = FALSE;
  1652. }
  1653. break;
  1654. case 14:
  1655. if (strcmp(type, "unsigned short") == 0)
  1656. sat = ushort_sat;
  1657. break;
  1658. case 16:
  1659. if (strcmp(type, "unsigned __int64") == 0)
  1660. sat = ulonglong_sat;
  1661. break;
  1662. case 18:
  1663. if (strcmp(type, "unsigned long long") == 0)
  1664. sat = ulonglong_sat;
  1665. break;
  1666. }
  1667. if (sat == unknown_sat)
  1668. {
  1669. const sipTypeDef *td = sipFindType(type);
  1670. if (td)
  1671. {
  1672. if (sipTypeIsClass(td))
  1673. {
  1674. if (indir == 0)
  1675. sat = class_sat;
  1676. else if (indir == 1)
  1677. sat = classp_sat;
  1678. arg->u.wt = (sipWrapperType *)sipTypeAsPyTypeObject(td);
  1679. }
  1680. else if (sipTypeIsMapped(td))
  1681. {
  1682. if (indir == 0)
  1683. sat = mtype_sat;
  1684. else if (indir == 1)
  1685. sat = mtypep_sat;
  1686. arg->u.mt = td;
  1687. }
  1688. else if (sipTypeIsEnum(td))
  1689. {
  1690. if (indir == 0)
  1691. sat = enum_sat;
  1692. arg->u.et = sipTypeAsPyTypeObject(td);
  1693. }
  1694. }
  1695. }
  1696. else if (unsup)
  1697. sat = unknown_sat;
  1698. arg->atype = sat;
  1699. }
  1700. // Dispose of a receiver that might be a universal slot.
  1701. static void sipTQtDestroyUniversalSlot(void *rx)
  1702. {
  1703. for (UniversalSlot *us = UniversalSlot::unislots; us; us = us->nextus)
  1704. if (us == reinterpret_cast<TQObject *>(rx))
  1705. {
  1706. delete us;
  1707. break;
  1708. }
  1709. }
  1710. // Search for the universal slot connected to a particular TQt signal.
  1711. static void *sipTQtFindSlot(void *tx, const char *sig, PyObject *rxObj,
  1712. const char *slot, const char **member)
  1713. {
  1714. for (UniversalSlot *us = UniversalSlot::unislots; us; us = us->nextus)
  1715. {
  1716. pyqt3SlotConnection *conn = &us->conn;
  1717. if (conn->sc_transmitter != tx)
  1718. continue;
  1719. if (!sipTQtSameSignalSlotName(conn->sc_signature->sg_signature, sig))
  1720. continue;
  1721. if (sipSameSlot(&conn->sc_slot, rxObj, slot))
  1722. {
  1723. *member = SLOT(unislot());
  1724. return us;
  1725. }
  1726. }
  1727. return 0;
  1728. }
  1729. // Connect a TQt signal to a TQt slot.
  1730. static int sipTQtConnect(void *tx, const char *sig, void *rx, const char *slot, int)
  1731. {
  1732. return TQObject::connect(reinterpret_cast<TQObject *>(tx), sig,
  1733. reinterpret_cast<TQObject *>(rx), slot);
  1734. }
  1735. // Disconnect a TQt signal from a TQt slot.
  1736. static int sipTQtDisconnect(void *tx, const char *sig, void *rx, const char *slot)
  1737. {
  1738. return TQObject::disconnect(reinterpret_cast<TQObject *>(tx), sig,
  1739. reinterpret_cast<TQObject *>(rx), slot);
  1740. }
  1741. // See if two signal or slot names are the same.
  1742. static int sipTQtSameSignalSlotName(const char *s1, const char *s2)
  1743. {
  1744. // moc formats signal names, so we should first convert the supplied
  1745. // string to the same format before comparing them. Instead we just
  1746. // compare them as they are, but ignoring all spaces - this will have
  1747. // the same result.
  1748. do
  1749. {
  1750. // Skip any spaces.
  1751. while (*s1 == ' ')
  1752. ++s1;
  1753. while (*s2 == ' ')
  1754. ++s2;
  1755. if (*s1++ != *s2)
  1756. return 0;
  1757. }
  1758. while (*s2++ != '\0');
  1759. return 1;
  1760. }
  1761. // Return the next slot for a particular transmitter. This will be called with
  1762. // the GIL locked.
  1763. static sipSlot *sipTQtFindSipslot(void *tx, void **context)
  1764. {
  1765. UniversalSlot *us = *reinterpret_cast<UniversalSlot **>(context);
  1766. if (!us)
  1767. us = UniversalSlot::unislots;
  1768. sipSlot *slot = 0;
  1769. while (us)
  1770. {
  1771. pyqt3SlotConnection *this_conn = &us->conn;
  1772. us = us->nextus;
  1773. if (this_conn->sc_transmitter == tx)
  1774. {
  1775. slot = &this_conn->sc_slot;
  1776. break;
  1777. }
  1778. }
  1779. *context = us;
  1780. return slot;
  1781. }
  1782. // Connect a slot from a Python signal.
  1783. static int sipTQtConnectPySignal(PyObject *txObj, const char *sig,
  1784. PyObject *rxObj, const char *slot)
  1785. {
  1786. pyqt3PySig *ps;
  1787. pyqt3SlotList *psrx;
  1788. pyqtWrapper *pw = (pyqtWrapper *)txObj;
  1789. /* Create a new one if necessary. */
  1790. if ((ps = find_py_signal(pw, sig)) == NULL)
  1791. {
  1792. if ((ps = (pyqt3PySig *)sipMalloc(sizeof (pyqt3PySig))) == NULL)
  1793. return -1;
  1794. if ((ps->name = (char *)sipMalloc(strlen(sig) + 1)) == NULL)
  1795. {
  1796. sipFree(ps);
  1797. return -1;
  1798. }
  1799. strcpy(ps->name, sig);
  1800. ps->rxlist = NULL;
  1801. ps->next = pw->pySigList;
  1802. pw->pySigList = ps;
  1803. }
  1804. /* Create the new receiver. */
  1805. if ((psrx = (pyqt3SlotList *)sipMalloc(sizeof (pyqt3SlotList))) == NULL)
  1806. return -1;
  1807. if (sipSaveSlot(&psrx->rx, rxObj, slot) < 0)
  1808. {
  1809. sipFree(psrx);
  1810. return -1;
  1811. }
  1812. psrx->next = ps->rxlist;
  1813. ps->rxlist = psrx;
  1814. return 0;
  1815. }
  1816. // Disconnect a slot from a Python signal.
  1817. static void sipTQtDisconnectPySignal(PyObject *txObj, const char *sig,
  1818. PyObject *rxObj, const char *slot)
  1819. {
  1820. pyqt3PySig *ps;
  1821. if ((ps = find_py_signal((pyqtWrapper *)txObj, sig)) != NULL)
  1822. {
  1823. pyqt3SlotList **psrxp;
  1824. for (psrxp = &ps->rxlist; *psrxp != NULL; psrxp = &(*psrxp)->next)
  1825. {
  1826. pyqt3SlotList *psrx = *psrxp;
  1827. if (sipSameSlot(&psrx->rx, rxObj, slot))
  1828. {
  1829. *psrxp = psrx->next;
  1830. free_slot_list(psrx);
  1831. break;
  1832. }
  1833. }
  1834. }
  1835. }
  1836. // Emit a signal for the sip module.
  1837. static int sipTQtEmitSignal(PyObject *self, const char *sig, PyObject *sigargs)
  1838. {
  1839. return pyqt3EmitSignal(self, sig, sigargs);
  1840. }
  1841. // Emit a Python or TQt signal.
  1842. int pyqt3EmitSignal(PyObject *self, const char *sig, PyObject *sigargs)
  1843. {
  1844. // Don't do anything if signals are blocked. TQt signals would be blocked
  1845. // anyway, but this blocks Python signals as well.
  1846. void *tx = sipGetCppPtr((sipSimpleWrapper *)self, sipType_TQObject);
  1847. if (!tx)
  1848. return 0;
  1849. if (reinterpret_cast<TQObject *>(tx)->signalsBlocked())
  1850. return 0;
  1851. // See if it is a TQt signal.
  1852. if (*sig == '2')
  1853. {
  1854. pyqt3TQtSignal *tab;
  1855. // Search the table.
  1856. for (tab = ((pyqt3ClassTypeDef *)((sipWrapperType *)(self->ob_type))->type)->qt3_emit; tab->st_name != NULL; ++tab)
  1857. {
  1858. const char *sp, *tp;
  1859. bool found;
  1860. // Compare only the base name.
  1861. sp = &sig[1];
  1862. tp = tab->st_name;
  1863. found = true;
  1864. while (*sp != '\0' && *sp != '(' && *tp != '\0')
  1865. if (*sp++ != *tp++)
  1866. {
  1867. found = false;
  1868. break;
  1869. }
  1870. if (found)
  1871. return (*tab->st_emitfunc)((sipSimpleWrapper *)self, sigargs);
  1872. }
  1873. // It wasn't found if we got this far.
  1874. PyErr_Format(PyExc_NameError, "Invalid signal %s", &sig[1]);
  1875. return -1;
  1876. }
  1877. pyqt3PySig *ps = find_py_signal((pyqtWrapper *)self, sig);
  1878. if (ps)
  1879. {
  1880. int rc = 0;
  1881. pyqt3SlotList *rxlist = ps->rxlist;
  1882. // Forget the last TQt sender and remember this one.
  1883. UniversalSlot::lastSender = 0;
  1884. py_sender = self;
  1885. // Apply the arguments to each slot method.
  1886. while (rxlist && rc >= 0)
  1887. {
  1888. pyqt3SlotList *next;
  1889. PyObject *res;
  1890. // We get the next in the list before calling the slot in case the
  1891. // list gets changed by the slot - usually because the slot
  1892. // disconnects itself.
  1893. next = rxlist->next;
  1894. res = sipInvokeSlot(&rxlist->rx, sigargs);
  1895. if (res)
  1896. Py_DECREF(res);
  1897. else
  1898. rc = -1;
  1899. rxlist = next;
  1900. }
  1901. // Forget this as a sender.
  1902. py_sender = NULL;
  1903. return rc;
  1904. }
  1905. return 0;
  1906. }
  1907. // Return the most recent signal sender.
  1908. PyObject *pyqt3GetSender()
  1909. {
  1910. PyObject *sender;
  1911. // If there is a TQt sender then it is more recent than the last Python
  1912. // sender, so use it instead.
  1913. if (UniversalSlot::lastSender)
  1914. {
  1915. sender = sipConvertFromType(UniversalSlot::lastSender, sipType_TQObject,
  1916. NULL);
  1917. }
  1918. else
  1919. {
  1920. sender = (py_sender ? py_sender : Py_None);
  1921. Py_INCREF(sender);
  1922. }
  1923. return sender;
  1924. }
  1925. %End
  1926. %InitialisationCode
  1927. // Initialise the meta-type.
  1928. pyqtWrapperType_Type.tp_base = sipWrapperType_Type;
  1929. if (PyType_Ready(&pyqtWrapperType_Type) < 0)
  1930. Py_FatalError("qt: Failed to initialise pyqtWrapperType type");
  1931. // Register the meta-type.
  1932. if (sipRegisterPyType((PyTypeObject *)&pyqtWrapperType_Type) < 0)
  1933. Py_FatalError("qt: Failed to register pyqtWrapperType type");
  1934. // Initialise the super-type.
  1935. #if PY_VERSION_HEX >= 0x02050000
  1936. pyqtWrapper_Type.super.ht_type.tp_base = sipWrapper_Type;
  1937. #else
  1938. pyqtWrapper_Type.super.type.tp_base = sipWrapper_Type;
  1939. #endif
  1940. if (PyType_Ready((PyTypeObject *)&pyqtWrapper_Type) < 0)
  1941. Py_FatalError("qt: Failed to initialise pyqtWrapper type");
  1942. // Register the super-type.
  1943. if (sipRegisterPyType((PyTypeObject *)&pyqtWrapper_Type) < 0)
  1944. Py_FatalError("qt: Failed to register pyqtWrapper type");
  1945. %End