├── LICENSE ├── README.md ├── handy ├── 1-box.py ├── 2-headerbar.py ├── 3-revealer.py ├── 4-stack.py ├── 5-style-classes.py └── 6-deck.py ├── libadwaita ├── 1-hello-world.py ├── 2-buttons.py ├── 3-leaflet.py ├── 4-clamp.py ├── 5-lists.py ├── 6-view-switcher.py ├── 7-carousel.py └── resources │ └── 2-buttons.css ├── screenshots ├── handy │ ├── 1-box-py.png │ ├── 2-headerbar-py.png │ ├── 3-revealer-py.png │ ├── 4-stack-py.png │ ├── 5-style-classes-py.png │ └── 6-deck-py.png └── libadwaita │ ├── 1-hello-world-py.png │ ├── 2-buttons-py.png │ ├── 3-leaflet-py.png │ ├── 4-clamp-py.png │ ├── 5-lists-py.png │ ├── 6-view-switcher-py.png │ └── 7-carousel-py.png ├── shell.nix └── vanilla-gtk └── 1-first-step.py /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | [This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.] 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS 459 | 460 | How to Apply These Terms to Your New Libraries 461 | 462 | If you develop a new library, and you want it to be of the greatest 463 | possible use to the public, we recommend making it free software that 464 | everyone can redistribute and change. You can do so by permitting 465 | redistribution under these terms (or, alternatively, under the terms of the 466 | ordinary General Public License). 467 | 468 | To apply these terms, attach the following notices to the library. It is 469 | safest to attach them to the start of each source file to most effectively 470 | convey the exclusion of warranty; and each file should have at least the 471 | "copyright" line and a pointer to where the full notice is found. 472 | 473 | 474 | Copyright (C) 475 | 476 | This library is free software; you can redistribute it and/or 477 | modify it under the terms of the GNU Lesser General Public 478 | License as published by the Free Software Foundation; either 479 | version 2.1 of the License, or (at your option) any later version. 480 | 481 | This library is distributed in the hope that it will be useful, 482 | but WITHOUT ANY WARRANTY; without even the implied warranty of 483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 484 | Lesser General Public License for more details. 485 | 486 | You should have received a copy of the GNU Lesser General Public 487 | License along with this library; if not, write to the Free Software 488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 489 | USA 490 | 491 | Also add information on how to contact you by electronic and paper mail. 492 | 493 | You should also get your employer (if you work as a programmer) or your 494 | school, if any, to sign a "copyright disclaimer" for the library, if 495 | necessary. Here is a sample; alter the names: 496 | 497 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 498 | library `Frob' (a library for tweaking knobs) written by James Random 499 | Hacker. 500 | 501 | , 1 April 1990 502 | Ty Coon, President of Vice 503 | 504 | That's all there is to it! 505 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PyGObject examples 2 | 3 | | libhandy | screenshot | 4 | | ------------------ | ---------------------------------------------------------- | 5 | | 1-box.py | ![box](screenshots/handy/1-box-py.png) | 6 | | 2-headerbar.py | ![headerbar](screenshots/handy/2-headerbar-py.png) | 7 | | 3-revealer.py | ![revealer](screenshots/handy/3-revealer-py.png) | 8 | | 4-stack.py | ![stack](screenshots/handy/4-stack-py.png) | 9 | | 5-style-classes.py | ![style-classes](screenshots/handy/5-style-classes-py.png) | 10 | | 6-deck.py | ![deck](screenshots/handy/6-deck-py.png) | 11 | 12 | | libadwaita | screenshot | 13 | | ------------------ | -------------------------------------------------------------- | 14 | | 1-hello-world.py | ![helloworld](screenshots/libadwaita/1-hello-world-py.png) | 15 | | 2-buttons.py | ![buttons](screenshots/libadwaita/2-buttons-py.png) | 16 | | 3-leaflet.py | ![leaflet](screenshots/libadwaita/3-leaflet-py.png) | 17 | | 4-clamp.py | ![clamp](screenshots/libadwaita/4-clamp-py.png) | 18 | | 5-lists.py | ![lists](screenshots/libadwaita/5-lists-py.png) | 19 | | 6-view-switcher.py | ![viewswitcher](screenshots/libadwaita/6-view-switcher-py.png) | 20 | | 7-carousel.py | ![carousel](screenshots/libadwaita/7-carousel-py.png) | 21 | 22 | ## Requirements: 23 | 24 | - Python 3 25 | - GTK+ 3.0 (4.0 for libadwaita) 26 | - Handy 1.0 27 | - Libadwaita 1.0 28 | -------------------------------------------------------------------------------- /handy/1-box.py: -------------------------------------------------------------------------------- 1 | import gi, os 2 | gi.require_version("Gtk", "3.0") 3 | gi.require_version("Handy", "1") 4 | from gi.repository import Gtk, Handy 5 | 6 | Handy.init() 7 | 8 | class MyWindow(Handy.Window): 9 | def __init__(self): 10 | super().__init__(title="Hello World") 11 | 12 | # WindowHandle 13 | self.handle = Handy.WindowHandle() 14 | self.add(self.handle) 15 | 16 | # Box 17 | self.box = Gtk.Box(spacing=6, halign=Gtk.Align.CENTER, valign=Gtk.Align.CENTER) 18 | self.handle.add(self.box) 19 | 20 | # Button 1 21 | self.button1 = Gtk.Button(label="Merhaba") 22 | self.button1.connect("clicked", self.on_button1_clicked) 23 | self.box.pack_start(self.button1, True, True, 0) 24 | 25 | # Button 2 26 | self.button2 = Gtk.Button(label="Güle güle") 27 | self.button2.connect("clicked", self.on_button2_clicked) 28 | self.box.pack_start(self.button2, True, True, 0) 29 | 30 | # Button 3 31 | self.button3 = Gtk.Button(label="Hebele") 32 | self.button3.connect("clicked", self.on_button3_clicked) 33 | self.box.pack_start(self.button3, True, True, 0) 34 | 35 | # Button 4 36 | self.button4 = Gtk.Button(label="Temizle") 37 | self.button4.connect("clicked", self.on_button4_clicked) 38 | self.box.pack_start(self.button4, True, True, 0) 39 | 40 | def on_button1_clicked(self, widget): 41 | print("Merhaba") 42 | 43 | def on_button2_clicked(self, widget): 44 | print("Güle güle") 45 | 46 | def on_button3_clicked(self, widget): 47 | print("Hübele") 48 | 49 | def on_button4_clicked(self, widget): 50 | os.system("clear") 51 | 52 | 53 | win = MyWindow() 54 | win.connect("destroy", Gtk.main_quit) 55 | win.show_all() 56 | Gtk.main() 57 | -------------------------------------------------------------------------------- /handy/2-headerbar.py: -------------------------------------------------------------------------------- 1 | selamun = "aleyküm" 2 | 3 | import gi, os 4 | gi.require_version("Gtk", "3.0") 5 | gi.require_version("Handy", "1") 6 | from gi.repository import Gtk, Handy, GLib 7 | 8 | Handy.init() 9 | 10 | class MyWindow(Handy.Window): 11 | def __init__(self): 12 | super().__init__(title="Hello World") 13 | GLib.set_application_name("Hello World") 14 | GLib.set_prgname('Hello World') 15 | self.set_default_size(500, 300) 16 | 17 | # WindowHandle 18 | self.handle = Handy.WindowHandle() 19 | self.add(self.handle) 20 | 21 | # Box 22 | self.winbox = Gtk.Box(spacing=6, orientation=Gtk.Orientation.VERTICAL) 23 | self.handle.add(self.winbox) 24 | 25 | # Headerbar 26 | self.hb = Handy.HeaderBar() 27 | self.hb.set_show_close_button(True) 28 | self.hb.props.title = "HeaderBar Example" 29 | self.winbox.pack_start(self.hb, False, True, 0) 30 | 31 | # Label 32 | self.lbl = Gtk.Label() 33 | self.lbl.set_text("Hebele hübele") 34 | self.lbl.set_justify(Gtk.Justification.CENTER) 35 | self.winbox.pack_start(self.lbl, True, True, 0) 36 | 37 | # Headerbar button 1 38 | self.button = Gtk.Button() 39 | self.button = Gtk.Button.new_from_icon_name("pan-start-symbolic", Gtk.IconSize.MENU) 40 | self.hb.pack_start(self.button) 41 | 42 | # Headerbar button 2 43 | self.button2 = Gtk.Button() 44 | self.button2 = Gtk.Button.new_from_icon_name("pan-end-symbolic", Gtk.IconSize.MENU) 45 | self.hb.pack_start(self.button2) 46 | 47 | 48 | win = MyWindow() 49 | win.connect("destroy", Gtk.main_quit) 50 | win.show_all() 51 | Gtk.main() 52 | -------------------------------------------------------------------------------- /handy/3-revealer.py: -------------------------------------------------------------------------------- 1 | selamun = "aleyküm" 2 | 3 | import gi, os 4 | gi.require_version("Gtk", "3.0") 5 | gi.require_version("Handy", "1") 6 | from gi.repository import Gtk, Handy 7 | 8 | Handy.init() 9 | 10 | class MyWindow(Handy.Window): 11 | def __init__(self): 12 | super().__init__(title="Hello World") 13 | self.set_default_size(500, 300) 14 | 15 | # WindowHandle 16 | self.handle = Handy.WindowHandle() 17 | self.add(self.handle) 18 | 19 | # WinBox 20 | self.winBox = Gtk.Box(spacing=6, orientation=Gtk.Orientation.VERTICAL) 21 | self.handle.add(self.winBox) 22 | 23 | # Revealer 24 | self.revealer = Gtk.Revealer() 25 | self.revealer.set_reveal_child(True) 26 | self.winBox.pack_start(self.revealer, False, True, 0) 27 | 28 | # Headerbar 29 | self.hb = Handy.HeaderBar() 30 | self.hb.set_show_close_button(True) 31 | self.hb.props.title = "Revealer Example" 32 | self.revealer.add(self.hb) 33 | 34 | # MainBox 35 | self.mainBox = Gtk.Box(spacing=6, orientation=Gtk.Orientation.VERTICAL, halign=Gtk.Align.CENTER, valign=Gtk.Align.CENTER) 36 | self.winBox.pack_start(self.mainBox, True, False, 0) 37 | 38 | # Revealer button 39 | self.rvBtn = Gtk.Button(label="Hide headerbar") 40 | self.mainBox.pack_start(self.rvBtn, True, False, 0) 41 | self.rvBtn.connect("clicked", self.on_rvBtn_clicked) 42 | 43 | def on_rvBtn_clicked(self, widget): 44 | reveal = self.revealer.get_reveal_child() 45 | if reveal == True: 46 | self.revealer.set_reveal_child(False) 47 | self.rvBtn.set_label("Show headerbar") 48 | else: 49 | self.revealer.set_reveal_child(True) 50 | self.rvBtn.set_label("Hide headerbar") 51 | 52 | win = MyWindow() 53 | win.connect("destroy", Gtk.main_quit) 54 | win.show_all() 55 | Gtk.main() -------------------------------------------------------------------------------- /handy/4-stack.py: -------------------------------------------------------------------------------- 1 | selamun = "aleyküm" 2 | 3 | import gi, os 4 | gi.require_version("Gtk", "3.0") 5 | gi.require_version("Handy", "1") 6 | from gi.repository import Gtk, Handy 7 | 8 | Handy.init() 9 | 10 | class MyWindow(Handy.Window): 11 | def __init__(self): 12 | super().__init__(title="Hello World") 13 | self.set_default_size(500, 300) 14 | 15 | # WindowHandle 16 | self.handle = Handy.WindowHandle() 17 | self.add(self.handle) 18 | 19 | # Box 20 | self.winbox = Gtk.Box(spacing=6, orientation=Gtk.Orientation.VERTICAL) 21 | self.handle.add(self.winbox) 22 | 23 | # Headerbar 24 | self.hb = Handy.HeaderBar() 25 | self.hb.set_show_close_button(True) 26 | self.hb.props.title = "Stack Example" 27 | self.winbox.pack_start(self.hb, False, True, 0) 28 | 29 | # Stack 30 | self.stack = Gtk.Stack() 31 | self.stack.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT_RIGHT) 32 | self.winbox.pack_start(self.stack, True, True, 0) 33 | 34 | # Labels 35 | self.label = Gtk.Label(label="Page 1") 36 | self.stack.add_titled(self.label, "page0", "Label") 37 | 38 | self.label = Gtk.Label(label="Page 2") 39 | self.stack.add_titled(self.label, "page1", "Label") 40 | 41 | self.label = Gtk.Label(label="Page 3") 42 | self.stack.add_titled(self.label, "page2", "Label") 43 | 44 | self.label = Gtk.Label(label="Page 4") 45 | self.stack.add_titled(self.label, "page3", "Label") 46 | 47 | self.label = Gtk.Label(label="Page 5") 48 | self.stack.add_titled(self.label, "page4", "Label") 49 | 50 | # Headerbar button 1 51 | self.button = Gtk.Button() 52 | self.button = Gtk.Button.new_from_icon_name("pan-start-symbolic", Gtk.IconSize.MENU) 53 | self.hb.pack_start(self.button) 54 | self.button.connect('clicked', self.on_button1_clicked) 55 | 56 | # Headerbar button 2 57 | self.button2 = Gtk.Button() 58 | self.button2 = Gtk.Button.new_from_icon_name("pan-end-symbolic", Gtk.IconSize.MENU) 59 | self.hb.pack_start(self.button2) 60 | self.button2.connect("clicked", self.on_button2_clicked) 61 | 62 | # https://stackoverflow.com/questions/69595073/pygobject-page-switching-with-buttons 63 | def on_button1_clicked(self, widget): 64 | pages = self.stack.get_children() 65 | cur_page = self.stack.get_visible_child() 66 | i = pages.index(cur_page) 67 | if i == 0: return 68 | self.stack.set_visible_child(pages[i-1]) 69 | 70 | def on_button2_clicked(self, widget): 71 | pages = self.stack.get_children() 72 | cur_page = self.stack.get_visible_child() 73 | i = pages.index(cur_page) 74 | if i == len(pages) - 1: return 75 | self.stack.set_visible_child(pages[i+1]) 76 | 77 | win = MyWindow() 78 | win.connect("destroy", Gtk.main_quit) 79 | win.show_all() 80 | Gtk.main() -------------------------------------------------------------------------------- /handy/5-style-classes.py: -------------------------------------------------------------------------------- 1 | import gi 2 | gi.require_version("Gtk", "3.0") 3 | gi.require_version("Handy", "1") 4 | from gi.repository import Gtk, Handy 5 | 6 | Handy.init() 7 | 8 | class MyWindow(Handy.Window): 9 | def __init__(self): 10 | super().__init__(title="Hello World") 11 | self.set_default_size(900, 300) 12 | self.handle = Handy.WindowHandle() 13 | self.add(self.handle) 14 | 15 | # Window box 16 | self.winbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) 17 | self.handle.add(self.winbox) 18 | ## Headerbar 19 | self.hb = Handy.HeaderBar() 20 | self.hb.set_show_close_button(True) 21 | self.hb.props.title = "Style Classes Example" 22 | self.winbox.pack_start(self.hb, False, True, 0) 23 | 24 | # MainBox 25 | self.mainbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6, halign=Gtk.Align.CENTER, valign=Gtk.Align.CENTER) 26 | self.winbox.pack_start(self.mainbox, True, True, 0) 27 | ## Button box 28 | self.btn_box = Gtk.ButtonBox(halign=Gtk.Align.CENTER, valign=Gtk.Align.CENTER, spacing=6) 29 | self.mainbox.pack_start(self.btn_box, True, True, 0) 30 | ### Normal button 31 | self.btn = Gtk.Button(label="Normal") 32 | self.btn_box.pack_start(self.btn, False, False, 0) 33 | ### Suggested button 34 | self.btn_suggested = Gtk.Button(label="Suggested") 35 | self.btn_suggested.get_style_context().add_class("suggested-action") 36 | self.btn_box.pack_start(self.btn_suggested, False, False, 0) 37 | ### Destructive button 38 | self.btn_destructive = Gtk.Button(label="Destructive") 39 | self.btn_destructive.get_style_context().add_class("destructive-action") 40 | self.btn_box.pack_start(self.btn_destructive, False, False, 0) 41 | 42 | ## Flat button box 43 | self.btn_box2 = Gtk.ButtonBox(halign=Gtk.Align.CENTER, valign=Gtk.Align.CENTER, spacing=6) 44 | self.mainbox.pack_start(self.btn_box2, True, True, 0) 45 | ### Normal button 46 | self.btn_flat = Gtk.Button(label="Flat") 47 | self.btn_flat.get_style_context().add_class("flat") 48 | self.btn_box.pack_start(self.btn_flat, False, False, 0) 49 | ### Suggested button 50 | self.btn_suggested_flat = Gtk.Button(label="Suggested Flat") 51 | self.btn_suggested_flat.get_style_context().add_class("suggested-action") 52 | self.btn_suggested_flat.get_style_context().add_class("flat") 53 | self.btn_box.pack_start(self.btn_suggested_flat, False, False, 0) 54 | ### Destructive button 55 | self.btn_destructive_flat = Gtk.Button(label="Destructive Flat") 56 | self.btn_destructive_flat.get_style_context().add_class("destructive-action") 57 | self.btn_destructive_flat.get_style_context().add_class("flat") 58 | self.btn_box.pack_start(self.btn_destructive_flat, False, False, 0) 59 | 60 | win = MyWindow() 61 | win.connect("destroy", Gtk.main_quit) 62 | win.show_all() 63 | Gtk.main() 64 | -------------------------------------------------------------------------------- /handy/6-deck.py: -------------------------------------------------------------------------------- 1 | import gi 2 | gi.require_version ('Gtk', '3.0') 3 | gi.require_version ('Handy', '1') 4 | from gi.repository import Gtk, Handy 5 | 6 | Handy.init () 7 | 8 | class MyWindow (Handy.Window): 9 | def __init__ (self): 10 | super() .__init__( 11 | title = 'Hello World' 12 | ) 13 | self.set_default_size (900, 300) 14 | 15 | # WindowHandle 16 | self.hdl = Handy.WindowHandle () 17 | self.add (self.hdl) 18 | 19 | # Deck 20 | self.deck = Handy.Deck () 21 | self.deck.set_can_swipe_back (True) 22 | self.hdl.add (self.deck) 23 | 24 | # Main Page 25 | self.mainpage = Gtk.Box( 26 | spacing = 6, 27 | orientation = Gtk.Orientation.VERTICAL 28 | ) 29 | 30 | self.hb = Handy.HeaderBar() 31 | self.hb.set_show_close_button(True) 32 | self.hb.props.title = "Handy Deck Example" 33 | self.mainpage.pack_start( 34 | self.hb, 35 | False, 36 | True, 37 | 0 38 | ) 39 | self.deck.add (self.mainpage) 40 | 41 | # Page 1 42 | self.page1 = Gtk.Box( 43 | spacing = 6, 44 | orientation = Gtk.Orientation.VERTICAL, 45 | halign = Gtk.Align.CENTER, 46 | valign = Gtk.Align.CENTER 47 | ) 48 | self.lbl_page1 = Gtk.Label ( 49 | label = 'Page 1', 50 | ) 51 | self.btn_prev1 = Gtk.Button ( 52 | label = 'Previous', 53 | halign = Gtk.Align.CENTER, 54 | valign = Gtk.Align.CENTER 55 | ) 56 | self.btn_prev1.connect( 57 | 'clicked', self.on_prev_clicked 58 | ) 59 | self.page1.pack_start( 60 | self.lbl_page1, 61 | True, 62 | True, 63 | 0 64 | ) 65 | self.page1.pack_start( 66 | self.btn_prev1, 67 | True, 68 | True, 69 | 0 70 | ) 71 | 72 | self.deck.add (self.page1) 73 | 74 | # Page 2 75 | self.page2 = Gtk.Box( 76 | spacing = 6, 77 | orientation = Gtk.Orientation.VERTICAL, 78 | halign = Gtk.Align.CENTER, 79 | valign = Gtk.Align.CENTER 80 | ) 81 | self.lbl_page2 = Gtk.Label ( 82 | label = 'Page 2' 83 | ) 84 | self.btn_prev2 = Gtk.Button ( 85 | label = 'Previous', 86 | halign = Gtk.Align.CENTER, 87 | valign = Gtk.Align.CENTER 88 | ) 89 | self.btn_prev2.connect( 90 | 'clicked', self.on_prev_clicked 91 | ) 92 | self.page2.pack_start( 93 | self.lbl_page2, 94 | True, 95 | True, 96 | 0 97 | ) 98 | self.page2.pack_start( 99 | self.btn_prev2, 100 | True, 101 | True, 102 | 0 103 | ) 104 | 105 | self.deck.add (self.page2) 106 | 107 | # Page 3 108 | self.page3 = Gtk.Box( 109 | spacing = 6, 110 | orientation = Gtk.Orientation.VERTICAL, 111 | halign = Gtk.Align.CENTER, 112 | valign = Gtk.Align.CENTER 113 | ) 114 | self.btn_prev3 = Gtk.Button ( 115 | label = 'Previous', 116 | halign = Gtk.Align.CENTER, 117 | valign = Gtk.Align.CENTER 118 | ) 119 | self.btn_prev3.connect( 120 | 'clicked', self.on_prev_clicked 121 | ) 122 | self.lbl_page3 = Gtk.Label ( 123 | label = 'Page 3' 124 | ) 125 | self.page3.pack_start( 126 | self.lbl_page3, 127 | True, 128 | True, 129 | 0 130 | ) 131 | self.page3.pack_start( 132 | self.btn_prev3, 133 | True, 134 | True, 135 | 0 136 | ) 137 | 138 | self.deck.add (self.page3) 139 | 140 | # Main page 141 | self.btn_box = Gtk.ButtonBox ( 142 | spacing = 6, 143 | halign = Gtk.Align.CENTER, 144 | valign = Gtk.Align.CENTER 145 | ) 146 | 147 | self.btn_page1 = Gtk.Button ( 148 | label = 'Page 1', 149 | ) 150 | self.btn_box.add (self.btn_page1) 151 | self.btn_page1.connect( 152 | 'clicked', 153 | self.on_btn_page1_clicked 154 | ) 155 | 156 | self.btn_page2 = Gtk.Button ( 157 | label = 'Page 2', 158 | ) 159 | self.btn_page2.connect( 160 | 'clicked', self.on_btn_page2_clicked 161 | ) 162 | 163 | self.btn_box.add (self.btn_page2) 164 | 165 | self.btn_page3 = Gtk.Button ( 166 | label = 'Page 3' 167 | ) 168 | 169 | self.btn_page3.connect( 170 | 'clicked', 171 | self.on_btn_page3_clicked 172 | ) 173 | 174 | self.btn_box.add (self.btn_page3) 175 | self.mainpage.pack_start( 176 | self.btn_box, 177 | True, 178 | True, 179 | 0 180 | ) 181 | 182 | def on_btn_page1_clicked (self, widget): 183 | self.deck.set_visible_child (self.page1) 184 | def on_btn_page2_clicked (self, widget): 185 | self.deck.set_visible_child (self.page2) 186 | def on_btn_page3_clicked (self, widget): 187 | self.deck.set_visible_child (self.page3) 188 | def on_prev_clicked (self, widget): 189 | self.deck.set_visible_child (self.mainpage) 190 | 191 | win = MyWindow () 192 | win.connect ('destroy', Gtk.main_quit) 193 | win.show_all () 194 | Gtk.main () 195 | -------------------------------------------------------------------------------- /libadwaita/1-hello-world.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import gi 3 | gi.require_version('Gtk', '4.0') 4 | gi.require_version('Adw', '1') 5 | from gi.repository import Gtk, Adw, GLib, Gio 6 | 7 | 8 | class MainWindow(Gtk.ApplicationWindow): 9 | def __init__(self, *args, **kwargs): 10 | super().__init__(*args, **kwargs) 11 | self.set_default_size(300, 400) 12 | self.set_title("Merhaba dünya!") 13 | GLib.set_application_name("Merhaba Dünya!") 14 | GLib.set_prgname('Merhaba Dünya!') 15 | 16 | self.main_box = Gtk.Box( 17 | orientation = Gtk.Orientation.VERTICAL, 18 | spacing = 6, # Öğeler arasında boşluk 19 | halign = Gtk.Align.CENTER, 20 | valign = Gtk.Align.CENTER # Öğeleri ortaya sabitledik 21 | ) 22 | self.set_child(self.main_box) 23 | 24 | self.lbl_hello = Gtk.Label( 25 | label = "Merhaba dünya" 26 | ) 27 | self.main_box.append(self.lbl_hello) 28 | 29 | self.btn_hello = Gtk.Button( 30 | label = "Bana tıkla" 31 | ) 32 | self.btn_hello.connect( 33 | "clicked", 34 | self.btn_hello_clicked 35 | ) 36 | self.main_box.append(self.btn_hello) 37 | 38 | self.hb = Gtk.HeaderBar() 39 | self.set_titlebar(self.hb) 40 | 41 | self.btn_open = Gtk.Button( 42 | label = "Aç" 43 | ) 44 | self.btn_open.set_icon_name("document-open-symbolic") 45 | self.hb.pack_start(self.btn_open) 46 | 47 | self.dyl_open = Gtk.FileChooserNative.new( 48 | title = "Bir dosya seçin", 49 | parent = self, 50 | action = Gtk.FileChooserAction.OPEN 51 | ) 52 | self.dyl_open.connect("response", self.open_response) 53 | self.btn_open.connect("clicked", self.show_open_dialog) 54 | 55 | self.lbl_filepath = Gtk.Label() 56 | 57 | menuAction = Gio.SimpleAction.new("birseyler", None) 58 | menuAction.connect("activate", self.print_something) 59 | self.add_action(menuAction) 60 | 61 | menu = Gio.Menu.new() 62 | menu.append("Bir şeyler yap!", "win.birseyler") 63 | 64 | self.popover = Gtk.PopoverMenu() 65 | self.popover.set_menu_model(menu) 66 | 67 | self.hamburger = Gtk.MenuButton() 68 | self.hamburger.set_popover(self.popover) 69 | self.hamburger.set_icon_name("open-menu-symbolic") 70 | 71 | self.hb.pack_end(self.hamburger) 72 | 73 | app = self.get_application() 74 | sm = app.get_style_manager() 75 | sm.set_color_scheme(Adw.ColorScheme.PREFER_DARK) 76 | 77 | self.main_box.set_margin_top(10) 78 | self.main_box.set_margin_bottom(10) 79 | self.main_box.set_margin_start(10) 80 | self.main_box.set_margin_end(10) 81 | 82 | def print_something(self, action, param): 83 | print("Bir şeyler!") 84 | 85 | def open_response(self, dialog, response): 86 | if response == Gtk.ResponseType.ACCEPT: 87 | file = dialog.get_file() 88 | filename = file.get_path() 89 | self.lbl_filepath.set_label(filename) 90 | self.main_box.append(self.lbl_filepath) 91 | 92 | def show_open_dialog(self, button): 93 | self.dyl_open.show() 94 | 95 | def btn_hello_clicked(self, button): 96 | print("Merhaba dünya!") 97 | 98 | class MyApp(Adw.Application): 99 | def __init__(self, **kwargs): 100 | super().__init__(**kwargs) 101 | self.connect('activate', self.on_activate) 102 | 103 | def on_activate(self, app): 104 | self.win = MainWindow(application=app) 105 | self.win.present() 106 | 107 | app = MyApp(application_id="net.teteos.example") 108 | app.run(sys.argv) -------------------------------------------------------------------------------- /libadwaita/2-buttons.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import gi 3 | import os 4 | gi.require_version ( 5 | 'Gtk', '4.0' 6 | ) 7 | gi.require_version ( 8 | 'Adw', '1' 9 | ) 10 | from gi.repository import Gtk, Adw, GLib, Gio, Gdk 11 | 12 | class MainWindow (Gtk.ApplicationWindow): 13 | def __init__ (self, *args, **kwargs): 14 | super ().__init__ (*args, **kwargs) 15 | GLib.set_application_name ('Adwaita Buttons') 16 | GLib.set_prgname ('Adwaita Examples by Afacanc38') 17 | 18 | self.set_default_size (500, 600) 19 | 20 | css_provider = Gtk.CssProvider() 21 | css_provider.load_from_file(Gio.File.new_for_path(f'{os.path.dirname(os.path.realpath(__file__))}/resources/2-buttons.css')) 22 | Gtk.StyleContext.add_provider_for_display(Gdk.Display.get_default(), css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION) 23 | 24 | self.hb = Gtk.HeaderBar () 25 | self.set_titlebar (self.hb) 26 | 27 | self.scroll = Gtk.ScrolledWindow () 28 | self.scroll.set_policy (Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) 29 | self.set_child (self.scroll) 30 | 31 | self.main_box = Gtk.Box ( 32 | spacing = 10, 33 | orientation = Gtk.Orientation.VERTICAL 34 | ) 35 | self.main_box.set_margin_top (20) 36 | self.main_box.set_margin_bottom (20) 37 | self.main_box.set_margin_start (20) 38 | self.main_box.set_margin_end (20) 39 | self.scroll.set_child(self.main_box) 40 | 41 | self.box_normal_buttons_group = Gtk.Box ( 42 | spacing = 6, 43 | orientation = Gtk.Orientation.VERTICAL, 44 | halign = Gtk.Align.START, 45 | valign = Gtk.Align.CENTER 46 | ) 47 | self.main_box.append (self.box_normal_buttons_group) 48 | 49 | self.lbl_normal_buttons_title = Gtk.Label ( 50 | label = 'Normal Buttons', 51 | halign = Gtk.Align.START 52 | ) 53 | self.lbl_normal_buttons_title.get_style_context().add_class ('title-1') 54 | self.box_normal_buttons_group.append (self.lbl_normal_buttons_title) 55 | 56 | self.box_normal_buttons = Gtk.Box ( 57 | spacing = 6 58 | ) 59 | self.box_normal_buttons_group.append (self.box_normal_buttons) 60 | 61 | self.normal_button_regular = Gtk.Button ( 62 | label = 'Regular' 63 | ) 64 | self.box_normal_buttons.append (self.normal_button_regular) 65 | 66 | self.normal_button_flat = Gtk.Button ( 67 | label = 'Flat' 68 | ) 69 | self.normal_button_flat.get_style_context().add_class ('flat') 70 | self.box_normal_buttons.append (self.normal_button_flat) 71 | 72 | self.normal_button_suggested = Gtk.Button ( 73 | label = 'Suggested' 74 | ) 75 | self.normal_button_suggested.get_style_context ().add_class ('suggested-action') 76 | self.box_normal_buttons.append (self.normal_button_suggested) 77 | 78 | self.normal_button_destructive = Gtk.Button ( 79 | label = 'Destructive' 80 | ) 81 | self.normal_button_destructive.get_style_context ().add_class ('destructive-action') 82 | self.box_normal_buttons.append (self.normal_button_destructive) 83 | 84 | self.box_custom_buttons = Gtk.Box ( 85 | spacing = 6 86 | ) 87 | self.box_normal_buttons_group.append (self.box_custom_buttons) 88 | 89 | self.custom_button_green = Gtk.Button ( 90 | label = 'Custom' 91 | ) 92 | self.custom_button_green.get_style_context ().add_class ('green') 93 | self.box_custom_buttons.append (self.custom_button_green) 94 | 95 | self.custom_button_purple = Gtk.Button ( 96 | label = 'Custom' 97 | ) 98 | self.custom_button_purple.get_style_context ().add_class ('purple') 99 | self.box_custom_buttons.append (self.custom_button_purple) 100 | 101 | self.custom_button_yellow = Gtk.Button ( 102 | label = 'Custom' 103 | ) 104 | self.custom_button_yellow.get_style_context ().add_class ('yellow') 105 | self.box_custom_buttons.append (self.custom_button_yellow) 106 | 107 | self.custom_button_orange = Gtk.Button ( 108 | label = 'Custom' 109 | ) 110 | self.custom_button_orange.get_style_context ().add_class ('orange') 111 | self.box_custom_buttons.append (self.custom_button_orange) 112 | 113 | self.box_other_buttons_group = Gtk.Box ( 114 | spacing = 6, 115 | orientation = Gtk.Orientation.VERTICAL, 116 | halign = Gtk.Align.START, 117 | valign = Gtk.Align.CENTER 118 | ) 119 | self.main_box.append (self.box_other_buttons_group) 120 | 121 | self.lbl_ohter_buttons_title = Gtk.Label ( 122 | label = 'Other Buttons', 123 | halign = Gtk.Align.START 124 | ) 125 | self.lbl_ohter_buttons_title.get_style_context ().add_class ('title-1') 126 | self.box_other_buttons_group.append (self.lbl_ohter_buttons_title) 127 | 128 | self.box_other_buttons = Gtk.Box ( 129 | spacing = 6 130 | ) 131 | self.box_other_buttons_group.append (self.box_other_buttons) 132 | 133 | self.circular_button_1 = Gtk.Button.new_from_icon_name ('go-home-symbolic') 134 | self.circular_button_1.get_style_context().add_class ('circular') 135 | self.box_other_buttons.append (self.circular_button_1) 136 | 137 | self.circular_button_2 = Gtk.Button.new_from_icon_name ('document-save-symbolic') 138 | self.circular_button_2.get_style_context().add_class ('circular') 139 | self.box_other_buttons.append (self.circular_button_2) 140 | 141 | self.circular_button_3 = Gtk.Button.new_from_icon_name ('document-properties-symbolic') 142 | self.circular_button_3.get_style_context().add_class ('circular') 143 | self.box_other_buttons.append (self.circular_button_3) 144 | 145 | self.box_other_buttons_2 = Gtk.Box ( 146 | spacing = 6 147 | ) 148 | self.box_other_buttons_group.append (self.box_other_buttons_2) 149 | 150 | self.pill_button = Gtk.Button ( 151 | label = 'Pill Button' 152 | ) 153 | self.pill_button.get_style_context ().add_class ('pill') 154 | self.box_other_buttons_2.append (self.pill_button) 155 | class MyApp (Adw.Application): 156 | def __init__ (self, **kwargs): 157 | super ().__init__ (**kwargs) 158 | self.connect ( 159 | 'activate', 160 | self.on_activate 161 | ) 162 | 163 | def on_activate (self, app): 164 | self.win = MainWindow ( 165 | application = app 166 | ) 167 | self.win.present () 168 | 169 | app = MyApp( 170 | application_id = 'io.github.afacanc38.adw-buttons' 171 | ) 172 | app.run(sys.argv) -------------------------------------------------------------------------------- /libadwaita/3-leaflet.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import gi 3 | import os 4 | gi.require_version ( 5 | 'Gtk', '4.0' 6 | ) 7 | gi.require_version ( 8 | 'Adw', '1' 9 | ) 10 | from gi.repository import Gtk, Adw, GLib, Gio, Gdk 11 | 12 | class MainWindow (Gtk.ApplicationWindow): 13 | def __init__ (self, *args, **kwargs): 14 | super ().__init__ ( 15 | *args, 16 | **kwargs 17 | ) 18 | 19 | GLib.set_application_name ( 20 | 'Adwaita Leaflet' 21 | ) 22 | GLib.set_prgname ( 23 | 'Adwaita Examples by Afacanc38' 24 | ) 25 | 26 | self.set_default_size (300, 300) 27 | 28 | self.hb = Gtk.HeaderBar () 29 | self.set_titlebar (self.hb) 30 | 31 | self.lf_main = Adw.Leaflet ( 32 | halign = Gtk.Align.FILL, 33 | valign = Gtk.Align.FILL 34 | ) 35 | self.lf_main.set_can_unfold (False) 36 | self.set_child ( 37 | self.lf_main 38 | ) 39 | 40 | # Home Page 41 | 42 | self.pg_home = Gtk.Box ( 43 | spacing = 6, 44 | halign = Gtk.Align.FILL, 45 | valign = Gtk.Align.FILL, 46 | hexpand = True, 47 | vexpand = True, 48 | orientation = Gtk.Orientation.VERTICAL 49 | ) 50 | self.pg_home.set_margin_top (20) 51 | self.pg_home.set_margin_bottom (20) 52 | self.pg_home.set_margin_start (20) 53 | self.pg_home.set_margin_end (20) 54 | 55 | self.lf_main.append ( 56 | self.pg_home 57 | ) 58 | 59 | self.btn_go_second = Gtk.Button ( 60 | label = "Go to second page" 61 | ) 62 | self.btn_go_second.connect ( 63 | 'clicked', 64 | self.on_btn_go_second 65 | ) 66 | self.btn_go_second.get_style_context ().add_class ('pill') 67 | self.pg_home.append ( 68 | self.btn_go_second 69 | ) 70 | self.sw_box_set_can_unfold = Gtk.Box ( 71 | spacing = 6, 72 | orientation = Gtk.Orientation.HORIZONTAL 73 | ) 74 | self.pg_home.append ( 75 | self.sw_box_set_can_unfold 76 | ) 77 | self.sw_set_can_unfold = Gtk.Switch () 78 | self.sw_set_can_unfold.set_active (True) 79 | self.sw_set_can_unfold.connect ( 80 | 'notify::active', 81 | self.on_set_can_unfold 82 | ) 83 | self.sw_box_set_can_unfold.append ( 84 | self.sw_set_can_unfold 85 | ) 86 | 87 | self.sw_lbl_set_can_unfold = Gtk.Label ( 88 | label = 'Can unfold' 89 | ) 90 | self.sw_box_set_can_unfold.append ( 91 | self.sw_lbl_set_can_unfold 92 | ) 93 | 94 | # Second page 95 | 96 | self.pg_second = Gtk.Box ( 97 | spacing = 6, 98 | halign = Gtk.Align.FILL, 99 | valign = Gtk.Align.FILL, 100 | hexpand = True, 101 | vexpand = True, 102 | orientation = Gtk.Orientation.VERTICAL 103 | ) 104 | 105 | self.pg_second.set_margin_top (20) 106 | self.pg_second.set_margin_bottom (20) 107 | self.pg_second.set_margin_start (20) 108 | self.pg_second.set_margin_end (20) 109 | 110 | self.lf_main.append ( 111 | self.pg_second 112 | ) 113 | 114 | self.lbl_pg2 = Gtk.Label ( 115 | label = 'Second Page' 116 | ) 117 | self.pg_second.append ( 118 | self.lbl_pg2 119 | ) 120 | 121 | self.btn_go_home = Gtk.Button ( 122 | label = "Retrun to home" 123 | ) 124 | self.btn_go_home.get_style_context ().add_class ('pill') 125 | self.pg_second.append ( 126 | self.btn_go_home 127 | ) 128 | self.btn_go_home.connect ( 129 | 'clicked', 130 | self.on_btn_go_home 131 | ) 132 | 133 | 134 | def on_set_can_unfold (self, switch, gparam): 135 | if self.sw_set_can_unfold.get_active() == False: 136 | self.lf_main.set_can_unfold (True) 137 | else: 138 | self.lf_main.set_can_unfold (False) 139 | 140 | def on_btn_go_second (self, widget): 141 | self.lf_main.set_visible_child (self.pg_second) 142 | 143 | def on_btn_go_home (self, widget): 144 | self.lf_main.set_visible_child (self.pg_home) 145 | 146 | class MyApp (Adw.Application): 147 | def __init__ (self, **kwargs): 148 | super ().__init__ ( 149 | **kwargs 150 | ) 151 | self.connect ( 152 | 'activate', 153 | self.on_activate 154 | ) 155 | 156 | def on_activate (self, app): 157 | self.win = MainWindow ( 158 | application = app 159 | ) 160 | self.win.present () 161 | 162 | app = MyApp ( 163 | application_id = 'io.github.afacanc38.adw-leaflet' 164 | ) 165 | app.run (sys.argv) -------------------------------------------------------------------------------- /libadwaita/4-clamp.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import gi 3 | gi.require_version('Gtk', '4.0') 4 | gi.require_version('Adw', '1') 5 | from gi.repository import Gtk, Adw, GLib 6 | 7 | class MainWindow (Adw.ApplicationWindow): 8 | def __init__ (self, *args, **kwargs): 9 | super ().__init__ ( 10 | *args, 11 | **kwargs 12 | ) 13 | # Set application name 14 | GLib.set_prgname ( 15 | 'Adwaita Examples by Afacanc38' 16 | ) 17 | GLib.set_application_name ( 18 | 'Adwaita Clamp' 19 | ) 20 | 21 | self.box_main = Gtk.Box ( 22 | orientation = Gtk.Orientation.VERTICAL 23 | ) 24 | self.set_content ( 25 | self.box_main 26 | ) 27 | 28 | # Headerbar 29 | self.hb = Gtk.HeaderBar () 30 | self.box_main.append ( 31 | self.hb 32 | ) 33 | 34 | # Clamp widget 35 | self.clamp = Adw.Clamp () 36 | self.box_main.append ( 37 | self.clamp 38 | ) 39 | 40 | # Wrapper inside Adw.Clamp 41 | self.box_wrapper = Gtk.Box ( 42 | spacing = 10, 43 | margin_start = 20, 44 | margin_end = 20, 45 | margin_top = 20, 46 | margin_bottom = 20, 47 | orientation = Gtk.Orientation.VERTICAL 48 | ) 49 | self.clamp.set_child ( 50 | self.box_wrapper 51 | ) 52 | 53 | # Label 54 | self.lbl1 = Gtk.Label ( 55 | label = 'This widget is inside the Clamp.', 56 | halign = Gtk.Align.CENTER 57 | ) 58 | self.lbl1.get_style_context ().add_class ( 59 | 'title-1' 60 | ) 61 | self.lbl1.set_wrap ( 62 | True 63 | ) 64 | self.box_wrapper.append ( 65 | self.lbl1 66 | ) 67 | 68 | # Sample box 69 | self.box_sample = Gtk.Box () 70 | self.box_sample.get_style_context ().add_class ( 71 | 'card' 72 | ) 73 | self.box_wrapper.append ( 74 | self.box_sample 75 | ) 76 | 77 | # Label inside sample box 78 | self.lbl2 = Gtk.Label ( 79 | label = "I am a box", 80 | margin_start = 10, 81 | margin_end = 10, 82 | margin_top = 10, 83 | margin_bottom = 10, 84 | ) 85 | self.box_sample.append ( 86 | self.lbl2 87 | ) 88 | 89 | class MyApp (Adw.Application): 90 | def __init__ (self, **kwargs): 91 | super ().__init__ ( 92 | **kwargs 93 | ) 94 | 95 | self.connect ( 96 | 'activate', 97 | self.on_activate 98 | ) 99 | 100 | def on_activate (self, app): 101 | self.win = MainWindow ( 102 | application = app 103 | ) 104 | self.win.present () 105 | 106 | app = MyApp ( 107 | application_id = 'io.github.afacanc38.adw-clamp' 108 | ) 109 | app.run (sys.argv) -------------------------------------------------------------------------------- /libadwaita/5-lists.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import gi 3 | import os 4 | gi.require_version('Gtk', '4.0') 5 | gi.require_version('Adw', '1') 6 | from gi.repository import Gtk, Adw, GLib, Gio, Gdk 7 | 8 | class MainWindow (Gtk.Window): 9 | def __init__ (self, *args, **kwargs): 10 | super ().__init__ (*args, **kwargs) 11 | 12 | GLib.set_prgname ( 13 | 'Adwaita Examples by Afacanc38' 14 | ) 15 | GLib.set_application_name ( 16 | 'Adwaita ListBox' 17 | ) 18 | 19 | self.set_default_size (650, 500) 20 | self.set_size_request (400, 400) 21 | 22 | self.scroll = Gtk.ScrolledWindow () 23 | self.scroll.set_policy (Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) 24 | self.set_child (self.scroll) 25 | 26 | self.box_main = Gtk.Box ( 27 | orientation = Gtk.Orientation.VERTICAL 28 | ) 29 | self.scroll.set_child ( 30 | self.box_main 31 | ) 32 | 33 | # HeaderBar 34 | self.hb = Gtk.HeaderBar () 35 | self.set_titlebar ( 36 | self.hb 37 | ) 38 | 39 | # Clamp 40 | self.clamp = Adw.Clamp () 41 | self.box_main.append ( 42 | self.clamp 43 | ) 44 | 45 | # Wrapper 46 | self.box_wrapper = Gtk.Box ( 47 | orientation = Gtk.Orientation.VERTICAL, 48 | margin_top = 20, 49 | margin_bottom = 20, 50 | margin_start = 20, 51 | margin_end = 20 52 | ) 53 | self.clamp.set_child ( 54 | self.box_wrapper 55 | ) 56 | 57 | # Header 58 | self.box_header = Gtk.Box ( 59 | orientation = Gtk.Orientation.VERTICAL, 60 | margin_bottom = 10 61 | ) 62 | self.box_wrapper.append ( 63 | self.box_header 64 | ) 65 | 66 | # Title 67 | self.lbl_title = Gtk.Label ( 68 | label = "Lists", 69 | halign = Gtk.Align.CENTER, 70 | wrap = True 71 | ) 72 | self.lbl_title.get_style_context ().add_class ('title-1') 73 | self.box_header.append ( 74 | self.lbl_title 75 | ) 76 | 77 | self.box_listbox_wrapper = Gtk.Box ( 78 | spacing = 20, 79 | orientation = Gtk.Orientation.VERTICAL 80 | ) 81 | self.box_wrapper.append ( 82 | self.box_listbox_wrapper 83 | ) 84 | 85 | # ListBox 86 | self.listbox1 = Gtk.ListBox ( 87 | selection_mode = Gtk.SelectionMode.NONE 88 | ) 89 | self.listbox1.get_style_context ().add_class ('boxed-list') 90 | self.box_listbox_wrapper.append ( 91 | self.listbox1 92 | ) 93 | 94 | # Row 1 95 | self.row_listbox1_1 = Adw.ActionRow ( 96 | title = 'ActionRow', 97 | subtitle = 'This ActionRow has subtitle and icon', 98 | icon_name = 'emblem-system-symbolic' 99 | ) 100 | self.listbox1.append ( 101 | self.row_listbox1_1 102 | ) 103 | 104 | # Row 2 105 | self.row_listbox1_2 = Adw.ActionRow ( 106 | title = 'ActionRow can have suffix widgets', 107 | icon_name = 'go-home-symbolic', 108 | subtitle = 'This listbox has subtitle, suffix widget and icon' 109 | ) 110 | 111 | self.btn_listbox1_2_suffix = Gtk.Button ( 112 | label = 'Button', 113 | halign = Gtk.Align.CENTER, 114 | valign = Gtk.Align.CENTER, 115 | ) 116 | self.row_listbox1_2.add_suffix ( 117 | self.btn_listbox1_2_suffix 118 | ) 119 | 120 | self.listbox1.append ( 121 | self.row_listbox1_2 122 | ) 123 | 124 | # ListBox 2 125 | self.listbox2 = Gtk.ListBox ( 126 | selection_mode = Gtk.SelectionMode.NONE 127 | ) 128 | self.listbox2.get_style_context ().add_class ('boxed-list') 129 | self.box_listbox_wrapper.append ( 130 | self.listbox2 131 | ) 132 | 133 | # Row 1 134 | self.row_listbox2_1 = Adw.ActionRow ( 135 | title = 'ActionRow can have prefix widgets', 136 | activatable = True 137 | ) 138 | 139 | self.rd_listbox2_1_prefix = Gtk.CheckButton () 140 | self.row_listbox2_1.add_prefix ( 141 | self.rd_listbox2_1_prefix 142 | ) 143 | self.row_listbox2_1.set_activatable_widget ( 144 | self.rd_listbox2_1_prefix 145 | ) 146 | 147 | self.listbox2.append ( 148 | self.row_listbox2_1 149 | ) 150 | 151 | # Row 2 152 | self.row_listbox2_2 = Adw.ActionRow ( 153 | title = 'ActionRow can have prefix widgets', 154 | activatable = True 155 | ) 156 | 157 | self.rd_listbox2_2_prefix = Gtk.CheckButton () 158 | self.row_listbox2_2.add_prefix ( 159 | self.rd_listbox2_2_prefix 160 | ) 161 | self.rd_listbox2_2_prefix.set_group ( 162 | self.rd_listbox2_1_prefix 163 | ) 164 | self.row_listbox2_2.set_activatable_widget ( 165 | self.rd_listbox2_2_prefix 166 | ) 167 | 168 | self.listbox2.append ( 169 | self.row_listbox2_2 170 | ) 171 | 172 | # ListBox 3 173 | self.prfgr_listbox3 = Adw.PreferencesGroup ( 174 | title = 'Expander Rows', 175 | margin_top = 10 176 | ) 177 | self.box_wrapper.append ( 178 | self.prfgr_listbox3 179 | ) 180 | 181 | self.listbox3 = Gtk.ListBox ( 182 | selection_mode = Gtk.SelectionMode.NONE 183 | ) 184 | self.listbox3.get_style_context ().add_class ('boxed-list') 185 | self.prfgr_listbox3.add ( 186 | self.listbox3 187 | ) 188 | 189 | # ExpanderRow 1 190 | self.row_listbox3_1 = Adw.ExpanderRow ( 191 | title = 'ExpanderRow', 192 | subtitle = 'This ActionRow has subtitle and icon', 193 | icon_name = 'emblem-system-symbolic' 194 | ) 195 | self.listbox3.append ( 196 | self.row_listbox3_1 197 | ) 198 | 199 | for x in range(3): 200 | self.row_listbox3_1.add_row ( 201 | Adw.ActionRow ( 202 | title = 'Nested row', 203 | ) 204 | ) 205 | # ExpanderRow 2 206 | self.row_listbox3_2 = Adw.ExpanderRow ( 207 | title = 'ExpanderRow', 208 | subtitle = 'With an action', 209 | icon_name = 'emblem-system-symbolic' 210 | ) 211 | self.btn_listbox3_2_action = Gtk.Button.new_from_icon_name ( 212 | 'edit-copy-symbolic', 213 | ) 214 | self.btn_listbox3_2_action.set_halign (Gtk.Align.CENTER) 215 | self.btn_listbox3_2_action.set_valign (Gtk.Align.CENTER) 216 | self.row_listbox3_2.add_action ( 217 | self.btn_listbox3_2_action 218 | ) 219 | self.listbox3.append ( 220 | self.row_listbox3_2 221 | ) 222 | 223 | for x in range(3): 224 | self.row_listbox3_2.add_row ( 225 | Adw.ActionRow ( 226 | title = 'Nested row', 227 | ) 228 | ) 229 | 230 | # ListBox 4 231 | self.prfgr_listbox4 = Adw.PreferencesGroup ( 232 | title = 'Preferences Group has a suffix', 233 | margin_top = 10 234 | ) 235 | 236 | self.btn_prfgr_listbox4_suffix = Gtk.Button () 237 | self.btn_prfgr_listbox4_suffix.get_style_context ().add_class ( 238 | 'image-text-button' 239 | ) 240 | self.btn_prfgr_listbox4_suffix.get_style_context ().add_class ( 241 | 'flat' 242 | ) 243 | 244 | self.btn_prfgr_listbox4_suffix_content = Adw.ButtonContent ( 245 | label = 'Button', 246 | icon_name = 'view-pin-symbolic' 247 | ) 248 | self.btn_prfgr_listbox4_suffix.set_child ( 249 | self.btn_prfgr_listbox4_suffix_content 250 | ) 251 | 252 | self.prfgr_listbox4.set_header_suffix ( 253 | self.btn_prfgr_listbox4_suffix 254 | ) 255 | 256 | self.box_wrapper.append ( 257 | self.prfgr_listbox4 258 | ) 259 | 260 | self.listbox4 = Gtk.ListBox ( 261 | selection_mode = Gtk.SelectionMode.NONE 262 | ) 263 | self.listbox4.get_style_context ().add_class ('boxed-list') 264 | self.prfgr_listbox4.add ( 265 | self.listbox4 266 | ) 267 | 268 | # ExpanderRow 1 269 | self.row_listbox4_1 = Adw.ExpanderRow ( 270 | title = 'ExpanderRow', 271 | subtitle = 'This ActionRow has subtitle and icon', 272 | icon_name = 'emblem-system-symbolic' 273 | ) 274 | self.listbox4.append ( 275 | self.row_listbox4_1 276 | ) 277 | 278 | for x in range(3): 279 | self.row_listbox4_1.add_row ( 280 | Adw.ActionRow ( 281 | title = 'Nested row', 282 | ) 283 | ) 284 | 285 | # ExpanderRow 2 286 | self.row_listbox4_2 = Adw.ExpanderRow ( 287 | title = 'ExpanderRow', 288 | subtitle = 'This ActionRow has subtitle and icon', 289 | icon_name = 'emblem-system-symbolic', 290 | show_enable_switch = True 291 | ) 292 | self.listbox4.append ( 293 | self.row_listbox4_2 294 | ) 295 | 296 | for x in range(3): 297 | self.row_listbox4_2.add_row ( 298 | Adw.ActionRow ( 299 | title = 'Nested row', 300 | ) 301 | ) 302 | 303 | # ListBox 5 304 | self.prfgr_listbox5 = Adw.PreferencesGroup ( 305 | title = 'Combo Rows', 306 | margin_top = 10 307 | ) 308 | self.box_wrapper.append ( 309 | self.prfgr_listbox5 310 | ) 311 | 312 | self.listbox5 = Gtk.ListBox ( 313 | selection_mode = Gtk.SelectionMode.NONE 314 | ) 315 | self.listbox5.get_style_context ().add_class ('boxed-list') 316 | self.prfgr_listbox5.add ( 317 | self.listbox5 318 | ) 319 | 320 | self.strlist_listbox5_1 = Gtk.StringList () 321 | self.strlist_listbox5_1.append ('Foo') 322 | self.strlist_listbox5_1.append ('Bar') 323 | self.strlist_listbox5_1.append ('Baz') 324 | # Row 1 325 | self.row_listbox5_1 = Adw.ComboRow ( 326 | title = 'This a combo row' 327 | ) 328 | self.row_listbox5_1.connect ( 329 | 'notify::selected-item', 330 | self.on_row_listbox5_1_select 331 | ) 332 | self.row_listbox5_1.set_model ( 333 | self.strlist_listbox5_1 334 | ) 335 | self.listbox5.append ( 336 | self.row_listbox5_1 337 | ) 338 | def on_row_listbox5_1_select (self, widget, event): 339 | print (f'"{self.row_listbox5_1.get_selected_item ().get_string ()}" is selected.') 340 | 341 | class MyApp (Adw.Application): 342 | def __init__ (self, **kwargs): 343 | super ().__init__ ( 344 | **kwargs 345 | ) 346 | self.connect ( 347 | 'activate', 348 | self.on_activate 349 | ) 350 | 351 | def on_activate (self, app): 352 | self.win = MainWindow ( 353 | application = app 354 | ) 355 | self.win.present () 356 | 357 | app = MyApp ( 358 | application_id = 'io.github.afacanc38.adw-listbox' 359 | ) 360 | app.run (sys.argv) -------------------------------------------------------------------------------- /libadwaita/6-view-switcher.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import gi 3 | gi.require_version ( 4 | "Gtk", 5 | "4.0" 6 | ) 7 | gi.require_version( 8 | "Adw", 9 | "1" 10 | ) 11 | from gi.repository import Gtk, Adw, GLib 12 | 13 | class MainWindow (Adw.ApplicationWindow): 14 | def __init__ (self, *args, **kwargs): 15 | super ().__init__ ( 16 | *args, 17 | **kwargs 18 | ) 19 | GLib.set_prgname ( 20 | 'Adwaita Examples by Afacanc38' 21 | ) 22 | GLib.set_application_name ( 23 | 'Adwaita ViewSwitcher' 24 | ) 25 | 26 | self.set_name ( 27 | 'ViewSwitcherDemo' 28 | ) 29 | self.set_default_size (600, 300) 30 | 31 | self.box_main = Gtk.Box ( 32 | orientation = Gtk.Orientation.VERTICAL, 33 | halign = Gtk.Align.FILL, 34 | valign = Gtk.Align.FILL, 35 | hexpand = True, 36 | vexpand = True 37 | ) 38 | self.set_content ( 39 | self.box_main 40 | ) 41 | 42 | self.hb = Adw.HeaderBar ( 43 | centering_policy = Adw.CenteringPolicy.STRICT 44 | ) 45 | self.box_main.append (self.hb) 46 | 47 | self.stack = Adw.ViewStack () 48 | self.box_main.append ( 49 | self.stack 50 | ) 51 | 52 | # Squeezer 53 | self.sq_viewswitcher = Adw.Squeezer ( 54 | halign = Gtk.Align.FILL, 55 | ) 56 | self.sq_viewswitcher.set_switch_threshold_policy ( 57 | Adw.FoldThresholdPolicy.NATURAL 58 | ) 59 | self.sq_viewswitcher.set_transition_type ( 60 | Adw.SqueezerTransitionType.CROSSFADE 61 | ) 62 | self.sq_viewswitcher.set_xalign (1) 63 | self.sq_viewswitcher.set_homogeneous (True) 64 | self.hb.set_title_widget ( 65 | self.sq_viewswitcher 66 | ) 67 | 68 | # ViewSwitcher (wide) 69 | self.viewswitcher_wide = Adw.ViewSwitcher ( 70 | halign = Gtk.Align.CENTER, 71 | margin_start = 50, 72 | margin_end = 50 73 | ) 74 | self.viewswitcher_wide.set_policy( 75 | Adw.ViewSwitcherPolicy.WIDE 76 | ) 77 | self.viewswitcher_wide.set_stack ( 78 | self.stack 79 | ) 80 | self.sq_viewswitcher.add ( 81 | self.viewswitcher_wide 82 | ) 83 | 84 | # ViewSwitcher (narrow) 85 | self.viewswitcher_narrow = Adw.ViewSwitcher ( 86 | halign = Gtk.Align.CENTER, 87 | ) 88 | self.viewswitcher_narrow.set_policy( 89 | Adw.ViewSwitcherPolicy.NARROW 90 | ) 91 | self.viewswitcher_narrow.set_stack ( 92 | self.stack 93 | ) 94 | self.sq_viewswitcher.add ( 95 | self.viewswitcher_narrow 96 | ) 97 | 98 | # ViewSwitcherBar (bottom viewswitcher) 99 | self.viewswitcherbar = Adw.ViewSwitcherBar ( 100 | vexpand = True, 101 | valign = Gtk.Align.END 102 | ) 103 | self.viewswitcherbar.set_stack ( 104 | self.stack 105 | ) 106 | self.viewswitcherbar.set_reveal (False) 107 | self.box_main.append ( 108 | self.viewswitcherbar 109 | ) 110 | 111 | # Window Title 112 | self.wintitle = Adw.WindowTitle ( 113 | title = 'Adwaita ViewSwitcher' 114 | ) 115 | self.sq_viewswitcher.add (self.wintitle) 116 | 117 | # Connect signals 118 | self.sq_viewswitcher.connect ( 119 | 'notify::visible-child', 120 | self.on_sq_get_visible_child 121 | ) 122 | 123 | # Page 1 124 | self.page1 = Adw.StatusPage ( 125 | title = 'Apps', 126 | icon_name = 'view-grid-symbolic', 127 | valign = Gtk.Align.CENTER, 128 | vexpand = True 129 | ) 130 | self.stack.add_titled ( 131 | self.page1, 132 | 'page0', 133 | 'Apps' 134 | ) 135 | self.stack.get_page (self.page1).set_icon_name ( 136 | 'view-grid-symbolic' 137 | ) 138 | 139 | # Page 2 140 | self.page2 = Adw.StatusPage ( 141 | title = 'Installed', 142 | icon_name = 'system-software-install-symbolic', 143 | valign = Gtk.Align.CENTER, 144 | vexpand = True 145 | ) 146 | self.stack.add_titled ( 147 | self.page2, 148 | 'page1', 149 | 'Installed' 150 | ) 151 | self.stack.get_page (self.page2).set_icon_name ( 152 | 'system-software-install-symbolic' 153 | ) 154 | 155 | # Page 3 156 | self.page3 = Adw.StatusPage ( 157 | title = 'Updates', 158 | icon_name = 'view-refresh-symbolic', 159 | valign = Gtk.Align.CENTER, 160 | vexpand = True 161 | ) 162 | self.stack.add_titled ( 163 | self.page3, 164 | 'page2', 165 | 'Updates' 166 | ) 167 | self.stack.get_page (self.page3).set_icon_name ( 168 | 'view-refresh-symbolic' 169 | ) 170 | 171 | def on_sq_get_visible_child (self, widget, event): 172 | if self.sq_viewswitcher.get_visible_child() == self.wintitle: 173 | self.viewswitcherbar.set_reveal (True) 174 | else: 175 | self.viewswitcherbar.set_reveal (False) 176 | 177 | class MyApp (Adw.Application): 178 | def __init__ (self, **kwargs): 179 | super ().__init__ (**kwargs) 180 | self.connect ( 181 | 'activate', 182 | self.on_activate 183 | ) 184 | 185 | def on_activate (self, app): 186 | self.win = MainWindow ( 187 | application = app 188 | ) 189 | self.win.present () 190 | 191 | app = MyApp ( 192 | application_id = 'io.github.afacanc38.adw-viewswitcher' 193 | ) 194 | app.run (sys.argv) 195 | -------------------------------------------------------------------------------- /libadwaita/7-carousel.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import gi 3 | gi.require_version ( 4 | 'Gtk', 5 | '4.0' 6 | ) 7 | gi.require_version ( 8 | 'Adw', 9 | '1' 10 | ) 11 | from gi.repository import Gtk, Adw, GLib 12 | 13 | class MainWindow (Adw.Window): 14 | def __init__ (self, *args, **kwargs): 15 | super ().__init__ ( 16 | *args, 17 | **kwargs 18 | ) 19 | GLib.set_prgname ( 20 | 'Adwaita Examples by Afacanc38' 21 | ) 22 | GLib.set_application_name ( 23 | 'Adwaita Carousel' 24 | ) 25 | self.set_default_size (650, 500) 26 | self.set_size_request (400, 400) 27 | 28 | self.box_main = Gtk.Box ( 29 | orientation = Gtk.Orientation.VERTICAL, 30 | valign = Gtk.Align.FILL, 31 | vexpand = True 32 | ) 33 | self.set_content ( 34 | self.box_main 35 | ) 36 | 37 | self.hb = Gtk.HeaderBar () 38 | self.box_main.append ( 39 | self.hb 40 | ) 41 | 42 | # Carousel 43 | self.carousel = Adw.Carousel ( 44 | hexpand = True, 45 | vexpand = True, 46 | allow_scroll_wheel = True, 47 | allow_long_swipes = False 48 | ) 49 | self.box_main.append ( 50 | self.carousel 51 | ) 52 | 53 | # Indicator 54 | self.stk_indicator = Gtk.Stack ( 55 | transition_type = Gtk.StackTransitionType.CROSSFADE 56 | ) 57 | self.box_main.append ( 58 | self.stk_indicator 59 | ) 60 | self.carousel_dots = Adw.CarouselIndicatorDots ( 61 | carousel = self.carousel 62 | ) 63 | self.stk_indicator.add_titled ( 64 | self.carousel_dots, 65 | 'page0', 66 | 'page0' 67 | ) 68 | self.carousel_lines = Adw.CarouselIndicatorLines ( 69 | carousel = self.carousel 70 | ) 71 | self.stk_indicator.add_titled ( 72 | self.carousel_lines, 73 | 'page1', 74 | 'page1' 75 | ) 76 | 77 | # Page 1 78 | self.page1 = Adw.StatusPage ( 79 | title = 'Carousel', 80 | description = 'A widget for paginated scrolling.', 81 | icon_name = 'go-next-symbolic', 82 | hexpand = True, 83 | vexpand = True, 84 | ) 85 | self.carousel.append ( 86 | self.page1 87 | ) 88 | # Page 2 89 | self.page2 = Gtk.Box ( 90 | hexpand = True, 91 | vexpand = True, 92 | halign = Gtk.Align.CENTER, 93 | valign = Gtk.Align.CENTER 94 | ) 95 | self.carousel.append ( 96 | self.page2 97 | ) 98 | 99 | self.clamp = Adw.Clamp () 100 | self.page2.append ( 101 | self.clamp 102 | ) 103 | 104 | self.listbox = Gtk.ListBox ( 105 | selection_mode = Gtk.SelectionMode.NONE 106 | ) 107 | self.listbox.get_style_context ().add_class ( 108 | 'boxed-list' 109 | ) 110 | self.clamp.set_child ( 111 | self.listbox 112 | ) 113 | 114 | self.setting1 = Adw.ComboRow ( 115 | title = 'Indicator Style' 116 | ) 117 | self.strlist1 = Gtk.StringList () 118 | self.strlist1.append ( 119 | 'Dots' 120 | ) 121 | self.strlist1.append ( 122 | 'Lines' 123 | ) 124 | self.setting1.set_model ( 125 | self.strlist1 126 | ) 127 | self.setting1.connect ( 128 | 'notify::selected-item', 129 | self.on_setting1_set 130 | ) 131 | self.listbox.append ( 132 | self.setting1 133 | ) 134 | 135 | self.setting2 = Adw.ActionRow ( 136 | title = 'Long swipes' 137 | ) 138 | self.sw_long_swipe = Gtk.Switch ( 139 | valign = Gtk.Align.CENTER 140 | ) 141 | self.sw_long_swipe.connect ( 142 | 'notify::active', 143 | self.on_long_swipe_set 144 | ) 145 | self.setting2.add_suffix ( 146 | self.sw_long_swipe 147 | ) 148 | self.listbox.append ( 149 | self.setting2 150 | ) 151 | 152 | self.setting3 = Adw.ActionRow ( 153 | title = 'Scroll with mouse wheel' 154 | ) 155 | self.sw_scroll_wheel = Gtk.Switch ( 156 | valign = Gtk.Align.CENTER 157 | ) 158 | self.sw_scroll_wheel.set_active (True) 159 | self.sw_scroll_wheel.connect ( 160 | 'notify::active', 161 | self.on_scroll_wheel_set 162 | ) 163 | self.setting3.add_suffix ( 164 | self.sw_scroll_wheel 165 | ) 166 | self.listbox.append ( 167 | self.setting3 168 | ) 169 | for x in range(4): 170 | self.carousel.append ( 171 | Adw.StatusPage ( 172 | title = f'Page {x}', 173 | hexpand = True, 174 | vexpand = True, 175 | ) 176 | ) 177 | 178 | self.page4 = Gtk.Box ( 179 | orientation = Gtk.Orientation.VERTICAL, 180 | hexpand = True, 181 | vexpand = True, 182 | halign = Gtk.Align.CENTER, 183 | valign = Gtk.Align.CENTER 184 | ) 185 | self.carousel.append ( 186 | self.page4 187 | ) 188 | 189 | self.page4_status = Adw.StatusPage ( 190 | title = 'Page 4', 191 | ) 192 | self.page4.append ( 193 | self.page4_status 194 | ) 195 | 196 | self.btn_go_first_page = Gtk.Button ( 197 | label = 'Return to the first page' 198 | ) 199 | self.btn_go_first_page.get_style_context ().add_class ( 200 | 'pill' 201 | ) 202 | self.btn_go_first_page.connect ( 203 | 'clicked', 204 | self.go_first_page 205 | ) 206 | self.btn_go_first_page.get_style_context ().add_class ( 207 | 'suggested-action' 208 | ) 209 | self.page4.append ( 210 | self.btn_go_first_page 211 | ) 212 | 213 | 214 | def on_setting1_set (self, widget, event): 215 | if "Dots" in self.setting1.get_selected_item ().get_string (): 216 | self.stk_indicator.set_visible_child (self.carousel_dots) 217 | if "Lines" in self.setting1.get_selected_item ().get_string (): 218 | self.stk_indicator.set_visible_child (self.carousel_lines) 219 | 220 | def on_long_swipe_set (self, widget, event): 221 | if self.sw_long_swipe.get_active (): 222 | self.carousel.set_allow_long_swipes (True) 223 | else: 224 | self.carousel.set_allow_long_swipes (False) 225 | 226 | def on_scroll_wheel_set (self, widget, event): 227 | if self.sw_scroll_wheel.get_active (): 228 | self.carousel.set_allow_scroll_wheel (True) 229 | else: 230 | self.carousel.set_allow_scroll_wheel (False) 231 | 232 | def go_first_page (self, widget): 233 | self.carousel.scroll_to (self.page1, True) 234 | 235 | class MyApp (Adw.Application): 236 | def __init__ (self, **kwargs): 237 | super ().__init__ (**kwargs) 238 | self.connect ( 239 | 'activate', 240 | self.on_activate 241 | ) 242 | 243 | def on_activate (self, app): 244 | self.win = MainWindow ( 245 | application = app 246 | ) 247 | self.win.present () 248 | 249 | app = MyApp ( 250 | application_id = 'io.github.afacanc38.adw-viewswitcher' 251 | ) 252 | app.run (sys.argv) -------------------------------------------------------------------------------- /libadwaita/resources/2-buttons.css: -------------------------------------------------------------------------------- 1 | .green { 2 | background: #2ec27e; 3 | } 4 | 5 | .yellow { 6 | background: #f5c211; 7 | } 8 | 9 | .purple { 10 | background: #813d9c; 11 | } 12 | 13 | .orange { 14 | background: #e66100; 15 | } -------------------------------------------------------------------------------- /screenshots/handy/1-box-py.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Afacanc38/gtk-examples-python/c09d764dbb1348c440c9ca453b0b4c384ac8ed06/screenshots/handy/1-box-py.png -------------------------------------------------------------------------------- /screenshots/handy/2-headerbar-py.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Afacanc38/gtk-examples-python/c09d764dbb1348c440c9ca453b0b4c384ac8ed06/screenshots/handy/2-headerbar-py.png -------------------------------------------------------------------------------- /screenshots/handy/3-revealer-py.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Afacanc38/gtk-examples-python/c09d764dbb1348c440c9ca453b0b4c384ac8ed06/screenshots/handy/3-revealer-py.png -------------------------------------------------------------------------------- /screenshots/handy/4-stack-py.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Afacanc38/gtk-examples-python/c09d764dbb1348c440c9ca453b0b4c384ac8ed06/screenshots/handy/4-stack-py.png -------------------------------------------------------------------------------- /screenshots/handy/5-style-classes-py.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Afacanc38/gtk-examples-python/c09d764dbb1348c440c9ca453b0b4c384ac8ed06/screenshots/handy/5-style-classes-py.png -------------------------------------------------------------------------------- /screenshots/handy/6-deck-py.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Afacanc38/gtk-examples-python/c09d764dbb1348c440c9ca453b0b4c384ac8ed06/screenshots/handy/6-deck-py.png -------------------------------------------------------------------------------- /screenshots/libadwaita/1-hello-world-py.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Afacanc38/gtk-examples-python/c09d764dbb1348c440c9ca453b0b4c384ac8ed06/screenshots/libadwaita/1-hello-world-py.png -------------------------------------------------------------------------------- /screenshots/libadwaita/2-buttons-py.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Afacanc38/gtk-examples-python/c09d764dbb1348c440c9ca453b0b4c384ac8ed06/screenshots/libadwaita/2-buttons-py.png -------------------------------------------------------------------------------- /screenshots/libadwaita/3-leaflet-py.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Afacanc38/gtk-examples-python/c09d764dbb1348c440c9ca453b0b4c384ac8ed06/screenshots/libadwaita/3-leaflet-py.png -------------------------------------------------------------------------------- /screenshots/libadwaita/4-clamp-py.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Afacanc38/gtk-examples-python/c09d764dbb1348c440c9ca453b0b4c384ac8ed06/screenshots/libadwaita/4-clamp-py.png -------------------------------------------------------------------------------- /screenshots/libadwaita/5-lists-py.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Afacanc38/gtk-examples-python/c09d764dbb1348c440c9ca453b0b4c384ac8ed06/screenshots/libadwaita/5-lists-py.png -------------------------------------------------------------------------------- /screenshots/libadwaita/6-view-switcher-py.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Afacanc38/gtk-examples-python/c09d764dbb1348c440c9ca453b0b4c384ac8ed06/screenshots/libadwaita/6-view-switcher-py.png -------------------------------------------------------------------------------- /screenshots/libadwaita/7-carousel-py.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Afacanc38/gtk-examples-python/c09d764dbb1348c440c9ca453b0b4c384ac8ed06/screenshots/libadwaita/7-carousel-py.png -------------------------------------------------------------------------------- /shell.nix: -------------------------------------------------------------------------------- 1 | { pkgs ? import {} }: 2 | 3 | pkgs.mkShell { 4 | name = "gtk-examples-python"; 5 | 6 | nativeBuildInputs = [ 7 | pkgs.gobject-introspection 8 | ]; 9 | 10 | buildInputs = [ 11 | pkgs.gtk3 12 | pkgs.libhandy 13 | pkgs.libadwaita 14 | pkgs.gst_all_1.gstreamer 15 | (pkgs.python3.withPackages (p: with p; [ 16 | pygobject3 gst-python 17 | ])) 18 | ]; 19 | } 20 | -------------------------------------------------------------------------------- /vanilla-gtk/1-first-step.py: -------------------------------------------------------------------------------- 1 | import gi 2 | 3 | gi.require_version("Gtk", "3.0") 4 | from gi.repository import Gtk 5 | 6 | win = Gtk.Window() 7 | win.connect("destroy", Gtk.main_quit) 8 | win.show_all() 9 | Gtk.main() --------------------------------------------------------------------------------