summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Andreoli <dave@gurumeditation.it>2016-04-09 13:34:31 +0200
committerDave Andreoli <dave@gurumeditation.it>2016-04-09 13:34:31 +0200
commit8f549cfaf5a5f77bf2cd2f15e8637fd84e0647f4 (patch)
tree24aa03a9865f33f65d2e29a12f6c59e94f90d237
Futuristic cffi python bindings autogenerated using eolian
not yet complete but works. agood starting point.
-rw-r--r--AUTHORS16
-rw-r--r--CODING126
-rw-r--r--COPYING674
-rw-r--r--COPYING.LESSER165
-rw-r--r--MANIFEST.in1
-rw-r--r--Makefile52
-rw-r--r--README.rst169
-rw-r--r--efl2/__init__.py23
-rw-r--r--efl2/_utils.py24
-rw-r--r--efl2/cffi/build_efl.py62
-rw-r--r--efl2/cffi/eina.h9
-rw-r--r--efl2/cffi/eo.h147
-rw-r--r--efl2/eina.py27
-rw-r--r--efl2/eo.py182
-rw-r--r--pyolian/__init__.py0
-rw-r--r--pyolian/eolian.h395
-rw-r--r--pyolian/eolian.py559
-rw-r--r--pyolian/generator.py643
-rw-r--r--requirements-testing.txt3
-rwxr-xr-xsetup.py92
-rw-r--r--tests/test_ecore.c50
-rw-r--r--tests/test_ecore.py24
-rw-r--r--tests/test_elm.c60
-rw-r--r--tests/test_elm.py87
-rw-r--r--tox.ini6
25 files changed, 3596 insertions, 0 deletions
diff --git a/AUTHORS b/AUTHORS
new file mode 100644
index 0000000..31c5e67
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,16 @@
1Active developers
2
3Davide Andreoli <dave@gurumeditation.it>
4Kai Huuhko <kai.huuhko@gmail.com>
5
6
7Inactive contributors
8
9Gustavo Sverzut Barbieri <barbieri@gmail.com>
10Ulisses Furquim <ulissesf@gmail.com>
11Fabiano Fidêncio <fidencio@profusion.mobi>
12Tiago Falcão <tiago@profusion.mobi>
13Simon Busch <morphis@gravedo.de>
14Boris 'billiob' Faure <billiob@gmail.com>
15Bruno Dilly <bdilly@profusion.mobi>
16Joost Albers <joost.albers@nomadrail.com>
diff --git a/CODING b/CODING
new file mode 100644
index 0000000..2a23778
--- /dev/null
+++ b/CODING
@@ -0,0 +1,126 @@
1
2Style
3=====
4
5* For indentation, use *four space characters* per level of indentation. Keep
6 lines under the 80 chars limit (only exception are the functions definition)
7
8* For long lines that do not fit in the 80 cols please use only the first
9 raccomandation from PEP-8 (Aligned with opening delimiter). Example:
10 Yes:
11 foo = long_function_name(var_one, var_two,
12 var_three, var_four)
13 No:
14 foo = long_function_name(
15 var_one, var_two,
16 var_three, var_four)
17
18 This to keep new code consistent with the rest of the bindings and to
19 try to match the style of the C efl code style as much as possible.
20 ...also because I found it more readable and I like it more :P -davemds-
21
22
23Documentation cheatsheet
24========================
25
26* Links:
27
28 :class:`List` (for classes)
29 :func:`elm_list_go` (for functions)
30 :attr:`homogeneous` (for properties)
31 :ref:`Elm_List_Mode` (for enums)
32 :data:`ELM_LIST_LIMIT` (for enum values)
33
34 :func:`efl.evas.Object.delete` (for items not in current scope)
35 :func:`~efl.evas.Object.delete` (will show it short, just "delete")
36
37* Formatting:
38
39 ``ELM_LIST_SCROLL`` (for enum values, bools and None)
40
41
42* Versions:
43
44.. versionadded:: 1.15
45
46.. versionchanged:: 1.15
47 Description of the change.
48
49.. deprecated:: 1.15
50 Use the blah, blah way instead.
51
52* Notes:
53
54 .. seealso:: :py:attr:`mode`
55
56 .. note:: Some text to be noted, blah, blah, blah,
57 some more information for this note, etc.
58
59 .. warning:: Same as note, but the box will be red
60 some more information for this warning, etc.
61
62
63Design patterns
64===============
65
66 * From "The Zen of Python":
67
68 Beautiful is better than ugly.
69 Explicit is better than implicit.
70 Simple is better than complex.
71 Complex is better than complicated.
72 Flat is better than nested.
73 Sparse is better than dense.
74 Readability counts.
75 Special cases aren't special enough to break the rules.
76 Although practicality beats purity.
77 Errors should never pass silently.
78 Unless explicitly silenced.
79 In the face of ambiguity, refuse the temptation to guess.
80 There should be one-- and preferably only one --obvious way to do it.
81 Although that way may not be obvious at first unless you're Dutch.
82 Now is better than never.
83 Although never is often better than *right* now.
84 If the implementation is hard to explain, it's a bad idea.
85 If the implementation is easy to explain, it may be a good idea.
86 Namespaces are one honking great idea -- let's do more of those!
87
88
89
90Release process instructions
91============================
92
93* Announce at enlightenment-release@lists.sourceforge.net and
94 enlightenment-devel@lists.sourceforge.net that you are planning for the release
95* Change versions in efl/__init__.py (ex: 1.9.0)
96* Update the ChangeLog file:
97 setup.py build_doc -b changes ...and manually merge from the html file
98* Git push and wait jenkins to generate the 2 tarballs
99* Test the generated tarballs
100* scp tarballs & md5sums to:
101 download.enlightenment.org:/srv/web/download.enlightenment.org/public_html/pre-releases/
102* Announce at enlightenment-release@lists.sourceforge.net and
103 enlightenment-devel@lists.sourceforge.net that tarballs are ready for testing
104
105... wait 24 hours, fix any issues found. In the mean time you can prepare the
106 release announcement for phame/ml.
107
108* ssh to download.enlightenment.org and mv tarballs & md5sums to:
109 /srv/web/download.enlightenment.org/public_html/rel/bindings/python/
110* Upload the .tar.gz archive to pypi:
111 - first upload the PKG-INFO file from the "edit" section on pypi
112 - then upload the tarball from the "files" section
113* Create and push the tag for the release
114 git tag -a v1.9.0 && git push origin v1.9.0
115* Create and push the branch for stable backporting
116 git branch python-efl-1.9 && git push origin python-efl-1.9
117* scp the generated html documentation to:
118 download.enlightenment.org:/srv/web/docs.enlightenment.org/public_html/python-efl/1.XX.0/
119 and update the 'current' link on the server (ssh)
120* Update download link on the wiki (www.enlightenment.org/download)
121* Publish the blog post on phame (Official Announcements)
122* Announce the release to release@lists.enlightenment.org
123* Change versions again in efl/__init__.py (ex: 1.9.99)
124
125more info at:
126phab.enlightenment.org/w/release_procedure/
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..94a9ed0
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,674 @@
1 GNU GENERAL PUBLIC LICENSE
2 Version 3, 29 June 2007
3
4 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5 Everyone is permitted to copy and distribute verbatim copies
6 of this license document, but changing it is not allowed.
7
8 Preamble
9
10 The GNU General Public License is a free, copyleft license for
11software and other kinds of works.
12
13 The licenses for most software and other practical works are designed
14to take away your freedom to share and change the works. By contrast,
15the GNU General Public License is intended to guarantee your freedom to
16share and change all versions of a program--to make sure it remains free
17software for all its users. We, the Free Software Foundation, use the
18GNU General Public License for most of our software; it applies also to
19any other work released this way by its authors. You can apply it to
20your programs, too.
21
22 When we speak of free software, we are referring to freedom, not
23price. Our General Public Licenses are designed to make sure that you
24have the freedom to distribute copies of free software (and charge for
25them if you wish), that you receive source code or can get it if you
26want it, that you can change the software or use pieces of it in new
27free programs, and that you know you can do these things.
28
29 To protect your rights, we need to prevent others from denying you
30these rights or asking you to surrender the rights. Therefore, you have
31certain responsibilities if you distribute copies of the software, or if
32you modify it: responsibilities to respect the freedom of others.
33
34 For example, if you distribute copies of such a program, whether
35gratis or for a fee, you must pass on to the recipients the same
36freedoms that you received. You must make sure that they, too, receive
37or can get the source code. And you must show them these terms so they
38know their rights.
39
40 Developers that use the GNU GPL protect your rights with two steps:
41(1) assert copyright on the software, and (2) offer you this License
42giving you legal permission to copy, distribute and/or modify it.
43
44 For the developers' and authors' protection, the GPL clearly explains
45that there is no warranty for this free software. For both users' and
46authors' sake, the GPL requires that modified versions be marked as
47changed, so that their problems will not be attributed erroneously to
48authors of previous versions.
49
50 Some devices are designed to deny users access to install or run
51modified versions of the software inside them, although the manufacturer
52can do so. This is fundamentally incompatible with the aim of
53protecting users' freedom to change the software. The systematic
54pattern of such abuse occurs in the area of products for individuals to
55use, which is precisely where it is most unacceptable. Therefore, we
56have designed this version of the GPL to prohibit the practice for those
57products. If such problems arise substantially in other domains, we
58stand ready to extend this provision to those domains in future versions
59of the GPL, as needed to protect the freedom of users.
60
61 Finally, every program is threatened constantly by software patents.
62States should not allow patents to restrict development and use of
63software on general-purpose computers, but in those that do, we wish to
64avoid the special danger that patents applied to a free program could
65make it effectively proprietary. To prevent this, the GPL assures that
66patents cannot be used to render the program non-free.
67
68 The precise terms and conditions for copying, distribution and
69modification follow.
70
71 TERMS AND CONDITIONS
72
73 0. Definitions.
74
75 "This License" refers to version 3 of the GNU General Public License.
76
77 "Copyright" also means copyright-like laws that apply to other kinds of
78works, such as semiconductor masks.
79
80 "The Program" refers to any copyrightable work licensed under this
81License. Each licensee is addressed as "you". "Licensees" and
82"recipients" may be individuals or organizations.
83
84 To "modify" a work means to copy from or adapt all or part of the work
85in a fashion requiring copyright permission, other than the making of an
86exact copy. The resulting work is called a "modified version" of the
87earlier work or a work "based on" the earlier work.
88
89 A "covered work" means either the unmodified Program or a work based
90on the Program.
91
92 To "propagate" a work means to do anything with it that, without
93permission, would make you directly or secondarily liable for
94infringement under applicable copyright law, except executing it on a
95computer or modifying a private copy. Propagation includes copying,
96distribution (with or without modification), making available to the
97public, and in some countries other activities as well.
98
99 To "convey" a work means any kind of propagation that enables other
100parties to make or receive copies. Mere interaction with a user through
101a computer network, with no transfer of a copy, is not conveying.
102
103 An interactive user interface displays "Appropriate Legal Notices"
104to the extent that it includes a convenient and prominently visible
105feature that (1) displays an appropriate copyright notice, and (2)
106tells the user that there is no warranty for the work (except to the
107extent that warranties are provided), that licensees may convey the
108work under this License, and how to view a copy of this License. If
109the interface presents a list of user commands or options, such as a
110menu, a prominent item in the list meets this criterion.
111
112 1. Source Code.
113
114 The "source code" for a work means the preferred form of the work
115for making modifications to it. "Object code" means any non-source
116form of a work.
117
118 A "Standard Interface" means an interface that either is an official
119standard defined by a recognized standards body, or, in the case of
120interfaces specified for a particular programming language, one that
121is widely used among developers working in that language.
122
123 The "System Libraries" of an executable work include anything, other
124than the work as a whole, that (a) is included in the normal form of
125packaging a Major Component, but which is not part of that Major
126Component, and (b) serves only to enable use of the work with that
127Major Component, or to implement a Standard Interface for which an
128implementation is available to the public in source code form. A
129"Major Component", in this context, means a major essential component
130(kernel, window system, and so on) of the specific operating system
131(if any) on which the executable work runs, or a compiler used to
132produce the work, or an object code interpreter used to run it.
133
134 The "Corresponding Source" for a work in object code form means all
135the source code needed to generate, install, and (for an executable
136work) run the object code and to modify the work, including scripts to
137control those activities. However, it does not include the work's
138System Libraries, or general-purpose tools or generally available free
139programs which are used unmodified in performing those activities but
140which are not part of the work. For example, Corresponding Source
141includes interface definition files associated with source files for
142the work, and the source code for shared libraries and dynamically
143linked subprograms that the work is specifically designed to require,
144such as by intimate data communication or control flow between those
145subprograms and other parts of the work.
146
147 The Corresponding Source need not include anything that users
148can regenerate automatically from other parts of the Corresponding
149Source.
150
151 The Corresponding Source for a work in source code form is that
152same work.
153
154 2. Basic Permissions.
155
156 All rights granted under this License are granted for the term of
157copyright on the Program, and are irrevocable provided the stated
158conditions are met. This License explicitly affirms your unlimited
159permission to run the unmodified Program. The output from running a
160covered work is covered by this License only if the output, given its
161content, constitutes a covered work. This License acknowledges your
162rights of fair use or other equivalent, as provided by copyright law.
163
164 You may make, run and propagate covered works that you do not
165convey, without conditions so long as your license otherwise remains
166in force. You may convey covered works to others for the sole purpose
167of having them make modifications exclusively for you, or provide you
168with facilities for running those works, provided that you comply with
169the terms of this License in conveying all material for which you do
170not control copyright. Those thus making or running the covered works
171for you must do so exclusively on your behalf, under your direction
172and control, on terms that prohibit them from making any copies of
173your copyrighted material outside their relationship with you.
174
175 Conveying under any other circumstances is permitted solely under
176the conditions stated below. Sublicensing is not allowed; section 10
177makes it unnecessary.
178
179 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180
181 No covered work shall be deemed part of an effective technological
182measure under any applicable law fulfilling obligations under article
18311 of the WIPO copyright treaty adopted on 20 December 1996, or
184similar laws prohibiting or restricting circumvention of such
185measures.
186
187 When you convey a covered work, you waive any legal power to forbid
188circumvention of technological measures to the extent such circumvention
189is effected by exercising rights under this License with respect to
190the covered work, and you disclaim any intention to limit operation or
191modification of the work as a means of enforcing, against the work's
192users, your or third parties' legal rights to forbid circumvention of
193technological measures.
194
195 4. Conveying Verbatim Copies.
196
197 You may convey verbatim copies of the Program's source code as you
198receive it, in any medium, provided that you conspicuously and
199appropriately publish on each copy an appropriate copyright notice;
200keep intact all notices stating that this License and any
201non-permissive terms added in accord with section 7 apply to the code;
202keep intact all notices of the absence of any warranty; and give all
203recipients a copy of this License along with the Program.
204
205 You may charge any price or no price for each copy that you convey,
206and you may offer support or warranty protection for a fee.
207
208 5. Conveying Modified Source Versions.
209
210 You may convey a work based on the Program, or the modifications to
211produce it from the Program, in the form of source code under the
212terms of section 4, provided that you also meet all of these conditions:
213
214 a) The work must carry prominent notices stating that you modified
215 it, and giving a relevant date.
216
217 b) The work must carry prominent notices stating that it is
218 released under this License and any conditions added under section
219 7. This requirement modifies the requirement in section 4 to
220 "keep intact all notices".
221
222 c) You must license the entire work, as a whole, under this
223 License to anyone who comes into possession of a copy. This
224 License will therefore apply, along with any applicable section 7
225 additional terms, to the whole of the work, and all its parts,
226 regardless of how they are packaged. This License gives no
227 permission to license the work in any other way, but it does not
228 invalidate such permission if you have separately received it.
229
230 d) If the work has interactive user interfaces, each must display
231 Appropriate Legal Notices; however, if the Program has interactive
232 interfaces that do not display Appropriate Legal Notices, your
233 work need not make them do so.
234
235 A compilation of a covered work with other separate and independent
236works, which are not by their nature extensions of the covered work,
237and which are not combined with it such as to form a larger program,
238in or on a volume of a storage or distribution medium, is called an
239"aggregate" if the compilation and its resulting copyright are not
240used to limit the access or legal rights of the compilation's users
241beyond what the individual works permit. Inclusion of a covered work
242in an aggregate does not cause this License to apply to the other
243parts of the aggregate.
244
245 6. Conveying Non-Source Forms.
246
247 You may convey a covered work in object code form under the terms
248of sections 4 and 5, provided that you also convey the
249machine-readable Corresponding Source under the terms of this License,
250in one of these ways:
251
252 a) Convey the object code in, or embodied in, a physical product
253 (including a physical distribution medium), accompanied by the
254 Corresponding Source fixed on a durable physical medium
255 customarily used for software interchange.
256
257 b) Convey the object code in, or embodied in, a physical product
258 (including a physical distribution medium), accompanied by a
259 written offer, valid for at least three years and valid for as
260 long as you offer spare parts or customer support for that product
261 model, to give anyone who possesses the object code either (1) a
262 copy of the Corresponding Source for all the software in the
263 product that is covered by this License, on a durable physical
264 medium customarily used for software interchange, for a price no
265 more than your reasonable cost of physically performing this
266 conveying of source, or (2) access to copy the
267 Corresponding Source from a network server at no charge.
268
269 c) Convey individual copies of the object code with a copy of the
270 written offer to provide the Corresponding Source. This
271 alternative is allowed only occasionally and noncommercially, and
272 only if you received the object code with such an offer, in accord
273 with subsection 6b.
274
275 d) Convey the object code by offering access from a designated
276 place (gratis or for a charge), and offer equivalent access to the
277 Corresponding Source in the same way through the same place at no
278 further charge. You need not require recipients to copy the
279 Corresponding Source along with the object code. If the place to
280 copy the object code is a network server, the Corresponding Source
281 may be on a different server (operated by you or a third party)
282 that supports equivalent copying facilities, provided you maintain
283 clear directions next to the object code saying where to find the
284 Corresponding Source. Regardless of what server hosts the
285 Corresponding Source, you remain obligated to ensure that it is
286 available for as long as needed to satisfy these requirements.
287
288 e) Convey the object code using peer-to-peer transmission, provided
289 you inform other peers where the object code and Corresponding
290 Source of the work are being offered to the general public at no
291 charge under subsection 6d.
292
293 A separable portion of the object code, whose source code is excluded
294from the Corresponding Source as a System Library, need not be
295included in conveying the object code work.
296
297 A "User Product" is either (1) a "consumer product", which means any
298tangible personal property which is normally used for personal, family,
299or household purposes, or (2) anything designed or sold for incorporation
300into a dwelling. In determining whether a product is a consumer product,
301doubtful cases shall be resolved in favor of coverage. For a particular
302product received by a particular user, "normally used" refers to a
303typical or common use of that class of product, regardless of the status
304of the particular user or of the way in which the particular user
305actually uses, or expects or is expected to use, the product. A product
306is a consumer product regardless of whether the product has substantial
307commercial, industrial or non-consumer uses, unless such uses represent
308the only significant mode of use of the product.
309
310 "Installation Information" for a User Product means any methods,
311procedures, authorization keys, or other information required to install
312and execute modified versions of a covered work in that User Product from
313a modified version of its Corresponding Source. The information must
314suffice to ensure that the continued functioning of the modified object
315code is in no case prevented or interfered with solely because
316modification has been made.
317
318 If you convey an object code work under this section in, or with, or
319specifically for use in, a User Product, and the conveying occurs as
320part of a transaction in which the right of possession and use of the
321User Product is transferred to the recipient in perpetuity or for a
322fixed term (regardless of how the transaction is characterized), the
323Corresponding Source conveyed under this section must be accompanied
324by the Installation Information. But this requirement does not apply
325if neither you nor any third party retains the ability to install
326modified object code on the User Product (for example, the work has
327been installed in ROM).
328
329 The requirement to provide Installation Information does not include a
330requirement to continue to provide support service, warranty, or updates
331for a work that has been modified or installed by the recipient, or for
332the User Product in which it has been modified or installed. Access to a
333network may be denied when the modification itself materially and
334adversely affects the operation of the network or violates the rules and
335protocols for communication across the network.
336
337 Corresponding Source conveyed, and Installation Information provided,
338in accord with this section must be in a format that is publicly
339documented (and with an implementation available to the public in
340source code form), and must require no special password or key for
341unpacking, reading or copying.
342
343 7. Additional Terms.
344
345 "Additional permissions" are terms that supplement the terms of this
346License by making exceptions from one or more of its conditions.
347Additional permissions that are applicable to the entire Program shall
348be treated as though they were included in this License, to the extent
349that they are valid under applicable law. If additional permissions
350apply only to part of the Program, that part may be used separately
351under those permissions, but the entire Program remains governed by
352this License without regard to the additional permissions.
353
354 When you convey a copy of a covered work, you may at your option
355remove any additional permissions from that copy, or from any part of
356it. (Additional permissions may be written to require their own
357removal in certain cases when you modify the work.) You may place
358additional permissions on material, added by you to a covered work,
359for which you have or can give appropriate copyright permission.
360
361 Notwithstanding any other provision of this License, for material you
362add to a covered work, you may (if authorized by the copyright holders of
363that material) supplement the terms of this License with terms:
364
365 a) Disclaiming warranty or limiting liability differently from the
366 terms of sections 15 and 16 of this License; or
367
368 b) Requiring preservation of specified reasonable legal notices or
369 author attributions in that material or in the Appropriate Legal
370 Notices displayed by works containing it; or
371
372 c) Prohibiting misrepresentation of the origin of that material, or
373 requiring that modified versions of such material be marked in
374 reasonable ways as different from the original version; or
375
376 d) Limiting the use for publicity purposes of names of licensors or
377 authors of the material; or
378
379 e) Declining to grant rights under trademark law for use of some
380 trade names, trademarks, or service marks; or
381
382 f) Requiring indemnification of licensors and authors of that
383 material by anyone who conveys the material (or modified versions of
384 it) with contractual assumptions of liability to the recipient, for
385 any liability that these contractual assumptions directly impose on
386 those licensors and authors.
387
388 All other non-permissive additional terms are considered "further
389restrictions" within the meaning of section 10. If the Program as you
390received it, or any part of it, contains a notice stating that it is
391governed by this License along with a term that is a further
392restriction, you may remove that term. If a license document contains
393a further restriction but permits relicensing or conveying under this
394License, you may add to a covered work material governed by the terms
395of that license document, provided that the further restriction does
396not survive such relicensing or conveying.
397
398 If you add terms to a covered work in accord with this section, you
399must place, in the relevant source files, a statement of the
400additional terms that apply to those files, or a notice indicating
401where to find the applicable terms.
402
403 Additional terms, permissive or non-permissive, may be stated in the
404form of a separately written license, or stated as exceptions;
405the above requirements apply either way.
406
407 8. Termination.
408
409 You may not propagate or modify a covered work except as expressly
410provided under this License. Any attempt otherwise to propagate or
411modify it is void, and will automatically terminate your rights under
412this License (including any patent licenses granted under the third
413paragraph of section 11).
414
415 However, if you cease all violation of this License, then your
416license from a particular copyright holder is reinstated (a)
417provisionally, unless and until the copyright holder explicitly and
418finally terminates your license, and (b) permanently, if the copyright
419holder fails to notify you of the violation by some reasonable means
420prior to 60 days after the cessation.
421
422 Moreover, your license from a particular copyright holder is
423reinstated permanently if the copyright holder notifies you of the
424violation by some reasonable means, this is the first time you have
425received notice of violation of this License (for any work) from that
426copyright holder, and you cure the violation prior to 30 days after
427your receipt of the notice.
428
429 Termination of your rights under this section does not terminate the
430licenses of parties who have received copies or rights from you under
431this License. If your rights have been terminated and not permanently
432reinstated, you do not qualify to receive new licenses for the same
433material under section 10.
434
435 9. Acceptance Not Required for Having Copies.
436
437 You are not required to accept this License in order to receive or
438run a copy of the Program. Ancillary propagation of a covered work
439occurring solely as a consequence of using peer-to-peer transmission
440to receive a copy likewise does not require acceptance. However,
441nothing other than this License grants you permission to propagate or
442modify any covered work. These actions infringe copyright if you do
443not accept this License. Therefore, by modifying or propagating a
444covered work, you indicate your acceptance of this License to do so.
445
446 10. Automatic Licensing of Downstream Recipients.
447
448 Each time you convey a covered work, the recipient automatically
449receives a license from the original licensors, to run, modify and
450propagate that work, subject to this License. You are not responsible
451for enforcing compliance by third parties with this License.
452
453 An "entity transaction" is a transaction transferring control of an
454organization, or substantially all assets of one, or subdividing an
455organization, or merging organizations. If propagation of a covered
456work results from an entity transaction, each party to that
457transaction who receives a copy of the work also receives whatever
458licenses to the work the party's predecessor in interest had or could
459give under the previous paragraph, plus a right to possession of the
460Corresponding Source of the work from the predecessor in interest, if
461the predecessor has it or can get it with reasonable efforts.
462
463 You may not impose any further restrictions on the exercise of the
464rights granted or affirmed under this License. For example, you may
465not impose a license fee, royalty, or other charge for exercise of
466rights granted under this License, and you may not initiate litigation
467(including a cross-claim or counterclaim in a lawsuit) alleging that
468any patent claim is infringed by making, using, selling, offering for
469sale, or importing the Program or any portion of it.
470
471 11. Patents.
472
473 A "contributor" is a copyright holder who authorizes use under this
474License of the Program or a work on which the Program is based. The
475work thus licensed is called the contributor's "contributor version".
476
477 A contributor's "essential patent claims" are all patent claims
478owned or controlled by the contributor, whether already acquired or
479hereafter acquired, that would be infringed by some manner, permitted
480by this License, of making, using, or selling its contributor version,
481but do not include claims that would be infringed only as a
482consequence of further modification of the contributor version. For
483purposes of this definition, "control" includes the right to grant
484patent sublicenses in a manner consistent with the requirements of
485this License.
486
487 Each contributor grants you a non-exclusive, worldwide, royalty-free
488patent license under the contributor's essential patent claims, to
489make, use, sell, offer for sale, import and otherwise run, modify and
490propagate the contents of its contributor version.
491
492 In the following three paragraphs, a "patent license" is any express
493agreement or commitment, however denominated, not to enforce a patent
494(such as an express permission to practice a patent or covenant not to
495sue for patent infringement). To "grant" such a patent license to a
496party means to make such an agreement or commitment not to enforce a
497patent against the party.
498
499 If you convey a covered work, knowingly relying on a patent license,
500and the Corresponding Source of the work is not available for anyone
501to copy, free of charge and under the terms of this License, through a
502publicly available network server or other readily accessible means,
503then you must either (1) cause the Corresponding Source to be so
504available, or (2) arrange to deprive yourself of the benefit of the
505patent license for this particular work, or (3) arrange, in a manner
506consistent with the requirements of this License, to extend the patent
507license to downstream recipients. "Knowingly relying" means you have
508actual knowledge that, but for the patent license, your conveying the
509covered work in a country, or your recipient's use of the covered work
510in a country, would infringe one or more identifiable patents in that
511country that you have reason to believe are valid.
512
513 If, pursuant to or in connection with a single transaction or
514arrangement, you convey, or propagate by procuring conveyance of, a
515covered work, and grant a patent license to some of the parties
516receiving the covered work authorizing them to use, propagate, modify
517or convey a specific copy of the covered work, then the patent license
518you grant is automatically extended to all recipients of the covered
519work and works based on it.
520
521 A patent license is "discriminatory" if it does not include within
522the scope of its coverage, prohibits the exercise of, or is
523conditioned on the non-exercise of one or more of the rights that are
524specifically granted under this License. You may not convey a covered
525work if you are a party to an arrangement with a third party that is
526in the business of distributing software, under which you make payment
527to the third party based on the extent of your activity of conveying
528the work, and under which the third party grants, to any of the
529parties who would receive the covered work from you, a discriminatory
530patent license (a) in connection with copies of the covered work
531conveyed by you (or copies made from those copies), or (b) primarily
532for and in connection with specific products or compilations that
533contain the covered work, unless you entered into that arrangement,
534or that patent license was granted, prior to 28 March 2007.
535
536 Nothing in this License shall be construed as excluding or limiting
537any implied license or other defenses to infringement that may
538otherwise be available to you under applicable patent law.
539
540 12. No Surrender of Others' Freedom.
541
542 If conditions are imposed on you (whether by court order, agreement or
543otherwise) that contradict the conditions of this License, they do not
544excuse you from the conditions of this License. If you cannot convey a
545covered work so as to satisfy simultaneously your obligations under this
546License and any other pertinent obligations, then as a consequence you may
547not convey it at all. For example, if you agree to terms that obligate you
548to collect a royalty for further conveying from those to whom you convey
549the Program, the only way you could satisfy both those terms and this
550License would be to refrain entirely from conveying the Program.
551
552 13. Use with the GNU Affero General Public License.
553
554 Notwithstanding any other provision of this License, you have
555permission to link or combine any covered work with a work licensed
556under version 3 of the GNU Affero General Public License into a single
557combined work, and to convey the resulting work. The terms of this
558License will continue to apply to the part which is the covered work,
559but the special requirements of the GNU Affero General Public License,
560section 13, concerning interaction through a network will apply to the
561combination as such.
562
563 14. Revised Versions of this License.
564
565 The Free Software Foundation may publish revised and/or new versions of
566the GNU General Public License from time to time. Such new versions will
567be similar in spirit to the present version, but may differ in detail to
568address new problems or concerns.
569
570 Each version is given a distinguishing version number. If the
571Program specifies that a certain numbered version of the GNU General
572Public License "or any later version" applies to it, you have the
573option of following the terms and conditions either of that numbered
574version or of any later version published by the Free Software
575Foundation. If the Program does not specify a version number of the
576GNU General Public License, you may choose any version ever published
577by the Free Software Foundation.
578
579 If the Program specifies that a proxy can decide which future
580versions of the GNU General Public License can be used, that proxy's
581public statement of acceptance of a version permanently authorizes you
582to choose that version for the Program.
583
584 Later license versions may give you additional or different
585permissions. However, no additional obligations are imposed on any
586author or copyright holder as a result of your choosing to follow a
587later version.
588
589 15. Disclaimer of Warranty.
590
591 THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599
600 16. Limitation of Liability.
601
602 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610SUCH DAMAGES.
611
612 17. Interpretation of Sections 15 and 16.
613
614 If the disclaimer of warranty and limitation of liability provided
615above cannot be given local legal effect according to their terms,
616reviewing courts shall apply local law that most closely approximates
617an absolute waiver of all civil liability in connection with the
618Program, unless a warranty or assumption of liability accompanies a
619copy of the Program in return for a fee.
620
621 END OF TERMS AND CONDITIONS
622
623 How to Apply These Terms to Your New Programs
624
625 If you develop a new program, and you want it to be of the greatest
626possible use to the public, the best way to achieve this is to make it
627free software which everyone can redistribute and change under these terms.
628
629 To do so, attach the following notices to the program. It is safest
630to attach them to the start of each source file to most effectively
631state the exclusion of warranty; and each file should have at least
632the "copyright" line and a pointer to where the full notice is found.
633
634 <one line to give the program's name and a brief idea of what it does.>
635 Copyright (C) <year> <name of author>
636
637 This program is free software: you can redistribute it and/or modify
638 it under the terms of the GNU General Public License as published by
639 the Free Software Foundation, either version 3 of the License, or
640 (at your option) any later version.
641
642 This program is distributed in the hope that it will be useful,
643 but WITHOUT ANY WARRANTY; without even the implied warranty of
644 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 GNU General Public License for more details.
646
647 You should have received a copy of the GNU General Public License
648 along with this program. If not, see <http://www.gnu.org/licenses/>.
649
650Also add information on how to contact you by electronic and paper mail.
651
652 If the program does terminal interaction, make it output a short
653notice like this when it starts in an interactive mode:
654
655 <program> Copyright (C) <year> <name of author>
656 This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 This is free software, and you are welcome to redistribute it
658 under certain conditions; type `show c' for details.
659
660The hypothetical commands `show w' and `show c' should show the appropriate
661parts of the General Public License. Of course, your program's commands
662might be different; for a GUI interface, you would use an "about box".
663
664 You should also get your employer (if you work as a programmer) or school,
665if any, to sign a "copyright disclaimer" for the program, if necessary.
666For more information on this, and how to apply and follow the GNU GPL, see
667<http://www.gnu.org/licenses/>.
668
669 The GNU General Public License does not permit incorporating your program
670into proprietary programs. If your program is a subroutine library, you
671may consider it more useful to permit linking proprietary applications with
672the library. If this is what you want to do, use the GNU Lesser General
673Public License instead of this License. But first, please read
674<http://www.gnu.org/philosophy/why-not-lgpl.html>.
diff --git a/COPYING.LESSER b/COPYING.LESSER
new file mode 100644
index 0000000..65c5ca8
--- /dev/null
+++ b/COPYING.LESSER
@@ -0,0 +1,165 @@
1 GNU LESSER GENERAL PUBLIC LICENSE
2 Version 3, 29 June 2007
3
4 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5 Everyone is permitted to copy and distribute verbatim copies
6 of this license document, but changing it is not allowed.
7
8
9 This version of the GNU Lesser General Public License incorporates
10the terms and conditions of version 3 of the GNU General Public
11License, supplemented by the additional permissions listed below.
12
13 0. Additional Definitions.
14
15 As used herein, "this License" refers to version 3 of the GNU Lesser
16General Public License, and the "GNU GPL" refers to version 3 of the GNU
17General Public License.
18
19 "The Library" refers to a covered work governed by this License,
20other than an Application or a Combined Work as defined below.
21
22 An "Application" is any work that makes use of an interface provided
23by the Library, but which is not otherwise based on the Library.
24Defining a subclass of a class defined by the Library is deemed a mode
25of using an interface provided by the Library.
26
27 A "Combined Work" is a work produced by combining or linking an
28Application with the Library. The particular version of the Library
29with which the Combined Work was made is also called the "Linked
30Version".
31
32 The "Minimal Corresponding Source" for a Combined Work means the
33Corresponding Source for the Combined Work, excluding any source code
34for portions of the Combined Work that, considered in isolation, are
35based on the Application, and not on the Linked Version.
36
37 The "Corresponding Application Code" for a Combined Work means the
38object code and/or source code for the Application, including any data
39and utility programs needed for reproducing the Combined Work from the
40Application, but excluding the System Libraries of the Combined Work.
41
42 1. Exception to Section 3 of the GNU GPL.
43
44 You may convey a covered work under sections 3 and 4 of this License
45without being bound by section 3 of the GNU GPL.
46
47 2. Conveying Modified Versions.
48
49 If you modify a copy of the Library, and, in your modifications, a
50facility refers to a function or data to be supplied by an Application
51that uses the facility (other than as an argument passed when the
52facility is invoked), then you may convey a copy of the modified
53version:
54
55 a) under this License, provided that you make a good faith effort to
56 ensure that, in the event an Application does not supply the
57 function or data, the facility still operates, and performs
58 whatever part of its purpose remains meaningful, or
59
60 b) under the GNU GPL, with none of the additional permissions of
61 this License applicable to that copy.
62
63 3. Object Code Incorporating Material from Library Header Files.
64
65 The object code form of an Application may incorporate material from
66a header file that is part of the Library. You may convey such object
67code under terms of your choice, provided that, if the incorporated
68material is not limited to numerical parameters, data structure
69layouts and accessors, or small macros, inline functions and templates
70(ten or fewer lines in length), you do both of the following:
71
72 a) Give prominent notice with each copy of the object code that the
73 Library is used in it and that the Library and its use are
74 covered by this License.
75
76 b) Accompany the object code with a copy of the GNU GPL and this license
77 document.
78
79 4. Combined Works.
80
81 You may convey a Combined Work under terms of your choice that,
82taken together, effectively do not restrict modification of the
83portions of the Library contained in the Combined Work and reverse
84engineering for debugging such modifications, if you also do each of
85the following:
86
87 a) Give prominent notice with each copy of the Combined Work that
88 the Library is used in it and that the Library and its use are
89 covered by this License.
90
91 b) Accompany the Combined Work with a copy of the GNU GPL and this license
92 document.
93
94 c) For a Combined Work that displays copyright notices during
95 execution, include the copyright notice for the Library among
96 these notices, as well as a reference directing the user to the
97 copies of the GNU GPL and this license document.
98
99 d) Do one of the following:
100
101 0) Convey the Minimal Corresponding Source under the terms of this
102 License, and the Corresponding Application Code in a form
103 suitable for, and under terms that permit, the user to
104 recombine or relink the Application with a modified version of
105 the Linked Version to produce a modified Combined Work, in the
106 manner specified by section 6 of the GNU GPL for conveying
107 Corresponding Source.
108
109 1) Use a suitable shared library mechanism for linking with the
110 Library. A suitable mechanism is one that (a) uses at run time
111 a copy of the Library already present on the user's computer
112 system, and (b) will operate properly with a modified version
113 of the Library that is interface-compatible with the Linked
114 Version.
115
116 e) Provide Installation Information, but only if you would otherwise
117 be required to provide such information under section 6 of the
118 GNU GPL, and only to the extent that such information is
119 necessary to install and execute a modified version of the
120 Combined Work produced by recombining or relinking the
121 Application with a modified version of the Linked Version. (If
122 you use option 4d0, the Installation Information must accompany
123 the Minimal Corresponding Source and Corresponding Application
124 Code. If you use option 4d1, you must provide the Installation
125 Information in the manner specified by section 6 of the GNU GPL
126 for conveying Corresponding Source.)
127
128 5. Combined Libraries.
129
130 You may place library facilities that are a work based on the
131Library side by side in a single library together with other library
132facilities that are not Applications and are not covered by this
133License, and convey such a combined library under terms of your
134choice, if you do both of the following:
135
136 a) Accompany the combined library with a copy of the same work based
137 on the Library, uncombined with any other library facilities,
138 conveyed under the terms of this License.
139
140 b) Give prominent notice with the combined library that part of it
141 is a work based on the Library, and explaining where to find the
142 accompanying uncombined form of the same work.
143
144 6. Revised Versions of the GNU Lesser General Public License.
145
146 The Free Software Foundation may publish revised and/or new versions
147of the GNU Lesser General Public License from time to time. Such new
148versions will be similar in spirit to the present version, but may
149differ in detail to address new problems or concerns.
150
151 Each version is given a distinguishing version number. If the
152Library as you received it specifies that a certain numbered version
153of the GNU Lesser General Public License "or any later version"
154applies to it, you have the option of following the terms and
155conditions either of that published version or of any later version
156published by the Free Software Foundation. If the Library as you
157received it does not specify a version number of the GNU Lesser
158General Public License, you may choose any version of the GNU Lesser
159General Public License ever published by the Free Software Foundation.
160
161 If the Library as you received it specifies that a proxy can decide
162whether future versions of the GNU Lesser General Public License shall
163apply, that proxy's public statement of acceptance of any version is
164permanent authorization for you to choose that version for the
165Library.
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..28dcbf1
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1 @@
include README.rst COPYING COPYING.LESSER AUTHORS ChangeLog
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..e395fcf
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,52 @@
1#
2# A simple and stupid Makefile for python-efl.
3#
4# This is mainly targeted at lazy devlopers (like me) that
5# want to type less or do not want to learn the python
6# setup syntax.
7#
8# NOTE: This file is also used to discriminate when we are building from
9# stable tarballs (in this case we disable cython by default) or from git
10# sources as the Makefile is not distributed.
11#
12# Usage:
13#
14# make <cmd> to build using the default python interpreter
15# make <cmd> PY=pythonX to build using the specified python interpreter
16#
17
18
19PY = python
20
21
22.PHONY: build
23build:
24 $(PY) setup.py build
25
26
27.PHONY: install
28install:
29 $(PY) setup.py install
30
31
32.PHONY: doc
33doc:
34 $(PY) setup.py build build_doc
35
36
37.PHONY: test
38test:
39 $(PY) setup.py test
40
41
42.PHONY: clean
43clean:
44 $(PY) setup.py clean --all
45 rm -rfv build/ dist/ *.egg-info
46
47
48.PHONY: dist
49dist:
50 $(PY) setup.py sdist --formats=gztar,bztar
51
52
diff --git a/README.rst b/README.rst
new file mode 100644
index 0000000..20d04bd
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,169 @@
1cffi-example: an example project showing how to use Python's CFFI
2=================================================================
3
4A complete project which demonstrates how to use CFFI 1.0 during development of
5a modern Python package:
6
7* Development
8* Testing across Python interpreters (Py2, Py3, PyPy)
9* Packaging and distribution
10
11
12Status
13------
14
15This repository is the result of a weeks worth of frustrated googling. I don't
16think anything is *too* misleading, but I would deeply appreciate feedback from
17anyone who actually knows what's going on.
18
19
20Examples
21--------
22
23* ``cffi_example/person.py`` and ``cffi_example/build_person.py`` is an example
24 of a Python class which wraps a C class, including proper memory management
25 and passing around string buffers::
26
27 >>> p = Person(u"Alex", u"Smith", 72) # --> calls person_create(...)
28 >>> p.get_full_name() # --> calls person_get_full_name(p, buf, len(buf))
29 u"Alex Smith"
30
31* ``cffi_example/fnmatch.py`` and ``cffi_example/build_fnmatch.py`` is an
32 example of wrapping a shared library (in this case ``libc``'s `fnmatch`__)::
33
34 >>> fnmatch("f*", "foo") # --> calls libc's fnmatch
35 True
36
37__ http://man7.org/linux/man-pages/man3/fnmatch.3.html
38
39
40Development
41-----------
42
431. Clone the repository::
44
45 $ git clone git@github.com:wolever/python-cffi-example.git
46
472. Make sure that ``cffi``, ``py.test``, and ``tox`` are installed::
48
49 $ pip install -r requirements-testing.txt
50
513. Run ``python setup.py develop`` to build development versions of the
52 modules::
53
54 $ python setup.py develop
55 ...
56 Finished processing dependencies for cffi-example==0.1
57
584. Test locally with ``py.test``::
59
60 $ py.test test/
61 =========================== test session starts ===========================
62 platform darwin -- Python 2.7.2 -- py-1.4.28 -- pytest-2.7.1
63 rootdir: /Users/wolever/code/python-cffi-example, inifile:
64 collected 7 items
65
66 test/test_fnmatch.py ....
67 test/test_person.py ...
68
69 ======================== 7 passed in 0.03 seconds =========================
70
715. Test against multiple Python environments using ``tox``::
72
73 $ tox
74 ...
75 _________________________________ summary _________________________________
76 py26: commands succeeded
77 py27: commands succeeded
78 py33: commands succeeded
79 pypy: commands succeeded
80 congratulations :)
81
826. I prefer to use ``make`` to clean and rebuild libraries during development
83 (since it's faster than ``setup.py develop``)::
84
85 $ make clean
86 ...
87 $ make
88 python cffi_example/build_person.py
89 python cffi_example/build_fnmatch.py
90
91
92Packaging
93---------
94
95This example uses `CFFI's recommended combination`__ of ``setuptools`` and
96``cffi_modules``::
97
98 $ cat setup.py
99 from setuptools import setup
100
101 setup(
102 ...
103 install_requires=["cffi>=1.0.0"],
104 setup_requires=["cffi>=1.0.0"],
105 cffi_modules=[
106 "./cffi_example/build_person.py:ffi",
107 "./cffi_example/build_fnmatch.py:ffi",
108 ],
109 )
110
111__ https://cffi.readthedocs.org/en/latest/cdef.html#distutils-setuptools
112
113This will cause the modules to be built with ``setup.py develop`` or ``setup.py
114build``, and installed with ``setup.py install``.
115
116**Note**: Many examples you'll see online use either the ``distutils``
117``ext_modules=[cffi_example.ffi.distribute_extension()]`` method, or the
118more complex ``keywords_with_side_effects`` method. To the best of my
119knowledge these methods are only necessary with CFFI < 1.0 or ``distutils``.
120`dstufft`__ has written a fantastic post —
121https://caremad.io/2014/11/distributing-a-cffi-project/ — which details the
122drawbacks of the ``ext_modules`` method and explains the
123``keywords_with_side_effects`` method, but I believe it was written before CFFI
1241.0 so it does not include the now preferred ``cffi_modules`` method.
125
126__ https://twitter.com/dstufft/
127
128
129Distribution
130------------
131
132Distribution is just like any other Python package, with the obvious caveat
133that wheels will be platform-specific::
134
135 $ python setup.py sdist bdist_wheel
136 ...
137 $ ls dist/
138 cffi-example-0.1.tar.gz
139 cffi_example-0.1-cp27-none-macosx_10_8_intel.whl
140
141And the package can be uploaded to PyPI using ``upload``::
142
143 $ python setup.py sdist upload
144
145
146Note that users of the source package will need to have ``cffi`` (and a C
147compiler, and development headers of any libraries you're linking against)
148installed to build and install your package.
149
150Note also that the ``MANIFEST.in`` file will need to be updated to include any
151new source or headers you may add during development. The ``tox`` tests will
152catch this error, but it may not be obvious how to correct it.
153
154
155Caveats
156-------
157
158* Doesn't yet cover using ``dlopen(...)`` to dynamically load ``.so`` files
159 because I haven't figured out any best practices for building custom shared
160 libraries along with a Python package's lifecycle, and the
161 `CFFI documentation on loading dynamic libraries`__ covers the details of
162 making the ``lib.dlopen(...)`` call.
163
164* Using ``make`` to build modules during development is less than ideal. Please
165 post here if there's a better way to do this:
166 http://stackoverflow.com/q/30823397/71522
167
168
169__ https://cffi.readthedocs.org/en/latest/overview.html#out-of-line-abi-level
diff --git a/efl2/__init__.py b/efl2/__init__.py
new file mode 100644
index 0000000..59e601d
--- /dev/null
+++ b/efl2/__init__.py
@@ -0,0 +1,23 @@
1# Copyright (C) 2007-2016 various contributors (see AUTHORS)
2#
3# This file is part of Python-EFL.
4#
5# Python-EFL is free software; you can redistribute it and/or
6# modify it under the terms of the GNU Lesser General Public
7# License as published by the Free Software Foundation; either
8# version 3 of the License, or (at your option) any later version.
9#
10# Python-EFL is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# Lesser General Public License for more details.
14#
15# You should have received a copy of the GNU Lesser General Public License
16# along with this Python-EFL. If not, see <http://www.gnu.org/licenses/>.
17
18# semver examples:
19# development: "1.12.99" ( 1, 12, 99 )
20# pre-release: "1.13.0-beta1" ( 1, 13, 0 )
21# release: "1.13.0" ( 1, 13, 0 )
22__version__ = "2.0.0-test1"
23__version_info__ = ( 2, 0, 0 )
diff --git a/efl2/_utils.py b/efl2/_utils.py
new file mode 100644
index 0000000..1dce005
--- /dev/null
+++ b/efl2/_utils.py
@@ -0,0 +1,24 @@
1import sys
2
3PY2 = sys.version_info[0] == 2
4PY3 = sys.version_info[0] == 3
5
6if PY3:
7 text_type = str
8 binary_type = bytes
9else:
10 text_type = unicode
11 binary_type = str
12
13
14def _to_bytes(s):
15 if isinstance(s, binary_type):
16 return s
17 return text_type(s).encode('utf-8')
18
19
20def _to_unicode(ffi, s):
21 s = ffi.string(s)
22 if isinstance(s, text_type):
23 return s
24 return binary_type(s).decode('utf-8')
diff --git a/efl2/cffi/build_efl.py b/efl2/cffi/build_efl.py
new file mode 100644
index 0000000..ea89593
--- /dev/null
+++ b/efl2/cffi/build_efl.py
@@ -0,0 +1,62 @@
1###################################
2## THIS FILE IS MANUALLY WRITTEN ##
3###################################
4
5from cffi import FFI
6import os
7
8
9ffi = FFI()
10
11ffi.set_source(
12 'efl2._efl_ffi',
13 libraries=['efl', 'eina', 'eo', 'evas', 'ecore', 'elementary'],
14 define_macros=[
15 ('EFL_BETA_API_SUPPORT', 1),
16 ('EFL_EO_API_SUPPORT', 1),
17 ],
18
19 include_dirs=[
20 '/usr/local/include/efl-1',
21 '/usr/local/include/eina-1',
22 '/usr/local/include/eina-1/eina',
23 '/usr/local/include/eo-1',
24 '/usr/local/include/ecore-1',
25 '/usr/local/include/eet-1',
26 '/usr/local/include/emile-1',
27 '/usr/local/include/evas-1',
28 '/usr/local/include/ecore-evas-1',
29 '/usr/local/include/ecore-file-1',
30 '/usr/local/include/ecore-input-1',
31 '/usr/local/include/ecore-imf-1',
32 '/usr/local/include/ecore-con-1',
33 '/usr/local/include/edje-1',
34 '/usr/local/include/eldbus-1',
35 '/usr/local/include/efreet-1',
36 '/usr/local/include/ethumb-client-1',
37 '/usr/local/include/ethumb-1',
38 '/usr/local/include/elocation-1',
39 '/usr/local/include/elementary-1',
40 ], # TODO FIXME
41
42 source="""
43 #include <Eina.h>
44 #include <Eo.h>
45 #include <Efl.h>
46 #include <Evas.h>
47 #include <Ecore.h>
48 #include <Elementary.h>
49 """
50)
51
52
53# TODO: read all the *.h files instead !!!
54# for header in 'eina.h', 'eo.h', 'efl.h', 'evas.h', 'ecore.h', 'elementary.h':
55for header in 'eina.h', 'eo.h', 'ecore_mainloop.h', 'ecore_timer.h':
56 with open(os.path.join(os.path.dirname(__file__), header)) as f:
57 ffi.cdef(f.read())
58
59
60
61if __name__ == '__main__':
62 ffi.compile()
diff --git a/efl2/cffi/eina.h b/efl2/cffi/eina.h
new file mode 100644
index 0000000..6718fb5
--- /dev/null
+++ b/efl2/cffi/eina.h
@@ -0,0 +1,9 @@
1// ###################################
2// ## THIS FILE IS MANUALLY WRITTEN ##
3// ###################################
4
5
6typedef unsigned char Eina_Bool;
7
8#define EINA_FALSE 0
9#define EINA_TRUE 1
diff --git a/efl2/cffi/eo.h b/efl2/cffi/eo.h
new file mode 100644
index 0000000..50e5a76
--- /dev/null
+++ b/efl2/cffi/eo.h
@@ -0,0 +1,147 @@
1// ###################################
2// ## THIS FILE IS MANUALLY WRITTEN ##
3// ###################################
4
5// TEMPORARY HACKS
6int ecore_init(void);
7// TEMPORARY HACKS END
8
9// enums
10#define EO_CALLBACK_PRIORITY_BEFORE -100
11#define EO_CALLBACK_PRIORITY_DEFAULT 0
12#define EO_CALLBACK_PRIORITY_AFTER 100
13#define EO_CALLBACK_STOP ...
14#define EO_CALLBACK_CONTINUE ...
15
16enum _Eo_Class_Type {
17 EO_CLASS_TYPE_REGULAR,
18 EO_CLASS_TYPE_REGULAR_NO_INSTANT,
19 EO_CLASS_TYPE_INTERFACE,
20 EO_CLASS_TYPE_MIXIN,
21 ... };
22typedef enum _Eo_Class_Type Eo_Class_Type;
23
24enum _Eo_Op_Type {
25 EO_OP_TYPE_INVALID,
26 EO_OP_TYPE_REGULAR,
27 EO_OP_TYPE_CLASS,
28 EO_OP_TYPE_REGULAR_OVERRIDE,
29 EO_OP_TYPE_CLASS_OVERRIDE,
30 ... };
31typedef enum _Eo_Op_Type Eo_Op_Type;
32
33
34// typedefs
35typedef struct _Eo_Opaque Eo;
36typedef Eo Eo_Class;
37typedef Eo Eo_Base;
38typedef short Eo_Callback_Priority;
39
40typedef struct _Eo_Op_Description
41{
42 void *api_func; /**< The EAPI function offering this op. (The name of the func on windows) */
43 void *func; /**< The static function to call for the op. */
44 Eo_Op_Type op_type; /**< The type of the Op. */
45} Eo_Op_Description;
46
47typedef struct _Eo_Event_Description
48{
49 const char *name;
50 Eina_Bool unfreezable;
51 Eina_Bool legacy_is;
52} Eo_Event_Description;
53
54typedef struct _Eo_Event
55{
56 Eo_Base *obj; /** The object the event was called on. */
57 const Eo_Event_Description *desc; /** The event description. */
58 void *event_info; /** Extra event information passed by the event caller. */
59} Eo_Event;
60
61typedef struct _Eo_Class_Description
62{
63 unsigned int version; /**< The current version of eo, use #EO_VERSION */
64 const char *name; /**< The name of the class. */
65 Eo_Class_Type type; /**< The type of the class. */
66 struct {
67 const Eo_Op_Description *descs; /**< The op descriptions array of size count. */
68 size_t count; /**< Number of op descriptions. */
69 } ops; /**< The ops description, should be filled using #EO_CLASS_DESCRIPTION_OPS (later sorted by Eo). */
70 const Eo_Event_Description **events; /**< The event descriptions for this class. */
71 size_t data_size; /**< The size of data (private + protected + public) this class needs per object. */
72 void (*class_constructor)(Eo_Class *klass); /**< The constructor of the class. */
73 void (*class_destructor)(Eo_Class *klass); /**< The destructor of the class. */
74}Eo_Class_Description;
75
76
77// typedef void (*eo_key_data_free_func)(void *);
78typedef Eina_Bool (*Eo_Event_Cb)(void *data, const Eo_Event *event);
79
80
81// functions
82int eo_init(void);
83int eo_shutdown(void);
84
85// Eo* eo_add(Eo_Class *klass, Eo *parent, ...);
86// Eo* _eo_add_internal_start(const char *file, int line, const Eo_Class *klass_id, Eo *parent, Eina_Bool ref);
87Eo* _eo_add_internal_start(const char *file, int line, const Eo_Class *klass_id, Eo *parent, Eina_Bool ref, Eina_Bool is_fallback);
88Eo* _eo_add_end(Eo *obj, Eina_Bool is_fallback);
89
90
91
92
93//Eo* eo_add_ref(Eo_Class *klass, Eo *parent);
94void eo_parent_set(Eo *obj, Eo_Base *parent);
95Eo_Base *eo_parent_get(const Eo *obj);
96int eo_event_global_freeze_count_get(const Eo *obj);
97int eo_event_freeze_count_get(const Eo *obj);
98Eina_Bool eo_finalized_get(const Eo *obj);
99Eo_Base *eo_constructor(Eo *obj);
100void eo_destructor(Eo *obj);
101Eo_Base *eo_finalize(Eo *obj);
102// void eo_wref_add(Eo *obj, Eo_Base **wref);
103// void eo_wref_del(Eo *obj, Eo_Base **wref);
104void eo_key_data_set(Eo *obj, const char *key, const void *data);
105void *eo_key_data_get(const Eo *obj, const char *key);
106void eo_key_data_del(Eo *obj, const char *key);
107void eo_event_thaw(Eo *obj);
108void eo_event_freeze(Eo *obj);
109void eo_event_global_thaw(const Eo *obj);
110void eo_event_global_freeze(const Eo *obj);
111Eina_Bool eo_event_callback_priority_add(Eo *obj, const Eo_Event_Description *desc, Eo_Callback_Priority priority, Eo_Event_Cb cb, const void *data);
112
113// faked #define
114Eina_Bool eo_event_callback_add(Eo *obj, const Eo_Event_Description *desc, Eo_Event_Cb func, const void *user_data);
115Eina_Bool eo_event_callback_del(Eo *obj, const Eo_Event_Description *desc, Eo_Event_Cb func, const void *user_data);
116
117
118
119// Eina_Bool eo_event_callback_array_priority_add(Eo *obj, const Eo_Callback_Array_Item *array, Eo_Callback_Priority priority, const void *data);
120// Eina_Bool eo_event_callback_array_del(Eo *obj, const Eo_Callback_Array_Item *array, const void *user_data);
121// Eina_Bool eo_event_callback_call(Eo *obj, const Eo_Event_Description *desc, void *event_info);
122// void eo_event_callback_forwarder_add(Eo *obj, const Eo_Event_Description *desc, Eo_Base *new_obj);
123// void eo_event_callback_forwarder_del(Eo *obj, const Eo_Event_Description *desc, Eo_Base *new_obj);
124// void eo_dbg_info_get(Eo *obj, Eo_Dbg_Info *root_node);
125// Eina_Iterator *eo_children_iterator_new(Eo *obj);
126
127
128// events
129extern static Eo_Event_Description *const EO_BASE_EVENT_DEL;
130extern static Eo_Event_Description *const EO_BASE_EVENT_CALLBACK_ADD;
131extern static Eo_Event_Description *const EO_BASE_EVENT_CALLBACK_DEL;
132
133// from Eo.h
134Eo *eo_ref(const Eo *obj);
135void eo_unref(const Eo *obj);
136int eo_ref_get(const Eo *obj);
137void eo_del(const Eo *obj);
138
139
140
141
142
143// python callbacks
144extern "Python" Eina_Bool _eo_base_event_cb(void *data, const Eo_Event *event);
145extern "Python" Eina_Bool _eo_base_del_cb(void *data, const Eo_Event *event);
146
147
diff --git a/efl2/eina.py b/efl2/eina.py
new file mode 100644
index 0000000..7836ff5
--- /dev/null
+++ b/efl2/eina.py
@@ -0,0 +1,27 @@
1# Copyright (C) 2007-2016 various contributors (see AUTHORS)
2#
3# This file is part of Python-EFL.
4#
5# Python-EFL is free software; you can redistribute it and/or
6# modify it under the terms of the GNU Lesser General Public
7# License as published by the Free Software Foundation; either
8# version 3 of the License, or (at your option) any later version.
9#
10# Python-EFL is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# Lesser General Public License for more details.
14#
15# You should have received a copy of the GNU Lesser General Public License
16# along with this Python-EFL. If not, see <http://www.gnu.org/licenses/>.
17
18from ._efl_ffi import ffi, lib
19
20import atexit
21
22print("EINA INIT")
23lib.eina_init()
24atexit.register(lambda: lib.eina_shutdown())
25
26
27
diff --git a/efl2/eo.py b/efl2/eo.py
new file mode 100644
index 0000000..7f4a9e0
--- /dev/null
+++ b/efl2/eo.py
@@ -0,0 +1,182 @@
1# Copyright (C) 2007-2016 various contributors (see AUTHORS)
2#
3# This file is part of Python-EFL.
4#
5# Python-EFL is free software; you can redistribute it and/or
6# modify it under the terms of the GNU Lesser General Public
7# License as published by the Free Software Foundation; either
8# version 3 of the License, or (at your option) any later version.
9#
10# Python-EFL is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# Lesser General Public License for more details.
14#
15# You should have received a copy of the GNU Lesser General Public License
16# along with this Python-EFL. If not, see <http://www.gnu.org/licenses/>.
17
18import inspect
19from ._efl_ffi import ffi, lib
20
21
22### module init/shutdown ####################################################
23print("EO INIT")
24import atexit
25lib.eo_init()
26atexit.register(lambda: lib.eo_shutdown())
27
28
29#### MOMENTARY HACKS
30lib.ecore_init()
31#### MOMENTARY HACKS END
32
33
34### enums ###################################################################
35EO_CALLBACK_CONTINUE = lib.EO_CALLBACK_CONTINUE
36EO_CALLBACK_STOP = lib.EO_CALLBACK_STOP
37
38EO_CALLBACK_PRIORITY_BEFORE = lib.EO_CALLBACK_PRIORITY_BEFORE
39EO_CALLBACK_PRIORITY_DEFAULT = lib.EO_CALLBACK_PRIORITY_DEFAULT
40EO_CALLBACK_PRIORITY_AFTER = lib.EO_CALLBACK_PRIORITY_AFTER
41
42
43### utils for internal usage utils ##########################################
44_class_mapping = {} # { 'Eo.Base': <class 'efl2.eo.Base'>, ... }
45
46
47def _class_register(class_name):
48 """ This decorator must be used on each Eo derived class """
49 def decorator(pyclass):
50 print('Registering eo class: "{}" as: {}'.format(class_name, pyclass))
51 _class_mapping[class_name] = pyclass
52 return pyclass
53 return decorator
54
55def _obj_event_search(obj, ev_name):
56 print('Searching event: "{}" for obj: {}'.format(ev_name, obj))
57
58 for klass in inspect.getmro(obj.__class__):
59 __events = getattr(klass, '_{}__events'.format(klass.__name__), None)
60 if __events and ev_name in __events:
61 return __events[ev_name]
62
63
64### Eo.Base #################################################################
65# Eina_Bool (*Eo_Event_Cb)(void *data, const Eo_Event *event);
66@ffi.def_extern() # TODO @ffi.def_extern(onerror=my_handler)
67def _eo_base_event_cb(c_data, c_event):
68
69 func, args, kargs = ffi.from_handle(c_data)
70
71 if callable(func):
72 ret = func(*args, **kargs) # TODO pass obj (and event?)
73
74 # TODO conversion functions for c_event??
75
76 return ret
77
78@ffi.def_extern() # TODO @ffi.def_extern(onerror=my_handler)
79def _eo_base_del_cb(c_data, c_event):
80 print("DEL "*20)
81
82 lib.eo_event_callback_del(c_event.obj, lib.EO_BASE_EVENT_DEL,
83 lib._eo_base_del_cb, ffi.NULL)
84
85 return lib.EO_CALLBACK_CONTINUE
86
87
88# EO_BASE_EVENT_DEL = lib.EO_BASE_EVENT_DEL
89# EO_BASE_EVENT_CALLBACK_ADD = lib.EO_BASE_EVENT_CALLBACK_ADD
90# EO_BASE_EVENT_CALLBACK_DEL = lib.EO_BASE_EVENT_CALLBACK_DEL
91
92@_class_register('Eo.Base')
93class Base(object):
94 """ Base class used by all the object in the EFL. """
95 __events = {
96 'del': lib.EO_BASE_EVENT_DEL,
97 'callback,add': lib.EO_BASE_EVENT_CALLBACK_ADD,
98 'callback,del': lib.EO_BASE_EVENT_CALLBACK_DEL,
99 }
100 def __init__(self, klass, parent=None, finalize=True, **kargs):
101 # print("Eo Base __init__ for klass:", klass)
102 self._priv = dict() # for bindings internal usage
103
104 self._obj = lib._eo_add_internal_start(ffi.NULL, 0, klass,
105 parent._obj if parent else ffi.NULL,
106 False, False) # add_ref, fallback
107
108 if self._obj == ffi.NULL:
109 raise MemoryError("Could not create the object")
110
111 if finalize is True:
112 self.__init__end__(**kargs)
113
114 def __init__end__(self, **kargs):
115
116 lib._eo_add_end(self._obj, False)
117
118 # set_properties_from_keyword_args
119 if kargs:
120 for k, v in kargs.items():
121 setattr(self, k, v)
122
123
124 lib.eo_event_callback_add(self._obj, lib.EO_BASE_EVENT_DEL,
125 lib._eo_base_del_cb, ffi.NULL)
126
127 def __nonzero__(self):
128 return 1 if (self._obj != None) and (self._obj != ffi.NULL) else 0
129
130 def delete(self):
131 lib.eo_del(self._obj)
132 # lib.eo_unref(self._obj)
133 self._obj = None
134 # TODO disconnect on_del
135
136 @property
137 def data(self):
138 """ For user convenience (dict lazy created only when used) """
139 if not hasattr(self, '_data'):
140 self._data = dict()
141 return self._data
142
143 def event_callback_priority_add(self, ev_name, priority, func, *args, **kargs):
144 ev = _obj_event_search(self, ev_name)
145 if ev is None:
146 raise RuntimeError('Unknown event "{}" for class "{}"' \
147 .format(ev_name, self.__class__.__name__))
148
149 c_data = ffi.new_handle((func, args, kargs))
150 self.TEST = c_data # TODO FIXME !!!!!!!!!!!!!!!!!!!!!!!
151
152 ret = lib.eo_event_callback_priority_add(self._obj, ev, priority,
153 lib._eo_base_event_cb, c_data)
154 if ret == 0:
155 raise RuntimeError('Cannot add callback for event "{}" in class "{}"' \
156 .format(ev_name, self.__class__.__name__))
157
158 def event_callback_add(self, ev_name, func, *args, **kargs):
159 self.event_callback_priority_add(ev_name, 0, func, *args, **kargs)
160
161 # just the really short alias "on" (do we like this?? remove the longer one?)
162 on = event_callback_add
163
164
165 """
166 def event_callback_add(self, ev, func, *args, **kargs):
167 c_data = ffi.new_handle((func, args, kargs))
168 self.TEST = c_data # TODO FIXME !!!!!!!!!!!!!!!!!!!!!!!
169
170 return bool(lib.eo_event_callback_add(self._obj, ev,
171 lib._eo_base_event_cb, c_data))
172 """
173
174 """
175 def event_callback_priority_add(self, priority, callback, *args, **kargs):
176 userdata = ffi.new_handle(self)
177 self._priv['self_h'] = userdata # must keep this alive! :/
178
179 return bool(lib.eo_event_callback_priority_add(self._obj, ev, priority,
180 lib._eo_base_event_cb, userdata))
181
182 """
diff --git a/pyolian/__init__.py b/pyolian/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/pyolian/__init__.py
diff --git a/pyolian/eolian.h b/pyolian/eolian.h
new file mode 100644
index 0000000..ac16cc1
--- /dev/null
+++ b/pyolian/eolian.h
@@ -0,0 +1,395 @@
1///////////////////////////////////////////////////////////////////////////////
2//// THIS FILE IS MANUALLY WRITTEN ////
3///////////////////////////////////////////////////////////////////////////////
4
5//// Eina ///////////////////////////////////////////////////////////////////
6typedef unsigned char Eina_Bool;
7#define EINA_FALSE 0
8#define EINA_TRUE 1
9
10typedef struct _Eina_Iterator Eina_Iterator;
11typedef const char Eina_Stringshare;
12
13void eina_iterator_free (Eina_Iterator *iterator);
14Eina_Bool eina_iterator_next (Eina_Iterator *iterator, void **data);
15Eina_Bool eina_iterator_lock (Eina_Iterator *iterator);
16Eina_Bool eina_iterator_unlock (Eina_Iterator *iterator);
17void *eina_iterator_container_get(Eina_Iterator *iterator);
18
19
20//// enums //////////////////////////////////////////////////////////////////
21typedef enum
22{
23 EOLIAN_UNRESOLVED = 0,
24 EOLIAN_PROPERTY,
25 EOLIAN_PROP_SET,
26 EOLIAN_PROP_GET,
27 EOLIAN_METHOD
28} Eolian_Function_Type;
29
30typedef enum
31{
32 EOLIAN_IN_PARAM = 0,
33 EOLIAN_OUT_PARAM,
34 EOLIAN_INOUT_PARAM
35} Eolian_Parameter_Dir;
36
37typedef enum
38{
39 EOLIAN_CLASS_UNKNOWN_TYPE = 0,
40 EOLIAN_CLASS_REGULAR,
41 EOLIAN_CLASS_ABSTRACT,
42 EOLIAN_CLASS_MIXIN,
43 EOLIAN_CLASS_INTERFACE
44} Eolian_Class_Type;
45
46typedef enum
47{
48 EOLIAN_SCOPE_PUBLIC = 0,
49 EOLIAN_SCOPE_PRIVATE,
50 EOLIAN_SCOPE_PROTECTED
51} Eolian_Object_Scope;
52
53typedef enum
54{
55 EOLIAN_TYPEDECL_UNKNOWN = 0,
56 EOLIAN_TYPEDECL_STRUCT,
57 EOLIAN_TYPEDECL_STRUCT_OPAQUE,
58 EOLIAN_TYPEDECL_ENUM,
59 EOLIAN_TYPEDECL_ALIAS
60} Eolian_Typedecl_Type;
61
62typedef enum
63{
64 EOLIAN_TYPE_UNKNOWN_TYPE = 0,
65 EOLIAN_TYPE_VOID,
66 EOLIAN_TYPE_REGULAR,
67 EOLIAN_TYPE_COMPLEX,
68 EOLIAN_TYPE_POINTER,
69 EOLIAN_TYPE_CLASS,
70 EOLIAN_TYPE_UNDEFINED
71} Eolian_Type_Type;
72
73typedef enum
74{
75 EOLIAN_EXPR_UNKNOWN = 0,
76 EOLIAN_EXPR_INT,
77 EOLIAN_EXPR_UINT,
78 EOLIAN_EXPR_LONG,
79 EOLIAN_EXPR_ULONG,
80 EOLIAN_EXPR_LLONG,
81 EOLIAN_EXPR_ULLONG,
82 EOLIAN_EXPR_FLOAT,
83 EOLIAN_EXPR_DOUBLE,
84 EOLIAN_EXPR_STRING,
85 EOLIAN_EXPR_CHAR,
86 EOLIAN_EXPR_NULL,
87 EOLIAN_EXPR_BOOL,
88 EOLIAN_EXPR_NAME,
89 EOLIAN_EXPR_UNARY,
90 EOLIAN_EXPR_BINARY
91} Eolian_Expression_Type;
92
93typedef enum
94{
95 EOLIAN_MASK_SINT,
96 EOLIAN_MASK_UINT,
97 EOLIAN_MASK_INT,
98 EOLIAN_MASK_FLOAT,
99 EOLIAN_MASK_BOOL,
100 EOLIAN_MASK_STRING,
101 EOLIAN_MASK_CHAR,
102 EOLIAN_MASK_NULL,
103 EOLIAN_MASK_NUMBER,
104 EOLIAN_MASK_ALL,
105 ...
106} Eolian_Expression_Mask;
107
108typedef enum
109{
110 EOLIAN_VAR_UNKNOWN = 0,
111 EOLIAN_VAR_CONSTANT,
112 EOLIAN_VAR_GLOBAL
113} Eolian_Variable_Type;
114
115typedef union
116{
117 char c;
118 Eina_Bool b;
119 const char *s;
120 signed int i;
121 unsigned int u;
122 signed long l;
123 unsigned long ul;
124 signed long long ll;
125 unsigned long long ull;
126 float f;
127 double d;
128} Eolian_Value_Union;
129
130typedef struct _Eolian_Value
131{
132 Eolian_Expression_Type type;
133 Eolian_Value_Union value;
134} Eolian_Value;
135
136typedef enum
137{
138 EOLIAN_BINOP_INVALID = -1,
139
140 EOLIAN_BINOP_ADD, /* + int, float */
141 EOLIAN_BINOP_SUB, /* - int, float */
142 EOLIAN_BINOP_MUL, /* * int, float */
143 EOLIAN_BINOP_DIV, /* / int, float */
144 EOLIAN_BINOP_MOD, /* % int */
145
146 EOLIAN_BINOP_EQ, /* == all types */
147 EOLIAN_BINOP_NQ, /* != all types */
148 EOLIAN_BINOP_GT, /* > int, float */
149 EOLIAN_BINOP_LT, /* < int, float */
150 EOLIAN_BINOP_GE, /* >= int, float */
151 EOLIAN_BINOP_LE, /* <= int, float */
152
153 EOLIAN_BINOP_AND, /* && all types */
154 EOLIAN_BINOP_OR, /* || all types */
155
156 EOLIAN_BINOP_BAND, /* & int */
157 EOLIAN_BINOP_BOR, /* | int */
158 EOLIAN_BINOP_BXOR, /* ^ int */
159 EOLIAN_BINOP_LSH, /* << int */
160 EOLIAN_BINOP_RSH /* >> int */
161} Eolian_Binary_Operator;
162
163typedef enum
164{
165 EOLIAN_UNOP_INVALID = -1,
166
167 EOLIAN_UNOP_UNM, /* - sint */
168 EOLIAN_UNOP_UNP, /* + sint */
169
170 EOLIAN_UNOP_NOT, /* ! int, float, bool */
171 EOLIAN_UNOP_BNOT, /* ~ int */
172} Eolian_Unary_Operator;
173
174typedef enum
175{
176 EOLIAN_DECL_UNKNOWN = -1,
177 EOLIAN_DECL_CLASS,
178 EOLIAN_DECL_ALIAS,
179 EOLIAN_DECL_STRUCT,
180 EOLIAN_DECL_ENUM,
181 EOLIAN_DECL_VAR,
182} Eolian_Declaration_Type;
183
184//// typedefs ///////////////////////////////////////////////////////////////
185typedef struct _Eolian_Class Eolian_Class;
186typedef struct _Eolian_Function Eolian_Function;
187typedef struct _Eolian_Type Eolian_Type;
188typedef struct _Eolian_Typedecl Eolian_Typedecl;
189typedef struct _Eolian_Function_Parameter Eolian_Function_Parameter;
190typedef struct _Eolian_Implement Eolian_Implement;
191typedef struct _Eolian_Constructor Eolian_Constructor;
192typedef struct _Eolian_Event Eolian_Event;
193typedef struct _Eolian_Expression Eolian_Expression;
194typedef struct _Eolian_Variable Eolian_Variable;
195typedef struct _Eolian_Struct_Type_Field Eolian_Struct_Type_Field;
196typedef struct _Eolian_Enum_Type_Field Eolian_Enum_Type_Field;
197typedef struct _Eolian_Declaration Eolian_Declaration;
198typedef struct _Eolian_Documentation Eolian_Documentation;
199
200
201//// functions //////////////////////////////////////////////////////////////
202int eolian_init(void);
203int eolian_shutdown(void);
204
205// database population
206Eina_Bool eolian_file_parse(const char *filepath);
207Eina_Iterator *eolian_all_eo_file_paths_get(void);
208Eina_Iterator *eolian_all_eot_file_paths_get(void);
209Eina_Iterator *eolian_all_eo_files_get(void);
210Eina_Iterator *eolian_all_eot_files_get(void);
211Eina_Bool eolian_directory_scan(const char *dir);
212Eina_Bool eolian_system_directory_scan(void);
213Eina_Bool eolian_all_eo_files_parse(void);
214Eina_Bool eolian_all_eot_files_parse(void);
215Eina_Bool eolian_database_validate(Eina_Bool silent_types);
216
217// class
218Eina_Iterator *eolian_all_classes_get(void);
219Eina_Stringshare *eolian_class_c_get_function_name_get(const Eolian_Class *klass);
220const Eolian_Class *eolian_class_get_by_name(const char *class_name);
221const Eolian_Class *eolian_class_get_by_file(const char *file_name);
222Eina_Stringshare *eolian_class_file_get(const Eolian_Class *klass);
223Eina_Stringshare *eolian_class_full_name_get(const Eolian_Class *klass);
224Eina_Stringshare *eolian_class_name_get(const Eolian_Class *klass);
225Eina_Iterator *eolian_class_namespaces_get(const Eolian_Class *klass);
226Eolian_Class_Type eolian_class_type_get(const Eolian_Class *klass);
227const Eolian_Documentation *eolian_class_documentation_get(const Eolian_Class *klass);
228Eina_Stringshare *eolian_class_legacy_prefix_get(const Eolian_Class *klass);
229Eina_Stringshare *eolian_class_eo_prefix_get(const Eolian_Class *klass);
230Eina_Stringshare *eolian_class_data_type_get(const Eolian_Class *klass);
231Eina_Iterator *eolian_class_inherits_get(const Eolian_Class *klass);
232Eina_Iterator *eolian_class_functions_get(const Eolian_Class *klass, Eolian_Function_Type func_type);
233const Eolian_Function *eolian_class_function_get_by_name(const Eolian_Class *klass, const char *func_name, Eolian_Function_Type f_type);
234const Eolian_Event *eolian_class_event_get_by_name(const Eolian_Class *klass, const char *event_name);
235Eina_Bool eolian_class_ctor_enable_get(const Eolian_Class *klass);
236Eina_Bool eolian_class_dtor_enable_get(const Eolian_Class *klass);
237Eina_Iterator *eolian_class_constructors_get(const Eolian_Class *klass);
238Eina_Iterator *eolian_class_events_get(const Eolian_Class *klass);
239Eina_Iterator *eolian_class_implements_get(const Eolian_Class *klass);
240
241// constructor
242Eina_Stringshare *eolian_constructor_full_name_get(const Eolian_Constructor *ctor);
243const Eolian_Class *eolian_constructor_class_get(const Eolian_Constructor *ctor);
244const Eolian_Function *eolian_constructor_function_get(const Eolian_Constructor *ctor);
245Eina_Bool eolian_constructor_is_optional(const Eolian_Constructor *ctor);
246
247// event
248Eina_Stringshare *eolian_event_name_get(const Eolian_Event *event);
249const Eolian_Type *eolian_event_type_get(const Eolian_Event *event);
250const Eolian_Documentation *eolian_event_documentation_get(const Eolian_Event *event);
251Eolian_Object_Scope eolian_event_scope_get(const Eolian_Event *event);
252Eina_Bool eolian_event_is_beta(const Eolian_Event *event);
253Eina_Bool eolian_event_is_hot(const Eolian_Event *event);
254Eina_Stringshare *eolian_event_c_name_get(const Eolian_Event *event);
255
256// property
257Eina_Iterator *eolian_property_keys_get(const Eolian_Function *foo_id, Eolian_Function_Type ftype);
258Eina_Iterator *eolian_property_values_get(const Eolian_Function *foo_id, Eolian_Function_Type ftype);
259
260// function
261Eolian_Function_Type eolian_function_type_get(const Eolian_Function *function_id);
262Eolian_Object_Scope eolian_function_scope_get(const Eolian_Function *function_id);
263Eina_Stringshare *eolian_function_name_get(const Eolian_Function *function_id);
264Eina_Stringshare *eolian_function_full_c_name_get(const Eolian_Function *function_id, Eolian_Function_Type ftype, Eina_Bool use_legacy);
265Eina_Stringshare *eolian_function_legacy_get(const Eolian_Function *function_id, Eolian_Function_Type f_type);
266const Eolian_Documentation *eolian_function_documentation_get(const Eolian_Function *function_id, Eolian_Function_Type f_type);
267Eina_Bool eolian_function_is_virtual_pure(const Eolian_Function *function_id, Eolian_Function_Type f_type);
268Eina_Bool eolian_function_is_auto(const Eolian_Function *function_id, Eolian_Function_Type f_type);
269Eina_Bool eolian_function_is_empty(const Eolian_Function *function_id, Eolian_Function_Type f_type);
270Eina_Bool eolian_function_is_legacy_only(const Eolian_Function *function_id, Eolian_Function_Type ftype);
271Eina_Bool eolian_function_is_class(const Eolian_Function *function_id);
272Eina_Bool eolian_function_is_c_only(const Eolian_Function *function_id);
273Eina_Bool eolian_function_is_beta(const Eolian_Function *function_id);
274Eina_Bool eolian_function_is_constructor(const Eolian_Function *function_id, const Eolian_Class *klass);
275Eina_Iterator *eolian_function_parameters_get(const Eolian_Function *function_id);
276Eina_Bool eolian_function_object_is_const(const Eolian_Function *function_id);
277const Eolian_Class *eolian_function_class_get(const Eolian_Function *function_id);
278Eina_Bool eolian_function_is_implemented(const Eolian_Function *function_id, Eolian_Function_Type func_type, const Eolian_Class *klass);
279
280// parameter
281Eolian_Parameter_Dir eolian_parameter_direction_get(const Eolian_Function_Parameter *param);
282const Eolian_Type *eolian_parameter_type_get(const Eolian_Function_Parameter *param);
283const Eolian_Expression *eolian_parameter_default_value_get(const Eolian_Function_Parameter *param);
284Eina_Stringshare *eolian_parameter_name_get(const Eolian_Function_Parameter *param);
285const Eolian_Documentation *eolian_parameter_documentation_get(const Eolian_Function_Parameter *param);
286Eina_Bool eolian_parameter_is_nonull(const Eolian_Function_Parameter *param_desc);
287Eina_Bool eolian_parameter_is_nullable(const Eolian_Function_Parameter *param_desc);
288Eina_Bool eolian_parameter_is_optional(const Eolian_Function_Parameter *param_desc);
289
290// return
291const Eolian_Type *eolian_function_return_type_get(const Eolian_Function *function_id, Eolian_Function_Type ftype);
292const Eolian_Expression *eolian_function_return_default_value_get(const Eolian_Function *foo_id, Eolian_Function_Type ftype);
293const Eolian_Documentation *eolian_function_return_documentation_get(const Eolian_Function *foo_id, Eolian_Function_Type ftype);
294Eina_Bool eolian_function_return_is_warn_unused(const Eolian_Function *foo_id, Eolian_Function_Type ftype);
295
296// implement
297Eina_Stringshare *eolian_implement_full_name_get(const Eolian_Implement *impl);
298const Eolian_Class *eolian_implement_class_get(const Eolian_Implement *impl);
299const Eolian_Function *eolian_implement_function_get(const Eolian_Implement *impl, Eolian_Function_Type *func_type);
300Eina_Bool eolian_implement_is_auto(const Eolian_Implement *impl);
301Eina_Bool eolian_implement_is_empty(const Eolian_Implement *impl);
302Eina_Bool eolian_implement_is_virtual(const Eolian_Implement *impl);
303Eina_Bool eolian_implement_is_prop_get(const Eolian_Implement *impl);
304Eina_Bool eolian_implement_is_prop_set(const Eolian_Implement *impl);
305
306// typedecl
307const Eolian_Typedecl *eolian_typedecl_alias_get_by_name(const char *name);
308const Eolian_Typedecl *eolian_typedecl_struct_get_by_name(const char *name);
309const Eolian_Typedecl *eolian_typedecl_enum_get_by_name(const char *name);
310Eina_Iterator *eolian_typedecl_aliases_get_by_file(const char *fname);
311Eina_Iterator *eolian_typedecl_structs_get_by_file(const char *fname);
312Eina_Iterator *eolian_typedecl_enums_get_by_file(const char *fname);
313Eolian_Typedecl_Type eolian_typedecl_type_get(const Eolian_Typedecl *tp);
314Eina_Iterator *eolian_typedecl_struct_fields_get(const Eolian_Typedecl *tp);
315const Eolian_Struct_Type_Field *eolian_typedecl_struct_field_get(const Eolian_Typedecl *tp, const char *field);
316Eina_Stringshare *eolian_typedecl_struct_field_name_get(const Eolian_Struct_Type_Field *fl);
317const Eolian_Documentation *eolian_typedecl_struct_field_documentation_get(const Eolian_Struct_Type_Field *fl);
318const Eolian_Type *eolian_typedecl_struct_field_type_get(const Eolian_Struct_Type_Field *fl);
319Eina_Iterator *eolian_typedecl_enum_fields_get(const Eolian_Typedecl *tp);
320const Eolian_Enum_Type_Field *eolian_typedecl_enum_field_get(const Eolian_Typedecl *tp, const char *field);
321Eina_Stringshare *eolian_typedecl_enum_field_name_get(const Eolian_Enum_Type_Field *fl);
322Eina_Stringshare *eolian_typedecl_enum_field_c_name_get(const Eolian_Enum_Type_Field *fl);
323const Eolian_Documentation *eolian_typedecl_enum_field_documentation_get(const Eolian_Enum_Type_Field *fl);
324const Eolian_Expression *eolian_typedecl_enum_field_value_get(const Eolian_Enum_Type_Field *fl, Eina_Bool force);
325Eina_Stringshare *eolian_typedecl_enum_legacy_prefix_get(const Eolian_Typedecl *tp);
326const Eolian_Documentation *eolian_typedecl_documentation_get(const Eolian_Typedecl *tp);
327Eina_Stringshare *eolian_typedecl_file_get(const Eolian_Typedecl *tp);
328const Eolian_Type *eolian_typedecl_base_type_get(const Eolian_Typedecl *tp);
329const Eolian_Type *eolian_typedecl_aliased_base_get(const Eolian_Typedecl *tp);
330Eina_Bool eolian_typedecl_is_extern(const Eolian_Typedecl *tp);
331Eina_Stringshare *eolian_typedecl_c_type_named_get(const Eolian_Typedecl *tp, const char *name);
332Eina_Stringshare *eolian_typedecl_c_type_get(const Eolian_Typedecl *tp);
333Eina_Stringshare *eolian_typedecl_name_get(const Eolian_Typedecl *tp);
334Eina_Stringshare *eolian_typedecl_full_name_get(const Eolian_Typedecl *tp);
335Eina_Iterator *eolian_typedecl_namespaces_get(const Eolian_Typedecl *tp);
336Eina_Stringshare *eolian_typedecl_free_func_get(const Eolian_Typedecl *tp);
337
338// type
339Eolian_Type_Type eolian_type_type_get(const Eolian_Type *tp);
340Eina_Iterator *eolian_type_subtypes_get(const Eolian_Type *tp);
341Eina_Stringshare *eolian_type_file_get(const Eolian_Type *tp);
342const Eolian_Type *eolian_type_base_type_get(const Eolian_Type *tp);
343const Eolian_Typedecl *eolian_type_typedecl_get(const Eolian_Type *tp);
344const Eolian_Type *eolian_type_aliased_base_get(const Eolian_Type *tp);
345const Eolian_Class *eolian_type_class_get(const Eolian_Type *tp);
346Eina_Bool eolian_type_is_own(const Eolian_Type *tp);
347Eina_Bool eolian_type_is_const(const Eolian_Type *tp);
348Eina_Stringshare *eolian_type_c_type_named_get(const Eolian_Type *tp, const char *name);
349Eina_Stringshare *eolian_type_c_type_get(const Eolian_Type *tp);
350Eina_Stringshare *eolian_type_name_get(const Eolian_Type *tp);
351Eina_Stringshare *eolian_type_full_name_get(const Eolian_Type *tp);
352Eina_Iterator *eolian_type_namespaces_get(const Eolian_Type *tp);
353Eina_Stringshare *eolian_type_free_func_get(const Eolian_Type *tp);
354
355// expression
356Eolian_Value eolian_expression_eval(const Eolian_Expression *expr, Eolian_Expression_Mask m);
357Eolian_Value eolian_expression_eval_type(const Eolian_Expression *expr, const Eolian_Type *type);
358Eina_Stringshare *eolian_expression_value_to_literal(const Eolian_Value *v);
359Eina_Stringshare *eolian_expression_serialize(const Eolian_Expression *expr);
360Eolian_Expression_Type eolian_expression_type_get(const Eolian_Expression *expr);
361Eolian_Binary_Operator eolian_expression_binary_operator_get(const Eolian_Expression *expr);
362const Eolian_Expression *eolian_expression_binary_lhs_get(const Eolian_Expression *expr);
363const Eolian_Expression *eolian_expression_binary_rhs_get(const Eolian_Expression *expr);
364Eolian_Unary_Operator eolian_expression_unary_operator_get(const Eolian_Expression *expr);
365const Eolian_Expression *eolian_expression_unary_expression_get(const Eolian_Expression *expr);
366Eolian_Value eolian_expression_value_get(const Eolian_Expression *expr);
367
368// variable
369const Eolian_Variable *eolian_variable_global_get_by_name(const char *name);
370const Eolian_Variable *eolian_variable_constant_get_by_name(const char *name);
371Eina_Iterator *eolian_variable_globals_get_by_file(const char *fname);
372Eina_Iterator *eolian_variable_constants_get_by_file(const char *fname);
373Eolian_Variable_Type eolian_variable_type_get(const Eolian_Variable *var);
374const Eolian_Documentation *eolian_variable_documentation_get(const Eolian_Variable *var);
375Eina_Stringshare *eolian_variable_file_get(const Eolian_Variable *var);
376const Eolian_Type *eolian_variable_base_type_get(const Eolian_Variable *var);
377const Eolian_Expression *eolian_variable_value_get(const Eolian_Variable *var);
378Eina_Stringshare *eolian_variable_name_get(const Eolian_Variable *var);
379Eina_Stringshare *eolian_variable_full_name_get(const Eolian_Variable *var);
380Eina_Iterator *eolian_variable_namespaces_get(const Eolian_Variable *var);
381Eina_Bool eolian_variable_is_extern(const Eolian_Variable *var);
382
383// declaration
384const Eolian_Declaration *eolian_declaration_get_by_name(const char *name);
385Eina_Iterator *eolian_declarations_get_by_file(const char *fname);
386Eolian_Declaration_Type eolian_declaration_type_get(const Eolian_Declaration *decl);
387Eina_Stringshare *eolian_declaration_name_get(const Eolian_Declaration *decl);
388const Eolian_Class *eolian_declaration_class_get(const Eolian_Declaration *decl);
389const Eolian_Typedecl *eolian_declaration_data_type_get(const Eolian_Declaration *decl);
390const Eolian_Variable *eolian_declaration_variable_get(const Eolian_Declaration *decl);
391
392// documentation
393Eina_Stringshare *eolian_documentation_summary_get(const Eolian_Documentation *doc);
394Eina_Stringshare *eolian_documentation_description_get(const Eolian_Documentation *doc);
395Eina_Stringshare *eolian_documentation_since_get(const Eolian_Documentation *doc);
diff --git a/pyolian/eolian.py b/pyolian/eolian.py
new file mode 100644
index 0000000..43bd56e
--- /dev/null
+++ b/pyolian/eolian.py
@@ -0,0 +1,559 @@
1###############################################################################
2### THIS FILE IS MANUALLY WRITTEN ###
3###############################################################################
4
5from __future__ import absolute_import, print_function, division
6
7from cffi import FFI
8import os
9
10ffi = FFI()
11
12
13with open(os.path.join(os.path.dirname(__file__), 'eolian.h')) as f:
14 ffi.cdef(f.read())
15
16lib = ffi.dlopen('eolian')
17
18# arg = ffi.new("char[]", "world") # equivalent to C code: char arg[] = "world";
19# lib.printf("hi there, %s.\n", arg) # call printf
20
21
22### utils (TO BE SHARED) ####################################################
23import sys
24
25PY2 = sys.version_info[0] == 2
26PY3 = sys.version_info[0] == 3
27
28if PY3:
29 text_type = str
30 binary_type = bytes
31else:
32 text_type = unicode
33 binary_type = str
34
35def _pystr_to_bytes(s):
36 if isinstance(s, binary_type):
37 return s
38 return text_type(s).encode('utf-8')
39
40
41def _cstr_to_unicode(ffi, s):
42 if s == ffi.NULL:
43 return None
44 s = ffi.string(s)
45 if isinstance(s, text_type):
46 return s
47 return binary_type(s).decode('utf-8')
48
49def _cstr_to_unicode2(s):
50 if s == ffi.NULL:
51 return None
52 s = ffi.string(ffi.cast('char *', s))
53 if isinstance(s, text_type):
54 return s
55 return binary_type(s).decode('utf-8')
56
57"""
58cdef class EoIterator:
59
60 def __iter__(self):
61 return self
62
63 def __next__(self):
64 cdef:
65 void* tmp
66 Eina_Bool result
67
68 if not eina_iterator_next(self.itr, &tmp):
69 raise StopIteration
70
71 return object_from_instance(<cEo *>tmp)
72
73 def __dealloc__(self):
74 eina_iterator_free(self.itr)
75"""
76
77class Iterator:
78 def __init__(self, conv_func, iter_obj):
79 self.next = self.__next__ # py2 compat
80 self._conv = conv_func
81 self._iter = iter_obj
82 self._tmp = ffi.new('void*[1]')
83
84 def __iter__(self):
85 return self
86
87 def __next__(self):
88 if not lib.eina_iterator_next(self._iter, self._tmp):
89 lib.eina_iterator_free(self._iter)
90 raise StopIteration
91
92 return self._conv(self._tmp[0])
93
94 def free(self):
95 lib.eina_iterator_free(self._iter)
96
97PY_KW = ['in']
98
99def _c_eolian_event_to_py(f):
100 return Event(f)
101
102def _c_eolian_function_to_py(f):
103 return Function(f)
104
105def _c_eolian_constructor_to_py(f):
106 return Constructor(f)
107
108def _c_eolian_parameter_to_py(p):
109 return Parameter(p)
110
111def _c_eolian_typedecl_to_py(t):
112 return Typedecl(t)
113
114def _c_eolian_enum_field_to_py(f):
115 return Enum_Type_Field(f)
116
117def _c_eolian_declaration_to_py(f):
118 return Declaration(f)
119
120### module init/shutdown ####################################################
121import atexit
122lib.eolian_init()
123atexit.register(lambda: lib.eolian_shutdown())
124
125
126### enums ###################################################################
127
128# Eolian_Function_Type:
129EOLIAN_UNRESOLVED = lib.EOLIAN_UNRESOLVED
130EOLIAN_PROPERTY = lib.EOLIAN_PROPERTY
131EOLIAN_PROP_SET = lib.EOLIAN_PROP_SET
132EOLIAN_PROP_GET = lib.EOLIAN_PROP_GET
133EOLIAN_METHOD = lib.EOLIAN_METHOD
134
135# Eolian_Class_Type:
136EOLIAN_CLASS_UNKNOWN_TYPE = lib.EOLIAN_CLASS_UNKNOWN_TYPE
137EOLIAN_CLASS_REGULAR = lib.EOLIAN_CLASS_REGULAR
138EOLIAN_CLASS_ABSTRACT = lib.EOLIAN_CLASS_ABSTRACT
139EOLIAN_CLASS_MIXIN = lib.EOLIAN_CLASS_MIXIN
140EOLIAN_CLASS_INTERFACE = lib.EOLIAN_CLASS_INTERFACE
141
142# Eolian_Declaration_Type:
143EOLIAN_DECL_UNKNOWN = lib.EOLIAN_DECL_UNKNOWN
144EOLIAN_DECL_CLASS = lib.EOLIAN_DECL_CLASS
145EOLIAN_DECL_ALIAS = lib.EOLIAN_DECL_ALIAS
146EOLIAN_DECL_STRUCT = lib.EOLIAN_DECL_STRUCT
147EOLIAN_DECL_ENUM = lib.EOLIAN_DECL_ENUM
148EOLIAN_DECL_VAR = lib.EOLIAN_DECL_VAR
149
150# Eolian_Parameter_Dir:
151EOLIAN_IN_PARAM = lib.EOLIAN_IN_PARAM
152EOLIAN_OUT_PARAM = lib.EOLIAN_OUT_PARAM
153EOLIAN_INOUT_PARAM = lib.EOLIAN_INOUT_PARAM
154
155# Eolian_Type_Type:
156EOLIAN_TYPE_UNKNOWN_TYPE = lib.EOLIAN_TYPE_UNKNOWN_TYPE
157EOLIAN_TYPE_VOID = lib.EOLIAN_TYPE_VOID
158EOLIAN_TYPE_REGULAR = lib.EOLIAN_TYPE_REGULAR
159EOLIAN_TYPE_COMPLEX = lib.EOLIAN_TYPE_COMPLEX
160EOLIAN_TYPE_POINTER = lib.EOLIAN_TYPE_POINTER
161EOLIAN_TYPE_CLASS = lib.EOLIAN_TYPE_CLASS
162EOLIAN_TYPE_UNDEFINED = lib.EOLIAN_TYPE_UNDEFINED
163
164# Eolian_Typedecl_Type:
165EOLIAN_TYPEDECL_UNKNOWN = lib.EOLIAN_TYPEDECL_UNKNOWN
166EOLIAN_TYPEDECL_STRUCT = lib.EOLIAN_TYPEDECL_STRUCT
167EOLIAN_TYPEDECL_STRUCT_OPAQUE = lib.EOLIAN_TYPEDECL_STRUCT_OPAQUE
168EOLIAN_TYPEDECL_ENUM = lib.EOLIAN_TYPEDECL_ENUM
169EOLIAN_TYPEDECL_ALIAS = lib.EOLIAN_TYPEDECL_ALIAS
170
171### module level functions ###################################################
172def file_parse(fname):
173 return bool(lib.eolian_file_parse(_pystr_to_bytes(fname)))
174
175def all_eot_files_parse():
176 return bool(lib.eolian_all_eot_files_parse())
177
178def system_directory_scan():
179 return bool(lib.eolian_system_directory_scan())
180
181def database_validate(silent_types=False):
182 return bool(lib.eolian_database_validate(silent_types))
183
184def typedecl_enums_get_by_file(fname):
185 return Iterator(_c_eolian_typedecl_to_py, lib.eolian_typedecl_enums_get_by_file(fname))
186
187def declarations_get_by_file(fname):
188 return Iterator(_c_eolian_declaration_to_py, lib.eolian_declarations_get_by_file(fname))
189# Eina_Iterator *eolian_declarations_get_by_file(const char *fname);
190
191### eolian.Class ############################################################
192
193class Class(object):
194 def __init__(self, eo_file=None, c_class=None):
195 if eo_file:
196 eo_file = _pystr_to_bytes(eo_file)
197 self._obj = lib.eolian_class_get_by_file(eo_file) # const Eolian_Class *
198 elif c_class:
199 self._obj = c_class
200 else:
201 ERR('Invalid Class constructor')
202
203
204 def __repr__(self):
205 return "<eolian.Class '{0.full_name}', prefix '{0.eo_prefix}'>".format(self)
206
207 @property
208 def name(self):
209 return _cstr_to_unicode(ffi, lib.eolian_class_name_get(self._obj))
210
211 @property
212 def full_name(self):
213 return _cstr_to_unicode(ffi, lib.eolian_class_full_name_get(self._obj))
214
215 @property
216 def type(self):
217 return lib.eolian_class_type_get(self._obj)
218 # Eolian_Class_Type eolian_class_type_get(const Eolian_Class *klass);
219 @property
220 def legacy_prefix(self):
221 return _cstr_to_unicode(ffi, lib.eolian_class_legacy_prefix_get(self._obj))
222
223 @property
224 def eo_prefix(self):
225 return _cstr_to_unicode(ffi, lib.eolian_class_eo_prefix_get(self._obj))
226
227 @property
228 def data_type(self):
229 return _cstr_to_unicode(ffi, lib.eolian_class_data_type_get(self._obj))
230
231 @property
232 def inherits(self):
233 return Iterator(_cstr_to_unicode2, lib.eolian_class_inherits_get(self._obj))
234
235 @property
236 def c_get_function_name(self):
237 return _cstr_to_unicode(ffi, lib.eolian_class_c_get_function_name_get(self._obj))
238
239 @property
240 def ctor_enable(self):
241 return bool(lib.eolian_class_ctor_enable_get(self._obj))
242
243 @property
244 def constructors(self):
245 return Iterator(_c_eolian_constructor_to_py, lib.eolian_class_constructors_get(self._obj))
246
247 @property
248 def events(self):
249 return Iterator(_c_eolian_event_to_py, lib.eolian_class_events_get(self._obj))
250
251 @property
252 def methods(self):
253 return Iterator(_c_eolian_function_to_py, lib.eolian_class_functions_get(self._obj, lib.EOLIAN_METHOD))
254
255 @property
256 def properties(self):
257 return Iterator(_c_eolian_function_to_py, lib.eolian_class_functions_get(self._obj, lib.EOLIAN_PROPERTY))
258
259 @property
260 def getters(self):
261 return Iterator(_c_eolian_function_to_py, lib.eolian_class_functions_get(self._obj, lib.EOLIAN_PROP_GET))
262
263 @property
264 def setters(self):
265 return Iterator(_c_eolian_function_to_py, lib.eolian_class_functions_get(self._obj, lib.EOLIAN_PROP_SET))
266
267
268class Constructor(object):
269 def __init__(self, c_ctor):
270 self._obj = c_ctor # const Eolian_Constructor *
271
272 def __repr__(self):
273 return "<eolian.Constructor '{0.full_name}', optional: {0.is_optional}>".format(self)
274
275 @property
276 def full_name(self):
277 return _cstr_to_unicode(ffi, lib.eolian_constructor_full_name_get(self._obj))
278
279 @property
280 def function(self):
281 return Function(lib.eolian_constructor_function_get(self._obj))
282
283 @property
284 def is_optional(self):
285 return bool(lib.eolian_constructor_is_optional(self._obj))
286
287
288class Event(object):
289 def __init__(self, c_event):
290 self._obj = c_event # const Eolian_Event *
291
292 def __repr__(self):
293 return "<eolian.Event '{0.name}', api: '{0.c_name}'>".format(self)
294
295 # @property
296 # def type(self):
297 # return lib.eolian_function_type_get(self._obj)
298
299 @property
300 def name(self):
301 return _cstr_to_unicode(ffi, lib.eolian_event_name_get(self._obj))
302
303 @property
304 def c_name(self):
305 return _cstr_to_unicode(ffi, lib.eolian_event_c_name_get(self._obj))
306
307
308class Function(object):
309 def __init__(self, c_func):
310 self._obj = c_func # const Eolian_Function *
311
312 def __repr__(self):
313 return "<eolian.Function '{0.name}'>".format(self)
314
315 @property
316 def type(self):
317 return lib.eolian_function_type_get(self._obj)
318
319 @property
320 def name(self):
321 return _cstr_to_unicode(ffi, lib.eolian_function_name_get(self._obj))
322
323 def full_c_name_get(self, ftype, uselegacy=False):
324 return _cstr_to_unicode(ffi, lib.eolian_function_full_c_name_get(self._obj, ftype, uselegacy))
325
326 @property
327 def is_constructor(self):
328 return lib.eolian_function_is_constructor(self._obj, lib.eolian_function_class_get(self._obj))
329
330 @property
331 def is_c_only(self):
332 return bool(lib.eolian_function_is_c_only(self._obj))
333
334 def is_legacy_only_get(self, ftype):
335 return bool(lib.eolian_function_is_legacy_only(self._obj, ftype))
336
337 @property
338 def parameters(self):
339 return Iterator(_c_eolian_parameter_to_py, lib.eolian_function_parameters_get(self._obj))
340
341 @property
342 def getter_values(self):
343 return Iterator(_c_eolian_parameter_to_py, lib.eolian_property_values_get(self._obj, lib.EOLIAN_PROP_GET))
344
345 @property
346 def setter_values(self):
347 return Iterator(_c_eolian_parameter_to_py, lib.eolian_property_values_get(self._obj, lib.EOLIAN_PROP_SET))
348
349 # @property
350 # def return_type(self):
351 # t = lib.eolian_function_return_type_get(self._obj, lib.EOLIAN_PROPERTY) ####### WRONG
352 # if t != ffi.NULL:
353 # return Type(t)
354
355 def return_type_get(self, ftype):
356 t = lib.eolian_function_return_type_get(self._obj, ftype)
357 if t != ffi.NULL:
358 return Type(t)
359
360 def full_c_define_get(self, ftype):
361 # TODO: move this code to generator.py
362 rtype = self.return_type_get(ftype)
363 ret = rtype.c_type if rtype is not None else 'void'
364
365 c_pars = ['Eo *obj']
366 if ftype == EOLIAN_METHOD: pars = list(self.parameters)
367 elif ftype == EOLIAN_PROP_GET: pars = list(self.getter_values)
368 elif ftype == EOLIAN_PROP_SET: pars = list(self.setter_values)
369 else: raise RuntimeError('Unsupported function type: %d' % ftype)
370 for p in pars:
371 if ftype == EOLIAN_PROP_GET:
372 if len(pars) > 1:
373 c_pars.append('{0.type.c_type} *{0.name}'.format(p))
374 else:
375 c_pars.append('{0.type.c_type} {0.name}'.format(p))
376
377 c_pars = ', '.join(c_pars)
378 return '{0} {1}({2})'.format(ret, self.full_c_name_get(ftype), c_pars)
379
380
381class Parameter(object):
382 def __init__(self, c_param):
383 self._obj = c_param # const Eolian_Parameter *
384
385 def __repr__(self):
386 return "<eolian.Parameter '{0.name}', {0.direction_str}, type: {0.type}," \
387 "optional: {0.is_optional}, nonull: {0.is_nonull}>".format(self)
388
389 # @property
390 # def name(self):
391 # return _cstr_to_unicode(ffi, lib.eolian_parameter_name_get(self._obj))
392
393 @property
394 def name_fixed(self):
395 name = _cstr_to_unicode(ffi, lib.eolian_parameter_name_get(self._obj))
396 if name in PY_KW:
397 return name + '_'
398 return name
399
400 name = name_fixed
401
402 @property
403 def direction(self):
404 return lib.eolian_parameter_direction_get(self._obj)
405
406 @property
407 def direction_str(self):
408 direction = lib.eolian_parameter_direction_get(self._obj)
409 if direction == EOLIAN_IN_PARAM: return 'in'
410 if direction == EOLIAN_OUT_PARAM: return 'out'
411 if direction == EOLIAN_INOUT_PARAM: return 'inout'
412
413 @property
414 def is_nonull(self):
415 return bool(lib.eolian_parameter_is_nonull(self._obj))
416
417 @property
418 def is_nullable(self):
419 return bool(lib.eolian_parameter_is_nullable(self._obj))
420
421 @property
422 def is_optional(self):
423 return bool(lib.eolian_parameter_is_optional(self._obj))
424
425 @property
426 def type(self):
427 return Type(lib.eolian_parameter_type_get(self._obj))
428
429
430class Type(object):
431 def __init__(self, c_type):
432 self._obj = c_type # const Eolian_Type *
433
434 def __repr__(self):
435 return "<eolian.Type '{0.full_name}', type: {0.type}, c_type: '{0.c_type}'>".format(self)
436
437 @property
438 def name(self):
439 return _cstr_to_unicode(ffi, lib.eolian_type_name_get(self._obj))
440
441 @property
442 def name2(self):
443 return self.name or self.c_type
444
445 @property
446 def full_name(self):
447 return _cstr_to_unicode(ffi, lib.eolian_type_full_name_get(self._obj))
448
449 @property
450 def type(self):
451 return lib.eolian_type_type_get(self._obj)
452
453 @property
454 def c_type(self):
455 return _cstr_to_unicode(ffi, lib.eolian_type_c_type_get(self._obj))
456
457 @property
458 def base_type(self):
459 return Type(lib.eolian_type_base_type_get(self._obj))
460
461 @property
462 def typedecl(self):
463 c_typedecl = lib.eolian_type_typedecl_get(self._obj)
464 return Typedecl(c_typedecl) if c_typedecl != ffi.NULL else None
465
466 @property
467 def aliased_base(self):
468 c_type = lib.eolian_type_aliased_base_get(self._obj)
469 return Type(c_type) if c_type != ffi.NULL else None
470
471
472
473
474class Typedecl(object):
475 def __init__(self, c_typedecl):
476 self._obj = c_typedecl # const Eolian_Typedecl *
477
478 def __repr__(self):
479 return "<eolian.Typedecl '{0.name}'>".format(self)
480
481 @property
482 def name(self):
483 return _cstr_to_unicode(ffi, lib.eolian_typedecl_name_get(self._obj))
484
485 @property
486 def full_name(self):
487 return _cstr_to_unicode(ffi, lib.eolian_typedecl_full_name_get(self._obj))
488
489 @property
490 def c_type(self):
491 return _cstr_to_unicode(ffi, lib.eolian_typedecl_c_type_get(self._obj))
492
493 @property
494 def enum_fields(self):
495 return Iterator(_c_eolian_enum_field_to_py, lib.eolian_typedecl_enum_fields_get(self._obj))
496
497 @property
498 def type(self):
499 return lib.eolian_typedecl_type_get(self._obj)
500
501
502class Enum_Type_Field(object):
503 def __init__(self, c_enum_field):
504 self._obj = c_enum_field # const Eolian_Enum_Type_Field *
505
506 def __repr__(self):
507 return "<eolian.Enum_Type_Field '{0.name}', api: '{0.c_name}'>".format(self)
508
509 @property
510 def name(self):
511 return _cstr_to_unicode(ffi, lib.eolian_typedecl_enum_field_name_get(self._obj))
512
513 @property
514 def c_name(self):
515 return _cstr_to_unicode(ffi, lib.eolian_typedecl_enum_field_c_name_get(self._obj))
516
517
518class Declaration(object):
519 def __init__(self, c_decl):
520 self._obj = c_decl # const Eolian_Declaration *
521
522 def __repr__(self):
523 return "<eolian.Declaration '{0.name}', type: {0.type}>".format(self)
524
525 @property
526 def name(self):
527 return _cstr_to_unicode(ffi, lib.eolian_declaration_name_get(self._obj))
528
529 @property
530 def type(self):
531 return lib.eolian_declaration_type_get(self._obj)
532
533 @property
534 def data_type(self):
535 return Typedecl(lib.eolian_declaration_data_type_get(self._obj))
536
537 @property
538 def variable(self):
539 return Variable(lib.eolian_declaration_variable_get(self._obj))
540
541 @property
542 def class_(self):
543 return Class(c_class=lib.eolian_declaration_class_get(self._obj))
544
545
546class Variable(object):
547 def __init__(self, c_var):
548 self._obj = c_var # const Eolian_Variable *
549
550 def __repr__(self):
551 return "<eolian.Variable '{0.name}', type: {0.data_type}>".format(self)
552
553 @property
554 def name(self):
555 return _cstr_to_unicode(ffi, lib.eolian_variable_name_get(self._obj))
556
557 @property
558 def full_name(self):
559 return _cstr_to_unicode(ffi, lib.eolian_variable_full_name_get(self._obj))
diff --git a/pyolian/generator.py b/pyolian/generator.py
new file mode 100644
index 0000000..e7d062b
--- /dev/null
+++ b/pyolian/generator.py
@@ -0,0 +1,643 @@
1###############################################################################
2####### THIS FILE IS MANUALLY WRITTEN #######
3###############################################################################
4
5from __future__ import absolute_import, print_function, division
6
7import os
8from os.path import relpath as REL
9import datetime
10
11from . import eolian
12
13# logging utils
14be_verbose = False
15def ERR(*args): print(*(('PYOLIAN ERROR:', ) + args))
16def WRN(*args): print(*(('PYOLIAN WARNING:', ) + args))
17def VRB(*args): print(*(('PYOLIAN ', ) + args)) if be_verbose else None
18def INF(*args): print(*(('PYOLIAN ', ) + args))
19
20
21def uncapitalize(s):
22 return s[0].lower() + s[1:]
23
24
25### Templates ###
26
27COPYRIGHT = """{0} Copyright (C) 2007-%d various contributors (see AUTHORS)
28{0}
29{0} This file is part of Python-EFL.
30{0}
31{0} Python-EFL is free software; you can redistribute it and/or
32{0} modify it under the terms of the GNU Lesser General Public
33{0} License as published by the Free Software Foundation; either
34{0} version 3 of the License, or (at your option) any later version.
35{0}
36{0} Python-EFL is distributed in the hope that it will be useful,
37{0} but WITHOUT ANY WARRANTY; without even the implied warranty of
38{0} MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
39{0} Lesser General Public License for more details.
40{0}
41{0} You should have received a copy of the GNU Lesser General Public License
42{0} along with this Python-EFL. If not, see <http://www.gnu.org/licenses/>.
43
44{0} {0} {0} {0}
45{0} {0} File automatically generated {0} {0}
46{0} {0} !!! DO NOT EDIT !!! {0} {0}
47{0} {0} {0} {0}
48""" % datetime.datetime.now().year
49
50PY_HEAD = """
51from efl2._efl_ffi import ffi, lib
52from efl2 import eo
53"""
54
55INIT_HEAD = """
56
57"""
58
59CLASS_TYPEDEF = """
60// {0} class
61typedef Eo {1};
62const Eo_Class *{2}(void);
63"""
64
65CLASS_DEF = """
66@eo._class_register('{0}')
67class {1}({2}):
68"""
69
70CLASS_CTOR_DEFAULT = """
71 def __init__(self, parent=None, **kargs):
72 eo.Base.__init__(self, lib.{}(), parent, **kargs)
73"""
74
75CLASS_METHOD_RET = """
76 def {0}({1}):
77 \""" {2} \"""
78 return {3}
79"""
80
81CLASS_METHOD_NORET = """
82 def {0}({1}):
83 \""" {2} \"""
84 lib.{3}({4})
85"""
86
87CLASS_METHOD = """
88 def {0}({1}):
89 \""" {2} \"""
90"""
91
92CLASS_GETTER = """
93 def {0}_get(self):
94 \""" {1} \"""
95"""
96
97CLASS_SETTER = """
98 def {0}_set(self, {1}):
99 \""" {2} \"""
100"""
101
102MANUAL_CONSTRUCTORS = {
103'Elm.Win': """
104 def __init__(self, name, type, *args, **kargs):
105 # custom constructor
106 eo.Base.__init__(self, lib.ELM_WIN_CLASS, ffi.NULL, False)
107 lib.elm_obj_win_type_set(self._obj, type)
108 lib.elm_obj_win_name_set(self._obj, _to_bytes(name))
109 eo.Base.__init__end__(self, **kargs)
110
111 print("Win INIT")
112""",
113'Ecore.Timer': """
114 def __init__(self, in_, callback, *args, **kargs):
115
116 userdata = ffi.new_handle(self)
117
118 # custom constructor
119 eo.Base.__init__(self, lib.ecore_timer_class_get(), None, False)
120 lib.ecore_obj_timer_constructor(self._obj, in_, lib._timer_cb, userdata)
121 eo.Base.__init__end__(self, **kargs)
122
123 # print("Timer INIT", in_)
124
125 self._priv['self_h'] = userdata # must keep this alive! :/
126 self._priv['cb'] = callback
127 self._priv['cb_args'] = args
128 self._priv['cb_kargs'] = kargs
129""",
130}
131
132MANUAL_EXCLUDES = [
133'ecore_mainloop_select_func_get', # type @extern Ecore_Select_Function: __undefined_type;
134# 'elm_obj_widget_event_callback_del', # return void *
135# 'elm_obj_win_illume_command_send', # eolian.Type 'Elm.Illume_Command'
136# 'evas_obj_clipees_get', # return Eina_List *
137# 'evas_obj_smart_data_get', # return void *
138# 'evas_obj_map_get', # const Evas_Map *
139]
140
141
142class Generator(object):
143 def __init__(self, main_py_path, headers_path, verbose=False):
144 global be_verbose
145 be_verbose = verbose
146 self.main_py_path = main_py_path
147 self.headers_path = headers_path
148
149 INF('generator startup')
150 INF('path for python files:', self.main_py_path)
151 INF('path for cffi headers:', self.headers_path)
152
153 self.already_started_py_files = set()
154 self.already_started_header_files = set()
155 self.already_started_init_files = set()
156
157 def generate_all(self):
158 INF('system directory scan')
159 if not eolian.system_directory_scan():
160 ERR('Failed to scan system directories')
161 return False
162
163 INF('parsing all EOT files')
164 if not eolian.all_eot_files_parse():
165 ERR('Failed to parse EOT files')
166 return False
167
168 ret = self.generate_eo_file('ecore_mainloop.eo', 'ecore')
169 ret = self.generate_eo_file('ecore_timer.eo', 'ecore')
170 # ret = self.generate_eo_file('efl_gfx_base.eo', 'gfx') # should be efl/gfx
171 # ret = self.generate_eo_file('evas_object.eo', 'evas')
172 # ret = self.generate_eo_file('elm_widget.eo', 'elm')
173 # ret = self.generate_eo_file('elm_win.eo', 'elm')
174 # ret = self.generate_eo_file('elm_label.eo', 'elm')
175
176 INF('generation complete')
177 return ret
178
179 def generate_eo_file(self, eo_fname, py_pkg):
180 VRB('=' * 79)
181 INF('generating from: ', eo_fname)
182
183 if not eolian.file_parse(eo_fname):
184 ERR('Failed parsing file')
185 return False
186
187 if not eolian.database_validate():
188 ERR('Failed validating database.')
189 return False
190
191 # header file
192 header_fname = os.path.join(self.headers_path, eo_fname.replace('.eo', '.h'))
193 VRB('to header: ', REL(header_fname))
194
195 # package __init__.py file
196 py_pkg = os.path.join(self.main_py_path, py_pkg)
197 if not os.path.exists(py_pkg):
198 VRB('creating python package:', REL(py_pkg))
199 os.makedirs(py_pkg)
200 init_fname = os.path.join(py_pkg, '__init__.py')
201 VRB('to package: ', REL(init_fname))
202
203 # python file
204 py_fname = os.path.join(py_pkg, eo_fname.replace('.eo', '.py'))
205 VRB('to python: ', REL(py_fname))
206
207
208 # open initf
209 mode = 'a' if init_fname in self.already_started_init_files else 'w'
210 with open(init_fname, mode) as initf:
211 if mode == 'w':
212 initf.write(COPYRIGHT.format('#'))
213 initf.write(INIT_HEAD)
214
215 # open headerf
216 mode = 'a' if header_fname in self.already_started_header_files else 'w'
217 with open(header_fname, mode) as headerf:
218 if mode == 'w':
219 headerf.write(COPYRIGHT.format('//'))
220
221 # open pythonf (f)
222 mode = 'a' if py_fname in self.already_started_py_files else 'w'
223 with open(py_fname, mode) as f:
224 if mode == 'w':
225 f.write(COPYRIGHT.format('#'))
226 f.write(PY_HEAD.format('#'))
227
228 ### generate all ###
229 self.emit_enums(eo_fname, f, headerf, initf)
230 self.emit_typedefs(eo_fname, f, headerf, initf)
231 self.emit_class(eo_fname, f, headerf, initf)#, excludes)
232
233 initf.write('from .{} import *\n'.format(eo_fname.replace('.eo', '')))
234
235 self.already_started_py_files.add(py_fname)
236 self.already_started_header_files.add(header_fname)
237 self.already_started_init_files.add(init_fname)
238
239 return True
240
241 def emit_enums(self, eo_fname, f, headerf, initf):
242 # TODO generate "new style" Enums instead
243 for enum in eolian.typedecl_enums_get_by_file(eo_fname):
244 c_name = enum.full_name.replace('.', '_')
245 VRB('gen enum:', enum.full_name)
246 f.write('\n# enum: {0}\n'.format(enum.full_name))
247 headerf.write('\ntypedef enum {\n')
248 for field in enum.enum_fields:
249 headerf.write(' {0},\n'.format(field.c_name))
250 f.write('{0} = lib.{0}\n'.format(field.c_name))
251 headerf.write(' ...\n')
252 headerf.write('}} {0};\n'.format(c_name))
253
254 def emit_typedefs(self, eo_fname, f, headerf, initf):
255 for d in eolian.declarations_get_by_file(eo_fname):
256 t = d.type
257 c_name = d.name.replace('.', '_')
258
259 if t == eolian.EOLIAN_DECL_CLASS:
260 VRB('gen class typedef:', d.name)
261 headerf.write(CLASS_TYPEDEF.format(d.name, c_name, d.class_.c_get_function_name))
262
263 elif t == eolian.EOLIAN_DECL_ENUM:
264 # headerf.write('typedef enum _{0} {0};\n'.format(c_name))
265 pass
266
267 else:
268 WRN('Unknow typedef type: ', t)
269
270 def emit_class(self, eo_fname, f, headerf, initf):
271 klass = eolian.Class(eo_fname)
272 VRB('gen class:', klass.full_name)
273
274 ### Class definition (change "Efl.Gfx.Base" to "efl.gfx.Base")
275 # TODO: fix to lowercase ALL the names (except the last)
276 inherits = ', '.join( [ uncapitalize(c) for c in klass.inherits ]) or 'object'
277 f.write(CLASS_DEF.format(klass.full_name, klass.name, inherits))
278
279 ### Events
280 py_code, h_code = '', ''
281 for ev in klass.events:
282 VRB('gen event:', ev.c_name)
283 py_code += " '{0.name}': lib.{0.c_name},\n".format(ev)
284 h_code += 'extern static Eo_Event_Description *const {};\n'.format(ev.c_name)
285
286 if py_code != '':
287 f.write(' __events = {{\n{} }}\n'.format(py_code))
288 headerf.write('\n// {} events\n{}\n'.format(klass.full_name, h_code))
289
290 ### Constructor
291 if klass.type == eolian.EOLIAN_CLASS_REGULAR:
292 self.emit_constructor(klass, f, headerf)
293
294 ### Methods
295 f.write('\n # methods\n')
296 headerf.write('// {} methods\n'.format(klass.full_name))
297 for func in sorted(klass.methods, key=lambda f: f.name):
298
299 if func.is_c_only:
300 print('C only - ' * 7) # TODO REMOVE ME
301 continue
302
303 if func.full_c_name_get(eolian.EOLIAN_METHOD) in MANUAL_EXCLUDES:
304 VRB('SKIPPED', func.full_c_name_get(eolian.EOLIAN_METHOD))
305 continue
306
307 if func.is_constructor:
308 continue
309
310 self.emit_function(klass, func, eolian.EOLIAN_METHOD, f, headerf)
311
312 # header file
313 # headerf.write('{};\n'.format(func.full_c_define_get(eolian.EOLIAN_METHOD)))
314
315 ### Properties
316 f.write('\n # properties\n')
317 headerf.write('\n// {} properties\n'.format(klass.full_name))
318 for func in sorted(klass.properties, key=lambda f: f.name):
319
320 if func.is_c_only:
321 print('C only - ' * 7) # TODO REMOVE ME
322 continue
323
324 if func.full_c_name_get(eolian.EOLIAN_PROPERTY) in MANUAL_EXCLUDES:
325 VRB('SKIPPED', func.full_c_name_get(eolian.EOLIAN_PROPERTY))
326 continue
327
328
329 ftype = func.type
330 can_read = ftype in (eolian.EOLIAN_PROPERTY, eolian.EOLIAN_PROP_GET)
331 can_write = ftype in (eolian.EOLIAN_PROPERTY, eolian.EOLIAN_PROP_SET)
332 if can_read:
333 self.emit_getter(klass, func, f, headerf)
334 if can_write:
335 self.emit_setter(klass, func, f, headerf)
336 # self.emit_function(klass, func, eolian.EOLIAN_PROP_SET, f, headerf)
337
338 f.write('\n {0} = property({1}, {2})\n'.format(
339 func.name,
340 func.name + '_get' if can_read else 'None',
341 func.name + '_set' if can_write else 'None'))
342
343 # header file
344 # headerf.write('{};\n'.format(func.full_c_define_get(eolian.EOLIAN_PROP_GET)))
345
346
347 def emit_constructor(self, klass, f, headerf):
348 std = True
349 ctors_py_code = ''
350 for ctor in klass.constructors:
351 std = False
352
353 func = ctor.function
354 ctors_py_code += ' lib.{}(...)\n'.format(func.full_c_name_get(eolian.EOLIAN_METHOD))
355
356 # print(klass.ctor_enable)
357
358 # standard
359 if std:
360 VRB('generating standard constructor for class:', klass.full_name)
361 f.write(CLASS_CTOR_DEFAULT.format(klass.c_get_function_name))
362
363 # custom constructor, ...manually written for the moment
364 elif klass.full_name in MANUAL_CONSTRUCTORS:
365 f.write(MANUAL_CONSTRUCTORS[klass.full_name])
366 else:
367 ERR('cannot find manual constructor for class', klass.full_name)
368
369 def emit_function(self, klass, func, ftype, f, headerf):
370 # header file
371 headerf.write('{};\n'.format(func.full_c_define_get(ftype)))
372
373 # function name (for setter and getters)
374 if ftype == eolian.EOLIAN_PROP_GET:
375 name = func.name + '_get'
376 name2 = 'prop get'
377 elif ftype == eolian.EOLIAN_PROP_SET:
378 name = func.name + '_set'
379 name2 = 'prop set'
380 else:
381 name = func.name
382 name2 = 'method'
383
384 VRB('gen {}: {}.{}()'.format(name2, klass.full_name, name))
385
386 # split in and out params in 2 lists
387 in_pars = ['self']
388 out_pars = []
389 if ftype == eolian.EOLIAN_PROP_GET:
390 for v in func.getter_values:
391 out_pars.append(_type_conv(v.type, v.name, False))
392 elif ftype == eolian.EOLIAN_PROP_SET:
393 for v in func.setter_values:
394 in_pars.append(v.name)
395 else:
396 for p in func.parameters:
397 if p.direction == eolian.EOLIAN_IN_PARAM:
398 in_pars.append(p.name)
399 elif p.direction == eolian.EOLIAN_OUT_PARAM:
400 out_pars.append(_type_conv(p.type, p.name, False))
401
402 # function definition (+ docs)
403 in_pars = ', '.join(in_pars)
404 docs = 'TODO ' + func.full_c_define_get(ftype) # TODO
405 f.write(CLASS_METHOD.format(name, in_pars, docs))
406
407 # c function call (+ allocs)
408 self.emit_c_function_call(func, ftype, f)
409
410 # return a tuple with all the out args
411 if len(out_pars) > 1:
412 out_pars = ', '.join(out_pars)
413 f.write(' return tuple({})\n'.format(out_pars))
414 return
415
416 # or return the single out arg
417 if len(out_pars) == 1:
418 f.write(' return {}\n'.format(out_pars[0]))
419 return
420
421 # or return the value returned from the c call (converted)
422 rtype = func.return_type_get(ftype)
423 if rtype is not None:
424 f.write(' return {}\n'.format(_type_conv(rtype, 'ret', False)))
425
426 def emit_getter(self, klass, func, f, headerf):
427 VRB('gen prop get: {}.{}_get()'.format(klass.full_name, func.name))
428 vals = list(func.getter_values)
429
430 ### header file
431 headerf.write('{};\n'.format(func.full_c_define_get(eolian.EOLIAN_PROP_GET)))
432
433 ### function definition (+ docs)
434 docs = 'TODO ' + func.full_c_define_get(eolian.EOLIAN_PROP_GET) # TODO
435 f.write(CLASS_GETTER.format(func.name, docs))
436
437 ### c function call (+ allocs)
438 params = ['self._obj']
439 if len(vals) > 1:
440 for p in vals:
441 params.append(p.name)
442 f.write(' {0} = ffi.new("{1}[1]")\n'.format(p.name, p.type.c_type))
443
444 # c function call
445 rtype = func.return_type_get(eolian.EOLIAN_PROP_GET)
446 ret = '_ret_ = ' if rtype is not None else ''
447 f.write(' {}lib.{}({})\n'.format(ret,
448 func.full_c_name_get(eolian.EOLIAN_PROP_GET),
449 ', '.join(params)))
450
451 # return a tuple of all the values
452 if len(vals) > 1:
453 vals = ', '.join([ _type_conv(v.type, v.name, False) for v in vals ])
454 # out_pars = ', '.join(out_pars)
455 f.write(' return tuple({})\n'.format(vals))
456
457 # or return the single value
458 elif len(vals) == 1:
459 f.write(' return {}\n'.format(_type_conv(vals[0].type, vals[0].name, False)))
460
461 # or return the value returned by the c function
462 elif rtype:
463 f.write(' return {}\n'.format(_type_conv(rtype, '_ret_', False)))
464
465 def emit_setter(self, klass, func, f, headerf):
466
467 if func.name.startswith('smart_clipped_clipper'):
468 print("********************** SET")
469 print(list(func.parameters))
470 print(list(func.setter_values))
471 print(func.return_type_get(eolian.EOLIAN_PROP_SET))
472
473 VRB('gen prop get: {}.{}_get()'.format(klass.full_name, func.name))
474 vals = list(func.setter_values)
475
476 ### header file
477 headerf.write('{};\n'.format(func.full_c_define_get(eolian.EOLIAN_PROP_SET)))
478
479 ### function definition (+ docs)
480 docs = 'TODO ' + func.full_c_define_get(eolian.EOLIAN_PROP_SET) # TODO
481 if len(vals) > 1:
482 val_name = '_val_'
483 elif len(vals) == 1:
484 val_name = vals[0].name
485 else:
486 raise RuntimeError('ASDASDASDASDASDASDASDASDASDASDASDASDASDASDASD')
487 f.write(CLASS_SETTER.format(func.name, val_name,docs))
488
489 ### unpack the tuple _val_
490 if len(vals) > 1:
491 vs = ', '.join([ v.name for v in vals])
492 f.write(' {} = _val_\n'.format(vs))
493
494 ### c function call
495 params = ['self._obj']
496 for p in func.setter_values:
497 params.append(_type_conv(p.type, p.name, True))
498
499 # c function call
500 rtype = func.return_type_get(eolian.EOLIAN_PROP_SET)
501 ret = '_ret_ = ' if rtype is not None else ''
502 f.write(' {}lib.{}({})\n'.format(ret,
503 func.full_c_name_get(eolian.EOLIAN_PROP_SET),
504 ', '.join(params)))
505
506 # or return the value returned by the c function
507 if rtype:
508 f.write(' return {}\n'.format(_type_conv(rtype, '_ret_', False)))
509
510 def emit_c_function_call(self, func, ftype, f, indent=8):
511 indent = ' ' * indent
512 params = ['self._obj']
513 allocs = []
514
515 ###################################################################
516 ###################################################################
517 # SIAMO QUI
518 # sistemare i parametri per i getter e setter
519 ###################################################################
520 ###################################################################
521 if ftype == eolian.EOLIAN_METHOD: pars = func.parameters
522 elif ftype == eolian.EOLIAN_PROP_GET: pars = func.getter_values
523 elif ftype == eolian.EOLIAN_PROP_SET: pars = func.setter_values
524 else: raise RuntimeError('Unsupported function type: %d' % ftype)
525
526 for p in pars:
527 direction = p.direction
528 ptype = p.type
529 if direction == eolian.EOLIAN_IN_PARAM:
530 params.append(_type_conv(ptype, p.name, True))
531 elif direction == eolian.EOLIAN_OUT_PARAM:
532 allocs.append('{0} = ffi.new("{1}")'.format(p.name, ptype.c_type))
533 params.append('&' + p.name)
534 else:
535 WRN('Unsupported INOUT param direction')
536
537 for a in allocs:
538 f.write(indent + a + '\n')
539
540 params = ', '.join(params)
541 ret = ''
542 if func.return_type_get(ftype):# or ftype == eolian.EOLIAN_PROP_GET:
543 ret = 'ret = '
544
545 f.write(indent + '{}lib.{}({})\n'.format(ret, func.full_c_name_get(ftype), params))
546
547def _type_conv(ty, expr, isin):
548
549 # c->py or py->c
550 conv_dict = CONVERSIONS_FROM_PY if isin else CONVERSIONS_FROM_C
551
552 # use the base type (ex: Evas.Coord -> int)
553 ty = ty.aliased_base
554
555 # an eo object instance ?
556 if ty.type == eolian.EOLIAN_TYPE_POINTER:
557 if ty.base_type.type == eolian.EOLIAN_TYPE_CLASS:
558 return conv_dict['eo_objects'].format(expr)
559
560 # an enum ?
561 try:
562 if ty.typedecl.type == eolian.EOLIAN_TYPEDECL_ENUM:
563 return conv_dict['enums'].format(expr)
564 except AttributeError:
565 pass
566
567 # or just use the mapping dict
568 tname = ty.name2
569 try:
570 fmt = conv_dict[tname]
571 except:
572 raise RuntimeError('Unsupported conversion for type: %s' % ty)
573 # ERR('Unsupported conversion for type:\n', ty)
574 return 'XXXXXX(%s)' % tname #######################################################
575 else:
576 return fmt.format(expr)
577
578def _type_conv_py2c(ty, expr, isin):
579
580 # use the base type (ex: Evas.Coord -> int)
581 ty = ty.aliased_base
582
583 # an eo object instance ?
584 if ty.type == eolian.EOLIAN_TYPE_POINTER:
585 if ty.base_type.type == eolian.EOLIAN_TYPE_CLASS:
586 return CONVERSIONS_FROM_PY['eo_objects'].format(expr)
587
588 # an enum ?
589 try:
590 if ty.typedecl.type == eolian.EOLIAN_TYPEDECL_ENUM:
591 return CONVERSIONS_FROM_PY['enums'].format(expr)
592 except AttributeError:
593 pass
594
595 # or just use the mapping dict
596 tname = ty.name2
597 try:
598 fmt = CONVERSIONS_FROM_PY[tname]
599 except:
600 # raise RuntimeError('Unsupported conversion from py to c for type: %s' % ty)
601 ERR('Unsupported conversion from py to c for type:\n', ty)
602 return 'XXXXXX(%s)' % tname #######################################################
603 else:
604 return fmt.format(expr)
605
606# how to convert a python type to a c type (that can be passed to c functions)
607CONVERSIONS_FROM_PY = {
608 # default types (as reported by type.name2)
609 'int': 'int({0})', #just to typecheck
610 'ullong': 'int({0})',
611 'double': 'float({0})',
612 'bool': 'bool({0})', #just to typecheck
613 'const char *': '_to_bytes({0})',
614 # special "types"
615 'eo_objects': '{0}._obj',
616 'enums': '{0}',
617}
618
619# how to convert a C type to a python object
620CONVERSIONS_FROM_C = {
621 # default types (as reported by type.name2)
622 'int': 'int({0})',
623 'uint': 'int({0})',
624 'double': 'float({0})',
625 'bool': 'bool({0})',
626 'const char *': '_to_unicode(ffi, {0})',
627
628 # special "types"
629 'eo_objects': '_object_from_instance({0})', # TODO rename and implement _object_from_instance
630 'enums': '{0}',
631
632 # 'char': '{0}.decode("utf-8")',
633 # "Elm_Object_Item": 'object_item_to_python({0})',
634 # "Evas_Object": 'object_from_instance({0})',
635 # "Eo": 'object_from_instance({0})',
636}
637
638
639if __name__ == '__main__':
640
641 print('Usage: "python setup.py generate" from the package root dir.')
642
643
diff --git a/requirements-testing.txt b/requirements-testing.txt
new file mode 100644
index 0000000..1d1f747
--- /dev/null
+++ b/requirements-testing.txt
@@ -0,0 +1,3 @@
1pytest>=2.7
2cffi>=1.0
3tox>=1.7
diff --git a/setup.py b/setup.py
new file mode 100755
index 0000000..8d6c9df
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,92 @@
1#!/usr/bin/env python
2
3from __future__ import absolute_import, print_function, division
4
5import os
6import sys
7
8from setuptools import setup, find_packages, Command
9from setuptools.command.build_py import build_py
10from efl2 import __version__, __version_info__
11
12
13PATH = os.path.dirname(os.path.realpath(__file__))
14
15
16class Generate(Command):
17 """ run the eolian generator """
18 description = "generate the source code from eo descriptions"
19 user_options = [('svg', 'v', 'Super Verbose Generation')]
20
21 def initialize_options(self):
22 self.svg = False
23
24 def finalize_options(self):
25 pass
26
27 def run(self):
28 print('-'*60)
29 print('generating bindings source code using pyolian')
30 from pyolian.generator import Generator
31
32 if not Generator(main_py_path=os.path.join(PATH, 'efl2/'),
33 headers_path=os.path.join(PATH, 'efl2/cffi/'),
34 verbose=self.svg).generate_all():
35 print('\nSomething goes wrong, generation aborted.\n')
36 exit(1)
37
38 print('-'*60)
39
40
41class BuildPy(build_py):
42 def run(self):
43 self.run_command("generate")
44 build_py.run(self)
45
46
47setup(
48 name = 'python-efl2',
49 version = __version__,
50 fullname = 'Python bindings for Enlightenment Foundation Libraries',
51 description = 'Python bindings for Enlightenment Foundation Libraries',
52 long_description = open('README.rst', 'rt').read(),
53 author = 'Davide Andreoli, Kai Huuhko, and others',
54 author_email = 'dave@gurumeditation.it, kai.huuhko@gmail.com',
55 contact = 'Enlightenment developer mailing list',
56 contact_email = 'enlightenment-devel@lists.sourceforge.net',
57 url = 'http://www.enlightenment.org',
58 license = 'GNU Lesser General Public License (LGPL)',
59 keywords = 'efl wrapper binding enlightenment eo evas ecore edje emotion elementary ethumb',
60 classifiers = [
61 'Development Status :: 5 - Production/Stable',
62 'Environment :: X11 Applications',
63 'Environment :: Console :: Framebuffer',
64 'Intended Audience :: End Users/Desktop',
65 'License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)',
66 'Operating System :: POSIX',
67 'Programming Language :: C',
68 'Programming Language :: cffi', # TODO is this right ??
69 'Programming Language :: Python :: 2',
70 'Programming Language :: Python :: 3',
71 'Topic :: Software Development :: Libraries :: Python Modules',
72 'Topic :: Software Development :: User Interfaces',
73 'Topic :: Software Development :: Widget Sets',
74 ],
75
76 install_requires = ["cffi>=1.4.0"],
77 setup_requires = ["cffi>=1.4.0"],
78
79 packages = find_packages(exclude=['pyolian']),
80 zip_safe = False, # zipped the egg is slower to start?
81 cmdclass = {
82 'generate': Generate,
83 'build_py': BuildPy,
84 },
85 cffi_modules = [
86 "./efl2/cffi/build_efl.py:ffi",
87 ],
88
89)
90
91
92# --disable-cxx-bindings --disable-doc
diff --git a/tests/test_ecore.c b/tests/test_ecore.c
new file mode 100644
index 0000000..91069ae
--- /dev/null
+++ b/tests/test_ecore.c
@@ -0,0 +1,50 @@
1
2
3// gcc -Wall -D EFL_BETA_API_SUPPORT -D EFL_EO_API_SUPPORT `pkg-config --libs --cflags eo ecore` test_ecore.c -o test_ecore
4
5
6#include <Eo.h>
7#include <Ecore.h>
8
9
10
11// Eina_Bool
12// _del_cb(void *data, const Eo_Event *event)
13// {
14 // printf("del !!!!\n");
15//
16 // return 0;
17// }
18
19
20Eina_Bool
21_timer_cb(void *data)
22{
23 printf("Timer\n");
24 return 1;
25}
26
27int
28main(int argc, char **argv)
29{
30 eo_init();
31 ecore_init();
32
33 // timer
34 Ecore_Timer *t;
35 t = _eo_add_internal_start(NULL, 0, ecore_timer_class_get(), NULL, EINA_FALSE, EINA_FALSE);
36 ecore_obj_timer_constructor(t, 1.0, _timer_cb, NULL);
37 _eo_add_end(t, EINA_FALSE);
38
39
40 // mainloop
41 Eo *ml;
42 ml = _eo_add_internal_start(NULL, 0, ecore_mainloop_class_get(), NULL, EINA_FALSE, EINA_FALSE);
43 _eo_add_end(ml, EINA_FALSE);
44 ecore_mainloop_begin(ml);
45
46
47 ecore_shutdown();
48 return 0;
49}
50
diff --git a/tests/test_ecore.py b/tests/test_ecore.py
new file mode 100644
index 0000000..94d4ae2
--- /dev/null
+++ b/tests/test_ecore.py
@@ -0,0 +1,24 @@
1
2from efl2 import ecore
3from efl2.ecore import Timer
4
5
6print("starting ecore ml :)")
7
8# def mycb(*args, **kargs):
9 # print(args, kargs)
10 # print(" \o/ " * 60)
11 # ecore.main_loop_quit()
12 # return ecore.ECORE_CALLBACK_CANCEL
13#
14def mycb2():
15 print("t")
16 return 1
17 # return ecore.ECORE_CALLBACK_RENEW
18
19# t = Timer(5.0, mycb, 567, asd='AsD')
20t2 = Timer(1.0, mycb2)
21
22ml = ecore.Ecore_Mainloop()
23print(ml)
24ml.begin()
diff --git a/tests/test_elm.c b/tests/test_elm.c
new file mode 100644
index 0000000..90156d2
--- /dev/null
+++ b/tests/test_elm.c
@@ -0,0 +1,60 @@
1
2
3// gcc -Wall -D EFL_BETA_API_SUPPORT -D EFL_EO_API_SUPPORT `pkg-config --libs --cflags elementary` test.c -o test
4
5
6#include <Elementary.h>
7
8
9
10Eina_Bool
11_del_cb(void *data, const Eo_Event *event)
12{
13 printf("del !!!!\n");
14
15 return 0;
16}
17
18Eina_Bool
19_click_cb(void *data, const Eo_Event *event)
20{
21 printf("click !!!!\n");
22
23 return 0;
24}
25
26Evas_Object *win, *bt;
27
28EAPI_MAIN int
29elm_main(int argc, char **argv)
30{
31 // win
32 // win = _eo_add_internal_start(NULL, 0, ELM_WIN_STANDARD_CLASS, NULL, EINA_FALSE);
33 win = _eo_add_internal_start(NULL, 0, elm_win_standard_class_get(), NULL, EINA_FALSE);
34 elm_obj_win_name_set(win, "c_test");
35 elm_obj_win_title_set(win, "Eo API test");
36 _eo_add_end(win);
37
38
39 // button
40 // bt = eo_add(ELM_BUTTON_CLASS, win);
41 bt = _eo_add_internal_start(NULL, 0, elm_button_class_get(), win, EINA_FALSE);
42 _eo_add_end(bt);
43
44 elm_obj_layout_text_set(bt, NULL, "asdasd");
45 elm_obj_win_resize_object_add(win, bt);
46 efl_gfx_visible_set(bt, EINA_TRUE);
47
48 eo_event_callback_add(bt, EVAS_CLICKABLE_INTERFACE_EVENT_CLICKED, _click_cb, NULL);
49 eo_event_callback_add(bt, EO_BASE_EVENT_DEL, _del_cb, NULL);
50
51
52 //
53 efl_gfx_size_set(win, 180, 180);
54 efl_gfx_visible_set(win, EINA_TRUE);
55 elm_run();
56
57
58 return 0;
59}
60ELM_MAIN()
diff --git a/tests/test_elm.py b/tests/test_elm.py
new file mode 100644
index 0000000..77a3b07
--- /dev/null
+++ b/tests/test_elm.py
@@ -0,0 +1,87 @@
1#!/usr/bin/env python
2# encoding: utf-8
3
4import platform
5
6import efl2 as efl
7
8from efl2 import eo
9# from efl2 import evas
10from efl2 import ecore
11# from efl2.ecore import Timer
12from efl2 import elementary as elm, __version__
13
14
15
16# def mycb(*args, **kargs):
17 # print(args, kargs)
18 # print(" \o/ " * 60)
19 # ecore.main_loop_quit()
20 # return ecore.ECORE_CALLBACK_CANCEL
21#
22
23
24def my_timer_cb():
25 global lb
26 print("t")
27 if lb:
28 print("TIMER")
29 lb.delete()
30 lb = None
31 return ecore.ECORE_CALLBACK_RENEW
32
33
34# t = Timer(5.0, mycb, 567, asd='AsD')
35t2 = efl.ecore.Timer(3.0, my_timer_cb)
36
37# ecore.main_loop_begin()
38
39# ml = ecore.Mainloop()
40
41def mycb3(*args):
42 print("CB!!!!!!!!!!!!" + str(args))
43 return eo.EO_CALLBACK_STOP
44
45def mycb4(*args):
46 print("... and click !" + str(args))
47 return eo.EO_CALLBACK_CONTINUE
48
49if __name__ == '__main__':
50 title = 'Python EFL version %s (on python: %s)' % (
51 __version__, platform.python_version())
52
53 # win = elm.Win('pyefl-test', elm.ELM_WIN_BASIC)
54 win = elm.Win_Standard(None, title='pyefl-test')
55 win.title = "asdasd àèìòù ね の は " * 3
56 # print("** " + win.title)
57 # print("** " + str(type(win.title)))
58
59 # box
60 box = elm.Box(win, visible=True)
61 win.resize_object_add(box)
62
63 # label
64 lb = elm.Label(win, visible=True, text=win.title)
65 lb.on('del', mycb3)
66 box.pack_end(lb)
67
68 # button
69 bt = elm.Button(win, visible=True, text=lb.text)
70 bt.on('clicked', mycb4)
71 box.pack_end(bt)
72
73
74 #
75 win.visible = True
76 elm.run()
77
78 print("DONE")
79 # win.delete()
80 """ ORIGINAL TO MIMIC:
81 win = StandardWindow("test", title)
82 win.callback_delete_request_add(destroy, "test1", "test2",
83 str3="test3", str4="test4")
84 win.resize(480, 480)
85 win.show()
86 elementary.run()
87 """
diff --git a/tox.ini b/tox.ini
new file mode 100644
index 0000000..db7a6d1
--- /dev/null
+++ b/tox.ini
@@ -0,0 +1,6 @@
1[tox]
2envlist=py26,py27,py33,pypy
3
4[testenv]
5deps=-rrequirements-testing.txt
6commands=py.test test/