diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..5ab7695 --- /dev/null +++ b/COPYING @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! + + diff --git a/PythonQt.pro b/PythonQt.pro new file mode 100644 index 0000000..66e19b7 --- /dev/null +++ b/PythonQt.pro @@ -0,0 +1,4 @@ +TEMPLATE = subdirs + +CONFIG += ordered +SUBDIRS = src extensions tests examples diff --git a/README b/README new file mode 100644 index 0000000..26f53c4 --- /dev/null +++ b/README @@ -0,0 +1,18 @@ +PythonQt +-------- + +PythonQt is a dynamic Python (http://www.python.org) binding for Qt (http://www.trolltech.com). +It offers an easy way to embedd the Python scripting language into +your Qt applications. It makes heavy use of the QMetaObject system and thus requires Qt4.x. + +Licensing +--------- +PythonQt is distributed under the LGPL license. + +Documentation +------------- + +More documentation is available at: + +http://pythonqt.sourceforge.net/ + diff --git a/doxygen/createDoc.bat b/doxygen/createDoc.bat new file mode 100644 index 0000000..ac034fb --- /dev/null +++ b/doxygen/createDoc.bat @@ -0,0 +1 @@ +doxygen doc.cfg \ No newline at end of file diff --git a/doxygen/doc.cfg b/doxygen/doc.cfg new file mode 100644 index 0000000..99b0655 --- /dev/null +++ b/doxygen/doc.cfg @@ -0,0 +1,1098 @@ +# Doxyfile 1.3.5 + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project +# +# All text after a hash (#) is considered a comment and will be ignored +# The format is: +# TAG = value [value, ...] +# For lists items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (" ") + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- + +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded +# by quotes) that should identify the project. + +PROJECT_NAME = PythonQt + +# The PROJECT_NUMBER tag can be used to enter a project or revision number. +# This could be handy for archiving the generated documentation or +# if some version control system is used. + +PROJECT_NUMBER = 1.0 + +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) +# base path where the generated documentation will be put. +# If a relative path is entered, it will be relative to the location +# where doxygen was started. If left blank the current directory will be used. + +OUTPUT_DIRECTORY = . + +# The OUTPUT_LANGUAGE tag is used to specify the language in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all constant output in the proper language. +# The default language is English, other supported languages are: +# Brazilian, Catalan, Chinese, Chinese-Traditional, Croatian, Czech, Danish, Dutch, +# Finnish, French, German, Greek, Hungarian, Italian, Japanese, Japanese-en +# (Japanese with English messages), Korean, Norwegian, Polish, Portuguese, +# Romanian, Russian, Serbian, Slovak, Slovene, Spanish, Swedish, and Ukrainian. + +OUTPUT_LANGUAGE = English + +# This tag can be used to specify the encoding used in the generated output. +# The encoding is not always determined by the language that is chosen, +# but also whether or not the output is meant for Windows or non-Windows users. +# In case there is a difference, setting the USE_WINDOWS_ENCODING tag to YES +# forces the Windows encoding (this is the default for the Windows binary), +# whereas setting the tag to NO uses a Unix-style encoding (the default for +# all platforms other than Windows). + +USE_WINDOWS_ENCODING = NO + +# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will +# include brief member descriptions after the members that are listed in +# the file and class documentation (similar to JavaDoc). +# Set to NO to disable this. + +BRIEF_MEMBER_DESC = YES + +# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend +# the brief description of a member or function before the detailed description. +# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# brief descriptions will be completely suppressed. + +REPEAT_BRIEF = YES + +# This tag implements a quasi-intelligent brief description abbreviator +# that is used to form the text in various listings. Each string +# in this list, if found as the leading text of the brief description, will be +# stripped from the text and the result after processing the whole list, is used +# as the annotated text. Otherwise, the brief description is used as-is. If left +# blank, the following values are used ("$name" is automatically replaced with the +# name of the entity): "The $name class" "The $name widget" "The $name file" +# "is" "provides" "specifies" "contains" "represents" "a" "an" "the" + +ABBREVIATE_BRIEF = + +# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then +# Doxygen will generate a detailed section even if there is only a brief +# description. + +ALWAYS_DETAILED_SEC = NO + +# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all inherited +# members of a class in the documentation of that class as if those members were +# ordinary class members. Constructors, destructors and assignment operators of +# the base classes will not be shown. + +INLINE_INHERITED_MEMB = NO + +# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full +# path before files name in the file list and in the header files. If set +# to NO the shortest path that makes the file name unique will be used. + +FULL_PATH_NAMES = NO + +# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag +# can be used to strip a user-defined part of the path. Stripping is +# only done if one of the specified strings matches the left-hand part of +# the path. It is allowed to use relative paths in the argument list. + +STRIP_FROM_PATH = + +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter +# (but less readable) file names. This can be useful is your file systems +# doesn't support long names like on DOS, Mac, or CD-ROM. + +SHORT_NAMES = NO + +# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen +# will interpret the first line (until the first dot) of a JavaDoc-style +# comment as the brief description. If set to NO, the JavaDoc +# comments will behave just like the Qt-style comments (thus requiring an +# explicit @brief command for a brief description. + +JAVADOC_AUTOBRIEF = NO + +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen +# treat a multi-line C++ special comment block (i.e. a block of //! or /// +# comments) as a brief description. This used to be the default behaviour. +# The new default is to treat a multi-line C++ comment block as a detailed +# description. Set this tag to YES if you prefer the old behaviour instead. + +MULTILINE_CPP_IS_BRIEF = NO + +# If the DETAILS_AT_TOP tag is set to YES then Doxygen +# will output the detailed description near the top, like JavaDoc. +# If set to NO, the detailed description appears after the member +# documentation. + +DETAILS_AT_TOP = NO + +# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented +# member inherits the documentation from any documented member that it +# re-implements. + +INHERIT_DOCS = YES + +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES, then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default +# all members of a group must be documented explicitly. + +DISTRIBUTE_GROUP_DOC = NO + +# The TAB_SIZE tag can be used to set the number of spaces in a tab. +# Doxygen uses this value to replace tabs by spaces in code fragments. + +TAB_SIZE = 4 + +# This tag can be used to specify a number of aliases that acts +# as commands in the documentation. An alias has the form "name=value". +# For example adding "sideeffect=\par Side Effects:\n" will allow you to +# put the command \sideeffect (or @sideeffect) in the documentation, which +# will result in a user-defined paragraph with heading "Side Effects:". +# You can put \n's in the value part of an alias to insert newlines. + +ALIASES = + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources +# only. Doxygen will then generate output that is more tailored for C. +# For instance, some of the names that are used will be different. The list +# of all members will be omitted, etc. + +OPTIMIZE_OUTPUT_FOR_C = NO + +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java sources +# only. Doxygen will then generate output that is more tailored for Java. +# For instance, namespaces will be presented as packages, qualified scopes +# will look different, etc. + +OPTIMIZE_OUTPUT_JAVA = NO + +# Set the SUBGROUPING tag to YES (the default) to allow class member groups of +# the same type (for instance a group of public functions) to be put as a +# subgroup of that type (e.g. under the Public Functions section). Set it to +# NO to prevent subgrouping. Alternatively, this can be done per class using +# the \nosubgrouping command. + +SUBGROUPING = YES + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- + +# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in +# documentation are documented, even if no documentation was available. +# Private class members and static file members will be hidden unless +# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES + +EXTRACT_ALL = YES + +# If the EXTRACT_PRIVATE tag is set to YES all private members of a class +# will be included in the documentation. + +EXTRACT_PRIVATE = NO + +# If the EXTRACT_STATIC tag is set to YES all static members of a file +# will be included in the documentation. + +EXTRACT_STATIC = YES + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) +# defined locally in source files will be included in the documentation. +# If set to NO only classes defined in header files are included. + +EXTRACT_LOCAL_CLASSES = YES + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all +# undocumented members of documented classes, files or namespaces. +# If set to NO (the default) these members will be included in the +# various overviews, but no documentation section is generated. +# This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_MEMBERS = NO + +# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. +# If set to NO (the default) these classes will be included in the various +# overviews. This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_CLASSES = NO + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all +# friend (class|struct|union) declarations. +# If set to NO (the default) these declarations will be included in the +# documentation. + +HIDE_FRIEND_COMPOUNDS = NO + +# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any +# documentation blocks found inside the body of a function. +# If set to NO (the default) these blocks will be appended to the +# function's detailed documentation block. + +HIDE_IN_BODY_DOCS = NO + +# The INTERNAL_DOCS tag determines if documentation +# that is typed after a \internal command is included. If the tag is set +# to NO (the default) then the documentation will be excluded. +# Set it to YES to include the internal documentation. + +INTERNAL_DOCS = NO + +# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate +# file names in lower-case letters. If set to YES upper-case letters are also +# allowed. This is useful if you have classes or files whose names only differ +# in case and if your file system supports case sensitive file names. Windows +# users are advised to set this option to NO. + +CASE_SENSE_NAMES = YES + +# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen +# will show members with their full class and namespace scopes in the +# documentation. If set to YES the scope will be hidden. + +HIDE_SCOPE_NAMES = NO + +# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen +# will put a list of the files that are included by a file in the documentation +# of that file. + +SHOW_INCLUDE_FILES = YES + +# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] +# is inserted in the documentation for inline members. + +INLINE_INFO = YES + +# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen +# will sort the (detailed) documentation of file and class members +# alphabetically by member name. If set to NO the members will appear in +# declaration order. + +SORT_MEMBER_DOCS = YES + +# The GENERATE_TODOLIST tag can be used to enable (YES) or +# disable (NO) the todo list. This list is created by putting \todo +# commands in the documentation. + +GENERATE_TODOLIST = NO + +# The GENERATE_TESTLIST tag can be used to enable (YES) or +# disable (NO) the test list. This list is created by putting \test +# commands in the documentation. + +GENERATE_TESTLIST = NO + +# The GENERATE_BUGLIST tag can be used to enable (YES) or +# disable (NO) the bug list. This list is created by putting \bug +# commands in the documentation. + +GENERATE_BUGLIST = YES + +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or +# disable (NO) the deprecated list. This list is created by putting +# \deprecated commands in the documentation. + +GENERATE_DEPRECATEDLIST= YES + +# The ENABLED_SECTIONS tag can be used to enable conditional +# documentation sections, marked by \if sectionname ... \endif. + +ENABLED_SECTIONS = sourceonly + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines +# the initial value of a variable or define consists of for it to appear in +# the documentation. If the initializer consists of more lines than specified +# here it will be hidden. Use a value of 0 to hide initializers completely. +# The appearance of the initializer of individual variables and defines in the +# documentation can be controlled using \showinitializer or \hideinitializer +# command in the documentation regardless of this setting. + +MAX_INITIALIZER_LINES = 30 + +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated +# at the bottom of the documentation of classes and structs. If set to YES the +# list will mention the files that were used to generate the documentation. + +SHOW_USED_FILES = YES + +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- + +# The QUIET tag can be used to turn on/off the messages that are generated +# by doxygen. Possible values are YES and NO. If left blank NO is used. + +QUIET = YES + +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated by doxygen. Possible values are YES and NO. If left blank +# NO is used. + +WARNINGS = YES + +# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings +# for undocumented members. If EXTRACT_ALL is set to YES then this flag will +# automatically be disabled. + +WARN_IF_UNDOCUMENTED = YES + +# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as not documenting some +# parameters in a documented function, or documenting parameters that +# don't exist or using markup commands wrongly. + +WARN_IF_DOC_ERROR = YES + +# The WARN_FORMAT tag determines the format of the warning messages that +# doxygen can produce. The string should contain the $file, $line, and $text +# tags, which will be replaced by the file and line number from which the +# warning originated and the warning text. + +WARN_FORMAT = "$file:$line: $text" + +# The WARN_LOGFILE tag can be used to specify a file to which warning +# and error messages should be written. If left blank the output is written +# to stderr. + +WARN_LOGFILE = doxygen.log + +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- + +# The INPUT tag can be used to specify the files and/or directories that contain +# documented source files. You may enter file names like "myfile.cpp" or +# directories like "/usr/src/myproject". Separate the files or directories +# with spaces. + +INPUT = ../src + +# If the value of the INPUT tag contains directories, you can use the +# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank the following patterns are tested: +# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx *.hpp +# *.h++ *.idl *.odl *.cs *.php *.php3 *.inc + +FILE_PATTERNS = *.h + +# The RECURSIVE tag can be used to turn specify whether or not subdirectories +# should be searched for input files as well. Possible values are YES and NO. +# If left blank NO is used. + +RECURSIVE = NO + +# The EXCLUDE tag can be used to specify files and/or directories that should +# excluded from the INPUT source files. This way you can easily exclude a +# subdirectory from a directory tree whose root is specified with the INPUT tag. + +EXCLUDE = + +# The EXCLUDE_SYMLINKS tag can be used select whether or not files or directories +# that are symbolic links (a Unix filesystem feature) are excluded from the input. + +EXCLUDE_SYMLINKS = NO + +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude +# certain files from those directories. + +EXCLUDE_PATTERNS = + +# The EXAMPLE_PATH tag can be used to specify one or more files or +# directories that contain example code fragments that are included (see +# the \include command). + +EXAMPLE_PATH = + +# If the value of the EXAMPLE_PATH tag contains directories, you can use the +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank all files are included. + +EXAMPLE_PATTERNS = + +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude +# commands irrespective of the value of the RECURSIVE tag. +# Possible values are YES and NO. If left blank NO is used. + +EXAMPLE_RECURSIVE = NO + +# The IMAGE_PATH tag can be used to specify one or more files or +# directories that contain image that are included in the documentation (see +# the \image command). + +IMAGE_PATH = + +# The INPUT_FILTER tag can be used to specify a program that doxygen should +# invoke to filter for each input file. Doxygen will invoke the filter program +# by executing (via popen()) the command , where +# is the value of the INPUT_FILTER tag, and is the name of an +# input file. Doxygen will then use the output that the filter program writes +# to standard output. + +INPUT_FILTER = + +# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using +# INPUT_FILTER) will be used to filter the input files when producing source +# files to browse (i.e. when SOURCE_BROWSER is set to YES). + +FILTER_SOURCE_FILES = NO + +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- + +# If the SOURCE_BROWSER tag is set to YES then a list of source files will +# be generated. Documented entities will be cross-referenced with these sources. +# Note: To get rid of all source code in the generated output, make sure also +# VERBATIM_HEADERS is set to NO. + +SOURCE_BROWSER = YES + +# Setting the INLINE_SOURCES tag to YES will include the body +# of functions and classes directly in the documentation. + +INLINE_SOURCES = YES + +# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct +# doxygen to hide any special comment blocks from generated source code +# fragments. Normal C and C++ comments will always remain visible. + +STRIP_CODE_COMMENTS = YES + +# If the REFERENCED_BY_RELATION tag is set to YES (the default) +# then for each documented function all documented +# functions referencing it will be listed. + +REFERENCED_BY_RELATION = YES + +# If the REFERENCES_RELATION tag is set to YES (the default) +# then for each documented function all documented entities +# called/used by that function will be listed. + +REFERENCES_RELATION = YES + +# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen +# will generate a verbatim copy of the header file for each class for +# which an include is specified. Set to NO to disable this. + +VERBATIM_HEADERS = YES + +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- + +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index +# of all compounds will be generated. Enable this if the project +# contains a lot of classes, structs, unions or interfaces. + +ALPHABETICAL_INDEX = YES + +# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then +# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns +# in which this list will be split (can be a number in the range [1..20]) + +COLS_IN_ALPHA_INDEX = 5 + +# In case all classes in a project start with a common prefix, all +# classes will be put under the same header in the alphabetical index. +# The IGNORE_PREFIX tag can be used to specify one or more prefixes that +# should be ignored while generating the index headers. + +IGNORE_PREFIX = PythonQt + +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- + +# If the GENERATE_HTML tag is set to YES (the default) Doxygen will +# generate HTML output. + +GENERATE_HTML = YES + +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `html' will be used as the default path. + +HTML_OUTPUT = html + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for +# each generated HTML page (for example: .htm,.php,.asp). If it is left blank +# doxygen will generate files with .html extension. + +HTML_FILE_EXTENSION = .html + +# The HTML_HEADER tag can be used to specify a personal HTML header for +# each generated HTML page. If it is left blank doxygen will generate a +# standard header. + +HTML_HEADER = header.html + +# The HTML_FOOTER tag can be used to specify a personal HTML footer for +# each generated HTML page. If it is left blank doxygen will generate a +# standard footer. + +HTML_FOOTER = + +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading +# style sheet that is used by each HTML page. It can be used to +# fine-tune the look of the HTML output. If the tag is left blank doxygen +# will generate a default style sheet. Note that doxygen will try to copy +# the style sheet file to the HTML output directory, so don't put your own +# stylesheet in the HTML output directory as well, or it will be erased! + +HTML_STYLESHEET = + +# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, +# files or namespaces will be aligned in HTML using tables. If set to +# NO a bullet list will be used. + +HTML_ALIGN_MEMBERS = YES + +# If the GENERATE_HTMLHELP tag is set to YES, additional index files +# will be generated that can be used as input for tools like the +# Microsoft HTML help workshop to generate a compressed HTML help file (.chm) +# of the generated HTML documentation. + +GENERATE_HTMLHELP = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can +# be used to specify the file name of the resulting .chm file. You +# can add a path in front of the file if the result should not be +# written to the html output directory. + +CHM_FILE = + +# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can +# be used to specify the location (absolute path including file name) of +# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run +# the HTML help compiler on the generated index.hhp. + +HHC_LOCATION = + +# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag +# controls if a separate .chi index file is generated (YES) or that +# it should be included in the master .chm file (NO). + +GENERATE_CHI = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag +# controls whether a binary table of contents is generated (YES) or a +# normal table of contents (NO) in the .chm file. + +BINARY_TOC = NO + +# The TOC_EXPAND flag can be set to YES to add extra items for group members +# to the contents of the HTML help documentation and to the tree view. + +TOC_EXPAND = NO + +# The DISABLE_INDEX tag can be used to turn on/off the condensed index at +# top of each HTML page. The value NO (the default) enables the index and +# the value YES disables it. + +DISABLE_INDEX = NO + +# This tag can be used to set the number of enum values (range [1..20]) +# that doxygen will group on one line in the generated HTML documentation. + +ENUM_VALUES_PER_LINE = 4 + +# If the GENERATE_TREEVIEW tag is set to YES, a side panel will be +# generated containing a tree-like index structure (just like the one that +# is generated for HTML Help). For this to work a browser that supports +# JavaScript, DHTML, CSS and frames is required (for instance Mozilla 1.0+, +# Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are +# probably better off using the HTML help feature. + +GENERATE_TREEVIEW = NO + +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be +# used to set the initial width (in pixels) of the frame in which the tree +# is shown. + +TREEVIEW_WIDTH = 250 + +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- + +# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will +# generate Latex output. + +GENERATE_LATEX = NO + +# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `latex' will be used as the default path. + +LATEX_OUTPUT = latex + +# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be +# invoked. If left blank `latex' will be used as the default command name. + +LATEX_CMD_NAME = latex + +# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to +# generate index for LaTeX. If left blank `makeindex' will be used as the +# default command name. + +MAKEINDEX_CMD_NAME = makeindex + +# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact +# LaTeX documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_LATEX = NO + +# The PAPER_TYPE tag can be used to set the paper type that is used +# by the printer. Possible values are: a4, a4wide, letter, legal and +# executive. If left blank a4wide will be used. + +PAPER_TYPE = a4wide + +# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX +# packages that should be included in the LaTeX output. + +EXTRA_PACKAGES = + +# The LATEX_HEADER tag can be used to specify a personal LaTeX header for +# the generated latex document. The header should contain everything until +# the first chapter. If it is left blank doxygen will generate a +# standard header. Notice: only use this tag if you know what you are doing! + +LATEX_HEADER = + +# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated +# is prepared for conversion to pdf (using ps2pdf). The pdf file will +# contain links (just like the HTML output) instead of page references +# This makes the output suitable for online browsing using a pdf viewer. + +PDF_HYPERLINKS = NO + +# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of +# plain latex in the generated Makefile. Set this option to YES to get a +# higher quality PDF documentation. + +USE_PDFLATEX = NO + +# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. +# command to the generated LaTeX files. This will instruct LaTeX to keep +# running if errors occur, instead of asking the user for help. +# This option is also used when generating formulas in HTML. + +LATEX_BATCHMODE = NO + +# If LATEX_HIDE_INDICES is set to YES then doxygen will not +# include the index chapters (such as File Index, Compound Index, etc.) +# in the output. + +LATEX_HIDE_INDICES = NO + +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- + +# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output +# The RTF output is optimized for Word 97 and may not look very pretty with +# other RTF readers or editors. + +GENERATE_RTF = NO + +# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `rtf' will be used as the default path. + +RTF_OUTPUT = rtf + +# If the COMPACT_RTF tag is set to YES Doxygen generates more compact +# RTF documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_RTF = NO + +# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated +# will contain hyperlink fields. The RTF file will +# contain links (just like the HTML output) instead of page references. +# This makes the output suitable for online browsing using WORD or other +# programs which support those fields. +# Note: wordpad (write) and others do not support links. + +RTF_HYPERLINKS = NO + +# Load stylesheet definitions from file. Syntax is similar to doxygen's +# config file, i.e. a series of assignments. You only have to provide +# replacements, missing definitions are set to their default value. + +RTF_STYLESHEET_FILE = + +# Set optional variables used in the generation of an rtf document. +# Syntax is similar to doxygen's config file. + +RTF_EXTENSIONS_FILE = + +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- + +# If the GENERATE_MAN tag is set to YES (the default) Doxygen will +# generate man pages + +GENERATE_MAN = NO + +# The MAN_OUTPUT tag is used to specify where the man pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `man' will be used as the default path. + +MAN_OUTPUT = man + +# The MAN_EXTENSION tag determines the extension that is added to +# the generated man pages (default is the subroutine's section .3) + +MAN_EXTENSION = .3 + +# If the MAN_LINKS tag is set to YES and Doxygen generates man output, +# then it will generate one additional man file for each entity +# documented in the real man page(s). These additional files +# only source the real man page, but without them the man command +# would be unable to find the correct page. The default is NO. + +MAN_LINKS = NO + +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- + +# If the GENERATE_XML tag is set to YES Doxygen will +# generate an XML file that captures the structure of +# the code including all documentation. + +GENERATE_XML = NO + +# The XML_OUTPUT tag is used to specify where the XML pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `xml' will be used as the default path. + +XML_OUTPUT = xml + +# The XML_SCHEMA tag can be used to specify an XML schema, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_SCHEMA = + +# The XML_DTD tag can be used to specify an XML DTD, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_DTD = + +# If the XML_PROGRAMLISTING tag is set to YES Doxygen will +# dump the program listings (including syntax highlighting +# and cross-referencing information) to the XML output. Note that +# enabling this will significantly increase the size of the XML output. + +XML_PROGRAMLISTING = YES + +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- + +# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will +# generate an AutoGen Definitions (see autogen.sf.net) file +# that captures the structure of the code including all +# documentation. Note that this feature is still experimental +# and incomplete at the moment. + +GENERATE_AUTOGEN_DEF = NO + +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- + +# If the GENERATE_PERLMOD tag is set to YES Doxygen will +# generate a Perl module file that captures the structure of +# the code including all documentation. Note that this +# feature is still experimental and incomplete at the +# moment. + +GENERATE_PERLMOD = NO + +# If the PERLMOD_LATEX tag is set to YES Doxygen will generate +# the necessary Makefile rules, Perl scripts and LaTeX code to be able +# to generate PDF and DVI output from the Perl module output. + +PERLMOD_LATEX = NO + +# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be +# nicely formatted so it can be parsed by a human reader. This is useful +# if you want to understand what is going on. On the other hand, if this +# tag is set to NO the size of the Perl module output will be much smaller +# and Perl will parse it just the same. + +PERLMOD_PRETTY = YES + +# The names of the make variables in the generated doxyrules.make file +# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. +# This is useful so different doxyrules.make files included by the same +# Makefile don't overwrite each other's variables. + +PERLMOD_MAKEVAR_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- + +# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will +# evaluate all C-preprocessor directives found in the sources and include +# files. + +ENABLE_PREPROCESSING = YES + +# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro +# names in the source code. If set to NO (the default) only conditional +# compilation will be performed. Macro expansion can be done in a controlled +# way by setting EXPAND_ONLY_PREDEF to YES. + +MACRO_EXPANSION = YES + +# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES +# then the macro expansion is limited to the macros specified with the +# PREDEFINED and EXPAND_AS_PREDEFINED tags. + +EXPAND_ONLY_PREDEF = YES + +# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files +# in the INCLUDE_PATH (see below) will be search if a #include is found. + +SEARCH_INCLUDES = YES + +# The INCLUDE_PATH tag can be used to specify one or more directories that +# contain include files that are not input files but should be processed by +# the preprocessor. + +INCLUDE_PATH = $(QTDIR)/include + +# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard +# patterns (like *.h and *.hpp) to filter out the header-files in the +# directories. If left blank, the patterns specified with FILE_PATTERNS will +# be used. + +INCLUDE_FILE_PATTERNS = *.h + +# The PREDEFINED tag can be used to specify one or more macro names that +# are defined before the preprocessor is started (similar to the -D option of +# gcc). The argument of the tag is a list of macros of the form: name +# or name=definition (no spaces). If the definition and the = are +# omitted =1 is assumed. + +PREDEFINED = + +# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then +# this tag can be used to specify a list of macro names that should be expanded. +# The macro definition that is found in the sources will be used. +# Use the PREDEFINED tag if you want to use a different macro definition. + +EXPAND_AS_DEFINED = + +# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then +# doxygen's preprocessor will remove all function-like macros that are alone +# on a line, have an all uppercase name, and do not end with a semicolon. Such +# function macros are typically used for boiler-plate code, and will confuse the +# parser if not removed. + +SKIP_FUNCTION_MACROS = YES + +#--------------------------------------------------------------------------- +# Configuration::addtions related to external references +#--------------------------------------------------------------------------- + +# The TAGFILES option can be used to specify one or more tagfiles. +# Optionally an initial location of the external documentation +# can be added for each tagfile. The format of a tag file without +# this location is as follows: +# TAGFILES = file1 file2 ... +# Adding location for the tag files is done as follows: +# TAGFILES = file1=loc1 "file2 = loc2" ... +# where "loc1" and "loc2" can be relative or absolute paths or +# URLs. If a location is present for each tag, the installdox tool +# does not have to be run to correct the links. +# Note that each tag file must have a unique name +# (where the name does NOT include the path) +# If a tag file is not located in the directory in which doxygen +# is run, you must also specify the path to the tagfile here. + +TAGFILES = + +# When a file name is specified after GENERATE_TAGFILE, doxygen will create +# a tag file that is based on the input files it reads. + +GENERATE_TAGFILE = + +# If the ALLEXTERNALS tag is set to YES all external classes will be listed +# in the class index. If set to NO only the inherited external classes +# will be listed. + +ALLEXTERNALS = NO + +# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed +# in the modules index. If set to NO, only the current project's groups will +# be listed. + +EXTERNAL_GROUPS = YES + +# The PERL_PATH should be the absolute path and name of the perl script +# interpreter (i.e. the result of `which perl'). + +PERL_PATH = /usr/bin/perl + +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- + +# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will +# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base or +# super classes. Setting the tag to NO turns the diagrams off. Note that this +# option is superseded by the HAVE_DOT option below. This is only a fallback. It is +# recommended to install and use dot, since it yields more powerful graphs. + +CLASS_DIAGRAMS = YES + +# If set to YES, the inheritance and collaboration graphs will hide +# inheritance and usage relations if the target is undocumented +# or is not a class. + +HIDE_UNDOC_RELATIONS = YES + +# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is +# available from the path. This tool is part of Graphviz, a graph visualization +# toolkit from AT&T and Lucent Bell Labs. The other options in this section +# have no effect if this option is set to NO (the default) + +HAVE_DOT = NO + +# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect inheritance relations. Setting this tag to YES will force the +# the CLASS_DIAGRAMS tag to NO. + +CLASS_GRAPH = YES + +# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect implementation dependencies (inheritance, containment, and +# class references variables) of the class with other documented classes. + +COLLABORATION_GRAPH = YES + +# If the UML_LOOK tag is set to YES doxygen will generate inheritance and +# collaboration diagrams in a style similar to the OMG's Unified Modeling +# Language. + +UML_LOOK = NO + +# If set to YES, the inheritance and collaboration graphs will show the +# relations between templates and their instances. + +TEMPLATE_RELATIONS = NO + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT +# tags are set to YES then doxygen will generate a graph for each documented +# file showing the direct and indirect include dependencies of the file with +# other documented files. + +INCLUDE_GRAPH = YES + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and +# HAVE_DOT tags are set to YES then doxygen will generate a graph for each +# documented header file showing the documented files that directly or +# indirectly include this file. + +INCLUDED_BY_GRAPH = YES + +# If the CALL_GRAPH and HAVE_DOT tags are set to YES then doxygen will +# generate a call dependency graph for every global function or class method. +# Note that enabling this option will significantly increase the time of a run. +# So in most cases it will be better to enable call graphs for selected +# functions only using the \callgraph command. + +CALL_GRAPH = NO + +# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen +# will graphical hierarchy of all classes instead of a textual one. + +GRAPHICAL_HIERARCHY = YES + +# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images +# generated by dot. Possible values are png, jpg, or gif +# If left blank png will be used. + +DOT_IMAGE_FORMAT = png + +# The tag DOT_PATH can be used to specify the path where the dot tool can be +# found. If left blank, it is assumed the dot tool can be found on the path. + +DOT_PATH = + +# The DOTFILE_DIRS tag can be used to specify one or more directories that +# contain dot files that are included in the documentation (see the +# \dotfile command). + +DOTFILE_DIRS = + +# The MAX_DOT_GRAPH_WIDTH tag can be used to set the maximum allowed width +# (in pixels) of the graphs generated by dot. If a graph becomes larger than +# this value, doxygen will try to truncate the graph, so that it fits within +# the specified constraint. Beware that most browsers cannot cope with very +# large images. + +MAX_DOT_GRAPH_WIDTH = 1024 + +# The MAX_DOT_GRAPH_HEIGHT tag can be used to set the maximum allows height +# (in pixels) of the graphs generated by dot. If a graph becomes larger than +# this value, doxygen will try to truncate the graph, so that it fits within +# the specified constraint. Beware that most browsers cannot cope with very +# large images. + +MAX_DOT_GRAPH_HEIGHT = 1024 + +# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the +# graphs generated by dot. A depth value of 3 means that only nodes reachable +# from the root by following a path via at most 3 edges will be shown. Nodes that +# lay further from the root node will be omitted. Note that setting this option to +# 1 or 2 may greatly reduce the computation time needed for large code bases. Also +# note that a graph may be further truncated if the graph's image dimensions are +# not sufficient to fit the graph (see MAX_DOT_GRAPH_WIDTH and MAX_DOT_GRAPH_HEIGHT). +# If 0 is used for the depth value (the default), the graph is not depth-constrained. + +MAX_DOT_GRAPH_DEPTH = 0 + +# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will +# generate a legend page explaining the meaning of the various boxes and +# arrows in the dot generated graphs. + +GENERATE_LEGEND = YES + +# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will +# remove the intermediate dot files that are used to generate +# the various graphs. + +DOT_CLEANUP = YES + +#--------------------------------------------------------------------------- +# Configuration::addtions related to the search engine +#--------------------------------------------------------------------------- + +# The SEARCHENGINE tag specifies whether or not a search engine should be +# used. If set to NO the values of all tags below this one will be ignored. + +SEARCHENGINE = NO diff --git a/doxygen/header.html b/doxygen/header.html new file mode 100644 index 0000000..7ff31a5 --- /dev/null +++ b/doxygen/header.html @@ -0,0 +1,7 @@ + + +$title + + + +
SourceForge.net Logo
diff --git a/examples/PyCPPWrapperExample/CustomObjects.cpp b/examples/PyCPPWrapperExample/CustomObjects.cpp new file mode 100644 index 0000000..27e088e --- /dev/null +++ b/examples/PyCPPWrapperExample/CustomObjects.cpp @@ -0,0 +1,43 @@ +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file CustomObjects.cpp +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2007-4 +*/ +//---------------------------------------------------------------------------------- + +#include "CustomObjects.h" + diff --git a/examples/PyCPPWrapperExample/CustomObjects.h b/examples/PyCPPWrapperExample/CustomObjects.h new file mode 100644 index 0000000..9017346 --- /dev/null +++ b/examples/PyCPPWrapperExample/CustomObjects.h @@ -0,0 +1,149 @@ +#ifndef _PYCUSTOMOBJECTS_H +#define _PYCUSTOMOBJECTS_H + +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file CustomObjects.h +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2007-4 +*/ +//---------------------------------------------------------------------------------- + +#include "PythonQt.h" +#include "PythonQtCppWrapperFactory.h" +#include + + +// declare our own custom object +class CustomObject { +public: + CustomObject() {} + CustomObject(const QString& first, const QString& last) { _firstName = first; _lastName = last; } + + QString _firstName; + QString _lastName; + +}; + + +// add a decorator that allows to access the CustomObject from PythonQt +class CustomObjectWrapper : public QObject { + + Q_OBJECT + +public slots: + // add a constructor + CustomObject* new_CustomObject(const QString& first, const QString& last) { return new CustomObject(first, last); } + + // add a destructor + void delete_CustomObject(CustomObject* o) { delete o; } + + // add access methods + QString firstName(CustomObject* o) { return o->_firstName; } + + QString lastName(CustomObject* o) { return o->_lastName; } + + void setFirstName(CustomObject* o, const QString& name) { o->_firstName = name; } + + void setLastName(CustomObject* o, const QString& name) { o->_lastName = name; } + +}; + + +//------------------------------------------------------------------------------------------------ +// alternative: we create a wrapper factory, which creates a wrapper object for each CPP instance: +//------------------------------------------------------------------------------------------------ + +// declare our own custom object +class CustomObject2 { +public: + CustomObject2() {} + CustomObject2(const QString& first, const QString& last) { _firstName = first; _lastName = last; } + + QString _firstName; + QString _lastName; + +}; + + +// add a decorator that allows to access the CustomObject from PythonQt +class CustomObject2Wrapper : public QObject { + + Q_OBJECT + +public: + CustomObject2Wrapper(CustomObject2* obj) { _ptr = obj; } + +public slots: + // add access methods + QString firstName() { return _ptr->_firstName; } + + QString lastName() { return _ptr->_lastName; } + + void setFirstName(const QString& name) { _ptr->_firstName = name; } + + void setLastName(const QString& name) { _ptr->_lastName = name; } + +private: + CustomObject2* _ptr; +}; + +// additional constructor/destructor for CustomObject2 (optional) +class CustomObject2Constructor : public QObject { + + Q_OBJECT + +public slots: + // add a constructor + CustomObject2* new_CustomObject2(const QString& first, const QString& last) { return new CustomObject2(first, last); } + + // add a destructor + void delete_CustomObject2(CustomObject2* o) { delete o; } +}; + +// a factory that can create wrappers for CustomObject2 +class CustomFactory : public PythonQtCppWrapperFactory +{ +public: + virtual QObject* create(const QByteArray& name, void *ptr) { + if (name == "CustomObject2") { + return new CustomObject2Wrapper((CustomObject2*)ptr); + } + return NULL; + } +}; + +#endif diff --git a/examples/PyCPPWrapperExample/PyCPPWrapperExample.bat b/examples/PyCPPWrapperExample/PyCPPWrapperExample.bat new file mode 100644 index 0000000..6137e59 --- /dev/null +++ b/examples/PyCPPWrapperExample/PyCPPWrapperExample.bat @@ -0,0 +1,2 @@ +"%MEVIS_LIB%\make\win32\createDsp.bat" PyCPPWrapperExample + diff --git a/examples/PyCPPWrapperExample/PyCPPWrapperExample.pro b/examples/PyCPPWrapperExample/PyCPPWrapperExample.pro new file mode 100644 index 0000000..63ed090 --- /dev/null +++ b/examples/PyCPPWrapperExample/PyCPPWrapperExample.pro @@ -0,0 +1,22 @@ +# --------- PyCPPWrapperExample profile ------------------- +# Last changed by $Author: florian $ +# $Id: PythonQt.pro 35381 2006-03-16 13:05:52Z florian $ +# $Source$ +# -------------------------------------------------- + +TARGET = PyCPPWrapperExample +TEMPLATE = app + +DESTDIR = ../../lib + +include ( ../../build/common.prf ) +include ( ../../build/PythonQt.prf ) + +HEADERS += \ + CustomObjects.h + +SOURCES += \ + main.cpp \ + CustomObjects.cpp + +RESOURCES += PyCPPWrapperExample.qrc diff --git a/examples/PyCPPWrapperExample/PyCPPWrapperExample.qrc b/examples/PyCPPWrapperExample/PyCPPWrapperExample.qrc new file mode 100644 index 0000000..0e28080 --- /dev/null +++ b/examples/PyCPPWrapperExample/PyCPPWrapperExample.qrc @@ -0,0 +1,5 @@ + + + example.py + + diff --git a/examples/PyCPPWrapperExample/example.py b/examples/PyCPPWrapperExample/example.py new file mode 100644 index 0000000..e31da13 --- /dev/null +++ b/examples/PyCPPWrapperExample/example.py @@ -0,0 +1,38 @@ +from PythonQt import * + +print "alternative 1 : CustomObject wrapped by decorators" + +# create a new object +custom = CustomObject("John","Doe") + +# print the object (to see how it is wrapped) +print custom + +# print the methods available +print dir(custom) + +# set a name +custom.setFirstName("Mike") +custom.setLastName("Michels") + +# get the name +print custom.firstName() + " " + custom.lastName(); + +print +print "alternative 2 : CustomObject2 wrapped by factory" + +# create a new object +custom2 = CustomObject2("John","Doe") + +# print the object (to see how it is wrapped) +print custom2 + +# print the methods available +print dir(custom2) + +# set a name +custom2.setFirstName("Mike") +custom2.setLastName("Michels") + +# get the name +print custom2.firstName() + " " + custom2.lastName(); diff --git a/examples/PyCPPWrapperExample/main.cpp b/examples/PyCPPWrapperExample/main.cpp new file mode 100644 index 0000000..57dbc98 --- /dev/null +++ b/examples/PyCPPWrapperExample/main.cpp @@ -0,0 +1,86 @@ +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PyGuiExample.cpp +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2007-04 +*/ +//---------------------------------------------------------------------------------- + +#include "PythonQt.h" +#include "gui/PythonQtScriptingConsole.h" +#include "CustomObjects.h" + +#include + +int main( int argc, char **argv ) +{ + QApplication qapp(argc, argv); + + PythonQt::init(PythonQt::IgnoreSiteModule | PythonQt::RedirectStdOut); + + PythonQtObjectPtr mainContext = PythonQt::self()->getMainModule(); + PythonQtScriptingConsole console(NULL, mainContext); + + // ----------------------------------------------------------------- + // Alternative 1: make CustomObject known and use decorators for wrapping: + // ----------------------------------------------------------------- + + // register the new object as a known classname + PythonQt::self()->registerCPPClassNames(QStringList() << "CustomObject"); + // add a decorator which can access CustomObject instances + PythonQt::self()->addDecorators(new CustomObjectWrapper()); + + // ----------------------------------------------------------------- + // Alternative 2: make CustomObject2 known and use a wrapper factory for wrapping: + // ----------------------------------------------------------------- + + // add a factory that can handle pointers to CustomObject2 + PythonQt::self()->addWrapperFactory(new CustomFactory()); + + // the following is optional and only needed if you want a constructor: + // register the new object as a known classname + PythonQt::self()->registerCPPClassNames(QStringList() << "CustomObject2"); + // add a constructor for CustomObject2 + PythonQt::self()->addClassDecorators(new CustomObject2Constructor()); + + mainContext.evalFile(":example.py"); + + console.appendCommandPrompt(); + console.show(); + + return qapp.exec(); +} + diff --git a/examples/PyCustomMetaTypeExample/CustomObject.cpp b/examples/PyCustomMetaTypeExample/CustomObject.cpp new file mode 100644 index 0000000..e16559f --- /dev/null +++ b/examples/PyCustomMetaTypeExample/CustomObject.cpp @@ -0,0 +1,43 @@ +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file CustomObject.cpp +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2007-4 +*/ +//---------------------------------------------------------------------------------- + +#include "CustomObject.h" + diff --git a/examples/PyCustomMetaTypeExample/CustomObject.h b/examples/PyCustomMetaTypeExample/CustomObject.h new file mode 100644 index 0000000..7330fc9 --- /dev/null +++ b/examples/PyCustomMetaTypeExample/CustomObject.h @@ -0,0 +1,85 @@ +#ifndef _PYCUSTOMOBJECT_H +#define _PYCUSTOMOBJECT_H + +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file CustomObject.h +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2007-4 +*/ +//---------------------------------------------------------------------------------- + +#include "PythonQt.h" +#include + + +// declare our own copyable custom object +class CustomObject { +public: + CustomObject() {} + CustomObject(const QString& first, const QString& last) { _firstName = first; _lastName = last; } + + QString _firstName; + QString _lastName; + +}; + +// register it to the meta type system +Q_DECLARE_METATYPE(CustomObject) + +// add a wrapper that allows to access the CustomObject from PythonQt +class CustomObjectWrapper : public QObject { + + Q_OBJECT + +public slots: + // add a constructor + QVariant new_CustomObject(const QString& first, const QString& last) { return qVariantFromValue(CustomObject(first, last)); } + + // add access methods + + QString firstName(CustomObject* o) { return o->_firstName; } + + QString lastName(CustomObject* o) { return o->_lastName; } + + void setFirstName(CustomObject* o, const QString& name) { o->_firstName = name; } + + void setLastName(CustomObject* o, const QString& name) { o->_lastName = name; } + +}; + + +#endif diff --git a/examples/PyCustomMetaTypeExample/PyCustomMetaTypeExample.bat b/examples/PyCustomMetaTypeExample/PyCustomMetaTypeExample.bat new file mode 100644 index 0000000..b4332c6 --- /dev/null +++ b/examples/PyCustomMetaTypeExample/PyCustomMetaTypeExample.bat @@ -0,0 +1,2 @@ +"%MEVIS_LIB%\make\win32\createDsp.bat" PyCustomMetaTypeExample + diff --git a/examples/PyCustomMetaTypeExample/PyCustomMetaTypeExample.pro b/examples/PyCustomMetaTypeExample/PyCustomMetaTypeExample.pro new file mode 100644 index 0000000..84c5ef6 --- /dev/null +++ b/examples/PyCustomMetaTypeExample/PyCustomMetaTypeExample.pro @@ -0,0 +1,23 @@ +# --------- PyCustomMetaTypeExample profile ------------------- +# Last changed by $Author: florian $ +# $Id: PythonQt.pro 35381 2006-03-16 13:05:52Z florian $ +# $Source$ +# -------------------------------------------------- + +TARGET = PyCustomMetaTypeExample +TEMPLATE = app + +DESTDIR = ../../lib + +include ( ../../build/common.prf ) +include ( ../../build/PythonQt.prf ) + + +HEADERS += \ + CustomObject.h + +SOURCES += \ + main.cpp \ + CustomObject.cpp + +RESOURCES += PyCustomMetaTypeExample.qrc diff --git a/examples/PyCustomMetaTypeExample/PyCustomMetaTypeExample.qrc b/examples/PyCustomMetaTypeExample/PyCustomMetaTypeExample.qrc new file mode 100644 index 0000000..0e28080 --- /dev/null +++ b/examples/PyCustomMetaTypeExample/PyCustomMetaTypeExample.qrc @@ -0,0 +1,5 @@ + + + example.py + + diff --git a/examples/PyCustomMetaTypeExample/example.py b/examples/PyCustomMetaTypeExample/example.py new file mode 100644 index 0000000..5214d92 --- /dev/null +++ b/examples/PyCustomMetaTypeExample/example.py @@ -0,0 +1,14 @@ +from PythonQt import * + +# create a new object +custom = CustomObject("John","Doe") + +# print the methods available +print dir(custom) + +# set a name +custom.setFirstName("Mike") +custom.setLastName("Michels") + +# get the name +print custom.firstName() + " " + custom.lastName(); diff --git a/examples/PyCustomMetaTypeExample/main.cpp b/examples/PyCustomMetaTypeExample/main.cpp new file mode 100644 index 0000000..6c4952c --- /dev/null +++ b/examples/PyCustomMetaTypeExample/main.cpp @@ -0,0 +1,69 @@ +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PyGuiExample.cpp +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2007-04 +*/ +//---------------------------------------------------------------------------------- + +#include "PythonQt.h" +#include "gui/PythonQtScriptingConsole.h" +#include "CustomObject.h" + +#include + +int main( int argc, char **argv ) +{ + QApplication qapp(argc, argv); + + PythonQt::init(PythonQt::IgnoreSiteModule | PythonQt::RedirectStdOut); + + PythonQtObjectPtr mainContext = PythonQt::self()->getMainModule(); + PythonQtScriptingConsole console(NULL, mainContext); + + // register the type with QMetaType + qRegisterMetaType("CustomObject"); + // add a wrapper object for the new variant type + PythonQt::self()->addVariantWrapper("CustomObject", new CustomObjectWrapper()); + + mainContext.evalFile(":example.py"); + + console.appendCommandPrompt(); + console.show(); + + return qapp.exec(); +} + diff --git a/examples/PyDecoratorsExample/PyDecoratorsExample.bat b/examples/PyDecoratorsExample/PyDecoratorsExample.bat new file mode 100644 index 0000000..3201f90 --- /dev/null +++ b/examples/PyDecoratorsExample/PyDecoratorsExample.bat @@ -0,0 +1,2 @@ +"%MEVIS_LIB%\make\win32\createDsp.bat" PyDecoratorsExample + diff --git a/examples/PyDecoratorsExample/PyDecoratorsExample.pro b/examples/PyDecoratorsExample/PyDecoratorsExample.pro new file mode 100644 index 0000000..3c00e5c --- /dev/null +++ b/examples/PyDecoratorsExample/PyDecoratorsExample.pro @@ -0,0 +1,23 @@ +# --------- PyGuiExample profile ------------------- +# Last changed by $Author: florian $ +# $Id: PythonQt.pro 35381 2006-03-16 13:05:52Z florian $ +# $Source$ +# -------------------------------------------------- + +TARGET = PyDecoratorsExample +TEMPLATE = app + +DESTDIR = ../../lib + +include ( ../../build/common.prf ) +include ( ../../build/PythonQt.prf ) + + +HEADERS += \ + PyExampleDecorators.h + +SOURCES += \ + main.cpp \ + PyExampleDecorators.cpp + +RESOURCES += PyDecoratorsExample.qrc diff --git a/examples/PyDecoratorsExample/PyDecoratorsExample.qrc b/examples/PyDecoratorsExample/PyDecoratorsExample.qrc new file mode 100644 index 0000000..0e28080 --- /dev/null +++ b/examples/PyDecoratorsExample/PyDecoratorsExample.qrc @@ -0,0 +1,5 @@ + + + example.py + + diff --git a/examples/PyDecoratorsExample/PyExampleDecorators.cpp b/examples/PyDecoratorsExample/PyExampleDecorators.cpp new file mode 100644 index 0000000..7eea8e6 --- /dev/null +++ b/examples/PyDecoratorsExample/PyExampleDecorators.cpp @@ -0,0 +1,43 @@ +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PyExampleObject.cpp +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-10 +*/ +//---------------------------------------------------------------------------------- + +#include "PyExampleDecorators.h" + diff --git a/examples/PyDecoratorsExample/PyExampleDecorators.h b/examples/PyDecoratorsExample/PyExampleDecorators.h new file mode 100644 index 0000000..daa9cd3 --- /dev/null +++ b/examples/PyDecoratorsExample/PyExampleDecorators.h @@ -0,0 +1,95 @@ +#ifndef _PYEXAMPLEDECORATORS_H +#define _PYEXAMPLEDECORATORS_H + +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PyExampleDecorators.h +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2007-4 +*/ +//---------------------------------------------------------------------------------- + +#include "PythonQt.h" +#include +#include +#include + +// an example CPP object +class YourCPPObject { +public: + YourCPPObject(int arg1, float arg2) { a = arg1; b = arg2; } + + float doSomething(int arg1) { return arg1*a*b; }; + + private: + + int a; + float b; +}; + +// an example decorator +class PyExampleDecorators : public QObject +{ + Q_OBJECT + +public slots: + // add a constructor to QSize variant that takes a QPoint + QVariant new_QSize(const QPoint& p) { return QSize(p.x(), p.y()); } + + // add a constructor for QPushButton that takes a text and a parent widget + QPushButton* new_QPushButton(const QString& text, QWidget* parent=NULL) { return new QPushButton(text, parent); } + + // add a constructor for a CPP object + YourCPPObject* new_YourCPPObject(int arg1, float arg2) { return new YourCPPObject(arg1, arg2); } + + // add a destructor for a CPP object + void delete_YourCPPObject(YourCPPObject* obj) { delete obj; } + + // add a static method to QWidget + QWidget* static_QWidget_mouseGrabber() { return QWidget::mouseGrabber(); } + + // add an additional slot to QWidget (make move() callable, which is not declared as a slot in QWidget) + void move(QWidget* w, const QPoint& p) { w->move(p); } + + // add an additional slot to QWidget, overloading the above move method + void move(QWidget* w, int x, int y) { w->move(x,y); } + + // add a method to your own CPP object + int doSomething(YourCPPObject* obj, int arg1) { return obj->doSomething(arg1); } +}; + + +#endif diff --git a/examples/PyDecoratorsExample/example.py b/examples/PyDecoratorsExample/example.py new file mode 100644 index 0000000..3648d0d --- /dev/null +++ b/examples/PyDecoratorsExample/example.py @@ -0,0 +1,28 @@ +from PythonQt import * + +# call our new constructor of QSize +size = QSize(QPoint(1,2)); + +# call our new QPushButton constructor +button = QPushButton("sometext"); + +# call the move slot (overload1) +button.move(QPoint(0,0)) + +# call the move slot (overload2) +button.move(0,0) + +# call the static method +print QWidget.mouseGrabber(); + +# create a CPP object via constructor +yourCpp = YourCPPObject(2,11.5) + +# call the wrapped method on CPP object +print yourCpp.doSomething(3); + +# show slots available on yourCpp +print dir(yourCpp) + +# destructor will be called: +yourCpp = None diff --git a/examples/PyDecoratorsExample/main.cpp b/examples/PyDecoratorsExample/main.cpp new file mode 100644 index 0000000..aea563d --- /dev/null +++ b/examples/PyDecoratorsExample/main.cpp @@ -0,0 +1,68 @@ +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PyGuiExample.cpp +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2007-04 +*/ +//---------------------------------------------------------------------------------- + +#include "PythonQt.h" +#include "gui/PythonQtScriptingConsole.h" +#include "PyExampleDecorators.h" + +#include + +int main( int argc, char **argv ) +{ + QApplication qapp(argc, argv); + + PythonQt::init(PythonQt::IgnoreSiteModule | PythonQt::RedirectStdOut); + + PythonQtObjectPtr mainContext = PythonQt::self()->getMainModule(); + PythonQtScriptingConsole console(NULL, mainContext); + + PythonQt::self()->addDecorators(new PyExampleDecorators()); + PythonQt::self()->registerClass(&QPushButton::staticMetaObject); + PythonQt::self()->registerCPPClassNames(QStringList() << "YourCPPObject"); + + mainContext.evalFile(":example.py"); + + console.appendCommandPrompt(); + console.show(); + + return qapp.exec(); +} + diff --git a/examples/PyGettingStarted/GettingStarted.py b/examples/PyGettingStarted/GettingStarted.py new file mode 100644 index 0000000..597b23a --- /dev/null +++ b/examples/PyGettingStarted/GettingStarted.py @@ -0,0 +1,26 @@ +from PythonQt import * + +# set the title of the group box, accessing the title property +box.title = 'PythonQt Example' + +# set the html content of the QTextBrowser +box.browser.html = 'Hello Qt!' + +# set the title of the button +box.button1.text = 'Append Text' + +# set the text of the line edit +box.edit.text = '42' + +# define our own python method that appends the text from the line edit +# to the text browser +def appendLine(): + box.browser.append(box.edit.text) + +# connect the button's clicked signal to our python method +box.button1.connect('clicked()', appendLine) +# connect the lineedit's returnPressed signal to our python method +box.edit.connect('returnPressed()', appendLine) + +# show the window +box.show() diff --git a/examples/PyGettingStarted/PyGettingStarted.bat b/examples/PyGettingStarted/PyGettingStarted.bat new file mode 100644 index 0000000..1b007c8 --- /dev/null +++ b/examples/PyGettingStarted/PyGettingStarted.bat @@ -0,0 +1,2 @@ +"%MEVIS_LIB%\make\win32\createDsp.bat" PyGettingStarted + diff --git a/examples/PyGettingStarted/PyGettingStarted.pro b/examples/PyGettingStarted/PyGettingStarted.pro new file mode 100644 index 0000000..c2a319d --- /dev/null +++ b/examples/PyGettingStarted/PyGettingStarted.pro @@ -0,0 +1,20 @@ +# --------- PyScriptingConsole profile ------------------- +# Last changed by $Author: florian $ +# $Id: PythonQt.pro 35381 2006-03-16 13:05:52Z florian $ +# $Source$ +# -------------------------------------------------- + +TARGET = PyGettingStarted +TEMPLATE = app + +DESTDIR = ../../lib + +CONFIG += console + +include ( ../../build/common.prf ) +include ( ../../build/PythonQt.prf ) + +SOURCES += \ + main.cpp + +RESOURCES += PyGettingStarted.qrc diff --git a/examples/PyGettingStarted/PyGettingStarted.qrc b/examples/PyGettingStarted/PyGettingStarted.qrc new file mode 100644 index 0000000..fb23bcc --- /dev/null +++ b/examples/PyGettingStarted/PyGettingStarted.qrc @@ -0,0 +1,5 @@ + + + GettingStarted.py + + diff --git a/examples/PyGettingStarted/main.cpp b/examples/PyGettingStarted/main.cpp new file mode 100644 index 0000000..1aa0adc --- /dev/null +++ b/examples/PyGettingStarted/main.cpp @@ -0,0 +1,90 @@ +/* +* +* Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* Further, this software is distributed without any warranty that it is +* free of the rightful claim of any third person regarding infringement +* or the like. Any license provided herein, whether implied or +* otherwise, applies only to this software file. Patent licenses, if +* any, provided herein do not apply to combinations of this program with +* other software, or any other product whatsoever. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Contact information: MeVis Research GmbH, Universitaetsallee 29, +* 28359 Bremen, Germany or: +* +* http://www.mevis.de +* +*/ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtTests.cpp +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-05 +*/ +//---------------------------------------------------------------------------------- + +#include "PythonQt.h" +#include +#include +#include +#include +#include +#include + +int main( int argc, char **argv ) +{ + QApplication qapp(argc, argv); + + // init PythonQt and Python + PythonQt::init(); + + // get the __main__ python module + PythonQtObjectPtr mainModule = PythonQt::self()->getMainModule(); + + // evaluate a simple python script and receive the result a qvariant: + QVariant result = mainModule.evalScript("19*2+4", Py_eval_input); + + // create a small Qt GUI + QVBoxLayout* vbox = new QVBoxLayout; + QGroupBox* box = new QGroupBox; + QTextBrowser* browser = new QTextBrowser(box); + QLineEdit* edit = new QLineEdit(box); + QPushButton* button = new QPushButton(box); + button->setObjectName("button1"); + edit->setObjectName("edit"); + browser->setObjectName("browser"); + vbox->addWidget(browser); + vbox->addWidget(edit); + vbox->addWidget(button); + box->setLayout(vbox); + + // make the groupbox to the python under the name "box" + mainModule.addObject("box", box); + + // evaluate the python script which is defined in the resources + mainModule.evalFile(":GettingStarted.py"); + + // define a python method that appends the passed text to the browser + mainModule.evalScript("def appendText(text):\n box.browser.append(text)"); + // shows how to call the method with a text that will be append to the browser + mainModule.call("appendText", QVariantList() << "The ultimate answer is "); + + return qapp.exec(); +} + diff --git a/examples/PyGuiExample/PyGuiExample.bat b/examples/PyGuiExample/PyGuiExample.bat new file mode 100644 index 0000000..64050ce --- /dev/null +++ b/examples/PyGuiExample/PyGuiExample.bat @@ -0,0 +1,2 @@ +"%MEVIS_LIB%\make\win32\createDsp.bat" PyGuiExample + diff --git a/examples/PyGuiExample/PyGuiExample.pro b/examples/PyGuiExample/PyGuiExample.pro new file mode 100644 index 0000000..d37d831 --- /dev/null +++ b/examples/PyGuiExample/PyGuiExample.pro @@ -0,0 +1,19 @@ +# --------- PyGuiExample profile ------------------- +# Last changed by $Author: florian $ +# $Id: PythonQt.pro 35381 2006-03-16 13:05:52Z florian $ +# $Source$ +# -------------------------------------------------- + +TARGET = PyGuiExample +TEMPLATE = app + +DESTDIR = ../../lib + +include ( ../../build/common.prf ) +include ( ../../build/PythonQt.prf ) +include ( ../../build/PythonQtGui.prf ) + +SOURCES += \ + main.cpp + +RESOURCES += PyGuiExample.qrc diff --git a/examples/PyGuiExample/PyGuiExample.qrc b/examples/PyGuiExample/PyGuiExample.qrc new file mode 100644 index 0000000..0e28080 --- /dev/null +++ b/examples/PyGuiExample/PyGuiExample.qrc @@ -0,0 +1,5 @@ + + + example.py + + diff --git a/examples/PyGuiExample/example.py b/examples/PyGuiExample/example.py new file mode 100644 index 0000000..cfbd90a --- /dev/null +++ b/examples/PyGuiExample/example.py @@ -0,0 +1,15 @@ +from PythonQt import * + +group = QGroupBox() +box = QVBoxLayout(group) +push1 = QPushButton(group) +box.addWidget(push1) +push2 = QPushButton(group) +box.addWidget(push2) +check = QCheckBox(group) +check.text = 'check me' +group.title = 'my title' +push1.text = 'press me' +push2.text = 'press me2' +box.addWidget(check) +group.show() diff --git a/examples/PyGuiExample/main.cpp b/examples/PyGuiExample/main.cpp new file mode 100644 index 0000000..caeff92 --- /dev/null +++ b/examples/PyGuiExample/main.cpp @@ -0,0 +1,68 @@ +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PyGuiExample.cpp +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2007-04 +*/ +//---------------------------------------------------------------------------------- + +#include "PythonQt.h" +#include "PythonQtGui.h" +#include "gui/PythonQtScriptingConsole.h" + +#include +#include +#include +#include +#include + + +int main( int argc, char **argv ) +{ + QApplication qapp(argc, argv); + + PythonQt::init(PythonQt::IgnoreSiteModule | PythonQt::RedirectStdOut); + PythonQtGui::init(); + + PythonQtObjectPtr mainContext = PythonQt::self()->getMainModule(); + PythonQtScriptingConsole console(NULL, mainContext); + + mainContext.evalFile(":example.py"); + + console.show(); + return qapp.exec(); +} + diff --git a/examples/PyScriptingConsole/PyExampleObject.cpp b/examples/PyScriptingConsole/PyExampleObject.cpp new file mode 100644 index 0000000..f78434f --- /dev/null +++ b/examples/PyScriptingConsole/PyExampleObject.cpp @@ -0,0 +1,87 @@ +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PyExampleObject.cpp +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-10 +*/ +//---------------------------------------------------------------------------------- + +#include "PyExampleObject.h" +#include +#include + +PyExampleObject::PyExampleObject():QObject(NULL) +{ +} + +PyObject* PyExampleObject::getMainModule() { + return PythonQt::self()->getMainModule(); +} + +void PyExampleObject::showInformation(const QString& str) +{ + QMessageBox::information ( NULL, "Test", str); +} + +QStringList PyExampleObject::readDirectory(const QString& dir) +{ + QDir d(dir); + return d.entryList(); +} + +QMainWindow* PyExampleObject::createWindow() +{ + QMainWindow* m = new QMainWindow(); + QPushButton* b = new QPushButton(m); + b->setObjectName("button1"); + + m->show(); + return m; +} + +QObject* PyExampleObject::findChild(QObject* o, const QString& name) +{ + return qFindChild(o, name); +} + +QVariantMap PyExampleObject::testMap() +{ + QVariantMap m; + m.insert("a", QStringList() << "test1" << "test2"); + m.insert("b", 12); + m.insert("c", 12.); + return m; +} diff --git a/examples/PyScriptingConsole/PyExampleObject.h b/examples/PyScriptingConsole/PyExampleObject.h new file mode 100644 index 0000000..1586c18 --- /dev/null +++ b/examples/PyScriptingConsole/PyExampleObject.h @@ -0,0 +1,79 @@ +#ifndef _PYEXAMPLEOBJECT_H +#define _PYEXAMPLEOBJECT_H + +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PyExampleObject.h +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-10 +*/ +//---------------------------------------------------------------------------------- + +#include "PythonQt.h" + +#include +#include +#include +#include +#include +#include + + +class PyExampleObject : public QObject { + + Q_OBJECT + +public: + PyExampleObject(); + +public slots: + + //! example for passing a PyObject directly from Qt to Python (without extra mashalling) + PyObject* getMainModule(); + + void showInformation(const QString& str); + + QStringList readDirectory(const QString& dir); + + QMainWindow* createWindow(); + + QObject* findChild(QObject* o, const QString& name); + + QVariantMap testMap(); + +}; + +#endif diff --git a/examples/PyScriptingConsole/PyScriptingConsole.bat b/examples/PyScriptingConsole/PyScriptingConsole.bat new file mode 100644 index 0000000..aa604fe --- /dev/null +++ b/examples/PyScriptingConsole/PyScriptingConsole.bat @@ -0,0 +1,2 @@ +"%MEVIS_LIB%\make\win32\createDsp.bat" PyScriptingConsole + diff --git a/examples/PyScriptingConsole/PyScriptingConsole.pro b/examples/PyScriptingConsole/PyScriptingConsole.pro new file mode 100644 index 0000000..b96bf63 --- /dev/null +++ b/examples/PyScriptingConsole/PyScriptingConsole.pro @@ -0,0 +1,23 @@ +# --------- PyScriptingConsole profile ------------------- +# Last changed by $Author: florian $ +# $Id: PythonQt.pro 35381 2006-03-16 13:05:52Z florian $ +# $Source$ +# -------------------------------------------------- + +TARGET = PyScriptingConsole +TEMPLATE = app + +DESTDIR = ../../lib + +include ( ../../build/common.prf ) +include ( ../../build/PythonQt.prf ) +include ( ../../build/PythonQtGui.prf ) + +HEADERS += \ + PyExampleObject.h + +SOURCES += \ + PyExampleObject.cpp \ + main.cpp + +RESOURCES += PyScriptingConsole.qrc diff --git a/examples/PyScriptingConsole/PyScriptingConsole.qrc b/examples/PyScriptingConsole/PyScriptingConsole.qrc new file mode 100644 index 0000000..0e28080 --- /dev/null +++ b/examples/PyScriptingConsole/PyScriptingConsole.qrc @@ -0,0 +1,5 @@ + + + example.py + + diff --git a/examples/PyScriptingConsole/example.py b/examples/PyScriptingConsole/example.py new file mode 100644 index 0000000..cfbd90a --- /dev/null +++ b/examples/PyScriptingConsole/example.py @@ -0,0 +1,15 @@ +from PythonQt import * + +group = QGroupBox() +box = QVBoxLayout(group) +push1 = QPushButton(group) +box.addWidget(push1) +push2 = QPushButton(group) +box.addWidget(push2) +check = QCheckBox(group) +check.text = 'check me' +group.title = 'my title' +push1.text = 'press me' +push2.text = 'press me2' +box.addWidget(check) +group.show() diff --git a/examples/PyScriptingConsole/main.cpp b/examples/PyScriptingConsole/main.cpp new file mode 100644 index 0000000..9a4ba84 --- /dev/null +++ b/examples/PyScriptingConsole/main.cpp @@ -0,0 +1,73 @@ +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtTests.cpp +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-05 +*/ +//---------------------------------------------------------------------------------- + +#include "PythonQt.h" +#include "PythonQtGui.h" +#include "PyExampleObject.h" +#include "gui/PythonQtScriptingConsole.h" + +#include +#include +#include +#include +#include + + +int main( int argc, char **argv ) +{ + QApplication qapp(argc, argv); + + PythonQt::init(PythonQt::IgnoreSiteModule | PythonQt::RedirectStdOut); + PythonQtGui::init(); + + PythonQtObjectPtr mainContext = PythonQt::self()->getMainModule(); + PythonQtScriptingConsole console(NULL, mainContext); + + // add a QObject to the namespace of the main python context + PyExampleObject example; + mainContext.addObject("example", &example); + + mainContext.evalFile(":example.py"); + + console.show(); + return qapp.exec(); +} + diff --git a/examples/examples.pro b/examples/examples.pro new file mode 100644 index 0000000..a33adb7 --- /dev/null +++ b/examples/examples.pro @@ -0,0 +1,7 @@ +TEMPLATE = subdirs +SUBDIRS = PyGettingStarted \ + PyCPPWrapperExample \ + PyCustomMetaTypeExample \ + PyGuiExample \ + PyDecoratorsExample \ + PyScriptingConsole diff --git a/extensions/PythonQtGui/PythonQtGui.bat b/extensions/PythonQtGui/PythonQtGui.bat new file mode 100644 index 0000000..791ff98 --- /dev/null +++ b/extensions/PythonQtGui/PythonQtGui.bat @@ -0,0 +1,2 @@ +"%MEVIS_LIB%\make\win32\createDsp.bat" PythonQtGui + diff --git a/extensions/PythonQtGui/PythonQtGui.cpp b/extensions/PythonQtGui/PythonQtGui.cpp new file mode 100644 index 0000000..3dbca45 --- /dev/null +++ b/extensions/PythonQtGui/PythonQtGui.cpp @@ -0,0 +1,216 @@ +/* +* +* Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* Further, this software is distributed without any warranty that it is +* free of the rightful claim of any third person regarding infringement +* or the like. Any license provided herein, whether implied or +* otherwise, applies only to this software file. Patent licenses, if +* any, provided herein do not apply to combinations of this program with +* other software, or any other product whatsoever. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Contact information: MeVis Research GmbH, Universitaetsallee 29, +* 28359 Bremen, Germany or: +* +* http://www.mevis.de +* +*/ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtGui.cpp +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2007-04 +*/ +//---------------------------------------------------------------------------------- + +#include "PythonQtGui.h" +#include "PythonQt.h" +#include +#include +#include +#include + +#include + +void PythonQtGui::init() +{ + PythonQt::self()->addConstructorHandler(new PythonQtUiLoaderConstructorHandler); + PythonQt::self()->addInstanceDecorators(new PythonQtUiDecorators()); + PythonQt::self()->addClassDecorators(new PythonQtUiConstructors()); + + PythonQt::self()->registerClass(&QAction::staticMetaObject); + PythonQt::self()->registerClass(&QActionGroup::staticMetaObject); + + PythonQt::self()->registerClass(&QCheckBox::staticMetaObject); + PythonQt::self()->registerClass(&QComboBox::staticMetaObject); + PythonQt::self()->registerClass(&QDateTimeEdit::staticMetaObject); + PythonQt::self()->registerClass(&QDateEdit::staticMetaObject); + PythonQt::self()->registerClass(&QTimeEdit::staticMetaObject); + PythonQt::self()->registerClass(&QDial::staticMetaObject); + PythonQt::self()->registerClass(&QDialog::staticMetaObject); + PythonQt::self()->registerClass(&QDockWidget::staticMetaObject); + PythonQt::self()->registerClass(&QFrame::staticMetaObject); + PythonQt::self()->registerClass(&QGroupBox::staticMetaObject); + PythonQt::self()->registerClass(&QLCDNumber::staticMetaObject); + PythonQt::self()->registerClass(&QLabel::staticMetaObject); + PythonQt::self()->registerClass(&QLineEdit::staticMetaObject); + PythonQt::self()->registerClass(&QListView::staticMetaObject); + PythonQt::self()->registerClass(&QListWidget::staticMetaObject); + PythonQt::self()->registerClass(&QMainWindow::staticMetaObject); + PythonQt::self()->registerClass(&QMenu::staticMetaObject); + PythonQt::self()->registerClass(&QMenuBar::staticMetaObject); + PythonQt::self()->registerClass(&QProgressBar::staticMetaObject); + PythonQt::self()->registerClass(&QPushButton::staticMetaObject); + PythonQt::self()->registerClass(&QRadioButton::staticMetaObject); + PythonQt::self()->registerClass(&QScrollBar::staticMetaObject); + PythonQt::self()->registerClass(&QSlider::staticMetaObject); + PythonQt::self()->registerClass(&QSpinBox::staticMetaObject); + PythonQt::self()->registerClass(&QDoubleSpinBox::staticMetaObject); + PythonQt::self()->registerClass(&QTabWidget::staticMetaObject); + PythonQt::self()->registerClass(&QTableView::staticMetaObject); + PythonQt::self()->registerClass(&QTableWidget::staticMetaObject); + PythonQt::self()->registerClass(&QTextBrowser::staticMetaObject); + PythonQt::self()->registerClass(&QTextEdit::staticMetaObject); + PythonQt::self()->registerClass(&QToolBar::staticMetaObject); + PythonQt::self()->registerClass(&QToolBox::staticMetaObject); + PythonQt::self()->registerClass(&QToolButton::staticMetaObject); + PythonQt::self()->registerClass(&QTreeView::staticMetaObject); + PythonQt::self()->registerClass(&QTreeWidget::staticMetaObject); + PythonQt::self()->registerClass(&QWidget::staticMetaObject); + PythonQt::self()->registerClass(&QWorkspace::staticMetaObject); + PythonQt::self()->registerClass(&QSplitter::staticMetaObject); + PythonQt::self()->registerClass(&QStackedWidget::staticMetaObject); + PythonQt::self()->registerClass(&QStatusBar::staticMetaObject); + PythonQt::self()->registerClass(&QDialogButtonBox::staticMetaObject); + PythonQt::self()->registerClass(&QFontComboBox::staticMetaObject); + PythonQt::self()->registerClass(&QCalendarWidget::staticMetaObject); + PythonQt::self()->registerClass(&QHBoxLayout::staticMetaObject); + PythonQt::self()->registerClass(&QStackedLayout::staticMetaObject); + PythonQt::self()->registerClass(&QVBoxLayout::staticMetaObject); +} + +bool PythonQt_inherits(const QMetaObject* self, const QMetaObject* parent) { + const QMetaObject* m = self; + while (m) { + if (m==parent) { + return true; + }; + m = m->superClass(); + } + return false; +} + +QObject* PythonQtUiLoaderConstructorHandler::create(const QMetaObject* meta, PyObject *args, PyObject *kw, QString& error) +{ + if (!PythonQt_inherits(meta, &QLayout::staticMetaObject) && + !PythonQt_inherits(meta, &QWidget::staticMetaObject) && + !PythonQt_inherits(meta, &QAction::staticMetaObject) && + !PythonQt_inherits(meta, &QActionGroup::staticMetaObject)) return NULL; + + static QUiLoader* loader = NULL; + if (!loader) { + loader = new QUiLoader(); + } + int argc = PyTuple_Size(args); + QObject* parent = NULL; + if (argc == 1) { + PyObject* arg1 = PyTuple_GET_ITEM(args, 0); + if (arg1 && arg1->ob_type == &PythonQtWrapper_Type) { + parent = ((PythonQtWrapper*)arg1)->_obj; + } else { + error = QString("constructor ") + meta->className() + " requires a QObject as parent"; + return NULL; + } + } else if (argc!=0) { + error = QString("constructor ") + meta->className() + " called with too many arguments"; + return NULL; + } + + if (PythonQt_inherits(meta, &QLayout::staticMetaObject)) { + return loader->createLayout(meta->className(), parent); + } + if (PythonQt_inherits(meta, &QWidget::staticMetaObject)) { + if (!parent || parent->isWidgetType()) { + return loader->createWidget(meta->className(), (QWidget*)parent); + } else { + error = QString("constructor ") + meta->className() + " requires a QWidget as parent"; + return NULL; + } + } + if (PythonQt_inherits(meta, &QAction::staticMetaObject)) { + return loader->createAction(parent); + } + if (PythonQt_inherits(meta, &QActionGroup::staticMetaObject)) { + return loader->createActionGroup(parent); + } + return NULL; +} + + +void PythonQtUiDecorators::addWidget(QLayout* l, QWidget* w) +{ + l->addWidget(w); +} + +QLayout* PythonQtUiDecorators::layout(QWidget* w) +{ + return w->layout(); +} + +void PythonQtUiDecorators::setLayout(QWidget* w, QLayout* l) +{ + w->setLayout(l); +} + +void PythonQtUiDecorators::setCentralWidget(QMainWindow* main, QWidget* w) +{ + main->setCentralWidget(w); +} + +void PythonQtUiDecorators::setMenuBar(QMainWindow* main, QMenuBar* w) +{ + main->setMenuBar(w); +} + +void PythonQtUiDecorators::addAction(QMenuBar* bar, QAction* action) +{ + bar->addAction(action); +} + +QAction* PythonQtUiDecorators::addMenu(QMenuBar* bar, QMenu* menu) +{ + return bar->addMenu(menu); +} + +QMenu* PythonQtUiDecorators::addMenu(QMenuBar* bar, const QString& name) +{ + return bar->addMenu(name); +} + +QAction* PythonQtUiDecorators::addAction(QMenu* m, const QString& name) +{ + return m->addAction(name); +} + +// -------------------------------------------------------------------- + +QWidget* PythonQtUiConstructors::new_QWidget(QWidget* parent) +{ + return new QWidget(parent); +} diff --git a/extensions/PythonQtGui/PythonQtGui.h b/extensions/PythonQtGui/PythonQtGui.h new file mode 100644 index 0000000..e78ac8a --- /dev/null +++ b/extensions/PythonQtGui/PythonQtGui.h @@ -0,0 +1,100 @@ +#ifndef _PYTHONQTGUI_H +#define _PYTHONQTGUI_H + +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtGUI.h +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2007-04 +*/ +//---------------------------------------------------------------------------------- + +#include "PythonQtGuiSystem.h" +#include "PythonQtMetaObjectWrapper.h" + +#include + +class QWidget; +class QLayout; +class QMainWindow; +class QMenuBar; +class QWidget; +class QAction; +class QMenu; + +class PYTHONQTGUI_EXPORT PythonQtGui +{ +public: + //! init the Qt GUI extensions + static void init(); +}; + +class PythonQtUiLoaderConstructorHandler : public PythonQtConstructorHandler { +public: + virtual QObject* create(const QMetaObject* meta, PyObject *args, PyObject *kw, QString& error); +}; + +class PythonQtUiConstructors : public QObject +{ + Q_OBJECT + + public slots: + QWidget* new_QWidget(QWidget* parent=NULL); + +}; + +class PythonQtUiDecorators : public QObject +{ + Q_OBJECT + +public slots: + void addWidget(QLayout* l, QWidget* w); + + QLayout* layout(QWidget* w); + void setLayout(QWidget* w, QLayout* l); + + void setCentralWidget(QMainWindow* main, QWidget* w); + void setMenuBar(QMainWindow* main, QMenuBar* w); + + void addAction(QMenuBar* bar, QAction* action); + QAction* addMenu(QMenuBar* bar, QMenu* menu); + QMenu* addMenu(QMenuBar* bar, const QString& name); + + QAction* addAction(QMenu* bar, const QString& name); + +}; + +#endif diff --git a/extensions/PythonQtGui/PythonQtGui.pro b/extensions/PythonQtGui/PythonQtGui.pro new file mode 100644 index 0000000..abe9012 --- /dev/null +++ b/extensions/PythonQtGui/PythonQtGui.pro @@ -0,0 +1,26 @@ +# --------- PythonQtGui profile ------------------- +# Last changed by $Author: florian $ +# $Id: PythonQt.pro 35381 2006-03-16 13:05:52Z florian $ +# $Source$ +# -------------------------------------------------- + +TARGET = PythonQtGui +TEMPLATE = lib + +DESTDIR = ../../lib +DLLDESTDIR = ../../lib + +include ( ../../build/common.prf ) +include ( ../../build/PythonQt.prf ) + +CONFIG += dll qt uitools + +DEFINES += PYTHONQTGUI_EXPORTS + +HEADERS += \ + PythonQtGui.h \ + PythonQtGuiSystem.h \ + +SOURCES += \ + PythonQtGui.cpp + diff --git a/extensions/PythonQtGui/PythonQtGuiSystem.h b/extensions/PythonQtGui/PythonQtGuiSystem.h new file mode 100644 index 0000000..4d2b930 --- /dev/null +++ b/extensions/PythonQtGui/PythonQtGuiSystem.h @@ -0,0 +1,56 @@ +#ifndef _PYTHONQTGUISYSTEM_ +#define _PYTHONQTGUISYSTEM_ + +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtGuiSystem.h +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-05 +*/ +//---------------------------------------------------------------------------------- + +#ifdef WIN32 +#ifdef PYTHONQTGUI_EXPORTS +#define PYTHONQTGUI_EXPORT __declspec(dllexport) +#else +#define PYTHONQTGUI_EXPORT __declspec(dllimport) +#endif +#else +#define PYTHONQTGUI_EXPORT +#endif + +#endif + diff --git a/extensions/extensions.pro b/extensions/extensions.pro new file mode 100644 index 0000000..8819a02 --- /dev/null +++ b/extensions/extensions.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS = PythonQtGui diff --git a/src/PythonQt.cpp b/src/PythonQt.cpp new file mode 100644 index 0000000..743161b --- /dev/null +++ b/src/PythonQt.cpp @@ -0,0 +1,946 @@ +/* +* +* Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* Further, this software is distributed without any warranty that it is +* free of the rightful claim of any third person regarding infringement +* or the like. Any license provided herein, whether implied or +* otherwise, applies only to this software file. Patent licenses, if +* any, provided herein do not apply to combinations of this program with +* other software, or any other product whatsoever. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Contact information: MeVis Research GmbH, Universitaetsallee 29, +* 28359 Bremen, Germany or: +* +* http://www.mevis.de +* +*/ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQt.cpp +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-05 +*/ +//---------------------------------------------------------------------------------- + +#include "PythonQt.h" +#include "PythonQtImporter.h" +#include "PythonQtClassInfo.h" +#include "PythonQtMethodInfo.h" +#include "PythonQtSignalReceiver.h" +#include "PythonQtConversion.h" +#include "PythonQtStdOut.h" +#include "PythonQtCppWrapperFactory.h" +#include "PythonQtVariants.h" +#include "PythonQtStdDecorators.h" +#include + +PythonQt* PythonQt::_self = NULL; + + +void PythonQt::init(int flags) +{ + if (!_self) { + _self = new PythonQt(flags); + } + + PythonQtMethodInfo::addParameterTypeAlias("QObjectList", "QList"); + qRegisterMetaType >("QList"); + + PythonQt::self()->addDecorators(new PythonQtStdDecorators()); + + PythonQt::priv()->addVariantWrapper("QBitArray", new PythonQtQBitArrayWrapper); + PythonQt::priv()->addVariantWrapper("QDate", new PythonQtQDateWrapper); + PythonQt::priv()->addVariantWrapper("QTime", new PythonQtQTimeWrapper); + PythonQt::priv()->addVariantWrapper("QDateTime", new PythonQtQDateTimeWrapper); + PythonQt::priv()->addVariantWrapper("QUrl", new PythonQtQUrlWrapper); + PythonQt::priv()->addVariantWrapper("QLocale", new PythonQtQLocaleWrapper); + PythonQt::priv()->addVariantWrapper("QRect", new PythonQtQRectWrapper); + PythonQt::priv()->addVariantWrapper("QRectF", new PythonQtQRectFWrapper); + PythonQt::priv()->addVariantWrapper("QSize", new PythonQtQSizeWrapper); + PythonQt::priv()->addVariantWrapper("QSizeF", new PythonQtQSizeFWrapper); + PythonQt::priv()->addVariantWrapper("QLine", new PythonQtQLineWrapper); + PythonQt::priv()->addVariantWrapper("QLineF", new PythonQtQLineFWrapper); + PythonQt::priv()->addVariantWrapper("QPoint", new PythonQtQPointWrapper); + PythonQt::priv()->addVariantWrapper("QPointF", new PythonQtQPointFWrapper); + PythonQt::priv()->addVariantWrapper("QRegExp", new PythonQtQRegExpWrapper); + PythonQt::priv()->addVariantWrapper("QFont", new PythonQtQFontWrapper); + PythonQt::priv()->addVariantWrapper("QPixmap", new PythonQtQPixmapWrapper); + PythonQt::priv()->addVariantWrapper("QBrush", new PythonQtQBrushWrapper); + PythonQt::priv()->addVariantWrapper("QColor", new PythonQtQColorWrapper); + PythonQt::priv()->addVariantWrapper("QPalette", new PythonQtQPaletteWrapper); + PythonQt::priv()->addVariantWrapper("QIcon", new PythonQtQIconWrapper); + PythonQt::priv()->addVariantWrapper("QImage", new PythonQtQImageWrapper); + PythonQt::priv()->addVariantWrapper("QPolygon", new PythonQtQPolygonWrapper); + PythonQt::priv()->addVariantWrapper("QRegion", new PythonQtQRegionWrapper); + PythonQt::priv()->addVariantWrapper("QBitmap", new PythonQtQBitmapWrapper); + PythonQt::priv()->addVariantWrapper("QCursor", new PythonQtQCursorWrapper); + PythonQt::priv()->addVariantWrapper("QSizePolicy", new PythonQtQSizePolicyWrapper); + PythonQt::priv()->addVariantWrapper("QKeySequence", new PythonQtQKeySequenceWrapper); + PythonQt::priv()->addVariantWrapper("QPen", new PythonQtQPenWrapper); + PythonQt::priv()->addVariantWrapper("QTextLength", new PythonQtQTextLengthWrapper); + PythonQt::priv()->addVariantWrapper("QTextFormat", new PythonQtQTextFormatWrapper); + PythonQt::priv()->addVariantWrapper("QMatrix", new PythonQtQMatrixWrapper); + +} + +void PythonQt::cleanup() +{ + if (_self) { + delete _self; + _self = NULL; + } +} + +PythonQt::PythonQt(int flags) +{ + _p = new PythonQtPrivate; + _p->_initFlags = flags; + + _p->_PythonQtObjectPtr_metaId = qRegisterMetaType("PythonQtObjectPtr"); + + Py_SetProgramName("PythonQt"); + if (flags & IgnoreSiteModule) { + // this prevents the automatic importing of Python site files + Py_NoSiteFlag = 1; + } + Py_Initialize(); + + // add our own python object types for qt object slots + if (PyType_Ready(&PythonQtSlotFunction_Type) < 0) { + std::cerr << "could not initialize PythonQtSlotFunction_Type" << ", in " << __FILE__ << ":" << __LINE__ << std::endl; + } + Py_INCREF(&PythonQtSlotFunction_Type); + + // add our own python object types for qt objects + if (PyType_Ready(&PythonQtWrapper_Type) < 0) { + std::cerr << "could not initialize PythonQtWrapper_Type" << ", in " << __FILE__ << ":" << __LINE__ << std::endl; + } + Py_INCREF(&PythonQtWrapper_Type); + + // add our own python object types for qt objects + if (PyType_Ready(&PythonQtVariantWrapper_Type) < 0) { + std::cerr << "could not initialize PythonQtVariantWrapper_Type" << ", in " << __FILE__ << ":" << __LINE__ << std::endl; + } + Py_INCREF(&PythonQtVariantWrapper_Type); + + // add our own python object types for qt objects + if (PyType_Ready(&PythonQtMetaObjectWrapper_Type) < 0) { + std::cerr << "could not initialize PythonQtMetaObjectWrapper_Type" << ", in " << __FILE__ << ":" << __LINE__ << std::endl; + } + Py_INCREF(&PythonQtMetaObjectWrapper_Type); + + // add our own python object types for redirection of stdout + if (PyType_Ready(&PythonQtStdOutRedirectType) < 0) { + std::cerr << "could not initialize PythonQtStdOutRedirectType" << ", in " << __FILE__ << ":" << __LINE__ << std::endl; + } + Py_INCREF(&PythonQtStdOutRedirectType); + + initPythonQtModule(flags & RedirectStdOut); + +} + +PythonQt::~PythonQt() { + delete _p; + _p = NULL; +} + +PythonQtPrivate::~PythonQtPrivate() { + { + QHashIterator i(_knownQtClasses); + while (i.hasNext()) { + delete i.next().value(); + } + } + { + QHashIterator i(_knownQtWrapperClasses); + while (i.hasNext()) { + delete i.next().value(); + } + } + { + QHashIterator > i(_knownVariantWrappers); + while (i.hasNext()) { + delete i.next().value().first; + } + } + { + QHashIterator i(_constructorSlots); + while (i.hasNext()) { + delete i.next().value(); + } + } + { + QHashIterator i(_destructorSlots); + while (i.hasNext()) { + delete i.next().value(); + } + } + PythonQtConv::global_valueStorage.clear(); + PythonQtConv::global_ptrStorage.clear(); + PythonQtConv::global_variantStorage.clear(); + + PythonQtMethodInfo::cleanupCachedMethodInfos(); + + delete _qtNamespace; +} + +PythonQtImportFileInterface* PythonQt::importInterface() +{ + return _self->_p->_importInterface; +} + +void PythonQt::registerClass(const QMetaObject* metaobject) +{ + _p->registerClass(metaobject); +} + +void PythonQtPrivate::registerClass(const QMetaObject* metaobject) +{ + // we register all classes in the hierarchy + const QMetaObject* m = metaobject; + while (m) { + PythonQtClassInfo* info = _knownQtClasses.value(m->className()); + if (!info) { + info = new PythonQtClassInfo(m); + _knownQtClasses.insert(m->className(), info); + PyModule_AddObject(_pythonQtModule, m->className(), (PyObject*)createNewPythonQtMetaObjectWrapper(info)); + } + m = m->superClass(); + } +} + +bool PythonQtPrivate::isEnumType(const QMetaObject* meta, const QByteArray& name) { + int i = meta?meta->indexOfEnumerator(name.constData()):-1; + if (i!=-1) { + return true; + } else { + // look for scope + int scopePos = name.indexOf("::"); + if (scopePos != -1) { + // slit into scope and enum name + QByteArray enumScope = name.mid(0,scopePos); + QByteArray enumName = name.mid(scopePos+2); + if (enumScope == "Qt") { + // special qt namespace case + return isEnumType(&staticQtMetaObject, enumName); + } else { + // look for known classes as scope + // TODO: Q_GADGETS are not yet handled + PythonQtClassInfo* info = _knownQtClasses.value(enumScope); + if (info) { + return isEnumType(info->metaObject(), enumName); + } + } + } + } + return false; +} + +PyObject* PythonQtPrivate::wrapQObject(QObject* obj) +{ + if (!obj) { + Py_INCREF(Py_None); + return Py_None; + } + PythonQtWrapper* wrap = _wrappedObjects.value(obj); + if (!wrap) { + // smuggling it in... + PythonQtClassInfo* classInfo = _knownQtClasses.value(obj->metaObject()->className()); + if (!classInfo) { + registerClass(obj->metaObject()); + classInfo = _knownQtClasses.value(obj->metaObject()->className()); + } + wrap = createNewPythonQtWrapper(obj, classInfo); + // insert destroyed handler + connect(obj, SIGNAL(destroyed(QObject*)), this, SLOT(wrappedObjectDestroyed(QObject*))); + // mlabDebugConst("MLABPython","new qobject wrapper added " << " " << wrap->_obj->className() << " " << wrap->_info->wrappedClassName().latin1()); + } else { + Py_INCREF(wrap); + // mlabDebugConst("MLABPython","qobject wrapper reused " << wrap->_obj->className() << " " << wrap->_info->wrappedClassName().latin1()); + } + return (PyObject*)wrap; +} + +PyObject* PythonQtPrivate::wrapPtr(void* ptr, const QByteArray& name) +{ + if (!ptr) { + Py_INCREF(Py_None); + return Py_None; + } + PythonQtWrapper* wrap = _wrappedObjects.value(ptr); + if (!wrap) { + PythonQtClassInfo* info = _knownQtClasses.value(name); + if (!info) { + // we do not know the metaobject yet, but we might know it by it's name: + if (_knownQObjectClassNames.find(name)!=_knownQObjectClassNames.end()) { + // yes, we know it, so we can convert to QObject + QObject* qptr = (QObject*)ptr; + registerClass(qptr->metaObject()); + info = _knownQtClasses.value(qptr->metaObject()->className()); + } + } + if (info) { + QObject* qptr = (QObject*)ptr; + // if the object is a derived object, we want to switch the class info to the one of the derived class: + if (name!=(qptr->metaObject()->className())) { + registerClass(qptr->metaObject()); + info = _knownQtClasses.value(qptr->metaObject()->className()); + } + wrap = createNewPythonQtWrapper(qptr, info); + // insert destroyed handler + connect(qptr, SIGNAL(destroyed(QObject*)), this, SLOT(wrappedObjectDestroyed(QObject*))); + // mlabDebugConst("MLABPython","new qobject wrapper added " << " " << wrap->_obj->className() << " " << wrap->_info->wrappedClassName().latin1()); + } else { + // maybe it is a PyObject, which we can return directly + if (name == "PyObject") { + PyObject* p = (PyObject*)ptr; + Py_INCREF(p); + return p; + } + // not a known QObject, so try our wrapper factory: + QObject* wrapper = NULL; + for (int i=0; i<_cppWrapperFactories.size(); i++) { + wrapper = _cppWrapperFactories.at(i)->create(name, ptr); + if (wrapper) { + break; + } + } + PythonQtClassInfo* info = _knownQtWrapperClasses.value(name); + if (!info) { + info = new PythonQtClassInfo(wrapper?wrapper->metaObject():&QObject::staticQtMetaObject, name); + _knownQtWrapperClasses.insert(name, info); + PyModule_AddObject(_pythonQtModule, name, (PyObject*)createNewPythonQtMetaObjectWrapper(info)); + } else { + if (wrapper && (info->metaObject() != wrapper->metaObject())) { + info->setMetaObject(wrapper->metaObject()); + } + } + wrap = createNewPythonQtWrapper(wrapper, info, ptr); + // mlabDebugConst("MLABPython","new c++ wrapper added " << wrap->_wrappedPtr << " " << wrap->_obj->className() << " " << wrap->_info->wrappedClassName().latin1()); + } + } else { + Py_INCREF(wrap); + //mlabDebugConst("MLABPython","c++ wrapper reused " << wrap->_wrappedPtr << " " << wrap->_obj->className() << " " << wrap->_info->wrappedClassName().latin1()); + } + return (PyObject*)wrap; +} + +void PythonQt::registerCPPClassNames(const QStringList& names) +{ + foreach ( QString n, names) { + QByteArray name = n.toLatin1(); + PythonQtClassInfo* info = _p->_knownQtWrapperClasses.value(name); + if (!info) { + info = new PythonQtClassInfo(&QObject::staticMetaObject, name); + _p->_knownQtWrapperClasses.insert(name, info); + PyModule_AddObject(_p->_pythonQtModule, name.data(), (PyObject*)_p->createNewPythonQtMetaObjectWrapper(info)); + } + } +} + +PythonQtWrapper* PythonQtPrivate::createNewPythonQtWrapper(QObject* obj, PythonQtClassInfo* info, void* wrappedPtr) { + PythonQtWrapper* result; + result = (PythonQtWrapper *)PythonQtWrapper_Type.tp_new(&PythonQtWrapper_Type, + NULL, NULL); + + result->_obj = obj; + result->_info = info; + result->_wrappedPtr = wrappedPtr; + result->_ownedByPythonQt = false; + + if (wrappedPtr) { + _wrappedObjects.insert(wrappedPtr, result); + } else { + _wrappedObjects.insert(obj, result); + } + return result; +} + +PythonQtVariantWrapper* PythonQtPrivate::createNewPythonQtVariantWrapper(const QVariant& variant) { + PythonQtVariantWrapper* result; + result = (PythonQtVariantWrapper *)PythonQtVariantWrapper_Type.tp_new(&PythonQtVariantWrapper_Type, + NULL, NULL); + + *result->_variant = variant; + QPair pair = _knownVariantWrappers.value(variant.userType()); + result->_wrapper = pair.second; + result->_info = pair.first; + return result; +} + +PythonQtMetaObjectWrapper* PythonQtPrivate::createNewPythonQtMetaObjectWrapper(PythonQtClassInfo* info) { + PythonQtMetaObjectWrapper* result; + result = (PythonQtMetaObjectWrapper *)PythonQtMetaObjectWrapper_Type.tp_new(&PythonQtMetaObjectWrapper_Type, + NULL, NULL); + result->_info = info; + return result; +} + + +PythonQtSignalReceiver* PythonQt::getSignalReceiver(QObject* obj) +{ + PythonQtSignalReceiver* r = _p->_signalReceivers[obj]; + if (!r) { + r = new PythonQtSignalReceiver(obj); + _p->_signalReceivers.insert(obj, r); + // insert destroyed handler + connect(obj, SIGNAL(destroyed(QObject*)), _p ,SLOT(destroyedSignalEmitter(QObject*))); + } + return r; +} + +bool PythonQt::addSignalHandler(QObject* obj, const char* signal, PyObject* module, const QString& objectname) +{ + bool flag = false; + PythonQtObjectPtr callable = lookupCallable(module, objectname); + if (callable) { + PythonQtSignalReceiver* r = getSignalReceiver(obj); + flag = r->addSignalHandler(signal, callable); + if (!flag) { + // signal not found + } + } else { + // callable not found + } + return flag; +} + +bool PythonQt::addSignalHandler(QObject* obj, const char* signal, PyObject* receiver) +{ + bool flag = false; + PythonQtSignalReceiver* r = getSignalReceiver(obj); + if (r) { + flag = r->addSignalHandler(signal, receiver); + } + return flag; +} + +bool PythonQt::removeSignalHandler(QObject* obj, const char* signal, PyObject* module, const QString& objectname) +{ + bool flag = false; + PythonQtObjectPtr callable = lookupCallable(module, objectname); + if (callable) { + PythonQtSignalReceiver* r = _p->_signalReceivers[obj]; + if (r) { + flag = r->removeSignalHandler(signal, callable); + } + } else { + // callable not found + } + return flag; +} + +bool PythonQt::removeSignalHandler(QObject* obj, const char* signal, PyObject* receiver) +{ + bool flag = false; + PythonQtSignalReceiver* r = _p->_signalReceivers[obj]; + if (r) { + flag = r->removeSignalHandler(signal, receiver); + } + return flag; +} + +PythonQtObjectPtr PythonQt::lookupCallable(PyObject* module, const QString& name) +{ + PythonQtObjectPtr p = lookupObject(module, name); + if (p) { + if (PyCallable_Check(p)) { + return p; + } + } + PyErr_Clear(); + return NULL; +} + +PythonQtObjectPtr PythonQt::lookupObject(PyObject* module, const QString& name) +{ + QStringList l = name.split('.'); + PythonQtObjectPtr p = module; + PythonQtObjectPtr prev; + QString s; + QByteArray b; + for (QStringList::ConstIterator i = l.begin(); i!=l.end() && p; ++i) { + prev = p; + b = (*i).toLatin1(); + p.setNewRef(PyObject_GetAttrString(p, b.data())); + } + PyErr_Clear(); + return p; +} + +PythonQtObjectPtr PythonQt::getMainModule() { + //both borrowed + PythonQtObjectPtr dict = PyImport_GetModuleDict(); + return PyDict_GetItemString(dict, "__main__"); +} + +QVariant PythonQt::evalCode(PyObject* module, PyObject* pycode) { + QVariant result; + if (pycode) { + PyObject* r = PyEval_EvalCode((PyCodeObject*)pycode, PyModule_GetDict((PyObject*)module) , PyModule_GetDict((PyObject*)module)); + if (r) { + result = PythonQtConv::PyObjToQVariant(r); + Py_DECREF(r); + } else { + handleError(); + } + } else { + handleError(); + } + return result; +} + +QVariant PythonQt::evalScript(PyObject* module, const QString& script, int start) +{ + QVariant result; + PythonQtObjectPtr p; + p.setNewRef(PyRun_String(script.toLatin1().data(), start, PyModule_GetDict(module), PyModule_GetDict(module))); + if (p) { + result = PythonQtConv::PyObjToQVariant(p); + } else { + handleError(); + } + return result; +} + +void PythonQt::evalFile(PyObject* module, const QString& filename) +{ + PythonQtObjectPtr code = parseFile(filename); + if (code) { + evalCode(module, code); + } else { + handleError(); + } +} + +PythonQtObjectPtr PythonQt::parseFile(const QString& filename) +{ + PythonQtObjectPtr p; + p.setNewRef(PythonQtImport::getCodeFromPyc(filename)); + if (!p) { + handleError(); + } + return p; +} + +void PythonQt::addObject(PyObject* module, const QString& name, QObject* object) +{ + PyModule_AddObject(module, name.toLatin1().data(), _p->wrapQObject(object)); +} + +void PythonQt::addVariable(PyObject* module, const QString& name, const QVariant& v) +{ + PyModule_AddObject(module, name.toLatin1().data(), PythonQtConv::QVariantToPyObject(v)); +} + +void PythonQt::removeVariable(PyObject* module, const QString& name) +{ + PyObject_DelAttrString(module, name.toLatin1().data()); +} + +QVariant PythonQt::getVariable(PyObject* module, const QString& objectname) +{ + QVariant result; + PythonQtObjectPtr obj = lookupObject(module, objectname); + if (obj) { + result = PythonQtConv::PyObjToQVariant(obj); + } + return result; +} + +QStringList PythonQt::introspection(PyObject* module, const QString& objectname, PythonQt::ObjectType type) +{ + QStringList results; + + PythonQtObjectPtr object; + if (objectname.isEmpty()) { + object = module; + } else { + object = lookupObject(module, objectname); + if (!object && type == CallOverloads) { + PyObject* dict = lookupObject(module, "__builtins__"); + if (dict) { + object = PyDict_GetItemString(dict, objectname.toLatin1().constData()); + } + } + } + + if (object) { + if (type == CallOverloads) { + if (PythonQtSlotFunction_Check(object)) { + PythonQtSlotFunctionObject* o = (PythonQtSlotFunctionObject*)object.object(); + PythonQtSlotInfo* info = o->m_ml; + + while (info) { + results << info->fullSignature(info->isInstanceDecorator() || o->m_self->ob_type == &PythonQtVariantWrapper_Type); + info = info->nextInfo(); + } + } else if (object->ob_type == &PythonQtMetaObjectWrapper_Type) { + PythonQtMetaObjectWrapper* o = (PythonQtMetaObjectWrapper*)object.object(); + PythonQtSlotInfo* info = o->_info->constructors(); + + while (info) { + results << info->fullSignature(false); + info = info->nextInfo(); + } + } else { + //TODO: use pydoc! + PyObject* doc = PyObject_GetAttrString(object, "__doc__"); + if (doc) { + results << PyString_AsString(doc); + Py_DECREF(doc); + } + } + } else { + PyObject* keys = PyObject_Dir(object); + if (keys) { + int count = PyList_Size(keys); + PyObject* key; + PyObject* value; + QString keystr; + for (int i = 0;iob_type == &PyClass_Type) { + results << keystr; + } + break; + case Variable: + if (value->ob_type != &PyClass_Type + && value->ob_type != &PyCFunction_Type + && value->ob_type != &PyFunction_Type + && value->ob_type != &PyModule_Type + ) { + results << keystr; + } + break; + case Function: + if (value->ob_type == &PyFunction_Type || + value->ob_type == &PyMethod_Type + ) { + results << keystr; + } + break; + case Module: + if (value->ob_type == &PyModule_Type) { + results << keystr; + } + break; + default: + std::cerr << "PythonQt: introspection: unknown case" << ", in " << __FILE__ << ":" << __LINE__ << std::endl; + } + } + Py_DECREF(value); + } + Py_DECREF(keys); + } + } + } + return results; +} + +QVariant PythonQt::call(PyObject* module, const QString& name, const QVariantList& args) +{ + QVariant r; + + PythonQtObjectPtr callable = lookupCallable(module, name); + if (callable) { + PythonQtObjectPtr pargs; + int count = args.size(); + if (count>0) { + pargs.setNewRef(PyTuple_New(count)); + } + bool err = false; + // transform QVariants to Python + for (int i = 0; i < count; i++) { + PyObject* arg = PythonQtConv::QVariantToPyObject(args.at(i)); + if (arg) { + // steals reference, no unref + PyTuple_SetItem(pargs, i,arg); + } else { + err = true; + break; + } + } + + if (!err) { + PyErr_Clear(); + PythonQtObjectPtr result; + result.setNewRef(PyObject_CallObject(callable, pargs)); + if (result) { + // ok + r = PythonQtConv::PyObjToQVariant(result); + } else { + PythonQt::self()->handleError(); + } + } + } + return r; +} + +void PythonQt::addInstanceDecorators(QObject* o) +{ + _p->addDecorators(o, true, false); +} + +void PythonQt::addClassDecorators(QObject* o) +{ + _p->addDecorators(o, false, true); +} + +void PythonQt::addDecorators(QObject* o) +{ + _p->addDecorators(o, true, true); +} + +void PythonQt::registerQObjectClassNames(const QStringList& names) +{ + _p->registerQObjectClassNames(names); +} + +void PythonQt::setImporter(PythonQtImportFileInterface* importInterface) +{ + static bool first = true; + if (first) { + first = false; + _p->_importInterface = importInterface; + PythonQtImport::init(); + } +} + +void PythonQt::setImporterIgnorePaths(const QStringList& paths) +{ + _p->_importIgnorePaths = paths; +} + +const QStringList& PythonQt::getImporterIgnorePaths() +{ + return _p->_importIgnorePaths; +} + +void PythonQt::addWrapperFactory(PythonQtCppWrapperFactory* factory) +{ + _p->_cppWrapperFactories.append(factory); +} + +void PythonQt::addConstructorHandler(PythonQtConstructorHandler* factory) +{ + _p->_constructorHandlers.append(factory); +} + +const QList& PythonQt::constructorHandlers() +{ + return _p->_constructorHandlers; +}; + +//--------------------------------------------------------------------------------------------------- +PythonQtPrivate::PythonQtPrivate() +{ + _importInterface = NULL; +} + +void PythonQtPrivate::addDecorators(QObject* o, bool instanceDeco, bool classDeco) +{ + o->setParent(this); + int numMethods = o->metaObject()->methodCount(); + for (int i = 0; i < numMethods; i++) { + QMetaMethod m = o->metaObject()->method(i); + if ((m.methodType() == QMetaMethod::Method || + m.methodType() == QMetaMethod::Slot) && m.access() == QMetaMethod::Public) { + const PythonQtMethodInfo* info = PythonQtMethodInfo::getCachedMethodInfo(m); + if (qstrncmp(m.signature(), "new_", 4)==0) { + if (!classDeco) continue; + // either it returns a * or a QVariant and the name starts with "new_" + bool isVariantReturn = info->parameters().at(0).typeId == PythonQtMethodInfo::Variant; + if ((info->parameters().at(0).isPointer || isVariantReturn)) { + QByteArray signature = m.signature(); + QByteArray nameOfClass = signature.mid(4, signature.indexOf('(')-4); + PythonQtSlotInfo* prev = _constructorSlots.value(nameOfClass); + PythonQtSlotInfo* newSlot = new PythonQtSlotInfo(m, i, o, PythonQtSlotInfo::ClassDecorator); + if (prev) { + newSlot->setNextInfo(prev->nextInfo()); + prev->setNextInfo(newSlot); + } else { + _constructorSlots.insert(nameOfClass, newSlot); + } + } + } else if (qstrncmp(m.signature(), "delete_", 7)==0) { + if (!classDeco) continue; + QByteArray signature = m.signature(); + QByteArray nameOfClass = signature.mid(7, signature.indexOf('(')-7); + PythonQtSlotInfo* newSlot = new PythonQtSlotInfo(m, i, o, PythonQtSlotInfo::ClassDecorator); + _destructorSlots.insert(nameOfClass, newSlot); + } else if (qstrncmp(m.signature(), "static_", 7)==0) { + if (!classDeco) continue; + QByteArray signature = m.signature(); + QByteArray nameOfClass = signature.mid(signature.indexOf('_')+1); + nameOfClass = nameOfClass.mid(0, nameOfClass.indexOf('_')); + PythonQtSlotInfo* slotCopy = new PythonQtSlotInfo(m, i, o, PythonQtSlotInfo::ClassDecorator); + _knownQtDecoratorSlots.insert(nameOfClass, slotCopy); + } else { + if (!instanceDeco) continue; + if (info->parameters().count()>1) { + PythonQtMethodInfo::ParameterInfo p = info->parameters().at(1); + if (p.isPointer) { + PythonQtSlotInfo* slotCopy = new PythonQtSlotInfo(m, i, o, PythonQtSlotInfo::InstanceDecorator); + _knownQtDecoratorSlots.insert(p.name, slotCopy); + } + } + } + } + } +} + +void PythonQtPrivate::registerQObjectClassNames(const QStringList& names) +{ + foreach(QString name, names) { + _knownQObjectClassNames.insert(name.toLatin1(), true); + } +} + +QList PythonQtPrivate::getDecoratorSlots(const QByteArray& className) +{ + return _knownQtDecoratorSlots.values(className); +} + +void PythonQtPrivate::wrappedObjectDestroyed(QObject* obj) +{ + // mlabDebugConst("MLABPython","PyWrapper QObject destroyed " << o << " " << o->name() << " " << o->className()); + PythonQtWrapper* wrap = _wrappedObjects[obj]; + if (wrap) { + _wrappedObjects.remove(obj); + // remove the pointer but keep the wrapper alive in python + wrap->_obj = NULL; + } +} + +void PythonQtPrivate::destroyedSignalEmitter(QObject* obj) +{ + _signalReceivers.take(obj); +} + +bool PythonQt::handleError() +{ + bool flag = false; + if (PyErr_Occurred()) { + + // currently we just print the error and the stderr handler parses the errors + PyErr_Print(); + + /* + // EXTRA: the format of the ptype and ptraceback is not really documented, so I use PyErr_Print() above + PyObject *ptype; + PyObject *pvalue; + PyObject *ptraceback; + PyErr_Fetch( &ptype, &pvalue, &ptraceback); + + Py_XDECREF(ptype); + Py_XDECREF(pvalue); + Py_XDECREF(ptraceback); + */ + PyErr_Clear(); + flag = true; + } + return flag; +} + +void PythonQt::overwriteSysPath(const QStringList& paths) +{ + PythonQtObjectPtr sys; + sys.setNewRef(PyImport_ImportModule("sys")); + PyModule_AddObject(sys, "path", PythonQtConv::QStringListToPyList(paths)); +} + +void PythonQt::setModuleImportPath(PyObject* module, const QStringList& paths) +{ + PyModule_AddObject(module, "__path__", PythonQtConv::QStringListToPyList(paths)); +} + +void PythonQt::stdOutRedirectCB(const QString& str) +{ + emit PythonQt::self()->pythonStdOut(str); +} + +void PythonQt::stdErrRedirectCB(const QString& str) +{ + emit PythonQt::self()->pythonStdErr(str); +} + + + +static PyMethodDef PythonQtMethods[] = { + {NULL, NULL, 0, NULL} +}; + +void PythonQt::initPythonQtModule(bool redirectStdOut) +{ + _p->_pythonQtModule.setNewRef(Py_InitModule("PythonQt", PythonQtMethods)); + _p->_qtNamespace = new PythonQtClassInfo(&staticQtMetaObject); + PyModule_AddObject(_p->_pythonQtModule, "Qt", (PyObject*)_p->createNewPythonQtMetaObjectWrapper(_p->_qtNamespace)); + + if (redirectStdOut) { + PythonQtObjectPtr sys; + PythonQtObjectPtr out; + PythonQtObjectPtr err; + sys.setNewRef(PyImport_ImportModule("sys")); + // create a redirection object for stdout and stderr + out = PythonQtStdOutRedirectType.tp_new(&PythonQtStdOutRedirectType,NULL, NULL); + ((PythonQtStdOutRedirect*)out.object())->_cb = stdOutRedirectCB; + err = PythonQtStdOutRedirectType.tp_new(&PythonQtStdOutRedirectType,NULL, NULL); + ((PythonQtStdOutRedirect*)err.object())->_cb = stdErrRedirectCB; + // replace the built in file objects with our own objects + PyModule_AddObject(sys, "stdout", out); + PyModule_AddObject(sys, "stderr", err); + } +} + +void PythonQt::addVariantWrapper(const char* typeName, QObject* wrapper) +{ + _p->addVariantWrapper(typeName, wrapper); +} + + +void PythonQtPrivate::addVariantWrapper(const char* typeName, QObject* wrapper) +{ + int type = QMetaType::type(typeName); + PythonQtClassInfo* info = new PythonQtClassInfo(wrapper->metaObject(), typeName); + _knownVariantWrappers.insert(type, qMakePair(info, wrapper)); + addDecorators(wrapper, false, true); + PyModule_AddObject(_pythonQtModule, typeName, (PyObject*)createNewPythonQtMetaObjectWrapper(info)); +} + +PyObject* PythonQt::helpCalled(PythonQtClassInfo* info) +{ + if (_p->_initFlags & ExternalHelp) { + emit pythonHelpRequest(QByteArray(info->className())); + return Py_BuildValue(""); + } else { + return PyString_FromString(info->help().toLatin1().data()); + } +} diff --git a/src/PythonQt.h b/src/PythonQt.h new file mode 100644 index 0000000..ded792b --- /dev/null +++ b/src/PythonQt.h @@ -0,0 +1,436 @@ +#ifndef _PYTHONQT_H +#define _PYTHONQT_H + +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQt.h +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-05 +*/ +//---------------------------------------------------------------------------------- + +#include "PythonQtSystem.h" +#include "PythonQtWrapper.h" +#include "PythonQtVariantWrapper.h" +#include "PythonQtMetaObjectWrapper.h" +#include "PythonQtSlot.h" +#include "PythonQtObjectPtr.h" +#include +#include +#include +#include +#include +#include +#include +#include + + +class PythonQtClassInfo; +class PythonQtPrivate; +class PythonQtMethodInfo; +class PythonQtSignalReceiver; +class PythonQtImportFileInterface; +class PythonQtCppWrapperFactory; +class PythonQtConstructorHandler; + +//! the main interface to the Python Qt binding, realized as a singleton +class PYTHONQT_EXPORT PythonQt : public QObject { + + Q_OBJECT + +public: + enum InitFlags { + RedirectStdOut = 1, //!<< sets if the std out/err is redirected to pythonStdOut() and pythonStdErr() signals + IgnoreSiteModule = 2, //!<< sets if Python should ignore the site module + ExternalHelp = 4 //!<< sets if help() calls on PythonQt modules are forwarded to the pythonHelpRequest() signal + }; + + //! initialize the python qt binding (flags are a or combination of InitFlags) + static void init(int flags = IgnoreSiteModule | RedirectStdOut); + + //! cleanup + static void cleanup(); + + //! get the singleton instance + static PythonQt* self() { return _self; } + + //----------------------------------------------------------------------------- + // Public API: + + //! defines the object types for introspection + enum ObjectType { + Class, + Function, + Variable, + Module, + Anything, + CallOverloads + }; + + //! overwrite the python sys path (call this directly after PythonQt::init() if you want to change the std python sys path) + void overwriteSysPath(const QStringList& paths); + + //! sets the __path__ list of a module to the given list (important for local imports) + void setModuleImportPath(PyObject* module, const QStringList& paths); + + //! get the __main__ module of python + PythonQtObjectPtr getMainModule(); + + //! registers a QObject derived class to PythonQt (this is implicitly called by addObject as well) + //! All added metaobjects will be visible under the className in the PythonQt module as MetaObjectWrappers and the enums + //! and constructors (added by addConstructors) will be available. + /* Since Qt4 does not offer a way to detect if a given classname is derived from QObject and thus has a QMetaObject, + you MUST register all your QObject derived classes here when you want them to be detected in signal and slot calls */ + void registerClass(const QMetaObject* metaobject); + + //! as an alternative to registerClass, you can tell PythonQt the names of QObject derived classes + //! and it will register the classes when it first sees a pointer to such a derived class + void registerQObjectClassNames(const QStringList& names); + + //! this will register CPP classnames as known CPP classes (NOT QObjects) and make their MetaObjectWrapper available in + //! the PythonQt module. In combination with addConstuctors(), this can be used to create CPP objects from PythonQt + void registerCPPClassNames(const QStringList& names); + + //! parses the given file and returns the python code object, this can then be used to call evalCode() + PythonQtObjectPtr parseFile(const QString& filename); + + //! evaluates the given code and returns the result value (use Py_Compile etc. to create pycode from string) + //! If pycode is NULL, a python error is printed. + QVariant evalCode(PyObject* module, PyObject* pycode); + + //! evaluates the given script code and returns the result value + QVariant evalScript(PyObject* module, const QString& script, int start = Py_file_input); + + //! evaluates the given script code from file + void evalFile(PyObject* module, const QString& filename); + + //@{ Signal handlers + + //! add a signal handler to the given \c signal of \c obj and connect it to a callable \c objectname in module + bool addSignalHandler(QObject* obj, const char* signal, PyObject* module, const QString& objectname); + + //! remove a signal handler from the given \c signal of \c obj + bool removeSignalHandler(QObject* obj, const char* signal, PyObject* module, const QString& objectname); + + //! add a signal handler to the given \c signal of \c obj and connect it to a callable \c receiver + bool addSignalHandler(QObject* obj, const char* signal, PyObject* receiver); + + //! remove a signal handler from the given \c signal of \c obj + bool removeSignalHandler(QObject* obj, const char* signal, PyObject* receiver); + + //@} + + //@{ Variable access + + //! add the given \c object to the \c module as a variable with \c name (it can be removed via clearVariable) + void addObject(PyObject* module, const QString& name, QObject* object); + + //! add the given variable to the module + void addVariable(PyObject* module, const QString& name, const QVariant& v); + + //! remove the given variable + void removeVariable(PyObject* module, const QString& name); + + //! get the variable with the \c name of the \c module, returns an invalid QVariant on error + QVariant getVariable(PyObject* module, const QString& name); + + //! read vars etc. in scope of a module, optional looking inside of an object \c objectname + QStringList introspection(PyObject* module, const QString& objectname, ObjectType type); + + //! returns the found callable object or NULL + //! @return new reference + PythonQtObjectPtr lookupCallable(PyObject* module, const QString& name); + + //@} + + //@{ Calling of python callables + + //! call the given python method, returns the result converted to a QVariant + QVariant call(PyObject* module, const QString& callable, const QVariantList& args); + + //@} + + //@{ Decorations, constructors, wrappers... + + + //! add an object whose slots will be used as decorator slots for + //! other QObjects or CPP classes. The slots need to follow the + //! convention that the first argument is a pointer to the wrapped object. + //! (ownership is passed to PythonQt) + /*! + Example: + + A slot with the signature + + \code + bool doSomething(QWidget* w, int a) + \endcode + + will extend QWidget instances (and derived classes) with a "bool doSomething(int a)" slot + that will be called with the concrete instance as first argument. + So in Python you can now e.g. call + + \code + someWidget.doSomething(12) + \endcode + + without QWidget really having this method. This allows to easily make normal methods + of Qt classes callable by forwarding them with such decorator slots + or to make CPP classes (which are not derived from QObject) callable from Python. + */ + void addInstanceDecorators(QObject* o); + + //! add an object whose slots will be used as decorator slots for + //! class objects (ownership is passed to PythonQt) + /*! + The slots need to follow the following convention: + - SomeClass* new_SomeClass(...) + - QVariant new_SomeClass(...) + - void delete_SomeClass(SomeClass*) + - ... static_SomeClass_someName(...) + + This will add: + - a constructor + - a constructor which generates a QVariant + - a destructor (only useful for CPP objects) + - a static decorator slot which will be available on the MetaObject (visible in PythonQt module) + + */ + void addClassDecorators(QObject* o); + + //! this will add the object both as class and instance decorator (ownership is passed to PythonQt) + void addDecorators(QObject* o); + + //! add a wrapper object for the given QMetaType typeName, also does an addClassDecorators() to add constructors for variants + //! (ownership of wrapper is passed to PythonQt) + /*! Make sure that you have done a qRegisterMetaType first, if typeName is a user type! + + This will add a wrapper object that is used to make calls to the given classname \c typeName. + All slots that take a pointer to typeName as the first argument will be callable from Python on + a variant object that contains such a type. + */ + void addVariantWrapper(const char* typeName, QObject* wrapper); + + //! add the given factory to PythonQt (ownership stays with caller) + void addWrapperFactory(PythonQtCppWrapperFactory* factory); + + //! add the given constructor handler to PythonQt (ownership stays with caller) + void addConstructorHandler(PythonQtConstructorHandler* handler); + + //! get list of constructor handlers + const QList& constructorHandlers(); + + //@} + + //@{ Custom importer (to replace internal import implementation of python) + + //! replace the internal import implementation and use the supplied interface to load files (both py and pyc files) + //! (this method should be called directly after initialization of init() and before calling overwriteSysPath(). + //! It can only be called once, further calls will be ignored silently. (ownership stays with caller) + void setImporter(PythonQtImportFileInterface* importInterface); + + //! set paths that the importer should ignore + void setImporterIgnorePaths(const QStringList& paths); + + //! get paths that the importer should ignore + const QStringList& getImporterIgnorePaths(); + + //@} + + //! get access to internal data (should not be used on the public API, but is used by some C functions) + static PythonQtPrivate* priv() { return _self->_p; } + + //! get access to the file importer (if set) + static PythonQtImportFileInterface* importInterface(); + + //! handle a python error, call this when a python function fails. If no error occurred, it returns false. + //! The error is currently just output to the python stderr, future version might implement better trace printing + bool handleError(); + +signals: + //! emitted when python outputs something to stdout (and redirection is turned on) + void pythonStdOut(const QString& str); + //! emitted when python outputs something to stderr (and redirection is turned on) + void pythonStdErr(const QString& str); + + //! emitted when help() is called on a PythonQt object and \c ExternalHelp is enabled + void pythonHelpRequest(const QByteArray& cppClassName); + + +public: + //! called by internal help methods + PyObject* helpCalled(PythonQtClassInfo* info); + + //! returns the found object or NULL + //! @return new reference + PythonQtObjectPtr lookupObject(PyObject* module, const QString& name); + +private: + void initPythonQtModule(bool redirectStdOut); + + //! callback for stdout redirection, emits pythonStdOut signal + static void stdOutRedirectCB(const QString& str); + //! callback for stderr redirection, emits pythonStdErr signal + static void stdErrRedirectCB(const QString& str); + + //! get (and create if not available) the signal receiver of that QObject, signal receiver is made child of the passed \c obj + PythonQtSignalReceiver* getSignalReceiver(QObject* obj); + + PythonQt(int flags); + ~PythonQt(); + + static PythonQt* _self; + + PythonQtPrivate* _p; + +}; + +//! internal PythonQt details +class PythonQtPrivate : public QObject { + + Q_OBJECT + +public: + PythonQtPrivate(); + ~PythonQtPrivate(); + + //! returns if the id is the id for PythonQtObjectPtr + bool isPythonQtObjectPtrMetaId(int id) { return _PythonQtObjectPtr_metaId == id; } + + //! remove the wrapper ptr again + void removeWrapperPointer(void* obj) { _wrappedObjects.take(obj); } + + //! wrap the given QObject into a Python object (or return existing wrapper!) + PyObject* wrapQObject(QObject* obj); + + //! wrap the given ptr into a Python object (or return existing wrapper!) if there is a known QObject of that name or a known wrapper in the factory + PyObject* wrapPtr(void* ptr, const QByteArray& name); + + //! registers a QObject derived class to PythonQt (this is implicitly called by addObject as well) + /* Since Qt4 does not offer a way to detect if a given classname is derived from QObject and thus has a QMetaObject, + you MUST register all your QObject derived classes here when you want them to be detected in signal and slot calls */ + void registerClass(const QMetaObject* metaobject); + + //! as an alternative to registerClass, you can tell PythonQt the names of QObject derived classes + //! and it will register the classes when it first sees a pointer to such a derived class + void registerQObjectClassNames(const QStringList& names); + + //! add a decorator object + void addDecorators(QObject* o, bool instanceDeco, bool classDeco); + + //! add a wrapper object for the given qvariant, also does an addConstructors() to add constructors for variants + void addVariantWrapper(const char* typeName, QObject* wrapper); + + //! get list of all slots that are available as decorator slots + QList getDecoratorSlots(const QByteArray& className); + + //! check if the enum is either part of the \c meta class or contains a scope and is + //! an enum of another known metaobject (and as last resort, of the Qt namespace) + bool isEnumType(const QMetaObject* meta, const QByteArray& name); + + //! helper method that creates a PythonQtMetaObjectWrapper object + PythonQtMetaObjectWrapper* createNewPythonQtMetaObjectWrapper(PythonQtClassInfo* info); + + //! helper method that creates a PythonQtWrapper object and registers it in the object map + PythonQtWrapper* createNewPythonQtWrapper(QObject* obj, PythonQtClassInfo* info, void* wrappedPtr = NULL); + + //! helper method that creates a PythonQtVariantWrapper object + PythonQtVariantWrapper* createNewPythonQtVariantWrapper(const QVariant& variant); + + //! get the class info for a meta object (if available) + PythonQtClassInfo* getClassInfo(const QMetaObject* meta) { return _knownQtClasses.value(meta->className()); } + + //! get the constructor slot for the given classname + PythonQtSlotInfo* getConstructorSlot(const QByteArray& className) { return _constructorSlots.value(className); } + + //! get the destructor slot for the given classname + PythonQtSlotInfo* getDestructorSlot(const QByteArray& className) { return _destructorSlots.value(className); } + +protected slots: + //! called when a wrapped QObject is destroyed + void wrappedObjectDestroyed(QObject* obj); + + //! called when a signal emitting QObject is destroyed to remove the signal handler from the hash map + void destroyedSignalEmitter(QObject* obj); + +private: + + //! stores pointer to PyObject mapping of wrapped QObjects AND C++ objects + QHash _wrappedObjects; + + //! stores the meta info of known Qt classes + QHash _knownQtClasses; + + //! stores the meta info of known Qt classes + QHash _knownQtWrapperClasses; + + //! stores the meta info of known Qt C++ wrapper classes + QMultiHash _knownQtDecoratorSlots; + + //! names of qobject derived classes that can be casted to qobject savely + QHash _knownQObjectClassNames; + + //! stores signal receivers for QObjects + QHash _signalReceivers; + + //! the PythonQt python module + PythonQtObjectPtr _pythonQtModule; + + //! the importer interface (if set) + PythonQtImportFileInterface* _importInterface; + + QStringList _importIgnorePaths; + + //! the cpp object wrapper factories + QList _cppWrapperFactories; + + //! the cpp object wrapper factories + QList _constructorHandlers; + + QHash _constructorSlots; + QHash _destructorSlots; + + QHash > _knownVariantWrappers; + + PythonQtClassInfo* _qtNamespace; + + int _initFlags; + int _PythonQtObjectPtr_metaId; + + friend class PythonQt; +}; + +#endif diff --git a/src/PythonQtClassInfo.cpp b/src/PythonQtClassInfo.cpp new file mode 100644 index 0000000..2687d0d --- /dev/null +++ b/src/PythonQtClassInfo.cpp @@ -0,0 +1,404 @@ +/* +* +* Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* Further, this software is distributed without any warranty that it is +* free of the rightful claim of any third person regarding infringement +* or the like. Any license provided herein, whether implied or +* otherwise, applies only to this software file. Patent licenses, if +* any, provided herein do not apply to combinations of this program with +* other software, or any other product whatsoever. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Contact information: MeVis Research GmbH, Universitaetsallee 29, +* 28359 Bremen, Germany or: +* +* http://www.mevis.de +* +*/ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQt.cpp +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-05 +*/ +//---------------------------------------------------------------------------------- + +#include "PythonQtClassInfo.h" +#include "PythonQtMethodInfo.h" +#include "PythonQt.h" +#include + +QHash PythonQtMethodInfo::_parameterTypeDict; + +PythonQtClassInfo::PythonQtClassInfo(const QMetaObject* meta, const QByteArray& wrappedClassName) { + _meta = meta; + _wrappedClassName = wrappedClassName; + _constructors = NULL; +} + +PythonQtClassInfo::~PythonQtClassInfo() +{ + QHashIterator i(_cachedMembers); + while (i.hasNext()) { + PythonQtMemberInfo member = i.next().value(); + if (member._type== PythonQtMemberInfo::Slot) { + PythonQtSlotInfo* info = member._slot; + while (info) { + PythonQtSlotInfo* next = info->nextInfo(); + delete info; + info = next; + } + } + } +} + +int PythonQtClassInfo::findCharOffset(const char* sigStart, char someChar) +{ + const char* sigEnd = sigStart; + char c; + do { + c = *sigEnd++; + } while (c!=someChar && c!=0); + return sigEnd-sigStart-1; +} + +PythonQtMemberInfo PythonQtClassInfo::member(const char* memberName) +{ + PythonQtMemberInfo info = _cachedMembers.value(memberName); + if (info._type != PythonQtMemberInfo::Invalid) { + return info; + } else { + bool found = false; + const char* attributeName = memberName; + bool nameMapped = false; + // look for properties + int i = _meta->indexOfProperty(attributeName); + if (i==-1) { + // try to map name to objectName + if (qstrcmp(attributeName, "name")==0) { + attributeName = "objectName"; + nameMapped = true; + i = _meta->indexOfProperty(attributeName); + } + } + if (i!=-1) { + PythonQtMemberInfo newInfo(_meta->property(i)); + _cachedMembers.insert(attributeName, newInfo); + if (nameMapped) { + _cachedMembers.insert(memberName, newInfo); + } +#ifdef PYTHONQT_DEBUG + std::cout << "caching property " << memberName << " on " << _meta->className() << std::endl; +#endif + found = true; + } else { + int memberNameLen = strlen(memberName); + // if it is not a property, look for slots + PythonQtSlotInfo* tail = NULL; + int numMethods = _meta->methodCount(); + for (int i = 0; i < numMethods; i++) { + QMetaMethod m = _meta->method(i); + if ((m.methodType() == QMetaMethod::Method || + m.methodType() == QMetaMethod::Slot) && m.access() == QMetaMethod::Public) { + + const char* sigStart = m.signature(); + // find the first '(' + int offset = findCharOffset(sigStart, '('); + + // check if same length and same name + if (memberNameLen == offset && qstrncmp(memberName, sigStart, offset)==0) { + found = true; + PythonQtSlotInfo* info = new PythonQtSlotInfo(m, i); + if (tail) { + tail->setNextInfo(info); + } else { + PythonQtMemberInfo newInfo(info); + _cachedMembers.insert(memberName, newInfo); + } + tail = info; + } + } + } + + // look for decorators + if (!_wrappedClassName.isEmpty()) { + tail = findDecoratorSlots(_wrappedClassName.constData(), memberName, memberNameLen, tail, found); + } + const QMetaObject* meta = _meta; + while (meta) { + tail = findDecoratorSlots(meta->className(), memberName, memberNameLen, tail, found); + meta = meta->superClass(); + } + + } + if (!found) { + // look for enum values + int enumCount = _meta->enumeratorCount(); + for (i=0;ienumerator(i); + for (int j=0; j < e.keyCount(); j++) { + if (qstrcmp(e.key(j), attributeName)==0) { + PythonQtMemberInfo newInfo(e.value(j)); + _cachedMembers.insert(memberName, newInfo); +#ifdef PYTHONQT_DEBUG + std::cout << "caching enum " << memberName << " on " << _meta->className() << std::endl; +#endif + found = true; + } + } + } + } + return _cachedMembers.value(memberName); + } +} + +PythonQtSlotInfo* PythonQtClassInfo::findDecoratorSlots(const char* classname, const char* memberName, int memberNameLen, PythonQtSlotInfo* tail, bool& found) +{ + QListIterator it(PythonQt::priv()->getDecoratorSlots(classname)); + while (it.hasNext()) { + + PythonQtSlotInfo* infoOrig = it.next(); + + const char* sigStart = infoOrig->metaMethod()->signature(); + if (qstrncmp("static_", sigStart, 7)==0) { + sigStart += 7; + sigStart += findCharOffset(sigStart, '_')+1; + } + int offset = findCharOffset(sigStart, '('); + if (memberNameLen == offset && qstrncmp(memberName, sigStart, offset)==0) { + //make a copy, otherwise we will have trouble on overloads! + PythonQtSlotInfo* info = new PythonQtSlotInfo(*infoOrig); + found = true; + if (tail) { + tail->setNextInfo(info); + } else { + PythonQtMemberInfo newInfo(info); + _cachedMembers.insert(memberName, newInfo); + } + tail = info; + } + } + return tail; +} + + +QStringList PythonQtClassInfo::memberList(bool metaOnly) +{ + QStringList l; + QString h; + if (_wrappedClassName.isEmpty()) { + int i; + int numProperties = _meta->propertyCount(); + for (i = 0; i < numProperties; i++) { + QMetaProperty p = _meta->property(i); + l << QString(p.name()); + } + } + + if (!metaOnly) { + int numMethods = _meta->methodCount(); + bool skipQObj = !_wrappedClassName.isEmpty(); + for (int i = skipQObj?QObject::staticMetaObject.methodCount():0; i < numMethods; i++) { + QMetaMethod m = _meta->method(i); + if ((m.methodType() == QMetaMethod::Method || + m.methodType() == QMetaMethod::Slot) && m.access() == QMetaMethod::Public) { + QByteArray signa(m.signature()); + if (signa.startsWith("new_")) continue; + if (signa.startsWith("delete_")) continue; + if (signa.startsWith("static_")) continue; + PythonQtSlotInfo slot(m, i); + l << slot.slotName(); + } + } + } + // look for decorators + QList names; + if (!_wrappedClassName.isEmpty()) { + names << _wrappedClassName.constData(); + } + const QMetaObject* meta = _meta; + while (meta) { + if (meta==&QObject::staticMetaObject && !_wrappedClassName.isEmpty()) break; + names << meta->className(); + meta = meta->superClass(); + } + + QListIterator nameIt(names); + while (nameIt.hasNext()) { + QListIterator it(PythonQt::priv()->getDecoratorSlots(nameIt.next())); + while (it.hasNext()) { + PythonQtSlotInfo* slot = it.next(); + if (metaOnly) { + if (slot->isClassDecorator()) { + QByteArray first = slot->slotName(); + if (first.startsWith("static_")) { + int idx = first.indexOf('_'); + idx = first.indexOf('_', idx+1); + first = first.mid(idx+1); + } + l << first; + } + } else { + l << slot->slotName(); + } + } + } + + if (_meta->enumeratorCount()) { + for (int i = 0; i<_meta->enumeratorCount(); i++) { + QMetaEnum e = _meta->enumerator(i); + for (int j=0; j < e.keyCount(); j++) { + l << QString(e.key(j)); + } + } + } + return l; +} + +const char* PythonQtClassInfo::className() +{ + if (!_wrappedClassName.isEmpty()) { + return _wrappedClassName.constData(); + } else { + return _meta->className(); + } +} + +bool PythonQtClassInfo::inherits(const char* name) +{ + const QMetaObject* m = _meta; + while (m) { + if (strcmp(name, m->className())==0) { + return true; + } + m = m->superClass(); + } + return false; +} + +const QByteArray& PythonQtClassInfo::wrappedCPPClassName() +{ + return _wrappedClassName; +} + +QString PythonQtClassInfo::help() +{ + QString h; + bool isVariant = QMetaType::type(className())!=QMetaType::Void; + h += QString("--- ") + QString(className()) + QString(" ---\n"); + + if (_wrappedClassName.isEmpty()) { + h += "Properties:\n"; + + int i; + int numProperties = _meta->propertyCount(); + for (i = 0; i < numProperties; i++) { + QMetaProperty p = _meta->property(i); + h += QString(p.name()) + " (" + QString(p.typeName()) + " )\n"; + } + } + + if (constructors()) { + h += "Constructors:\n"; + PythonQtSlotInfo* constr = constructors(); + while (constr) { + h += constr->fullSignature(false) + "\n"; + constr = constr->nextInfo(); + } + } + + h += "Slots:\n"; + h += "QString help()\n"; + h += "QString className()\n"; + + int numMethods = _meta->methodCount(); + for (int i = isVariant?QObject::staticMetaObject.methodCount():0; i < numMethods; i++) { + QMetaMethod m = _meta->method(i); + if ((m.methodType() == QMetaMethod::Method || + m.methodType() == QMetaMethod::Slot) && m.access() == QMetaMethod::Public) { + QByteArray signa(m.signature()); + if (signa.startsWith("new_")) continue; + if (signa.startsWith("delete_")) continue; + if (signa.startsWith("static_")) continue; + PythonQtSlotInfo slot(m, i); + h += slot.fullSignature(isVariant)+ "\n"; + } + } + // look for decorators + QList names; + if (!_wrappedClassName.isEmpty()) { + names << _wrappedClassName.constData(); + } + const QMetaObject* meta = _meta; + while (meta) { + names << meta->className(); + meta = meta->superClass(); + if (isVariant && meta==&QObject::staticMetaObject) break; + } + + QListIterator nameIt(names); + while (nameIt.hasNext()) { + QListIterator it(PythonQt::priv()->getDecoratorSlots(nameIt.next())); + while (it.hasNext()) { + PythonQtSlotInfo* slot = it.next(); + h += slot->fullSignature(slot->isInstanceDecorator()) + "\n"; + } + } + + if (_meta->enumeratorCount()) { + h += "Enums:\n"; + for (int i = 0; i<_meta->enumeratorCount(); i++) { + QMetaEnum e = _meta->enumerator(i); + h += QString(e.name()) + " {"; + for (int j=0; j < e.keyCount(); j++) { + if (j) { h+= ", "; } + h += e.key(j); + } + h += " }\n"; + } + } + + if (_wrappedClassName.isEmpty()) { + int numMethods = _meta->methodCount(); + if (numMethods>0) { + h += "Signals:\n"; + for (int i = isVariant?QObject::staticMetaObject.methodCount():0; i < numMethods; i++) { + QMetaMethod m = _meta->method(i); + if (m.methodType() == QMetaMethod::Signal) { + h += QString(m.signature()) + "\n"; + } + } + } + } + return h; +} + +PythonQtSlotInfo* PythonQtClassInfo::constructors() +{ + if (!_constructors) { + _constructors = PythonQt::priv()->getConstructorSlot(!_wrappedClassName.isEmpty()?_wrappedClassName:QByteArray(_meta->className())); + } + return _constructors; +} + +void PythonQtClassInfo::setMetaObject(const QMetaObject* meta) +{ + _meta = meta; + _cachedMembers.clear(); +} diff --git a/src/PythonQtClassInfo.h b/src/PythonQtClassInfo.h new file mode 100644 index 0000000..d9edfab --- /dev/null +++ b/src/PythonQtClassInfo.h @@ -0,0 +1,127 @@ +#ifndef _PYTHONQTCLASSINFO_H +#define _PYTHONQTCLASSINFO_H + +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +#include +#include +#include +#include +#include + +class PythonQtSlotInfo; + +struct PythonQtMemberInfo { + enum Type { + Invalid, Slot, EnumValue, Property + }; + + PythonQtMemberInfo() { _type = Invalid; } + + PythonQtMemberInfo(PythonQtSlotInfo* info) { + _type = Slot; + _slot = info; + _enumValue = 0; + } + + PythonQtMemberInfo(unsigned int enumValue) { + _type = EnumValue; + _slot = NULL; + _enumValue = enumValue; + } + + PythonQtMemberInfo(const QMetaProperty& prop) { + _type = Property; + _slot = NULL; + _enumValue = 0; + _property = prop; + } + + PythonQtSlotInfo* _slot; + unsigned int _enumValue; + QMetaProperty _property; + Type _type; +}; + +//! a class that stores all required information about a Qt object (and an optional associated C++ class name) +/*! for fast lookup of slots when calling the object from Python +*/ +class PythonQtClassInfo { + +public: + PythonQtClassInfo(const QMetaObject* meta, const QByteArray& wrappedClassName = QByteArray()); + + ~PythonQtClassInfo(); + + //! get the Python method definition for a given slot name (without return type and signature) + PythonQtMemberInfo member(const char* member); + + PythonQtSlotInfo* constructors(); + + //! get the Qt classname + const char* className(); + + //! get the classname of the wrapped C++ class + const QByteArray& wrappedCPPClassName(); + + //! returns if the object is a CPP wrapper + bool isCPPWrapper() { return !_wrappedClassName.isEmpty(); } + + //! get the meta object + const QMetaObject* metaObject() { return _meta; } + + //! set the meta object, this will reset the caching + void setMetaObject(const QMetaObject* meta); + + //! returns if the meta object inherits the given classname + bool inherits(const char* name); + + //! get help string for the metaobject + QString help(); + + //! get list of all members + QStringList memberList(bool metaOnly = false); + +private: + PythonQtSlotInfo* findDecoratorSlots(const char* classname, const char* memberName, int memberNameLen, PythonQtSlotInfo* tail, bool &found); + int findCharOffset(const char* sigStart, char someChar); + QHash _cachedMembers; + PythonQtSlotInfo* _constructors; + const QMetaObject* _meta; + QByteArray _wrappedClassName; +}; + +//--------------------------------------------------------------- + + +#endif diff --git a/src/PythonQtConversion.cpp b/src/PythonQtConversion.cpp new file mode 100644 index 0000000..507c1e2 --- /dev/null +++ b/src/PythonQtConversion.cpp @@ -0,0 +1,1012 @@ +/* +* +* Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* Further, this software is distributed without any warranty that it is +* free of the rightful claim of any third person regarding infringement +* or the like. Any license provided herein, whether implied or +* otherwise, applies only to this software file. Patent licenses, if +* any, provided herein do not apply to combinations of this program with +* other software, or any other product whatsoever. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Contact information: MeVis Research GmbH, Universitaetsallee 29, +* 28359 Bremen, Germany or: +* +* http://www.mevis.de +* +*/ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtConversion.cpp +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-05 +*/ +//---------------------------------------------------------------------------------- + +#include "PythonQtConversion.h" +#include "PythonQtVariants.h" +#include "PythonQtVariantWrapper.h" +#include +#include +#include + +PythonQtValueStorage PythonQtConv::global_valueStorage; +PythonQtValueStorage PythonQtConv::global_ptrStorage; +PythonQtValueStorage PythonQtConv::global_variantStorage; + + +PyObject* PythonQtConv::GetPyBool(bool val) +{ + PyObject* r = val?Py_True:Py_False; + Py_INCREF(r); + return r; +} + +PyObject* PythonQtConv::ConvertQtValueToPython(const PythonQtMethodInfo::ParameterInfo& info, void* data) { + if (info.typeId == QMetaType::Void) { + Py_INCREF(Py_None); + return Py_None; + } else { + if (info.isPointer && (info.typeId == PythonQtMethodInfo::Unknown)) { + // try to convert the pointer to a Python Object + PyObject* pyObj = PythonQt::priv()->wrapPtr(*((void**)data), info.name); + if (pyObj) { + return pyObj; + } else { + std::cerr << "unknown pointer type " << info.name.data() << ", in " << __FILE__ << ":" << __LINE__ << std::endl; + Py_INCREF(Py_None); + return Py_None; + } + } else if (info.isPointer && (info.typeId == QMetaType::Char)) { + // a char ptr will probably be a null terminated string, so we support that: + return PyString_FromString(*((char**)data)); + } else { + if (info.typeId == PythonQtMethodInfo::Unknown || info.typeId >= QMetaType::User) { + if (info.name.startsWith("QList<")) { + QByteArray innerType = info.name.mid(6,info.name.length()-7); + if (innerType.endsWith("*")) { + innerType.truncate(innerType.length()-1); + return ConvertQListWithPointersToPython((QList*)data, innerType); + } + } + } + // handle values that are not yet handled and not pointers + return ConvertQtValueToPythonInternal(info.typeId, data); + } + } +} + +PyObject* PythonQtConv::ConvertQtValueToPythonInternal(int type, void* data) { + switch (type) { + case QMetaType::Void: + Py_INCREF(Py_None); + return Py_None; + case QMetaType::Char: + return PyInt_FromLong(*((char*)data)); + case QMetaType::UChar: + return PyInt_FromLong(*((unsigned char*)data)); + case QMetaType::Short: + return PyInt_FromLong(*((short*)data)); + case QMetaType::UShort: + return PyInt_FromLong(*((unsigned short*)data)); + case QMetaType::Long: + return PyInt_FromLong(*((long*)data)); + case QMetaType::ULong: + // does not fit into simple int of python + return PyLong_FromUnsignedLong(*((unsigned long*)data)); + case QMetaType::Bool: + return PythonQtConv::GetPyBool(*((bool*)data)); + case QMetaType::Int: + return PyInt_FromLong(*((int*)data)); + case QMetaType::UInt: + return PyInt_FromLong(*((unsigned int*)data)); + case QMetaType::QChar: + return PyInt_FromLong(*((short*)data)); + case QMetaType::Float: + return PyFloat_FromDouble(*((float*)data)); + case QMetaType::Double: + return PyFloat_FromDouble(*((double*)data)); + case QMetaType::LongLong: + return PyLong_FromLongLong(*((qint64*)data)); + case QMetaType::ULongLong: + return PyLong_FromUnsignedLongLong(*((quint64*)data)); + case QMetaType::QByteArray: { + QByteArray* v = (QByteArray*) data; + return PyString_FromStringAndSize(*v, v->size()); + } + case QMetaType::QVariantMap: + return PythonQtConv::QVariantMapToPyObject(*((QVariantMap*)data)); + case QMetaType::QVariantList: + return PythonQtConv::QVariantListToPyObject(*((QVariantList*)data)); + case QMetaType::QString: + return PythonQtConv::QStringToPyObject(*((QString*)data)); + case QMetaType::QStringList: + return PythonQtConv::QStringListToPyObject(*((QStringList*)data)); + + case PythonQtMethodInfo::Variant: + return PythonQtConv::QVariantToPyObject(*((QVariant*)data)); + case QMetaType::QObjectStar: + case QMetaType::QWidgetStar: + return PythonQt::priv()->wrapQObject(*((QObject**)data)); + + // the following cases could be handled by the default case, but it is faster to do it with + // direct casts: + case QMetaType::QDate: + return (PyObject*)PythonQt::priv()->createNewPythonQtVariantWrapper(QVariant(*((QDate*)data))); + case QMetaType::QTime: + return (PyObject*)PythonQt::priv()->createNewPythonQtVariantWrapper(QVariant(*((QTime*)data))); + case QMetaType::QDateTime: + return (PyObject*)PythonQt::priv()->createNewPythonQtVariantWrapper(QVariant(*((QDateTime*)data))); + case QMetaType::QRect: + return (PyObject*)PythonQt::priv()->createNewPythonQtVariantWrapper(QVariant(*((QRect*)data))); + case QMetaType::QSize: + return (PyObject*)PythonQt::priv()->createNewPythonQtVariantWrapper(QVariant(*((QSize*)data))); + case QMetaType::QPoint: + return (PyObject*)PythonQt::priv()->createNewPythonQtVariantWrapper(QVariant(*((QPoint*)data))); + case QMetaType::QColor: + return (PyObject*)PythonQt::priv()->createNewPythonQtVariantWrapper(QVariant(*((QColor*)data))); + case QMetaType::QPixmap: + return (PyObject*)PythonQt::priv()->createNewPythonQtVariantWrapper(QVariant(*((QPixmap*)data))); + case QMetaType::QUrl: + return (PyObject*)PythonQt::priv()->createNewPythonQtVariantWrapper(QVariant(*((QUrl*)data))); + case QMetaType::QRectF: + return (PyObject*)PythonQt::priv()->createNewPythonQtVariantWrapper(QVariant(*((QRectF*)data))); + case QMetaType::QSizeF: + return (PyObject*)PythonQt::priv()->createNewPythonQtVariantWrapper(QVariant(*((QSizeF*)data))); + case QMetaType::QLine: + return (PyObject*)PythonQt::priv()->createNewPythonQtVariantWrapper(QVariant(*((QLine*)data))); + case QMetaType::QLineF: + return (PyObject*)PythonQt::priv()->createNewPythonQtVariantWrapper(QVariant(*((QLineF*)data))); + case QMetaType::QPointF: + return (PyObject*)PythonQt::priv()->createNewPythonQtVariantWrapper(QVariant(*((QPointF*)data))); + case QMetaType::QRegExp: + return (PyObject*)PythonQt::priv()->createNewPythonQtVariantWrapper(QVariant(*((QRegExp*)data))); + case QMetaType::QBitArray: + return (PyObject*)PythonQt::priv()->createNewPythonQtVariantWrapper(QVariant(*((QBitArray*)data))); + case QMetaType::QLocale: + return (PyObject*)PythonQt::priv()->createNewPythonQtVariantWrapper(QVariant(*((QLocale*)data))); + case QMetaType::QFont: + return (PyObject*)PythonQt::priv()->createNewPythonQtVariantWrapper(QVariant(*((QFont*)data))); + case QMetaType::QBrush: + return (PyObject*)PythonQt::priv()->createNewPythonQtVariantWrapper(QVariant(*((QBrush*)data))); + case QMetaType::QPalette: + return (PyObject*)PythonQt::priv()->createNewPythonQtVariantWrapper(QVariant(*((QPalette*)data))); + case QMetaType::QIcon: + return (PyObject*)PythonQt::priv()->createNewPythonQtVariantWrapper(qVariantFromValue(*((QIcon*)data))); + case QMetaType::QImage: + return (PyObject*)PythonQt::priv()->createNewPythonQtVariantWrapper(QVariant(*((QImage*)data))); + case QMetaType::QPolygon: + return (PyObject*)PythonQt::priv()->createNewPythonQtVariantWrapper(QVariant(*((QPolygon*)data))); + case QMetaType::QRegion: + return (PyObject*)PythonQt::priv()->createNewPythonQtVariantWrapper(QVariant(*((QRegion*)data))); + case QMetaType::QBitmap: + return (PyObject*)PythonQt::priv()->createNewPythonQtVariantWrapper(qVariantFromValue(*((QBitmap*)data))); + case QMetaType::QCursor: + return (PyObject*)PythonQt::priv()->createNewPythonQtVariantWrapper(QVariant(*((QCursor*)data))); + case QMetaType::QSizePolicy: + return (PyObject*)PythonQt::priv()->createNewPythonQtVariantWrapper(QVariant(*((QSizePolicy*)data))); + case QMetaType::QKeySequence: + return (PyObject*)PythonQt::priv()->createNewPythonQtVariantWrapper(qVariantFromValue(*((QKeySequence*)data))); + case QMetaType::QPen: + return (PyObject*)PythonQt::priv()->createNewPythonQtVariantWrapper(qVariantFromValue(*((QPen*)data))); + case QMetaType::QTextLength: + return (PyObject*)PythonQt::priv()->createNewPythonQtVariantWrapper(qVariantFromValue(*((QTextLength*)data))); + case QMetaType::QTextFormat: + return (PyObject*)PythonQt::priv()->createNewPythonQtVariantWrapper(qVariantFromValue(*((QTextFormat*)data))); + case QMetaType::QMatrix: + return (PyObject*)PythonQt::priv()->createNewPythonQtVariantWrapper(qVariantFromValue(*((QMatrix*)data))); + default: + if (PythonQt::priv()->isPythonQtObjectPtrMetaId(type)) { + PyObject* o = ((PythonQtObjectPtr*)data)->object(); + Py_INCREF(o); + return o; + } else { + if (type != PythonQtMethodInfo::Unknown) { + QVariant v(type, data); + if (v.isValid()) { + return (PyObject*)PythonQt::priv()->createNewPythonQtVariantWrapper(v); + } + } + std::cerr << "Unknown type that can not be converted to Python: " << type << ", in " << __FILE__ << ":" << __LINE__ << std::endl; + } +} +Py_INCREF(Py_None); +return Py_None; + } + + void* PythonQtConv::CreateQtReturnValue(const PythonQtMethodInfo::ParameterInfo& info) { + void* ptr = NULL; + if (info.isPointer) { + PythonQtValueStorage_ADD_VALUE(global_ptrStorage, void*, NULL, ptr); + } else { + switch (info.typeId) { + case QMetaType::Char: + case QMetaType::UChar: + case QMetaType::Short: + case QMetaType::UShort: + case QMetaType::Long: + case QMetaType::ULong: + case QMetaType::Bool: + case QMetaType::Int: + case QMetaType::UInt: + case QMetaType::QChar: + case QMetaType::Float: + case QMetaType::Double: + PythonQtValueStorage_ADD_VALUE(global_valueStorage, long, 0, ptr); + break; + case PythonQtMethodInfo::Variant: + PythonQtValueStorage_ADD_VALUE(global_variantStorage, QVariant, 0, ptr); + // return the ptr to the variant + break; + default: + if (info.typeId == PythonQtMethodInfo::Unknown) { + // check if we have a QList of pointers, which we can circumvent with a QList + if (info.name.startsWith("QList<")) { + QByteArray innerType = info.name.mid(6,info.name.length()-7); + if (innerType.endsWith("*")) { + static int id = QMetaType::type("QList"); + PythonQtValueStorage_ADD_VALUE(global_variantStorage, QVariant, QVariant::Type(id), ptr); + // return the constData pointer that will be filled with the result value later on + ptr = (void*)((QVariant*)ptr)->constData(); + } + } + } + + if (!ptr) { + // everything else is stored in a QVariant... + PythonQtValueStorage_ADD_VALUE(global_variantStorage, QVariant, QVariant::Type(info.typeId), ptr); + // return the constData pointer that will be filled with the result value later on + ptr = (void*)((QVariant*)ptr)->constData(); + } + } + } + return ptr; + } + + void* PythonQtConv::ConvertPythonToQt(const PythonQtMethodInfo::ParameterInfo& info, PyObject* obj, bool strict, const QMetaObject* meta) + { + bool ok; + void* ptr = NULL; + if (info.isPointer) { + if (obj->ob_type == &PythonQtWrapper_Type) { + PythonQtWrapper* wrap = (PythonQtWrapper*)obj; + // c++ wrapper, check if the class names of the c++ objects match + if (wrap->_info->isCPPWrapper()) { + //TODO: we could support inheritance on cpp wrappers as well + if (wrap->_info->wrappedCPPClassName() == info.name) { + PythonQtValueStorage_ADD_VALUE(global_ptrStorage, void*, wrap->_wrappedPtr, ptr); + } else { + // not matching + } + } else { + if (wrap->_info->inherits(info.name)) { + PythonQtValueStorage_ADD_VALUE(global_ptrStorage, void*, wrap->_obj, ptr); + } else { + // not matching + } + } + } else + if (info.typeId == QMetaType::Char || info.typeId == QMetaType::UChar) { + QString str = PyObjGetString(obj, strict, ok); + if (ok) { + void* ptr2 = NULL; + PythonQtValueStorage_ADD_VALUE(global_variantStorage, QVariant, QVariant(str.toUtf8()), ptr2); + PythonQtValueStorage_ADD_VALUE(global_ptrStorage, void*, (((QByteArray*)((QVariant*)ptr2)->constData())->data()), ptr); + } + } else if (info.name == "PyObject") { + // handle low level PyObject directly + PythonQtValueStorage_ADD_VALUE(global_ptrStorage, void*, obj, ptr); + } else if (obj == Py_None) { + // None is treated as a NULL ptr + PythonQtValueStorage_ADD_VALUE(global_ptrStorage, void*, NULL, ptr); + } else { + // if we are not strict, we try if we are passed a 0 integer + if (!strict) { + bool ok; + int value = PyObjGetInt(obj, true, ok); + if (ok && value==0) { + PythonQtValueStorage_ADD_VALUE(global_ptrStorage, void*, NULL, ptr); + } + } + // EXTRA: we could support pointers to other simple types, but this would not make sense in most situations + } + + } else { + // not a pointer + switch (info.typeId) { + case QMetaType::Char: + { + int val = PyObjGetInt(obj, strict, ok); + if (ok) { + PythonQtValueStorage_ADD_VALUE(global_valueStorage, char, val, ptr); + } + } + break; + case QMetaType::UChar: + { + int val = PyObjGetInt(obj, strict, ok); + if (ok) { + PythonQtValueStorage_ADD_VALUE(global_valueStorage, unsigned char, val, ptr); + } + } + break; + case QMetaType::Short: + { + int val = PyObjGetInt(obj, strict, ok); + if (ok) { + PythonQtValueStorage_ADD_VALUE(global_valueStorage, short, val, ptr); + } + } + break; + case QMetaType::UShort: + { + int val = PyObjGetInt(obj, strict, ok); + if (ok) { + PythonQtValueStorage_ADD_VALUE(global_valueStorage, unsigned short, val, ptr); + } + } + break; + case QMetaType::Long: + { + long val = (long)PyObjGetLongLong(obj, strict, ok); + if (ok) { + PythonQtValueStorage_ADD_VALUE(global_valueStorage, long, val, ptr); + } + } + break; + case QMetaType::ULong: + { + unsigned long val = (unsigned long)PyObjGetLongLong(obj, strict, ok); + if (ok) { + PythonQtValueStorage_ADD_VALUE(global_valueStorage, unsigned long, val, ptr); + } + } + break; + case QMetaType::Bool: + { + bool val = PyObjGetBool(obj, strict, ok); + if (ok) { + PythonQtValueStorage_ADD_VALUE(global_valueStorage, bool, val, ptr); + } + } + break; + case QMetaType::Int: + { + int val = PyObjGetInt(obj, strict, ok); + if (ok) { + PythonQtValueStorage_ADD_VALUE(global_valueStorage, int, val, ptr); + } + } + break; + case QMetaType::UInt: + { + unsigned int val = (unsigned int)PyObjGetLongLong(obj, strict, ok); + if (ok) { + PythonQtValueStorage_ADD_VALUE(global_valueStorage, unsigned int, val, ptr); + } + } + break; + case QMetaType::QChar: + { + int val = PyObjGetInt(obj, strict, ok); + if (ok) { + PythonQtValueStorage_ADD_VALUE(global_valueStorage, short, val, ptr); + } + } + break; + case QMetaType::Float: + { + float val = (float)PyObjGetDouble(obj, strict, ok); + if (ok) { + PythonQtValueStorage_ADD_VALUE(global_valueStorage, float, val, ptr); + } + } + break; + case QMetaType::Double: + { + double val = (double)PyObjGetDouble(obj, strict, ok); + if (ok) { + PythonQtValueStorage_ADD_VALUE(global_valueStorage, double, val, ptr); + } + } + break; + case QMetaType::LongLong: + { + qint64 val = PyObjGetLongLong(obj, strict, ok); + if (ok) { + PythonQtValueStorage_ADD_VALUE(global_valueStorage, qint64, val, ptr); + } + } + break; + case QMetaType::ULongLong: + { + quint64 val = PyObjGetULongLong(obj, strict, ok); + if (ok) { + PythonQtValueStorage_ADD_VALUE(global_valueStorage, quint64, val, ptr); + } + } + break; + case QMetaType::QByteArray: + { + QByteArray bytes = PyObjGetBytes(obj, strict, ok); + if (ok) { + PythonQtValueStorage_ADD_VALUE(global_variantStorage, QVariant, QVariant(bytes), ptr); + ptr = (void*)((QVariant*)ptr)->constData(); + } + } + break; + case QMetaType::QString: + { + QString str = PyObjGetString(obj, strict, ok); + if (ok) { + PythonQtValueStorage_ADD_VALUE(global_variantStorage, QVariant, QVariant(str), ptr); + ptr = (void*)((QVariant*)ptr)->constData(); + } + } + break; + case QMetaType::QStringList: + { + QStringList l = PyObjToStringList(obj, strict, ok); + if (ok) { + PythonQtValueStorage_ADD_VALUE(global_variantStorage, QVariant, QVariant(l), ptr); + ptr = (void*)((QVariant*)ptr)->constData(); + } + } + break; + + case PythonQtMethodInfo::Variant: + { + QVariant v = PyObjToQVariant(obj); + if (v.isValid()) { + PythonQtValueStorage_ADD_VALUE(global_variantStorage, QVariant, v, ptr); + } + } + break; + default: + { + if (info.typeId == PythonQtMethodInfo::Unknown) { + // check for enum case + if (PythonQt::priv()->isEnumType(meta, info.name)) { + unsigned int val = (unsigned int)PyObjGetLongLong(obj, strict, ok); + if (ok) { + PythonQtValueStorage_ADD_VALUE(global_valueStorage, unsigned int, val, ptr); + return ptr; + } + } + } + if (info.typeId == PythonQtMethodInfo::Unknown || info.typeId >= QMetaType::User) { + // check for QList case, where we will use a QList QVariant + if (info.name.startsWith("QList<")) { + QByteArray innerType = info.name.mid(6,info.name.length()-7); + if (innerType.endsWith("*")) { + innerType.truncate(innerType.length()-1); + static int id = QMetaType::type("QList"); + PythonQtValueStorage_ADD_VALUE(global_variantStorage, QVariant, QVariant::Type(id), ptr); + ptr = (void*)((QVariant*)ptr)->constData(); + ok = ConvertPythonListToQListOfType(obj, (QList*)ptr, innerType, strict); + if (ok) { + return ptr; + } else { + return NULL; + } + } + } + } + + // for all other types, we use the same qvariant conversion and pass out the constData of the variant: + QVariant v = PyObjToQVariant(obj, info.typeId); + if (v.isValid()) { + PythonQtValueStorage_ADD_VALUE(global_variantStorage, QVariant, v, ptr); + ptr = (void*)((QVariant*)ptr)->constData(); + } + } + } + } + return ptr; +} + + +QStringList PythonQtConv::PyObjToStringList(PyObject* val, bool strict, bool& ok) { + QStringList v; + ok = false; + // if we are strict, we do not want to convert a string to a stringlist + // (strings in python are detected to be sequences) + if (strict && + (val->ob_type == &PyString_Type || + PyUnicode_Check(val))) { + ok = false; + return v; + } + if (PySequence_Check(val)) { + int count = PySequence_Size(val); + for (int i = 0;iob_type == &PyString_Type) { + r = QString(PyString_AS_STRING(val)); + } else if (PyUnicode_Check(val)) { +#ifdef WIN32 + r = QString::fromUtf16(PyUnicode_AS_UNICODE(val)); +#else + PyObject *ptmp = PyUnicode_AsUTF8String(val); + if(ptmp) { + r = QString::fromUtf8(PyString_AS_STRING(ptmp)); + Py_DECREF(ptmp); + } +#endif + } else if (!strict) { + // EXTRA: could also use _Unicode, but why should we? + PyObject* str = PyObject_Str(val); + if (str) { + r = QString(PyString_AS_STRING(str)); + Py_DECREF(str); + } else { + ok = false; + } + } else { + ok = false; + } + return r; +} + +QByteArray PythonQtConv::PyObjGetBytes(PyObject* val, bool strict, bool& ok) { + QByteArray r; + ok = true; + if (val->ob_type == &PyString_Type) { + long size = PyString_GET_SIZE(val); + r = QByteArray(PyString_AS_STRING(val), size); + } else { + ok = false; + } + return r; +} + +bool PythonQtConv::PyObjGetBool(PyObject* val, bool strict, bool &ok) { + bool d = false; + ok = false; + if (val == Py_False) { + d = false; + ok = true; + } else if (val == Py_True) { + d = true; + ok = true; + } else if (!strict) { + d = PyObjGetInt(val, false, ok)!=0; + ok = true; + } + return d; +} + +int PythonQtConv::PyObjGetInt(PyObject* val, bool strict, bool &ok) { + int d = 0; + ok = true; + if (val->ob_type == &PyInt_Type) { + d = PyInt_AS_LONG(val); + } else if (!strict) { + if (val->ob_type == &PyFloat_Type) { + d = floor(PyFloat_AS_DOUBLE(val)); + } else if (val->ob_type == &PyLong_Type) { + // handle error on overflow! + d = PyLong_AsLong(val); + } else if (val == Py_False) { + d = 0; + } else if (val == Py_True) { + d = 1; + } else { + ok = false; + } + } else { + ok = false; + } + return d; +} + +qint64 PythonQtConv::PyObjGetLongLong(PyObject* val, bool strict, bool &ok) { + qint64 d = 0; + ok = true; + if (val->ob_type == &PyInt_Type) { + d = PyInt_AS_LONG(val); + } else if (val->ob_type == &PyLong_Type) { + d = PyLong_AsLongLong(val); + } else if (!strict) { + if (val->ob_type == &PyFloat_Type) { + d = floor(PyFloat_AS_DOUBLE(val)); + } else if (val == Py_False) { + d = 0; + } else if (val == Py_True) { + d = 1; + } else { + ok = false; + } + } else { + ok = false; + } + return d; +} + +quint64 PythonQtConv::PyObjGetULongLong(PyObject* val, bool strict, bool &ok) { + quint64 d = 0; + ok = true; + if (val->ob_type == &PyInt_Type) { + d = PyInt_AS_LONG(val); + } else if (val->ob_type == &PyLong_Type) { + d = PyLong_AsLongLong(val); + } else if (!strict) { + if (val->ob_type == &PyFloat_Type) { + d = floor(PyFloat_AS_DOUBLE(val)); + } else if (val == Py_False) { + d = 0; + } else if (val == Py_True) { + d = 1; + } else { + ok = false; + } + } else { + ok = false; + } + return d; +} + +double PythonQtConv::PyObjGetDouble(PyObject* val, bool strict, bool &ok) { + double d = 0; + ok = true; + if (val->ob_type == &PyFloat_Type) { + d = PyFloat_AS_DOUBLE(val); + } else if (!strict) { + if (val->ob_type == &PyInt_Type) { + d = PyInt_AS_LONG(val); + } else if (val->ob_type == &PyLong_Type) { + d = PyLong_AsLong(val); + } else if (val == Py_False) { + d = 0; + } else if (val == Py_True) { + d = 1; + } else { + ok = false; + } + } else { + ok = false; + } + return d; +} + +QVariant PythonQtConv::PyObjToQVariant(PyObject* val, int type) +{ + QVariant v; + bool ok = true; + + if (type==-1) { + // no special type requested + if (val->ob_type==&PyString_Type || val->ob_type==&PyUnicode_Type) { + type = QVariant::String; + } else if (val->ob_type==&PyInt_Type) { + type = QVariant::Int; + } else if (val->ob_type==&PyLong_Type) { + type = QVariant::LongLong; + } else if (val->ob_type==&PyFloat_Type) { + type = QVariant::Double; + } else if (val == Py_False || val == Py_True) { + type = QVariant::Bool; + } else if (val->ob_type == &PythonQtWrapper_Type) { + PythonQtWrapper* wrap = (PythonQtWrapper*)val; + // c++ wrapper, check if the class names of the c++ objects match + if (wrap->_info->isCPPWrapper()) { + // is this worth anything? we loose the knowledge of the cpp object type + v = qVariantFromValue(wrap->_wrappedPtr); + } else { + v = qVariantFromValue(wrap->_obj); + } + return v; + } else if (val->ob_type==&PyDict_Type) { + type = QVariant::Map; + } else if (val->ob_type==&PyList_Type || val->ob_type==&PyTuple_Type || PySequence_Check(val)) { + type = QVariant::List; + } else if (val == Py_None) { + // none is invalid + type = QVariant::Invalid; + } else if (val->ob_type == &PythonQtVariantWrapper_Type) { + PythonQtVariantWrapper* varWrap = (PythonQtVariantWrapper*)val; + if (varWrap->_variant->userType() == type) { + v = *varWrap->_variant; + return v; + } + } else { + // this used to be: + // type = QVariant::String; + // but now we want to transport the Python Objects directly: + PythonQtObjectPtr o(val); + v = qVariantFromValue(o); + return v; + } + } + // special type request: + switch (type) { + case QVariant::Invalid: + return v; + break; + case QVariant::Int: + { + int d = PyObjGetInt(val, false, ok); + if (ok) return QVariant(d); + } + break; + case QVariant::UInt: + { + int d = PyObjGetInt(val, false,ok); + if (ok) v = QVariant((unsigned int)d); + } + break; + case QVariant::Bool: + { + int d = PyObjGetBool(val,false,ok); + if (ok) v = QVariant((bool)(d!=0)); + } + break; + case QVariant::Double: + { + double d = PyObjGetDouble(val,false,ok); + if (ok) v = QVariant(d); + break; + } + case QMetaType::Float: + { + float d = (float) PyObjGetDouble(val,false,ok); + if (ok) v = qVariantFromValue(d); + break; + } + case QMetaType::Long: + { + long d = (long) PyObjGetLongLong(val,false,ok); + if (ok) v = qVariantFromValue(d); + break; + } + case QMetaType::ULong: + { + unsigned long d = (unsigned long) PyObjGetLongLong(val,false,ok); + if (ok) v = qVariantFromValue(d); + break; + } + case QMetaType::Short: + { + short d = (short) PyObjGetInt(val,false,ok); + if (ok) v = qVariantFromValue(d); + break; + } + case QMetaType::UShort: + { + unsigned short d = (unsigned short) PyObjGetInt(val,false,ok); + if (ok) v = qVariantFromValue(d); + break; + } + case QMetaType::Char: + { + char d = (char) PyObjGetInt(val,false,ok); + if (ok) v = qVariantFromValue(d); + break; + } + case QMetaType::UChar: + { + unsigned char d = (unsigned char) PyObjGetInt(val,false,ok); + if (ok) v = qVariantFromValue(d); + break; + } + + case QVariant::ByteArray: + case QVariant::String: + { + bool ok; + v = QVariant(PyObjGetString(val, false, ok)); + } + break; + + // these are important for MeVisLab + case QVariant::Map: + { + if (PyMapping_Check(val)) { + QMap map; + PyObject* items = PyMapping_Items(val); + if (items) { + int count = PyList_Size(items); + PyObject* value; + PyObject* key; + PyObject* tuple; + for (int i = 0;iob_type == &PythonQtVariantWrapper_Type) { + PythonQtVariantWrapper* varWrap = (PythonQtVariantWrapper*)val; + if (varWrap->_variant->userType() == type) { + v = *varWrap->_variant; + } + } else { + v = QVariant(); + } + } + return v; +} + +PyObject* PythonQtConv::QStringToPyObject(const QString& str) +{ + if (str.isNull()) { + return PyString_FromString(""); + } else { +#ifdef WIN32 + // return PyString_FromString(str.toLatin1().data()); + return PyUnicode_FromUnicode(str.utf16(), str.length()); +#else + return PyUnicode_DecodeUTF16((const char*)str.utf16(), str.length()*2, NULL, NULL); +#endif + } +} + +PyObject* PythonQtConv::QStringListToPyObject(const QStringList& list) +{ + PyObject* result = PyTuple_New(list.count()); + int i = 0; + QString str; + foreach (str, list) { + PyTuple_SET_ITEM(result, i, PythonQtConv::QStringToPyObject(str)); + i++; + } + // why is the error state bad after this? + PyErr_Clear(); + return result; +} + +PyObject* PythonQtConv::QStringListToPyList(const QStringList& list) +{ + PyObject* result = PyList_New(list.count()); + int i = 0; + for (QStringList::ConstIterator it = list.begin(); it!=list.end(); ++it) { + PyList_SET_ITEM(result, i, PythonQtConv::QStringToPyObject(*it)); + i++; + } + return result; +} + +PyObject* PythonQtConv::QVariantToPyObject(const QVariant& v) +{ + return ConvertQtValueToPythonInternal(v.userType(), (void*)v.constData()); +} + +PyObject* PythonQtConv::QVariantMapToPyObject(const QVariantMap& m) { + PyObject* result = PyDict_New(); + QVariantMap::const_iterator t = m.constBegin(); + PyObject* key; + PyObject* val; + for (;t!=m.end();t++) { + key = QStringToPyObject(t.key()); + val = QVariantToPyObject(t.value()); + PyDict_SetItem(result, key, val); + Py_DECREF(key); + Py_DECREF(val); + } + return result; +} + +PyObject* PythonQtConv::QVariantListToPyObject(const QVariantList& l) { + PyObject* result = PyTuple_New(l.count()); + int i = 0; + QVariant v; + foreach (v, l) { + PyTuple_SET_ITEM(result, i, PythonQtConv::QVariantToPyObject(v)); + i++; + } + // why is the error state bad after this? + PyErr_Clear(); + return result; +} + +PyObject* PythonQtConv::ConvertQListWithPointersToPython(QList* list, const QByteArray& type) +{ + PyObject* result = PyTuple_New(list->count()); + int i = 0; + foreach (void* value, *list) { + PyTuple_SET_ITEM(result, i, PythonQt::priv()->wrapPtr(value, type)); + i++; + } + return result; +} + +bool PythonQtConv::ConvertPythonListToQListOfType(PyObject* obj, QList* list, const QByteArray& type, bool strict) +{ + bool result = false; + if (PySequence_Check(obj)) { + result = true; + int count = PySequence_Size(obj); + PyObject* value; + for (int i = 0;iob_type == &PythonQtWrapper_Type) { + PythonQtWrapper* wrap = (PythonQtWrapper*)value; + // c++ wrapper, check if the class names of the c++ objects match + if (wrap->_info->isCPPWrapper()) { + //TODO: we could support inheritance on cpp wrappers as well + if (wrap->_info->wrappedCPPClassName() == type) { + list->append(wrap->_wrappedPtr); + } else { + result = false; + break; + } + } else { + if (wrap->_info->inherits(type)) { + list->append((void*)wrap->_obj); + } else { + result = false; + break; + } + } + } + } + } + return result; +} + diff --git a/src/PythonQtConversion.h b/src/PythonQtConversion.h new file mode 100644 index 0000000..4f515f7 --- /dev/null +++ b/src/PythonQtConversion.h @@ -0,0 +1,127 @@ +#ifndef _PYTHONQTCONVERSION_H +#define _PYTHONQTCONVERSION_H + +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtConversion.h +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-05 +*/ +//---------------------------------------------------------------------------------- + +#include "PythonQt.h" +#include "PythonQtMisc.h" +#include "PythonQtClassInfo.h" +#include "PythonQtMethodInfo.h" + +#include + +//! a static class that offers methods for type conversion +class PythonQtConv { + +public: + + //! get a ref counted True or False Python object + static PyObject* GetPyBool(bool val); + + //! converts the Qt parameter given in \c data, interpreting it as a \c info parameter, into a Python object, + static PyObject* ConvertQtValueToPython(const PythonQtMethodInfo::ParameterInfo& info, void* data); + + //! convert python object to Qt (according to the given parameter) and if the conversion should be strict, the meta object is passed in for enum resolving + static void* ConvertPythonToQt(const PythonQtMethodInfo::ParameterInfo& info, PyObject* obj, bool strict, const QMetaObject* meta); + + //! creates a data storage for the passed parameter type and returns a void pointer to be set as arg[0] of qt_metacall + static void* CreateQtReturnValue(const PythonQtMethodInfo::ParameterInfo& info); + + //! converts QString to Python string (unicode!) + static PyObject* QStringToPyObject(const QString& str); + + //! converts QStringList to Python tuple + static PyObject* QStringListToPyObject(const QStringList& list); + + //! converts QStringList to Python list + static PyObject* QStringListToPyList(const QStringList& list); + + //! get string representation of py object + static QString PyObjGetRepresentation(PyObject* val); + + //! get string value from py object + static QString PyObjGetString(PyObject* val) { bool ok; QString s = PyObjGetString(val, false, ok); return s; } + //! get string value from py object + static QString PyObjGetString(PyObject* val, bool strict, bool &ok); + //! get bytes from py object + static QByteArray PyObjGetBytes(PyObject* val, bool strict, bool &ok); + //! get int from py object + static int PyObjGetInt(PyObject* val, bool strict, bool &ok); + //! get int64 from py object + static qint64 PyObjGetLongLong(PyObject* val, bool strict, bool &ok); + //! get int64 from py object + static quint64 PyObjGetULongLong(PyObject* val, bool strict, bool &ok); + //! get double from py object + static double PyObjGetDouble(PyObject* val, bool strict, bool &ok); + //! get bool from py object + static bool PyObjGetBool(PyObject* val, bool strict, bool &ok); + + //! create a string list from python sequence + static QStringList PyObjToStringList(PyObject* val, bool strict, bool& ok); + + //! convert python object to qvariant, if type is given it will try to create a qvariant of that type, otherwise + //! it will guess from the python type + static QVariant PyObjToQVariant(PyObject* val, int type = -1); + + //! convert QVariant from PyObject + static PyObject* QVariantToPyObject(const QVariant& v); + + static PyObject* QVariantMapToPyObject(const QVariantMap& m); + static PyObject* QVariantListToPyObject(const QVariantList& l); + +public: + + static PythonQtValueStorage global_valueStorage; + static PythonQtValueStorage global_ptrStorage; + static PythonQtValueStorage global_variantStorage; + +protected: + //! converts the Qt parameter given in \c data, interpreting it as a \c type registered qvariant/meta type, into a Python object, + static PyObject* ConvertQtValueToPythonInternal(int type, void* data); + + //! converts the list of pointers of given type to Python + static PyObject* ConvertQListWithPointersToPython(QList* list, const QByteArray& type); + //! tries to convert the python object to a QList of pointers to \c type objects, returns true on success + static bool ConvertPythonListToQListOfType(PyObject* obj, QList* list, const QByteArray& type, bool strict); +}; + +#endif diff --git a/src/PythonQtCppWrapperFactory.h b/src/PythonQtCppWrapperFactory.h new file mode 100644 index 0000000..54ab336 --- /dev/null +++ b/src/PythonQtCppWrapperFactory.h @@ -0,0 +1,61 @@ +#ifndef _PYTHONQTCPPWRAPPERFACTORY_H +#define _PYTHONQTCPPWRAPPERFACTORY_H + +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtCppWrapperFactory.h +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-06 +*/ +//---------------------------------------------------------------------------------- + +//! Factory interface for C++ classes that can be wrapped by QObject objects +/*! To create your own factory, derive PythonQtCppWrapperFactory and implement +the create() method. +A factory can be added to PythonQt by PythonQt::addCppWrapperFactory(). +*/ +class PYTHONQT_EXPORT PythonQtCppWrapperFactory +{ +public: + PythonQtCppWrapperFactory() {}; + virtual ~PythonQtCppWrapperFactory() {}; + + //! create a wrapper for the given object + virtual QObject* create(const QByteArray& name, void *ptr) = 0; + +}; + +#endif \ No newline at end of file diff --git a/src/PythonQtDoc.h b/src/PythonQtDoc.h new file mode 100644 index 0000000..c715efc --- /dev/null +++ b/src/PythonQtDoc.h @@ -0,0 +1,462 @@ +#ifndef _PYTHONQTDOC_H +#define _PYTHONQTDOC_H + +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtDoc.h +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-10 +*/ +//---------------------------------------------------------------------------------- + +/*! + \if USE_GLOBAL_DOXYGEN_DOC + \page PythonQtPage PythonQt Overview + \else + \mainpage PythonQt Overview + \endif + + \section Introduction + + \b PythonQt is a dynamic Python (http://www.python.org) binding for Qt (http://www.trolltech.com). + It offers an easy way to embedd the Python scripting language into + your Qt applications. It makes heavy use of the QMetaObject system and thus requires Qt4.x. + + In contrast to PyQt , PythonQt is \b not a complete + Python wrapper around the complete Qt functionality. So if you are looking for a way to + write complete applications in Python using the Qt GUI, you should use PyQt. + + If you are looking for a simple way to embed the Python language into your Qt Application + and to script parts of your application via Python, PythonQt is the way to go! + + PythonQt is a stable library that was developed to make the Image Processing and Visualization platform MeVisLab (http://www.mevislab.de) + scriptable from Python. + + \section Licensing + + PythonQt is distributed under the LGPL license. + + \section Download + + PythonQt is hosted on SourceForge at http://sourceforge.net/projects/pythonqt , you can access it via SVN + or download a tarball. + + \section Features + + - Access all \b slots, \b properties, children and registered enums of any QObject derived class from Python + - Connecting Qt Signals to Python functions (both from within Python and from C++) + - Wrapping of C++ objects (which are not derived from QObject) via PythonQtCPPWrapperFactory + - Extending C++ and QObject derived classes with additional slots, static methods and constructors (see Decorators) + - StdOut/Err redirection to Qt signals instead of cout + - Interface for creating your own \c import replacement, so that Python scripts can be e.g. signed/verified before they are executed (PythonQtImportInterface) + - Mapping of plain-old-datatypes and ALL QVariant types to and from Python + - Support for wrapping of user QVariant types which are registerd via QMetaType + - Support for Qt namespace (with all enumerators) + - All PythonQt wrapped objects support the dir() statement, so that you can see easily which attributes a QObject, CPP object or QVariant has + - No preprocessing/wrapping tool needs to be started, PythonQt can script any QObject without prior knowledge about it (except for the MetaObject information from the \b moc) + + \section Non-Features + + Features that PythonQt does NOT support (and will not support): + + - you can not derive from QObjects inside of Python, this would require wrapper generation like PyQt does + - you can only script QObject derived classes, for normal C++ classes you need to create a PythonQtCPPWrapperFactory and adequate wrapper classes or add decorator slots + - you can not access normal member functions of QObjects, only slots and properties, because the \b moc does not store normal member functions in the MetaObject system + + \section Interface + + The main interface to PythonQt is the PythonQt singleton. + PythonQt needs to be initialized via PythonQt::init() once. + Afterwards you communicate with the singleton via PythonQt::self(). + PythonQt offers a default binding for the complete QWidget set, which + needs to be enabled via PythonQtGui::init(). + + + \section Datatype Datatype Mapping + + The following table shows the mapping between Python and Qt objects: + + + + + + + + + + + + + + + + + + + + + +
Qt/C++Python
boolbool
doublefloat
floatfloat
char/uchar,int/uint,short,ushort,QCharinteger
longinteger
ulong,longlong,ulonglonglong
QStringunicode string
QByteArraystr
char*str
QStringListtuple of unicode strings
QVariantListtuple of objects
QVariantMapdict of objects
QVariantdepends on type, see below
QSize, QRect and all other standard Qt QVariantsvariant wrapper that supports complete API of the respective Qt classes
OwnRegisteredMetaTypevariant wrapper, optionally with a wrapper provided by addVariantWrapper()
EnumTypeinteger (all enums that are known via the moc and the Qt namespace are supported)
QObject (and derived classes)QObject wrapper
C++ objectCPP wrapper, either wrapped via PythonQtCPPWrapperFactory or just decorated with decorators
PyObjectPyObject
+ + PyObject is passed as simple pointer, which allows to pass/return any Python Object directly to/from + a Qt slot. + QVariants are mapped recursively as given above, e.g. a dictionary can + contain lists of dictionaries of doubles. + For example a QVariant of type "String" is mapped to a python unicode string. + All Qt QVariant types are implemented, PythonQt supports the complete Qt API for these object. + + \section QObject QObject Wrapping + + All classes derived from QObject are automatically wrapped with a python wrapper class + when they become visible to the Python interpreter. This can happen via + - the PythonQt::addObject() method + - when a Qt \b slot returns a QObject derived object to python + - when a Qt \b signal contains a QObject and is connected to a python function + + It is important that you call PythonQt::registerClass() for any QObject derived class + that may become visible to Python, except when you add it via PythonQt::addObject(). + This will register the complete parent hierachy of the registered class, so that + when you register e.g. a QPushButton, QWidget will be registered as well (and all intermediate + parents). + + From Python, you can talk to the returned QObjects in a natural way by calling + their slots and receiving the return values. You can also read/write all + properties of the objects as if they where normal python properties. + + In addition to this, the wrapped objects support + - className() - returns a string that reprents the classname of the QObject + - help() - shows all properties, slots, enums, decorator slots and constructors of the object, in a printable form + - connect(signal, function) - connect the signal of the given object to a python function + - connect(signal, qobject, slot) - connect the signal of the given object to a slot of another QObject + - disconnect(signal, function) - disconnect the signal of the given object from a python function + - disconnect(signal, qobject, slot) - disconnect the signal of the given object from a slot of another QObject + - children() - returns the children of the object + - setParent(QObject) - set the parent + - QObject* parent() - get the parent + + The below example shows how to connect signals in Python: + + \code + # define a signal handler function + def someFunction(flag): + print flag + + # button1 is a QPushButton that has been added to Python via addObject() + # connect the clicked signal to a python function: + button1.connect("clicked(bool)", someFunction) + + \endcode + +\section CPP CPP Wrapping + +You can create dedicated wrapper QObject for any C++ class. This is done by deriving from PythonQtCPPWrapperFactory +and adding your factory via addWrapperFactory(). Whenever PythonQt encounters a CPP pointer (e.g. on a slot or signal) +and it does not known it as a QObject derived class, it will create a generic CPP wrapper. So even unknown C++ objects +can be passed through Python. If the wrapper factory supports the CPP class, a QObject wrapper will be created for each +instance that enters Python. An alternative to a complete wrapper via the wrapper factory are decorators, see \ref Decorators + +\section MetaObject Meta Object/Class access + +For each known CPP class, QObject derived class and QVariant type, PythonQt provides a Meta class. These meta classes are visible +inside of the "PythonQt" python module. + +A Meta class supports: + +- access to all declared enum values +- constructors +- static decorator slots +- help() and className() + +From within Python, you can import the module "PythonQt" to access these meta objects and the Qt namespace. + +\code +from PythonQt import * + +# namespace access: +print Qt.AlignLeft + +# constructors +a = QSize(12,13) +b = QFont() + +# static method +QDate.currentDate() + +# enum value +QFont.UltraCondensed + +\endcode + +\section Decorators Decorator slots + +PythonQt introduces a new generic approach to extend any wrapped QObject or CPP object with + +- constructors +- destructors (for CPP objects) +- additional slots +- static slots (callable on both the Meta object and the instances) + +The idea behind decorators is that we wanted to make it as easy as possible to extend +wrapped objects. Since we already have an implementation for invoking any Qt Slot from +Python, it looked promising to use this approach for the extension of wrapped objects as well. +This avoids that the PythonQt user needs to care about how Python arguments are mapped from/to +Qt when he wants to create static methods, constructors and additional member functions. + +The basic idea about decorators is to create a QObject derived class that implements slots +which take one of the above roles (e.g. constructor, destructor etc.) via a naming convention. +These slots are then assigned to other classes via the naming convention. + +- QVariant new_SomeClassName(...) - defines a constructor for "SomeClassName" that returns a QVariant +- SomeClassName* new_SomeClassName(...) - defines a constructor for "SomeClassName" that returns a new object of type SomeClassName (where SomeClassName can be any CPP class, not just QObject classes) +- void delete_SomeClassName(SomeClassName* o) - defines a destructor, which should delete the passed in object o +- anything static_SomeClassName_someMethodName(...) - defines a static method that is callable on instances and the meta class +- anything someMethodName(SomeClassName* o, ...) - defines a slot that will be available on SomeClassName instances (and derived instances). When such a slot is called the first argument is the pointer to the instance and the rest of the arguments can be used to make a call on the instance. + +The below example shows all kinds of decorators in action: + +\code + +// an example CPP object +class YourCPPObject { +public: + YourCPPObject(int arg1, float arg2) { a = arg1; b = arg2; } + + float doSomething(int arg1) { return arg1*a*b; }; + + private: + + int a; + float b; +}; + +// an example decorator +class ExampleDecorator : public QObject +{ + Q_OBJECT + +public slots: + // add a constructor to QSize variant that takes a QPoint + QVariant new_QSize(const QPoint& p) { return QSize(p.x(), p.y()); } + + // add a constructor for QPushButton that takes a text and a parent widget + QPushButton* new_QPushButton(const QString& text, QWidget* parent=NULL) { return new QPushButton(text, parent); } + + // add a constructor for a CPP object + YourCPPObject* new_YourCPPObject(int arg1, float arg2) { return new YourCPPObject(arg1, arg2); } + + // add a destructor for a CPP object + void delete_YourCPPObject(YourCPPObject* obj) { delete obj; } + + // add a static method to QWidget + QWidget* static_QWidget_mouseGrabber() { return QWidget::mouseGrabber(); } + + // add an additional slot to QWidget (make move() callable, which is not declared as a slot in QWidget) + void move(QWidget* w, const QPoint& p) { w->move(p); } + + // add an additional slot to QWidget, overloading the above move method + void move(QWidget* w, int x, int y) { w->move(x,y); } + + // add a method to your own CPP object + int doSomething(YourCPPObject* obj, int arg1) { return obj->doSomething(arg1); } +}; + +... + +PythonQt::self()->addDecorators(new ExampleDecorator()); +PythonQt::self()->registerClass(&QPushButton::staticMetaObject); +PythonQt::self()->registerCPPClassNames(QStringList() << "YourCPPObject"); + +\endcode + +After you have registered an instance of the above ExampleDecorator, you can do the following from Python +(all these calls are mapped to the above decorator slots): + +\code +from PythonQt import * + +# call our new constructor of QSize +size = QSize(QPoint(1,2)); + +# call our new QPushButton constructor +button = QPushButton("sometext"); + +# call the move slot (overload1) +button.move(QPoint(0,0)) + +# call the move slot (overload2) +button.move(0,0) + +# call the static method +grabber = QWidget.mouseWrapper(); + +# create a CPP object via constructor +yourCpp = YourCPPObject(1,11.5) + +# call the wrapped method on CPP object +print yourCpp.doSomething(1); + +# destructor will be called: +yourCpp = None + +\endcode + + \section Building + + PythonQt requires at least Qt 4.2.2 (or higher) and Python 2.3, 2.4 or 2.5 on Windows, Linux and MacOS X. + To compile PythonQt, you will need a python developer installation which includes Python's header files and +the python2x.[lib | dll | so | dynlib]. + The build scripts a currently set to use Python 2.5. + You may need to tweak the \b build/python.prf file to set the correct Python includes and libs on your system. + + \subsection Windows + + On Windows, the (non-source) Python Windows installer can be used. + Make sure that you use the same compiler, the current Python distribution is built + with Visual Studio 2003. If you want to use another compiler, you will need to build + Python yourself, using your compiler. + + To build PythonQt, you need to set the environment variable \b PYTHON_PATH to point to the root + dir of the python installation and \b PYTHON_LIB to point to + the directory where the python lib file is located. + + When using the prebuild Python installer, this will be: + + \code + > set PYTHON_PATH = c:\Python25 + > set PYTHON_LIB = c:\Python25\libs + \endcode + + When using the python sources, this will be something like: + + \code + > set PYTHON_PATH = c:\yourDir\Python-2.5.1\ + > set PYTHON_LIB = c:\yourDir\Python-2.5.1\PCbuild8\Win32 + \endcode + + To build all, do the following (after setting the above variables): + + \code + > cd PythonQtRoot + > vcvars32 + > qmake + > nmake + \endcode + + This should build everything. If Python can not be linked or include files can not be found, + you probably need to tweak \b build/python.prf + + The tests and examples are located in PythonQt/lib. + + \subsection Linux + + On Linux, you need to install a Python-dev package. + If Python can not be linked or include files can not be found, + you probably need to tweak \b build/python.prf + + To build PythonQt, just do a: + + \code + > cd PythonQtRoot + > qmake + > make all + \endcode + + The tests and examples are located in PythonQt/lib. + You should add PythonQt/lib to your LD_LIBRARY_PATH so that the runtime + linker can find the *.so files. + + \subsection MacOsX + + On Mac, Python is installed as a Framework, so you should not need to install it. + To build PythonQt, just do a: + + \code + > cd PythonQtRoot + > qmake + > make all + \endcode + + \section Tests + + There is a unit test that tests most features of PythonQt, see the \b tests subdirectory for details. + + \section Examples + + Examples are available in the \b examples directory. The PyScriptingConsole implements a simple + interactive scripting console that shows how to script a simple application. + + The following shows how to integrate PythonQt into you Qt application: + + \code + #include "PythonQt.h" + #include + ... + + int main( int argc, char **argv ) + { + + QApplication qapp(argc, argv); + + // init PythonQt and Python itself + PythonQt::init(PythonQt::IgnoreSiteModule | PythonQt::RedirectStdOut); + + // get a smart pointer to the __main__ module of the Python interpreter + PythonQtObjectPtr mainContext = PythonQt::self()->getMainModule(); + + // add a QObject as variable of name "example" to the namespace of the __main__ module + PyExampleObject example; + PythonQt::self()->addObject(mainContext, "example", &example); + + // register all other QObjects that you want to script and that are returned by your API + PythonQt::self()->registerClass(&QMainWindow::staticMetaObject); + PythonQt::self()->registerClass(&QPushButton::staticMetaObject); + ... + + // do something + PythonQt::self()->runScript(mainContext, "print example\n"); + PythonQt::self()->runScript(mainContext, "def multiply(a,b):\n return a*b;\n"); + QVariantList args; + args << 42 << 47; + QVariant result = PythonQt::self()->call(mainContext,"multiply", args); + ... + \endcode + + + \section TODOs + + - add more information on how to distribute an application that uses PythonQt, including the Python distribution + +*/ diff --git a/src/PythonQtImportFileInterface.h b/src/PythonQtImportFileInterface.h new file mode 100644 index 0000000..cfd98f5 --- /dev/null +++ b/src/PythonQtImportFileInterface.h @@ -0,0 +1,68 @@ +#ifndef _PYTHONQTIMPORTFILEINTERFACE_H +#define _PYTHONQTIMPORTFILEINTERFACE_H + +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtImportFileInterface.h +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-05 +*/ +//---------------------------------------------------------------------------------- + +#include +#include +#include + +//! defines an abstract interface to file access for the Python import statement +class PythonQtImportFileInterface { + +public: + //! read the given file as byte array, without doing any linefeed translations + virtual QByteArray readFileAsBytes(const QString& filename) = 0; + + //! read a source file, expects a readable Python text file with translated line feeds. + //! If the file can not be load OR it can not be verified, ok is set to false + virtual QByteArray readSourceFile(const QString& filename, bool& ok) = 0; + + //! returns if the file exists + virtual bool exists(const QString& filename) = 0; + + //! get the last modified data of a file + virtual QDateTime lastModifiedDate(const QString& filename) = 0; + +}; + +#endif \ No newline at end of file diff --git a/src/PythonQtImporter.cpp b/src/PythonQtImporter.cpp new file mode 100644 index 0000000..c1e225a --- /dev/null +++ b/src/PythonQtImporter.cpp @@ -0,0 +1,788 @@ +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtImporter.h +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-05 +*/ +// This module was inspired by the zipimport.c module of the original +// Python distribution. Most of the functions are identical or slightly +// modified to do all the loading of Python files via an external file interface. +// In contrast to zipimport.c, this module also writes *.pyc files +// automatically if it has write access/is not inside of a zip file. +//---------------------------------------------------------------------------------- + +#include "PythonQtImporter.h" +#include "PythonQtImportFileInterface.h" +#include "PythonQt.h" +#include +#include + +#define IS_SOURCE 0x0 +#define IS_BYTECODE 0x1 +#define IS_PACKAGE 0x2 + +struct st_mlab_searchorder { + char suffix[14]; + int type; +}; + +/* mlab_searchorder defines how we search for a module in the Zip + archive: we first search for a package __init__, then for + non-package .pyc, .pyo and .py entries. The .pyc and .pyo entries + are swapped by initmlabimport() if we run in optimized mode. Also, + '/' is replaced by SEP there. */ + struct st_mlab_searchorder mlab_searchorder[] = { + {"/__init__.pyc", IS_PACKAGE | IS_BYTECODE}, + {"/__init__.pyo", IS_PACKAGE | IS_BYTECODE}, + {"/__init__.py", IS_PACKAGE | IS_SOURCE}, + {".pyc", IS_BYTECODE}, + {".pyo", IS_BYTECODE}, + {".py", IS_SOURCE}, + {"", 0} +}; + +extern PyTypeObject PythonQtImporter_Type; +PyObject *PythonQtImportError; + +QString PythonQtImport::getSubName(const QString& str) +{ + int idx = str.lastIndexOf('.'); + if (idx!=-1) { + return str.mid(idx+1); + } else { + return str; + } +} + +PythonQtImport::module_info PythonQtImport::getModuleInfo(PythonQtImporter* self, const QString& fullname) +{ + QString subname; + struct st_mlab_searchorder *zso; + + subname = getSubName(fullname); + QString path = *self->_path + "/" + subname; + + QString test; + for (zso = mlab_searchorder; *zso->suffix; zso++) { + test = path + zso->suffix; + if (PythonQt::importInterface()->exists(test)) { + if (zso->type & IS_PACKAGE) + return MI_PACKAGE; + else + return MI_MODULE; + } + } + return MI_NOT_FOUND; +} + + +/* PythonQtImporter.__init__ + Just store the path argument +*/ +int PythonQtImporter_init(PythonQtImporter *self, PyObject *args, PyObject *kwds) +{ + self->_path = NULL; + + const char* path; + if (!PyArg_ParseTuple(args, "s", + &path)) + return -1; + + if (PythonQt::importInterface()->exists(path)) { + //qDebug("path %s", path); + QString p(path); + const QStringList& ignorePaths = PythonQt::self()->getImporterIgnorePaths(); + foreach(QString a, ignorePaths) { + if (a==p) { + PyErr_SetString(PythonQtImportError, + "path ignored"); + return -1; + } + } + + self->_path = new QString(p); + + //mlabDebugConst("MLABPython", "PythonQtImporter init: " << *self->_path); + + return 0; + } else { + PyErr_SetString(PythonQtImportError, + "path does not exist error"); + return -1; + } +} + +void +PythonQtImporter_dealloc(PythonQtImporter *self) +{ + // free the stored path + if (self->_path) delete self->_path; + // free ourself + self->ob_type->tp_free((PyObject *)self); +} + + +/* Check whether we can satisfy the import of the module named by + 'fullname'. Return self if we can, None if we can't. */ +PyObject * +PythonQtImporter_find_module(PyObject *obj, PyObject *args) +{ + PythonQtImporter *self = (PythonQtImporter *)obj; + PyObject *path = NULL; + char *fullname; + + if (!PyArg_ParseTuple(args, "s|O:PythonQtImporter.find_module", + &fullname, &path)) + return NULL; + +// mlabDebugConst("MLABPython", "FindModule " << fullname << " in " << *self->_path); + + PythonQtImport::module_info info = PythonQtImport::getModuleInfo(self, fullname); + if (info == PythonQtImport::MI_MODULE || info == PythonQtImport::MI_PACKAGE) { + Py_INCREF(self); + return (PyObject *)self; + } else { + Py_INCREF(Py_None); + return Py_None; + } +} + +/* Load and return the module named by 'fullname'. */ +PyObject * +PythonQtImporter_load_module(PyObject *obj, PyObject *args) +{ + PythonQtImporter *self = (PythonQtImporter *)obj; + PyObject *code, *mod, *dict; + char *fullname; + QString modpath; + int ispackage; + + if (!PyArg_ParseTuple(args, "s:PythonQtImporter.load_module", + &fullname)) + return NULL; + + code = PythonQtImport::getModuleCode(self, fullname, &ispackage, modpath); + if (code == NULL) + return NULL; + + mod = PyImport_AddModule(fullname); + if (mod == NULL) { + Py_DECREF(code); + return NULL; + } + dict = PyModule_GetDict(mod); + + if (PyDict_SetItemString(dict, "__loader__", (PyObject *)self) != 0) + goto error; + + if (ispackage) { + PyObject *pkgpath, *fullpath; + QString subname = PythonQtImport::getSubName(fullname); + int err; + + fullpath = PyString_FromFormat("%s%c%s", + self->_path->toLatin1().constData(), + SEP, + subname.toLatin1().constData()); + if (fullpath == NULL) + goto error; + + pkgpath = Py_BuildValue("[O]", fullpath); + Py_DECREF(fullpath); + if (pkgpath == NULL) + goto error; + err = PyDict_SetItemString(dict, "__path__", pkgpath); + Py_DECREF(pkgpath); + if (err != 0) + goto error; + } + mod = PyImport_ExecCodeModuleEx(fullname, code, (char*)modpath.toLatin1().data()); + Py_DECREF(code); + if (Py_VerboseFlag) + PySys_WriteStderr("import %s # loaded from %s\n", + fullname, modpath); + return mod; +error: + Py_DECREF(code); + Py_DECREF(mod); + return NULL; +} + + +PyObject * +PythonQtImporter_get_data(PyObject *obj, PyObject *args) +{ + // EXTRA, NOT YET IMPLEMENTED + return NULL; +} + +PyObject * +PythonQtImporter_get_code(PyObject *obj, PyObject *args) +{ + PythonQtImporter *self = (PythonQtImporter *)obj; + char *fullname; + + if (!PyArg_ParseTuple(args, "s:PythonQtImporter.get_code", &fullname)) + return NULL; + + QString notused; + return PythonQtImport::getModuleCode(self, fullname, NULL, notused); +} + +PyObject * +PythonQtImporter_get_source(PyObject *obj, PyObject *args) +{ + // EXTRA, NOT YET IMPLEMENTED +/* + PythonQtImporter *self = (PythonQtImporter *)obj; + PyObject *toc_entry; + char *fullname, *subname, path[MAXPATHLEN+1]; + int len; + enum module_info mi; + + if (!PyArg_ParseTuple(args, "s:PythonQtImporter.get_source", &fullname)) + return NULL; + + mi = get_module_info(self, fullname); + if (mi == MI_ERROR) + return NULL; + if (mi == MI_NOT_FOUND) { + PyErr_Format(PythonQtImportError, "can't find module '%.200s'", + fullname); + return NULL; + } + subname = get_subname(fullname); + + len = make_filename(PyString_AsString(self->prefix), subname, path); + if (len < 0) + return NULL; + + if (mi == MI_PACKAGE) { + path[len] = SEP; + strcpy(path + len + 1, "__init__.py"); + } + else + strcpy(path + len, ".py"); + + toc_entry = PyDict_GetItemString(self->files, path); + if (toc_entry != NULL) + return get_data(PyString_AsString(self->archive), toc_entry); + + Py_INCREF(Py_None); + return Py_None; +*/ + return NULL; +} + +PyDoc_STRVAR(doc_find_module, +"find_module(fullname, path=None) -> self or None.\n\ +\n\ +Search for a module specified by 'fullname'. 'fullname' must be the\n\ +fully qualified (dotted) module name. It returns the PythonQtImporter\n\ +instance itself if the module was found, or None if it wasn't.\n\ +The optional 'path' argument is ignored -- it's there for compatibility\n\ +with the importer protocol."); + +PyDoc_STRVAR(doc_load_module, +"load_module(fullname) -> module.\n\ +\n\ +Load the module specified by 'fullname'. 'fullname' must be the\n\ +fully qualified (dotted) module name. It returns the imported\n\ +module, or raises PythonQtImportError if it wasn't found."); + +PyDoc_STRVAR(doc_get_data, +"get_data(pathname) -> string with file data.\n\ +\n\ +Return the data associated with 'pathname'. Raise IOError if\n\ +the file wasn't found."); + +PyDoc_STRVAR(doc_get_code, +"get_code(fullname) -> code object.\n\ +\n\ +Return the code object for the specified module. Raise PythonQtImportError\n\ +is the module couldn't be found."); + +PyDoc_STRVAR(doc_get_source, +"get_source(fullname) -> source string.\n\ +\n\ +Return the source code for the specified module. Raise PythonQtImportError\n\ +is the module couldn't be found, return None if the archive does\n\ +contain the module, but has no source for it."); + +PyMethodDef PythonQtImporter_methods[] = { + {"find_module", PythonQtImporter_find_module, METH_VARARGS, + doc_find_module}, + {"load_module", PythonQtImporter_load_module, METH_VARARGS, + doc_load_module}, + {"get_data", PythonQtImporter_get_data, METH_VARARGS, + doc_get_data}, + {"get_code", PythonQtImporter_get_code, METH_VARARGS, + doc_get_code}, + {"get_source", PythonQtImporter_get_source, METH_VARARGS, + doc_get_source}, + {NULL, NULL} /* sentinel */ +}; + + +PyDoc_STRVAR(PythonQtImporter_doc, +"PythonQtImporter(path) -> PythonQtImporter object\n\ +\n\ +Create a new PythonQtImporter instance. 'path' must be a valid path on disk/or inside of a zip file known to MeVisLab\n\ +. Every path is accepted."); + +#define DEFERRED_ADDRESS(ADDR) 0 + +PyTypeObject PythonQtImporter_Type = { + PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) + 0, + "PythonQtImport.PythonQtImporter", + sizeof(PythonQtImporter), + 0, /* tp_itemsize */ + (destructor)PythonQtImporter_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_compare */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + PyObject_GenericGetAttr, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE , /* tp_flags */ + PythonQtImporter_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + PythonQtImporter_methods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)PythonQtImporter_init, /* tp_init */ + PyType_GenericAlloc, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ + PyObject_Del, /* tp_free */ +}; + + +/* Given a buffer, return the long that is represented by the first + 4 bytes, encoded as little endian. This partially reimplements + marshal.c:r_long() */ +long +PythonQtImport::getLong(unsigned char *buf) +{ + long x; + x = buf[0]; + x |= (long)buf[1] << 8; + x |= (long)buf[2] << 16; + x |= (long)buf[3] << 24; +#if SIZEOF_LONG > 4 + /* Sign extension for 64-bit machines */ + x |= -(x & 0x80000000L); +#endif + return x; +} + +FILE * +open_exclusive(const QString& filename) +{ +#if defined(O_EXCL)&&defined(O_CREAT)&&defined(O_WRONLY)&&defined(O_TRUNC) + /* Use O_EXCL to avoid a race condition when another process tries to + write the same file. When that happens, our open() call fails, + which is just fine (since it's only a cache). + XXX If the file exists and is writable but the directory is not + writable, the file will never be written. Oh well. + */ + QFile::remove(filename); + + int fd; + int flags = O_EXCL|O_CREAT|O_WRONLY|O_TRUNC; +#ifdef O_BINARY + flags |= O_BINARY; /* necessary for Windows */ +#endif +#ifdef WIN32 + fd = _wopen(filename.ucs2(), flags, 0666); +#else + fd = open(filename.local8Bit(), flags, 0666); +#endif + if (fd < 0) + return NULL; + return fdopen(fd, "wb"); +#else + /* Best we can do -- on Windows this can't happen anyway */ + return fopen(filename.toLocal8Bit().constData(), "wb"); +#endif +} + + +void PythonQtImport::writeCompiledModule(PyCodeObject *co, const QString& filename, long mtime) +{ + FILE *fp; + + fp = open_exclusive(filename); + if (fp == NULL) { + if (Py_VerboseFlag) + PySys_WriteStderr( + "# can't create %s\n", filename.toLatin1().constData()); + return; + } +#if PY_VERSION_HEX < 0x02040000 + PyMarshal_WriteLongToFile(PyImport_GetMagicNumber(), fp); +#else + PyMarshal_WriteLongToFile(PyImport_GetMagicNumber(), fp, Py_MARSHAL_VERSION); +#endif + /* First write a 0 for mtime */ +#if PY_VERSION_HEX < 0x02040000 + PyMarshal_WriteLongToFile(0L, fp); +#else + PyMarshal_WriteLongToFile(0L, fp, Py_MARSHAL_VERSION); +#endif +#if PY_VERSION_HEX < 0x02040000 + PyMarshal_WriteObjectToFile((PyObject *)co, fp); +#else + PyMarshal_WriteObjectToFile((PyObject *)co, fp, Py_MARSHAL_VERSION); +#endif + if (ferror(fp)) { + if (Py_VerboseFlag) + PySys_WriteStderr("# can't write %s\n", filename.toLatin1().constData()); + /* Don't keep partial file */ + fclose(fp); + QFile::remove(filename); + return; + } + /* Now write the true mtime */ + fseek(fp, 4L, 0); +#if PY_VERSION_HEX < 0x02040000 + PyMarshal_WriteLongToFile(mtime, fp); +#else + PyMarshal_WriteLongToFile(mtime, fp, Py_MARSHAL_VERSION); +#endif + fflush(fp); + fclose(fp); + if (Py_VerboseFlag) + PySys_WriteStderr("# wrote %s\n", filename.toLatin1().constData()); +//#ifdef macintosh +// PyMac_setfiletype(cpathname, 'Pyth', 'PYC '); +//#endif +} + +/* Given the contents of a .py[co] file in a buffer, unmarshal the data + and return the code object. Return None if it the magic word doesn't + match (we do this instead of raising an exception as we fall back + to .py if available and we don't want to mask other errors). + Returns a new reference. */ +PyObject * +PythonQtImport::unmarshalCode(const QString& path, const QByteArray& data, time_t mtime) +{ + PyObject *code; + // ugly cast, but Python API is not const safe + char *buf = (char*) data.constData(); + int size = data.size(); + + if (size <= 9) { + PySys_WriteStderr("# %s has bad pyc data\n", + path.toLatin1().constData()); + Py_INCREF(Py_None); + return Py_None; + } + + if (getLong((unsigned char *)buf) != PyImport_GetMagicNumber()) { + if (Py_VerboseFlag) + PySys_WriteStderr("# %s has bad magic\n", + path.toLatin1().constData()); + Py_INCREF(Py_None); + return Py_None; + } + + if (mtime != 0 && !(getLong((unsigned char *)buf + 4) == mtime)) { + if (Py_VerboseFlag) + PySys_WriteStderr("# %s has bad mtime\n", + path.toLatin1().constData()); + Py_INCREF(Py_None); + return Py_None; + } + + code = PyMarshal_ReadObjectFromString(buf + 8, size - 8); + if (code == NULL) + return NULL; + if (!PyCode_Check(code)) { + Py_DECREF(code); + PyErr_Format(PyExc_TypeError, + "compiled module %.200s is not a code object", + path.toLatin1().constData()); + return NULL; + } + return code; +} + + +/* Given a string buffer containing Python source code, compile it + return and return a code object as a new reference. */ +PyObject * +PythonQtImport::compileSource(const QString& path, const QByteArray& data) +{ + PyObject *code; + QByteArray data1 = data; +// in qt4, data is null terminated +// data1.resize(data.size()+1); +// data1.data()[data.size()-1] = 0; + code = Py_CompileString(data.data(), path.toLatin1().constData(), + Py_file_input); + return code; +} + + +/* Return the code object for the module named by 'fullname' from the + Zip archive as a new reference. */ +PyObject * +PythonQtImport::getCodeFromData(const QString& path, int isbytecode,int ispackage, time_t mtime) +{ + bool hasImporter = PythonQt::importInterface()!=NULL; + + PyObject *code; + + QByteArray qdata; + if (!hasImporter) { + QFile file(path); + QIODevice::OpenMode flags = QIODevice::ReadOnly; + if (!isbytecode) { + flags |= QIODevice::Text; + } + if (!file.open(flags)) { + return NULL; + } + qdata = file.readAll(); + } else { + if (!isbytecode) { + // mlabDebugConst("MLABPython", "reading source " << path); + bool ok; + qdata = PythonQt::importInterface()->readSourceFile(path, ok); + if (!ok) { + // mlabErrorConst("PythonQtImporter","File could not be verified" << path); + return NULL; + } + if (qdata == " ") { + qdata.clear(); + } + } else { + qdata = PythonQt::importInterface()->readFileAsBytes(path); + } + } + + if (isbytecode) { +// mlabDebugConst("MLABPython", "reading bytecode " << path); + code = unmarshalCode(path, qdata, mtime); + } + else { + // mlabDebugConst("MLABPython", "compiling source " << path); + code = compileSource(path, qdata); + // save a pyc file if possible + QDateTime time; + time = hasImporter?PythonQt::importInterface()->lastModifiedDate(path):QFileInfo(path).lastModified(); + writeCompiledModule((PyCodeObject*)code, path+"c", time.toTime_t()); + } + return code; +} + +time_t +PythonQtImport::getMTimeOfSource(const QString& path) +{ + time_t mtime = 0; + QString path2 = path; + path2.truncate(path.length()-1); + + bool hasImporter = PythonQt::importInterface()!=NULL; + if (hasImporter) { + if (PythonQt::importInterface()->exists(path2)) { + mtime = PythonQt::importInterface()->lastModifiedDate(path2).toTime_t(); + } + } else { + if (QFile::exists(path2)) { + mtime = QFileInfo(path2).lastModified().toTime_t(); + } + } + return mtime; +} + +/* Get the code object associated with the module specified by + 'fullname'. */ +PyObject * +PythonQtImport::getModuleCode(PythonQtImporter *self, char *fullname, + int *p_ispackage, QString& modpath) +{ + QString subname; + struct st_mlab_searchorder *zso; + + subname = getSubName(fullname); + QString path = *self->_path + "/" + subname; + + QString test; + for (zso = mlab_searchorder; *zso->suffix; zso++) { + PyObject *code = NULL; + test = path + zso->suffix; + + if (Py_VerboseFlag > 1) + PySys_WriteStderr("# trying %s\n", + test.toLatin1().constData()); + if (PythonQt::importInterface()->exists(test)) { + time_t mtime = 0; + int ispackage = zso->type & IS_PACKAGE; + int isbytecode = zso->type & IS_BYTECODE; + + if (isbytecode) + mtime = getMTimeOfSource(test); + if (p_ispackage != NULL) + *p_ispackage = ispackage; + code = getCodeFromData(test, isbytecode, ispackage, mtime); + if (code == Py_None) { + Py_DECREF(code); + continue; + } + if (code != NULL) + modpath = test; + return code; + } + } + PyErr_Format(PythonQtImportError, "can't find module '%.200s'", fullname); + + return NULL; +} + +QString PythonQtImport::replaceExtension(const QString& str, const QString& ext) +{ + QString r; + int i = str.lastIndexOf('.'); + if (i!=-1) { + r = str.mid(0,i) + "." + ext; + } else { + r = str + "." + ext; + } + return r; +} + +PyObject* PythonQtImport::getCodeFromPyc(const QString& file) +{ + bool hasImporter = PythonQt::importInterface()!=NULL; + + PyObject* code; + const static QString pycStr("pyc"); + QString pyc = replaceExtension(file, pycStr); + if ((hasImporter && PythonQt::importInterface()->exists(pyc)) || + (!hasImporter && QFile::exists(pyc))) { + time_t mtime = 0; + mtime = getMTimeOfSource(pyc); + code = getCodeFromData(pyc, true, false, mtime); + if (code != Py_None && code != NULL) { + return code; + } + if (code) { + Py_DECREF(code); + } + } + code = getCodeFromData(file,false,false,0); + return code; +} + +/* Module init */ + +PyDoc_STRVAR(mlabimport_doc, +"Imports python files into MeVisLab, completely replaces internal python import"); + +void PythonQtImport::init() +{ + PyObject *mod; + + if (PyType_Ready(&PythonQtImporter_Type) < 0) + return; + + /* Correct directory separator */ + mlab_searchorder[0].suffix[0] = SEP; + mlab_searchorder[1].suffix[0] = SEP; + mlab_searchorder[2].suffix[0] = SEP; + if (Py_OptimizeFlag) { + /* Reverse *.pyc and *.pyo */ + struct st_mlab_searchorder tmp; + tmp = mlab_searchorder[0]; + mlab_searchorder[0] = mlab_searchorder[1]; + mlab_searchorder[1] = tmp; + tmp = mlab_searchorder[3]; + mlab_searchorder[3] = mlab_searchorder[4]; + mlab_searchorder[4] = tmp; + } + + mod = Py_InitModule4("PythonQtImport", NULL, mlabimport_doc, + NULL, PYTHON_API_VERSION); + + PythonQtImportError = PyErr_NewException("PythonQtImport.PythonQtImportError", + PyExc_ImportError, NULL); + if (PythonQtImportError == NULL) + return; + + Py_INCREF(PythonQtImportError); + if (PyModule_AddObject(mod, "PythonQtImportError", + PythonQtImportError) < 0) + return; + + Py_INCREF(&PythonQtImporter_Type); + if (PyModule_AddObject(mod, "PythonQtImporter", + (PyObject *)&PythonQtImporter_Type) < 0) + return; + + // set our importer into the path_hooks to handle all path on sys.path + PyObject* classobj = PyDict_GetItemString(PyModule_GetDict(mod), "PythonQtImporter"); + PyObject* path_hooks = PySys_GetObject("path_hooks"); + PyList_Append(path_hooks, classobj); + +#ifndef WIN32 + // reload the encodings module, because it might fail to custom import requirements (e.g. encryption). + PyObject* modules = PyImport_GetModuleDict(); + PyObject* encodingsModule = PyDict_GetItemString(modules, "encodings"); + if (encodingsModule != NULL) { + PyImport_ReloadModule(encodingsModule); + } +#endif +} diff --git a/src/PythonQtImporter.h b/src/PythonQtImporter.h new file mode 100644 index 0000000..cee6f0a --- /dev/null +++ b/src/PythonQtImporter.h @@ -0,0 +1,127 @@ +#ifndef _PYTHONQTIMPORTER_ +#define _PYTHONQTIMPORTER_ + +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtImporter.h +// \author Florian Link +// \author Last changed by $Author: stk $ +// \date 2004-06 +*/ +//---------------------------------------------------------------------------------- + +#include "Python.h" +#include "structmember.h" +#include "osdefs.h" +#include "marshal.h" +#include "compile.h" +#include + +#include +#include + + +//! defines a python object that stores a Qt slot info +typedef struct _PythonQtImporter { + PyObject_HEAD + QString* _path; +} PythonQtImporter; + + +//! implements importing of python files into PythonQt +/*! also compiles/marshalls/unmarshalls py/pyc files and handles time stamps correctly +*/ +class PythonQtImport +{ +public: + enum module_info { + MI_ERROR, + MI_NOT_FOUND, + MI_MODULE, + MI_PACKAGE + }; + + //! initialize + static void init(); + + //! writes the python code to disk, marshalling and writing the time stamp + static void writeCompiledModule(PyCodeObject *co, const QString& filename, long mtime); + + /*! Given the contents of a .py[co] file in a buffer, unmarshal the data + and return the code object. Return None if it the magic word doesn't + match (we do this instead of raising an exception as we fall back + to .py if available and we don't want to mask other errors). + Returns a new reference. */ + static PyObject *unmarshalCode(const QString& path, const QByteArray& data, time_t mtime); + + //! Given a string buffer containing Python source code, compile it + //! return and return a code object as a new reference. + static PyObject *compileSource(const QString& path, const QByteArray& data); + + //! Return the code object for the module named by 'fullname' from the + //! Zip archive as a new reference. + static PyObject *getCodeFromData(const QString& path, int isbytecode = 0, int ispackage = 0, + time_t mtime = 0); + + //! Get the code object associated with the module specified by + //! 'fullname'. + static PyObject * getModuleCode(PythonQtImporter *self, char *fullname, + int *p_ispackage, QString& modpath); + + + //! gets the compiled code for the given *.py file if there is a valid pyc file, otherwise compiles the file and writes the pyc + static PyObject* getCodeFromPyc(const QString& file); + + //! Return if module exists and is a package or a module + static module_info getModuleInfo(PythonQtImporter* self, const QString& fullname); + + //! get the last name of a dot chain (first.second.last) + static QString getSubName(const QString& str); + + //! Given a buffer, return the long that is represented by the first + //! 4 bytes, encoded as little endian. This partially reimplements + //! marshal.c:r_long() + static long getLong(unsigned char *buf); + + //! get time stamp of file + static time_t getMTimeOfSource(const QString& path); + + //! replace extension of file + static QString replaceExtension(const QString& str, const QString& ext); + +}; + +#endif + diff --git a/src/PythonQtMetaObjectWrapper.cpp b/src/PythonQtMetaObjectWrapper.cpp new file mode 100644 index 0000000..590f002 --- /dev/null +++ b/src/PythonQtMetaObjectWrapper.cpp @@ -0,0 +1,240 @@ +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtMetaObjectWrapper.cpp +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-05 +*/ +//---------------------------------------------------------------------------------- + +#include "PythonQtMetaObjectWrapper.h" +#include + +#include "PythonQt.h" +#include "PythonQtSlot.h" +#include "PythonQtClassInfo.h" +#include "PythonQtConversion.h" + +static void PythonQtMetaObjectWrapper_dealloc(PythonQtMetaObjectWrapper* self) +{ + self->ob_type->tp_free((PyObject*)self); +} + +static PyObject* PythonQtMetaObjectWrapper_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + PythonQtMetaObjectWrapper *self; + + self = (PythonQtMetaObjectWrapper *)type->tp_alloc(type, 0); + if (self != NULL) { + self->_info = NULL; + } + return (PyObject *)self; +} + +static int PythonQtMetaObjectWrapper_init(PythonQtMetaObjectWrapper *self, PyObject *args, PyObject *kwds) +{ + return 0; +} + +PyObject *PythonQtMetaObjectWrapper_call(PyObject *func, PyObject *args, PyObject *kw) { + PythonQtMetaObjectWrapper* wrapper = (PythonQtMetaObjectWrapper*)func; + PyObject* result = NULL; + QString error; + PyObject* err = NULL; + if (wrapper->_info->constructors()) { + result = PythonQtSlotFunction_CallImpl(NULL, wrapper->_info->constructors(), args, kw); + err = PyErr_Occurred(); + } + if (!result) { + QObject* v = NULL; + QListIterator it(PythonQt::self()->constructorHandlers()); + while (!v && it.hasNext()) { + v = it.next()->create(wrapper->_info->metaObject(), args, kw, error); + } + if (v) { + result = PythonQt::priv()->wrapQObject(v); + } + } + if (result) { + // change ownershipflag to be owned by PythonQt + if (result->ob_type == &PythonQtWrapper_Type) { + ((PythonQtWrapper*)result)->_ownedByPythonQt = true; + } + } else { + if (!wrapper->_info->constructors()) { + if (!err) { + if (error.isEmpty()) { + error = QString("No constructors available for ") + wrapper->_info->className(); + } + PyErr_SetString(PyExc_ValueError, error.toLatin1().data()); + } + } + } + return result; +} + +static PyObject *PythonQtMetaObjectWrapper_classname(PythonQtMetaObjectWrapper* type) +{ + return PyString_FromString((QString("Meta_") + type->_info->className()).toLatin1().data()); +} + +static PyObject *PythonQtMetaObjectWrapper_help(PythonQtMetaObjectWrapper* type) +{ + return PythonQt::self()->helpCalled(type->_info); +} + + +static PyMethodDef PythonQtMetaObjectWrapper_methods[] = { + {"className", (PyCFunction)PythonQtMetaObjectWrapper_classname, METH_NOARGS, + "Return the classname of the object" + }, + {"help", (PyCFunction)PythonQtMetaObjectWrapper_help, METH_NOARGS, + "Shows the help of available methods for this class" + }, + {NULL} /* Sentinel */ +}; + + +static PyObject *PythonQtMetaObjectWrapper_getattro(PyObject *obj,PyObject *name) +{ + const char *attributeName; + PythonQtMetaObjectWrapper *wt = (PythonQtMetaObjectWrapper *)obj; + + if ((attributeName = PyString_AsString(name)) == NULL) { + return NULL; + } + + PythonQtMemberInfo member = wt->_info->member(attributeName); + if (member._type == PythonQtMemberInfo::EnumValue) { + return PyInt_FromLong(member._enumValue); + } + if (member._type == PythonQtMemberInfo::Slot && member._slot->isClassDecorator()) { + return PythonQtSlotFunction_New(member._slot, obj, NULL); + } + + // look for the interal methods (className(), help()) + PyObject* internalMethod = Py_FindMethod( PythonQtMetaObjectWrapper_methods, obj, (char*)attributeName); + if (internalMethod) { + return internalMethod; + } + PyErr_Clear(); + + if (qstrcmp(attributeName, "__dict__")==0) { + QStringList l = wt->_info->memberList(true); + PyObject* dict = PyDict_New(); + foreach (QString name, l) { + //PyObject* o = PyObject_GetAttrString(obj, name.toLatin1().data()); + PyDict_SetItemString(dict, name.toLatin1().data(), Py_None); + //Py_DECREF(o); + } + return dict; + } + + QString error = QString(wt->_info->className()) + " has no attribute named '" + QString(attributeName) + "'"; + PyErr_SetString(PyExc_AttributeError, error.toLatin1().data()); + return NULL; +} + +static PyObject * PythonQtMetaObjectWrapper_repr(PyObject * obj) +{ + PythonQtMetaObjectWrapper* wt = (PythonQtMetaObjectWrapper*)obj; + if (wt->_info->isCPPWrapper()) { + return PyString_FromFormat("%s Class (C++ wrapped by %s)", wt->_info->className(), wt->_info->metaObject()->className()); + } else { + return PyString_FromFormat("%s Class", wt->_info->className()); + } +} + +static int PythonQtMetaObjectWrapper_compare(PyObject * obj1, PyObject * obj2) +{ + if (obj1->ob_type == &PythonQtMetaObjectWrapper_Type && + obj2->ob_type == &PythonQtMetaObjectWrapper_Type) { + + PythonQtMetaObjectWrapper* w1 = (PythonQtMetaObjectWrapper*)obj1; + PythonQtMetaObjectWrapper* w2 = (PythonQtMetaObjectWrapper*)obj2; + if (w1->_info == w2->_info) { + return 0; + } else { + return -1; + } + } else { + return -1; + } +} + +PyTypeObject PythonQtMetaObjectWrapper_Type = { + PyObject_HEAD_INIT(NULL) + 0, /*ob_size*/ + "PythonQt.PythonQtMetaObjectWrapper", /*tp_name*/ + sizeof(PythonQtMetaObjectWrapper), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + (destructor)PythonQtMetaObjectWrapper_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + PythonQtMetaObjectWrapper_compare, /*tp_compare*/ + PythonQtMetaObjectWrapper_repr, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash */ + PythonQtMetaObjectWrapper_call, /*tp_call*/ + 0, /*tp_str*/ + PythonQtMetaObjectWrapper_getattro, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ + "PythonQtMetaObjectWrapper object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)PythonQtMetaObjectWrapper_init, /* tp_init */ + 0, /* tp_alloc */ + PythonQtMetaObjectWrapper_new, /* tp_new */ +}; + +//------------------------------------------------------- + diff --git a/src/PythonQtMetaObjectWrapper.h b/src/PythonQtMetaObjectWrapper.h new file mode 100644 index 0000000..6cfff20 --- /dev/null +++ b/src/PythonQtMetaObjectWrapper.h @@ -0,0 +1,76 @@ +#ifndef _PYTHONQTMETAOBJECTWRAPPER_H +#define _PYTHONQTMETAOBJECTWRAPPER_H + +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtMetaObjectWrapper.h +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-05 +*/ +//---------------------------------------------------------------------------------- + +#include + +#include "structmember.h" +#include "methodobject.h" +#include "compile.h" +#include "eval.h" +#include + +class PythonQtClassInfo; +class QObject; +struct QMetaObject; + +extern PyTypeObject PythonQtMetaObjectWrapper_Type; + +//--------------------------------------------------------------- +//! a Python wrapper object for Qt meta objects +typedef struct { + PyObject_HEAD + + //! the class information (which contains the meta object as well) + PythonQtClassInfo* _info; + +} PythonQtMetaObjectWrapper; + +//--------------------------------------------------------------- +// an abstact class for handling construction of objects +class PythonQtConstructorHandler { +public: + virtual QObject* create(const QMetaObject* meta, PyObject *args, PyObject *kw, QString& error) = 0; +}; + +#endif \ No newline at end of file diff --git a/src/PythonQtMethodInfo.cpp b/src/PythonQtMethodInfo.cpp new file mode 100644 index 0000000..e1587e2 --- /dev/null +++ b/src/PythonQtMethodInfo.cpp @@ -0,0 +1,294 @@ +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtMethodInfo.cpp +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-05 +*/ +//---------------------------------------------------------------------------------- + +#include "PythonQtMethodInfo.h" +#include + +QHash PythonQtMethodInfo::_cachedSignatures; +QHash PythonQtMethodInfo::_parameterNameAliases; + +PythonQtMethodInfo::PythonQtMethodInfo(const QMetaMethod& meta) +{ +#ifdef PYTHONQT_DEBUG + QByteArray sig(meta.signature()); + sig = sig.mid(sig.indexOf('(')); + QByteArray fullSig = QByteArray(meta.typeName()) + " " + sig; + std::cout << "caching " << fullSig.data() << std::endl; +#endif + + ParameterInfo type; + fillParameterInfo(type, QByteArray(meta.typeName())); + _parameters.append(type); + QByteArray name; + QList names = meta.parameterTypes(); + foreach (name, names) { + fillParameterInfo(type, name); + _parameters.append(type); + } +} + + +const PythonQtMethodInfo* PythonQtMethodInfo::getCachedMethodInfo(const QMetaMethod& signal) +{ + QByteArray sig(signal.signature()); + sig = sig.mid(sig.indexOf('(')); + QByteArray fullSig = QByteArray(signal.typeName()) + " " + sig; + PythonQtMethodInfo* result = _cachedSignatures.value(fullSig); + if (!result) { + result = new PythonQtMethodInfo(signal); + _cachedSignatures.insert(fullSig, result); + } + return result; +} + +void PythonQtMethodInfo::fillParameterInfo(ParameterInfo& type, const QByteArray& orgName) +{ + QByteArray name = orgName; + + int len = name.length(); + if (len>0) { + if (strncmp(name.constData(), "const ", 6)==0) { + name = name.mid(6); + len -= 6; + type.isConst = true; + } else { + type.isConst = false; + } + // EXTRA: & references are not yet supported, while const & is removed by moc + while (name.at(len-1) == '*') { + len--; + } + if (len!=name.length()) { + name = name.left(len); + type.isPointer = true; + } else { + type.isPointer = false; + } + QByteArray alias = _parameterNameAliases.value(name); + if (!alias.isEmpty()) { + name = alias; + } + + type.typeId = nameToType(name); + if (!type.isPointer && type.typeId == Unknown) { + type.typeId = QMetaType::type(name.constData()); + if (type.typeId == QMetaType::Void) { + type.typeId = Unknown; + } + } + type.name = name; + } else { + type.typeId = QMetaType::Void; + type.isPointer = false; + type.isConst = false; + } +} + +int PythonQtMethodInfo::nameToType(const char* name) +{ + if (_parameterTypeDict.isEmpty()) { + // we could also use QMetaType::nameToType, but that does a string compare search + // and does not support QVariant + + // QMetaType names + _parameterTypeDict.insert("long", QMetaType::Long); + _parameterTypeDict.insert("int", QMetaType::Int); + _parameterTypeDict.insert("short", QMetaType::Short); + _parameterTypeDict.insert("char", QMetaType::Char); + _parameterTypeDict.insert("ulong", QMetaType::ULong); + _parameterTypeDict.insert("unsigned long", QMetaType::ULong); + _parameterTypeDict.insert("uint", QMetaType::UInt); + _parameterTypeDict.insert("unsigned int", QMetaType::UInt); + _parameterTypeDict.insert("ushort", QMetaType::UShort); + _parameterTypeDict.insert("unsigned short", QMetaType::UShort); + _parameterTypeDict.insert("uchar", QMetaType::UChar); + _parameterTypeDict.insert("unsigned char", QMetaType::UChar); + _parameterTypeDict.insert("bool", QMetaType::Bool); + _parameterTypeDict.insert("float", QMetaType::Float); + _parameterTypeDict.insert("double", QMetaType::Double); + _parameterTypeDict.insert("qreal", QMetaType::Double); + _parameterTypeDict.insert("QChar", QMetaType::QChar); + _parameterTypeDict.insert("QByteArray", QMetaType::QByteArray); + _parameterTypeDict.insert("Q3CString", QMetaType::QByteArray); + _parameterTypeDict.insert("QString", QMetaType::QString); + _parameterTypeDict.insert("", QMetaType::Void); + _parameterTypeDict.insert("void", QMetaType::Void); + // QVariant names + _parameterTypeDict.insert("Q_LLONG", QMetaType::LongLong); + _parameterTypeDict.insert("Q_ULLONG", QMetaType::ULongLong); + _parameterTypeDict.insert("qlonglong", QMetaType::LongLong); + _parameterTypeDict.insert("qulonglong", QMetaType::ULongLong); + _parameterTypeDict.insert("qint64", QMetaType::LongLong); + _parameterTypeDict.insert("quint64", QMetaType::ULongLong); + _parameterTypeDict.insert("QIconSet", QMetaType::QIcon); + _parameterTypeDict.insert("QVariantMap", QMetaType::QVariantMap); + _parameterTypeDict.insert("QVariantList", QMetaType::QVariantList); + _parameterTypeDict.insert("QMap", QMetaType::QVariantMap); + _parameterTypeDict.insert("QList", QMetaType::QVariantList); + _parameterTypeDict.insert("QStringList", QMetaType::QStringList); + _parameterTypeDict.insert("QBitArray", QMetaType::QBitArray); + _parameterTypeDict.insert("QDate", QMetaType::QDate); + _parameterTypeDict.insert("QTime", QMetaType::QTime); + _parameterTypeDict.insert("QDateTime", QMetaType::QDateTime); + _parameterTypeDict.insert("QUrl", QMetaType::QUrl); + _parameterTypeDict.insert("QLocale", QMetaType::QLocale); + _parameterTypeDict.insert("QRect", QMetaType::QRect); + _parameterTypeDict.insert("QRectf", QMetaType::QRectF); + _parameterTypeDict.insert("QSize", QMetaType::QSize); + _parameterTypeDict.insert("QSizef", QMetaType::QSizeF); + _parameterTypeDict.insert("QLine", QMetaType::QLine); + _parameterTypeDict.insert("QLinef", QMetaType::QLineF); + _parameterTypeDict.insert("QPoint", QMetaType::QPoint); + _parameterTypeDict.insert("QPointf", QMetaType::QPointF); + _parameterTypeDict.insert("QRegExp", QMetaType::QRegExp); +// _parameterTypeDict.insert("QColorGroup", QMetaType::QColorGroup); + _parameterTypeDict.insert("QFont", QMetaType::QFont); + _parameterTypeDict.insert("QPixmap", QMetaType::QPixmap); + _parameterTypeDict.insert("QBrush", QMetaType::QBrush); + _parameterTypeDict.insert("QColor", QMetaType::QColor); + _parameterTypeDict.insert("QCursor", QMetaType::QCursor); + _parameterTypeDict.insert("QPalette", QMetaType::QPalette); + _parameterTypeDict.insert("QIcon", QMetaType::QIcon); + _parameterTypeDict.insert("QImage", QMetaType::QPolygon); + _parameterTypeDict.insert("QRegion", QMetaType::QRegion); + _parameterTypeDict.insert("QBitmap", QMetaType::QBitmap); + _parameterTypeDict.insert("QSizePolicy", QMetaType::QSizePolicy); + _parameterTypeDict.insert("QKeySequence", QMetaType::QKeySequence); + _parameterTypeDict.insert("QPen", QMetaType::QPen); + _parameterTypeDict.insert("QTextLength", QMetaType::QTextLength); + _parameterTypeDict.insert("QTextFormat", QMetaType::QTextFormat); + _parameterTypeDict.insert("QMatrix", QMetaType::QMatrix); + _parameterTypeDict.insert("QVariant", PythonQtMethodInfo::Variant); + // own special types... (none so far, could be e.g. ObjectList + } + QHash::const_iterator it = _parameterTypeDict.find(name); + if (it!=_parameterTypeDict.end()) { + return it.value(); + } else { + return PythonQtMethodInfo::Unknown; + } +} + +void PythonQtMethodInfo::cleanupCachedMethodInfos() +{ + QHashIterator i(_cachedSignatures); + while (i.hasNext()) { + delete i.next().value(); + } +} + +void PythonQtMethodInfo::addParameterTypeAlias(const QByteArray& alias, const QByteArray& name) +{ + _parameterNameAliases.insert(alias, name); +} + +//------------------------------------------------------------------------------------------------- + +QString PythonQtSlotInfo::fullSignature(bool skipFirstArg) +{ + QString result = _meta.typeName(); + QByteArray sig = slotName(); + QList names = _meta.parameterNames(); + + bool isStatic = false; + bool isConstructor = false; + bool isDestructor = false; + + if (_type == ClassDecorator) { + if (sig.startsWith("new_")) { + sig = sig.mid(strlen("new_")); + isConstructor = true; + } else if (sig.startsWith("delete_")) { + sig = sig.mid(strlen("delete_")); + isDestructor = true; + } else if(sig.startsWith("static_")) { + isStatic = true; + sig = sig.mid(strlen("static_")); + int idx = sig.indexOf("_"); + if (idx>=0) { + sig = sig.mid(idx+1); + } + } + } + + result += QByteArray(" ") + sig; + result += "("; + + int lastEntry = _parameters.count()-1; + for (int i = skipFirstArg?2:1; i<_parameters.count(); i++) { + if (_parameters.at(i).isConst) { + result += "const "; + } + result += _parameters.at(i).name; + if (_parameters.at(i).isPointer) { + result += "*"; + } + if (!names.at(i-1).isEmpty()) { + result += " "; + result += names.at(i-1); + } + if (i!=lastEntry) { + result += ", "; + } + } + result += ")"; + + if (isStatic) { + result = QString("static ") + result; + } + if (isConstructor) { +// result = QString("constructor ") + result; + } + if (isDestructor) { + result = QString("~") + result; + } + return result; +} + + +QByteArray PythonQtSlotInfo::slotName() +{ + QByteArray sig(_meta.signature()); + int idx = sig.indexOf('('); + sig = sig.left(idx); + return sig; +} + diff --git a/src/PythonQtMethodInfo.h b/src/PythonQtMethodInfo.h new file mode 100644 index 0000000..412eee6 --- /dev/null +++ b/src/PythonQtMethodInfo.h @@ -0,0 +1,173 @@ +#ifndef _PYTHONQTMETHODINFO_H +#define _PYTHONQTMETHODINFO_H + +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtMethodInfo.h +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-05 +*/ +//---------------------------------------------------------------------------------- + +#include +#include +#include +#include + +//! stores information about a specific signal/slot/method +class PythonQtMethodInfo +{ +public: + //! this is a funny type union of QMetaType and QVariant, only god knows + //! why QMetaType do not support identical types in Qt4, + //! especial the support of Long, Short, Char etc. is missing in QVariant + //! and QMetaType does not know anything about most variant types and e.g. LongLong + enum ParameterType { + Unknown = -1, + Variant = -2 + }; + + //! stores the QVariant id (if available) and the name of the type + struct ParameterInfo { + int typeId; // a mixture from QMetaType and ParameterType + QByteArray name; + bool isPointer; + bool isConst; + }; + + PythonQtMethodInfo() {}; + ~PythonQtMethodInfo() {}; + PythonQtMethodInfo(const QMetaMethod& meta); + PythonQtMethodInfo(const PythonQtMethodInfo& other) { + _parameters = other._parameters; + } + + //! returns the method info of the signature, uses a cache internally to speed up + //! multiple requests for the same method + static const PythonQtMethodInfo* getCachedMethodInfo(const QMetaMethod& method); + + //! cleanup the cache + static void cleanupCachedMethodInfos(); + + //! returns the number of parameters (without the return value) + int parameterCount() const { return _parameters.size(); }; + + //! returns the id for the given type (using an internal dictionary) + static int nameToType(const char* name); + + //! get the parameter infos + const QList& parameters() const { return _parameters; } + + //! add an alias for a typename, e.g. QObjectList and QList. + static void addParameterTypeAlias(const QByteArray& alias, const QByteArray& name); + + protected: + static void fillParameterInfo(ParameterInfo& type, const QByteArray& name); + + static QHash _parameterTypeDict; + static QHash _parameterNameAliases; + + //! stores the cached signatures of methods to speedup mapping from Qt to Python types + static QHash _cachedSignatures; + + QList _parameters; +}; + +//! stores information about a slot, including a next pointer to overloaded slots +class PythonQtSlotInfo : public PythonQtMethodInfo +{ +public: + enum Type { + MemberSlot, InstanceDecorator, ClassDecorator + }; + + PythonQtSlotInfo(const PythonQtSlotInfo& info):PythonQtMethodInfo() { + _meta = info._meta; + _parameters = info._parameters; + _slotIndex = info._slotIndex; + _next = NULL; + _decorator = info._decorator; + _type = info._type; + } + + PythonQtSlotInfo(const QMetaMethod& meta, int slotIndex, QObject* decorator = NULL, Type type = MemberSlot ):PythonQtMethodInfo() + { + const PythonQtMethodInfo* info = getCachedMethodInfo(meta); + _meta = meta; + _parameters = info->parameters(); + _slotIndex = slotIndex; + _next = NULL; + _decorator = decorator; + _type = type; + } + + +public: + const QMetaMethod* metaMethod() const { return &_meta; } + + //! get the index of the slot (needed for qt_metacall) + int slotIndex() const { return _slotIndex; } + + //! get next overloaded slot (which has the same name) + PythonQtSlotInfo* nextInfo() const { return _next; } + + //! set the next overloaded slot + void setNextInfo(PythonQtSlotInfo* next) { _next = next; } + + //! returns if the slot is a decorator slot + bool isInstanceDecorator() { return _decorator!=NULL && _type == InstanceDecorator; } + + //! returns if the slot is a constructor slot + bool isClassDecorator() { return _decorator!=NULL && _type == ClassDecorator; } + + QObject* decorator() { return _decorator; } + + //! get the full signature including return type + QString fullSignature(bool skipFirstArg); + + //! get the short slot name + QByteArray slotName(); + +private: + int _slotIndex; + PythonQtSlotInfo* _next; + QObject* _decorator; + Type _type; + QMetaMethod _meta; +}; + + +#endif diff --git a/src/PythonQtMisc.cpp b/src/PythonQtMisc.cpp new file mode 100644 index 0000000..5628cbc --- /dev/null +++ b/src/PythonQtMisc.cpp @@ -0,0 +1,43 @@ +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtMisc.cpp +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-05 +*/ +//---------------------------------------------------------------------------------- + +#include "PythonQtMisc.h" + diff --git a/src/PythonQtMisc.h b/src/PythonQtMisc.h new file mode 100644 index 0000000..ffc83b5 --- /dev/null +++ b/src/PythonQtMisc.h @@ -0,0 +1,134 @@ +#ifndef _PYTHONQTMISC_H +#define _PYTHONQTMISC_H + +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtMisc.h +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-05 +*/ +//---------------------------------------------------------------------------------- + + +#include + +#define PythonQtValueStorage_ADD_VALUE(store, type, value, ptr) \ +{ type* item = (type*)store.nextValuePtr(); \ + *item = value; \ + ptr = (void*)item; \ +} + +//! stores a position in the PythonQtValueStorage +class PythonQtValueStoragePosition { + +public: + PythonQtValueStoragePosition() { chunkIdx = 0; chunkOffset = 0; } + + int chunkIdx; + int chunkOffset; + +}; + +//! a helper class that stores basic C++ value types in chunks +template class PythonQtValueStorage +{ +public: + PythonQtValueStorage() { + _chunkIdx = 0; + _chunkOffset = 0; + _currentChunk = new T[chunkEntries]; + _chunks.append(_currentChunk); + }; + + //! clear all memory + void clear() { + T* chunk; + foreach(chunk, _chunks) { + delete[]chunk; + } + } + + //! reset the storage to 0 (without freeing memory, thus caching old entries for reuse) + void reset() { + _chunkIdx = 0; + _chunkOffset = 0; + _currentChunk = _chunks.at(0); + } + + //! get the current position to be restored with setPos + void getPos(PythonQtValueStoragePosition & pos) { + pos.chunkIdx = _chunkIdx; + pos.chunkOffset = _chunkOffset; + } + + //! set the current position (without freeing memory, thus caching old entries for reuse) + void setPos(const PythonQtValueStoragePosition& pos) { + _chunkOffset = pos.chunkOffset; + if (_chunkIdx != pos.chunkIdx) { + _chunkIdx = pos.chunkIdx; + _currentChunk = _chunks.at(_chunkIdx); + } + } + + //! add one default constructed value and return the pointer to it + T* nextValuePtr() { + if (_chunkOffset>=chunkEntries) { + _chunkIdx++; + if (_chunkIdx >= _chunks.size()) { + T* newChunk = new T[chunkEntries]; + _chunks.append(newChunk); + _currentChunk = newChunk; + } else { + _currentChunk = _chunks.at(_chunkIdx); + } + _chunkOffset = 0; + } + T* newEntry = _currentChunk + _chunkOffset; + _chunkOffset++; + return newEntry; + }; + +private: + QList _chunks; + + int _chunkIdx; + int _chunkOffset; + T* _currentChunk; + +}; + + +#endif diff --git a/src/PythonQtObjectPtr.cpp b/src/PythonQtObjectPtr.cpp new file mode 100644 index 0000000..d424b52 --- /dev/null +++ b/src/PythonQtObjectPtr.cpp @@ -0,0 +1,84 @@ +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtObjectPtr.cpp +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-05 +*/ +//---------------------------------------------------------------------------------- + +#include + +QVariant PythonQtObjectPtr::evalScript(const QString& script, int start) +{ + return PythonQt::self()->evalScript(_object, script, start); +} + +void PythonQtObjectPtr::evalFile(const QString& file) +{ + PythonQt::self()->evalFile(_object, file); +} + +QVariant PythonQtObjectPtr::evalCode(PyObject* pycode) +{ + return PythonQt::self()->evalCode(_object, pycode); +} + +void PythonQtObjectPtr::addObject(const QString& name, QObject* object) +{ + PythonQt::self()->addObject(_object, name, object); +} + +void PythonQtObjectPtr::addVariable(const QString& name, const QVariant& v) +{ + PythonQt::self()->addVariable(_object, name, v); +} + +void PythonQtObjectPtr::removeVariable(const QString& name) +{ + PythonQt::self()->removeVariable(_object, name); +} + +QVariant PythonQtObjectPtr::getVariable(const QString& name) +{ + return PythonQt::self()->getVariable(_object, name); +} + + +QVariant PythonQtObjectPtr::call(const QString& callable, const QVariantList& args) +{ + return PythonQt::self()->call(_object, callable, args); +} + diff --git a/src/PythonQtObjectPtr.h b/src/PythonQtObjectPtr.h new file mode 100644 index 0000000..5a15859 --- /dev/null +++ b/src/PythonQtObjectPtr.h @@ -0,0 +1,155 @@ +#ifndef _PYTHONQTOBJECTPTR_H +#define _PYTHONQTOBJECTPTR_H + +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtObjectPtr.h +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-05 +*/ +//---------------------------------------------------------------------------------- + +#include +#include "PythonQtSystem.h" + +//! a smart pointer that stores a PyObject pointer and that handles reference counting automatically +class PYTHONQT_EXPORT PythonQtObjectPtr +{ +public: + PythonQtObjectPtr():_object(NULL) {} + + PythonQtObjectPtr(const PythonQtObjectPtr &p):_object(NULL) { + setObject(p.object()); + } + + PythonQtObjectPtr(PyObject* o) { + _object = o; + if (o) Py_INCREF(_object); + } + + ~PythonQtObjectPtr() { if (_object) Py_DECREF(_object); } + + PythonQtObjectPtr &operator=(const PythonQtObjectPtr &p) { + setObject(p.object()); + return *this; + } + + PythonQtObjectPtr &operator=(PyObject* o) { + setObject(o); + return *this; + } + + bool operator==( const PythonQtObjectPtr &p ) const { + return object() == p.object(); + } + + bool operator!= ( const PythonQtObjectPtr& p ) const { + return !( *this == p ); + } + + bool operator==( PyObject* p ) const { + return object() == p; + } + + bool operator!= ( PyObject* p ) const { + return object() != p; + } + + bool isNull() const { return !object(); } + + PyObject* operator->() const { return object(); } + + PyObject& operator*() const { return *( object() ); } + + operator PyObject*() const { return object(); } + + //! sets the object and passes the ownership (stealing the reference, in Python slang) + void setNewRef(PyObject* o) { + if (o != _object) { + if (_object) Py_DECREF(_object); + _object = o; + } + } + + PyObject* object() const { + return _object; + } + + //! evaluates the given script code in the context of this object and returns the result value + QVariant evalScript(const QString& script, int start = Py_file_input); + + //! evaluates the given code and returns the result value (use Py_Compile etc. to create pycode from string) + //! If pycode is NULL, a python error is printed. + QVariant evalCode(PyObject* pycode); + + //! evaluates the given code in the context + void evalFile(const QString& filename); + + //! add the given \c object to the \c module as a variable with \c name (it can be removed via clearVariable) + void addObject(const QString& name, QObject* object); + + //! add the given variable to the module + void addVariable(const QString& name, const QVariant& v); + + //! remove the given variable + void removeVariable(const QString& name); + + //! get the variable with the \c name of the \c module, returns an invalid QVariant on error + QVariant getVariable(const QString& name); + + //! call the given python object (in the scope of the current object), returns the result converted to a QVariant + QVariant call(const QString& callable, const QVariantList& args); + + +protected: + + void setObject(PyObject* o) { + if (o != _object) { + if (_object) Py_DECREF(_object); + _object = o; + if (_object) Py_INCREF(_object); + } + } + +private: + PyObject* _object; +}; + + +// register it to the meta type system +Q_DECLARE_METATYPE(PythonQtObjectPtr) + +#endif \ No newline at end of file diff --git a/src/PythonQtSignalReceiver.cpp b/src/PythonQtSignalReceiver.cpp new file mode 100644 index 0000000..e83fd2e --- /dev/null +++ b/src/PythonQtSignalReceiver.cpp @@ -0,0 +1,171 @@ +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtSignalReceiver.cpp +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-05 +*/ +//---------------------------------------------------------------------------------- + +#include "PythonQtSignalReceiver.h" +#include "PythonQtClassInfo.h" +#include "PythonQtMethodInfo.h" +#include "PythonQtConversion.h" +#include +#include + +void PythonQtSignalTarget::call(void **arguments) const +{ + const PythonQtMethodInfo* m = methodInfo(); + // paramterCount includes return value: + int count = m->parameterCount(); + + PyObject* pargs = NULL; + if (count>1) { + pargs = PyTuple_New(count-1); + } + bool err = false; + // transform Qt values to Python + const QList& params = m->parameters(); + for (int i = 1; i < count; i++) { + const PythonQtMethodInfo::ParameterInfo& param = params.at(i); + PyObject* arg = PythonQtConv::ConvertQtValueToPython(param, arguments[i]); + if (arg) { + // steals reference, no unref + PyTuple_SetItem(pargs, i-1,arg); + } else { + err = true; + break; + } + } + + if (!err) { + PyErr_Clear(); + PyObject* result = PyObject_CallObject(_callable, pargs); + if (result) { + // ok + Py_DECREF(result); + } else { + PythonQt::self()->handleError(); + } + } + if (pargs) { + // free the arguments again + Py_DECREF(pargs); + } +} + +//------------------------------------------------------------------------------ + +PythonQtSignalReceiver::PythonQtSignalReceiver(QObject* obj):PythonQtSignalReceiverBase(obj) +{ + _obj = obj; + _slotCount = staticMetaObject.methodOffset(); +} + +PythonQtSignalReceiver::~PythonQtSignalReceiver() +{ +} + + +bool PythonQtSignalReceiver::addSignalHandler(const char* signal, PyObject* callable) +{ + bool flag = false; + int sigId = getSignalIndex(signal); + if (sigId>=0) { + // create PythonQtMethodInfo from signal + QMetaMethod meta = _obj->metaObject()->method(sigId); + const PythonQtMethodInfo* signalInfo = PythonQtMethodInfo::getCachedMethodInfo(meta); + PythonQtSignalTarget t(sigId, signalInfo, _slotCount, callable); + _targets.append(t); + // now connect to ourselves with the new slot id + QMetaObject::connect(_obj, sigId, this, _slotCount, Qt::AutoConnection, 0); + + _slotCount++; + flag = true; + } + return flag; +} + +bool PythonQtSignalReceiver::removeSignalHandler(const char* signal, PyObject* callable) +{ + bool found = false; + int sigId = getSignalIndex(signal); + if (sigId>=0) { + QMutableListIterator i(_targets); + while (i.hasNext()) { + if (i.next().isSame(sigId, callable)) { + i.remove(); + found = true; + break; + } + } + } + return found; +} + +void PythonQtSignalReceiver::removeSignalHandlers() +{ + _targets.clear(); +} + +int PythonQtSignalReceiver::getSignalIndex(const char* signal) +{ + int sigId = _obj->metaObject()->indexOfSignal(signal+1); + if (sigId<0) { + QByteArray tmpSig = QMetaObject::normalizedSignature(signal+1); + sigId = _obj->metaObject()->indexOfSignal(tmpSig); + } + return sigId; +} + +int PythonQtSignalReceiver::qt_metacall(QMetaObject::Call c, int id, void **arguments) +{ +// mlabDebugConst("PythonQt", "PythonQtSignalReceiver invoke " << _obj->className() << " " << _obj->name() << " " << id); + if (c != QMetaObject::InvokeMetaMethod) { + QObject::qt_metacall(c, id, arguments); + } + + bool found = false; + foreach(const PythonQtSignalTarget& t, _targets) { + if (t.slotId() == id) { + found = true; + t.call(arguments); + break; + } + } + return 0; +} + diff --git a/src/PythonQtSignalReceiver.h b/src/PythonQtSignalReceiver.h new file mode 100644 index 0000000..6a59517 --- /dev/null +++ b/src/PythonQtSignalReceiver.h @@ -0,0 +1,133 @@ +#ifndef _PYTHONQTSIGNALRECEIVER_H +#define _PYTHONQTSIGNALRECEIVER_H + +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtSignalReceiver.h +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-05 +*/ +//---------------------------------------------------------------------------------- + +#include "PythonQt.h" +class PythonQtMethodInfo; + +//! stores information about a signal target +/*! copy construction and assignment works fine with the C++ standard behaviour and are thus not implemented +*/ +class PythonQtSignalTarget { +public: + PythonQtSignalTarget() { + _signalId = -1; + _methodInfo = NULL; + _slotId = -1; + } + + PythonQtSignalTarget(int signalId,const PythonQtMethodInfo* methodInfo, int slotId, PyObject* callable) + { + _signalId = signalId; + _slotId = slotId; + _methodInfo = methodInfo; + _callable = callable; + }; + + ~PythonQtSignalTarget() { + }; + + //! get the id of the original signal + int signalId() const { return _signalId; } + + //! get the id that was assigned to this simulated slot + int slotId() const { return _slotId; } + + //! get the signals parameter info + const PythonQtMethodInfo* methodInfo() const { return _methodInfo; } + + //! call the python callable with the given arguments (as defined in methodInfo) + void call(void **arguments) const; + + //! check if it is the same signal target + bool isSame(int signalId, PyObject* callable) const { return callable==_callable && signalId==_signalId; } + +private: + int _signalId; + int _slotId; + const PythonQtMethodInfo* _methodInfo; + PythonQtObjectPtr _callable; +}; + +//! base class for signal receivers +/*! +*/ +class PythonQtSignalReceiverBase : public QObject { + Q_OBJECT +public: + PythonQtSignalReceiverBase(QObject* obj):QObject(obj) {}; +}; + +//! receives all signals for one QObject +/*! we derive from our base but do not declare the QObject macro because we want to reimplement qt_metacall only. +*/ +class PythonQtSignalReceiver : public PythonQtSignalReceiverBase { + +public: + PythonQtSignalReceiver(QObject* obj); + ~PythonQtSignalReceiver(); + + //! add a signal handler + bool addSignalHandler(const char* signal, PyObject* callable); + + //! remove a signal handler + bool removeSignalHandler(const char* signal, PyObject* callable); + + //! remove all signal handlers + void removeSignalHandlers(); + + //! we implement this method to simulate a number of slots that match the ids in _targets + virtual int qt_metacall(QMetaObject::Call c, int id, void **arguments); + +private: + //! get the index of the signal + int getSignalIndex(const char* signal); + + QObject* _obj; + int _slotCount; + // linear list may get slow on multiple targets, but I think typically we have many objects and just a few signals + QList _targets; +}; + + +#endif diff --git a/src/PythonQtSlot.cpp b/src/PythonQtSlot.cpp new file mode 100644 index 0000000..84cec69 --- /dev/null +++ b/src/PythonQtSlot.cpp @@ -0,0 +1,450 @@ +/* +* +* Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* Further, this software is distributed without any warranty that it is +* free of the rightful claim of any third person regarding infringement +* or the like. Any license provided herein, whether implied or +* otherwise, applies only to this software file. Patent licenses, if +* any, provided herein do not apply to combinations of this program with +* other software, or any other product whatsoever. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Contact information: MeVis Research GmbH, Universitaetsallee 29, +* 28359 Bremen, Germany or: +* +* http://www.mevis.de +* +*/ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtSlot.cpp +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-05 +*/ +//---------------------------------------------------------------------------------- + +#include "PythonQt.h" +#include "PythonQtSlot.h" +#include "PythonQtWrapper.h" +#include "PythonQtClassInfo.h" +#include "PythonQtMisc.h" +#include "PythonQtConversion.h" +#include + +#define PYTHONQT_MAX_ARGS 32 + + +PyObject* PythonQtCallSlot(QObject* objectToCall, PyObject* args, bool strict, PythonQtSlotInfo* info, bool isVariantCall, void* firstArgument) +{ + if (isVariantCall && info->isInstanceDecorator()) return NULL; + + static unsigned int recursiveEntry = 0; + + // store the current storage position, so that we can get back to this state after a slot is called + // (do this locally, so that we have all positions on the stack + PythonQtValueStoragePosition globalValueStoragePos; + PythonQtValueStoragePosition globalPtrStoragePos; + PythonQtValueStoragePosition globalVariantStoragePos; + PythonQtConv::global_valueStorage.getPos(globalValueStoragePos); + PythonQtConv::global_ptrStorage.getPos(globalPtrStoragePos); + PythonQtConv::global_variantStorage.getPos(globalVariantStoragePos); + + recursiveEntry++; + + // the arguments that are passed to qt_metacall + void* argList[PYTHONQT_MAX_ARGS]; + PyObject* result = NULL; + int argc = info->parameterCount(); + const QList& params = info->parameters(); + + bool returnValueIsEnum = false; + const PythonQtSlotInfo::ParameterInfo& returnValueParam = params.at(0); + // set return argument to NULL + argList[0] = NULL; + + if (returnValueParam.typeId != QMetaType::Void) { + // extra handling of enum return value + if (!returnValueParam.isPointer && returnValueParam.typeId == PythonQtMethodInfo::Unknown) { + returnValueIsEnum = PythonQt::priv()->isEnumType(objectToCall->metaObject(), returnValueParam.name); + if (returnValueIsEnum) { + // create enum return value + PythonQtValueStorage_ADD_VALUE(PythonQtConv::global_valueStorage, long, 0, argList[0]); + } + } + if (argList[0]==NULL) { + // create empty default value for the return value + argList[0] = PythonQtConv::CreateQtReturnValue(returnValueParam); + } + } + + const QMetaObject* meta = objectToCall?objectToCall->metaObject():NULL; + bool ok = true; + bool skipFirst = false; + if (info->isInstanceDecorator() || isVariantCall) { + skipFirst = true; + if (!firstArgument) { + argList[1] = &objectToCall; + } else { + // for the variant call we take the ptr to the variant data, for decorators on CPP objects, we take the cpp ptr + argList[1] = &firstArgument; + } + if (ok) { + for (int i = 2; idecorator()?info->decorator():objectToCall)->qt_metacall(QMetaObject::InvokeMetaMethod, info->slotIndex(), argList); + + if (argList[0] || returnValueParam.typeId == QMetaType::Void) { + if (!returnValueIsEnum) { + result = PythonQtConv::ConvertQtValueToPython(returnValueParam, argList[0]); + } else { + result = PyInt_FromLong(*((unsigned int*)argList[0])); + } + } else { + QString e = QString("Called ") + info->fullSignature(skipFirst) + ", return type is ignored because it is unknown to PythonQt."; + PyErr_SetString(PyExc_ValueError, e.toLatin1().data()); + result = NULL; + } + } + recursiveEntry--; + + // reset the parameter storage position to the stored pos to "pop" the parameter stack + PythonQtConv::global_valueStorage.setPos(globalValueStoragePos); + PythonQtConv::global_ptrStorage.setPos(globalPtrStoragePos); + PythonQtConv::global_variantStorage.setPos(globalVariantStoragePos); + + // NOTE: it is important to only return here, otherwise the stack will not be popped!!! + return result; +} + +//----------------------------------------------------------------------------------- + +static PythonQtSlotFunctionObject *pythonqtslot_free_list = NULL; + +PyObject *PythonQtSlotFunction_Call(PyObject *func, PyObject *args, PyObject *kw) +{ + PythonQtSlotFunctionObject* f = (PythonQtSlotFunctionObject*)func; + PythonQtSlotInfo* info = f->m_ml; + if (f->m_self->ob_type == &PythonQtWrapper_Type) { + PythonQtWrapper* self = (PythonQtWrapper*) f->m_self; + return PythonQtSlotFunction_CallImpl(self->_obj, info, args, kw, false, self->_wrappedPtr); + } else if (f->m_self->ob_type == &PythonQtVariantWrapper_Type) { + PythonQtVariantWrapper* self = (PythonQtVariantWrapper*) f->m_self; + if (!info->isClassDecorator()) { + return PythonQtSlotFunction_CallImpl(self->_wrapper, info, args, kw, true, (void*)self->_variant->constData()); + } else { + return PythonQtSlotFunction_CallImpl(NULL, info, args, kw); + } + } else if (f->m_self->ob_type == &PythonQtMetaObjectWrapper_Type) { + return PythonQtSlotFunction_CallImpl(NULL, info, args, kw); + } else { + return NULL; + } +} + +PyObject *PythonQtSlotFunction_CallImpl(QObject* objectToCall, PythonQtSlotInfo* info, PyObject *args, PyObject *kw, bool isVariantCall, void* firstArg) +{ + int argc = PyTuple_Size(args); + +#ifdef PYTHONQT_DEBUG + std::cout << "called " << info->metaMethod()->typeName() << " " << info->metaMethod()->signature() << std::endl; +#endif + + PyObject* r = NULL; + + if (info->nextInfo()) { + // overloaded slot call, try on all slots with strict conversion first + PythonQtSlotInfo* i = info; + while (i && r==NULL) { + bool skipFirst = (i->isInstanceDecorator() || isVariantCall); + if (i->parameterCount()-1-(skipFirst?1:0) == argc) { + PyErr_Clear(); + r = PythonQtCallSlot(objectToCall, args, true, i, isVariantCall, firstArg); + if (PyErr_Occurred()) break; + } + i = i->nextInfo(); + } + if (!r) { + // try on all slots with non-strict conversion + i = info; + while (i && r==NULL) { + bool skipFirst = (i->isInstanceDecorator() || isVariantCall); + if (i->parameterCount()-1-(skipFirst?1:0) == argc) { + PyErr_Clear(); + r = PythonQtCallSlot(objectToCall, args, false, i, isVariantCall, firstArg); + if (PyErr_Occurred()) break; + } + i = i->nextInfo(); + } + } + if (r==NULL && !PyErr_Occurred()) { + QString e = QString("Could not find matching overload for given arguments:\n" + PythonQtConv::PyObjGetString(args) + "\n The following slots are available:\n"); + PythonQtSlotInfo* i = info; + while (i) { + bool skipFirst = (i->isInstanceDecorator() || isVariantCall); + e += QString(i->fullSignature(skipFirst)) + "\n"; + i = i->nextInfo(); + } + PyErr_SetString(PyExc_ValueError, e.toLatin1().data()); + } + } else { + // simple (non-overloaded) slot call + bool skipFirst = (info->isInstanceDecorator() || isVariantCall); + if (info->parameterCount()-1-(skipFirst?1:0) == argc) { + PyErr_Clear(); + r = PythonQtCallSlot(objectToCall, args, false, info, isVariantCall, firstArg); + if (r==NULL && !PyErr_Occurred()) { + QString e = QString("Called ") + info->fullSignature(skipFirst) + " with wrong arguments: " + PythonQtConv::PyObjGetString(args); + PyErr_SetString(PyExc_ValueError, e.toLatin1().data()); + } + } else { + QString e = QString("Called ") + info->fullSignature(skipFirst) + " with wrong number of arguments: " + PythonQtConv::PyObjGetString(args); + PyErr_SetString(PyExc_ValueError, e.toLatin1().data()); + } + } + + return r; +} + +PyObject * +PythonQtSlotFunction_New(PythonQtSlotInfo *ml, PyObject *self, PyObject *module) +{ + PythonQtSlotFunctionObject *op; + op = pythonqtslot_free_list; + if (op != NULL) { + pythonqtslot_free_list = (PythonQtSlotFunctionObject *)(op->m_self); + PyObject_INIT(op, &PythonQtSlotFunction_Type); + } + else { + op = PyObject_GC_New(PythonQtSlotFunctionObject, &PythonQtSlotFunction_Type); + if (op == NULL) + return NULL; + } + op->m_ml = ml; + Py_XINCREF(self); + op->m_self = self; + Py_XINCREF(module); + op->m_module = module; + PyObject_GC_Track(op); + return (PyObject *)op; +} + +PythonQtSlotInfo* +PythonQtSlotFunction_GetSlotInfo(PyObject *op) +{ + if (!PythonQtSlotFunction_Check(op)) { + PyErr_BadInternalCall(); + return NULL; + } + return ((PythonQtSlotFunctionObject *)op) -> m_ml; +} + +PyObject * +PythonQtSlotFunction_GetSelf(PyObject *op) +{ + if (!PythonQtSlotFunction_Check(op)) { + PyErr_BadInternalCall(); + return NULL; + } + return ((PythonQtSlotFunctionObject *)op) -> m_self; +} + +/* Methods (the standard built-in methods, that is) */ + +static void +meth_dealloc(PythonQtSlotFunctionObject *m) +{ + PyObject_GC_UnTrack(m); + Py_XDECREF(m->m_self); + Py_XDECREF(m->m_module); + m->m_self = (PyObject *)pythonqtslot_free_list; + pythonqtslot_free_list = m; +} + +static PyObject * +meth_get__doc__(PythonQtSlotFunctionObject *m, void *closure) +{ + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject * +meth_get__name__(PythonQtSlotFunctionObject *m, void *closure) +{ + return PyString_FromString(m->m_ml->metaMethod()->signature()); +} + +static int +meth_traverse(PythonQtSlotFunctionObject *m, visitproc visit, void *arg) +{ + int err; + if (m->m_self != NULL) { + err = visit(m->m_self, arg); + if (err) + return err; + } + if (m->m_module != NULL) { + err = visit(m->m_module, arg); + if (err) + return err; + } + return 0; +} + +static PyObject * +meth_get__self__(PythonQtSlotFunctionObject *m, void *closure) +{ + PyObject *self; + if (PyEval_GetRestricted()) { + PyErr_SetString(PyExc_RuntimeError, + "method.__self__ not accessible in restricted mode"); + return NULL; + } + self = m->m_self; + if (self == NULL) + self = Py_None; + Py_INCREF(self); + return self; +} + +static PyGetSetDef meth_getsets [] = { + {"__doc__", (getter)meth_get__doc__, NULL, NULL}, + {"__name__", (getter)meth_get__name__, NULL, NULL}, + {"__self__", (getter)meth_get__self__, NULL, NULL}, + {0} +}; + +#define OFF(x) offsetof(PythonQtSlotFunctionObject, x) + +static PyMemberDef meth_members[] = { + {"__module__", T_OBJECT, OFF(m_module), WRITE_RESTRICTED}, + {NULL} +}; + +static PyObject * +meth_repr(PythonQtSlotFunctionObject *m) +{ + return PyString_FromFormat("", + m->m_ml->metaMethod()->signature(), + m->m_self->ob_type->tp_name, + m->m_self); +} + +static int +meth_compare(PythonQtSlotFunctionObject *a, PythonQtSlotFunctionObject *b) +{ + if (a->m_self != b->m_self) + return (a->m_self < b->m_self) ? -1 : 1; + if (a->m_ml == b->m_ml) + return 0; + if (strcmp(a->m_ml->metaMethod()->signature(), b->m_ml->metaMethod()->signature()) < 0) + return -1; + else + return 1; +} + +static long +meth_hash(PythonQtSlotFunctionObject *a) +{ + long x,y; + if (a->m_self == NULL) + x = 0; + else { + x = PyObject_Hash(a->m_self); + if (x == -1) + return -1; + } + y = _Py_HashPointer((void*)(a->m_ml)); + if (y == -1) + return -1; + x ^= y; + if (x == -1) + x = -2; + return x; +} + + +PyTypeObject PythonQtSlotFunction_Type = { + PyObject_HEAD_INIT(&PyType_Type) + 0, + "builtin_qt_slot", + sizeof(PythonQtSlotFunctionObject), + 0, + (destructor)meth_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + (cmpfunc)meth_compare, /* tp_compare */ + (reprfunc)meth_repr, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + (hashfunc)meth_hash, /* tp_hash */ + PythonQtSlotFunction_Call, /* tp_call */ + 0, /* tp_str */ + PyObject_GenericGetAttr, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ + 0, /* tp_doc */ + (traverseproc)meth_traverse, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + meth_members, /* tp_members */ + meth_getsets, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ +}; + +/* Clear out the free list */ + +void +PythonQtSlotFunction_Fini(void) +{ + while (pythonqtslot_free_list) { + PythonQtSlotFunctionObject *v = pythonqtslot_free_list; + pythonqtslot_free_list = (PythonQtSlotFunctionObject *)(v->m_self); + PyObject_GC_Del(v); + } +} + diff --git a/src/PythonQtSlot.h b/src/PythonQtSlot.h new file mode 100644 index 0000000..8fc1cdb --- /dev/null +++ b/src/PythonQtSlot.h @@ -0,0 +1,79 @@ +#ifndef _PYTHONQTSLOT_H +#define _PYTHONQTSLOT_H + +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtSlot.h +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-05 +*/ +//---------------------------------------------------------------------------------- + +#include "Python.h" +#include "structmember.h" + +class PythonQtSlotInfo; + +extern PyTypeObject PythonQtSlotFunction_Type; + +#define PythonQtSlotFunction_Check(op) ((op)->ob_type == &PythonQtSlotFunction_Type) + +PythonQtSlotInfo* PythonQtSlotFunction_GetSlotInfo(PyObject *); +PyObject* PythonQtSlotFunction_GetSelf(PyObject *); + +/* Macros for direct access to these values. Type checks are *not* + done, so use with care. */ +#define PythonQtSlotFunction_GET_SELF(func) \ + (((PythonQtSlotFunctionObject *)func) -> m_self) + +PyObject* PythonQtSlotFunction_Call(PyObject *, PyObject *, PyObject *); + +PyObject *PythonQtSlotFunction_CallImpl(QObject* objectToCall, PythonQtSlotInfo* info, PyObject *args, PyObject *kw, bool isVariantCall=false, void* firstArg=NULL); + + +PyObject* PythonQtSlotFunction_New(PythonQtSlotInfo *, PyObject *, + PyObject *); + +//! defines a python object that stores a Qt slot info +typedef struct { + PyObject_HEAD + PythonQtSlotInfo *m_ml; /* Description of the C function to call */ + PyObject *m_self; /* Passed as 'self' arg to the C func, can be NULL */ + PyObject *m_module; /* The __module__ attribute, can be anything */ +} PythonQtSlotFunctionObject; + + +#endif diff --git a/src/PythonQtStdDecorators.cpp b/src/PythonQtStdDecorators.cpp new file mode 100644 index 0000000..145496b --- /dev/null +++ b/src/PythonQtStdDecorators.cpp @@ -0,0 +1,116 @@ +/* +* +* Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* Further, this software is distributed without any warranty that it is +* free of the rightful claim of any third person regarding infringement +* or the like. Any license provided herein, whether implied or +* otherwise, applies only to this software file. Patent licenses, if +* any, provided herein do not apply to combinations of this program with +* other software, or any other product whatsoever. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Contact information: MeVis Research GmbH, Universitaetsallee 29, +* 28359 Bremen, Germany or: +* +* http://www.mevis.de +* +*/ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtStdDecorators.cpp +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2007-04 +*/ +//---------------------------------------------------------------------------------- + +#include "PythonQtStdDecorators.h" +#include "PythonQt.h" +#include "PythonQtClassInfo.h" + + +bool PythonQtStdDecorators::connect(QObject* sender, const QByteArray& signal, PyObject* callable) +{ + QByteArray signalTmp("2"); + signalTmp += signal; + if (sender) { + return PythonQt::self()->addSignalHandler(sender, signalTmp, callable); + } else { + return false; + } +} + +bool PythonQtStdDecorators::connect(QObject* sender, const QByteArray& signal, QObject* receiver, const QByteArray& slot) +{ + bool r = false; + if (sender && receiver) { + QByteArray signalTmp("2"); + signalTmp += signal; + QByteArray slotTmp("1"); + slotTmp += slot; + if (receiver) { + r = QObject::connect(sender, signalTmp, receiver, slotTmp); + } + } + return r; +} + +bool PythonQtStdDecorators::disconnect(QObject* sender, const QByteArray& signal, PyObject* callable) +{ + QByteArray signalTmp("2"); + signalTmp += signal; + if (sender) { + return PythonQt::self()->removeSignalHandler(sender, signalTmp, callable); + } else { + return false; + } +} + +bool PythonQtStdDecorators::disconnect(QObject* sender, const QByteArray& signal, QObject* receiver, const QByteArray& slot) +{ + bool r = false; + if (sender && receiver) { + QByteArray signalTmp("2"); + signalTmp += signal; + QByteArray slotTmp("1"); + slotTmp += slot; + if (receiver) { + r = QObject::disconnect(sender, signalTmp, receiver, slotTmp); + } + } + return r; +} + +QObject* PythonQtStdDecorators::parent(QObject* o) { + return o->parent(); +} + +void PythonQtStdDecorators::setParent(QObject* o, QObject* parent) +{ + o->setParent(parent); +} + +QVariantList PythonQtStdDecorators::children(QObject* o) +{ + QVariantList v; + QListIterator it(o->children()); + while (it.hasNext()) { + v << qVariantFromValue(it.next()); + } + return v; +} diff --git a/src/PythonQtStdDecorators.h b/src/PythonQtStdDecorators.h new file mode 100644 index 0000000..983d81e --- /dev/null +++ b/src/PythonQtStdDecorators.h @@ -0,0 +1,87 @@ +#ifndef _PYTHONQTSTDDECORATORS_H +#define _PYTHONQTSTDDECORATORS_H + +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtStdDecorators.h +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2007-04 +*/ +//---------------------------------------------------------------------------------- + +#include "PythonQtSystem.h" +#include +#include +#include +#include +#include +#include +#include +#include + +class PYTHONQT_EXPORT PythonQtStdDecorators : public QObject +{ + Q_OBJECT + +public slots: + // additional constructors + QVariant new_QSize(const QSize& o) { QSize a = o; return a; } + QVariant new_QSizeF(const QSizeF& o) { QSizeF a = o; return a; } + QVariant new_QPoint(const QPoint& o) { QPoint a = o; return a; } + QVariant new_QPointF(const QPointF& o) { QPointF a = o; return a; } + QVariant new_QRect(const QRect& o) { QRect a = o; return a; } + QVariant new_QRectF(const QRectF& o) { QRectF a = o; return a; } + QVariant new_QDate(const QDate& o) { QDate a = o; return a; } + QVariant new_QDateTime(const QDateTime& o) { QDateTime a = o; return a; } + QVariant new_QTime(const QTime& o) { QTime a = o; return a; } + + bool connect(QObject* sender, const QByteArray& signal, PyObject* callable); + bool connect(QObject* sender, const QByteArray& signal, QObject* receiver, const QByteArray& slot); + bool disconnect(QObject* sender, const QByteArray& signal, PyObject* callable); + bool disconnect(QObject* sender, const QByteArray& signal, QObject* receiver, const QByteArray& slot); + + QObject* parent(QObject* o); + void setParent(QObject* o, QObject* parent); + + QVariantList children(QObject* o); + + QString static_Qt_escape(const QString& s) { return Qt::escape(s); } + + //TODO: add findChild/findChildren/children/... +}; + + +#endif diff --git a/src/PythonQtStdOut.cpp b/src/PythonQtStdOut.cpp new file mode 100644 index 0000000..091f3b6 --- /dev/null +++ b/src/PythonQtStdOut.cpp @@ -0,0 +1,128 @@ +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtStdOut.cpp +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-05 +*/ +//---------------------------------------------------------------------------------- + +#include "PythonQtStdOut.h" + +static PyObject *PythonQtStdOutRedirect_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + PythonQtStdOutRedirect *self; + self = (PythonQtStdOutRedirect *)type->tp_alloc(type, 0); + + self->softspace = 0; + self->_cb = NULL; + + return (PyObject *)self; +} + +static PyObject *PythonQtStdOutRedirect_write(PyObject *self, PyObject *args) +{ + PythonQtStdOutRedirect* s = (PythonQtStdOutRedirect*)self; + if (s->_cb) { + char *string; + if (!PyArg_ParseTuple(args, "s", &string)) + return NULL; + + if (s->softspace > 0) { + (*s->_cb)(QString("")); + s->softspace = 0; + } + + (*s->_cb)(QString(string)); + } + return Py_BuildValue(""); +} + + +static PyMethodDef PythonQtStdOutRedirect_methods[] = { + {"write", (PyCFunction)PythonQtStdOutRedirect_write, METH_VARARGS, + "redirect the writing to a callback" + }, + {NULL} /* Sentinel */ +}; + +static PyMemberDef PythonQtStdOutRedirect_members[] = { + {"softspace", T_INT, offsetof(PythonQtStdOutRedirect, softspace), 0, + "soft space flag" + }, + {NULL} /* Sentinel */ +}; + +PyTypeObject PythonQtStdOutRedirectType = { + PyObject_HEAD_INIT(NULL) + 0, /*ob_size*/ + "PythonQtStdOutRedirect", /*tp_name*/ + sizeof(PythonQtStdOutRedirect), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + 0, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + 0, /*tp_compare*/ + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash */ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ + "PythonQtStdOutRedirect", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + PythonQtStdOutRedirect_methods, /* tp_methods */ + PythonQtStdOutRedirect_members, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + PythonQtStdOutRedirect_new, /* tp_new */ +}; diff --git a/src/PythonQtStdOut.h b/src/PythonQtStdOut.h new file mode 100644 index 0000000..c247f32 --- /dev/null +++ b/src/PythonQtStdOut.h @@ -0,0 +1,64 @@ +#ifndef _PYTHONQTSTDOUT_H +#define _PYTHONQTSTDOUT_H + +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtStdOut.h +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-05 +*/ +//---------------------------------------------------------------------------------- + + + +#include +#include "structmember.h" +#include + +//! declares the type of the stdout redirection class +extern PyTypeObject PythonQtStdOutRedirectType; + +//! declares the callback that is called from the write() function +typedef void PythonQtOutputChangedCB(const QString& str); + +//! declares the stdout redirection class +typedef struct { + PyObject_HEAD + PythonQtOutputChangedCB* _cb; + int softspace; +} PythonQtStdOutRedirect; + +#endif diff --git a/src/PythonQtSystem.h b/src/PythonQtSystem.h new file mode 100644 index 0000000..52981ae --- /dev/null +++ b/src/PythonQtSystem.h @@ -0,0 +1,56 @@ +#ifndef _PYTHONQTSYSTEM_ +#define _PYTHONQTSYSTEM_ + +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtSystem.h +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-05 +*/ +//---------------------------------------------------------------------------------- + +#ifdef WIN32 +#ifdef PYTHONQT_EXPORTS +#define PYTHONQT_EXPORT __declspec(dllexport) +#else +#define PYTHONQT_EXPORT __declspec(dllimport) +#endif +#else +#define PYTHONQT_EXPORT +#endif + +#endif + diff --git a/src/PythonQtVariantWrapper.cpp b/src/PythonQtVariantWrapper.cpp new file mode 100644 index 0000000..1ee838b --- /dev/null +++ b/src/PythonQtVariantWrapper.cpp @@ -0,0 +1,256 @@ +/* +* +* Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* Further, this software is distributed without any warranty that it is +* free of the rightful claim of any third person regarding infringement +* or the like. Any license provided herein, whether implied or +* otherwise, applies only to this software file. Patent licenses, if +* any, provided herein do not apply to combinations of this program with +* other software, or any other product whatsoever. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Contact information: MeVis Research GmbH, Universitaetsallee 29, +* 28359 Bremen, Germany or: +* +* http://www.mevis.de +* +*/ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtVariantWrapper.cpp +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-05 +*/ +//---------------------------------------------------------------------------------- + +#include "PythonQtVariantWrapper.h" +#include +#include +#include +#include +#include "PythonQt.h" +#include "PythonQtSlot.h" +#include "PythonQtClassInfo.h" +#include "PythonQtConversion.h" + +static void PythonQtVariantWrapper_dealloc(PythonQtVariantWrapper* self) +{ + if (self->_variant) { + delete self->_variant; + self->_variant = NULL; + } + self->ob_type->tp_free((PyObject*)self); +} + +static PyObject* PythonQtVariantWrapper_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + PythonQtVariantWrapper *self; + + self = (PythonQtVariantWrapper *)type->tp_alloc(type, 0); + if (self != NULL) { + self->_variant = new QVariant(); + self->_info = NULL; + } + return (PyObject *)self; +} + +static int PythonQtVariantWrapper_init(PythonQtVariantWrapper *self, PyObject *args, PyObject *kwds) +{ + return 0; +} + +static PyObject *PythonQtVariantWrapper_classname(PythonQtVariantWrapper* type) +{ + return PyString_FromString(type->_info->className()); +} + +static PyObject *PythonQtVariantWrapper_help(PythonQtVariantWrapper* type) +{ + return PythonQt::self()->helpCalled(type->_info); +} + + +static PyMethodDef PythonQtVariantWrapper_methods[] = { + {"className", (PyCFunction)PythonQtVariantWrapper_classname, METH_NOARGS, + "Return the classname of the object" + }, + {"help", (PyCFunction)PythonQtVariantWrapper_help, METH_NOARGS, + "Shows the help of available methods for this class" + }, + {NULL} /* Sentinel */ +}; + + +static PyObject *PythonQtVariantWrapper_getattro(PyObject *obj,PyObject *name) +{ + const char *attributeName; + PythonQtVariantWrapper *wt = (PythonQtVariantWrapper *)obj; + + if ((attributeName = PyString_AsString(name)) == NULL) { + return NULL; + } + + if (wt->_wrapper && wt->_info) { + PythonQtMemberInfo member = wt->_info->member(attributeName); + if (member._type == PythonQtMemberInfo::Slot) { + return PythonQtSlotFunction_New(member._slot, obj, NULL); + } else if (member._type == PythonQtMemberInfo::EnumValue) { + return PyInt_FromLong(member._enumValue); + } + } + + // look for the interal methods (className(), help()) + PyObject* internalMethod = Py_FindMethod( PythonQtVariantWrapper_methods, obj, (char*)attributeName); + if (internalMethod) { + return internalMethod; + } + PyErr_Clear(); + + if (qstrcmp(attributeName, "__dict__")==0) { + QStringList l = wt->_info->memberList(false); + PyObject* dict = PyDict_New(); + foreach (QString name, l) { + //PyObject* o = PyObject_GetAttrString(obj, name.toLatin1().data()); + PyDict_SetItemString(dict, name.toLatin1().data(), Py_None); + //Py_DECREF(o); + } + return dict; + } + + QString error = QString(wt->_variant->typeName()) + " has no attribute named '" + QString(attributeName) + "'"; + PyErr_SetString(PyExc_AttributeError, error.toLatin1().data()); + + return NULL; +} + +QString qVariantToString(const QVariant& v) { + QString r; + switch (v.type()) { + case QVariant::Size: + r = QString::number(v.toSize().width()) + ", " + QString::number(v.toSize().height()); + break; + case QVariant::SizeF: + r = QString::number(v.toSizeF().width()) + ", " + QString::number(v.toSizeF().height()); + break; + case QVariant::Point: + r = QString::number(v.toPoint().x()) + ", " + QString::number(v.toPoint().y()); + break; + case QVariant::PointF: + r = QString::number(v.toPointF().x()) + ", " + QString::number(v.toPointF().y()); + break; + case QVariant::Rect: + r = QString::number(v.toRect().x()) + ", " + QString::number(v.toRect().y()); + r += ", " + QString::number(v.toRect().width()) + ", " + QString::number(v.toRect().height()); + break; + case QVariant::RectF: + r = QString::number(v.toRectF().x()) + ", " + QString::number(v.toRectF().y()); + r += ", " + QString::number(v.toRectF().width()) + ", " + QString::number(v.toRectF().height()); + break; + case QVariant::Date: + r = v.toDate().toString(Qt::ISODate); + break; + case QVariant::DateTime: + r = v.toDateTime().toString(Qt::ISODate); + break; + case QVariant::Time: + r = v.toTime().toString(Qt::ISODate); + break; + //TODO: add more printing for other variant types + default: + r = v.toString(); + } + return r; +} + +static PyObject * PythonQtVariantWrapper_str(PyObject * obj) +{ + PythonQtVariantWrapper* wt = (PythonQtVariantWrapper*)obj; + QString val = qVariantToString(*wt->_variant); + return PyString_FromFormat("%s", val.toLatin1().constData()); +} + +static PyObject * PythonQtVariantWrapper_repr(PyObject * obj) +{ + PythonQtVariantWrapper* wt = (PythonQtVariantWrapper*)obj; + QString val = qVariantToString(*wt->_variant); + return PyString_FromFormat("%s(%s)", wt->_variant->typeName(), val.toLatin1().constData()); +} + +static int PythonQtVariantWrapper_compare(PyObject * obj1, PyObject * obj2) +{ + if (obj1->ob_type == &PythonQtVariantWrapper_Type && + obj2->ob_type == &PythonQtVariantWrapper_Type) { + + PythonQtVariantWrapper* w1 = (PythonQtVariantWrapper*)obj1; + PythonQtVariantWrapper* w2 = (PythonQtVariantWrapper*)obj2; + if (*w1->_variant == *w2->_variant) { + return 0; + } else { + return -1; + } + } else { + return -1; + } +} + + +PyTypeObject PythonQtVariantWrapper_Type = { + PyObject_HEAD_INIT(NULL) + 0, /*ob_size*/ + "PythonQt.PythonQtVariantWrapper", /*tp_name*/ + sizeof(PythonQtVariantWrapper), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + (destructor)PythonQtVariantWrapper_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + PythonQtVariantWrapper_compare, /*tp_compare*/ + PythonQtVariantWrapper_repr, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash */ + 0, /*tp_call*/ + PythonQtVariantWrapper_str, /*tp_str*/ + PythonQtVariantWrapper_getattro, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ + "PythonQtVariantWrapper object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)PythonQtVariantWrapper_init, /* tp_init */ + 0, /* tp_alloc */ + PythonQtVariantWrapper_new, /* tp_new */ +}; + +//------------------------------------------------------- + diff --git a/src/PythonQtVariantWrapper.h b/src/PythonQtVariantWrapper.h new file mode 100644 index 0000000..dd6a196 --- /dev/null +++ b/src/PythonQtVariantWrapper.h @@ -0,0 +1,72 @@ +#ifndef _PYTHONQTVARIANTWRAPPER_H +#define _PYTHONQTVARIANTWRAPPER_H + +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtVariantWrapper.h +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-05 +*/ +//---------------------------------------------------------------------------------- + +#include + +#include "structmember.h" +#include "methodobject.h" +#include "compile.h" +#include "eval.h" + +#include + +extern PyTypeObject PythonQtVariantWrapper_Type; + +class PythonQtClassInfo; + +//--------------------------------------------------------------- +//! a Python wrapper object for Qt variants +typedef struct { + PyObject_HEAD + + QVariant* _variant; + + PythonQtClassInfo* _info; + + QObject* _wrapper; + +} PythonQtVariantWrapper; + + +#endif diff --git a/src/PythonQtVariants.cpp b/src/PythonQtVariants.cpp new file mode 100644 index 0000000..1062530 --- /dev/null +++ b/src/PythonQtVariants.cpp @@ -0,0 +1,44 @@ +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtVariants.cpp +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-08 +*/ +//---------------------------------------------------------------------------------- + +#include "PythonQtVariants.h" + + diff --git a/src/PythonQtVariants.h b/src/PythonQtVariants.h new file mode 100644 index 0000000..596a7f2 --- /dev/null +++ b/src/PythonQtVariants.h @@ -0,0 +1,52 @@ +#ifndef _PYTHONQTVARIANTS_ +#define _PYTHONQTVARIANTS_ + +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtVariants.h +// \author Florian Link +// \author Last changed by $Author: stk $ +// \date 2006-08 +*/ +//---------------------------------------------------------------------------------- + +#include "Python.h" +#include "structmember.h" + + +#include "wrapper/PythonQtWrappedVariants.h" + +#endif + diff --git a/src/PythonQtWrapper.cpp b/src/PythonQtWrapper.cpp new file mode 100644 index 0000000..b6780ef --- /dev/null +++ b/src/PythonQtWrapper.cpp @@ -0,0 +1,376 @@ +/* +* +* Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* Further, this software is distributed without any warranty that it is +* free of the rightful claim of any third person regarding infringement +* or the like. Any license provided herein, whether implied or +* otherwise, applies only to this software file. Patent licenses, if +* any, provided herein do not apply to combinations of this program with +* other software, or any other product whatsoever. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Contact information: MeVis Research GmbH, Universitaetsallee 29, +* 28359 Bremen, Germany or: +* +* http://www.mevis.de +* +*/ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtWrapper.cpp +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-05 +*/ +//---------------------------------------------------------------------------------- + +#include "PythonQtWrapper.h" +#include +#include "PythonQt.h" +#include "PythonQtSlot.h" +#include "PythonQtClassInfo.h" +#include "PythonQtConversion.h" + +static void PythonQtWrapper_dealloc(PythonQtWrapper* self) +{ + if (self->_wrappedPtr) { + + //mlabDebugConst("Python","c++ wrapper removed " << self->_wrappedPtr << " " << self->_obj->className() << " " << self->_info->wrappedClassName().latin1()); + + PythonQt::priv()->removeWrapperPointer(self->_wrappedPtr); + // we own our qobject, so we delete it now: + delete self->_obj; + self->_obj = NULL; + if (self->_ownedByPythonQt) { + PythonQtSlotInfo* slot = PythonQt::priv()->getDestructorSlot(self->_info->wrappedCPPClassName()); + if (slot) { + void* args[2]; + args[0] = NULL; + args[1] = &self->_wrappedPtr; + slot->decorator()->qt_metacall(QMetaObject::InvokeMetaMethod, slot->slotIndex(), args); + self->_wrappedPtr = NULL; + } else { + // TODO: print a warning? we can not destroy that object + } + } + } else if (self->_obj) { + //mlabDebugConst("Python","qobject wrapper removed " << self->_obj->className() << " " << self->_info->wrappedClassName().latin1()); + PythonQt::priv()->removeWrapperPointer(self->_obj); + if (self->_ownedByPythonQt) { + if (!self->_obj->parent()) { + delete self->_obj; + self->_obj = NULL; + } + } + } + self->ob_type->tp_free((PyObject*)self); +} + +static PyObject* PythonQtWrapper_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + PythonQtWrapper *self; + + self = (PythonQtWrapper *)type->tp_alloc(type, 0); + if (self != NULL) { + self->_info = NULL; + self->_obj = NULL; + self->_wrappedPtr = NULL; + self->_ownedByPythonQt = false; + } + return (PyObject *)self; +} + +static int PythonQtWrapper_init(PythonQtWrapper *self, PyObject *args, PyObject *kwds) +{ + return 0; +} + +static PyObject *PythonQtWrapper_classname(PythonQtWrapper* type) +{ + return PyString_FromString(type->_info->className()); +} + +static PyObject *PythonQtWrapper_help(PythonQtWrapper* type) +{ + return PythonQt::self()->helpCalled(type->_info); +} + + +static PyMethodDef PythonQtWrapper_methods[] = { + {"className", (PyCFunction)PythonQtWrapper_classname, METH_NOARGS, + "Return the classname of the object" + }, + {"help", (PyCFunction)PythonQtWrapper_help, METH_NOARGS, + "Shows the help of available methods for this class" + }, + {NULL} /* Sentinel */ +}; + + +static PyObject *PythonQtWrapper_getattro(PyObject *obj,PyObject *name) +{ + const char *attributeName; + PythonQtWrapper *wt = (PythonQtWrapper *)obj; + + if ((attributeName = PyString_AsString(name)) == NULL) { + return NULL; + } + + if (!wt->_obj && !wt->_wrappedPtr) { + QString error = QString("Trying to read attribute '") + attributeName + "' from a destroyed " + wt->_info->className() + " object"; + PyErr_SetString(PyExc_ValueError, error.toLatin1().data()); + return NULL; + } + + // mlabDebugConst("Python","get " << attributeName); + + // TODO: dynamic properties are missing + + PythonQtMemberInfo member = wt->_info->member(attributeName); + switch (member._type) { + case PythonQtMemberInfo::Property: + if (wt->_obj) { + return PythonQtConv::QVariantToPyObject(member._property.read(wt->_obj)); + } + break; + case PythonQtMemberInfo::Slot: + return PythonQtSlotFunction_New(member._slot, obj, NULL); + break; + case PythonQtMemberInfo::EnumValue: + return PyInt_FromLong(member._enumValue); + break; + } + + // look for the interal methods (className(), help()) + PyObject* internalMethod = Py_FindMethod( PythonQtWrapper_methods, obj, (char*)attributeName); + if (internalMethod) { + return internalMethod; + } + PyErr_Clear(); + + if (wt->_obj) { + // look for a child + QObjectList children = wt->_obj->children(); + for (int i = 0; i < children.count(); i++) { + QObject *child = children.at(i); + if (child->objectName() == attributeName) { + return PythonQt::self()->priv()->wrapQObject(child); + } + } + } + + if (qstrcmp(attributeName, "__dict__")==0) { + QStringList l = wt->_info->memberList(false); + PyObject* dict = PyDict_New(); + foreach (QString name, l) { + //PyObject* o = PyObject_GetAttrString(obj, name.toLatin1().data()); + PyDict_SetItemString(dict, name.toLatin1().data(), Py_None); + //Py_DECREF(o); + } + // Note: we do not put children into the dict, is would look confusing?! + return dict; + } + + + QString error = QString(wt->_info->className()) + " has no attribute named '" + QString(attributeName) + "'"; + PyErr_SetString(PyExc_AttributeError, error.toLatin1().data()); + return NULL; +} + +static int PythonQtWrapper_setattro(PyObject *obj,PyObject *name,PyObject *value) +{ + QString error; + char *attributeName; + PythonQtWrapper *wt = (PythonQtWrapper *)obj; + + if ((attributeName = PyString_AsString(name)) == NULL) + return -1; + + if (!wt->_obj) { + error = QString("Trying to set attribute '") + attributeName + "' on a destroyed " + wt->_info->className() + " object"; + PyErr_SetString(PyExc_AttributeError, error.toLatin1().data()); + return -1; + } + + PythonQtMemberInfo member = wt->_info->member(attributeName); + if (member._type == PythonQtMemberInfo::Property) { + QMetaProperty prop = member._property; + if (prop.isWritable()) { + QVariant v; + if (prop.isEnumType()) { + // this will give us either a string or an int, everything else will probably be an error + v = PythonQtConv::PyObjToQVariant(value); + } else { + int t = prop.userType(); + v = PythonQtConv::PyObjToQVariant(value, t); + } + bool success = false; + if (v.isValid()) { + success = prop.write(wt->_obj, v); + } + if (success) { + return 0; + } else { + error = QString("Property '") + attributeName + "' of type '" + + prop.typeName() + "' does not accept an object of type " + + QString(value->ob_type->tp_name) + " (" + PythonQtConv::PyObjGetRepresentation(value) + ")"; + } + } else { + error = QString("Property '") + attributeName + "' of " + wt->_info->className() + " object is not writable"; + } + } else { + if (member._type == PythonQtMemberInfo::Slot) { + error = QString("Slot '") + attributeName + "' can not be overwritten on " + wt->_info->className() + " object"; + } else if (member._type == PythonQtMemberInfo::EnumValue) { + error = QString("EnumValue '") + attributeName + "' can not be overwritten on " + wt->_info->className() + " object"; + } + } + + PyErr_SetString(PyExc_AttributeError, error.toLatin1().data()); + return -1; +} + +static PyObject * PythonQtWrapper_repr(PyObject * obj) +{ + PythonQtWrapper* wt = (PythonQtWrapper*)obj; + if (wt->_wrappedPtr) { + if (wt->_obj) { + return PyString_FromFormat("%s (C++ Object 0x%x wrapped by %s 0x%x))", wt->_info->className(), wt->_wrappedPtr, wt->_obj->metaObject()->className(), wt->_obj); + } else { + return PyString_FromFormat("%s (C++ Object 0x%x unwrapped)", wt->_info->className(), wt->_wrappedPtr); + } + } else { + return PyString_FromFormat("%s (QObject 0x%x)", wt->_info->className(), wt->_obj, wt->_wrappedPtr); + } +} + +static int PythonQtWrapper_compare(PyObject * obj1, PyObject * obj2) +{ + if (obj1->ob_type == &PythonQtWrapper_Type && + obj2->ob_type == &PythonQtWrapper_Type) { + + PythonQtWrapper* w1 = (PythonQtWrapper*)obj1; + PythonQtWrapper* w2 = (PythonQtWrapper*)obj2; + if (w1->_wrappedPtr != NULL) { + if (w1->_wrappedPtr == w1->_wrappedPtr) { + return 0; + } else { + return -1; + } + } else if (w1->_obj == w2->_obj) { + return 0; + } else { + return -1; + } + } else { + return -1; + } +} + +static int PythonQtWrapper_nonzero(PyObject *obj) +{ + PythonQtWrapper* wt = (PythonQtWrapper*)obj; + return (wt->_wrappedPtr == NULL && wt->_obj == NULL)?0:1; +} + +// we override nb_nonzero, so that one can do 'if' expressions to test for a NULL ptr +static PyNumberMethods PythonQtWrapper_as_number = { + 0, /* nb_add */ + 0, /* nb_subtract */ + 0, /* nb_multiply */ + 0, /* nb_divide */ + 0, /* nb_remainder */ + 0, /* nb_divmod */ + 0, /* nb_power */ + 0, /* nb_negative */ + 0, /* nb_positive */ + 0, /* nb_absolute */ + PythonQtWrapper_nonzero, /* nb_nonzero */ + 0, /* nb_invert */ + 0, /* nb_lshift */ + 0, /* nb_rshift */ + 0, /* nb_and */ + 0, /* nb_xor */ + 0, /* nb_or */ + 0, /* nb_coerce */ + 0, /* nb_int */ + 0, /* nb_long */ + 0, /* nb_float */ + 0, /* nb_oct */ + 0, /* nb_hex */ + 0, /* nb_inplace_add */ + 0, /* nb_inplace_subtract */ + 0, /* nb_inplace_multiply */ + 0, /* nb_inplace_divide */ + 0, /* nb_inplace_remainder */ + 0, /* nb_inplace_power */ + 0, /* nb_inplace_lshift */ + 0, /* nb_inplace_rshift */ + 0, /* nb_inplace_and */ + 0, /* nb_inplace_xor */ + 0, /* nb_inplace_or */ + 0, /* nb_floor_divide */ + 0, /* nb_true_divide */ + 0, /* nb_inplace_floor_divide */ + 0, /* nb_inplace_true_divide */ +}; + +PyTypeObject PythonQtWrapper_Type = { + PyObject_HEAD_INIT(NULL) + 0, /*ob_size*/ + "PythonQt.PythonQtWrapper", /*tp_name*/ + sizeof(PythonQtWrapper), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + (destructor)PythonQtWrapper_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + PythonQtWrapper_compare, /*tp_compare*/ + PythonQtWrapper_repr, /*tp_repr*/ + &PythonQtWrapper_as_number, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash */ + 0, /*tp_call*/ + 0, /*tp_str*/ + PythonQtWrapper_getattro, /*tp_getattro*/ + PythonQtWrapper_setattro, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ + "PythonQtWrapper object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)PythonQtWrapper_init, /* tp_init */ + 0, /* tp_alloc */ + PythonQtWrapper_new, /* tp_new */ +}; + +//------------------------------------------------------- + diff --git a/src/PythonQtWrapper.h b/src/PythonQtWrapper.h new file mode 100644 index 0000000..493c4cd --- /dev/null +++ b/src/PythonQtWrapper.h @@ -0,0 +1,78 @@ +#ifndef _PYTHONQTWRAPPER_H +#define _PYTHONQTWRAPPER_H + +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtWrapper.h +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-05 +*/ +//---------------------------------------------------------------------------------- + +#include + +#include "PythonQtSystem.h" + +#include "structmember.h" +#include "methodobject.h" +#include "compile.h" +#include "eval.h" + +class PythonQtClassInfo; +class QObject; + +extern PYTHONQT_EXPORT PyTypeObject PythonQtWrapper_Type; + +//--------------------------------------------------------------- +//! a Python wrapper object for Qt objects and C++ objects (that are themselves wrapped by wrapper QObjects) +typedef struct { + PyObject_HEAD + + //! pointer to the wrapped Qt object or if _wrappedPtr is set, the Qt object that wraps the C++ Ptr + QObject* _obj; + //! optional C++ object Ptr that is wrapped by the above _obj + void* _wrappedPtr; + + //! the class information, this is set even if the _obj or _wrappedPtr is NULL to support typed NULL pointers + PythonQtClassInfo* _info; + + //! flag that stores if the object is owned by pythonQt + bool _ownedByPythonQt; + +} PythonQtWrapper; + + +#endif \ No newline at end of file diff --git a/src/gui/PythonQtScriptingConsole.cpp b/src/gui/PythonQtScriptingConsole.cpp new file mode 100644 index 0000000..2784a1c --- /dev/null +++ b/src/gui/PythonQtScriptingConsole.cpp @@ -0,0 +1,564 @@ +/* +* +* Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* Further, this software is distributed without any warranty that it is +* free of the rightful claim of any third person regarding infringement +* or the like. Any license provided herein, whether implied or +* otherwise, applies only to this software file. Patent licenses, if +* any, provided herein do not apply to combinations of this program with +* other software, or any other product whatsoever. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Contact information: MeVis Research GmbH, Universitaetsallee 29, +* 28359 Bremen, Germany or: +* +* http://www.mevis.de +* +*/ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtScriptingConsole.cpp +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-10 +*/ +//---------------------------------------------------------------------------------- + +#include "PythonQtScriptingConsole.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//----------------------------------------------------------------------------- + +PythonQtScriptingConsole::PythonQtScriptingConsole(QWidget* parent, const PythonQtObjectPtr& context, Qt::WindowFlags windowFlags) +: QTextEdit(parent) { + + setWindowFlags(windowFlags); + + _defaultTextCharacterFormat = currentCharFormat(); + _context = context; + _historyPosition = 0; + + _completer = new QCompleter(this); + _completer->setWidget(this); + QObject::connect(_completer, SIGNAL(activated(const QString&)), + this, SLOT(insertCompletion(const QString&))); + + clear(); + + connect(PythonQt::self(), SIGNAL(pythonStdOut(const QString&)), this, SLOT(stdOut(const QString&))); + connect(PythonQt::self(), SIGNAL(pythonStdErr(const QString&)), this, SLOT(stdErr(const QString&))); +} + +//----------------------------------------------------------------------------- + +void PythonQtScriptingConsole::stdOut(const QString& s) +{ + _stdOut += s; + int idx; + while ((idx = _stdOut.indexOf('\n'))!=-1) { + consoleMessage(_stdOut.left(idx)); + std::cout << _stdOut.left(idx).toLatin1().data() << std::endl; + _stdOut = _stdOut.mid(idx+1); + } +} + +void PythonQtScriptingConsole::stdErr(const QString& s) +{ + _stdErr += s; + int idx; + while ((idx = _stdErr.indexOf('\n'))!=-1) { + consoleMessage(_stdErr.left(idx)); + std::cout << _stdErr.left(idx).toLatin1().data() << std::endl; + _stdErr = _stdErr.mid(idx+1); + } +} + +void PythonQtScriptingConsole::flushStdOut() +{ + if (!_stdOut.isEmpty()) { + stdOut("\n"); + } + if (!_stdErr.isEmpty()) { + stdErr("\n"); + } +} + +//----------------------------------------------------------------------------- + +PythonQtScriptingConsole::~PythonQtScriptingConsole() { +} + + + +//----------------------------------------------------------------------------- + +void PythonQtScriptingConsole::clear() { + + QTextEdit::clear(); + appendCommandPrompt(); +} + +//----------------------------------------------------------------------------- + +void PythonQtScriptingConsole::executeLine(bool storeOnly) +{ + QTextCursor textCursor = this->textCursor(); + textCursor.movePosition(QTextCursor::End); + + // Select the text from the command prompt until the end of the block + // and get the selected text. + textCursor.setPosition(commandPromptPosition()); + textCursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor); + QString code = textCursor.selectedText(); + + // i don't know where this trailing space is coming from, blast it! + if (code.endsWith(" ")) { + code.truncate(code.length()-1); + } + + if (!code.isEmpty()) { + // Update the history + _history << code; + _historyPosition = _history.count(); + _currentMultiLineCode += code + "\n"; + + if (!storeOnly) { + executeCode(_currentMultiLineCode); + _currentMultiLineCode = ""; + } + } + // Insert a new command prompt + appendCommandPrompt(storeOnly); + +} + +void PythonQtScriptingConsole::executeCode(const QString& code) +{ + // put visible cursor to the end of the line + QTextCursor cursor = QTextEdit::textCursor(); + cursor.movePosition(QTextCursor::End); + setTextCursor(cursor); + + int cursorPosition = this->textCursor().position(); + + // evaluate the code + _stdOut = ""; + _stdErr = ""; + PythonQtObjectPtr p; + p.setNewRef(PyRun_String(code.toLatin1().data(), Py_single_input, PyModule_GetDict(_context), PyModule_GetDict(_context))); + if (!p) { + PythonQt::self()->handleError(); + } + + flushStdOut(); + + bool messageInserted = (this->textCursor().position() != cursorPosition); + + // If a message was inserted, then put another empty line before the command prompt + // to improve readability. + if (messageInserted) { + append(QString()); + } +} + + +//----------------------------------------------------------------------------- + +void PythonQtScriptingConsole::appendCommandPrompt(bool storeOnly) { + if (storeOnly) { + _commandPrompt = "...> "; + } else { + _commandPrompt = "py> "; + } + append(_commandPrompt); + + QTextCursor cursor = textCursor(); + cursor.movePosition(QTextCursor::End); + setTextCursor(cursor); +} + + + +//----------------------------------------------------------------------------- + +void PythonQtScriptingConsole::setCurrentFont(const QColor& color, bool bold) { + + QTextCharFormat charFormat(_defaultTextCharacterFormat); + + QFont font(charFormat.font()); + font.setBold(bold); + charFormat.setFont(font); + + QBrush brush(charFormat.foreground()); + brush.setColor(color); + charFormat.setForeground(brush); + + setCurrentCharFormat(charFormat); +} + + + +//----------------------------------------------------------------------------- + +int PythonQtScriptingConsole::commandPromptPosition() { + + QTextCursor textCursor(this->textCursor()); + textCursor.movePosition(QTextCursor::End); + + return textCursor.block().position() + _commandPrompt.length(); +} + + + +//----------------------------------------------------------------------------- + +void PythonQtScriptingConsole::insertCompletion(const QString& completion) +{ + QTextCursor tc = textCursor(); + tc.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor); + if (tc.selectedText()==".") { + tc.insertText(QString(".") + completion); + } else { + tc = textCursor(); + tc.movePosition(QTextCursor::StartOfWord, QTextCursor::MoveAnchor); + tc.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor); + tc.insertText(completion); + setTextCursor(tc); + } +} + +//----------------------------------------------------------------------------- +void PythonQtScriptingConsole::handleTabCompletion() +{ + QTextCursor textCursor = this->textCursor(); + int pos = textCursor.position(); + textCursor.setPosition(commandPromptPosition()); + textCursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor); + int startPos = textCursor.selectionStart(); + + int offset = pos-startPos; + QString text = textCursor.selectedText(); + + QString textToComplete; + int cur = offset; + while (cur--) { + QChar c = text.at(cur); + if (c.isLetterOrNumber() || c == '.' || c == '_') { + textToComplete.prepend(c); + } else { + break; + } + } + + + QString lookup; + QString compareText = textToComplete; + int dot = compareText.lastIndexOf('.'); + if (dot!=-1) { + lookup = compareText.mid(0, dot); + compareText = compareText.mid(dot+1, offset); + } + if (!lookup.isEmpty() || !compareText.isEmpty()) { + compareText = compareText.toLower(); + QStringList found; + QStringList l = PythonQt::self()->introspection(_context, lookup, PythonQt::Anything); + foreach (QString n, l) { + if (n.toLower().startsWith(compareText)) { + found << n; + } + } + + if (!found.isEmpty()) { + _completer->setCompletionPrefix(compareText); + _completer->setCompletionMode(QCompleter::PopupCompletion); + _completer->setModel(new QStringListModel(found, _completer)); + _completer->setCaseSensitivity(Qt::CaseInsensitive); + QTextCursor c = this->textCursor(); + c.movePosition(QTextCursor::StartOfWord); + QRect cr = cursorRect(c); + cr.setWidth(_completer->popup()->sizeHintForColumn(0) + + _completer->popup()->verticalScrollBar()->sizeHint().width()); + cr.translate(0,8); + _completer->complete(cr); + } else { + _completer->popup()->hide(); + } + } else { + _completer->popup()->hide(); + } +} + +void PythonQtScriptingConsole::keyPressEvent(QKeyEvent* event) { + + if (_completer && _completer->popup()->isVisible()) { + // The following keys are forwarded by the completer to the widget + switch (event->key()) { + case Qt::Key_Return: + if (!_completer->popup()->currentIndex().isValid()) { + insertCompletion(_completer->currentCompletion()); + _completer->popup()->hide(); + event->accept(); + } + event->ignore(); + return; + break; + case Qt::Key_Enter: + case Qt::Key_Escape: + case Qt::Key_Tab: + case Qt::Key_Backtab: + + event->ignore(); + return; // let the completer do default behavior + default: + break; + } + } + bool eventHandled = false; + QTextCursor textCursor = this->textCursor(); + + int key = event->key(); + switch (key) { + + case Qt::Key_Left: + + // Moving the cursor left is limited to the position + // of the command prompt. + + if (textCursor.position() <= commandPromptPosition()) { + + QApplication::beep(); + eventHandled = true; + } + break; + + case Qt::Key_Up: + + // Display the previous command in the history + if (_historyPosition>0) { + _historyPosition--; + changeHistory(); + } + + eventHandled = true; + break; + + case Qt::Key_Down: + + // Display the next command in the history + if (_historyPosition+1<_history.count()) { + _historyPosition++; + changeHistory(); + } + + eventHandled = true; + break; + + case Qt::Key_Return: + + executeLine(event->modifiers() & Qt::ShiftModifier); + eventHandled = true; + break; + + case Qt::Key_Backspace: + + if (textCursor.hasSelection()) { + + cut(); + eventHandled = true; + + } else { + + // Intercept backspace key event to check if + // deleting a character is allowed. It is not + // allowed, if the user wants to delete the + // command prompt. + + if (textCursor.position() <= commandPromptPosition()) { + + QApplication::beep(); + eventHandled = true; + } + } + break; + + case Qt::Key_Delete: + + cut(); + eventHandled = true; + break; + + default: + + if (key >= Qt::Key_Space && key <= Qt::Key_division) { + + if (textCursor.hasSelection() && !verifySelectionBeforeDeletion()) { + + // The selection must not be deleted. + eventHandled = true; + + } else { + + // The key is an input character, check if the cursor is + // behind the last command prompt, else inserting the + // character is not allowed. + + int commandPromptPosition = this->commandPromptPosition(); + if (textCursor.position() < commandPromptPosition) { + + textCursor.setPosition(commandPromptPosition); + setTextCursor(textCursor); + } + } + } + } + + if (eventHandled) { + + _completer->popup()->hide(); + event->accept(); + + } else { + + QTextEdit::keyPressEvent(event); + QString text = event->text(); + if (!text.isEmpty()) { + handleTabCompletion(); + } else { + _completer->popup()->hide(); + } + eventHandled = true; + } +} + + + +//----------------------------------------------------------------------------- + +void PythonQtScriptingConsole::cut() { + + bool deletionAllowed = verifySelectionBeforeDeletion(); + if (deletionAllowed) { + QTextEdit::cut(); + } +} + + + +//----------------------------------------------------------------------------- + +bool PythonQtScriptingConsole::verifySelectionBeforeDeletion() { + + bool deletionAllowed = true; + + + QTextCursor textCursor = this->textCursor(); + + int commandPromptPosition = this->commandPromptPosition(); + int selectionStart = textCursor.selectionStart(); + int selectionEnd = textCursor.selectionEnd(); + + if (textCursor.hasSelection()) { + + // Selected text may only be deleted after the last command prompt. + // If the selection is partly after the command prompt set the selection + // to the part and deletion is allowed. If the selection occurs before the + // last command prompt, then deletion is not allowed. + + if (selectionStart < commandPromptPosition || + selectionEnd < commandPromptPosition) { + + // Assure selectionEnd is bigger than selection start + if (selectionStart > selectionEnd) { + int tmp = selectionEnd; + selectionEnd = selectionStart; + selectionStart = tmp; + } + + if (selectionEnd < commandPromptPosition) { + + // Selection is completely before command prompt, + // so deletion is not allowed. + QApplication::beep(); + deletionAllowed = false; + + } else { + + // The selectionEnd is after the command prompt, so set + // the selection start to the commandPromptPosition. + selectionStart = commandPromptPosition; + textCursor.setPosition(selectionStart); + textCursor.setPosition(selectionStart, QTextCursor::KeepAnchor); + setTextCursor(textCursor); + } + } + + } else { // if (hasSelectedText()) + + // When there is no selected text, deletion is not allowed before the + // command prompt. + if (textCursor.position() < commandPromptPosition) { + + QApplication::beep(); + deletionAllowed = false; + } + } + + return deletionAllowed; +} + + + +//----------------------------------------------------------------------------- + +void PythonQtScriptingConsole::changeHistory() { + + // Select the text after the last command prompt ... + QTextCursor textCursor = this->textCursor(); + textCursor.movePosition(QTextCursor::End); + textCursor.setPosition(commandPromptPosition(), QTextCursor::KeepAnchor); + + // ... and replace it with the history text. + textCursor.insertText(_history.value(_historyPosition)); + + textCursor.movePosition(QTextCursor::End); + setTextCursor(textCursor); +} + + + +//----------------------------------------------------------------------------- + +void PythonQtScriptingConsole::consoleMessage(const QString & message) { + + append(QString()); + insertPlainText(message); + + // Reset all font modifications done by the html string + setCurrentCharFormat(_defaultTextCharacterFormat); +} diff --git a/src/gui/PythonQtScriptingConsole.h b/src/gui/PythonQtScriptingConsole.h new file mode 100644 index 0000000..eec4c72 --- /dev/null +++ b/src/gui/PythonQtScriptingConsole.h @@ -0,0 +1,136 @@ +#ifndef _PythonQtScriptingConsole_H +#define _PythonQtScriptingConsole_H + +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtScriptingConsole.h +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-10 +*/ +//---------------------------------------------------------------------------------- + +#include "PythonQt.h" +#include +#include + +class QCompleter; + +//------------------------------------------------------------------------------- +//! A simple console for python scripting +class PYTHONQT_EXPORT PythonQtScriptingConsole : public QTextEdit +{ + Q_OBJECT + +public: + PythonQtScriptingConsole(QWidget* parent, const PythonQtObjectPtr& context, Qt::WindowFlags i = 0); + + ~PythonQtScriptingConsole(); + +public slots: + //! execute current line + void executeLine(bool storeOnly); + + //! derived key press event + void keyPressEvent (QKeyEvent * e); + + //! output from console + void consoleMessage(const QString & message); + + //! get history + QStringList history() { return _history; } + + //! set history + void setHistory(const QStringList& h) { _history = h; _historyPosition = 0; } + + //! clear the console + void clear(); + + //! overridden to control which characters a user may delete + virtual void cut(); + + //! output redirection + void stdOut(const QString& s); + //! output redirection + void stdErr(const QString& s); + + void insertCompletion(const QString&); + + //! Appends a newline and command prompt at the end of the document. + void appendCommandPrompt(bool storeOnly = false); +protected: + //! handle the pressing of tab + void handleTabCompletion(); + + //! Returns the position of the command prompt + int commandPromptPosition(); + + //! Returns if deletion is allowed at the current cursor + //! (with and without selected text) + bool verifySelectionBeforeDeletion(); + + //! Sets the current font + void setCurrentFont(const QColor& color = QColor(0,0,0), bool bold = false); + + //! change the history according to _historyPos + void changeHistory(); + + //! flush output that was not yet printed + void flushStdOut(); + +private: + void executeCode(const QString& code); + + PythonQtObjectPtr _context; + + QStringList _history; + int _historyPosition; + + QString _clickedAnchor; + QString _storageKey; + QString _commandPrompt; + + QString _currentMultiLineCode; + + QString _stdOut; + QString _stdErr; + + QTextCharFormat _defaultTextCharacterFormat; + QCompleter* _completer; +}; + + + +#endif \ No newline at end of file diff --git a/src/src.pri b/src/src.pri new file mode 100644 index 0000000..b61cb50 --- /dev/null +++ b/src/src.pri @@ -0,0 +1,42 @@ +DEFINES += PYTHONQT_EXPORTS + +HEADERS += \ + $$PWD/PythonQt.h \ + $$PWD/PythonQtStdDecorators.h \ + $$PWD/PythonQtClassInfo.h \ + $$PWD/PythonQtImporter.h \ + $$PWD/PythonQtObjectPtr.h \ + $$PWD/PythonQtSlot.h \ + $$PWD/PythonQtStdOut.h \ + $$PWD/PythonQtMisc.h \ + $$PWD/PythonQtMethodInfo.h \ + $$PWD/PythonQtImportFileInterface.h \ + $$PWD/PythonQtConversion.h \ + $$PWD/PythonQtSignalReceiver.h \ + $$PWD/PythonQtWrapper.h \ + $$PWD/PythonQtMetaObjectWrapper.h \ + $$PWD/PythonQtCppWrapperFactory.h \ + $$PWD/PythonQtVariants.h \ + $$PWD/PythonQtVariantWrapper.h \ + $$PWD/wrapper/PythonQtWrappedVariants.h \ + $$PWD/gui/PythonQtScriptingConsole.h \ + $$PWD/PythonQtSystem.h + +SOURCES += \ + $$PWD/PythonQtStdDecorators.cpp \ + $$PWD/PythonQt.cpp \ + $$PWD/PythonQtClassInfo.cpp \ + $$PWD/PythonQtImporter.cpp \ + $$PWD/PythonQtObjectPtr.cpp \ + $$PWD/PythonQtStdOut.cpp \ + $$PWD/PythonQtSlot.cpp \ + $$PWD/PythonQtMisc.cpp \ + $$PWD/PythonQtMethodInfo.cpp \ + $$PWD/PythonQtConversion.cpp \ + $$PWD/PythonQtSignalReceiver.cpp \ + $$PWD/PythonQtVariants.cpp \ + $$PWD/PythonQtVariantWrapper.cpp \ + $$PWD/PythonQtWrapper.cpp \ + $$PWD/PythonQtMetaObjectWrapper.cpp \ + $$PWD/gui/PythonQtScriptingConsole.cpp + diff --git a/src/src.pro b/src/src.pro new file mode 100644 index 0000000..404a957 --- /dev/null +++ b/src/src.pro @@ -0,0 +1,18 @@ +# --------- PythonQt profile ------------------- +# Last changed by $Author: florian $ +# $Id: PythonQt.pro 35381 2006-03-16 13:05:52Z florian $ +# $Source$ +# -------------------------------------------------- + +TARGET = PythonQt +TEMPLATE = lib + + +DESTDIR = ../lib + +CONFIG += qt dll + +include ( ../build/common.prf ) +include ( ../build/python.prf ) + +include ( src.pri ) diff --git a/src/wrapper/PythonQtWrappedVariants.h b/src/wrapper/PythonQtWrappedVariants.h new file mode 100644 index 0000000..82e761e --- /dev/null +++ b/src/wrapper/PythonQtWrappedVariants.h @@ -0,0 +1,2506 @@ + +#include +#include +#include +#include +/**************************************************************************** +** Meta object code from reading C++ file 'qbitarray.h' +** +** Created: Thu 12. Apr 14:07:28 2007 +** by: The Qt Meta Object Compiler version 59 (Qt 4.2.3) +** +** WARNING! All changes made in this file will be lost! +*****************************************************************************/ + +#include "qbitarray.h" +class PythonQtQBitArrayWrapper : public QObject { + Q_OBJECT + +public: +public slots: +QVariant new_QBitArray() { return QBitArray(); } +QVariant new_QBitArray(int arg0,bool arg1) { return QBitArray(arg0,arg1); } +QVariant new_QBitArray(int arg0) { return QBitArray(arg0); } +QVariant new_QBitArray(const QBitArray & arg0) { return QBitArray(arg0); } +int size(QBitArray* obj) const {return obj->size(); } +int count(QBitArray* obj) const {return obj->count(); } +int count(QBitArray* obj,bool arg0) const {return obj->count(arg0); } +bool isEmpty(QBitArray* obj) const {return obj->isEmpty(); } +bool isNull(QBitArray* obj) const {return obj->isNull(); } +void resize(QBitArray* obj,int arg0) {obj->resize(arg0); } +void detach(QBitArray* obj) {obj->detach(); } +bool isDetached(QBitArray* obj) const {return obj->isDetached(); } +void clear(QBitArray* obj) {obj->clear(); } +bool testBit(QBitArray* obj,int arg0) const {return obj->testBit(arg0); } +void setBit(QBitArray* obj,int arg0) {obj->setBit(arg0); } +void setBit(QBitArray* obj,int arg0,bool arg1) {obj->setBit(arg0,arg1); } +void clearBit(QBitArray* obj,int arg0) {obj->clearBit(arg0); } +bool toggleBit(QBitArray* obj,int arg0) {return obj->toggleBit(arg0); } +bool at(QBitArray* obj,int arg0) const {return obj->at(arg0); } +bool fill(QBitArray* obj,bool arg0,int arg1) {return obj->fill(arg0,arg1); } +bool fill(QBitArray* obj,bool arg0) {return obj->fill(arg0); } +void fill(QBitArray* obj,bool arg0,int arg1,int arg2) {obj->fill(arg0,arg1,arg2); } +void truncate(QBitArray* obj,int arg0) {obj->truncate(arg0); } + +}; + +/**************************************************************************** +** Meta object code from reading C++ file 'qdatetime.h' +** +** Created: Thu 12. Apr 14:07:28 2007 +** by: The Qt Meta Object Compiler version 59 (Qt 4.2.3) +** +** WARNING! All changes made in this file will be lost! +*****************************************************************************/ + +#include "qdatetime.h" +class PythonQtQDateWrapper : public QObject { + Q_OBJECT + +public: +public slots: +QVariant new_QDate() { return QDate(); } +QVariant new_QDate(int arg0,int arg1,int arg2) { return QDate(arg0,arg1,arg2); } +bool isNull(QDate* obj) const {return obj->isNull(); } +bool isValid(QDate* obj) const {return obj->isValid(); } +int year(QDate* obj) const {return obj->year(); } +int month(QDate* obj) const {return obj->month(); } +int day(QDate* obj) const {return obj->day(); } +int dayOfWeek(QDate* obj) const {return obj->dayOfWeek(); } +int dayOfYear(QDate* obj) const {return obj->dayOfYear(); } +int daysInMonth(QDate* obj) const {return obj->daysInMonth(); } +int daysInYear(QDate* obj) const {return obj->daysInYear(); } +int weekNumber(QDate* obj,int * arg0) const {return obj->weekNumber(arg0); } +int weekNumber(QDate* obj) const {return obj->weekNumber(); } +QString static_QDate_shortMonthName(int arg0) {return QDate::shortMonthName(arg0); } +QString static_QDate_shortDayName(int arg0) {return QDate::shortDayName(arg0); } +QString static_QDate_longMonthName(int arg0) {return QDate::longMonthName(arg0); } +QString static_QDate_longDayName(int arg0) {return QDate::longDayName(arg0); } +QString toString(QDate* obj,Qt::DateFormat arg0) const {return obj->toString(arg0); } +QString toString(QDate* obj) const {return obj->toString(); } +QString toString(QDate* obj,const QString & arg0) const {return obj->toString(arg0); } +bool setYMD(QDate* obj,int arg0,int arg1,int arg2) {return obj->setYMD(arg0,arg1,arg2); } +bool setDate(QDate* obj,int arg0,int arg1,int arg2) {return obj->setDate(arg0,arg1,arg2); } +QDate addDays(QDate* obj,int arg0) const {return obj->addDays(arg0); } +QDate addMonths(QDate* obj,int arg0) const {return obj->addMonths(arg0); } +QDate addYears(QDate* obj,int arg0) const {return obj->addYears(arg0); } +int daysTo(QDate* obj,const QDate & arg0) const {return obj->daysTo(arg0); } +QDate static_QDate_currentDate() {return QDate::currentDate(); } +QDate static_QDate_fromString(const QString & arg0,Qt::DateFormat arg1) {return QDate::fromString(arg0,arg1); } +QDate static_QDate_fromString(const QString & arg0) {return QDate::fromString(arg0); } +QDate static_QDate_fromString(const QString & arg0,const QString & arg1) {return QDate::fromString(arg0,arg1); } +bool static_QDate_isValid(int arg0,int arg1,int arg2) {return QDate::isValid(arg0,arg1,arg2); } +bool static_QDate_isLeapYear(int arg0) {return QDate::isLeapYear(arg0); } +uint static_QDate_gregorianToJulian(int arg0,int arg1,int arg2) {return QDate::gregorianToJulian(arg0,arg1,arg2); } +void static_QDate_julianToGregorian(uint arg0,int & arg1,int & arg2,int & arg3) {QDate::julianToGregorian(arg0,arg1,arg2,arg3); } +QDate fromJulianDay(QDate* obj,int arg0) {return obj->fromJulianDay(arg0); } +int toJulianDay(QDate* obj) const {return obj->toJulianDay(); } + +}; + +class PythonQtQTimeWrapper : public QObject { + Q_OBJECT + +public: +public slots: +QVariant new_QTime() { return QTime(); } +bool isNull(QTime* obj) const {return obj->isNull(); } +bool isValid(QTime* obj) const {return obj->isValid(); } +int hour(QTime* obj) const {return obj->hour(); } +int minute(QTime* obj) const {return obj->minute(); } +int second(QTime* obj) const {return obj->second(); } +int msec(QTime* obj) const {return obj->msec(); } +QString toString(QTime* obj,Qt::DateFormat arg0) const {return obj->toString(arg0); } +QString toString(QTime* obj) const {return obj->toString(); } +QString toString(QTime* obj,const QString & arg0) const {return obj->toString(arg0); } +bool setHMS(QTime* obj,int arg0,int arg1,int arg2,int arg3) {return obj->setHMS(arg0,arg1,arg2,arg3); } +bool setHMS(QTime* obj,int arg0,int arg1,int arg2) {return obj->setHMS(arg0,arg1,arg2); } +QTime addSecs(QTime* obj,int arg0) const {return obj->addSecs(arg0); } +int secsTo(QTime* obj,const QTime & arg0) const {return obj->secsTo(arg0); } +QTime addMSecs(QTime* obj,int arg0) const {return obj->addMSecs(arg0); } +int msecsTo(QTime* obj,const QTime & arg0) const {return obj->msecsTo(arg0); } +QTime static_QTime_currentTime() {return QTime::currentTime(); } +QTime static_QTime_fromString(const QString & arg0,Qt::DateFormat arg1) {return QTime::fromString(arg0,arg1); } +QTime static_QTime_fromString(const QString & arg0) {return QTime::fromString(arg0); } +QTime static_QTime_fromString(const QString & arg0,const QString & arg1) {return QTime::fromString(arg0,arg1); } +bool static_QTime_isValid(int arg0,int arg1,int arg2,int arg3) {return QTime::isValid(arg0,arg1,arg2,arg3); } +bool static_QTime_isValid(int arg0,int arg1,int arg2) {return QTime::isValid(arg0,arg1,arg2); } +void start(QTime* obj) {obj->start(); } +int restart(QTime* obj) {return obj->restart(); } +int elapsed(QTime* obj) const {return obj->elapsed(); } + +}; + +class PythonQtQDateTimeWrapper : public QObject { + Q_OBJECT + +public: +public slots: +QVariant new_QDateTime() { return QDateTime(); } +QVariant new_QDateTime(const QDate & arg0) { return QDateTime(arg0); } +QVariant new_QDateTime(const QDate & arg0,const QTime & arg1,Qt::TimeSpec arg2) { return QDateTime(arg0,arg1,arg2); } +QVariant new_QDateTime(const QDate & arg0,const QTime & arg1) { return QDateTime(arg0,arg1); } +QVariant new_QDateTime(const QDateTime & arg0) { return QDateTime(arg0); } +bool isNull(QDateTime* obj) const {return obj->isNull(); } +bool isValid(QDateTime* obj) const {return obj->isValid(); } +QDate date(QDateTime* obj) const {return obj->date(); } +QTime time(QDateTime* obj) const {return obj->time(); } +Qt::TimeSpec timeSpec(QDateTime* obj) const {return obj->timeSpec(); } +uint toTime_t(QDateTime* obj) const {return obj->toTime_t(); } +void setDate(QDateTime* obj,const QDate & arg0) {obj->setDate(arg0); } +void setTime(QDateTime* obj,const QTime & arg0) {obj->setTime(arg0); } +void setTimeSpec(QDateTime* obj,Qt::TimeSpec arg0) {obj->setTimeSpec(arg0); } +void setTime_t(QDateTime* obj,uint arg0) {obj->setTime_t(arg0); } +QString toString(QDateTime* obj,Qt::DateFormat arg0) const {return obj->toString(arg0); } +QString toString(QDateTime* obj) const {return obj->toString(); } +QString toString(QDateTime* obj,const QString & arg0) const {return obj->toString(arg0); } +QDateTime addDays(QDateTime* obj,int arg0) const {return obj->addDays(arg0); } +QDateTime addMonths(QDateTime* obj,int arg0) const {return obj->addMonths(arg0); } +QDateTime addYears(QDateTime* obj,int arg0) const {return obj->addYears(arg0); } +QDateTime addSecs(QDateTime* obj,int arg0) const {return obj->addSecs(arg0); } +QDateTime addMSecs(QDateTime* obj,qint64 arg0) const {return obj->addMSecs(arg0); } +QDateTime toTimeSpec(QDateTime* obj,Qt::TimeSpec arg0) const {return obj->toTimeSpec(arg0); } +QDateTime toLocalTime(QDateTime* obj) const {return obj->toLocalTime(); } +QDateTime toUTC(QDateTime* obj) const {return obj->toUTC(); } +int daysTo(QDateTime* obj,const QDateTime & arg0) const {return obj->daysTo(arg0); } +int secsTo(QDateTime* obj,const QDateTime & arg0) const {return obj->secsTo(arg0); } +QDateTime static_QDateTime_currentDateTime() {return QDateTime::currentDateTime(); } +QDateTime static_QDateTime_fromString(const QString & arg0,Qt::DateFormat arg1) {return QDateTime::fromString(arg0,arg1); } +QDateTime static_QDateTime_fromString(const QString & arg0) {return QDateTime::fromString(arg0); } +QDateTime static_QDateTime_fromString(const QString & arg0,const QString & arg1) {return QDateTime::fromString(arg0,arg1); } +QDateTime static_QDateTime_fromTime_t(uint arg0) {return QDateTime::fromTime_t(arg0); } + +}; + +/**************************************************************************** +** Meta object code from reading C++ file 'qurl.h' +** +** Created: Thu 12. Apr 14:07:28 2007 +** by: The Qt Meta Object Compiler version 59 (Qt 4.2.3) +** +** WARNING! All changes made in this file will be lost! +*****************************************************************************/ + +#include "qurl.h" +class PythonQtQUrlWrapper : public QObject { + Q_OBJECT + +public: +Q_ENUMS(ParsingMode FormattingOption ) +enum ParsingMode {TolerantMode = QUrl::TolerantMode, +StrictMode = QUrl::StrictMode }; +enum FormattingOption {None = QUrl::None, +RemoveScheme = QUrl::RemoveScheme, +RemovePassword = QUrl::RemovePassword, +RemoveUserInfo = QUrl::RemoveUserInfo, +RemovePort = QUrl::RemovePort, +RemoveAuthority = QUrl::RemoveAuthority, +RemovePath = QUrl::RemovePath, +RemoveQuery = QUrl::RemoveQuery, +RemoveFragment = QUrl::RemoveFragment, +StripTrailingSlash = QUrl::StripTrailingSlash }; +Q_DECLARE_FLAGS(FormattingOptions, FormattingOption) +public slots: +QVariant new_QUrl(const QString & arg0) { return QUrl(arg0); } +QVariant new_QUrl(const QString & arg0,ParsingMode arg1) { return QUrl(arg0,(QUrl::ParsingMode)arg1); } +QVariant new_QUrl(const QUrl & arg0) { return QUrl(arg0); } +void setUrl(QUrl* obj,const QString & arg0) {obj->setUrl(arg0); } +void setUrl(QUrl* obj,const QString & arg0,ParsingMode arg1) {obj->setUrl(arg0,(QUrl::ParsingMode)arg1); } +void setEncodedUrl(QUrl* obj,const QByteArray & arg0) {obj->setEncodedUrl(arg0); } +void setEncodedUrl(QUrl* obj,const QByteArray & arg0,ParsingMode arg1) {obj->setEncodedUrl(arg0,(QUrl::ParsingMode)arg1); } +bool isValid(QUrl* obj) const {return obj->isValid(); } +bool isEmpty(QUrl* obj) const {return obj->isEmpty(); } +void clear(QUrl* obj) {obj->clear(); } +void setScheme(QUrl* obj,const QString & arg0) {obj->setScheme(arg0); } +QString scheme(QUrl* obj) const {return obj->scheme(); } +void setAuthority(QUrl* obj,const QString & arg0) {obj->setAuthority(arg0); } +QString authority(QUrl* obj) const {return obj->authority(); } +void setUserInfo(QUrl* obj,const QString & arg0) {obj->setUserInfo(arg0); } +QString userInfo(QUrl* obj) const {return obj->userInfo(); } +void setUserName(QUrl* obj,const QString & arg0) {obj->setUserName(arg0); } +QString userName(QUrl* obj) const {return obj->userName(); } +void setPassword(QUrl* obj,const QString & arg0) {obj->setPassword(arg0); } +QString password(QUrl* obj) const {return obj->password(); } +void setHost(QUrl* obj,const QString & arg0) {obj->setHost(arg0); } +QString host(QUrl* obj) const {return obj->host(); } +void setPort(QUrl* obj,int arg0) {obj->setPort(arg0); } +int port(QUrl* obj) const {return obj->port(); } +int port(QUrl* obj,int arg0) const {return obj->port(arg0); } +void setPath(QUrl* obj,const QString & arg0) {obj->setPath(arg0); } +QString path(QUrl* obj) const {return obj->path(); } +bool hasQuery(QUrl* obj) const {return obj->hasQuery(); } +void setEncodedQuery(QUrl* obj,const QByteArray & arg0) {obj->setEncodedQuery(arg0); } +QByteArray encodedQuery(QUrl* obj) const {return obj->encodedQuery(); } +void setQueryDelimiters(QUrl* obj,char arg0,char arg1) {obj->setQueryDelimiters(arg0,arg1); } +char queryValueDelimiter(QUrl* obj) const {return obj->queryValueDelimiter(); } +char queryPairDelimiter(QUrl* obj) const {return obj->queryPairDelimiter(); } +void setQueryItems(QUrl* obj,const QList > & arg0) {obj->setQueryItems(arg0); } +void addQueryItem(QUrl* obj,const QString & arg0,const QString & arg1) {obj->addQueryItem(arg0,arg1); } +QList > queryItems(QUrl* obj) const {return obj->queryItems(); } +bool hasQueryItem(QUrl* obj,const QString & arg0) const {return obj->hasQueryItem(arg0); } +QString queryItemValue(QUrl* obj,const QString & arg0) const {return obj->queryItemValue(arg0); } +QStringList allQueryItemValues(QUrl* obj,const QString & arg0) const {return obj->allQueryItemValues(arg0); } +void removeQueryItem(QUrl* obj,const QString & arg0) {obj->removeQueryItem(arg0); } +void removeAllQueryItems(QUrl* obj,const QString & arg0) {obj->removeAllQueryItems(arg0); } +void setFragment(QUrl* obj,const QString & arg0) {obj->setFragment(arg0); } +QString fragment(QUrl* obj) const {return obj->fragment(); } +bool hasFragment(QUrl* obj) const {return obj->hasFragment(); } +QUrl resolved(QUrl* obj,const QUrl & arg0) const {return obj->resolved(arg0); } +bool isRelative(QUrl* obj) const {return obj->isRelative(); } +bool isParentOf(QUrl* obj,const QUrl & arg0) const {return obj->isParentOf(arg0); } +QUrl static_QUrl_fromLocalFile(const QString & arg0) {return QUrl::fromLocalFile(arg0); } +QString toLocalFile(QUrl* obj) const {return obj->toLocalFile(); } +QString toString(QUrl* obj,FormattingOptions arg0) const {return obj->toString((QUrl::FormattingOptions)QFlag(arg0)); } +QString toString(QUrl* obj) const {return obj->toString(); } +QByteArray toEncoded(QUrl* obj,FormattingOptions arg0) const {return obj->toEncoded((QUrl::FormattingOptions)QFlag(arg0)); } +QByteArray toEncoded(QUrl* obj) const {return obj->toEncoded(); } +QUrl static_QUrl_fromEncoded(const QByteArray & arg0) {return QUrl::fromEncoded(arg0); } +QUrl static_QUrl_fromEncoded(const QByteArray & arg0,ParsingMode arg1) {return QUrl::fromEncoded(arg0,(QUrl::ParsingMode)arg1); } +void detach(QUrl* obj) {obj->detach(); } +bool isDetached(QUrl* obj) const {return obj->isDetached(); } +QString static_QUrl_fromPercentEncoding(const QByteArray & arg0) {return QUrl::fromPercentEncoding(arg0); } +QByteArray static_QUrl_toPercentEncoding(const QString & arg0,const QByteArray & arg1,const QByteArray & arg2) {return QUrl::toPercentEncoding(arg0,arg1,arg2); } +QByteArray static_QUrl_toPercentEncoding(const QString & arg0,const QByteArray & arg1) {return QUrl::toPercentEncoding(arg0,arg1); } +QByteArray static_QUrl_toPercentEncoding(const QString & arg0) {return QUrl::toPercentEncoding(arg0); } +QString static_QUrl_fromPunycode(const QByteArray & arg0) {return QUrl::fromPunycode(arg0); } +QByteArray static_QUrl_toPunycode(const QString & arg0) {return QUrl::toPunycode(arg0); } +QString static_QUrl_fromAce(const QByteArray & arg0) {return QUrl::fromAce(arg0); } +QByteArray static_QUrl_toAce(const QString & arg0) {return QUrl::toAce(arg0); } +QStringList static_QUrl_idnWhitelist() {return QUrl::idnWhitelist(); } +void static_QUrl_setIdnWhitelist(const QStringList & arg0) {QUrl::setIdnWhitelist(arg0); } +QString errorString(QUrl* obj) const {return obj->errorString(); } + +}; + +/**************************************************************************** +** Meta object code from reading C++ file 'qlocale.h' +** +** Created: Thu 12. Apr 14:07:28 2007 +** by: The Qt Meta Object Compiler version 59 (Qt 4.2.3) +** +** WARNING! All changes made in this file will be lost! +*****************************************************************************/ + +#include "qlocale.h" +class PythonQtQLocaleWrapper : public QObject { + Q_OBJECT + +public: +Q_ENUMS(Language Country FormatType NumberOption ) +enum Language {C = QLocale::C, +Abkhazian = QLocale::Abkhazian, +Afan = QLocale::Afan, +Afar = QLocale::Afar, +Afrikaans = QLocale::Afrikaans, +Albanian = QLocale::Albanian, +Amharic = QLocale::Amharic, +Arabic = QLocale::Arabic, +Armenian = QLocale::Armenian, +Assamese = QLocale::Assamese, +Aymara = QLocale::Aymara, +Azerbaijani = QLocale::Azerbaijani, +Bashkir = QLocale::Bashkir, +Basque = QLocale::Basque, +Bengali = QLocale::Bengali, +Bhutani = QLocale::Bhutani, +Bihari = QLocale::Bihari, +Bislama = QLocale::Bislama, +Breton = QLocale::Breton, +Bulgarian = QLocale::Bulgarian, +Burmese = QLocale::Burmese, +Byelorussian = QLocale::Byelorussian, +Cambodian = QLocale::Cambodian, +Catalan = QLocale::Catalan, +Chinese = QLocale::Chinese, +Corsican = QLocale::Corsican, +Croatian = QLocale::Croatian, +Czech = QLocale::Czech, +Danish = QLocale::Danish, +Dutch = QLocale::Dutch, +English = QLocale::English, +Esperanto = QLocale::Esperanto, +Estonian = QLocale::Estonian, +Faroese = QLocale::Faroese, +FijiLanguage = QLocale::FijiLanguage, +Finnish = QLocale::Finnish, +French = QLocale::French, +Frisian = QLocale::Frisian, +Gaelic = QLocale::Gaelic, +Galician = QLocale::Galician, +Georgian = QLocale::Georgian, +German = QLocale::German, +Greek = QLocale::Greek, +Greenlandic = QLocale::Greenlandic, +Guarani = QLocale::Guarani, +Gujarati = QLocale::Gujarati, +Hausa = QLocale::Hausa, +Hebrew = QLocale::Hebrew, +Hindi = QLocale::Hindi, +Hungarian = QLocale::Hungarian, +Icelandic = QLocale::Icelandic, +Indonesian = QLocale::Indonesian, +Interlingua = QLocale::Interlingua, +Interlingue = QLocale::Interlingue, +Inuktitut = QLocale::Inuktitut, +Inupiak = QLocale::Inupiak, +Irish = QLocale::Irish, +Italian = QLocale::Italian, +Japanese = QLocale::Japanese, +Javanese = QLocale::Javanese, +Kannada = QLocale::Kannada, +Kashmiri = QLocale::Kashmiri, +Kazakh = QLocale::Kazakh, +Kinyarwanda = QLocale::Kinyarwanda, +Kirghiz = QLocale::Kirghiz, +Korean = QLocale::Korean, +Kurdish = QLocale::Kurdish, +Kurundi = QLocale::Kurundi, +Laothian = QLocale::Laothian, +Latin = QLocale::Latin, +Latvian = QLocale::Latvian, +Lingala = QLocale::Lingala, +Lithuanian = QLocale::Lithuanian, +Macedonian = QLocale::Macedonian, +Malagasy = QLocale::Malagasy, +Malay = QLocale::Malay, +Malayalam = QLocale::Malayalam, +Maltese = QLocale::Maltese, +Maori = QLocale::Maori, +Marathi = QLocale::Marathi, +Moldavian = QLocale::Moldavian, +Mongolian = QLocale::Mongolian, +NauruLanguage = QLocale::NauruLanguage, +Nepali = QLocale::Nepali, +Norwegian = QLocale::Norwegian, +Occitan = QLocale::Occitan, +Oriya = QLocale::Oriya, +Pashto = QLocale::Pashto, +Persian = QLocale::Persian, +Polish = QLocale::Polish, +Portuguese = QLocale::Portuguese, +Punjabi = QLocale::Punjabi, +Quechua = QLocale::Quechua, +RhaetoRomance = QLocale::RhaetoRomance, +Romanian = QLocale::Romanian, +Russian = QLocale::Russian, +Samoan = QLocale::Samoan, +Sangho = QLocale::Sangho, +Sanskrit = QLocale::Sanskrit, +Serbian = QLocale::Serbian, +SerboCroatian = QLocale::SerboCroatian, +Sesotho = QLocale::Sesotho, +Setswana = QLocale::Setswana, +Shona = QLocale::Shona, +Sindhi = QLocale::Sindhi, +Singhalese = QLocale::Singhalese, +Siswati = QLocale::Siswati, +Slovak = QLocale::Slovak, +Slovenian = QLocale::Slovenian, +Somali = QLocale::Somali, +Spanish = QLocale::Spanish, +Sundanese = QLocale::Sundanese, +Swahili = QLocale::Swahili, +Swedish = QLocale::Swedish, +Tagalog = QLocale::Tagalog, +Tajik = QLocale::Tajik, +Tamil = QLocale::Tamil, +Tatar = QLocale::Tatar, +Telugu = QLocale::Telugu, +Thai = QLocale::Thai, +Tibetan = QLocale::Tibetan, +Tigrinya = QLocale::Tigrinya, +TongaLanguage = QLocale::TongaLanguage, +Tsonga = QLocale::Tsonga, +Turkish = QLocale::Turkish, +Turkmen = QLocale::Turkmen, +Twi = QLocale::Twi, +Uigur = QLocale::Uigur, +Ukrainian = QLocale::Ukrainian, +Urdu = QLocale::Urdu, +Uzbek = QLocale::Uzbek, +Vietnamese = QLocale::Vietnamese, +Volapuk = QLocale::Volapuk, +Welsh = QLocale::Welsh, +Wolof = QLocale::Wolof, +Xhosa = QLocale::Xhosa, +Yiddish = QLocale::Yiddish, +Yoruba = QLocale::Yoruba, +Zhuang = QLocale::Zhuang, +Zulu = QLocale::Zulu, +Nynorsk = QLocale::Nynorsk, +Bosnian = QLocale::Bosnian, +Divehi = QLocale::Divehi, +Manx = QLocale::Manx, +Cornish = QLocale::Cornish, +LastLanguage = QLocale::LastLanguage }; +enum Country {AnyCountry = QLocale::AnyCountry, +Afghanistan = QLocale::Afghanistan, +Albania = QLocale::Albania, +Algeria = QLocale::Algeria, +AmericanSamoa = QLocale::AmericanSamoa, +Andorra = QLocale::Andorra, +Angola = QLocale::Angola, +Anguilla = QLocale::Anguilla, +Antarctica = QLocale::Antarctica, +AntiguaAndBarbuda = QLocale::AntiguaAndBarbuda, +Argentina = QLocale::Argentina, +Armenia = QLocale::Armenia, +Aruba = QLocale::Aruba, +Australia = QLocale::Australia, +Austria = QLocale::Austria, +Azerbaijan = QLocale::Azerbaijan, +Bahamas = QLocale::Bahamas, +Bahrain = QLocale::Bahrain, +Bangladesh = QLocale::Bangladesh, +Barbados = QLocale::Barbados, +Belarus = QLocale::Belarus, +Belgium = QLocale::Belgium, +Belize = QLocale::Belize, +Benin = QLocale::Benin, +Bermuda = QLocale::Bermuda, +Bhutan = QLocale::Bhutan, +Bolivia = QLocale::Bolivia, +BosniaAndHerzegowina = QLocale::BosniaAndHerzegowina, +Botswana = QLocale::Botswana, +BouvetIsland = QLocale::BouvetIsland, +Brazil = QLocale::Brazil, +BritishIndianOceanTerritory = QLocale::BritishIndianOceanTerritory, +BruneiDarussalam = QLocale::BruneiDarussalam, +Bulgaria = QLocale::Bulgaria, +BurkinaFaso = QLocale::BurkinaFaso, +Burundi = QLocale::Burundi, +Cambodia = QLocale::Cambodia, +Cameroon = QLocale::Cameroon, +Canada = QLocale::Canada, +CapeVerde = QLocale::CapeVerde, +CaymanIslands = QLocale::CaymanIslands, +CentralAfricanRepublic = QLocale::CentralAfricanRepublic, +Chad = QLocale::Chad, +Chile = QLocale::Chile, +China = QLocale::China, +ChristmasIsland = QLocale::ChristmasIsland, +CocosIslands = QLocale::CocosIslands, +Colombia = QLocale::Colombia, +Comoros = QLocale::Comoros, +DemocraticRepublicOfCongo = QLocale::DemocraticRepublicOfCongo, +PeoplesRepublicOfCongo = QLocale::PeoplesRepublicOfCongo, +CookIslands = QLocale::CookIslands, +CostaRica = QLocale::CostaRica, +IvoryCoast = QLocale::IvoryCoast, +Croatia = QLocale::Croatia, +Cuba = QLocale::Cuba, +Cyprus = QLocale::Cyprus, +CzechRepublic = QLocale::CzechRepublic, +Denmark = QLocale::Denmark, +Djibouti = QLocale::Djibouti, +Dominica = QLocale::Dominica, +DominicanRepublic = QLocale::DominicanRepublic, +EastTimor = QLocale::EastTimor, +Ecuador = QLocale::Ecuador, +Egypt = QLocale::Egypt, +ElSalvador = QLocale::ElSalvador, +EquatorialGuinea = QLocale::EquatorialGuinea, +Eritrea = QLocale::Eritrea, +Estonia = QLocale::Estonia, +Ethiopia = QLocale::Ethiopia, +FalklandIslands = QLocale::FalklandIslands, +FaroeIslands = QLocale::FaroeIslands, +FijiCountry = QLocale::FijiCountry, +Finland = QLocale::Finland, +France = QLocale::France, +MetropolitanFrance = QLocale::MetropolitanFrance, +FrenchGuiana = QLocale::FrenchGuiana, +FrenchPolynesia = QLocale::FrenchPolynesia, +FrenchSouthernTerritories = QLocale::FrenchSouthernTerritories, +Gabon = QLocale::Gabon, +Gambia = QLocale::Gambia, +Georgia = QLocale::Georgia, +Germany = QLocale::Germany, +Ghana = QLocale::Ghana, +Gibraltar = QLocale::Gibraltar, +Greece = QLocale::Greece, +Greenland = QLocale::Greenland, +Grenada = QLocale::Grenada, +Guadeloupe = QLocale::Guadeloupe, +Guam = QLocale::Guam, +Guatemala = QLocale::Guatemala, +Guinea = QLocale::Guinea, +GuineaBissau = QLocale::GuineaBissau, +Guyana = QLocale::Guyana, +Haiti = QLocale::Haiti, +HeardAndMcDonaldIslands = QLocale::HeardAndMcDonaldIslands, +Honduras = QLocale::Honduras, +HongKong = QLocale::HongKong, +Hungary = QLocale::Hungary, +Iceland = QLocale::Iceland, +India = QLocale::India, +Indonesia = QLocale::Indonesia, +Iran = QLocale::Iran, +Iraq = QLocale::Iraq, +Ireland = QLocale::Ireland, +Israel = QLocale::Israel, +Italy = QLocale::Italy, +Jamaica = QLocale::Jamaica, +Japan = QLocale::Japan, +Jordan = QLocale::Jordan, +Kazakhstan = QLocale::Kazakhstan, +Kenya = QLocale::Kenya, +Kiribati = QLocale::Kiribati, +DemocraticRepublicOfKorea = QLocale::DemocraticRepublicOfKorea, +RepublicOfKorea = QLocale::RepublicOfKorea, +Kuwait = QLocale::Kuwait, +Kyrgyzstan = QLocale::Kyrgyzstan, +Lao = QLocale::Lao, +Latvia = QLocale::Latvia, +Lebanon = QLocale::Lebanon, +Lesotho = QLocale::Lesotho, +Liberia = QLocale::Liberia, +LibyanArabJamahiriya = QLocale::LibyanArabJamahiriya, +Liechtenstein = QLocale::Liechtenstein, +Lithuania = QLocale::Lithuania, +Luxembourg = QLocale::Luxembourg, +Macau = QLocale::Macau, +Macedonia = QLocale::Macedonia, +Madagascar = QLocale::Madagascar, +Malawi = QLocale::Malawi, +Malaysia = QLocale::Malaysia, +Maldives = QLocale::Maldives, +Mali = QLocale::Mali, +Malta = QLocale::Malta, +MarshallIslands = QLocale::MarshallIslands, +Martinique = QLocale::Martinique, +Mauritania = QLocale::Mauritania, +Mauritius = QLocale::Mauritius, +Mayotte = QLocale::Mayotte, +Mexico = QLocale::Mexico, +Micronesia = QLocale::Micronesia, +Moldova = QLocale::Moldova, +Monaco = QLocale::Monaco, +Mongolia = QLocale::Mongolia, +Montserrat = QLocale::Montserrat, +Morocco = QLocale::Morocco, +Mozambique = QLocale::Mozambique, +Myanmar = QLocale::Myanmar, +Namibia = QLocale::Namibia, +NauruCountry = QLocale::NauruCountry, +Nepal = QLocale::Nepal, +Netherlands = QLocale::Netherlands, +NetherlandsAntilles = QLocale::NetherlandsAntilles, +NewCaledonia = QLocale::NewCaledonia, +NewZealand = QLocale::NewZealand, +Nicaragua = QLocale::Nicaragua, +Niger = QLocale::Niger, +Nigeria = QLocale::Nigeria, +Niue = QLocale::Niue, +NorfolkIsland = QLocale::NorfolkIsland, +NorthernMarianaIslands = QLocale::NorthernMarianaIslands, +Norway = QLocale::Norway, +Oman = QLocale::Oman, +Pakistan = QLocale::Pakistan, +Palau = QLocale::Palau, +PalestinianTerritory = QLocale::PalestinianTerritory, +Panama = QLocale::Panama, +PapuaNewGuinea = QLocale::PapuaNewGuinea, +Paraguay = QLocale::Paraguay, +Peru = QLocale::Peru, +Philippines = QLocale::Philippines, +Pitcairn = QLocale::Pitcairn, +Poland = QLocale::Poland, +Portugal = QLocale::Portugal, +PuertoRico = QLocale::PuertoRico, +Qatar = QLocale::Qatar, +Reunion = QLocale::Reunion, +Romania = QLocale::Romania, +RussianFederation = QLocale::RussianFederation, +Rwanda = QLocale::Rwanda, +SaintKittsAndNevis = QLocale::SaintKittsAndNevis, +StLucia = QLocale::StLucia, +StVincentAndTheGrenadines = QLocale::StVincentAndTheGrenadines, +Samoa = QLocale::Samoa, +SanMarino = QLocale::SanMarino, +SaoTomeAndPrincipe = QLocale::SaoTomeAndPrincipe, +SaudiArabia = QLocale::SaudiArabia, +Senegal = QLocale::Senegal, +Seychelles = QLocale::Seychelles, +SierraLeone = QLocale::SierraLeone, +Singapore = QLocale::Singapore, +Slovakia = QLocale::Slovakia, +Slovenia = QLocale::Slovenia, +SolomonIslands = QLocale::SolomonIslands, +Somalia = QLocale::Somalia, +SouthAfrica = QLocale::SouthAfrica, +SouthGeorgiaAndTheSouthSandwichIslands = QLocale::SouthGeorgiaAndTheSouthSandwichIslands, +Spain = QLocale::Spain, +SriLanka = QLocale::SriLanka, +StHelena = QLocale::StHelena, +StPierreAndMiquelon = QLocale::StPierreAndMiquelon, +Sudan = QLocale::Sudan, +Suriname = QLocale::Suriname, +SvalbardAndJanMayenIslands = QLocale::SvalbardAndJanMayenIslands, +Swaziland = QLocale::Swaziland, +Sweden = QLocale::Sweden, +Switzerland = QLocale::Switzerland, +SyrianArabRepublic = QLocale::SyrianArabRepublic, +Taiwan = QLocale::Taiwan, +Tajikistan = QLocale::Tajikistan, +Tanzania = QLocale::Tanzania, +Thailand = QLocale::Thailand, +Togo = QLocale::Togo, +Tokelau = QLocale::Tokelau, +TongaCountry = QLocale::TongaCountry, +TrinidadAndTobago = QLocale::TrinidadAndTobago, +Tunisia = QLocale::Tunisia, +Turkey = QLocale::Turkey, +Turkmenistan = QLocale::Turkmenistan, +TurksAndCaicosIslands = QLocale::TurksAndCaicosIslands, +Tuvalu = QLocale::Tuvalu, +Uganda = QLocale::Uganda, +Ukraine = QLocale::Ukraine, +UnitedArabEmirates = QLocale::UnitedArabEmirates, +UnitedKingdom = QLocale::UnitedKingdom, +UnitedStates = QLocale::UnitedStates, +UnitedStatesMinorOutlyingIslands = QLocale::UnitedStatesMinorOutlyingIslands, +Uruguay = QLocale::Uruguay, +Uzbekistan = QLocale::Uzbekistan, +Vanuatu = QLocale::Vanuatu, +VaticanCityState = QLocale::VaticanCityState, +Venezuela = QLocale::Venezuela, +VietNam = QLocale::VietNam, +BritishVirginIslands = QLocale::BritishVirginIslands, +USVirginIslands = QLocale::USVirginIslands, +WallisAndFutunaIslands = QLocale::WallisAndFutunaIslands, +WesternSahara = QLocale::WesternSahara, +Yemen = QLocale::Yemen, +Yugoslavia = QLocale::Yugoslavia, +Zambia = QLocale::Zambia, +Zimbabwe = QLocale::Zimbabwe, +SerbiaAndMontenegro = QLocale::SerbiaAndMontenegro, +LastCountry = QLocale::LastCountry }; +enum FormatType {LongFormat = QLocale::LongFormat, +ShortFormat = QLocale::ShortFormat }; +enum NumberOption {OmitGroupSeparator = QLocale::OmitGroupSeparator, +RejectGroupSeparator = QLocale::RejectGroupSeparator }; +Q_DECLARE_FLAGS(NumberOptions, NumberOption) +public slots: +QVariant new_QLocale(const QString & arg0) { return QLocale(arg0); } +QVariant new_QLocale(Language arg0,Country arg1) { return QLocale((QLocale::Language)arg0,(QLocale::Country)arg1); } +QVariant new_QLocale(Language arg0) { return QLocale((QLocale::Language)arg0); } +QVariant new_QLocale(const QLocale & arg0) { return QLocale(arg0); } +Language language(QLocale* obj) const {return (PythonQtQLocaleWrapper::Language)obj->language(); } +Country country(QLocale* obj) const {return (PythonQtQLocaleWrapper::Country)obj->country(); } +QString name(QLocale* obj) const {return obj->name(); } +short toShort(QLocale* obj,const QString & arg0,bool * arg1,int arg2) const {return obj->toShort(arg0,arg1,arg2); } +short toShort(QLocale* obj,const QString & arg0,bool * arg1) const {return obj->toShort(arg0,arg1); } +short toShort(QLocale* obj,const QString & arg0) const {return obj->toShort(arg0); } +ushort toUShort(QLocale* obj,const QString & arg0,bool * arg1,int arg2) const {return obj->toUShort(arg0,arg1,arg2); } +ushort toUShort(QLocale* obj,const QString & arg0,bool * arg1) const {return obj->toUShort(arg0,arg1); } +ushort toUShort(QLocale* obj,const QString & arg0) const {return obj->toUShort(arg0); } +int toInt(QLocale* obj,const QString & arg0,bool * arg1,int arg2) const {return obj->toInt(arg0,arg1,arg2); } +int toInt(QLocale* obj,const QString & arg0,bool * arg1) const {return obj->toInt(arg0,arg1); } +int toInt(QLocale* obj,const QString & arg0) const {return obj->toInt(arg0); } +uint toUInt(QLocale* obj,const QString & arg0,bool * arg1,int arg2) const {return obj->toUInt(arg0,arg1,arg2); } +uint toUInt(QLocale* obj,const QString & arg0,bool * arg1) const {return obj->toUInt(arg0,arg1); } +uint toUInt(QLocale* obj,const QString & arg0) const {return obj->toUInt(arg0); } +qlonglong toLongLong(QLocale* obj,const QString & arg0,bool * arg1,int arg2) const {return obj->toLongLong(arg0,arg1,arg2); } +qlonglong toLongLong(QLocale* obj,const QString & arg0,bool * arg1) const {return obj->toLongLong(arg0,arg1); } +qlonglong toLongLong(QLocale* obj,const QString & arg0) const {return obj->toLongLong(arg0); } +qlonglong toULongLong(QLocale* obj,const QString & arg0,bool * arg1,int arg2) const {return obj->toULongLong(arg0,arg1,arg2); } +qlonglong toULongLong(QLocale* obj,const QString & arg0,bool * arg1) const {return obj->toULongLong(arg0,arg1); } +qlonglong toULongLong(QLocale* obj,const QString & arg0) const {return obj->toULongLong(arg0); } +float toFloat(QLocale* obj,const QString & arg0,bool * arg1) const {return obj->toFloat(arg0,arg1); } +float toFloat(QLocale* obj,const QString & arg0) const {return obj->toFloat(arg0); } +double toDouble(QLocale* obj,const QString & arg0,bool * arg1) const {return obj->toDouble(arg0,arg1); } +double toDouble(QLocale* obj,const QString & arg0) const {return obj->toDouble(arg0); } +QString toString(QLocale* obj,qlonglong arg0) const {return obj->toString(arg0); } +QString toString(QLocale* obj,qulonglong arg0) const {return obj->toString(arg0); } +QString toString(QLocale* obj,short arg0) const {return obj->toString(arg0); } +QString toString(QLocale* obj,ushort arg0) const {return obj->toString(arg0); } +QString toString(QLocale* obj,int arg0) const {return obj->toString(arg0); } +QString toString(QLocale* obj,uint arg0) const {return obj->toString(arg0); } +QString toString(QLocale* obj,double arg0,char arg1,int arg2) const {return obj->toString(arg0,arg1,arg2); } +QString toString(QLocale* obj,double arg0,char arg1) const {return obj->toString(arg0,arg1); } +QString toString(QLocale* obj,double arg0) const {return obj->toString(arg0); } +QString toString(QLocale* obj,float arg0,char arg1,int arg2) const {return obj->toString(arg0,arg1,arg2); } +QString toString(QLocale* obj,float arg0,char arg1) const {return obj->toString(arg0,arg1); } +QString toString(QLocale* obj,float arg0) const {return obj->toString(arg0); } +QString toString(QLocale* obj,const QDate & arg0,const QString & arg1) const {return obj->toString(arg0,arg1); } +QString toString(QLocale* obj,const QDate & arg0,FormatType arg1) const {return obj->toString(arg0,(QLocale::FormatType)arg1); } +QString toString(QLocale* obj,const QDate & arg0) const {return obj->toString(arg0); } +QString toString(QLocale* obj,const QTime & arg0,const QString & arg1) const {return obj->toString(arg0,arg1); } +QString toString(QLocale* obj,const QTime & arg0,FormatType arg1) const {return obj->toString(arg0,(QLocale::FormatType)arg1); } +QString toString(QLocale* obj,const QTime & arg0) const {return obj->toString(arg0); } +QString dateFormat(QLocale* obj,FormatType arg0) const {return obj->dateFormat((QLocale::FormatType)arg0); } +QString dateFormat(QLocale* obj) const {return obj->dateFormat(); } +QString timeFormat(QLocale* obj,FormatType arg0) const {return obj->timeFormat((QLocale::FormatType)arg0); } +QString timeFormat(QLocale* obj) const {return obj->timeFormat(); } +QChar decimalPoint(QLocale* obj) const {return obj->decimalPoint(); } +QChar groupSeparator(QLocale* obj) const {return obj->groupSeparator(); } +QChar percent(QLocale* obj) const {return obj->percent(); } +QChar zeroDigit(QLocale* obj) const {return obj->zeroDigit(); } +QChar negativeSign(QLocale* obj) const {return obj->negativeSign(); } +QChar exponential(QLocale* obj) const {return obj->exponential(); } +QString monthName(QLocale* obj,int arg0,FormatType arg1) const {return obj->monthName(arg0,(QLocale::FormatType)arg1); } +QString monthName(QLocale* obj,int arg0) const {return obj->monthName(arg0); } +QString dayName(QLocale* obj,int arg0,FormatType arg1) const {return obj->dayName(arg0,(QLocale::FormatType)arg1); } +QString dayName(QLocale* obj,int arg0) const {return obj->dayName(arg0); } +QString static_QLocale_languageToString(Language arg0) {return QLocale::languageToString((QLocale::Language)arg0); } +QString static_QLocale_countryToString(Country arg0) {return QLocale::countryToString((QLocale::Country)arg0); } +void static_QLocale_setDefault(const QLocale & arg0) {QLocale::setDefault(arg0); } +QLocale static_QLocale_c() {return QLocale::c(); } +QLocale static_QLocale_system() {return QLocale::system(); } +void setNumberOptions(QLocale* obj,NumberOptions arg0) {obj->setNumberOptions((QLocale::NumberOptions)QFlag(arg0)); } +NumberOptions numberOptions(QLocale* obj) const {return (PythonQtQLocaleWrapper::NumberOptions)QFlag(obj->numberOptions()); } + +}; + +class PythonQtQSystemLocaleWrapper : public QObject { + Q_OBJECT + +public: +Q_ENUMS(QueryType ) +enum QueryType {LanguageId = QSystemLocale::LanguageId, +CountryId = QSystemLocale::CountryId, +DecimalPoint = QSystemLocale::DecimalPoint, +GroupSeparator = QSystemLocale::GroupSeparator, +ZeroDigit = QSystemLocale::ZeroDigit, +NegativeSign = QSystemLocale::NegativeSign, +DateFormatLong = QSystemLocale::DateFormatLong, +DateFormatShort = QSystemLocale::DateFormatShort, +TimeFormatLong = QSystemLocale::TimeFormatLong, +TimeFormatShort = QSystemLocale::TimeFormatShort, +DayNameLong = QSystemLocale::DayNameLong, +DayNameShort = QSystemLocale::DayNameShort, +MonthNameLong = QSystemLocale::MonthNameLong, +MonthNameShort = QSystemLocale::MonthNameShort, +DateToStringLong = QSystemLocale::DateToStringLong, +DateToStringShort = QSystemLocale::DateToStringShort, +TimeToStringLong = QSystemLocale::TimeToStringLong, +TimeToStringShort = QSystemLocale::TimeToStringShort }; +public slots: +void delete_QSystemLocale(QSystemLocale* obj) { delete obj; } +QSystemLocale* new_QSystemLocale() { return new QSystemLocale(); } +QVariant query(QSystemLocale* obj,QueryType arg0,QVariant arg1) const {return obj->query((QSystemLocale::QueryType)arg0,arg1); } +QLocale fallbackLocale(QSystemLocale* obj) const {return obj->fallbackLocale(); } + +}; + +/**************************************************************************** +** Meta object code from reading C++ file 'qrect.h' +** +** Created: Thu 12. Apr 14:07:28 2007 +** by: The Qt Meta Object Compiler version 59 (Qt 4.2.3) +** +** WARNING! All changes made in this file will be lost! +*****************************************************************************/ + +#include "qrect.h" +class PythonQtQRectWrapper : public QObject { + Q_OBJECT + +public: +public slots: +QVariant new_QRect() { return QRect(); } +QVariant new_QRect(const QPoint & arg0,const QPoint & arg1) { return QRect(arg0,arg1); } +QVariant new_QRect(const QPoint & arg0,const QSize & arg1) { return QRect(arg0,arg1); } +QVariant new_QRect(int arg0,int arg1,int arg2,int arg3) { return QRect(arg0,arg1,arg2,arg3); } +bool isNull(QRect* obj) const {return obj->isNull(); } +bool isEmpty(QRect* obj) const {return obj->isEmpty(); } +bool isValid(QRect* obj) const {return obj->isValid(); } +int left(QRect* obj) const {return obj->left(); } +int top(QRect* obj) const {return obj->top(); } +int right(QRect* obj) const {return obj->right(); } +int bottom(QRect* obj) const {return obj->bottom(); } +QRect normalized(QRect* obj) const {return obj->normalized(); } +int x(QRect* obj) const {return obj->x(); } +int y(QRect* obj) const {return obj->y(); } +void setLeft(QRect* obj,int arg0) {obj->setLeft(arg0); } +void setTop(QRect* obj,int arg0) {obj->setTop(arg0); } +void setRight(QRect* obj,int arg0) {obj->setRight(arg0); } +void setBottom(QRect* obj,int arg0) {obj->setBottom(arg0); } +void setX(QRect* obj,int arg0) {obj->setX(arg0); } +void setY(QRect* obj,int arg0) {obj->setY(arg0); } +void setTopLeft(QRect* obj,const QPoint & arg0) {obj->setTopLeft(arg0); } +void setBottomRight(QRect* obj,const QPoint & arg0) {obj->setBottomRight(arg0); } +void setTopRight(QRect* obj,const QPoint & arg0) {obj->setTopRight(arg0); } +void setBottomLeft(QRect* obj,const QPoint & arg0) {obj->setBottomLeft(arg0); } +QPoint topLeft(QRect* obj) const {return obj->topLeft(); } +QPoint bottomRight(QRect* obj) const {return obj->bottomRight(); } +QPoint topRight(QRect* obj) const {return obj->topRight(); } +QPoint bottomLeft(QRect* obj) const {return obj->bottomLeft(); } +QPoint center(QRect* obj) const {return obj->center(); } +void moveLeft(QRect* obj,int arg0) {obj->moveLeft(arg0); } +void moveTop(QRect* obj,int arg0) {obj->moveTop(arg0); } +void moveRight(QRect* obj,int arg0) {obj->moveRight(arg0); } +void moveBottom(QRect* obj,int arg0) {obj->moveBottom(arg0); } +void moveTopLeft(QRect* obj,const QPoint & arg0) {obj->moveTopLeft(arg0); } +void moveBottomRight(QRect* obj,const QPoint & arg0) {obj->moveBottomRight(arg0); } +void moveTopRight(QRect* obj,const QPoint & arg0) {obj->moveTopRight(arg0); } +void moveBottomLeft(QRect* obj,const QPoint & arg0) {obj->moveBottomLeft(arg0); } +void moveCenter(QRect* obj,const QPoint & arg0) {obj->moveCenter(arg0); } +void translate(QRect* obj,int arg0,int arg1) {obj->translate(arg0,arg1); } +void translate(QRect* obj,const QPoint & arg0) {obj->translate(arg0); } +QRect translated(QRect* obj,int arg0,int arg1) const {return obj->translated(arg0,arg1); } +QRect translated(QRect* obj,const QPoint & arg0) const {return obj->translated(arg0); } +void moveTo(QRect* obj,int arg0,int arg1) {obj->moveTo(arg0,arg1); } +void moveTo(QRect* obj,const QPoint & arg0) {obj->moveTo(arg0); } +void setRect(QRect* obj,int arg0,int arg1,int arg2,int arg3) {obj->setRect(arg0,arg1,arg2,arg3); } +void getRect(QRect* obj,int * arg0,int * arg1,int * arg2,int * arg3) const {obj->getRect(arg0,arg1,arg2,arg3); } +void setCoords(QRect* obj,int arg0,int arg1,int arg2,int arg3) {obj->setCoords(arg0,arg1,arg2,arg3); } +void getCoords(QRect* obj,int * arg0,int * arg1,int * arg2,int * arg3) const {obj->getCoords(arg0,arg1,arg2,arg3); } +void adjust(QRect* obj,int arg0,int arg1,int arg2,int arg3) {obj->adjust(arg0,arg1,arg2,arg3); } +QRect adjusted(QRect* obj,int arg0,int arg1,int arg2,int arg3) const {return obj->adjusted(arg0,arg1,arg2,arg3); } +QSize size(QRect* obj) const {return obj->size(); } +int width(QRect* obj) const {return obj->width(); } +int height(QRect* obj) const {return obj->height(); } +void setWidth(QRect* obj,int arg0) {obj->setWidth(arg0); } +void setHeight(QRect* obj,int arg0) {obj->setHeight(arg0); } +void setSize(QRect* obj,const QSize & arg0) {obj->setSize(arg0); } +bool contains(QRect* obj,const QPoint & arg0,bool arg1) const {return obj->contains(arg0,arg1); } +bool contains(QRect* obj,const QPoint & arg0) const {return obj->contains(arg0); } +bool contains(QRect* obj,int arg0,int arg1) const {return obj->contains(arg0,arg1); } +bool contains(QRect* obj,int arg0,int arg1,bool arg2) const {return obj->contains(arg0,arg1,arg2); } +bool contains(QRect* obj,const QRect & arg0,bool arg1) const {return obj->contains(arg0,arg1); } +bool contains(QRect* obj,const QRect & arg0) const {return obj->contains(arg0); } +QRect unite(QRect* obj,const QRect & arg0) const {return obj->unite(arg0); } +QRect united(QRect* obj,const QRect & arg0) const {return obj->united(arg0); } +QRect intersect(QRect* obj,const QRect & arg0) const {return obj->intersect(arg0); } +QRect intersected(QRect* obj,const QRect & arg0) const {return obj->intersected(arg0); } +bool intersects(QRect* obj,const QRect & arg0) const {return obj->intersects(arg0); } + +}; + +class PythonQtQRectFWrapper : public QObject { + Q_OBJECT + +public: +public slots: +QVariant new_QRectF() { return QRectF(); } +QVariant new_QRectF(const QPointF & arg0,const QSizeF & arg1) { return QRectF(arg0,arg1); } +QVariant new_QRectF(qreal arg0,qreal arg1,qreal arg2,qreal arg3) { return QRectF(arg0,arg1,arg2,arg3); } +QVariant new_QRectF(const QRect & arg0) { return QRectF(arg0); } +bool isNull(QRectF* obj) const {return obj->isNull(); } +bool isEmpty(QRectF* obj) const {return obj->isEmpty(); } +bool isValid(QRectF* obj) const {return obj->isValid(); } +QRectF normalized(QRectF* obj) const {return obj->normalized(); } +qreal left(QRectF* obj) const {return obj->left(); } +qreal top(QRectF* obj) const {return obj->top(); } +qreal right(QRectF* obj) const {return obj->right(); } +qreal bottom(QRectF* obj) const {return obj->bottom(); } +qreal x(QRectF* obj) const {return obj->x(); } +qreal y(QRectF* obj) const {return obj->y(); } +void setLeft(QRectF* obj,qreal arg0) {obj->setLeft(arg0); } +void setTop(QRectF* obj,qreal arg0) {obj->setTop(arg0); } +void setRight(QRectF* obj,qreal arg0) {obj->setRight(arg0); } +void setBottom(QRectF* obj,qreal arg0) {obj->setBottom(arg0); } +void setX(QRectF* obj,qreal arg0) {obj->setX(arg0); } +void setY(QRectF* obj,qreal arg0) {obj->setY(arg0); } +QPointF topLeft(QRectF* obj) const {return obj->topLeft(); } +QPointF bottomRight(QRectF* obj) const {return obj->bottomRight(); } +QPointF topRight(QRectF* obj) const {return obj->topRight(); } +QPointF bottomLeft(QRectF* obj) const {return obj->bottomLeft(); } +QPointF center(QRectF* obj) const {return obj->center(); } +void setTopLeft(QRectF* obj,const QPointF & arg0) {obj->setTopLeft(arg0); } +void setBottomRight(QRectF* obj,const QPointF & arg0) {obj->setBottomRight(arg0); } +void setTopRight(QRectF* obj,const QPointF & arg0) {obj->setTopRight(arg0); } +void setBottomLeft(QRectF* obj,const QPointF & arg0) {obj->setBottomLeft(arg0); } +void moveLeft(QRectF* obj,qreal arg0) {obj->moveLeft(arg0); } +void moveTop(QRectF* obj,qreal arg0) {obj->moveTop(arg0); } +void moveRight(QRectF* obj,qreal arg0) {obj->moveRight(arg0); } +void moveBottom(QRectF* obj,qreal arg0) {obj->moveBottom(arg0); } +void moveTopLeft(QRectF* obj,const QPointF & arg0) {obj->moveTopLeft(arg0); } +void moveBottomRight(QRectF* obj,const QPointF & arg0) {obj->moveBottomRight(arg0); } +void moveTopRight(QRectF* obj,const QPointF & arg0) {obj->moveTopRight(arg0); } +void moveBottomLeft(QRectF* obj,const QPointF & arg0) {obj->moveBottomLeft(arg0); } +void moveCenter(QRectF* obj,const QPointF & arg0) {obj->moveCenter(arg0); } +void translate(QRectF* obj,qreal arg0,qreal arg1) {obj->translate(arg0,arg1); } +void translate(QRectF* obj,const QPointF & arg0) {obj->translate(arg0); } +QRectF translated(QRectF* obj,qreal arg0,qreal arg1) const {return obj->translated(arg0,arg1); } +QRectF translated(QRectF* obj,const QPointF & arg0) const {return obj->translated(arg0); } +void moveTo(QRectF* obj,qreal arg0,qreal arg1) {obj->moveTo(arg0,arg1); } +void moveTo(QRectF* obj,const QPointF & arg0) {obj->moveTo(arg0); } +void setRect(QRectF* obj,qreal arg0,qreal arg1,qreal arg2,qreal arg3) {obj->setRect(arg0,arg1,arg2,arg3); } +void getRect(QRectF* obj,qreal * arg0,qreal * arg1,qreal * arg2,qreal * arg3) const {obj->getRect(arg0,arg1,arg2,arg3); } +void setCoords(QRectF* obj,qreal arg0,qreal arg1,qreal arg2,qreal arg3) {obj->setCoords(arg0,arg1,arg2,arg3); } +void getCoords(QRectF* obj,qreal * arg0,qreal * arg1,qreal * arg2,qreal * arg3) const {obj->getCoords(arg0,arg1,arg2,arg3); } +void adjust(QRectF* obj,qreal arg0,qreal arg1,qreal arg2,qreal arg3) {obj->adjust(arg0,arg1,arg2,arg3); } +QRectF adjusted(QRectF* obj,qreal arg0,qreal arg1,qreal arg2,qreal arg3) const {return obj->adjusted(arg0,arg1,arg2,arg3); } +QSizeF size(QRectF* obj) const {return obj->size(); } +qreal width(QRectF* obj) const {return obj->width(); } +qreal height(QRectF* obj) const {return obj->height(); } +void setWidth(QRectF* obj,qreal arg0) {obj->setWidth(arg0); } +void setHeight(QRectF* obj,qreal arg0) {obj->setHeight(arg0); } +void setSize(QRectF* obj,const QSizeF & arg0) {obj->setSize(arg0); } +bool contains(QRectF* obj,const QPointF & arg0) const {return obj->contains(arg0); } +bool contains(QRectF* obj,qreal arg0,qreal arg1) const {return obj->contains(arg0,arg1); } +bool contains(QRectF* obj,const QRectF & arg0) const {return obj->contains(arg0); } +QRectF unite(QRectF* obj,const QRectF & arg0) const {return obj->unite(arg0); } +QRectF united(QRectF* obj,const QRectF & arg0) const {return obj->united(arg0); } +QRectF intersect(QRectF* obj,const QRectF & arg0) const {return obj->intersect(arg0); } +QRectF intersected(QRectF* obj,const QRectF & arg0) const {return obj->intersected(arg0); } +bool intersects(QRectF* obj,const QRectF & arg0) const {return obj->intersects(arg0); } +QRect toRect(QRectF* obj) const {return obj->toRect(); } + +}; + +/**************************************************************************** +** Meta object code from reading C++ file 'qsize.h' +** +** Created: Thu 12. Apr 14:07:28 2007 +** by: The Qt Meta Object Compiler version 59 (Qt 4.2.3) +** +** WARNING! All changes made in this file will be lost! +*****************************************************************************/ + +#include "qsize.h" +class PythonQtQSizeWrapper : public QObject { + Q_OBJECT + +public: +public slots: +QVariant new_QSize() { return QSize(); } +QVariant new_QSize(int arg0,int arg1) { return QSize(arg0,arg1); } +bool isNull(QSize* obj) const {return obj->isNull(); } +bool isEmpty(QSize* obj) const {return obj->isEmpty(); } +bool isValid(QSize* obj) const {return obj->isValid(); } +int width(QSize* obj) const {return obj->width(); } +int height(QSize* obj) const {return obj->height(); } +void setWidth(QSize* obj,int arg0) {obj->setWidth(arg0); } +void setHeight(QSize* obj,int arg0) {obj->setHeight(arg0); } +void transpose(QSize* obj) {obj->transpose(); } +void scale(QSize* obj,int arg0,int arg1,Qt::AspectRatioMode arg2) {obj->scale(arg0,arg1,arg2); } +void scale(QSize* obj,const QSize & arg0,Qt::AspectRatioMode arg1) {obj->scale(arg0,arg1); } +QSize expandedTo(QSize* obj,const QSize & arg0) const {return obj->expandedTo(arg0); } +QSize boundedTo(QSize* obj,const QSize & arg0) const {return obj->boundedTo(arg0); } +void rwidth(QSize* obj) {obj->rwidth(); } +void rheight(QSize* obj) {obj->rheight(); } + +}; + +class PythonQtQSizeFWrapper : public QObject { + Q_OBJECT + +public: +public slots: +QVariant new_QSizeF() { return QSizeF(); } +QVariant new_QSizeF(const QSize & arg0) { return QSizeF(arg0); } +QVariant new_QSizeF(qreal arg0,qreal arg1) { return QSizeF(arg0,arg1); } +bool isNull(QSizeF* obj) const {return obj->isNull(); } +bool isEmpty(QSizeF* obj) const {return obj->isEmpty(); } +bool isValid(QSizeF* obj) const {return obj->isValid(); } +qreal width(QSizeF* obj) const {return obj->width(); } +qreal height(QSizeF* obj) const {return obj->height(); } +void setWidth(QSizeF* obj,qreal arg0) {obj->setWidth(arg0); } +void setHeight(QSizeF* obj,qreal arg0) {obj->setHeight(arg0); } +void transpose(QSizeF* obj) {obj->transpose(); } +void scale(QSizeF* obj,qreal arg0,qreal arg1,Qt::AspectRatioMode arg2) {obj->scale(arg0,arg1,arg2); } +void scale(QSizeF* obj,const QSizeF & arg0,Qt::AspectRatioMode arg1) {obj->scale(arg0,arg1); } +QSizeF expandedTo(QSizeF* obj,const QSizeF & arg0) const {return obj->expandedTo(arg0); } +QSizeF boundedTo(QSizeF* obj,const QSizeF & arg0) const {return obj->boundedTo(arg0); } +void rwidth(QSizeF* obj) {obj->rwidth(); } +void rheight(QSizeF* obj) {obj->rheight(); } +QSize toSize(QSizeF* obj) const {return obj->toSize(); } + +}; + +/**************************************************************************** +** Meta object code from reading C++ file 'qline.h' +** +** Created: Thu 12. Apr 14:07:28 2007 +** by: The Qt Meta Object Compiler version 59 (Qt 4.2.3) +** +** WARNING! All changes made in this file will be lost! +*****************************************************************************/ + +#include "qline.h" +class PythonQtQLineWrapper : public QObject { + Q_OBJECT + +public: +public slots: +QVariant new_QLine() { return QLine(); } +QVariant new_QLine(const QPoint & arg0,const QPoint & arg1) { return QLine(arg0,arg1); } +QVariant new_QLine(int arg0,int arg1,int arg2,int arg3) { return QLine(arg0,arg1,arg2,arg3); } +bool isNull(QLine* obj) const {return obj->isNull(); } +QPoint p1(QLine* obj) const {return obj->p1(); } +QPoint p2(QLine* obj) const {return obj->p2(); } +int x1(QLine* obj) const {return obj->x1(); } +int y1(QLine* obj) const {return obj->y1(); } +int x2(QLine* obj) const {return obj->x2(); } +int y2(QLine* obj) const {return obj->y2(); } +int dx(QLine* obj) const {return obj->dx(); } +int dy(QLine* obj) const {return obj->dy(); } +void translate(QLine* obj,const QPoint & arg0) {obj->translate(arg0); } +void translate(QLine* obj,int arg0,int arg1) {obj->translate(arg0,arg1); } + +}; + +class PythonQtQLineFWrapper : public QObject { + Q_OBJECT + +public: +Q_ENUMS(IntersectType ) +enum IntersectType {NoIntersection = QLineF::NoIntersection, +BoundedIntersection = QLineF::BoundedIntersection, +UnboundedIntersection = QLineF::UnboundedIntersection }; +public slots: +QVariant new_QLineF() { return QLineF(); } +QVariant new_QLineF(const QPointF & arg0,const QPointF & arg1) { return QLineF(arg0,arg1); } +QVariant new_QLineF(qreal arg0,qreal arg1,qreal arg2,qreal arg3) { return QLineF(arg0,arg1,arg2,arg3); } +QVariant new_QLineF(const QLine & arg0) { return QLineF(arg0); } +int isNull(QLineF* obj) const {return obj->isNull(); } +QPointF p1(QLineF* obj) const {return obj->p1(); } +QPointF p2(QLineF* obj) const {return obj->p2(); } +qreal x1(QLineF* obj) const {return obj->x1(); } +qreal y1(QLineF* obj) const {return obj->y1(); } +qreal x2(QLineF* obj) const {return obj->x2(); } +qreal y2(QLineF* obj) const {return obj->y2(); } +qreal dx(QLineF* obj) const {return obj->dx(); } +qreal dy(QLineF* obj) const {return obj->dy(); } +qreal length(QLineF* obj) const {return obj->length(); } +void setLength(QLineF* obj,qreal arg0) {obj->setLength(arg0); } +QLineF unitVector(QLineF* obj) const {return obj->unitVector(); } +QLineF normalVector(QLineF* obj) const {return obj->normalVector(); } +IntersectType intersect(QLineF* obj,const QLineF & arg0,QPointF * arg1) const {return (PythonQtQLineFWrapper::IntersectType)obj->intersect(arg0,arg1); } +qreal angle(QLineF* obj,const QLineF & arg0) const {return obj->angle(arg0); } +QPointF pointAt(QLineF* obj,qreal arg0) const {return obj->pointAt(arg0); } +void translate(QLineF* obj,const QPointF & arg0) {obj->translate(arg0); } +void translate(QLineF* obj,qreal arg0,qreal arg1) {obj->translate(arg0,arg1); } +QLine toLine(QLineF* obj) const {return obj->toLine(); } + +}; + +/**************************************************************************** +** Meta object code from reading C++ file 'qpoint.h' +** +** Created: Thu 12. Apr 14:07:28 2007 +** by: The Qt Meta Object Compiler version 59 (Qt 4.2.3) +** +** WARNING! All changes made in this file will be lost! +*****************************************************************************/ + +#include "qpoint.h" +class PythonQtQPointWrapper : public QObject { + Q_OBJECT + +public: +public slots: +QVariant new_QPoint() { return QPoint(); } +QVariant new_QPoint(int arg0,int arg1) { return QPoint(arg0,arg1); } +bool isNull(QPoint* obj) const {return obj->isNull(); } +int x(QPoint* obj) const {return obj->x(); } +int y(QPoint* obj) const {return obj->y(); } +void setX(QPoint* obj,int arg0) {obj->setX(arg0); } +void setY(QPoint* obj,int arg0) {obj->setY(arg0); } +int manhattanLength(QPoint* obj) const {return obj->manhattanLength(); } +void rx(QPoint* obj) {obj->rx(); } +void ry(QPoint* obj) {obj->ry(); } + +}; + +class PythonQtQPointFWrapper : public QObject { + Q_OBJECT + +public: +public slots: +QVariant new_QPointF() { return QPointF(); } +QVariant new_QPointF(const QPoint & arg0) { return QPointF(arg0); } +QVariant new_QPointF(qreal arg0,qreal arg1) { return QPointF(arg0,arg1); } +bool isNull(QPointF* obj) const {return obj->isNull(); } +qreal x(QPointF* obj) const {return obj->x(); } +qreal y(QPointF* obj) const {return obj->y(); } +void setX(QPointF* obj,qreal arg0) {obj->setX(arg0); } +void setY(QPointF* obj,qreal arg0) {obj->setY(arg0); } +void rx(QPointF* obj) {obj->rx(); } +void ry(QPointF* obj) {obj->ry(); } +QPoint toPoint(QPointF* obj) const {return obj->toPoint(); } + +}; + +/**************************************************************************** +** Meta object code from reading C++ file 'qregexp.h' +** +** Created: Thu 12. Apr 14:07:29 2007 +** by: The Qt Meta Object Compiler version 59 (Qt 4.2.3) +** +** WARNING! All changes made in this file will be lost! +*****************************************************************************/ + +#include "qregexp.h" +class PythonQtQRegExpWrapper : public QObject { + Q_OBJECT + +public: +Q_ENUMS(PatternSyntax CaretMode ) +enum PatternSyntax {RegExp = QRegExp::RegExp, +Wildcard = QRegExp::Wildcard, +FixedString = QRegExp::FixedString, +RegExp2 = QRegExp::RegExp2 }; +enum CaretMode {CaretAtZero = QRegExp::CaretAtZero, +CaretAtOffset = QRegExp::CaretAtOffset, +CaretWontMatch = QRegExp::CaretWontMatch }; +public slots: +QVariant new_QRegExp() { return QRegExp(); } +QVariant new_QRegExp(const QString & arg0,Qt::CaseSensitivity arg1,PatternSyntax arg2) { return QRegExp(arg0,arg1,(QRegExp::PatternSyntax)arg2); } +QVariant new_QRegExp(const QString & arg0,Qt::CaseSensitivity arg1) { return QRegExp(arg0,arg1); } +QVariant new_QRegExp(const QString & arg0) { return QRegExp(arg0); } +QVariant new_QRegExp(const QRegExp & arg0) { return QRegExp(arg0); } +bool isEmpty(QRegExp* obj) const {return obj->isEmpty(); } +bool isValid(QRegExp* obj) const {return obj->isValid(); } +QString pattern(QRegExp* obj) const {return obj->pattern(); } +void setPattern(QRegExp* obj,const QString & arg0) {obj->setPattern(arg0); } +Qt::CaseSensitivity caseSensitivity(QRegExp* obj) const {return obj->caseSensitivity(); } +void setCaseSensitivity(QRegExp* obj,Qt::CaseSensitivity arg0) {obj->setCaseSensitivity(arg0); } +PatternSyntax patternSyntax(QRegExp* obj) const {return (PythonQtQRegExpWrapper::PatternSyntax)obj->patternSyntax(); } +void setPatternSyntax(QRegExp* obj,PatternSyntax arg0) {obj->setPatternSyntax((QRegExp::PatternSyntax)arg0); } +bool isMinimal(QRegExp* obj) const {return obj->isMinimal(); } +void setMinimal(QRegExp* obj,bool arg0) {obj->setMinimal(arg0); } +bool exactMatch(QRegExp* obj,const QString & arg0) const {return obj->exactMatch(arg0); } +int indexIn(QRegExp* obj,const QString & arg0,int arg1,CaretMode arg2) const {return obj->indexIn(arg0,arg1,(QRegExp::CaretMode)arg2); } +int indexIn(QRegExp* obj,const QString & arg0,int arg1) const {return obj->indexIn(arg0,arg1); } +int indexIn(QRegExp* obj,const QString & arg0) const {return obj->indexIn(arg0); } +int lastIndexIn(QRegExp* obj,const QString & arg0,int arg1,CaretMode arg2) const {return obj->lastIndexIn(arg0,arg1,(QRegExp::CaretMode)arg2); } +int lastIndexIn(QRegExp* obj,const QString & arg0,int arg1) const {return obj->lastIndexIn(arg0,arg1); } +int lastIndexIn(QRegExp* obj,const QString & arg0) const {return obj->lastIndexIn(arg0); } +int matchedLength(QRegExp* obj) const {return obj->matchedLength(); } +int numCaptures(QRegExp* obj) const {return obj->numCaptures(); } +QStringList capturedTexts(QRegExp* obj) {return obj->capturedTexts(); } +QString cap(QRegExp* obj,int arg0) {return obj->cap(arg0); } +QString cap(QRegExp* obj) {return obj->cap(); } +int pos(QRegExp* obj,int arg0) {return obj->pos(arg0); } +int pos(QRegExp* obj) {return obj->pos(); } +QString errorString(QRegExp* obj) {return obj->errorString(); } +QString static_QRegExp_escape(const QString & arg0) {return QRegExp::escape(arg0); } + +}; + +/**************************************************************************** +** Meta object code from reading C++ file 'qfont.h' +** +** Created: Thu 12. Apr 14:07:29 2007 +** by: The Qt Meta Object Compiler version 59 (Qt 4.2.3) +** +** WARNING! All changes made in this file will be lost! +*****************************************************************************/ + +#include "qfont.h" +class PythonQtQFontWrapper : public QObject { + Q_OBJECT + +public: +Q_ENUMS(StyleHint StyleStrategy Weight Style Stretch ) +enum StyleHint {Helvetica = QFont::Helvetica, +SansSerif = QFont::SansSerif, +Times = QFont::Times, +Serif = QFont::Serif, +Courier = QFont::Courier, +TypeWriter = QFont::TypeWriter, +OldEnglish = QFont::OldEnglish, +Decorative = QFont::Decorative, +System = QFont::System, +AnyStyle = QFont::AnyStyle }; +enum StyleStrategy {PreferDefault = QFont::PreferDefault, +PreferBitmap = QFont::PreferBitmap, +PreferDevice = QFont::PreferDevice, +PreferOutline = QFont::PreferOutline, +ForceOutline = QFont::ForceOutline, +PreferMatch = QFont::PreferMatch, +PreferQuality = QFont::PreferQuality, +PreferAntialias = QFont::PreferAntialias, +NoAntialias = QFont::NoAntialias, +OpenGLCompatible = QFont::OpenGLCompatible, +NoFontMerging = QFont::NoFontMerging }; +enum Weight {Light = QFont::Light, +Normal = QFont::Normal, +DemiBold = QFont::DemiBold, +Bold = QFont::Bold, +Black = QFont::Black }; +enum Style {StyleNormal = QFont::StyleNormal, +StyleItalic = QFont::StyleItalic, +StyleOblique = QFont::StyleOblique }; +enum Stretch {UltraCondensed = QFont::UltraCondensed, +ExtraCondensed = QFont::ExtraCondensed, +Condensed = QFont::Condensed, +SemiCondensed = QFont::SemiCondensed, +Unstretched = QFont::Unstretched, +SemiExpanded = QFont::SemiExpanded, +Expanded = QFont::Expanded, +ExtraExpanded = QFont::ExtraExpanded, +UltraExpanded = QFont::UltraExpanded }; +public slots: +QVariant new_QFont() { return QFont(); } +QVariant new_QFont(const QString & arg0,int arg1,int arg2,bool arg3) { return QFont(arg0,arg1,arg2,arg3); } +QVariant new_QFont(const QString & arg0,int arg1,int arg2) { return QFont(arg0,arg1,arg2); } +QVariant new_QFont(const QString & arg0,int arg1) { return QFont(arg0,arg1); } +QVariant new_QFont(const QString & arg0) { return QFont(arg0); } +QVariant new_QFont(const QFont & arg0,QPaintDevice * arg1) { return QFont(arg0,arg1); } +QVariant new_QFont(const QFont & arg0) { return QFont(arg0); } +QString family(QFont* obj) const {return obj->family(); } +void setFamily(QFont* obj,const QString & arg0) {obj->setFamily(arg0); } +int pointSize(QFont* obj) const {return obj->pointSize(); } +void setPointSize(QFont* obj,int arg0) {obj->setPointSize(arg0); } +qreal pointSizeF(QFont* obj) const {return obj->pointSizeF(); } +void setPointSizeF(QFont* obj,qreal arg0) {obj->setPointSizeF(arg0); } +int pixelSize(QFont* obj) const {return obj->pixelSize(); } +void setPixelSize(QFont* obj,int arg0) {obj->setPixelSize(arg0); } +int weight(QFont* obj) const {return obj->weight(); } +void setWeight(QFont* obj,int arg0) {obj->setWeight(arg0); } +bool bold(QFont* obj) const {return obj->bold(); } +void setBold(QFont* obj,bool arg0) {obj->setBold(arg0); } +void setStyle(QFont* obj,Style arg0) {obj->setStyle((QFont::Style)arg0); } +Style style(QFont* obj) const {return (PythonQtQFontWrapper::Style)obj->style(); } +bool italic(QFont* obj) const {return obj->italic(); } +void setItalic(QFont* obj,bool arg0) {obj->setItalic(arg0); } +bool underline(QFont* obj) const {return obj->underline(); } +void setUnderline(QFont* obj,bool arg0) {obj->setUnderline(arg0); } +bool overline(QFont* obj) const {return obj->overline(); } +void setOverline(QFont* obj,bool arg0) {obj->setOverline(arg0); } +bool strikeOut(QFont* obj) const {return obj->strikeOut(); } +void setStrikeOut(QFont* obj,bool arg0) {obj->setStrikeOut(arg0); } +bool fixedPitch(QFont* obj) const {return obj->fixedPitch(); } +void setFixedPitch(QFont* obj,bool arg0) {obj->setFixedPitch(arg0); } +bool kerning(QFont* obj) const {return obj->kerning(); } +void setKerning(QFont* obj,bool arg0) {obj->setKerning(arg0); } +StyleHint styleHint(QFont* obj) const {return (PythonQtQFontWrapper::StyleHint)obj->styleHint(); } +StyleStrategy styleStrategy(QFont* obj) const {return (PythonQtQFontWrapper::StyleStrategy)obj->styleStrategy(); } +void setStyleHint(QFont* obj,StyleHint arg0,StyleStrategy arg1) {obj->setStyleHint((QFont::StyleHint)arg0,(QFont::StyleStrategy)arg1); } +void setStyleHint(QFont* obj,StyleHint arg0) {obj->setStyleHint((QFont::StyleHint)arg0); } +void setStyleStrategy(QFont* obj,StyleStrategy arg0) {obj->setStyleStrategy((QFont::StyleStrategy)arg0); } +int stretch(QFont* obj) const {return obj->stretch(); } +void setStretch(QFont* obj,int arg0) {obj->setStretch(arg0); } +bool rawMode(QFont* obj) const {return obj->rawMode(); } +void setRawMode(QFont* obj,bool arg0) {obj->setRawMode(arg0); } +bool exactMatch(QFont* obj) const {return obj->exactMatch(); } +bool isCopyOf(QFont* obj,const QFont & arg0) const {return obj->isCopyOf(arg0); } +Qt::HANDLE handle(QFont* obj) const {return obj->handle(); } +void setRawName(QFont* obj,const QString & arg0) {obj->setRawName(arg0); } +QString rawName(QFont* obj) const {return obj->rawName(); } +QString key(QFont* obj) const {return obj->key(); } +QString toString(QFont* obj) const {return obj->toString(); } +bool fromString(QFont* obj,const QString & arg0) {return obj->fromString(arg0); } +QString static_QFont_substitute(const QString & arg0) {return QFont::substitute(arg0); } +QStringList static_QFont_substitutes(const QString & arg0) {return QFont::substitutes(arg0); } +QStringList static_QFont_substitutions() {return QFont::substitutions(); } +void static_QFont_insertSubstitution(const QString & arg0,const QString & arg1) {QFont::insertSubstitution(arg0,arg1); } +void static_QFont_insertSubstitutions(const QString & arg0,const QStringList & arg1) {QFont::insertSubstitutions(arg0,arg1); } +void static_QFont_removeSubstitution(const QString & arg0) {QFont::removeSubstitution(arg0); } +void static_QFont_initialize() {QFont::initialize(); } +void static_QFont_cleanup() {QFont::cleanup(); } +void static_QFont_cacheStatistics() {QFont::cacheStatistics(); } +QString defaultFamily(QFont* obj) const {return obj->defaultFamily(); } +QString lastResortFamily(QFont* obj) const {return obj->lastResortFamily(); } +QString lastResortFont(QFont* obj) const {return obj->lastResortFont(); } +QFont resolve(QFont* obj,const QFont & arg0) const {return obj->resolve(arg0); } +uint resolve(QFont* obj) const {return obj->resolve(); } +void resolve(QFont* obj,uint arg0) {obj->resolve(arg0); } + +}; + +/**************************************************************************** +** Meta object code from reading C++ file 'qpixmap.h' +** +** Created: Thu 12. Apr 14:07:29 2007 +** by: The Qt Meta Object Compiler version 59 (Qt 4.2.3) +** +** WARNING! All changes made in this file will be lost! +*****************************************************************************/ + +#include "qpixmap.h" +class PythonQtQPixmapWrapper : public QObject { + Q_OBJECT + +public: +public slots: +QVariant new_QPixmap() { return QPixmap(); } +QVariant new_QPixmap(int arg0,int arg1) { return QPixmap(arg0,arg1); } +QVariant new_QPixmap(const QSize & arg0) { return QPixmap(arg0); } +QVariant new_QPixmap(const QString & arg0,const char * arg1,Qt::ImageConversionFlags arg2) { return QPixmap(arg0,arg1,arg2); } +QVariant new_QPixmap(const QString & arg0,const char * arg1) { return QPixmap(arg0,arg1); } +QVariant new_QPixmap(const QString & arg0) { return QPixmap(arg0); } +QVariant new_QPixmap(const QPixmap & arg0) { return QPixmap(arg0); } +bool isNull(QPixmap* obj) const {return obj->isNull(); } +int devType(QPixmap* obj) const {return obj->devType(); } +int width(QPixmap* obj) const {return obj->width(); } +int height(QPixmap* obj) const {return obj->height(); } +QSize size(QPixmap* obj) const {return obj->size(); } +QRect rect(QPixmap* obj) const {return obj->rect(); } +int depth(QPixmap* obj) const {return obj->depth(); } +int static_QPixmap_defaultDepth() {return QPixmap::defaultDepth(); } +void fill(QPixmap* obj,const QColor & arg0) {obj->fill(arg0); } +void fill(QPixmap* obj) {obj->fill(); } +void fill(QPixmap* obj,const QWidget * arg0,const QPoint & arg1) {obj->fill(arg0,arg1); } +void fill(QPixmap* obj,const QWidget * arg0,int arg1,int arg2) {obj->fill(arg0,arg1,arg2); } +QBitmap mask(QPixmap* obj) const {return obj->mask(); } +void setMask(QPixmap* obj,const QBitmap & arg0) {obj->setMask(arg0); } +QPixmap alphaChannel(QPixmap* obj) const {return obj->alphaChannel(); } +void setAlphaChannel(QPixmap* obj,const QPixmap & arg0) {obj->setAlphaChannel(arg0); } +bool hasAlpha(QPixmap* obj) const {return obj->hasAlpha(); } +bool hasAlphaChannel(QPixmap* obj) const {return obj->hasAlphaChannel(); } +QBitmap createHeuristicMask(QPixmap* obj,bool arg0) const {return obj->createHeuristicMask(arg0); } +QBitmap createHeuristicMask(QPixmap* obj) const {return obj->createHeuristicMask(); } +QBitmap createMaskFromColor(QPixmap* obj,const QColor & arg0) const {return obj->createMaskFromColor(arg0); } +QPixmap static_QPixmap_grabWindow(WId arg0,int arg1,int arg2,int arg3,int arg4) {return QPixmap::grabWindow(arg0,arg1,arg2,arg3,arg4); } +QPixmap static_QPixmap_grabWindow(WId arg0,int arg1,int arg2,int arg3) {return QPixmap::grabWindow(arg0,arg1,arg2,arg3); } +QPixmap static_QPixmap_grabWindow(WId arg0,int arg1,int arg2) {return QPixmap::grabWindow(arg0,arg1,arg2); } +QPixmap static_QPixmap_grabWindow(WId arg0,int arg1) {return QPixmap::grabWindow(arg0,arg1); } +QPixmap static_QPixmap_grabWindow(WId arg0) {return QPixmap::grabWindow(arg0); } +QPixmap static_QPixmap_grabWidget(QWidget * arg0,const QRect & arg1) {return QPixmap::grabWidget(arg0,arg1); } +QPixmap grabWidget(QPixmap* obj,QWidget * arg0,int arg1,int arg2,int arg3,int arg4) {return obj->grabWidget(arg0,arg1,arg2,arg3,arg4); } +QPixmap grabWidget(QPixmap* obj,QWidget * arg0,int arg1,int arg2,int arg3) {return obj->grabWidget(arg0,arg1,arg2,arg3); } +QPixmap grabWidget(QPixmap* obj,QWidget * arg0,int arg1,int arg2) {return obj->grabWidget(arg0,arg1,arg2); } +QPixmap grabWidget(QPixmap* obj,QWidget * arg0,int arg1) {return obj->grabWidget(arg0,arg1); } +QPixmap grabWidget(QPixmap* obj,QWidget * arg0) {return obj->grabWidget(arg0); } +QPixmap scaled(QPixmap* obj,int arg0,int arg1,Qt::AspectRatioMode arg2,Qt::TransformationMode arg3) const {return obj->scaled(arg0,arg1,arg2,arg3); } +QPixmap scaled(QPixmap* obj,int arg0,int arg1,Qt::AspectRatioMode arg2) const {return obj->scaled(arg0,arg1,arg2); } +QPixmap scaled(QPixmap* obj,int arg0,int arg1) const {return obj->scaled(arg0,arg1); } +QPixmap scaled(QPixmap* obj,const QSize & arg0,Qt::AspectRatioMode arg1,Qt::TransformationMode arg2) const {return obj->scaled(arg0,arg1,arg2); } +QPixmap scaled(QPixmap* obj,const QSize & arg0,Qt::AspectRatioMode arg1) const {return obj->scaled(arg0,arg1); } +QPixmap scaled(QPixmap* obj,const QSize & arg0) const {return obj->scaled(arg0); } +QPixmap scaledToWidth(QPixmap* obj,int arg0,Qt::TransformationMode arg1) const {return obj->scaledToWidth(arg0,arg1); } +QPixmap scaledToWidth(QPixmap* obj,int arg0) const {return obj->scaledToWidth(arg0); } +QPixmap scaledToHeight(QPixmap* obj,int arg0,Qt::TransformationMode arg1) const {return obj->scaledToHeight(arg0,arg1); } +QPixmap scaledToHeight(QPixmap* obj,int arg0) const {return obj->scaledToHeight(arg0); } +QPixmap transformed(QPixmap* obj,const QMatrix & arg0,Qt::TransformationMode arg1) const {return obj->transformed(arg0,arg1); } +QPixmap transformed(QPixmap* obj,const QMatrix & arg0) const {return obj->transformed(arg0); } +QMatrix static_QPixmap_trueMatrix(const QMatrix & arg0,int arg1,int arg2) {return QPixmap::trueMatrix(arg0,arg1,arg2); } +QImage toImage(QPixmap* obj) const {return obj->toImage(); } +QPixmap static_QPixmap_fromImage(const QImage & arg0,Qt::ImageConversionFlags arg1) {return QPixmap::fromImage(arg0,arg1); } +QPixmap static_QPixmap_fromImage(const QImage & arg0) {return QPixmap::fromImage(arg0); } +bool load(QPixmap* obj,const QString & arg0,const char * arg1,Qt::ImageConversionFlags arg2) {return obj->load(arg0,arg1,arg2); } +bool load(QPixmap* obj,const QString & arg0,const char * arg1) {return obj->load(arg0,arg1); } +bool load(QPixmap* obj,const QString & arg0) {return obj->load(arg0); } +bool loadFromData(QPixmap* obj,const uchar * arg0,uint arg1,const char * arg2,Qt::ImageConversionFlags arg3) {return obj->loadFromData(arg0,arg1,arg2,arg3); } +bool loadFromData(QPixmap* obj,const uchar * arg0,uint arg1,const char * arg2) {return obj->loadFromData(arg0,arg1,arg2); } +bool loadFromData(QPixmap* obj,const uchar * arg0,uint arg1) {return obj->loadFromData(arg0,arg1); } +bool loadFromData(QPixmap* obj,const QByteArray & arg0,const char * arg1,Qt::ImageConversionFlags arg2) {return obj->loadFromData(arg0,arg1,arg2); } +bool loadFromData(QPixmap* obj,const QByteArray & arg0,const char * arg1) {return obj->loadFromData(arg0,arg1); } +bool loadFromData(QPixmap* obj,const QByteArray & arg0) {return obj->loadFromData(arg0); } +bool save(QPixmap* obj,const QString & arg0,const char * arg1,int arg2) const {return obj->save(arg0,arg1,arg2); } +bool save(QPixmap* obj,const QString & arg0,const char * arg1) const {return obj->save(arg0,arg1); } +bool save(QPixmap* obj,const QString & arg0) const {return obj->save(arg0); } +bool save(QPixmap* obj,QIODevice * arg0,const char * arg1,int arg2) const {return obj->save(arg0,arg1,arg2); } +bool save(QPixmap* obj,QIODevice * arg0,const char * arg1) const {return obj->save(arg0,arg1); } +bool save(QPixmap* obj,QIODevice * arg0) const {return obj->save(arg0); } +QPixmap copy(QPixmap* obj,int arg0,int arg1,int arg2,int arg3) const {return obj->copy(arg0,arg1,arg2,arg3); } +QPixmap copy(QPixmap* obj,const QRect & arg0) const {return obj->copy(arg0); } +QPixmap copy(QPixmap* obj) const {return obj->copy(); } +int serialNumber(QPixmap* obj) const {return obj->serialNumber(); } +bool isDetached(QPixmap* obj) const {return obj->isDetached(); } +void detach(QPixmap* obj) {obj->detach(); } +bool isQBitmap(QPixmap* obj) const {return obj->isQBitmap(); } +QPaintEngine* paintEngine(QPixmap* obj) const {return obj->paintEngine(); } + +}; + +/**************************************************************************** +** Meta object code from reading C++ file 'qbrush.h' +** +** Created: Thu 12. Apr 14:07:29 2007 +** by: The Qt Meta Object Compiler version 59 (Qt 4.2.3) +** +** WARNING! All changes made in this file will be lost! +*****************************************************************************/ + +#include "qbrush.h" +class PythonQtQBrushWrapper : public QObject { + Q_OBJECT + +public: +public slots: +QVariant new_QBrush() { return QBrush(); } +QVariant new_QBrush(Qt::BrushStyle arg0) { return QBrush(arg0); } +QVariant new_QBrush(const QColor & arg0,Qt::BrushStyle arg1) { return QBrush(arg0,arg1); } +QVariant new_QBrush(const QColor & arg0) { return QBrush(arg0); } +QVariant new_QBrush(Qt::GlobalColor arg0,Qt::BrushStyle arg1) { return QBrush(arg0,arg1); } +QVariant new_QBrush(Qt::GlobalColor arg0) { return QBrush(arg0); } +QVariant new_QBrush(const QColor & arg0,const QPixmap & arg1) { return QBrush(arg0,arg1); } +QVariant new_QBrush(Qt::GlobalColor arg0,const QPixmap & arg1) { return QBrush(arg0,arg1); } +QVariant new_QBrush(const QPixmap & arg0) { return QBrush(arg0); } +QVariant new_QBrush(const QImage & arg0) { return QBrush(arg0); } +QVariant new_QBrush(const QBrush & arg0) { return QBrush(arg0); } +QVariant new_QBrush(const QGradient & arg0) { return QBrush(arg0); } +Qt::BrushStyle style(QBrush* obj) const {return obj->style(); } +void setStyle(QBrush* obj,Qt::BrushStyle arg0) {obj->setStyle(arg0); } +void matrix(QBrush* obj) const {obj->matrix(); } +void setMatrix(QBrush* obj,const QMatrix & arg0) {obj->setMatrix(arg0); } +QPixmap texture(QBrush* obj) const {return obj->texture(); } +void setTexture(QBrush* obj,const QPixmap & arg0) {obj->setTexture(arg0); } +QImage textureImage(QBrush* obj) const {return obj->textureImage(); } +void setTextureImage(QBrush* obj,const QImage & arg0) {obj->setTextureImage(arg0); } +void color(QBrush* obj) const {obj->color(); } +void setColor(QBrush* obj,const QColor & arg0) {obj->setColor(arg0); } +void setColor(QBrush* obj,Qt::GlobalColor arg0) {obj->setColor(arg0); } +const QGradient* gradient(QBrush* obj) const {return obj->gradient(); } +bool isOpaque(QBrush* obj) const {return obj->isOpaque(); } + +}; + +class PythonQtQBrushDataWrapper : public QObject { + Q_OBJECT + +public: +public slots: +void delete_QBrushData(QBrushData* obj) { delete obj; } + +}; + +class PythonQtQGradientWrapper : public QObject { + Q_OBJECT + +public: +Q_ENUMS(Type Spread CoordinateMode ) +enum Type {LinearGradient = QGradient::LinearGradient, +RadialGradient = QGradient::RadialGradient, +ConicalGradient = QGradient::ConicalGradient, +NoGradient = QGradient::NoGradient }; +enum Spread {PadSpread = QGradient::PadSpread, +ReflectSpread = QGradient::ReflectSpread, +RepeatSpread = QGradient::RepeatSpread }; +enum CoordinateMode {LogicalMode = QGradient::LogicalMode, +StretchToDeviceMode = QGradient::StretchToDeviceMode }; +public slots: +void delete_QGradient(QGradient* obj) { delete obj; } +QGradient* new_QGradient() { return new QGradient(); } +Type type(QGradient* obj) const {return (PythonQtQGradientWrapper::Type)obj->type(); } +void setSpread(QGradient* obj,Spread arg0) {obj->setSpread((QGradient::Spread)arg0); } +Spread spread(QGradient* obj) const {return (PythonQtQGradientWrapper::Spread)obj->spread(); } +void setColorAt(QGradient* obj,qreal arg0,const QColor & arg1) {obj->setColorAt(arg0,arg1); } +void setStops(QGradient* obj,const QGradientStops & arg0) {obj->setStops(arg0); } +QGradientStops stops(QGradient* obj) const {return obj->stops(); } +CoordinateMode coordinateMode(QGradient* obj) const {return (PythonQtQGradientWrapper::CoordinateMode)obj->coordinateMode(); } +void setCoordinateMode(QGradient* obj,CoordinateMode arg0) {obj->setCoordinateMode((QGradient::CoordinateMode)arg0); } + +}; + +class PythonQtQLinearGradientWrapper : public QObject { + Q_OBJECT + +public: +public slots: +void delete_QLinearGradient(QLinearGradient* obj) { delete obj; } +QLinearGradient* new_QLinearGradient() { return new QLinearGradient(); } +QLinearGradient* new_QLinearGradient(const QPointF & arg0,const QPointF & arg1) { return new QLinearGradient(arg0,arg1); } +QLinearGradient* new_QLinearGradient(qreal arg0,qreal arg1,qreal arg2,qreal arg3) { return new QLinearGradient(arg0,arg1,arg2,arg3); } +QPointF start(QLinearGradient* obj) const {return obj->start(); } +void setStart(QLinearGradient* obj,const QPointF & arg0) {obj->setStart(arg0); } +void setStart(QLinearGradient* obj,qreal arg0,qreal arg1) {obj->setStart(arg0,arg1); } +QPointF finalStop(QLinearGradient* obj) const {return obj->finalStop(); } +void setFinalStop(QLinearGradient* obj,const QPointF & arg0) {obj->setFinalStop(arg0); } +void setFinalStop(QLinearGradient* obj,qreal arg0,qreal arg1) {obj->setFinalStop(arg0,arg1); } + +}; + +class PythonQtQRadialGradientWrapper : public QObject { + Q_OBJECT + +public: +public slots: +void delete_QRadialGradient(QRadialGradient* obj) { delete obj; } +QRadialGradient* new_QRadialGradient() { return new QRadialGradient(); } +QRadialGradient* new_QRadialGradient(const QPointF & arg0,qreal arg1,const QPointF & arg2) { return new QRadialGradient(arg0,arg1,arg2); } +QRadialGradient* new_QRadialGradient(qreal arg0,qreal arg1,qreal arg2,qreal arg3,qreal arg4) { return new QRadialGradient(arg0,arg1,arg2,arg3,arg4); } +QRadialGradient* new_QRadialGradient(const QPointF & arg0,qreal arg1) { return new QRadialGradient(arg0,arg1); } +QRadialGradient* new_QRadialGradient(qreal arg0,qreal arg1,qreal arg2) { return new QRadialGradient(arg0,arg1,arg2); } +QPointF center(QRadialGradient* obj) const {return obj->center(); } +void setCenter(QRadialGradient* obj,const QPointF & arg0) {obj->setCenter(arg0); } +void setCenter(QRadialGradient* obj,qreal arg0,qreal arg1) {obj->setCenter(arg0,arg1); } +QPointF focalPoint(QRadialGradient* obj) const {return obj->focalPoint(); } +void setFocalPoint(QRadialGradient* obj,const QPointF & arg0) {obj->setFocalPoint(arg0); } +void setFocalPoint(QRadialGradient* obj,qreal arg0,qreal arg1) {obj->setFocalPoint(arg0,arg1); } +qreal radius(QRadialGradient* obj) const {return obj->radius(); } +void setRadius(QRadialGradient* obj,qreal arg0) {obj->setRadius(arg0); } + +}; + +class PythonQtQConicalGradientWrapper : public QObject { + Q_OBJECT + +public: +public slots: +void delete_QConicalGradient(QConicalGradient* obj) { delete obj; } +QConicalGradient* new_QConicalGradient() { return new QConicalGradient(); } +QConicalGradient* new_QConicalGradient(const QPointF & arg0,qreal arg1) { return new QConicalGradient(arg0,arg1); } +QConicalGradient* new_QConicalGradient(qreal arg0,qreal arg1,qreal arg2) { return new QConicalGradient(arg0,arg1,arg2); } +QPointF center(QConicalGradient* obj) const {return obj->center(); } +void setCenter(QConicalGradient* obj,const QPointF & arg0) {obj->setCenter(arg0); } +void setCenter(QConicalGradient* obj,qreal arg0,qreal arg1) {obj->setCenter(arg0,arg1); } +qreal angle(QConicalGradient* obj) const {return obj->angle(); } +void setAngle(QConicalGradient* obj,qreal arg0) {obj->setAngle(arg0); } + +}; + +/**************************************************************************** +** Meta object code from reading C++ file 'qcolor.h' +** +** Created: Thu 12. Apr 14:07:30 2007 +** by: The Qt Meta Object Compiler version 59 (Qt 4.2.3) +** +** WARNING! All changes made in this file will be lost! +*****************************************************************************/ + +#include "qcolor.h" +class PythonQtQColorWrapper : public QObject { + Q_OBJECT + +public: +Q_ENUMS(Spec ) +enum Spec {Invalid = QColor::Invalid, +Rgb = QColor::Rgb, +Hsv = QColor::Hsv, +Cmyk = QColor::Cmyk }; +public slots: +QVariant new_QColor() { return QColor(); } +QVariant new_QColor(Qt::GlobalColor arg0) { return QColor(arg0); } +QVariant new_QColor(int arg0,int arg1,int arg2,int arg3) { return QColor(arg0,arg1,arg2,arg3); } +QVariant new_QColor(int arg0,int arg1,int arg2) { return QColor(arg0,arg1,arg2); } +QVariant new_QColor(QRgb arg0) { return QColor(arg0); } +QVariant new_QColor(const QString & arg0) { return QColor(arg0); } +QVariant new_QColor(const char * arg0) { return QColor(arg0); } +QVariant new_QColor(const QColor & arg0) { return QColor(arg0); } +QVariant new_QColor(Spec arg0) { return QColor((QColor::Spec)arg0); } +bool isValid(QColor* obj) const {return obj->isValid(); } +QString name(QColor* obj) const {return obj->name(); } +void setNamedColor(QColor* obj,const QString & arg0) {obj->setNamedColor(arg0); } +QStringList static_QColor_colorNames() {return QColor::colorNames(); } +Spec spec(QColor* obj) const {return (PythonQtQColorWrapper::Spec)obj->spec(); } +int alpha(QColor* obj) const {return obj->alpha(); } +void setAlpha(QColor* obj,int arg0) {obj->setAlpha(arg0); } +qreal alphaF(QColor* obj) const {return obj->alphaF(); } +void setAlphaF(QColor* obj,qreal arg0) {obj->setAlphaF(arg0); } +int red(QColor* obj) const {return obj->red(); } +int green(QColor* obj) const {return obj->green(); } +int blue(QColor* obj) const {return obj->blue(); } +void setRed(QColor* obj,int arg0) {obj->setRed(arg0); } +void setGreen(QColor* obj,int arg0) {obj->setGreen(arg0); } +void setBlue(QColor* obj,int arg0) {obj->setBlue(arg0); } +qreal redF(QColor* obj) const {return obj->redF(); } +qreal greenF(QColor* obj) const {return obj->greenF(); } +qreal blueF(QColor* obj) const {return obj->blueF(); } +void setRedF(QColor* obj,qreal arg0) {obj->setRedF(arg0); } +void setGreenF(QColor* obj,qreal arg0) {obj->setGreenF(arg0); } +void setBlueF(QColor* obj,qreal arg0) {obj->setBlueF(arg0); } +void getRgb(QColor* obj,int * arg0,int * arg1,int * arg2,int * arg3) const {obj->getRgb(arg0,arg1,arg2,arg3); } +void getRgb(QColor* obj,int * arg0,int * arg1,int * arg2) const {obj->getRgb(arg0,arg1,arg2); } +void setRgb(QColor* obj,int arg0,int arg1,int arg2,int arg3) {obj->setRgb(arg0,arg1,arg2,arg3); } +void setRgb(QColor* obj,int arg0,int arg1,int arg2) {obj->setRgb(arg0,arg1,arg2); } +void getRgbF(QColor* obj,qreal * arg0,qreal * arg1,qreal * arg2,qreal * arg3) const {obj->getRgbF(arg0,arg1,arg2,arg3); } +void getRgbF(QColor* obj,qreal * arg0,qreal * arg1,qreal * arg2) const {obj->getRgbF(arg0,arg1,arg2); } +void setRgbF(QColor* obj,qreal arg0,qreal arg1,qreal arg2,qreal arg3) {obj->setRgbF(arg0,arg1,arg2,arg3); } +void setRgbF(QColor* obj,qreal arg0,qreal arg1,qreal arg2) {obj->setRgbF(arg0,arg1,arg2); } +QRgb rgba(QColor* obj) const {return obj->rgba(); } +void setRgba(QColor* obj,QRgb arg0) {obj->setRgba(arg0); } +QRgb rgb(QColor* obj) const {return obj->rgb(); } +void setRgb(QColor* obj,QRgb arg0) {obj->setRgb(arg0); } +int hue(QColor* obj) const {return obj->hue(); } +int saturation(QColor* obj) const {return obj->saturation(); } +int value(QColor* obj) const {return obj->value(); } +qreal hueF(QColor* obj) const {return obj->hueF(); } +qreal saturationF(QColor* obj) const {return obj->saturationF(); } +qreal valueF(QColor* obj) const {return obj->valueF(); } +void getHsv(QColor* obj,int * arg0,int * arg1,int * arg2,int * arg3) const {obj->getHsv(arg0,arg1,arg2,arg3); } +void getHsv(QColor* obj,int * arg0,int * arg1,int * arg2) const {obj->getHsv(arg0,arg1,arg2); } +void setHsv(QColor* obj,int arg0,int arg1,int arg2,int arg3) {obj->setHsv(arg0,arg1,arg2,arg3); } +void setHsv(QColor* obj,int arg0,int arg1,int arg2) {obj->setHsv(arg0,arg1,arg2); } +void getHsvF(QColor* obj,qreal * arg0,qreal * arg1,qreal * arg2,qreal * arg3) const {obj->getHsvF(arg0,arg1,arg2,arg3); } +void getHsvF(QColor* obj,qreal * arg0,qreal * arg1,qreal * arg2) const {obj->getHsvF(arg0,arg1,arg2); } +void setHsvF(QColor* obj,qreal arg0,qreal arg1,qreal arg2,qreal arg3) {obj->setHsvF(arg0,arg1,arg2,arg3); } +void setHsvF(QColor* obj,qreal arg0,qreal arg1,qreal arg2) {obj->setHsvF(arg0,arg1,arg2); } +int cyan(QColor* obj) const {return obj->cyan(); } +int magenta(QColor* obj) const {return obj->magenta(); } +int yellow(QColor* obj) const {return obj->yellow(); } +int black(QColor* obj) const {return obj->black(); } +qreal cyanF(QColor* obj) const {return obj->cyanF(); } +qreal magentaF(QColor* obj) const {return obj->magentaF(); } +qreal yellowF(QColor* obj) const {return obj->yellowF(); } +qreal blackF(QColor* obj) const {return obj->blackF(); } +void getCmyk(QColor* obj,int * arg0,int * arg1,int * arg2,int * arg3,int * arg4) {obj->getCmyk(arg0,arg1,arg2,arg3,arg4); } +void getCmyk(QColor* obj,int * arg0,int * arg1,int * arg2,int * arg3) {obj->getCmyk(arg0,arg1,arg2,arg3); } +void setCmyk(QColor* obj,int arg0,int arg1,int arg2,int arg3,int arg4) {obj->setCmyk(arg0,arg1,arg2,arg3,arg4); } +void setCmyk(QColor* obj,int arg0,int arg1,int arg2,int arg3) {obj->setCmyk(arg0,arg1,arg2,arg3); } +void getCmykF(QColor* obj,qreal * arg0,qreal * arg1,qreal * arg2,qreal * arg3,qreal * arg4) {obj->getCmykF(arg0,arg1,arg2,arg3,arg4); } +void getCmykF(QColor* obj,qreal * arg0,qreal * arg1,qreal * arg2,qreal * arg3) {obj->getCmykF(arg0,arg1,arg2,arg3); } +void setCmykF(QColor* obj,qreal arg0,qreal arg1,qreal arg2,qreal arg3,qreal arg4) {obj->setCmykF(arg0,arg1,arg2,arg3,arg4); } +void setCmykF(QColor* obj,qreal arg0,qreal arg1,qreal arg2,qreal arg3) {obj->setCmykF(arg0,arg1,arg2,arg3); } +QColor toRgb(QColor* obj) const {return obj->toRgb(); } +QColor toHsv(QColor* obj) const {return obj->toHsv(); } +QColor toCmyk(QColor* obj) const {return obj->toCmyk(); } +QColor convertTo(QColor* obj,Spec arg0) const {return obj->convertTo((QColor::Spec)arg0); } +QColor static_QColor_fromRgb(QRgb arg0) {return QColor::fromRgb(arg0); } +QColor static_QColor_fromRgba(QRgb arg0) {return QColor::fromRgba(arg0); } +QColor static_QColor_fromRgb(int arg0,int arg1,int arg2,int arg3) {return QColor::fromRgb(arg0,arg1,arg2,arg3); } +QColor static_QColor_fromRgb(int arg0,int arg1,int arg2) {return QColor::fromRgb(arg0,arg1,arg2); } +QColor static_QColor_fromRgbF(qreal arg0,qreal arg1,qreal arg2,qreal arg3) {return QColor::fromRgbF(arg0,arg1,arg2,arg3); } +QColor static_QColor_fromRgbF(qreal arg0,qreal arg1,qreal arg2) {return QColor::fromRgbF(arg0,arg1,arg2); } +QColor static_QColor_fromHsv(int arg0,int arg1,int arg2,int arg3) {return QColor::fromHsv(arg0,arg1,arg2,arg3); } +QColor static_QColor_fromHsv(int arg0,int arg1,int arg2) {return QColor::fromHsv(arg0,arg1,arg2); } +QColor static_QColor_fromHsvF(qreal arg0,qreal arg1,qreal arg2,qreal arg3) {return QColor::fromHsvF(arg0,arg1,arg2,arg3); } +QColor static_QColor_fromHsvF(qreal arg0,qreal arg1,qreal arg2) {return QColor::fromHsvF(arg0,arg1,arg2); } +QColor static_QColor_fromCmyk(int arg0,int arg1,int arg2,int arg3,int arg4) {return QColor::fromCmyk(arg0,arg1,arg2,arg3,arg4); } +QColor static_QColor_fromCmyk(int arg0,int arg1,int arg2,int arg3) {return QColor::fromCmyk(arg0,arg1,arg2,arg3); } +QColor static_QColor_fromCmykF(qreal arg0,qreal arg1,qreal arg2,qreal arg3,qreal arg4) {return QColor::fromCmykF(arg0,arg1,arg2,arg3,arg4); } +QColor static_QColor_fromCmykF(qreal arg0,qreal arg1,qreal arg2,qreal arg3) {return QColor::fromCmykF(arg0,arg1,arg2,arg3); } +QColor light(QColor* obj,int arg0) const {return obj->light(arg0); } +QColor light(QColor* obj) const {return obj->light(); } +QColor dark(QColor* obj,int arg0) const {return obj->dark(arg0); } +QColor dark(QColor* obj) const {return obj->dark(); } + +}; + +/**************************************************************************** +** Meta object code from reading C++ file 'qpalette.h' +** +** Created: Thu 12. Apr 14:07:30 2007 +** by: The Qt Meta Object Compiler version 59 (Qt 4.2.3) +** +** WARNING! All changes made in this file will be lost! +*****************************************************************************/ + +#include "qpalette.h" +class PythonQtQPaletteWrapper : public QObject { + Q_OBJECT + +public: +Q_ENUMS(ColorGroup ColorRole ) +enum ColorGroup {Active = QPalette::Active, +Disabled = QPalette::Disabled, +Inactive = QPalette::Inactive, +NColorGroups = QPalette::NColorGroups, +Current = QPalette::Current, +All = QPalette::All, +Normal = QPalette::Normal }; +enum ColorRole {WindowText = QPalette::WindowText, +Button = QPalette::Button, +Light = QPalette::Light, +Midlight = QPalette::Midlight, +Dark = QPalette::Dark, +Mid = QPalette::Mid, +Text = QPalette::Text, +BrightText = QPalette::BrightText, +ButtonText = QPalette::ButtonText, +Base = QPalette::Base, +Window = QPalette::Window, +Shadow = QPalette::Shadow, +Highlight = QPalette::Highlight, +HighlightedText = QPalette::HighlightedText, +Link = QPalette::Link, +LinkVisited = QPalette::LinkVisited, +AlternateBase = QPalette::AlternateBase, +NoRole = QPalette::NoRole, +NColorRoles = QPalette::NColorRoles, +Foreground = QPalette::Foreground, +Background = QPalette::Background }; +public slots: +QVariant new_QPalette() { return QPalette(); } +QVariant new_QPalette(const QColor & arg0) { return QPalette(arg0); } +QVariant new_QPalette(Qt::GlobalColor arg0) { return QPalette(arg0); } +QVariant new_QPalette(const QColor & arg0,const QColor & arg1) { return QPalette(arg0,arg1); } +QVariant new_QPalette(const QBrush & arg0,const QBrush & arg1,const QBrush & arg2,const QBrush & arg3,const QBrush & arg4,const QBrush & arg5,const QBrush & arg6,const QBrush & arg7,const QBrush & arg8) { return QPalette(arg0,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8); } +QVariant new_QPalette(const QColor & arg0,const QColor & arg1,const QColor & arg2,const QColor & arg3,const QColor & arg4,const QColor & arg5,const QColor & arg6) { return QPalette(arg0,arg1,arg2,arg3,arg4,arg5,arg6); } +QVariant new_QPalette(const QPalette & arg0) { return QPalette(arg0); } +ColorGroup currentColorGroup(QPalette* obj) const {return (PythonQtQPaletteWrapper::ColorGroup)obj->currentColorGroup(); } +void setCurrentColorGroup(QPalette* obj,ColorGroup arg0) {obj->setCurrentColorGroup((QPalette::ColorGroup)arg0); } +void color(QPalette* obj,ColorGroup arg0,ColorRole arg1) const {obj->color((QPalette::ColorGroup)arg0,(QPalette::ColorRole)arg1); } +void brush(QPalette* obj,ColorGroup arg0,ColorRole arg1) const {obj->brush((QPalette::ColorGroup)arg0,(QPalette::ColorRole)arg1); } +void setColor(QPalette* obj,ColorGroup arg0,ColorRole arg1,const QColor & arg2) {obj->setColor((QPalette::ColorGroup)arg0,(QPalette::ColorRole)arg1,arg2); } +void setColor(QPalette* obj,ColorRole arg0,const QColor & arg1) {obj->setColor((QPalette::ColorRole)arg0,arg1); } +void setBrush(QPalette* obj,ColorRole arg0,const QBrush & arg1) {obj->setBrush((QPalette::ColorRole)arg0,arg1); } +bool isBrushSet(QPalette* obj,ColorGroup arg0,ColorRole arg1) const {return obj->isBrushSet((QPalette::ColorGroup)arg0,(QPalette::ColorRole)arg1); } +void setBrush(QPalette* obj,ColorGroup arg0,ColorRole arg1,const QBrush & arg2) {obj->setBrush((QPalette::ColorGroup)arg0,(QPalette::ColorRole)arg1,arg2); } +void setColorGroup(QPalette* obj,ColorGroup arg0,const QBrush & arg1,const QBrush & arg2,const QBrush & arg3,const QBrush & arg4,const QBrush & arg5,const QBrush & arg6,const QBrush & arg7,const QBrush & arg8,const QBrush & arg9) {obj->setColorGroup((QPalette::ColorGroup)arg0,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9); } +bool isEqual(QPalette* obj,ColorGroup arg0,ColorGroup arg1) const {return obj->isEqual((QPalette::ColorGroup)arg0,(QPalette::ColorGroup)arg1); } +void color(QPalette* obj,ColorRole arg0) const {obj->color((QPalette::ColorRole)arg0); } +void brush(QPalette* obj,ColorRole arg0) const {obj->brush((QPalette::ColorRole)arg0); } +void foreground(QPalette* obj) const {obj->foreground(); } +void windowText(QPalette* obj) const {obj->windowText(); } +void button(QPalette* obj) const {obj->button(); } +void light(QPalette* obj) const {obj->light(); } +void dark(QPalette* obj) const {obj->dark(); } +void mid(QPalette* obj) const {obj->mid(); } +void text(QPalette* obj) const {obj->text(); } +void base(QPalette* obj) const {obj->base(); } +void alternateBase(QPalette* obj) const {obj->alternateBase(); } +void background(QPalette* obj) const {obj->background(); } +void window(QPalette* obj) const {obj->window(); } +void midlight(QPalette* obj) const {obj->midlight(); } +void brightText(QPalette* obj) const {obj->brightText(); } +void buttonText(QPalette* obj) const {obj->buttonText(); } +void shadow(QPalette* obj) const {obj->shadow(); } +void highlight(QPalette* obj) const {obj->highlight(); } +void highlightedText(QPalette* obj) const {obj->highlightedText(); } +void link(QPalette* obj) const {obj->link(); } +void linkVisited(QPalette* obj) const {obj->linkVisited(); } +bool isCopyOf(QPalette* obj,const QPalette & arg0) const {return obj->isCopyOf(arg0); } +int serialNumber(QPalette* obj) const {return obj->serialNumber(); } +QPalette resolve(QPalette* obj,const QPalette & arg0) const {return obj->resolve(arg0); } +uint resolve(QPalette* obj) const {return obj->resolve(); } +void resolve(QPalette* obj,uint arg0) {obj->resolve(arg0); } + +}; + +/**************************************************************************** +** Meta object code from reading C++ file 'qicon.h' +** +** Created: Thu 12. Apr 14:07:30 2007 +** by: The Qt Meta Object Compiler version 59 (Qt 4.2.3) +** +** WARNING! All changes made in this file will be lost! +*****************************************************************************/ + +#include "qicon.h" +class PythonQtQIconWrapper : public QObject { + Q_OBJECT + +public: +Q_ENUMS(Mode State ) +enum Mode {Normal = QIcon::Normal, +Disabled = QIcon::Disabled, +Active = QIcon::Active, +Selected = QIcon::Selected }; +enum State {On = QIcon::On, +Off = QIcon::Off }; +public slots: +QVariant new_QIcon() { return QIcon(); } +QVariant new_QIcon(const QPixmap & arg0) { return QIcon(arg0); } +QVariant new_QIcon(const QIcon & arg0) { return QIcon(arg0); } +QVariant new_QIcon(const QString & arg0) { return QIcon(arg0); } +QVariant new_QIcon(QIconEngine * arg0) { return QIcon(arg0); } +QPixmap pixmap(QIcon* obj,const QSize & arg0,Mode arg1,State arg2) const {return obj->pixmap(arg0,(QIcon::Mode)arg1,(QIcon::State)arg2); } +QPixmap pixmap(QIcon* obj,const QSize & arg0,Mode arg1) const {return obj->pixmap(arg0,(QIcon::Mode)arg1); } +QPixmap pixmap(QIcon* obj,const QSize & arg0) const {return obj->pixmap(arg0); } +QPixmap pixmap(QIcon* obj,int arg0,int arg1,Mode arg2,State arg3) const {return obj->pixmap(arg0,arg1,(QIcon::Mode)arg2,(QIcon::State)arg3); } +QPixmap pixmap(QIcon* obj,int arg0,int arg1,Mode arg2) const {return obj->pixmap(arg0,arg1,(QIcon::Mode)arg2); } +QPixmap pixmap(QIcon* obj,int arg0,int arg1) const {return obj->pixmap(arg0,arg1); } +QPixmap pixmap(QIcon* obj,int arg0,Mode arg1,State arg2) const {return obj->pixmap(arg0,(QIcon::Mode)arg1,(QIcon::State)arg2); } +QPixmap pixmap(QIcon* obj,int arg0,Mode arg1) const {return obj->pixmap(arg0,(QIcon::Mode)arg1); } +QPixmap pixmap(QIcon* obj,int arg0) const {return obj->pixmap(arg0); } +QSize actualSize(QIcon* obj,const QSize & arg0,Mode arg1,State arg2) const {return obj->actualSize(arg0,(QIcon::Mode)arg1,(QIcon::State)arg2); } +QSize actualSize(QIcon* obj,const QSize & arg0,Mode arg1) const {return obj->actualSize(arg0,(QIcon::Mode)arg1); } +QSize actualSize(QIcon* obj,const QSize & arg0) const {return obj->actualSize(arg0); } +void paint(QIcon* obj,QPainter * arg0,const QRect & arg1,Qt::Alignment arg2,Mode arg3,State arg4) const {obj->paint(arg0,arg1,arg2,(QIcon::Mode)arg3,(QIcon::State)arg4); } +void paint(QIcon* obj,QPainter * arg0,const QRect & arg1,Qt::Alignment arg2,Mode arg3) const {obj->paint(arg0,arg1,arg2,(QIcon::Mode)arg3); } +void paint(QIcon* obj,QPainter * arg0,const QRect & arg1,Qt::Alignment arg2) const {obj->paint(arg0,arg1,arg2); } +void paint(QIcon* obj,QPainter * arg0,const QRect & arg1) const {obj->paint(arg0,arg1); } +void paint(QIcon* obj,QPainter * arg0,int arg1,int arg2,int arg3,int arg4,Qt::Alignment arg5,Mode arg6,State arg7) const {obj->paint(arg0,arg1,arg2,arg3,arg4,arg5,(QIcon::Mode)arg6,(QIcon::State)arg7); } +void paint(QIcon* obj,QPainter * arg0,int arg1,int arg2,int arg3,int arg4,Qt::Alignment arg5,Mode arg6) const {obj->paint(arg0,arg1,arg2,arg3,arg4,arg5,(QIcon::Mode)arg6); } +void paint(QIcon* obj,QPainter * arg0,int arg1,int arg2,int arg3,int arg4,Qt::Alignment arg5) const {obj->paint(arg0,arg1,arg2,arg3,arg4,arg5); } +void paint(QIcon* obj,QPainter * arg0,int arg1,int arg2,int arg3,int arg4) const {obj->paint(arg0,arg1,arg2,arg3,arg4); } +bool isNull(QIcon* obj) const {return obj->isNull(); } +bool isDetached(QIcon* obj) const {return obj->isDetached(); } +int serialNumber(QIcon* obj) const {return obj->serialNumber(); } +void addPixmap(QIcon* obj,const QPixmap & arg0,Mode arg1,State arg2) {obj->addPixmap(arg0,(QIcon::Mode)arg1,(QIcon::State)arg2); } +void addPixmap(QIcon* obj,const QPixmap & arg0,Mode arg1) {obj->addPixmap(arg0,(QIcon::Mode)arg1); } +void addPixmap(QIcon* obj,const QPixmap & arg0) {obj->addPixmap(arg0); } +void addFile(QIcon* obj,const QString & arg0,const QSize & arg1,Mode arg2,State arg3) {obj->addFile(arg0,arg1,(QIcon::Mode)arg2,(QIcon::State)arg3); } +void addFile(QIcon* obj,const QString & arg0,const QSize & arg1,Mode arg2) {obj->addFile(arg0,arg1,(QIcon::Mode)arg2); } +void addFile(QIcon* obj,const QString & arg0,const QSize & arg1) {obj->addFile(arg0,arg1); } +void addFile(QIcon* obj,const QString & arg0) {obj->addFile(arg0); } + +}; + +/**************************************************************************** +** Meta object code from reading C++ file 'qimage.h' +** +** Created: Thu 12. Apr 14:07:30 2007 +** by: The Qt Meta Object Compiler version 59 (Qt 4.2.3) +** +** WARNING! All changes made in this file will be lost! +*****************************************************************************/ + +#include "qimage.h" +class PythonQtQImageTextKeyLangWrapper : public QObject { + Q_OBJECT + +public: +public slots: +void delete_QImageTextKeyLang(QImageTextKeyLang* obj) { delete obj; } +QImageTextKeyLang* new_QImageTextKeyLang(const char * arg0,const char * arg1) { return new QImageTextKeyLang(arg0,arg1); } + +}; + +class PythonQtQImageWrapper : public QObject { + Q_OBJECT + +public: +Q_ENUMS(InvertMode Format ) +enum InvertMode {InvertRgb = QImage::InvertRgb, +InvertRgba = QImage::InvertRgba }; +enum Format {Format_Invalid = QImage::Format_Invalid, +Format_Mono = QImage::Format_Mono, +Format_MonoLSB = QImage::Format_MonoLSB, +Format_Indexed8 = QImage::Format_Indexed8, +Format_RGB32 = QImage::Format_RGB32, +Format_ARGB32 = QImage::Format_ARGB32, +Format_ARGB32_Premultiplied = QImage::Format_ARGB32_Premultiplied, +Format_RGB16 = QImage::Format_RGB16, +NImageFormats = QImage::NImageFormats }; +public slots: +QVariant new_QImage() { return QImage(); } +QVariant new_QImage(const QSize & arg0,Format arg1) { return QImage(arg0,(QImage::Format)arg1); } +QVariant new_QImage(int arg0,int arg1,Format arg2) { return QImage(arg0,arg1,(QImage::Format)arg2); } +QVariant new_QImage(uchar * arg0,int arg1,int arg2,Format arg3) { return QImage(arg0,arg1,arg2,(QImage::Format)arg3); } +QVariant new_QImage(const uchar * arg0,int arg1,int arg2,Format arg3) { return QImage(arg0,arg1,arg2,(QImage::Format)arg3); } +QVariant new_QImage(const QString & arg0,const char * arg1) { return QImage(arg0,arg1); } +QVariant new_QImage(const QString & arg0) { return QImage(arg0); } +QVariant new_QImage(const char * arg0,const char * arg1) { return QImage(arg0,arg1); } +QVariant new_QImage(const char * arg0) { return QImage(arg0); } +QVariant new_QImage(const QImage & arg0) { return QImage(arg0); } +bool isNull(QImage* obj) const {return obj->isNull(); } +int devType(QImage* obj) const {return obj->devType(); } +void detach(QImage* obj) {obj->detach(); } +bool isDetached(QImage* obj) const {return obj->isDetached(); } +QImage copy(QImage* obj,const QRect & arg0) const {return obj->copy(arg0); } +QImage copy(QImage* obj) const {return obj->copy(); } +QImage copy(QImage* obj,int arg0,int arg1,int arg2,int arg3) const {return obj->copy(arg0,arg1,arg2,arg3); } +Format format(QImage* obj) const {return (PythonQtQImageWrapper::Format)obj->format(); } +QImage convertToFormat(QImage* obj,Format arg0,Qt::ImageConversionFlags arg1) const {return obj->convertToFormat((QImage::Format)arg0,arg1); } +QImage convertToFormat(QImage* obj,Format arg0) const {return obj->convertToFormat((QImage::Format)arg0); } +QImage convertToFormat(QImage* obj,Format arg0,const QVector & arg1,Qt::ImageConversionFlags arg2) const {return obj->convertToFormat((QImage::Format)arg0,arg1,arg2); } +QImage convertToFormat(QImage* obj,Format arg0,const QVector & arg1) const {return obj->convertToFormat((QImage::Format)arg0,arg1); } +int width(QImage* obj) const {return obj->width(); } +int height(QImage* obj) const {return obj->height(); } +QSize size(QImage* obj) const {return obj->size(); } +QRect rect(QImage* obj) const {return obj->rect(); } +int depth(QImage* obj) const {return obj->depth(); } +int numColors(QImage* obj) const {return obj->numColors(); } +QRgb color(QImage* obj,int arg0) const {return obj->color(arg0); } +void setColor(QImage* obj,int arg0,QRgb arg1) {obj->setColor(arg0,arg1); } +void setNumColors(QImage* obj,int arg0) {obj->setNumColors(arg0); } +bool allGray(QImage* obj) const {return obj->allGray(); } +bool isGrayscale(QImage* obj) const {return obj->isGrayscale(); } +uchar* bits(QImage* obj) {return obj->bits(); } +const uchar* bits(QImage* obj) const {return obj->bits(); } +int numBytes(QImage* obj) const {return obj->numBytes(); } +uchar* scanLine(QImage* obj,int arg0) {return obj->scanLine(arg0); } +const uchar* scanLine(QImage* obj,int arg0) const {return obj->scanLine(arg0); } +int bytesPerLine(QImage* obj) const {return obj->bytesPerLine(); } +bool valid(QImage* obj,int arg0,int arg1) const {return obj->valid(arg0,arg1); } +bool valid(QImage* obj,const QPoint & arg0) const {return obj->valid(arg0); } +int pixelIndex(QImage* obj,int arg0,int arg1) const {return obj->pixelIndex(arg0,arg1); } +int pixelIndex(QImage* obj,const QPoint & arg0) const {return obj->pixelIndex(arg0); } +QRgb pixel(QImage* obj,int arg0,int arg1) const {return obj->pixel(arg0,arg1); } +QRgb pixel(QImage* obj,const QPoint & arg0) const {return obj->pixel(arg0); } +void setPixel(QImage* obj,int arg0,int arg1,uint arg2) {obj->setPixel(arg0,arg1,arg2); } +void setPixel(QImage* obj,const QPoint & arg0,uint arg1) {obj->setPixel(arg0,arg1); } +QVector colorTable(QImage* obj) const {return obj->colorTable(); } +void setColorTable(QImage* obj,const QVector arg0) {obj->setColorTable(arg0); } +void fill(QImage* obj,uint arg0) {obj->fill(arg0); } +bool hasAlphaChannel(QImage* obj) const {return obj->hasAlphaChannel(); } +void setAlphaChannel(QImage* obj,const QImage & arg0) {obj->setAlphaChannel(arg0); } +QImage alphaChannel(QImage* obj) const {return obj->alphaChannel(); } +QImage createAlphaMask(QImage* obj,Qt::ImageConversionFlags arg0) const {return obj->createAlphaMask(arg0); } +QImage createAlphaMask(QImage* obj) const {return obj->createAlphaMask(); } +QImage createHeuristicMask(QImage* obj,bool arg0) const {return obj->createHeuristicMask(arg0); } +QImage createHeuristicMask(QImage* obj) const {return obj->createHeuristicMask(); } +QImage scaled(QImage* obj,int arg0,int arg1,Qt::AspectRatioMode arg2,Qt::TransformationMode arg3) const {return obj->scaled(arg0,arg1,arg2,arg3); } +QImage scaled(QImage* obj,int arg0,int arg1,Qt::AspectRatioMode arg2) const {return obj->scaled(arg0,arg1,arg2); } +QImage scaled(QImage* obj,int arg0,int arg1) const {return obj->scaled(arg0,arg1); } +QImage scaled(QImage* obj,const QSize & arg0,Qt::AspectRatioMode arg1,Qt::TransformationMode arg2) const {return obj->scaled(arg0,arg1,arg2); } +QImage scaled(QImage* obj,const QSize & arg0,Qt::AspectRatioMode arg1) const {return obj->scaled(arg0,arg1); } +QImage scaled(QImage* obj,const QSize & arg0) const {return obj->scaled(arg0); } +QImage scaledToWidth(QImage* obj,int arg0,Qt::TransformationMode arg1) const {return obj->scaledToWidth(arg0,arg1); } +QImage scaledToWidth(QImage* obj,int arg0) const {return obj->scaledToWidth(arg0); } +QImage scaledToHeight(QImage* obj,int arg0,Qt::TransformationMode arg1) const {return obj->scaledToHeight(arg0,arg1); } +QImage scaledToHeight(QImage* obj,int arg0) const {return obj->scaledToHeight(arg0); } +QImage transformed(QImage* obj,const QMatrix & arg0,Qt::TransformationMode arg1) const {return obj->transformed(arg0,arg1); } +QImage transformed(QImage* obj,const QMatrix & arg0) const {return obj->transformed(arg0); } +QMatrix static_QImage_trueMatrix(const QMatrix & arg0,int arg1,int arg2) {return QImage::trueMatrix(arg0,arg1,arg2); } +QImage mirrored(QImage* obj,bool arg0,bool arg1) const {return obj->mirrored(arg0,arg1); } +QImage mirrored(QImage* obj,bool arg0) const {return obj->mirrored(arg0); } +QImage mirrored(QImage* obj) const {return obj->mirrored(); } +QImage rgbSwapped(QImage* obj) const {return obj->rgbSwapped(); } +void invertPixels(QImage* obj,InvertMode arg0) {obj->invertPixels((QImage::InvertMode)arg0); } +void invertPixels(QImage* obj) {obj->invertPixels(); } +bool load(QImage* obj,QIODevice * arg0,const char * arg1) {return obj->load(arg0,arg1); } +bool load(QImage* obj,const QString & arg0,const char * arg1) {return obj->load(arg0,arg1); } +bool load(QImage* obj,const QString & arg0) {return obj->load(arg0); } +bool loadFromData(QImage* obj,const uchar * arg0,int arg1,const char * arg2) {return obj->loadFromData(arg0,arg1,arg2); } +bool loadFromData(QImage* obj,const uchar * arg0,int arg1) {return obj->loadFromData(arg0,arg1); } +bool loadFromData(QImage* obj,const QByteArray & arg0,const char * arg1) {return obj->loadFromData(arg0,arg1); } +bool loadFromData(QImage* obj,const QByteArray & arg0) {return obj->loadFromData(arg0); } +bool save(QImage* obj,const QString & arg0,const char * arg1,int arg2) const {return obj->save(arg0,arg1,arg2); } +bool save(QImage* obj,const QString & arg0,const char * arg1) const {return obj->save(arg0,arg1); } +bool save(QImage* obj,const QString & arg0) const {return obj->save(arg0); } +bool save(QImage* obj,QIODevice * arg0,const char * arg1,int arg2) const {return obj->save(arg0,arg1,arg2); } +bool save(QImage* obj,QIODevice * arg0,const char * arg1) const {return obj->save(arg0,arg1); } +bool save(QImage* obj,QIODevice * arg0) const {return obj->save(arg0); } +QImage static_QImage_fromData(const uchar * arg0,int arg1,const char * arg2) {return QImage::fromData(arg0,arg1,arg2); } +QImage static_QImage_fromData(const uchar * arg0,int arg1) {return QImage::fromData(arg0,arg1); } +QImage static_QImage_fromData(const QByteArray & arg0,const char * arg1) {return QImage::fromData(arg0,arg1); } +QImage static_QImage_fromData(const QByteArray & arg0) {return QImage::fromData(arg0); } +int serialNumber(QImage* obj) const {return obj->serialNumber(); } +QPaintEngine* paintEngine(QImage* obj) const {return obj->paintEngine(); } +int dotsPerMeterX(QImage* obj) const {return obj->dotsPerMeterX(); } +int dotsPerMeterY(QImage* obj) const {return obj->dotsPerMeterY(); } +void setDotsPerMeterX(QImage* obj,int arg0) {obj->setDotsPerMeterX(arg0); } +void setDotsPerMeterY(QImage* obj,int arg0) {obj->setDotsPerMeterY(arg0); } +QPoint offset(QImage* obj) const {return obj->offset(); } +void setOffset(QImage* obj,const QPoint & arg0) {obj->setOffset(arg0); } +QStringList textKeys(QImage* obj) const {return obj->textKeys(); } +QString text(QImage* obj,const QString & arg0) const {return obj->text(arg0); } +QString text(QImage* obj) const {return obj->text(); } +void setText(QImage* obj,const QString & arg0,const QString & arg1) {obj->setText(arg0,arg1); } +QString text(QImage* obj,const char * arg0,const char * arg1) const {return obj->text(arg0,arg1); } +QString text(QImage* obj,const char * arg0) const {return obj->text(arg0); } +QList textList(QImage* obj) const {return obj->textList(); } +QStringList textLanguages(QImage* obj) const {return obj->textLanguages(); } +QString text(QImage* obj,const QImageTextKeyLang & arg0) const {return obj->text(arg0); } +void setText(QImage* obj,const char * arg0,const char * arg1,const QString & arg2) {obj->setText(arg0,arg1,arg2); } + +}; + +/**************************************************************************** +** Meta object code from reading C++ file 'qpolygon.h' +** +** Created: Thu 12. Apr 14:07:30 2007 +** by: The Qt Meta Object Compiler version 59 (Qt 4.2.3) +** +** WARNING! All changes made in this file will be lost! +*****************************************************************************/ + +#include "qpolygon.h" +class PythonQtQPolygonWrapper : public QObject { + Q_OBJECT + +public: +public slots: +QVariant new_QPolygon() { return QPolygon(); } +QVariant new_QPolygon(int arg0) { return QPolygon(arg0); } +QVariant new_QPolygon(const QPolygon & arg0) { return QPolygon(arg0); } +QVariant new_QPolygon(const QVector & arg0) { return QPolygon(arg0); } +QVariant new_QPolygon(int arg0,const int * arg1) { return QPolygon(arg0,arg1); } +void translate(QPolygon* obj,int arg0,int arg1) {obj->translate(arg0,arg1); } +void translate(QPolygon* obj,const QPoint & arg0) {obj->translate(arg0); } +QRect boundingRect(QPolygon* obj) const {return obj->boundingRect(); } +void point(QPolygon* obj,int arg0,int * arg1,int * arg2) const {obj->point(arg0,arg1,arg2); } +QPoint point(QPolygon* obj,int arg0) const {return obj->point(arg0); } +void setPoint(QPolygon* obj,int arg0,int arg1,int arg2) {obj->setPoint(arg0,arg1,arg2); } +void setPoint(QPolygon* obj,int arg0,const QPoint & arg1) {obj->setPoint(arg0,arg1); } + +}; + +class PythonQtQPolygonFWrapper : public QObject { + Q_OBJECT + +public: +public slots: +void delete_QPolygonF(QPolygonF* obj) { delete obj; } +QPolygonF* new_QPolygonF() { return new QPolygonF(); } +QPolygonF* new_QPolygonF(int arg0) { return new QPolygonF(arg0); } +QPolygonF* new_QPolygonF(const QPolygonF & arg0) { return new QPolygonF(arg0); } +QPolygonF* new_QPolygonF(const QVector & arg0) { return new QPolygonF(arg0); } +QPolygonF* new_QPolygonF(const QPolygon & arg0) { return new QPolygonF(arg0); } +void translate(QPolygonF* obj,qreal arg0,qreal arg1) {obj->translate(arg0,arg1); } +void translate(QPolygonF* obj,const QPointF & arg0) {obj->translate(arg0); } +QPolygon toPolygon(QPolygonF* obj) const {return obj->toPolygon(); } +bool isClosed(QPolygonF* obj) const {return obj->isClosed(); } +QRectF boundingRect(QPolygonF* obj) const {return obj->boundingRect(); } + +}; + +/**************************************************************************** +** Meta object code from reading C++ file 'qregion.h' +** +** Created: Thu 12. Apr 14:07:30 2007 +** by: The Qt Meta Object Compiler version 59 (Qt 4.2.3) +** +** WARNING! All changes made in this file will be lost! +*****************************************************************************/ + +#include "qregion.h" +class PythonQtQRegionWrapper : public QObject { + Q_OBJECT + +public: +Q_ENUMS(RegionType ) +enum RegionType {Rectangle = QRegion::Rectangle, +Ellipse = QRegion::Ellipse }; +public slots: +QVariant new_QRegion() { return QRegion(); } +QVariant new_QRegion(int arg0,int arg1,int arg2,int arg3,RegionType arg4) { return QRegion(arg0,arg1,arg2,arg3,(QRegion::RegionType)arg4); } +QVariant new_QRegion(int arg0,int arg1,int arg2,int arg3) { return QRegion(arg0,arg1,arg2,arg3); } +QVariant new_QRegion(const QRect & arg0,RegionType arg1) { return QRegion(arg0,(QRegion::RegionType)arg1); } +QVariant new_QRegion(const QRect & arg0) { return QRegion(arg0); } +QVariant new_QRegion(const QPolygon & arg0,Qt::FillRule arg1) { return QRegion(arg0,arg1); } +QVariant new_QRegion(const QPolygon & arg0) { return QRegion(arg0); } +QVariant new_QRegion(const QRegion & arg0) { return QRegion(arg0); } +QVariant new_QRegion(const QBitmap & arg0) { return QRegion(arg0); } +bool isEmpty(QRegion* obj) const {return obj->isEmpty(); } +bool contains(QRegion* obj,const QPoint & arg0) const {return obj->contains(arg0); } +bool contains(QRegion* obj,const QRect & arg0) const {return obj->contains(arg0); } +void translate(QRegion* obj,int arg0,int arg1) {obj->translate(arg0,arg1); } +void translate(QRegion* obj,const QPoint & arg0) {obj->translate(arg0); } +QRegion translated(QRegion* obj,int arg0,int arg1) const {return obj->translated(arg0,arg1); } +QRegion translated(QRegion* obj,const QPoint & arg0) const {return obj->translated(arg0); } +QRegion unite(QRegion* obj,const QRegion & arg0) const {return obj->unite(arg0); } +QRegion intersect(QRegion* obj,const QRegion & arg0) const {return obj->intersect(arg0); } +QRegion subtract(QRegion* obj,const QRegion & arg0) const {return obj->subtract(arg0); } +QRegion eor(QRegion* obj,const QRegion & arg0) const {return obj->eor(arg0); } +QRegion united(QRegion* obj,const QRegion & arg0) const {return obj->united(arg0); } +QRegion intersected(QRegion* obj,const QRegion & arg0) const {return obj->intersected(arg0); } +QRegion subtracted(QRegion* obj,const QRegion & arg0) const {return obj->subtracted(arg0); } +QRegion xored(QRegion* obj,const QRegion & arg0) const {return obj->xored(arg0); } +bool intersects(QRegion* obj,const QRegion & arg0) const {return obj->intersects(arg0); } +bool intersects(QRegion* obj,const QRect & arg0) const {return obj->intersects(arg0); } +QRect boundingRect(QRegion* obj) const {return obj->boundingRect(); } +QVector rects(QRegion* obj) const {return obj->rects(); } +void setRects(QRegion* obj,const QRect * arg0,int arg1) {obj->setRects(arg0,arg1); } + +}; + +/**************************************************************************** +** Meta object code from reading C++ file 'qbitmap.h' +** +** Created: Thu 12. Apr 14:07:31 2007 +** by: The Qt Meta Object Compiler version 59 (Qt 4.2.3) +** +** WARNING! All changes made in this file will be lost! +*****************************************************************************/ + +#include "qbitmap.h" +class PythonQtQBitmapWrapper : public QObject { + Q_OBJECT + +public: +public slots: +QVariant new_QBitmap() { return QBitmap(); } +QVariant new_QBitmap(const QPixmap & arg0) { return QBitmap(arg0); } +QVariant new_QBitmap(int arg0,int arg1) { return QBitmap(arg0,arg1); } +QVariant new_QBitmap(const QSize & arg0) { return QBitmap(arg0); } +QVariant new_QBitmap(const QString & arg0,const char * arg1) { return QBitmap(arg0,arg1); } +QVariant new_QBitmap(const QString & arg0) { return QBitmap(arg0); } +void clear(QBitmap* obj) {obj->clear(); } +QBitmap static_QBitmap_fromImage(const QImage & arg0,Qt::ImageConversionFlags arg1) {return QBitmap::fromImage(arg0,arg1); } +QBitmap static_QBitmap_fromImage(const QImage & arg0) {return QBitmap::fromImage(arg0); } +QBitmap static_QBitmap_fromData(const QSize & arg0,const uchar * arg1,QImage::Format arg2) {return QBitmap::fromData(arg0,arg1,arg2); } +QBitmap static_QBitmap_fromData(const QSize & arg0,const uchar * arg1) {return QBitmap::fromData(arg0,arg1); } +QBitmap transformed(QBitmap* obj,const QMatrix & arg0) const {return obj->transformed(arg0); } + +}; + +/**************************************************************************** +** Meta object code from reading C++ file 'qcursor.h' +** +** Created: Thu 12. Apr 14:07:31 2007 +** by: The Qt Meta Object Compiler version 59 (Qt 4.2.3) +** +** WARNING! All changes made in this file will be lost! +*****************************************************************************/ + +#include "qcursor.h" +class PythonQtQCursorWrapper : public QObject { + Q_OBJECT + +public: +public slots: +QVariant new_QCursor() { return QCursor(); } +QVariant new_QCursor(Qt::CursorShape arg0) { return QCursor(arg0); } +QVariant new_QCursor(const QBitmap & arg0,const QBitmap & arg1,int arg2,int arg3) { return QCursor(arg0,arg1,arg2,arg3); } +QVariant new_QCursor(const QBitmap & arg0,const QBitmap & arg1,int arg2) { return QCursor(arg0,arg1,arg2); } +QVariant new_QCursor(const QBitmap & arg0,const QBitmap & arg1) { return QCursor(arg0,arg1); } +QVariant new_QCursor(const QPixmap & arg0,int arg1,int arg2) { return QCursor(arg0,arg1,arg2); } +QVariant new_QCursor(const QPixmap & arg0,int arg1) { return QCursor(arg0,arg1); } +QVariant new_QCursor(const QPixmap & arg0) { return QCursor(arg0); } +QVariant new_QCursor(const QCursor & arg0) { return QCursor(arg0); } +Qt::CursorShape shape(QCursor* obj) const {return obj->shape(); } +void setShape(QCursor* obj,Qt::CursorShape arg0) {obj->setShape(arg0); } +const QBitmap* bitmap(QCursor* obj) const {return obj->bitmap(); } +const QBitmap* mask(QCursor* obj) const {return obj->mask(); } +QPixmap pixmap(QCursor* obj) const {return obj->pixmap(); } +QPoint hotSpot(QCursor* obj) const {return obj->hotSpot(); } +QPoint static_QCursor_pos() {return QCursor::pos(); } +void static_QCursor_setPos(int arg0,int arg1) {QCursor::setPos(arg0,arg1); } +void static_QCursor_setPos(const QPoint & arg0) {QCursor::setPos(arg0); } + +}; + +/**************************************************************************** +** Meta object code from reading C++ file 'qsizepolicy.h' +** +** Created: Thu 12. Apr 14:07:33 2007 +** by: The Qt Meta Object Compiler version 59 (Qt 4.2.3) +** +** WARNING! All changes made in this file will be lost! +*****************************************************************************/ + +#include "qsizepolicy.h" +class PythonQtQSizePolicyWrapper : public QObject { + Q_OBJECT + +public: +Q_ENUMS(PolicyFlag Policy ) +enum PolicyFlag {GrowFlag = QSizePolicy::GrowFlag, +ExpandFlag = QSizePolicy::ExpandFlag, +ShrinkFlag = QSizePolicy::ShrinkFlag, +IgnoreFlag = QSizePolicy::IgnoreFlag }; +enum Policy {Fixed = QSizePolicy::Fixed, +Minimum = QSizePolicy::Minimum, +Maximum = QSizePolicy::Maximum, +Preferred = QSizePolicy::Preferred, +MinimumExpanding = QSizePolicy::MinimumExpanding, +Expanding = QSizePolicy::Expanding, +Ignored = QSizePolicy::Ignored }; +public slots: +QVariant new_QSizePolicy() { return QSizePolicy(); } +Policy horizontalPolicy(QSizePolicy* obj) const {return (PythonQtQSizePolicyWrapper::Policy)obj->horizontalPolicy(); } +Policy verticalPolicy(QSizePolicy* obj) const {return (PythonQtQSizePolicyWrapper::Policy)obj->verticalPolicy(); } +void setHorizontalPolicy(QSizePolicy* obj,Policy arg0) {obj->setHorizontalPolicy((QSizePolicy::Policy)arg0); } +void setVerticalPolicy(QSizePolicy* obj,Policy arg0) {obj->setVerticalPolicy((QSizePolicy::Policy)arg0); } +Qt::Orientations expandingDirections(QSizePolicy* obj) const {return obj->expandingDirections(); } +void setHeightForWidth(QSizePolicy* obj,bool arg0) {obj->setHeightForWidth(arg0); } +bool hasHeightForWidth(QSizePolicy* obj) const {return obj->hasHeightForWidth(); } +int horizontalStretch(QSizePolicy* obj) const {return obj->horizontalStretch(); } +int verticalStretch(QSizePolicy* obj) const {return obj->verticalStretch(); } +void setHorizontalStretch(QSizePolicy* obj,uchar arg0) {obj->setHorizontalStretch(arg0); } +void setVerticalStretch(QSizePolicy* obj,uchar arg0) {obj->setVerticalStretch(arg0); } +void transpose(QSizePolicy* obj) {obj->transpose(); } + +}; + +/**************************************************************************** +** Meta object code from reading C++ file 'qkeysequence.h' +** +** Created: Thu 12. Apr 14:07:34 2007 +** by: The Qt Meta Object Compiler version 59 (Qt 4.2.3) +** +** WARNING! All changes made in this file will be lost! +*****************************************************************************/ + +#include "qkeysequence.h" +class PythonQtQKeySequenceWrapper : public QObject { + Q_OBJECT + +public: +Q_ENUMS(StandardKey SequenceMatch SequenceFormat ) +enum StandardKey {UnknownKey = QKeySequence::UnknownKey, +HelpContents = QKeySequence::HelpContents, +WhatsThis = QKeySequence::WhatsThis, +Open = QKeySequence::Open, +Close = QKeySequence::Close, +Save = QKeySequence::Save, +New = QKeySequence::New, +Delete = QKeySequence::Delete, +Cut = QKeySequence::Cut, +Copy = QKeySequence::Copy, +Paste = QKeySequence::Paste, +Undo = QKeySequence::Undo, +Redo = QKeySequence::Redo, +Back = QKeySequence::Back, +Forward = QKeySequence::Forward, +Refresh = QKeySequence::Refresh, +ZoomIn = QKeySequence::ZoomIn, +ZoomOut = QKeySequence::ZoomOut, +Print = QKeySequence::Print, +AddTab = QKeySequence::AddTab, +NextChild = QKeySequence::NextChild, +PreviousChild = QKeySequence::PreviousChild, +Find = QKeySequence::Find, +FindNext = QKeySequence::FindNext, +FindPrevious = QKeySequence::FindPrevious, +Replace = QKeySequence::Replace, +SelectAll = QKeySequence::SelectAll, +Bold = QKeySequence::Bold, +Italic = QKeySequence::Italic, +Underline = QKeySequence::Underline, +MoveToNextChar = QKeySequence::MoveToNextChar, +MoveToPreviousChar = QKeySequence::MoveToPreviousChar, +MoveToNextWord = QKeySequence::MoveToNextWord, +MoveToPreviousWord = QKeySequence::MoveToPreviousWord, +MoveToNextLine = QKeySequence::MoveToNextLine, +MoveToPreviousLine = QKeySequence::MoveToPreviousLine, +MoveToNextPage = QKeySequence::MoveToNextPage, +MoveToPreviousPage = QKeySequence::MoveToPreviousPage, +MoveToStartOfLine = QKeySequence::MoveToStartOfLine, +MoveToEndOfLine = QKeySequence::MoveToEndOfLine, +MoveToStartOfBlock = QKeySequence::MoveToStartOfBlock, +MoveToEndOfBlock = QKeySequence::MoveToEndOfBlock, +MoveToStartOfDocument = QKeySequence::MoveToStartOfDocument, +MoveToEndOfDocument = QKeySequence::MoveToEndOfDocument, +SelectNextChar = QKeySequence::SelectNextChar, +SelectPreviousChar = QKeySequence::SelectPreviousChar, +SelectNextWord = QKeySequence::SelectNextWord, +SelectPreviousWord = QKeySequence::SelectPreviousWord, +SelectNextLine = QKeySequence::SelectNextLine, +SelectPreviousLine = QKeySequence::SelectPreviousLine, +SelectNextPage = QKeySequence::SelectNextPage, +SelectPreviousPage = QKeySequence::SelectPreviousPage, +SelectStartOfLine = QKeySequence::SelectStartOfLine, +SelectEndOfLine = QKeySequence::SelectEndOfLine, +SelectStartOfBlock = QKeySequence::SelectStartOfBlock, +SelectEndOfBlock = QKeySequence::SelectEndOfBlock, +SelectStartOfDocument = QKeySequence::SelectStartOfDocument, +SelectEndOfDocument = QKeySequence::SelectEndOfDocument, +DeleteStartOfWord = QKeySequence::DeleteStartOfWord, +DeleteEndOfWord = QKeySequence::DeleteEndOfWord, +DeleteEndOfLine = QKeySequence::DeleteEndOfLine }; +enum SequenceMatch {NoMatch = QKeySequence::NoMatch, +PartialMatch = QKeySequence::PartialMatch, +ExactMatch = QKeySequence::ExactMatch }; +enum SequenceFormat {NativeText = QKeySequence::NativeText, +PortableText = QKeySequence::PortableText }; +public slots: +QVariant new_QKeySequence() { return QKeySequence(); } +QVariant new_QKeySequence(const QString & arg0) { return QKeySequence(arg0); } +QVariant new_QKeySequence(int arg0,int arg1,int arg2,int arg3) { return QKeySequence(arg0,arg1,arg2,arg3); } +QVariant new_QKeySequence(int arg0,int arg1,int arg2) { return QKeySequence(arg0,arg1,arg2); } +QVariant new_QKeySequence(int arg0,int arg1) { return QKeySequence(arg0,arg1); } +QVariant new_QKeySequence(int arg0) { return QKeySequence(arg0); } +QVariant new_QKeySequence(const QKeySequence & arg0) { return QKeySequence(arg0); } +QVariant new_QKeySequence(StandardKey arg0) { return QKeySequence((QKeySequence::StandardKey)arg0); } +uint count(QKeySequence* obj) const {return obj->count(); } +bool isEmpty(QKeySequence* obj) const {return obj->isEmpty(); } +QString toString(QKeySequence* obj,SequenceFormat arg0) const {return obj->toString((QKeySequence::SequenceFormat)arg0); } +QString toString(QKeySequence* obj) const {return obj->toString(); } +QKeySequence static_QKeySequence_fromString(const QString & arg0,SequenceFormat arg1) {return QKeySequence::fromString(arg0,(QKeySequence::SequenceFormat)arg1); } +QKeySequence static_QKeySequence_fromString(const QString & arg0) {return QKeySequence::fromString(arg0); } +SequenceMatch matches(QKeySequence* obj,const QKeySequence & arg0) const {return (PythonQtQKeySequenceWrapper::SequenceMatch)obj->matches(arg0); } +QKeySequence static_QKeySequence_mnemonic(const QString & arg0) {return QKeySequence::mnemonic(arg0); } +QList static_QKeySequence_keyBindings(StandardKey arg0) {return QKeySequence::keyBindings((QKeySequence::StandardKey)arg0); } +bool isDetached(QKeySequence* obj) const {return obj->isDetached(); } + +}; + +/**************************************************************************** +** Meta object code from reading C++ file 'qpen.h' +** +** Created: Thu 12. Apr 14:07:35 2007 +** by: The Qt Meta Object Compiler version 59 (Qt 4.2.3) +** +** WARNING! All changes made in this file will be lost! +*****************************************************************************/ + +#include "qpen.h" +class PythonQtQPenWrapper : public QObject { + Q_OBJECT + +public: +public slots: +QVariant new_QPen() { return QPen(); } +QVariant new_QPen(Qt::PenStyle arg0) { return QPen(arg0); } +QVariant new_QPen(const QColor & arg0) { return QPen(arg0); } +QVariant new_QPen(const QBrush & arg0,qreal arg1,Qt::PenStyle arg2,Qt::PenCapStyle arg3,Qt::PenJoinStyle arg4) { return QPen(arg0,arg1,arg2,arg3,arg4); } +QVariant new_QPen(const QBrush & arg0,qreal arg1,Qt::PenStyle arg2,Qt::PenCapStyle arg3) { return QPen(arg0,arg1,arg2,arg3); } +QVariant new_QPen(const QBrush & arg0,qreal arg1,Qt::PenStyle arg2) { return QPen(arg0,arg1,arg2); } +QVariant new_QPen(const QBrush & arg0,qreal arg1) { return QPen(arg0,arg1); } +QVariant new_QPen(const QPen & arg0) { return QPen(arg0); } +Qt::PenStyle style(QPen* obj) const {return obj->style(); } +void setStyle(QPen* obj,Qt::PenStyle arg0) {obj->setStyle(arg0); } +QVector dashPattern(QPen* obj) const {return obj->dashPattern(); } +void setDashPattern(QPen* obj,const QVector & arg0) {obj->setDashPattern(arg0); } +qreal miterLimit(QPen* obj) const {return obj->miterLimit(); } +void setMiterLimit(QPen* obj,qreal arg0) {obj->setMiterLimit(arg0); } +qreal widthF(QPen* obj) const {return obj->widthF(); } +void setWidthF(QPen* obj,qreal arg0) {obj->setWidthF(arg0); } +int width(QPen* obj) const {return obj->width(); } +void setWidth(QPen* obj,int arg0) {obj->setWidth(arg0); } +QColor color(QPen* obj) const {return obj->color(); } +void setColor(QPen* obj,const QColor & arg0) {obj->setColor(arg0); } +QBrush brush(QPen* obj) const {return obj->brush(); } +void setBrush(QPen* obj,const QBrush & arg0) {obj->setBrush(arg0); } +bool isSolid(QPen* obj) const {return obj->isSolid(); } +Qt::PenCapStyle capStyle(QPen* obj) const {return obj->capStyle(); } +void setCapStyle(QPen* obj,Qt::PenCapStyle arg0) {obj->setCapStyle(arg0); } +Qt::PenJoinStyle joinStyle(QPen* obj) const {return obj->joinStyle(); } +void setJoinStyle(QPen* obj,Qt::PenJoinStyle arg0) {obj->setJoinStyle(arg0); } +bool isDetached(QPen* obj) {return obj->isDetached(); } + +}; + +/**************************************************************************** +** Meta object code from reading C++ file 'qtextformat.h' +** +** Created: Thu 12. Apr 14:07:35 2007 +** by: The Qt Meta Object Compiler version 59 (Qt 4.2.3) +** +** WARNING! All changes made in this file will be lost! +*****************************************************************************/ + +#include "qtextformat.h" +class PythonQtQTextLengthWrapper : public QObject { + Q_OBJECT + +public: +Q_ENUMS(Type ) +enum Type {VariableLength = QTextLength::VariableLength, +FixedLength = QTextLength::FixedLength, +PercentageLength = QTextLength::PercentageLength }; +public slots: +QVariant new_QTextLength() { return QTextLength(); } +QVariant new_QTextLength(Type arg0,qreal arg1) { return QTextLength((QTextLength::Type)arg0,arg1); } +Type type(QTextLength* obj) const {return (PythonQtQTextLengthWrapper::Type)obj->type(); } +qreal value(QTextLength* obj,qreal arg0) const {return obj->value(arg0); } +qreal rawValue(QTextLength* obj) const {return obj->rawValue(); } + +}; + +class PythonQtQTextFormatWrapper : public QObject { + Q_OBJECT + +public: +Q_ENUMS(FormatType Property ObjectTypes PageBreakFlag ) +enum FormatType {InvalidFormat = QTextFormat::InvalidFormat, +BlockFormat = QTextFormat::BlockFormat, +CharFormat = QTextFormat::CharFormat, +ListFormat = QTextFormat::ListFormat, +TableFormat = QTextFormat::TableFormat, +FrameFormat = QTextFormat::FrameFormat, +UserFormat = QTextFormat::UserFormat }; +enum Property {ObjectIndex = QTextFormat::ObjectIndex, +CssFloat = QTextFormat::CssFloat, +LayoutDirection = QTextFormat::LayoutDirection, +OutlinePen = QTextFormat::OutlinePen, +BackgroundBrush = QTextFormat::BackgroundBrush, +ForegroundBrush = QTextFormat::ForegroundBrush, +BlockAlignment = QTextFormat::BlockAlignment, +BlockTopMargin = QTextFormat::BlockTopMargin, +BlockBottomMargin = QTextFormat::BlockBottomMargin, +BlockLeftMargin = QTextFormat::BlockLeftMargin, +BlockRightMargin = QTextFormat::BlockRightMargin, +TextIndent = QTextFormat::TextIndent, +BlockIndent = QTextFormat::BlockIndent, +BlockNonBreakableLines = QTextFormat::BlockNonBreakableLines, +BlockTrailingHorizontalRulerWidth = QTextFormat::BlockTrailingHorizontalRulerWidth, +FontFamily = QTextFormat::FontFamily, +FontPointSize = QTextFormat::FontPointSize, +FontSizeAdjustment = QTextFormat::FontSizeAdjustment, +FontSizeIncrement = QTextFormat::FontSizeIncrement, +FontWeight = QTextFormat::FontWeight, +FontItalic = QTextFormat::FontItalic, +FontUnderline = QTextFormat::FontUnderline, +FontOverline = QTextFormat::FontOverline, +FontStrikeOut = QTextFormat::FontStrikeOut, +FontFixedPitch = QTextFormat::FontFixedPitch, +FontPixelSize = QTextFormat::FontPixelSize, +TextUnderlineColor = QTextFormat::TextUnderlineColor, +TextVerticalAlignment = QTextFormat::TextVerticalAlignment, +TextOutline = QTextFormat::TextOutline, +TextUnderlineStyle = QTextFormat::TextUnderlineStyle, +IsAnchor = QTextFormat::IsAnchor, +AnchorHref = QTextFormat::AnchorHref, +AnchorName = QTextFormat::AnchorName, +ObjectType = QTextFormat::ObjectType, +ListStyle = QTextFormat::ListStyle, +ListIndent = QTextFormat::ListIndent, +FrameBorder = QTextFormat::FrameBorder, +FrameMargin = QTextFormat::FrameMargin, +FramePadding = QTextFormat::FramePadding, +FrameWidth = QTextFormat::FrameWidth, +FrameHeight = QTextFormat::FrameHeight, +TableColumns = QTextFormat::TableColumns, +TableColumnWidthConstraints = QTextFormat::TableColumnWidthConstraints, +TableCellSpacing = QTextFormat::TableCellSpacing, +TableCellPadding = QTextFormat::TableCellPadding, +TableHeaderRowCount = QTextFormat::TableHeaderRowCount, +TableCellRowSpan = QTextFormat::TableCellRowSpan, +TableCellColumnSpan = QTextFormat::TableCellColumnSpan, +ImageName = QTextFormat::ImageName, +ImageWidth = QTextFormat::ImageWidth, +ImageHeight = QTextFormat::ImageHeight, +FullWidthSelection = QTextFormat::FullWidthSelection, +PageBreakPolicy = QTextFormat::PageBreakPolicy, +UserProperty = QTextFormat::UserProperty }; +enum ObjectTypes {NoObject = QTextFormat::NoObject, +ImageObject = QTextFormat::ImageObject, +TableObject = QTextFormat::TableObject, +UserObject = QTextFormat::UserObject }; +enum PageBreakFlag {PageBreak_Auto = QTextFormat::PageBreak_Auto, +PageBreak_AlwaysBefore = QTextFormat::PageBreak_AlwaysBefore, +PageBreak_AlwaysAfter = QTextFormat::PageBreak_AlwaysAfter }; +Q_DECLARE_FLAGS(PageBreakFlags, PageBreakFlag) +public slots: +QVariant new_QTextFormat(int arg0) { return QTextFormat(arg0); } +QVariant new_QTextFormat(const QTextFormat & arg0) { return QTextFormat(arg0); } +void merge(QTextFormat* obj,const QTextFormat & arg0) {obj->merge(arg0); } +bool isValid(QTextFormat* obj) const {return obj->isValid(); } +int type(QTextFormat* obj) const {return obj->type(); } +int objectIndex(QTextFormat* obj) const {return obj->objectIndex(); } +void setObjectIndex(QTextFormat* obj,int arg0) {obj->setObjectIndex(arg0); } +QVariant property(QTextFormat* obj,int arg0) const {return obj->property(arg0); } +void setProperty(QTextFormat* obj,int arg0,const QVariant & arg1) {obj->setProperty(arg0,arg1); } +void clearProperty(QTextFormat* obj,int arg0) {obj->clearProperty(arg0); } +bool hasProperty(QTextFormat* obj,int arg0) const {return obj->hasProperty(arg0); } +bool boolProperty(QTextFormat* obj,int arg0) const {return obj->boolProperty(arg0); } +int intProperty(QTextFormat* obj,int arg0) const {return obj->intProperty(arg0); } +qreal doubleProperty(QTextFormat* obj,int arg0) const {return obj->doubleProperty(arg0); } +QString stringProperty(QTextFormat* obj,int arg0) const {return obj->stringProperty(arg0); } +QColor colorProperty(QTextFormat* obj,int arg0) const {return obj->colorProperty(arg0); } +QPen penProperty(QTextFormat* obj,int arg0) const {return obj->penProperty(arg0); } +QBrush brushProperty(QTextFormat* obj,int arg0) const {return obj->brushProperty(arg0); } +QTextLength lengthProperty(QTextFormat* obj,int arg0) const {return obj->lengthProperty(arg0); } +QVector lengthVectorProperty(QTextFormat* obj,int arg0) const {return obj->lengthVectorProperty(arg0); } +void setProperty(QTextFormat* obj,int arg0,const QVector & arg1) {obj->setProperty(arg0,arg1); } +QMap properties(QTextFormat* obj) const {return obj->properties(); } +void setObjectType(QTextFormat* obj,int arg0) {obj->setObjectType(arg0); } +int objectType(QTextFormat* obj) const {return obj->objectType(); } +bool isCharFormat(QTextFormat* obj) const {return obj->isCharFormat(); } +bool isBlockFormat(QTextFormat* obj) const {return obj->isBlockFormat(); } +bool isListFormat(QTextFormat* obj) const {return obj->isListFormat(); } +bool isFrameFormat(QTextFormat* obj) const {return obj->isFrameFormat(); } +bool isImageFormat(QTextFormat* obj) const {return obj->isImageFormat(); } +bool isTableFormat(QTextFormat* obj) const {return obj->isTableFormat(); } +QTextBlockFormat toBlockFormat(QTextFormat* obj) const {return obj->toBlockFormat(); } +QTextCharFormat toCharFormat(QTextFormat* obj) const {return obj->toCharFormat(); } +QTextListFormat toListFormat(QTextFormat* obj) const {return obj->toListFormat(); } +QTextTableFormat toTableFormat(QTextFormat* obj) const {return obj->toTableFormat(); } +QTextFrameFormat toFrameFormat(QTextFormat* obj) const {return obj->toFrameFormat(); } +QTextImageFormat toImageFormat(QTextFormat* obj) const {return obj->toImageFormat(); } +void setLayoutDirection(QTextFormat* obj,Qt::LayoutDirection arg0) {obj->setLayoutDirection(arg0); } +Qt::LayoutDirection layoutDirection(QTextFormat* obj) const {return obj->layoutDirection(); } +void setBackground(QTextFormat* obj,const QBrush & arg0) {obj->setBackground(arg0); } +QBrush background(QTextFormat* obj) const {return obj->background(); } +void clearBackground(QTextFormat* obj) {obj->clearBackground(); } +void setForeground(QTextFormat* obj,const QBrush & arg0) {obj->setForeground(arg0); } +QBrush foreground(QTextFormat* obj) const {return obj->foreground(); } +void clearForeground(QTextFormat* obj) {obj->clearForeground(); } + +}; + +/**************************************************************************** +** Meta object code from reading C++ file 'qmatrix.h' +** +** Created: Thu 12. Apr 14:07:35 2007 +** by: The Qt Meta Object Compiler version 59 (Qt 4.2.3) +** +** WARNING! All changes made in this file will be lost! +*****************************************************************************/ + +#include "qmatrix.h" +class PythonQtQMatrixWrapper : public QObject { + Q_OBJECT + +public: +public slots: +QVariant new_QMatrix() { return QMatrix(); } +QVariant new_QMatrix(qreal arg0,qreal arg1,qreal arg2,qreal arg3,qreal arg4,qreal arg5) { return QMatrix(arg0,arg1,arg2,arg3,arg4,arg5); } +QVariant new_QMatrix(const QMatrix & arg0) { return QMatrix(arg0); } +void setMatrix(QMatrix* obj,qreal arg0,qreal arg1,qreal arg2,qreal arg3,qreal arg4,qreal arg5) {obj->setMatrix(arg0,arg1,arg2,arg3,arg4,arg5); } +qreal m11(QMatrix* obj) const {return obj->m11(); } +qreal m12(QMatrix* obj) const {return obj->m12(); } +qreal m21(QMatrix* obj) const {return obj->m21(); } +qreal m22(QMatrix* obj) const {return obj->m22(); } +qreal dx(QMatrix* obj) const {return obj->dx(); } +qreal dy(QMatrix* obj) const {return obj->dy(); } +void map(QMatrix* obj,int arg0,int arg1,int * arg2,int * arg3) const {obj->map(arg0,arg1,arg2,arg3); } +void map(QMatrix* obj,qreal arg0,qreal arg1,qreal * arg2,qreal * arg3) const {obj->map(arg0,arg1,arg2,arg3); } +QRect mapRect(QMatrix* obj,const QRect & arg0) const {return obj->mapRect(arg0); } +QRectF mapRect(QMatrix* obj,const QRectF & arg0) const {return obj->mapRect(arg0); } +QPoint map(QMatrix* obj,const QPoint & arg0) const {return obj->map(arg0); } +QPointF map(QMatrix* obj,const QPointF & arg0) const {return obj->map(arg0); } +QLine map(QMatrix* obj,const QLine & arg0) const {return obj->map(arg0); } +QLineF map(QMatrix* obj,const QLineF & arg0) const {return obj->map(arg0); } +QPolygonF map(QMatrix* obj,const QPolygonF & arg0) const {return obj->map(arg0); } +QPolygon map(QMatrix* obj,const QPolygon & arg0) const {return obj->map(arg0); } +QRegion map(QMatrix* obj,const QRegion & arg0) const {return obj->map(arg0); } +QPainterPath map(QMatrix* obj,const QPainterPath & arg0) const {return obj->map(arg0); } +QPolygon mapToPolygon(QMatrix* obj,const QRect & arg0) const {return obj->mapToPolygon(arg0); } +void reset(QMatrix* obj) {obj->reset(); } +bool isIdentity(QMatrix* obj) const {return obj->isIdentity(); } +void translate(QMatrix* obj,qreal arg0,qreal arg1) {obj->translate(arg0,arg1); } +void scale(QMatrix* obj,qreal arg0,qreal arg1) {obj->scale(arg0,arg1); } +void shear(QMatrix* obj,qreal arg0,qreal arg1) {obj->shear(arg0,arg1); } +void rotate(QMatrix* obj,qreal arg0) {obj->rotate(arg0); } +bool isInvertible(QMatrix* obj) const {return obj->isInvertible(); } +qreal det(QMatrix* obj) const {return obj->det(); } +QMatrix inverted(QMatrix* obj,bool * arg0) const {return obj->inverted(arg0); } +QMatrix inverted(QMatrix* obj) const {return obj->inverted(); } + +}; + diff --git a/tests/PythonQtTest.bat b/tests/PythonQtTest.bat new file mode 100644 index 0000000..7c6f8a4 --- /dev/null +++ b/tests/PythonQtTest.bat @@ -0,0 +1,2 @@ +"%MEVIS_LIB%\make\win32\createDsp.bat" PythonQtTest + diff --git a/tests/PythonQtTestMain.cpp b/tests/PythonQtTestMain.cpp new file mode 100644 index 0000000..0c3ee42 --- /dev/null +++ b/tests/PythonQtTestMain.cpp @@ -0,0 +1,61 @@ +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtTests.cpp +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-05 +*/ +//---------------------------------------------------------------------------------- + +#include "PythonQt.h" +#include "PythonQtTests.h" + +int main( int argc, char **argv ) +{ + QApplication qapp(argc, argv); + + PythonQt::init(PythonQt::IgnoreSiteModule | PythonQt::RedirectStdOut); + + PythonQtTestApi api; + QTest::qExec(&api, argc, argv); + PythonQtTestSignalHandler signalHandler; + QTest::qExec(&signalHandler, argc, argv); + PythonQtTestSlotCalling slotCalling; + QTest::qExec(&slotCalling, argc, argv); + + PythonQt::cleanup(); + return 0; +} + diff --git a/tests/PythonQtTests.cpp b/tests/PythonQtTests.cpp new file mode 100644 index 0000000..e35d8c6 --- /dev/null +++ b/tests/PythonQtTests.cpp @@ -0,0 +1,325 @@ +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtTests.cpp +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-05 +*/ +//---------------------------------------------------------------------------------- + +#include "PythonQtTests.h" + +void PythonQtTestSlotCalling::initTestCase() +{ + _helper = new PythonQtTestSlotCallingHelper(this); + PythonQtObjectPtr main = PythonQt::self()->getMainModule(); + PythonQt::self()->addObject(main, "obj", _helper); +} + +void PythonQtTestSlotCalling::init() { + +} + +void PythonQtTestSlotCalling::testNoArgSlotCall() +{ + QVERIFY(_helper->runScript("obj.testNoArg(); obj.setPassed();\n")); +} + +void PythonQtTestSlotCalling::testOverloadedCall() +{ + QVERIFY(_helper->runScript("obj.overload(False); obj.setPassed();\n", 0)); + QVERIFY(_helper->runScript("obj.overload(True); obj.setPassed();\n", 0)); + QVERIFY(_helper->runScript("obj.overload(12.5); obj.setPassed();\n", 1)); + QVERIFY(_helper->runScript("obj.overload(12); obj.setPassed();\n", 2)); + QVERIFY(_helper->runScript("obj.overload('test'); obj.setPassed();\n", 3)); + QVERIFY(_helper->runScript("obj.overload(u'test'); obj.setPassed();\n", 3)); + QVERIFY(_helper->runScript("obj.overload(('test','test2')); obj.setPassed();\n", 4)); + QVERIFY(_helper->runScript("obj.overload(obj); obj.setPassed();\n", 5)); + QVERIFY(_helper->runScript("obj.overload(12,13); obj.setPassed();\n", 6)); +} + +void PythonQtTestSlotCalling::testPODSlotCalls() +{ + QVERIFY(_helper->runScript("if obj.getBool(False)==False: obj.setPassed();\n")); + QVERIFY(_helper->runScript("if obj.getBool(True)==True: obj.setPassed();\n")); + QVERIFY(_helper->runScript("if obj.getInt(-42)==-42: obj.setPassed();\n")); + QVERIFY(_helper->runScript("if obj.getUInt(42)==42: obj.setPassed();\n")); + QVERIFY(_helper->runScript("if obj.getShort(-43)==-43: obj.setPassed();\n")); + QVERIFY(_helper->runScript("if obj.getUShort(43)==43: obj.setPassed();\n")); + QVERIFY(_helper->runScript("if obj.getChar(-12)==-12: obj.setPassed();\n")); + QVERIFY(_helper->runScript("if obj.getUChar(12)==12: obj.setPassed();\n")); + QVERIFY(_helper->runScript("if obj.getLong(-256*256*256)==-256*256*256: obj.setPassed();\n")); + QVERIFY(_helper->runScript("if obj.getULong(256*256*256)==256*256*256: obj.setPassed();\n")); + QVERIFY(_helper->runScript("if obj.getLongLong(-42)==-42: obj.setPassed();\n")); + QVERIFY(_helper->runScript("if obj.getULongLong(42)==42: obj.setPassed();\n")); + QVERIFY(_helper->runScript("if obj.getQChar(4096)==4096: obj.setPassed();\n")); + QVERIFY(_helper->runScript("if obj.getDouble(47.12)==47.12: obj.setPassed();\n")); + QVERIFY(_helper->runScript("if abs(obj.getFloat(47.11)-47.11)<0.01: obj.setPassed();\n")); + QVERIFY(_helper->runScript("if obj.getQString('testStr')=='testStr': obj.setPassed();\n")); + QVERIFY(_helper->runScript("if obj.getQString('')=='': obj.setPassed();\n")); + QVERIFY(_helper->runScript("if obj.getQStringList(('test','test2'))==('test','test2'): obj.setPassed();\n")); +} + +void PythonQtTestSlotCalling::testQVariantSlotCalls() +{ + QVERIFY(_helper->runScript("if obj.getQVariant(-42)==-42: obj.setPassed();\n")); + QVERIFY(_helper->runScript("if obj.getQVariant('testStr')=='testStr': obj.setPassed();\n")); + QVERIFY(_helper->runScript("if obj.getQVariant(('test','test2'))==('test','test2'): obj.setPassed();\n")); + QVERIFY(_helper->runScript("if obj.getQVariant(('test',12, 47.11))==('test',12, 47.11): obj.setPassed();\n")); + QVERIFY(_helper->runScript("if obj.getQVariant({'test':'bla','test2':47.11})=={'test':'bla','test2':47.11}: obj.setPassed();\n")); + QEXPECT_FAIL("", "Testing to pass a map and compare with a different map", Continue); + QVERIFY(_helper->runScript("if obj.getQVariant({'test':'bla2','test2':47.11})=={'test':'bla','test2':47.11}: obj.setPassed();\n")); + QVERIFY(_helper->runScript("if obj.getQVariant(obj)==obj: obj.setPassed();\n")); +} + +void PythonQtTestSlotCalling::testObjectSlotCalls() +{ + QVERIFY(_helper->runScript("if obj.getQObject(obj)==obj: obj.setPassed();\n")); + QVERIFY(_helper->runScript("if obj.getTestObject(obj)==obj: obj.setPassed();\n")); + QVERIFY(_helper->runScript("if obj.getNewObject().className()=='PythonQtTestSlotCallingHelper': obj.setPassed();\n")); + QEXPECT_FAIL("", "Testing to pass a QObject when another object was expected", Continue); + QVERIFY(_helper->runScript("if obj.getQWidget(obj)==obj: obj.setPassed();\n")); +} + +void PythonQtTestSlotCalling::testCppFactory() +{ + PythonQtTestCppFactory* f = new PythonQtTestCppFactory; + PythonQt::self()->addInstanceDecorators(new PQCppObjectDecorator); + PythonQt::self()->addInstanceDecorators(new PQCppObjectNoWrapDecorator); + + PythonQt::self()->addWrapperFactory(f); + QVERIFY(_helper->runScript("if obj.createPQCppObject(12).getHeight()==12: obj.setPassed();\n")); + QVERIFY(_helper->runScript("if obj.createPQCppObject(12).getH()==12: obj.setPassed();\n")); + QVERIFY(_helper->runScript("pq1 = obj.createPQCppObject(12);\n" + "pq2 = obj.createPQCppObject(13);\n" + "pq3 = obj.getPQCppObject(pq1);\n" + "pq4 = obj.getPQCppObject(pq2);\n" + "if pq3.getHeight()==12 and pq4.getHeight()==13: obj.setPassed();\n" + )); + + QVERIFY(_helper->runScript("if obj.createPQCppObjectNoWrap(12).getH()==12: obj.setPassed();\n")); +} + + +void PythonQtTestSlotCalling::testMultiArgsSlotCall() +{ + QVERIFY(_helper->runScript("if obj.getMultiArgs(12,47.11,'test')==(12,47.11,'test'): obj.setPassed();\n")); +} + +bool PythonQtTestSlotCallingHelper::runScript(const char* script, int expectedOverload) +{ + _called = false; + _passed = false; + _calledOverload = -1; + PyRun_SimpleString(script); + return _called && _passed && _calledOverload==expectedOverload; +} + + +void PythonQtTestSignalHandler::initTestCase() +{ + _helper = new PythonQtTestSignalHandlerHelper(this); + PythonQtObjectPtr main = PythonQt::self()->getMainModule(); + PythonQt::self()->addObject(main, "obj", _helper); +} + +void PythonQtTestSignalHandler::testSignalHandler() +{ + PythonQtObjectPtr main = PythonQt::self()->getMainModule(); + PyRun_SimpleString("def testIntSignal(a):\n if a==12: obj.setPassed();\n"); + QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(intSignal(int)), main, "testIntSignal")); + QVERIFY(_helper->emitIntSignal(12)); + + PyRun_SimpleString("def testFloatSignal(a):\n if a==12: obj.setPassed();\n"); + QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(floatSignal(float)), main, "testFloatSignal")); + QVERIFY(_helper->emitFloatSignal(12)); + + PyRun_SimpleString("def testVariantSignal(a):\n if a==obj.expectedVariant(): obj.setPassed();\n"); + QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(variantSignal(QVariant)), main, "testVariantSignal")); + _helper->setExpectedVariant(QString("Test")); + QVERIFY(_helper->emitVariantSignal(QString("Test"))); + _helper->setExpectedVariant(12); + QVERIFY(_helper->emitVariantSignal(12)); + _helper->setExpectedVariant(QStringList() << "test1" << "test2"); + QVERIFY(_helper->emitVariantSignal(QStringList() << "test1" << "test2")); + _helper->setExpectedVariant(qVariantFromValue((QObject*)_helper)); + QVERIFY(_helper->emitVariantSignal(qVariantFromValue((QObject*)_helper))); + + PyRun_SimpleString("def testComplexSignal(a,b,l,o):\n if a==12 and b==13 and l==('test1','test2') and o == obj: obj.setPassed();\n"); + // intentionally not normalized signal: + QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(complexSignal( int, float , const QStringList , QObject*)), main, "testComplexSignal")); + QVERIFY(_helper->emitComplexSignal(12,13,QStringList() << "test1" << "test2", _helper)); + + // try removing the handler + QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(complexSignal( int, float , const QStringList , QObject*)), main, "testComplexSignal")); + // and emit the signal, which should fail because the handler was removed + QVERIFY(!_helper->emitComplexSignal(12,13,QStringList() << "test1" << "test2", _helper)); + + QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(intSignal(int)), main, "testIntSignal")); + QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(floatSignal(float)), main, "testFloatSignal")); + QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(variantSignal(QVariant)), main, "testVariantSignal")); + +} + +void PythonQtTestSignalHandler::testRecursiveSignalHandler() +{ + PythonQtObjectPtr main = PythonQt::self()->getMainModule(); + PyRun_SimpleString("def testSignal1(a):\n obj.emitSignal2(a);\n"); + PyRun_SimpleString("def testSignal2(a):\n obj.emitSignal3(float(a));\n"); + PyRun_SimpleString("def testSignal3(a):\n if a==12: obj.setPassed();\n"); + QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(signal1(int)), main, "testSignal1")); + QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(signal2(const QString&)), main, "testSignal2")); + QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(signal3(float)), main, "testSignal3")); + QVERIFY(_helper->emitSignal1(12)); +} + + +void PythonQtTestApi::initTestCase() +{ + _helper = new PythonQtTestApiHelper(); + PythonQtObjectPtr main = PythonQt::self()->getMainModule(); + PythonQt::self()->addObject(main, "obj", _helper); +} + +bool PythonQtTestApiHelper::call(const QString& function, const QVariantList& args, const QVariant& expectedResult) { + _passed = false; + QVariant r = PythonQt::self()->call(PythonQt::self()->getMainModule(), function, args); + return _passed && expectedResult==r; +} + +void PythonQtTestApi::testCall() +{ + PythonQtObjectPtr main = PythonQt::self()->getMainModule(); + + QVERIFY(qVariantValue(PythonQt::self()->getVariable(main, "obj"))==_helper); + + PyRun_SimpleString("def testCallNoArgs():\n obj.setPassed();\n"); + QVERIFY(_helper->call("testCallNoArgs", QVariantList(), QVariant())); + + PyRun_SimpleString("def testCall1(a):\n if a=='test': obj.setPassed();\n return 'test2';\n"); + QVERIFY(_helper->call("testCall1", QVariantList() << QVariant("test"), QVariant(QString("test2")))); + + PyRun_SimpleString("def testCall2(a, b):\n if a=='test' and b==obj: obj.setPassed();\n return obj;\n"); + QVariant r = PythonQt::self()->call(PythonQt::self()->getMainModule(), "testCall2", QVariantList() << QVariant("test") << qVariantFromValue((QObject*)_helper)); + QObject* p = qVariantValue(r); + QVERIFY(p==_helper); +} + +void PythonQtTestApi::testVariables() +{ + PythonQt::self()->addObject(PythonQt::self()->getMainModule(), "someObject", _helper); + QVariant v = PythonQt::self()->getVariable(PythonQt::self()->getMainModule(), "someObject"); + QObject* p = qVariantValue(v); + QVERIFY(p==_helper); + // test for unset variable + QVariant v2 = PythonQt::self()->getVariable(PythonQt::self()->getMainModule(), "someObject2"); + QVERIFY(v2==QVariant()); + + PythonQt::self()->addVariable(PythonQt::self()->getMainModule(), "someValue", QStringList() << "test1" << "test2"); + QVariant v3 = PythonQt::self()->getVariable(PythonQt::self()->getMainModule(), "someValue"); + QVERIFY(v3 == QVariant(QStringList() << "test1" << "test2")); + + QStringList l = PythonQt::self()->introspection(PythonQt::self()->getMainModule(), QString::null, PythonQt::Variable); + QSet s; + // check that at least these three variables are set + s << "obj" << "someObject" << "someValue"; + QString a; + foreach (a, l) { + QVERIFY(s.contains(a)); + } + + // insert a second time! + PythonQt::self()->addObject(PythonQt::self()->getMainModule(), "someObject", _helper); + // and remove + PythonQt::self()->removeVariable(PythonQt::self()->getMainModule(), "someObject"); + // we expect to find no variable + QVariant v4 = PythonQt::self()->getVariable(PythonQt::self()->getMainModule(), "someObject"); + QVERIFY(v4==QVariant()); +} + +void PythonQtTestApi::testImporter() +{ + PythonQt::self()->setImporter(_helper); + PythonQt::self()->overwriteSysPath(QStringList() << "c:\\test"); + PyRun_SimpleString("import bla\n"); +} + +QByteArray PythonQtTestApiHelper::readFileAsBytes(const QString& filename) +{ + QByteArray b; + return b; +} + +QByteArray PythonQtTestApiHelper::readSourceFile(const QString& filename, bool& ok) +{ + QByteArray b; + ok = true; + return b; +} + +bool PythonQtTestApiHelper::exists(const QString& filename) +{ + return true; +} + +QDateTime PythonQtTestApiHelper::lastModifiedDate(const QString& filename) { + return QDateTime::currentDateTime(); +} + + +void PythonQtTestApi::testRedirect() +{ + connect(PythonQt::self(), SIGNAL(pythonStdOut(const QString&)), _helper, SLOT(stdOut(const QString&))); + connect(PythonQt::self(), SIGNAL(pythonStdErr(const QString&)), _helper, SLOT(stdErr(const QString&))); + PyRun_SimpleString("print 'test'\n"); +} + +void PythonQtTestApiHelper::stdOut(const QString& s) +{ + qDebug() << s; +} + +void PythonQtTestApiHelper::stdErr(const QString& s) +{ + qDebug() << s; +} + +QObject* PythonQtTestCppFactory::create(const QByteArray& name, void *ptr) +{ + if (name == "PQCppObject") { + return new PQCppObjectWrapper(ptr); + } + return NULL; +} diff --git a/tests/PythonQtTests.h b/tests/PythonQtTests.h new file mode 100644 index 0000000..6b14ebc --- /dev/null +++ b/tests/PythonQtTests.h @@ -0,0 +1,332 @@ +#ifndef _PYTHONQTTESTS_H +#define _PYTHONQTTESTS_H + +/* + * + * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Contact information: MeVis Research GmbH, Universitaetsallee 29, + * 28359 Bremen, Germany or: + * + * http://www.mevis.de + * + */ + +//---------------------------------------------------------------------------------- +/*! +// \file PythonQtTests.h +// \author Florian Link +// \author Last changed by $Author: florian $ +// \date 2006-05 +*/ +//---------------------------------------------------------------------------------- + +#include "PythonQt.h" +#include +#include +#include "PythonQtImportFileInterface.h" +#include "PythonQtCppWrapperFactory.h" + +class PythonQtTestSlotCallingHelper; +class PythonQtTestApiHelper; +class QWidget; + +//! test the PythonQt api +class PythonQtTestApi : public QObject +{ + Q_OBJECT + +private slots: + void initTestCase(); + void testCall(); + void testVariables(); + void testRedirect(); + void testImporter(); + +private: + PythonQtTestApiHelper* _helper; + +}; + +//! test the PythonQt api (helper) +class PythonQtTestApiHelper : public QObject , public PythonQtImportFileInterface +{ + Q_OBJECT +public: + PythonQtTestApiHelper() { + }; + + bool call(const QString& function, const QVariantList& args, const QVariant& expectedResult); + + virtual QByteArray readFileAsBytes(const QString& filename); + + virtual QByteArray readSourceFile(const QString& filename, bool& ok); + + virtual bool exists(const QString& filename); + + virtual QDateTime lastModifiedDate(const QString& filename); + +public slots: + + //! call to set that the test has passed (from Python!) + void setPassed() { _passed = true; } + + void stdOut(const QString&); + void stdErr(const QString&); + +private: + bool _passed; +}; + +// test implementation of the wrapper factory +class PythonQtTestCppFactory : public PythonQtCppWrapperFactory +{ +public: + virtual QObject* create(const QByteArray& name, void *ptr); +}; + +//! an cpp object to be wrapped +class PQCppObject { + +public: + PQCppObject(int h) { _height = h; } + + int getHeight() { return _height; } + void setHeight(int h) { _height = h; } + +private: + int _height; +}; + +//! an qobject that wraps the existing cpp object +class PQCppObjectWrapper : public QObject { + Q_OBJECT +public: + PQCppObjectWrapper(void* ptr) { + _ptr = (PQCppObject*)ptr; + } + +public slots: + int getHeight() { return _ptr->getHeight(); } + void setHeight(int h) { _ptr->setHeight(h); } + +private: + PQCppObject* _ptr; +}; + +class PQCppObjectDecorator : public QObject { + Q_OBJECT +public slots: + int getH(PQCppObject* obj) { return obj->getHeight(); } + +}; + +//! an cpp object to be wrapped by decorators only +class PQCppObjectNoWrap { + +public: + PQCppObjectNoWrap(int h) { _height = h; } + + int getHeight() { return _height; } + void setHeight(int h) { _height = h; } + +private: + int _height; +}; + +class PQCppObjectNoWrapDecorator : public QObject { + Q_OBJECT +public slots: + int getH(PQCppObjectNoWrap* obj) { return obj->getHeight(); } + +}; + + +//! test the calling of slots +class PythonQtTestSlotCalling : public QObject +{ + Q_OBJECT + +private slots: + void initTestCase(); + void init(); + + void testNoArgSlotCall(); + void testPODSlotCalls(); + void testQVariantSlotCalls(); + void testObjectSlotCalls(); + void testMultiArgsSlotCall(); + + void testOverloadedCall(); + + void testCppFactory(); + +private: + PythonQtTestSlotCallingHelper* _helper; + +}; + +//! helper class for slot calling test +class PythonQtTestSlotCallingHelper : public QObject +{ + Q_OBJECT +public: + PythonQtTestSlotCallingHelper(PythonQtTestSlotCalling* test) { + _test = test; + }; + + bool runScript(const char* script, int expectedOverload = -1); + +public slots: + + //! call to set that the test has passed (from Python!) + void setPassed() { _passed = true; } + + //! no arguments, no return value: + void testNoArg() { _called = true; } + + //! overload test! + void overload(bool a) { _calledOverload = 0; _called = true; } + void overload(float a) { _calledOverload = 1; _called = true;} + void overload(int a) { _calledOverload = 2; _called = true;} + void overload(const QString& str) { _calledOverload = 3; _called = true;} + void overload(const QStringList& str) { _calledOverload = 4; _called = true;} + void overload(QObject* str) { _calledOverload = 5; _called = true;} + void overload(float a, int b) { _calledOverload = 6; _called = true;} + + //! POD values: + int getInt(int a) { _called = true; return a; } + unsigned int getUInt(unsigned int a) { _called = true; return a; } + bool getBool(bool a) { _called = true; return a; } + char getChar(char a) { _called = true; return a; } + unsigned char getUChar(unsigned char a) { _called = true; return a; } + long getLong(long a) { _called = true; return a; } + unsigned long getULong(unsigned long a) { _called = true; return a; } + short getShort(short a) { _called = true; return a; } + unsigned short getUShort(unsigned short a) { _called = true; return a; } + QChar getQChar(QChar a) { _called = true; return a; } + qint64 getLongLong(qint64 a) { _called = true; return a; } + quint64 getULongLong(quint64 a) { _called = true; return a; } + double getDouble(double d) { _called = true; return d; } + float getFloat(float d) { _called = true; return d; } + + //! important qt types: + QString getQString(const QString& s) { _called = true; return s; } + QStringList getQStringList(const QStringList& l) { _called = true; return l; } + QVariant getQVariant(const QVariant& var) { _called = true; return var; } + + //! testing pointer passing + PythonQtTestSlotCallingHelper* getTestObject(PythonQtTestSlotCallingHelper* obj) { _called = true; return obj; } + //! testing inheritance checking + QObject* getQObject(QObject* obj) { _called = true; return obj; } + QWidget* getQWidget(QWidget* obj) { _called = true; return obj; } + //! testing if an object that was not wrapped is wrapped earlier is wrapped correctly + QObject* getNewObject() { _called = true; return new PythonQtTestSlotCallingHelper(NULL); } + + QVariantList getMultiArgs(int a, double b, const QString& str) { _called = true; return (QVariantList() << a << b << str); } + // more exotic, not yet tested + //void setByteArray(QByteArray array) { qDebug() << array.data(); } + //void setCharPtr(char* data) { qDebug() << data; } + + //! cpp wrapper factory test + PQCppObject* createPQCppObject(int h) { _called = true; return new PQCppObject(h); } + + //! cpp wrapper factory test + PQCppObject* getPQCppObject(PQCppObject* p) { _called = true; return p; } + + //! cpp wrapper factory test + PQCppObjectNoWrap* createPQCppObjectNoWrap(int h) { _called = true; return new PQCppObjectNoWrap(h); } + + //! cpp wrapper factory test + PQCppObjectNoWrap* getPQCppObjectNoWrap(PQCppObjectNoWrap* p) { _called = true; return p; } + +private: + bool _passed; + bool _called; + int _calledOverload; + PythonQtTestSlotCalling* _test; +}; + +class PythonQtTestSignalHandlerHelper; + +//! test the connection of signals to python +class PythonQtTestSignalHandler : public QObject +{ + Q_OBJECT + +private slots: + void initTestCase(); + + void testSignalHandler(); + void testRecursiveSignalHandler(); + +private: + PythonQtTestSignalHandlerHelper* _helper; + +}; + +//! helper class for signal testing +class PythonQtTestSignalHandlerHelper : public QObject +{ + Q_OBJECT + +public: + PythonQtTestSignalHandlerHelper(PythonQtTestSignalHandler* test) { + _test = test; + }; + +public slots: + void setPassed() { _passed = true; } + + bool emitIntSignal(int a) { _passed = false; emit intSignal(a); return _passed; }; + bool emitFloatSignal(float a) { _passed = false; emit floatSignal(a); return _passed; }; + + bool emitVariantSignal(const QVariant& v) { _passed = false; emit variantSignal(v); return _passed; }; + QVariant expectedVariant() { return _v; } + void setExpectedVariant(const QVariant& v) { _v = v; } + + bool emitComplexSignal(int a, float b, const QStringList& l, QObject* obj) { _passed = false; emit complexSignal(a,b,l,obj); return _passed; }; + + bool emitSignal1(int a) { _passed = false; emit signal1(a); return _passed; }; + bool emitSignal2(const QString& s) { _passed = false; emit signal2(s); return _passed; }; + bool emitSignal3(float a) { _passed = false; emit signal3(a); return _passed; }; + +signals: + void intSignal(int); + void floatSignal(float); + void variantSignal(const QVariant& v); + void complexSignal(int a, float b, const QStringList& l, QObject* obj); + + void signal1(int); + void signal2(const QString&); + void signal3(float); + +private: + bool _passed; + QVariant _v; + + PythonQtTestSignalHandler* _test; +}; + +#endif diff --git a/tests/tests.pro b/tests/tests.pro new file mode 100644 index 0000000..b75c477 --- /dev/null +++ b/tests/tests.pro @@ -0,0 +1,19 @@ +# --------- PythonQtTest profile ------------------- +# Last changed by $Author: florian $ +# $Id: PythonQt.pro 35381 2006-03-16 13:05:52Z florian $ +# $Source$ +# -------------------------------------------------- +TARGET = PythonQtTest +TEMPLATE = app + +CONFIG += qtestlib + +include ( ../build/common.prf ) +include ( ../build/PythonQt.prf ) + +HEADERS += \ + PythonQtTests.h + +SOURCES += \ + PythonQtTestMain.cpp \ + PythonQtTests.cpp