tictactoe-0.3.2.1/0000755000175000017500000000000011266666125012311 5ustar alexalextictactoe-0.3.2.1/setup.py0000755000175000017500000000215711266666123014031 0ustar alexalex#!/usr/bin/env python # # (C) 2009 Alex Launi try: import DistUtilsExtra.auto except: import sys print >> sys.stderr, 'To build tictactoe you need https://launchpad.net/python-distutils-extra' sys.exit(1) MIN_DISTUTILSEXTRA_MAJOR = 2 MIN_DISTUTILSEXTRA_MINOR = 4 MIN_DISTUTILSEXTRA_MICRO = 0 dist_utils_version = map(int, DistUtilsExtra.auto.__version__.split(".")) while len(dist_utils_version) < 3: dist_utils_version.append(0) major, minor, micro = dist_utils_version[0], dist_utils_version[1], dist_utils_version[2] assert major >= MIN_DISTUTILSEXTRA_MAJOR if major == MIN_DISTUTILSEXTRA_MAJOR: assert minor >= MIN_DISTUTILSEXTRA_MINOR if minor == MIN_DISTUTILSEXTRA_MINOR: assert micro >= MIN_DISTUTILSEXTRA_MICRO DistUtilsExtra.auto.setup( name='tictactoe', version='0.3.2.1', description='A simple, fun tic tac toe game using telepathy tubes for two player action', url='http://launchpad.net/tictactoe', license='GNU General Public License (GPL)', author='Alex Launi', author_email='alex.launi@gmail.com', scripts = ['bin/tictactoe'], ) tictactoe-0.3.2.1/README0000644000175000017500000000044311264716434013167 0ustar alexalexTic Tac Toe ------- Tic Tac Toe (naughts & crosses) is a simple two player game where the object is to place your shapes on the game board so that you get three in a row either horizontally, vertically, or across one of the diagonals while trying to block your oponent from doing the same. tictactoe-0.3.2.1/data/0000755000175000017500000000000011266666125013222 5ustar alexalextictactoe-0.3.2.1/data/icons/0000755000175000017500000000000011266666125014335 5ustar alexalextictactoe-0.3.2.1/data/icons/16x16/0000755000175000017500000000000011266666125015122 5ustar alexalextictactoe-0.3.2.1/data/icons/16x16/apps/0000755000175000017500000000000011266666125016065 5ustar alexalextictactoe-0.3.2.1/data/icons/16x16/apps/tictactoe.png0000644000175000017500000000124611264716434020552 0ustar alexalexPNG  IHDRasRGBbKGD pHYs B(xtIME"憚&IDAT8˭nSA=8qID.RJ y h x%@+@ADC $B {'P88fVvc8:ZFQߤ43QPYlR|[̭t^3GYdT$E%!IɁjQDRʚsM˂KQFIʏN UzELF9<#229pR(DԖ[SIQR+2lpyQ K>`FI^ C%'F#Q G?Ar@906'9VDQ$ !ZGs2c5cT+3u+DE41 rOzY_f9zz hTК1݃.L0" |$V }04jq3#DJF,'}z6a/49*8ιL 3Kf@D0  <4"& ]^(b\9% rDIM3E3_ɇsZVG(DsqGH!]`: jsP-#SW?C1\הskPSTf~af~!냩 bM$HH3JvceD̟]%rVFbYڂc]#9'\PW. U/KG1 Bw3CMQ u6TT jJ/_B##"rfΐ)ى k[wOpu@T)V d@ #iW:!Ga Vcx,<8i9Tzq@G\ITenW%̌csphz^LC=x#\PxQ$}/^gFYԈ{CXAZ4hoz/x}l8HbѤ^-!XDF.FګW:^z0w{!Ʌ§1=^3˷Bb)E5凘 ȑwy/?‰S7>@^PDTpN`*KZ1@*Պn\XYLsP.ĐWHL90N+G#@HRʱ9r_oxh%.['٧FMT r*SK͌Πf^\Cw>p|+oenrƍfcwPAjov:<$Z\n;Zfsm"`3}gak ԩi?ou=jC1_fŸh{IENDB`tictactoe-0.3.2.1/data/icons/24x24/0000755000175000017500000000000011266666125015120 5ustar alexalextictactoe-0.3.2.1/data/icons/24x24/apps/0000755000175000017500000000000011266666125016063 5ustar alexalextictactoe-0.3.2.1/data/icons/24x24/apps/tictactoe.png0000644000175000017500000000206111264716434020544 0ustar alexalexPNG  IHDRw=sRGBbKGD pHYs B(xtIME9ub^IDATHՖnG r H.2OȎlٲ*O,Xe]. D! dnOK3V(RtT]W7Gh_|w/$w}<Ϊ=Q˗?@_J %f9ffjAMv$T:gg&xPkP[]Ǻf1=Qb=E8Vm03T72?j W(agEHBT;<$ݔ \MKYmuR-8z[8~pD%Jc=w+p}"G9{xwI[;yd ^\$=!'Fz}~q!xjJoM_~ghfvaoanXz JL [\ɳ5W Xz`)tc(]k;xBȻ{œ_gziIENDB`tictactoe-0.3.2.1/data/icons/scalable/0000755000175000017500000000000011266666125016103 5ustar alexalextictactoe-0.3.2.1/data/icons/scalable/apps/0000755000175000017500000000000011266666125017046 5ustar alexalextictactoe-0.3.2.1/data/icons/scalable/apps/tictactoe.svg0000644000175000017500000002216411264716434021550 0ustar alexalex image/svg+xml tictactoe-0.3.2.1/data/icons/22x22/0000755000175000017500000000000011266666125015114 5ustar alexalextictactoe-0.3.2.1/data/icons/22x22/apps/0000755000175000017500000000000011266666125016057 5ustar alexalextictactoe-0.3.2.1/data/icons/22x22/apps/tictactoe.png0000644000175000017500000000200611264716434020537 0ustar alexalexPNG  IHDRĴl;sRGBbKGD pHYs B(xtIMECIDAT8Օk]E?3̏6VJMAh%B7nqB7 q%]nu#(B_MŤBƼ3sqq{yW 0w{9whߝO 00 Tjnf\{ձk}>{7g 83H$*"․J"*JAXh֓oiiK2JZNedI9<0 B?$!FȋdT6w{xxe@>d9&:@j P3G|{{sὯS.祏:㇊C:/rzw )YlQ1%FlTp$"$j8ZF=I UeLճ2T , ǁ@HNf#G8,-}@!$\:J^#1 ! 1qx($\@ɾwrᐝNno1#a3RP3.\]=g_E .W.a($Ĕ.%fs(H SN9yrFUY)IY* YIec@= L]'wD=3!3Ox8X. 2#Ɔ(^ ˲aY2,XoElY šB{,a X¾Pk{m-ֵ/{,Y ˲y`$^޸XPް6pay5S۲ 8\B@Տ Oprv5U0e!XC8~% JW 4T6|m#<0v g|@߂A W!Yn13dy)dr. #h `"G0u# sHPႱPZuyhvu<,9mܓ\Esݓs3I wP(Q-é}я)EI^vhhZ$̕iE!RKr֋O@ĸ?aۚ2e%5v0N0J(J!#/ = $1^-]:FVu`^)㲼SBF&rw8m?72ʮ&{w<&*LQwkB I@9YrV%:|3C3+(Q_] ᫶cU"z9nw{+3*خp- 0 6@ Mg:=FRiى$IωHPʹ@U2ceV)OI@^9liF0 0"ZSPL, ~;t$5"ם{8W_Ya7L±udL9 ƽ=a'.ubs]^j(L,^!P3k% t¨5;%]^/ CkRJxd i*u{QKq7@1J##Ĕf>ePixl9ժKDΛY^8Yd‰@NFHA _fC ox#KL$Ʀe)#̌ XU) \Vf9}j,S5m<ҸTą^߃ogB8w;|HR3cʉDG7īJ*^[:5=}Q ֡3#I6ס:X>o؄ƕF "t=b߮XY/Iʒ\۵FumF0fx6L:to:G/ '{az-SJHbttWw#Js!PUq+h`[wk];Dt|Gw;ُ~RlL({G.{.lm\\𐾱nV< =5qݚ:۰r9>:r}JFcN5joEK'l/;MנjDQUҩ(:XJhnDu@5Q/MhaYzSmn{{xx>X7^m_㳷pWx&T9VU:3><݊ 5BnNlŎ6_l)g 6h>kQ*u{2w>8%x{_3׌YOLIN옪4yq{u Mϟ\bN)7lhgv 82ES'"4D4;33=y@W,~+\(YOɿ'g&η7~Q}g*  Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . tictactoe-0.3.2.1/tictactoe.10000644000175000017500000000172511264716434014354 0ustar alexalex.\" Process this file with .\" groff -man -Tascii tictactoe.1 .\" .TH TICTACTOE 1 "AUGUST 2009" Linux "User Manuals" .SH NAME tictactoe \- Fun, Simple, Tic Tac Toe game for GNOME .SH SYNOPSIS .B tictactoe [ .I OPTIONS .B ] .SH DESCRIPTION .B Tic Tac Toe is an open source Tic Tac Toe game supporting three modes of play; Human vs. Computer, Human vs. Human where both players are local trading the mouse back and forth, and Human vs. Human networked via telepathy tubes. .SH OPTIONS .IP "-h, --help" Show help message and exit .IP "-v, --verbose" Verbose messages .IP "-d, --debug" Debug messages .SH BUGS Please report all bugs to the Tic Tac Toe bug tracker: http://launchpad.net/tictactoe .SH AUTHORS .B Tic Tac Toe was written by Alex Launi . This manual page was written by Alex Launi. .SH COPYRIGHT Copyright (c) 2009. This manual page is licensed under the GNU General Public License (GPL) version 3, see: . tictactoe-0.3.2.1/po/0000755000175000017500000000000011266666125012727 5ustar alexalextictactoe-0.3.2.1/po/POTFILES.in0000644000175000017500000000012411264716434014476 0ustar alexalextictactoe.desktop.in tictactoe/main.py tictactoe/tubehandler.py tictactoe/widgets.pytictactoe-0.3.2.1/po/tictactoe.pot0000644000175000017500000000517411264716434015436 0ustar alexalex# SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR , YEAR. # #, fuzzy msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2009-09-30 09:52-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" #: ../tictactoe.desktop.in.h:1 msgid "Simple, fun tic tac toe game for GNOME" msgstr "" #: ../tictactoe.desktop.in.h:2 msgid "Tic Tac Toe" msgstr "" #: ../tictactoe/main.py:52 msgid "tic-tac-toe all by yourself" msgstr "" #: ../tictactoe/main.py:53 #, python-format msgid "tic-tac-toe with %s" msgstr "" #: ../tictactoe/main.py:82 msgid "the computer" msgstr "" #: ../tictactoe/main.py:82 msgid "" "Bored? All alone? Play by yourself vs. the computer, but watch out the " "computer might be smarter than you think!" msgstr "" #: ../tictactoe/main.py:83 msgid "an online friend" msgstr "" #: ../tictactoe/main.py:83 msgid "" "You can even play instantly, online, right now, at this very moment, with " "one of your Empathy contacts." msgstr "" #: ../tictactoe/main.py:84 msgid "a friend sitting next to you" msgstr "" #: ../tictactoe/main.py:84 msgid "" "Hanging out with a friend? Want to play tic tac toe but are totally into " "this green zero-paper lifestyle craze? Trade the mouse back and forth in " "this fast paced high aventure game of tic tac toe." msgstr "" #: ../tictactoe/main.py:139 msgid "_Game" msgstr "" #: ../tictactoe/main.py:142 msgid "_New game" msgstr "" #: ../tictactoe/main.py:373 msgid "a friend" msgstr "" #: ../tictactoe/tubehandler.py:117 msgid "New game request!" msgstr "" #: ../tictactoe/tubehandler.py:124 #, python-format msgid "" "%s would like to play a game of tic tac toe with you! Would you like " "to play?" msgstr "" #: ../tictactoe/widgets.py:278 msgid "Cross wins" msgstr "" #: ../tictactoe/widgets.py:280 msgid "Circle wins" msgstr "" #: ../tictactoe/widgets.py:282 msgid "It's a tie" msgstr "" #. cr.set_source_rgb(1.0, 1.0, 1.0) #. cr.select_font_face("sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD) #. cr.set_font_size(50) #. cr.move_to(x, y) #: ../tictactoe/widgets.py:291 msgid "Again?" msgstr "" #: ../tictactoe/widgets.py:371 msgid "How would you like to play today?" msgstr "" #: ../tictactoe/widgets.py:405 #, python-format msgid "Play a game of tic tac toe against %s" msgstr "" tictactoe-0.3.2.1/AUTHORS0000644000175000017500000000016411264716434013357 0ustar alexalexTictactoe Authors --------------------------- * Alex Launi Icon --------------------------- * Daniel Foretictactoe-0.3.2.1/bin/0000755000175000017500000000000011266666125013061 5ustar alexalextictactoe-0.3.2.1/bin/tictactoe0000755000175000017500000000320311264716434014761 0ustar alexalex#!/usr/bin/env python """ Tic Tac Toe Alex Launi """ import sys, logging, gtk, optparse from os.path import join, dirname, exists, realpath, abspath ###################################################################### # Options and configuration def parse_opts(): usage = "usage: %prog [options]" oparse = optparse.OptionParser(usage=usage) oparse.add_option("-v", "--verbose", action="store_true", help="Verbose messages", default=False) oparse.add_option("-d", "--debug", action="store_true", help="Debug messages", default=False) opts, rest = oparse.parse_args() return opts opts = parse_opts() if opts.debug: logging.root.setLevel(logging.DEBUG) elif opts.verbose: logging.root.setLevel(logging.INFO) ###################################################################### # Setup path LAUNCH_DIR = abspath(sys.path[0]) logging.debug("Launched from %s", LAUNCH_DIR) source_tree_tictactoe = join(LAUNCH_DIR, "..", "tictactoe") # If we were invoked from a tictactoe source directory add that as the # preferred module path ... if exists(join(source_tree_tictactoe, "main.py")): logging.info("Running from source tree; adjusting path") sys.path.insert(0, realpath(dirname(source_tree_tictactoe))) try: from tictactoe.main import TicTacToeGame finally: del sys.path[0] else: sys.path.insert(0, "/usr/lib/python2.6/site-packages/") logging.debug("Assuming path is correct") from tictactoe.main import TicTacToeGame ###################################################################### # Go... TicTacToeGame() gtk.main() tictactoe-0.3.2.1/PKG-INFO0000644000175000017500000000072011266666125013405 0ustar alexalexMetadata-Version: 1.1 Name: tictactoe Version: 0.3.2.1 Summary: A simple, fun tic tac toe game using telepathy tubes for two player action Home-page: http://launchpad.net/tictactoe Author: Alex Launi Author-email: alex.launi@gmail.com License: GNU General Public License (GPL) Description: UNKNOWN Platform: UNKNOWN Requires: cairo Requires: dbus Requires: glib Requires: gobject Requires: gtk Requires: pygtk Requires: telepathy Requires: xdg Provides: tictactoe tictactoe-0.3.2.1/INSTALL0000644000175000017500000000201711264716434013337 0ustar alexalexInstalling Tic Tac Toe ================== Requirements ------------ Please note that the version numbers listed below only reflect my test environment. Tic Tac Toe is known to work with those specific versions, but will probably work fine on most current desktop distributions. * python (2.5) * python-cairo (1.8.6) * python-dbus (0.83) * python-distutils-extra (2.9) * python-gobject (2.18.0) * python-gtk2 (2.10.4) * python-telepathy (0.15.10) * python-xdg (0.15.1) Installation ------------ Tic tac toe uses Python's distutils framework for installation. In order to install Tic tac toe, you will need root access. To install Tic tac toe, perform the following command as root: $ ./setup.py install Run Tic tac toe ----------- If you installed Tic tac toe using the setup.py script, you can launch the program by typing "tictactoe" at the command line. If you want to run Tic tac toe without installing it, start "bin/tictactoe" from within the Tic tac toe directory. tictactoe-0.3.2.1/tictactoe/0000755000175000017500000000000011266666125014270 5ustar alexalextictactoe-0.3.2.1/tictactoe/tubehandler.py0000644000175000017500000001143111264716434017134 0ustar alexalex#!/usr/bin/python # tubehandler.py # (C) 2009 Alex Launi - alex.launi@gmail.com # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . import logging import os import dbus import dbus.service import gtk from dbus import PROPERTIES_IFACE from dbus.mainloop.glib import DBusGMainLoop from gettext import gettext as _ from telepathy.client.conn import Connection from telepathy.client.channel import Channel from telepathy.constants import ( TUBE_STATE_OPEN, SOCKET_ACCESS_CONTROL_CREDENTIALS) from telepathy.interfaces import ( CHANNEL_INTERFACE, CHANNEL_INTERFACE_TUBE, CHANNEL_TYPE_DBUS_TUBE, CONN_INTERFACE_ALIASING) import gettext _ = gettext.lgettext logger = logging.root DBusGMainLoop(set_as_default=True) def _get_contact_alias(conn, handle): return conn[CONN_INTERFACE_ALIASING].RequestAliases([handle])[0] def _sanitize_service_name(service_name): return service_name.replace('.', '_') def _build_bus_name(service_name): return "org.gnome.Empathy.DTubeHandler.%s" % _sanitize_service_name(service_name) def _build_object_path(bus_name): return '/' + bus_name.replace('.', '/') class TubeHandler(dbus.service.Object): """Listen to coming tube tube_received_cb is called when the tube becomes open """ def __init__(self, service_name, tube_received_cb): logger.debug('creating TubeHandler') self._tube_received_cb = tube_received_cb bus_name = _build_bus_name(service_name) obj_path = _build_object_path(bus_name) logger.debug('Bus name: %s' % bus_name) logger.debug('Object path: %s' % obj_path) bus = dbus.SessionBus() # this bus_name has to be retained, so make it a instance attribute self.busname = dbus.service.BusName(bus_name, bus) super(TubeHandler, self).__init__(bus, obj_path) @dbus.service.method(dbus_interface="org.gnome.Empathy.TubeHandler", in_signature='soouu', out_signature='') def HandleTube(self, bus_name, connection, channel, handle_type, handle): """Called when we are offered a tube""" logger.debug('Tube received on %s' % channel) self._bus_name = bus_name self._channel = channel self._peer_handle = handle self._conn = Connection(bus_name, connection, ready_handler=self._ready_handler) def _ready_handler(self, conn): self._tube_chan = Channel(self._bus_name, self._channel) self._tube_chan[CHANNEL_INTERFACE_TUBE].connect_to_signal( 'TubeChannelStateChanged', self._tube_state_changed_cb) params = self._tube_chan[PROPERTIES_IFACE].Get( CHANNEL_INTERFACE_TUBE, 'Parameters') self._process_incoming_tube(params) def _tube_state_changed_cb(self, state): if state == TUBE_STATE_OPEN: logger.debug('Tube state changed ->open') bus = dbus.connection.Connection(self._address) self._tube_received_cb(bus, self._tube_chan) else: logger.debug('Tube state changed ->%s' % state) def _process_incoming_tube(self, params): def reply_cb(dialog, response_id): if response_id == gtk.RESPONSE_ACCEPT: self._address = self._tube_chan[CHANNEL_TYPE_DBUS_TUBE].Accept( SOCKET_ACCESS_CONTROL_CREDENTIALS) else: self._tube_chan[CHANNEL_INTERFACE].Close() dialog.destroy() alias = _get_contact_alias(self._conn, self._peer_handle) logger.debug('Processing incoming tube request') dialog = gtk.Dialog(_('New game request!'), None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)) dialog.connect('response', reply_cb) label = gtk.Label() label.set_line_wrap(True) label.set_markup(_('%s would like to play a game of tic tac toe with you! Would you like to play?') % alias) label.show() align = gtk.Alignment(1, 1, 0, 0) align.set_padding(5, 5, 5, 5) align.add(label) vbox = dialog.get_content_area() vbox.pack_start(align, True, True, 0) vbox.show_all() dialog.run() tictactoe-0.3.2.1/tictactoe/widgets.py0000644000175000017500000003524311264716434016314 0ustar alexalex#!/usr/bin/python # tictactoe-widget.py # (C) 2009 Alex Launi - alex.launi@gmail.com # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . import math import logging import gtk import glib import cairo import gobject from gtk import gdk import pygtk pygtk.require('2.0') import gettext _ = gettext.lgettext class TicTacToeBoard(gtk.DrawingArea): BAR_THICKNESS = 8 SHAPE_THICKNESS = 25 REPLAY_TIMEOUT = 750 Blank = 0 X = 1 O = 2 def __init__(self, parent=None): self.par = parent super(TicTacToeBoard, self).__init__() self.add_events(gdk.BUTTON_PRESS_MASK) self.connect('expose-event', self._expose) self._set_board() def new_game(self): self._set_board() self._expose(self, None) def make_move(self, space, player): x, y = space[0], space[1] if player == self.current_player and self.game_matrix[x][y] == self.Blank: self.move_count = self.move_count + 1 self.game_matrix[x][y] = player self.winning_points = self.determine_if_winner(space) if self.move_count == 9 and not self.winning_points: self.winning_points = ((0,0), (0,0)) self.winning_player = self.Blank else: self.winning_player = player if self.current_player == self.X: self.current_player = self.O else: self.current_player = self.X else: return False self._expose(self, None) return True def space_clicked(self, widget, event): (stage_w, stage_h) = widget.window.get_size() space = [] if (event.y < stage_h * 1/3): space.append(0) elif (event.y < stage_h * 2/3): space.append(1) else: space.append(2) if (event.x < stage_w * 1/3): space.append(0) elif (event.x < stage_w * 2/3): space.append(1) else: space.append(2) return space def determine_if_winner(self, space): #check vertical if self.game_matrix[space[0]][0] == self.game_matrix[space[0]][1] == self.game_matrix[space[0]][2]: return ((space[0], 0), (space[0], 2)) #check horizontal elif self.game_matrix[0][space[1]] == self.game_matrix[1][space[1]] == self.game_matrix[2][space[1]]: return ((0, space[1]), (2, space[1])) #check diagonal elif self.game_matrix[0][0] == self.game_matrix[1][1] == self.game_matrix[2][2] and self.game_matrix[0][0] != self.Blank: return ((0,0), (2,2)) elif self.game_matrix[2][0] == self.game_matrix[1][1] == self.game_matrix[0][2] and self.game_matrix[2][0] != self.Blank: return ((2,0), (0,2)) def _set_board(self): self.move_count = 0 self.winning_points = None self.current_player = self.X self.game_matrix = [ [0, 0, 0], [0, 0, 0], [0, 0, 0] ] def _expose(self, widget, event): cr = widget.window.cairo_create() #set white background cr.set_source_rgba(1.0, 1.0, 1.0, 1.0) cr.paint() self._draw_game_board(widget, cr) self._draw_players(widget, cr, self.game_matrix) if not self.winning_points is None: self._draw_cross_through(widget, cr) gobject.timeout_add(self.REPLAY_TIMEOUT, self._draw_replay_dialog, widget, cr) return False def _draw_game_board(self, widget, cr): (stage_w, stage_h) = widget.window.get_size() self._draw_bar(cr, 0, 0, stage_w, self.BAR_THICKNESS) self._draw_bar(cr, 0, stage_h * 1/3, stage_w, self.BAR_THICKNESS) self._draw_bar(cr, 0, stage_h * 2/3, stage_w, self.BAR_THICKNESS) self._draw_bar(cr, 0, 0, self.BAR_THICKNESS, stage_h) self._draw_bar(cr, stage_w * 1/3, 0, self.BAR_THICKNESS, stage_h) self._draw_bar(cr, stage_w * 2/3, 0, self.BAR_THICKNESS, stage_h) def _draw_bar(self, cr, x, y, width, height): '''Draws a gray semi-transparent bar for the space seperator''' cr.set_source_rgba(.9, 0.9, 0.9, 1.0) cr.rectangle(x, y, width, height) cr.fill() cr.stroke() def _draw_players(self, widget, cr, board): for i in range(len(board)): for j in range(len(board[i])): if board[i][j] == self.X: self._draw_x(widget, cr, i, j) elif board[i][j] == self.O: self._draw_o(widget, cr, i, j) def _draw_cross_through(self, widget, cr): #this is my stupid hack to handle the tie case better #this game has some serious design flaws... if self.winning_points[0] == self.winning_points[1]: return (stage_w, stage_h) = widget.window.get_size() cr.set_source_rgba(1.0, 0.0, 0.0, 1.0) cr.set_line_width(self.SHAPE_THICKNESS) startx_factor = 0 starty_factor = 0 endx_factor = 0 endy_factor = 0 #if our X winning points are equal, we've got a vertical win if self.winning_points[0][1] == self.winning_points[1][1]: startx_factor = 1.0/6 + self.winning_points[0][1] * 1.0/3 endx_factor = startx_factor endy_factor = 1 #if our Y winning points are equal we've got a horizontal win elif self.winning_points[0][0] == self.winning_points[1][0]: starty_factor = 1.0/6 + self.winning_points[0][0] * 1.0/3 endy_factor = starty_factor endx_factor = 1 #if we have winning points, then we've got a diagonal elif self.winning_points[0] == (0,0): startx_factor = 0 starty_factor = 0 endx_factor = 1 endy_factor = 1 elif self.winning_points[0] == (2,0): startx_factor = 0 starty_factor = 1 endx_factor = 1 endy_factor = 0 cr.move_to(stage_w * startx_factor + self.BAR_THICKNESS, self.BAR_THICKNESS + stage_h * starty_factor) cr.line_to(stage_w * endx_factor + self.BAR_THICKNESS, self.BAR_THICKNESS + stage_h * endy_factor)# * starty_factor) cr.stroke() def _draw_x(self, widget, cr, x, y): (stage_w, stage_h) = widget.window.get_size() cr.set_line_width(self.SHAPE_THICKNESS) cr.set_source_rgba(0, 1, 0, 0.8) xpos = stage_w * y/3 + self.BAR_THICKNESS/2 + self.SHAPE_THICKNESS ypos = stage_h * x/3 + self.BAR_THICKNESS/2 + self.SHAPE_THICKNESS cr.move_to(xpos, ypos) cr.line_to(xpos + stage_w/4, ypos + stage_h/4) cr.move_to(xpos, ypos + stage_w/4 - self.BAR_THICKNESS) cr.line_to(xpos + stage_w/4, ypos) cr.stroke() def _draw_o(self, widget, cr, x, y): (stage_w, stage_h) = widget.window.get_size() cr.set_line_width(self.SHAPE_THICKNESS) cr.set_source_rgba(1.0, 0.5, 0.31, 1.0) xpos = stage_w * y/3 + stage_w/7 + self.BAR_THICKNESS/2 + self.SHAPE_THICKNESS/2 ypos = stage_h * x/3 + stage_h/7 + self.BAR_THICKNESS/2 + self.SHAPE_THICKNESS/2 cr.save() cr.translate(xpos, ypos) cr.arc(0.0, 0.0, stage_w/8, 0, 2*math.pi) cr.stroke() cr.restore() def _draw_replay_dialog(self, widget, cr): (stage_w, stage_h) = widget.window.get_size() xpos = stage_w * 1/6 + self.BAR_THICKNESS ypos = stage_h * 1/3 - self.BAR_THICKNESS * 2 width = stage_w * 2/3 height = stage_h * 1/3 self._draw_board_screen(widget, cr) self._write_winner_loser(widget, cr, self.BAR_THICKNESS, stage_h * 1/3 - self.SHAPE_THICKNESS) self._draw_rounded_rectangle(widget, cr, xpos, ypos, width, height, 40) self._write_replay_text(widget, cr, xpos + width/4, ypos + height/2 + self.BAR_THICKNESS) return False def _draw_board_screen(self, widget, cr): (stage_w, stage_h) = widget.window.get_size() cr.set_source_rgba(0.3, 0.3, 0.3, 0.8) cr.rectangle(0, 0, stage_w, stage_h) cr.fill() cr.stroke() def _draw_rounded_rectangle(self, widget, cr, x, y, width, height, radius): if width/2 < radius or height/2 < radius: radius = min(width/2, height/2) cr.save() cr.set_source_rgba(0.96, 0.96, 0.96, 0.75) cr.move_to(x, y + radius) cr.arc(x + radius, y + radius, radius, math.pi, -math.pi/2) cr.line_to(x + width - radius, y) cr.arc(x + width - radius, y + radius, radius, -math.pi/2, 0) cr.line_to(x + width, y + height - radius) cr.arc(x + width - radius, y + height - radius, radius, 0, math.pi/2) cr.line_to(x + radius, y + height) cr.arc(x + radius, y + height - radius, radius, math.pi/2, math.pi) cr.close_path() cr.fill() cr.restore() return False def _write_winner_loser(self, widget, cr, x, y): if self.winning_player == self.X: text = _('Cross wins') elif self.winning_player == self.O: text = _('Circle wins') else: text = _('It\'s a tie') self._write(widget, cr, x, y, 75, text) def _write_replay_text(self, widget, cr, x, y): #cr.set_source_rgb(1.0, 1.0, 1.0) #cr.select_font_face("sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD) #cr.set_font_size(50) #cr.move_to(x, y) self._write(widget, cr, x, y, 50, _('Again?')) def _write(self, widget, cr, x, y, size, text): cr.set_source_rgb(1.0, 1.0, 1.0) cr.select_font_face("sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD) cr.set_font_size(size) cr.move_to(x, y) cr.show_text(text) class WaitingAnimation(gtk.DrawingArea): TIMEOUT = 100 NUM_LINES = 8 BAR_THICKNESS = 20 def __init__(self, parent=None): self.par = parent super(WaitingAnimation, self).__init__() self.count = 0 self.trs = ( ( 0.0, 0.15, 0.30, 0.5, 0.65, 0.80, 0.9, 1.0 ), ( 1.0, 0.0, 0.15, 0.30, 0.5, 0.65, 0.8, 0.9 ), ( 0.9, 1.0, 0.0, 0.15, 0.3, 0.5, 0.65, 0.8 ), ( 0.8, 0.9, 1.0, 0.0, 0.15, 0.3, 0.5, 0.65 ), ( 0.65, 0.8, 0.9, 1.0, 0.0, 0.15, 0.3, 0.5 ), ( 0.5, 0.65, 0.8, 0.9, 1.0, 0.0, 0.15, 0.3 ), ( 0.3, 0.5, 0.65, 0.8, 0.9, 1.0, 0.0, 0.15 ), ( 0.15, 0.3, 0.5, 0.65, 0.8, 0.9, 1.0, 0.0, ) ) self.connect('expose-event', self._expose) def start(self): glib.timeout_add(self.TIMEOUT, self.on_timer) def on_timer(self): self.count = self.count + 1 self.queue_draw() return True def _expose(self, widget, event): cr = widget.window.cairo_create() #set white background cr.set_source_rgba(1.0, 1.0, 1.0, 1.0) cr.paint() cr.set_line_width(self.BAR_THICKNESS) cr.set_line_cap(cairo.LINE_CAP_ROUND) w = self.allocation.width h = self.allocation.height cr.translate(w/2, h/2) for i in range(self.NUM_LINES): cr.set_source_rgba(0, 0, 0, self.trs[self.count%8][i]) cr.move_to(0.0, -35.0) cr.line_to(0.0, -100.0) cr.rotate(math.pi/4) cr.stroke() class WelcomePane(gtk.VBox): def __init__(self, parent=None): self.par = parent super(WelcomePane, self).__init__() self.connect('expose-event', self._expose) self._option_table = gtk.Table(1, 2, False) self._option_table.set_col_spacings(12) self._option_table.set_homogeneous(False) header_table = gtk.Table(1, 2, False) header_table.set_col_spacings(12) header_icon = gtk.image_new_from_icon_name('face-laugh', gtk.ICON_SIZE_DIALOG) header_icon.yalign = 0.0 header = gtk.Label() header.set_markup(_('How would you like to play today?')) header.set_alignment(0.0, 0.5) header_table.attach(header_icon, 0, 1, 0, 1, gtk.FILL, gtk.FILL, 0, 0) header_table.attach(header, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL, 0, 0) self._header_align = gtk.Alignment(0, 1, 0, 0) self._table_align = gtk.Alignment(0, 0, 0, 0) self._set_alignments() self._header_align.add(header_table) self.pack_start(self._header_align, False, False, 5) self._row = 0 self._table_align.add(self._option_table) self.pack_start(self._table_align, False, False, 0) self.show_all() def _set_alignments(self): header_top_spacing = (self.par.get_size()[0] - 430) / 2 self._header_align.set_padding(25, 5, header_top_spacing, 0) self._table_align.set_padding(15, 0, header_top_spacing + 20, 0) def _attach_arrow(self, row): arrow_icon = gtk.image_new_from_stock(gtk.STOCK_GO_FORWARD, gtk.ICON_SIZE_BUTTON) arrow_icon.set_alignment(0.0, 1.0) arrow_icon.show() self._option_table.attach(arrow_icon, 0, 1, self._row, self._row + 1, gtk.FILL, gtk.FILL, 0, 0) def append(self, choice, detail, callback): button = gtk.Button() button.set_label(_('Play a game of tic tac toe against %s') % choice) if callback is not None: button.connect('clicked', callback) detail_label = self._build_detail_label('%s' % detail) detail_label.show() self._attach_arrow(self._row) self._option_table.attach(button, 1, 2, self._row, self._row + 1, gtk.EXPAND | gtk.FILL, 0, 0, 0) self._option_table.attach(detail_label, 1, 2, self._row + 1, self._row + 2, gtk.EXPAND | gtk.FILL, 0, 0, 0) self._option_table.set_row_spacing(self._row + 1, 15) self._row = self._row + 2 def _build_detail_label(self, markup): label = gtk.Label() label.set_markup(markup) label.set_alignment(0.0, 0.5) label.set_line_wrap(True) return label def _expose(self, widget, event): self._set_alignments() cr = widget.window.cairo_create() cr.set_source_rgba(1.0, 1.0, 1.0) cr.paint() tictactoe-0.3.2.1/tictactoe/contactselector.py0000644000175000017500000002676411264716434020052 0ustar alexalex#!/usr/bin/python # contactselector.py # (C) 2009 Alex Launi - alex.launi@gmail.com # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . import os import logging import gtk import dbus.mainloop.glib import telepathy from xdg import BaseDirectory from telepathy.interfaces import ( CHANNEL, CHANNEL_INTERFACE_GROUP, CHANNEL_TYPE_CONTACT_LIST, CONNECTION, CONNECTION_INTERFACE_ALIASING, CONNECTION_INTERFACE_AVATARS, CONNECTION_INTERFACE_CONTACTS, CONNECTION_INTERFACE_REQUESTS, CONNECTION_INTERFACE_SIMPLE_PRESENCE) from telepathy.constants import ( CONNECTION_PRESENCE_TYPE_AVAILABLE, CONNECTION_PRESENCE_TYPE_AWAY, CONNECTION_PRESENCE_TYPE_BUSY, CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY, HANDLE_TYPE_LIST) dbus.mainloop.glib.DBusGMainLoop(set_as_default = True) theme = gtk.icon_theme_get_default() logger = logging.root cache_dir = os.path.join(BaseDirectory.xdg_cache_home, 'tictactoe') avatar_cache_dir = os.path.join(cache_dir, 'avatars') if not os.path.exists(cache_dir): os.mkdir(cache_dir) if not os.path.exists(avatar_cache_dir): os.mkdir(avatar_cache_dir) def dbus_int_list_to_string(dbus_list): """Convert a dbus-list of integer to normal python one dbus_list can also be a normal python list; can't hurt""" return [int(x) for x in dbus_list] class _Contact: """Help class for the contact to be stored in ContactListStore""" def __init__(self, contact_id, alias, presence, avatar): self.contact_id = contact_id self.alias = alias self.presence = presence self.avatar = avatar class ContactList: """the list of contacts from *one* connection""" def __init__(self, list_store, conn): self._list_store = list_store self._conn = conn # dict of {handle=>Contact} # If ListStore supports searching, this _contact_list is not needed. self._contact_list = {} self._conn.call_when_ready(self._connection_ready_cb) def _connection_ready_cb(self, conn): logger.debug('Connection is ready: %s' % conn.service_name) # TODO react to connection status change if CONNECTION_INTERFACE_SIMPLE_PRESENCE not in conn: logger.warning('SIMPLE_PRESENCE interface not available on %s' % conn.service_name) return if CONNECTION_INTERFACE_REQUESTS not in conn: logger.warning('REQUESTS interface not available on %s' % conn.service_name) return if CONNECTION_INTERFACE_AVATARS not in conn: logger.warning('AVATARS interface not available on %s' % conn.service_name) else: self._conn[CONNECTION_INTERFACE_AVATARS].connect_to_signal( 'AvatarRetrieved', self._avatar_retrieved_cb, byte_arrays=True) conn[CONNECTION_INTERFACE_SIMPLE_PRESENCE].connect_to_signal( 'PresencesChanged', self._contact_presence_changed_cb) self._ensure_channel() def _ensure_channel(self): """Request the channel we needed to fetch contact-list""" # TODO is it ok to include only these two groups? groups = ["subscribe", "publish"] for group in groups: requests = { CHANNEL + ".ChannelType": CHANNEL_TYPE_CONTACT_LIST, CHANNEL + ".TargetHandleType": HANDLE_TYPE_LIST, CHANNEL + ".TargetID": group} self._conn[CONNECTION_INTERFACE_REQUESTS].EnsureChannel( requests, reply_handler = self._ensure_channel_cb, error_handler = self._error_cb) def _ensure_channel_cb(self, is_yours, channel, properties): """Got channel""" logger.debug('new channel ensured: channel=%s; it-is-yours=%s' % (channel, is_yours)) channel = telepathy.client.Channel( service_name = self._conn.service_name, object_path = channel) DBUS_PROPERTIES = 'org.freedesktop.DBus.Properties' channel[DBUS_PROPERTIES].Get( CHANNEL_INTERFACE_GROUP, 'Members', reply_handler = self._request_contact_info, error_handler = self._error_cb) def _request_contact_info(self, handles): """Request contact-info for a list of contact-handles""" interfaces = [CONNECTION, CONNECTION_INTERFACE_ALIASING, CONNECTION_INTERFACE_AVATARS, CONNECTION_INTERFACE_SIMPLE_PRESENCE] self._conn[CONNECTION_INTERFACE_CONTACTS].GetContactAttributes( handles, interfaces, False, reply_handler = self._get_contact_attributes_cb, error_handler = self._error_cb) self._conn[CONNECTION_INTERFACE_AVATARS].RequestAvatars(handles) def _avatar_retrieved_cb(self, contact, token, avatar, type): path = os.path.join(avatar_cache_dir, token) if os.path.exists(path): return file = open(path, 'wb') file.write(avatar) file.close() def _get_contact_attributes_cb(self, attributes): for handle, member in attributes.iteritems(): contact_info = self._parse_member_attributes(member) contact = _Contact(*contact_info) if handle not in self._contact_list: self._add_contact(handle, contact) def _parse_member_attributes(self, member): """Parse contact information out from dbus.Struct member""" contact_id, alias, presence, avatar = None, None, None, None # TODO won't these be in a certain order? for key, value in member.iteritems(): if key == CONNECTION + '/contact-id': contact_id = value elif key == CONNECTION_INTERFACE_ALIASING + '/alias': alias = value elif key == CONNECTION_INTERFACE_AVATARS + '/token': avatar = value elif key == CONNECTION_INTERFACE_SIMPLE_PRESENCE + '/presence': presence = value # TODO Can they be None? assert contact_id is not None assert presence is not None assert alias is not None return (contact_id, alias, presence, avatar) def _add_contact(self, handle, contact): self._contact_list[handle] = contact self._list_store.add_contact(self._conn, handle, contact) def _contact_presence_changed_cb(self, presences): for handle, presence in presences.iteritems(): if handle in self._contact_list: self._update_contact_presence(handle, presence) else: # request its info and consequently add it to the list self._request_contact_info([handle]) def _update_contact_presence(self, handle, presence): logger.debug('update presence of %s' % self._contact_list[handle].alias) self._contact_list[handle].presence = presence self._list_store.update_contact_presence(self._conn, handle, presence) def _error_cb(self, *args): logger.error('Error happens: %s' % args) class ContactListStore(gtk.ListStore): """ ListStore that contains contact list from (all connections of) telepathy """ # indices of columns that are of interest to display COL_CONTACT = 2 def __init__(self): # row format: , , , , gtk.ListStore.__init__(self, object, int, object, str, gtk.gdk.Pixbuf) # dict of {connection->ContactList} self._contact_lists = {} connections = self._get_telepathy_connections() # TODO: what if new connection is available? self._watch_contacts(connections) def _get_telepathy_connections(self): """Return telepathy connections on dbus Use a separate method for the sake of easy test""" return telepathy.client.Connection.get_connections() def _watch_contacts(self, connections): if not connections: logger.warning('No telepathy connections available') return logger.debug('Got %s telepathy connections' % len(connections)) for conn in connections: self._contact_lists[conn] = ContactList(self, conn) def add_contact(self, conn, handle, contact): """ Add a row to ListStore. conn and handle are used to uniquely refer to a certain row/contact """ if contact.avatar is None: avatar = self._load_default_avatar() else: avatar = self._load_contact_avatar(contact) self.append((conn, handle, contact, contact.alias, avatar)) def update_contact_presence(self, conn, handle, presence): # TODO: bruteforce for row in self: if (row[0], row[1]) == (conn, handle): self[row.iter][self.COL_CONTACT].presence = presence self.row_changed(row.path, row.iter) def _load_contact_avatar(self, contact): path = os.path.join(avatar_cache_dir, contact.avatar) if os.path.exists(path): try: avatar = gtk.gdk.pixbuf_new_from_file(path) avatar = avatar.scale_simple(48, 48, gtk.gdk.INTERP_BILINEAR) return avatar except: pass return self._load_default_avatar() def _load_default_avatar(self): return theme.load_icon("stock_people", 48, 0) class ContactSelector(gtk.IconView): """An Icon view for selecting contacts""" COL_CONTACT = 2 COL_NAME = 3 COL_PIXBUF = 4 def __init__(self): list_store = ContactListStore() list_store.set_sort_func(1, self._sort_contacts) list_store.set_sort_column_id(1, gtk.SORT_ASCENDING) online_model_filter = list_store.filter_new() online_model_filter.set_visible_func(self._filter_online_contacts) super(ContactSelector, self).__init__(online_model_filter) self.set_selection_mode(gtk.SELECTION_SINGLE) self.set_text_column(self.COL_NAME) self.set_pixbuf_column(self.COL_PIXBUF) self.set_margin(2) self.set_column_spacing(2) self.set_row_spacing(2) self.set_columns(4) def _sort_contacts(self, model, iter1, iter2): contact1 = self._get_contact(model, iter1) contact2 = self._get_contact(model, iter2) if contact1 is not None and contact2 is not None: return contact1.alias.lower() > contact2.alias.lower() return 0 def _filter_online_contacts(self, model, treeiter): online_statues = [ CONNECTION_PRESENCE_TYPE_AVAILABLE, CONNECTION_PRESENCE_TYPE_AWAY, CONNECTION_PRESENCE_TYPE_BUSY, CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY] contact = self._get_contact(model, treeiter) if contact: return contact.presence[0] in online_statues else: return False def _get_contact(self, model, treeiter): contact_column = ContactListStore.COL_CONTACT return model[treeiter][contact_column] # TODO: why contact can be None? tictactoe-0.3.2.1/tictactoe/__init__.py0000644000175000017500000000000211264716434016366 0ustar alexalex tictactoe-0.3.2.1/tictactoe/main.py0000644000175000017500000003465611264716434015601 0ustar alexalex#!/usr/bin/python # main.py # (C) 2009 Alex Launi - alex.launi@gmail.com # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . import sys import logging import random import time import gtk from widgets import TicTacToeBoard from widgets import WaitingAnimation from widgets import WelcomePane import tptube import tubehandler import contactselector import networking # i18n import locale import gettext LOCALEDIR = '/usr/share/locale' DOMAIN = 'tictactoe' locale.setlocale(locale.LC_ALL, "") gettext.bindtextdomain(DOMAIN, LOCALEDIR) gettext.textdomain(DOMAIN) _ = gettext.lgettext logger = logging.root class TicTacToeGame(gtk.Window): _single_title = _('tic-tac-toe all by yourself') _tube_title = _('tic-tac-toe with %s') _tube_service = 'org.gnome.TicTacToe' _initiator_obj_path = '/Initiator' _receiver_obj_path = '/Receiver' def __init__(self): super(TicTacToeGame, self).__init__() random.seed(time.time()) try: self.set_icon_name("tictactoe") except: logger.warning('No tictactoe icon exists; not using window icon') self.set_default_size(600, 600) self.set_geometry_hints(self, min_width=500, min_height=500, max_width=-1, max_height=-1, min_aspect=1.0, max_aspect=1.0) #self.set_size_request(500, 500) self.set_app_paintable(True) self.set_title(self._single_title) self.set_position(gtk.WIN_POS_CENTER) self._content_vbox = gtk.VBox(False, 0) self._board = TicTacToeBoard(self._content_vbox) self.on_button_press_handler = self._board.connect('button-press-event', self.on_board_button_press_event) self._build_menu() self._welcome = WelcomePane(self) self._welcome.append(_('the computer'), _('Bored? All alone? Play by yourself vs. the computer, but watch out the computer might be smarter than you think!'), self._new_with_computer_clicked) self._welcome.append(_('an online friend'), _('You can even play instantly, online, right now, at this very moment, with one of your Empathy contacts.'), self._new_with_contact_clicked) self._welcome.append(_('a friend sitting next to you'), _('Hanging out with a friend? Want to play tic tac toe but are totally into this green zero-paper lifestyle craze? Trade the mouse back and forth in this fast paced high aventure game of tic tac toe.'), self._new_with_local_friend_clicked) self._content_vbox.pack_start(self._welcome, True, True, 0) #self._content_vbox.pack_start(self._board, True, True, 0) self.add(self._content_vbox) self.connect('destroy', gtk.main_quit) self.in_game = False self.player = self._board.X self.computer = None self._friend = None self._tube = None self._peer = None self._is_initiator = None self._is_waiting_for_response = None # this should be extraced out self.tubehandler = tubehandler.TubeHandler(self._tube_service, tube_received_cb=self._process_accepted_tube) self.show_all() # this is kind of silly but we call this here to build the avatar cache contactselector.ContactSelector() def _playable(self): return self.in_game and self._board.winning_points is None and self._board.move_count < 9 def _start_game(self): def reply_handler(*args): logger.debug('signal peer: %s' % str(args)) def error_handler(error): logger.debug('signal peer: %s' % error) self.in_game = True self._board.new_game() if self._peer: self._peer.new_game( reply_handler=reply_handler, error_handler=error_handler) self.queue_draw() def _end_game(self): self.in_game = False self._board.disconnect(self.on_button_press_handler) self.on_button_press_handler = self._board.connect('button-press-event', self._on_board_newgame_button_press) def _build_menu(self): accel_group = gtk.AccelGroup() self.add_accel_group(accel_group) menubar = gtk.MenuBar() gamemenu = gtk.Menu() gamem = gtk.MenuItem(_('_Game')) gamem.set_submenu(gamemenu) new_game_item = gtk.MenuItem(_('_New game')) new_game_item.connect('activate', self._on_newgame_menu_btn_clicked) gamemenu.append(new_game_item) sep = gtk.SeparatorMenuItem() gamemenu.append(sep) exit_item = gtk.ImageMenuItem(gtk.STOCK_QUIT, accel_group) key, mod = gtk.accelerator_parse('Q') exit_item.add_accelerator('activate', accel_group, key, mod, gtk.ACCEL_VISIBLE) exit_item.connect('activate', gtk.main_quit) gamemenu.append(exit_item) menubar.append(gamem) self._content_vbox.pack_start(menubar, False, False, 0) def _get_computer_move(self): found_winner = False winner = [0, self.computer, self.computer] loser = [0, self.player, self.player] board = self._board.game_matrix # in case there aren't any other decent moves we just use (2, 2) or a random if board[1][1] == self._board.Blank: x = y = 1 else: x = random.randint(0, 2) y = random.randint(0, 2) # find any horizontal wins i = 0 for row in board: tmp = list(row) tmp.sort() if tmp == winner or tmp == loser: x = i y = row.index(self._board.Blank) if tmp == winner: found_winner = True break i = i + 1 for i in range(3): if found_winner: break col = [] for j in range(3): col.append(board[j][i]) tmp = list(col) tmp.sort() if tmp == winner or tmp == loser: x = col.index(self._board.Blank) y = i if tmp == winner: found_winner = True break diag1 = [board[0][0], board[1][1], board[2][2]] diag2 = [board[2][0], board[1][1], board[0][2]] tmp1 = list(diag1) tmp1.sort() tmp2 = list(diag2) tmp2.sort() if not found_winner: diag = None if tmp1 == winner: x = y = diag1.index(self._board.Blank) elif tmp2 == winner: y = diag2.index(self._board.Blank) if y == 0: x = 2 elif y == 1: x = 1 else: x = 0 elif tmp1 == loser: x = y = diag1.index(self._board.Blank) elif tmp2 == loser: y = diag2.index(self._board.Blank) if y == 0: x = 2 elif y == 1: x = 1 else: x = 0 return (x, y) def _on_newgame_menu_btn_clicked(self, action): self._set_main_widget(self._welcome) def _new_with_computer_clicked(self, action): self.computer = self._board.O self._show_board() self._start_game() def _new_with_local_friend_clicked(self, action): self._show_board() self._start_game() def _new_with_contact_clicked(self, action): selector = contactselector.ContactSelector() selector.connect('item-activated', self._on_contact_activated) sw = gtk.ScrolledWindow() sw.set_shadow_type(gtk.SHADOW_NONE) sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) sw.add(selector) self._set_main_widget(sw, True) def on_board_button_press_event(self, widget, event): def reply_handler(*args): logger.debug('signal peer: %s' % str(args)) def error_handler(error): logger.debug('signal peer: %s' % error) if not self._playable(): self.in_game = True return space = self._board.space_clicked(widget, event) if self._board.make_move(space, self.player): if self._peer: self._peer.make_move(space[0], space[1], self.player, reply_handler=reply_handler, error_handler=error_handler) elif self.computer is not None: while self._playable(): space = self._get_computer_move() if self._board.make_move(space, self.computer): break else: if self.player == self._board.X: self.player = self._board.O else: self.player = self._board.X if not self._playable(): self._end_game() return False def _on_board_newgame_button_press(self, widget, event): self._board.disconnect(self.on_button_press_handler) self._start_game() self.on_button_press_handler = self._board.connect('button-press-event', self.on_board_button_press_event) if not self._peer: self.player = self._board.X self.in_game = True def _on_contact_activated(self, widget, iter): def response_cb(dialog, response_id): if self._is_waiting_for_response: if response_id in (gtk.RESPONSE_CANCEL, gtk.RESPONSE_DELETE_EVENT): self._tube_offer.cancel() self._is_initiator = None # else don't need to do anything self._show_board() def offer_fail_cb(offer, reason): self._is_waiting_for_response = False self._is_initiator = None self._set_main_widget(self._welcome) logger.error('failed to connect dbus tube') model = widget.get_model() contact = model[iter] if contact: conn, handle, contact, alias, icon = contact choice = (conn, handle) if not choice: return self._friend = alias self.in_game = True self._is_initiator = True self.player = self._board.X conn, handle = choice self._tube_offer = tptube.TubeOffer(conn, handle, self._tube_service) self._tube_offer.connect("offer-succeeded", self._tube_offered_cb) self._tube_offer.connect("offer-failed", offer_fail_cb) self._waiting_animation() try: self._tube_offer.execute() except: offer_fail_cb(self._tube_offer, "You can't tube yourself, weirdo") def _set_main_widget(self, widget, cancelable=False, stock=gtk.STOCK_GO_BACK, callback=None): self._previous = self._content_vbox.get_children()[1] self._content_vbox.remove(self._previous) if callback is None: callback = self._cancel_btn_clicked if cancelable: cancel_btn = gtk.Button(stock=stock) cancel_btn.connect('clicked', callback) bbox = gtk.HButtonBox() bbox.set_layout(gtk.BUTTONBOX_END) bbox.pack_start(cancel_btn, False, False, 5) halign = gtk.Alignment(1, 0, 0, 0) halign.set_padding(2, 0, 0, 3) halign.add(bbox) vbox = gtk.VBox() vbox.set_spacing(2) vbox.pack_start(widget, True, True, 0) vbox.pack_end(halign, False, False, 0) self._content_vbox.add(vbox) else: self._content_vbox.add(widget) self._content_vbox.show_all() def _set_playing_with_friend_title(self): if self._friend: title = self._tube_title % self._friend else: title = self._tube_title % _("a friend") self.set_title(title) def _board_showing(self): return self._content_vbox.get_children()[1] == self._board def _show_board(self): if self._board_showing(): return self.in_game = True self._set_main_widget(self._board) def _waiting_animation(self): waiting = WaitingAnimation(self._content_vbox) self._set_main_widget(waiting) waiting.start() def _cancel_btn_clicked(self, button): self._set_main_widget(self._previous) def _tube_offered_cb(self, offer, bus, tube): """Called when the peer accepts our tube""" self._show_board() self._board.new_game() self._tube = tube self._tube[tptube.CHANNEL_INTERFACE].connect_to_signal( 'Closed', self._tube_closed_cb) if not self._negotiate_peer_proxy(bus): return self._set_playing_with_friend_title() def _tube_closed_cb(self): self._is_initiator = None self._tube = None self._friend = None def _process_accepted_tube(self, bus, tube): """User has accepted the tube """ self._is_initiator = False self._tube = tube self._tube[tptube.CHANNEL_INTERFACE].connect_to_signal( 'Closed', self._tube_closed_cb) if not self._negotiate_peer_proxy(bus): return self._set_playing_with_friend_title() self.player = self._board.O self._show_board() self._board.new_game() def _incoming_cancel_btn_clicked(self, action, reply_handler): self._content_vbox.remove(self._content_vbox.get_children()[1]) reply_handler(gtk.RESPONSE_CANCEL) def _negotiate_peer_proxy(self, bus): if self._is_initiator: me, peer = self._initiator_obj_path, self._receiver_obj_path else: me, peer = self._receiver_obj_path, self._initiator_obj_path myself = networking.Peer(bus, me, self._board) try: self._peer = bus.get_object(object_path=peer) except dbus.exceptions.DBusException, err: logger.error('Error when contacting with initiator: %s' % err) return False return True if __name__ == '__main__': TicTacToeGame() gtk.main() tictactoe-0.3.2.1/tictactoe/tptube.py0000644000175000017500000001071611264716434016147 0ustar alexalex#!/usr/bin/python # tptube.py # (C) 2009 Alex Launi - alex.launi@gmail.com # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . import logging import dbus import gobject from gettext import gettext as _ from telepathy.client.channel import Channel from telepathy.interfaces import ( CHANNEL_INTERFACE, CHANNEL_INTERFACE_TUBE, CHANNEL_TYPE_DBUS_TUBE, CONNECTION_INTERFACE_REQUESTS) from telepathy.constants import ( HANDLE_TYPE_CONTACT, SOCKET_ACCESS_CONTROL_CREDENTIALS, TUBE_CHANNEL_STATE_OPEN, TUBE_CHANNEL_STATE_REMOTE_PENDING) import telepathy.errors logger = logging.root class TubeOffer(gobject.GObject): __gsignals__ = { "offer-succeeded": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (object, object)), "offer-failed": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (str,)), } def __init__(self, conn, handle, tube_service): logger.debug('Create tube request') gobject.GObject.__init__(self) self._tube_state = None self._address = None self._chan = None self._closed_signal = None self._conn = conn self._handle = handle self._tube_service = tube_service def _tube_state_changed_cb(self, state): self._tube_state = state if state == TUBE_CHANNEL_STATE_OPEN: logger.debug('Tube state changed ->open') tube_conn = dbus.connection.Connection(self._address) self.emit("offer-succeeded", tube_conn, self._chan) elif state == TUBE_CHANNEL_STATE_REMOTE_PENDING: logger.debug('Tube state changed ->remote-pending') else: logger.debug('Tube state changed ->%s' % state) def _tube_closed_cb(self): logger.debug('tube closed') if self._tube_state == TUBE_CHANNEL_STATE_REMOTE_PENDING: # if tube is already open, it's not _offer_ failed (it's other # problems) self.emit("offer-failed", _("Connection closed by peer")) def cancel(self): if self._chan: logger.debug('Cancelling tube request') self._closed_signal.remove() self._chan[CHANNEL_INTERFACE].Close() def execute(self): request = { CHANNEL_INTERFACE + ".ChannelType": CHANNEL_TYPE_DBUS_TUBE, CHANNEL_INTERFACE + ".TargetHandleType": HANDLE_TYPE_CONTACT, CHANNEL_INTERFACE + ".TargetHandle": self._handle, CHANNEL_TYPE_DBUS_TUBE + ".ServiceName": self._tube_service} try: path, props = self._conn[CONNECTION_INTERFACE_REQUESTS].CreateChannel(request) except dbus.exceptions.DBusException, excep: error_busname = telepathy.errors.NotImplemented().get_dbus_name() if excep.get_dbus_name() == error_busname: msg = ('REQUESTS interface not implemented on %s' % self._conn.service_name) self.emit('offer-failed', msg) return else: raise self._chan = Channel(self._conn.service_name, path) self._chan[CHANNEL_INTERFACE_TUBE].connect_to_signal( 'TubeChannelStateChanged', self._tube_state_changed_cb) self._closed_signal = self._chan[CHANNEL_INTERFACE].connect_to_signal( 'Closed', self._tube_closed_cb) logger.debug('offering tube') try: data = "" self._address = self._chan[CHANNEL_TYPE_DBUS_TUBE].Offer( data, SOCKET_ACCESS_CONTROL_CREDENTIALS) except dbus.exceptions.DBusException, excep: error_busname = telepathy.errors.NotAvailable().get_dbus_name() if excep.get_dbus_name() == error_busname: msg = str(excep) self.emit("offer-failed", msg) return else: raise tictactoe-0.3.2.1/tictactoe/networking.py0000644000175000017500000000257511264716434017037 0ustar alexalex#!/usr/bin/python # networking.py # (C) 2009 Alex Launi - alex.launi@gmail.com # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . import dbus game_interface = "org.gnome.TicTacToe.game" class Peer(dbus.service.Object): def __init__(self, bus, obj_path, board): """game is the UI in main.py, for which we should get a better name """ dbus.service.Object.__init__(self, bus, obj_path) self._board = board @dbus.service.method(dbus_interface=game_interface, in_signature="", out_signature="") def new_game(self): self._board.new_game() @dbus.service.method(dbus_interface=game_interface, in_signature="iii", out_signature="") def make_move(self, x, y, player): x, y, player = int(x), int(y), int(player) self._board.make_move([x, y], player) tictactoe-0.3.2.1/tictactoe.desktop.in0000644000175000017500000000025311264716434016265 0ustar alexalex[Desktop Entry] _Name=Tic Tac Toe Type=Application _Comment=Simple, fun tic tac toe game for GNOME Exec=tictactoe Icon=tictactoe Terminal=False Categories=GNOME;GTK;Game;