├── .gitignore ├── LICENSE ├── README.md ├── redesign ├── __init__.py ├── actions_and_settings.py ├── color_map.py ├── config.py ├── css_class.py ├── gui.py ├── icons.py ├── internals.py ├── languages.py ├── menu.py ├── meta.json ├── mode.py ├── redesign.py ├── selector.py ├── stylers.py ├── styles.py └── user_files │ └── icons │ └── arrow.png ├── redesign_progress_bar ├── __init__.py ├── meta.json └── reviewer_progress_bar.py └── screenshots ├── redesign_clip.gif ├── v8-card.png ├── v8-decks.png └── v8.png /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Redesign 2 | A new look for [Anki](https://apps.ankiweb.net/). 3 | 4 | _Created by Developer Nick._ 5 | 6 | 7 |
8 | 9 | 10 | 11 | ![](screenshots/v8.png) 12 | 13 |
14 | 15 | ### How to contribute 16 | 17 | Feel free to ask questions in the "Issues" tab or submit Pull requests if you have improvements or bug fixes! 18 | 19 |
20 | 21 | ### License 22 | 23 | *Copyright © 2020 [Developer Nick](https://twitter.com/nickdvlpr)* 24 | 25 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY. 26 | 27 |
28 | 29 | ### Credits 30 | 31 | Special thanks to the author of [Night Mode](https://ankiweb.net/shared/info/1496166067) and to those who supported its development on Patreon and elsewhere, especially [Basiskarten Jura](https://www.basiskarten.de/). 32 | 33 | Redesign is released under the GNU AGPLv3 license, extended by a number of additional terms. For more information please see the [LICENSE](https://github.com/nickdvlpr/Redesign/blob/master/LICENSE) file that accompanied this program. 34 | -------------------------------------------------------------------------------- /redesign/__init__.py: -------------------------------------------------------------------------------- 1 | from .redesign import Redesign 2 | from aqt import mw 3 | from anki.hooks import addHook 4 | from aqt.deckbrowser import DeckBrowser 5 | 6 | #addons should selectively load before or after a delay of 666 7 | NM_RESERVED_DELAY = 100 8 | 9 | redesign = None 10 | 11 | def delayedLoader(): 12 | """ 13 | Delays loading of NM to avoid addon conflicts. 14 | """ 15 | global redesign 16 | from .redesign import Redesign 17 | redesign = Redesign() 18 | redesign.load() 19 | 20 | def onProfileLoaded(): 21 | if not redesign: 22 | mw.progress.timer( 23 | NM_RESERVED_DELAY, delayedLoader, False 24 | ) 25 | else: 26 | redesign.load() 27 | 28 | addHook('profileLoaded', onProfileLoaded) 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | customFont = "default"; # Set your desired font here. 37 | # Format is "Font Name With Spaces" (i.e. customFont="Times New Roman";) 38 | # Note: If you want to change this, you need to do so in three files: _init_.py, styles.py, and stylers.py 39 | 40 | 41 | 42 | 43 | ############################# 44 | # WHAT THIS FILE DOES 45 | 46 | # This code example helped me figure out centering one item with text left-justified to it by using a grid layout: 47 | # https://www.w3schools.com/css/css_grid.asp 48 | # The following code uses a 3x3 grid where the grid items are numbered 1, 2, 3 horizontally, next row 4, 5, 6 etc. and all of them are empty except for the middle ones. This way the entire grid takes up the whole screen, thereby centering the middle column, while also allowing the title text in grid-item 2 to be left-aligned. 49 | # This also styles the line of text on Main screen (Decks) at the bottom that says Studied x cards in x minutes 50 | # customFont is a variable found in styles.py and stylers.py 51 | ############################# 52 | 53 | DeckBrowser._body = """ 54 | 55 | 56 | 59 | 60 | 61 | 62 | 63 | 75 | 76 | 77 | 78 | 79 |
80 |
81 |

Anki

82 |
83 |
84 |
85 | 86 | %(tree)s 87 |
88 |
89 |
90 |
91 |
92 |
93 | %(stats)s 94 | %(countwarn)s
95 |
96 |
97 | 98 | 99 | 100 | 101 | """ 102 | -------------------------------------------------------------------------------- /redesign/actions_and_settings.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime 2 | 3 | from PyQt5.QtCore import QTimer 4 | from PyQt5.QtGui import QColor 5 | from PyQt5.QtWidgets import QColorDialog 6 | 7 | from .internals import Setting, MenuAction, alert 8 | from .color_map import ColorMapWindow 9 | from .mode import ModeWindow 10 | from .selector import StylersSelectorWindow 11 | 12 | 13 | class UserColorMap(Setting, MenuAction): 14 | value = {'#000000': 'white'} 15 | window = None 16 | label = 'Customize colors on cards' 17 | 18 | def action(self): 19 | from aqt import mw as main_window 20 | if not self.window: 21 | # self.value is mutable, any modifications done by ColorMapWindow 22 | # will be done on the value of this singleton class object 23 | self.window = ColorMapWindow( 24 | main_window, 25 | self.value, 26 | on_update=self.on_colors_changed 27 | ) 28 | self.window.show() 29 | 30 | def on_colors_changed(self): 31 | self.app.refresh() 32 | 33 | 34 | 35 | 36 | class InvertImage(Setting, MenuAction): 37 | """Toggles image inversion. 38 | 39 | To learn how images are inverted check also append_to_styles(). 40 | """ 41 | 42 | # setting 43 | value = False 44 | 45 | # menu action 46 | label = '&Invert images' 47 | checkable = True 48 | 49 | def action(self): 50 | self.value = not self.value 51 | self.app.refresh() 52 | 53 | 54 | 55 | 56 | class InvertLatex(Setting, MenuAction): 57 | """Toggles latex inversion. 58 | 59 | Latex formulas are nothing more than images with class "latex". 60 | To learn how formulas are inverted check also append_to_styles(). 61 | """ 62 | value = False 63 | label = 'Invert &latex' 64 | checkable = True 65 | 66 | def action(self): 67 | self.value = not self.value 68 | self.app.refresh() 69 | 70 | 71 | 72 | 73 | class TransparentLatex(Setting, MenuAction): 74 | """Toggles transparent latex generation. 75 | 76 | See make_latex_transparent() for details. 77 | """ 78 | value = False 79 | label = 'Force transparent latex' 80 | checkable = True 81 | 82 | def action(self): 83 | self.value = not self.value 84 | if self.value: 85 | self.make_latex_transparent() 86 | 87 | def make_latex_transparent(self): 88 | """Overwrite latex generation commands to use transparent images. 89 | 90 | Already generated latex images won't be affected; 91 | delete those manually from your media folder in order 92 | to regenerate images in transparent version. 93 | """ 94 | 95 | commands = self.get_commands() 96 | 97 | for command in commands: 98 | command[1] = [ 99 | "dvipng", 100 | "-D", "200", 101 | "-T", "tight", 102 | "-bg", "Transparent", 103 | "-z", "9", # use maximal PNG compression 104 | "tmp.dvi", 105 | "-o", "tmp.png" 106 | ] 107 | 108 | @staticmethod 109 | def get_commands(): 110 | from anki.latex import pngCommands 111 | from anki.latex import svgCommands 112 | commands = [] 113 | commands.extend([pngCommands, svgCommands]) 114 | return commands 115 | 116 | def on_load(self): 117 | if self.value: 118 | self.make_latex_transparent() 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | # COLORS 128 | # 3 Sections: 129 | # Section 1 is default colors with the names of the colors used throughout the addon (color_t, color_b, etc.). 130 | # Section 2 is light mode colors. "LightMode" can be selected in View menu by user to switch to these colors. 131 | # Section 3 is dark mode colors. "DarkMode" can be selected in View menu by user to switch to these colors. 132 | class ColorAction(Setting, MenuAction): 133 | def action(self): 134 | qt_color_old = QColor(self.value) 135 | qt_color = QColorDialog.getColor(qt_color_old) 136 | if qt_color.isValid(): 137 | self.value = qt_color.name() 138 | self.app.refresh() 139 | 140 | class TextColor(ColorAction): 141 | """ 142 | Open color picker and set chosen color to text (in content) 143 | """ 144 | name = 'color_t' 145 | value = '#000000' 146 | label = 'Set &text color' 147 | 148 | class BackgroundColor(ColorAction): 149 | """ 150 | Open color picker and set chosen color to background (of main window content) 151 | """ 152 | name = 'color_b' 153 | value = '#fafafa' 154 | label = 'Set &background color' 155 | 156 | class CardColor(ColorAction): 157 | """ 158 | Open color picker and set chosen color to background (of content) 159 | """ 160 | name = 'color_c' 161 | value = '#ffffff' 162 | label = 'Set &card color' 163 | 164 | class PrimaryColor(ColorAction): 165 | """ 166 | Open color picker and set chosen color to primary color (of buttons and more) 167 | """ 168 | name = 'color_p' 169 | value = '#2196f3' 170 | label = 'Set &primary color' 171 | 172 | class AuxiliaryBackgroundColor(ColorAction): 173 | """ 174 | Open color picker and set chosen color to auxiliary background (of content) 175 | """ 176 | name = 'color_s' 177 | value = '#00ff00' 178 | label = 'Set &auxiliary background color' 179 | 180 | # TODO: include in menu 181 | class ActiveBackgroundColor(ColorAction): 182 | """ 183 | Open color picker and set chosen color to auxiliary background (of content) 184 | """ 185 | name = 'color_a' 186 | value = '#2196f3' 187 | label = 'Set active color' 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | # LIGHT MODE COLORS 197 | class TextColor(ColorAction): 198 | name = 'color_t_light' 199 | value = '#000000' 200 | label = 'Set &text color' 201 | 202 | class BackgroundColor(ColorAction): 203 | name = 'color_b_light' 204 | value = '#fafafa' 205 | label = 'Set &background color' 206 | 207 | class CardColor(ColorAction): 208 | name = 'color_c_light' 209 | value = '#ffffff' 210 | label = 'Set &card color' 211 | 212 | class PrimaryColor(ColorAction): 213 | name = 'color_p_light' 214 | value = '#2196f3' 215 | label = 'Set &primary color' 216 | 217 | class AuxiliaryBackgroundColor(ColorAction): 218 | name = 'color_s_light' 219 | value = '#00ff00' 220 | label = 'Set &auxiliary background color' 221 | 222 | class ActiveBackgroundColor(ColorAction): 223 | name = 'color_a_light' 224 | value = '#2196f3' 225 | label = 'Set active color' 226 | 227 | 228 | class LightColors(MenuAction): 229 | """Reset colors""" 230 | label = '&Light mode' 231 | 232 | def action(self): 233 | self.app.config.color_p = self.app.config.color_p_light 234 | self.app.config.color_b = self.app.config.color_b_light 235 | self.app.config.color_c = self.app.config.color_c_light 236 | self.app.config.color_t = self.app.config.color_t_light 237 | self.app.refresh() 238 | 239 | 240 | 241 | 242 | 243 | # DARK MODE COLORS 244 | class TextColor(ColorAction): 245 | name = 'color_t_dark' 246 | value = 'rgba(255,255,255,0.7)' 247 | label = 'Set &text color' 248 | 249 | class BackgroundColor(ColorAction): 250 | name = 'color_b_dark' 251 | value = '#312e42' 252 | label = 'Set &background color' 253 | 254 | class CardColor(ColorAction): 255 | name = 'color_c_dark' 256 | value = '#44405a' 257 | label = 'Set &card color' 258 | 259 | class PrimaryColor(ColorAction): 260 | name = 'color_p_dark' 261 | value = '#00b79f' # Blue: #2196f3, Red: #ef5350, Teal: #00b79f 262 | label = 'Set &primary color' 263 | 264 | class AuxiliaryBackgroundColor(ColorAction): 265 | name = 'color_s_dark' 266 | value = '#00ffff' 267 | label = 'Set &auxiliary background color' 268 | 269 | class ActiveBackgroundColor(ColorAction): 270 | name = 'color_a_dark' 271 | value = '#2196f3' 272 | label = 'Set active color' 273 | 274 | class DarkColors(MenuAction): 275 | label = '&Dark mode' 276 | 277 | def action(self): 278 | self.app.config.color_p = self.app.config.color_p_dark 279 | self.app.config.color_b = self.app.config.color_b_dark 280 | self.app.config.color_c = self.app.config.color_c_dark 281 | self.app.config.color_t = self.app.config.color_t_dark 282 | self.app.refresh() 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | class About(MenuAction): 292 | """Show "about" window""" 293 | label = '&About...' 294 | 295 | def action(self): 296 | self.app.about() 297 | 298 | 299 | 300 | 301 | class EnableInDialogs(Setting, MenuAction): 302 | """Switch for night mode in dialogs""" 303 | value = True 304 | label = 'Enable in &dialogs' 305 | checkable = True 306 | 307 | def action(self): 308 | self.value = not self.value 309 | 310 | 311 | 312 | class StyleScrollBars(Setting, MenuAction): 313 | value = True 314 | label = 'Enable new scrollbars' 315 | checkable = True 316 | 317 | def action(self): 318 | self.value = not self.value 319 | self.app.refresh() 320 | 321 | 322 | 323 | 324 | class ModeSettings(Setting, MenuAction): 325 | value = { 326 | 'mode': 'manual', 327 | 'start_at': '21:30', 328 | 'end_at': '07:30' 329 | } 330 | window = None 331 | label = 'Start automatically' 332 | checkable = True 333 | 334 | @property 335 | def is_checked(self): 336 | return self.mode == 'auto' 337 | 338 | @property 339 | def mode(self): 340 | return self.value['mode'] 341 | 342 | def action(self): 343 | from aqt import mw as main_window 344 | 345 | if not self.window: 346 | # self.value is mutable, any modifications done by ColorMapWindow 347 | # will be done on the value of this singleton class object 348 | self.window = ModeWindow( 349 | main_window, 350 | self.value, 351 | on_update=self.update 352 | ) 353 | self.window.show() 354 | self.app.update_menu() 355 | 356 | def update(self): 357 | self.app.refresh() 358 | 359 | @property 360 | def is_active(self): 361 | current_time = datetime.now().time() 362 | start = self.time('start_at') 363 | end = self.time('end_at') 364 | if end > start: 365 | return start <= current_time <= end 366 | else: 367 | return start <= current_time or current_time <= end 368 | 369 | def time(self, which): 370 | return datetime.strptime(self.value[which], '%H:%M').time() 371 | 372 | 373 | 374 | 375 | class EnableNightMode(Setting, MenuAction): 376 | """Switch night mode""" 377 | value = False 378 | label = '&Enable redesign' 379 | shortcut = 'Ctrl+n' 380 | checkable = True 381 | 382 | require = { 383 | ModeSettings, 384 | # 'StateSettings' (circular dependency) 385 | } 386 | 387 | def action(self): 388 | self.value = not self.value 389 | 390 | if self.mode_settings.mode != 'manual': 391 | alert( 392 | 'Automatic Redesign has been disabled. ' 393 | '(You pressed "ctrl+n" or switched a toggle in the menu). ' 394 | 'Now you can toggle Night Mode manually ' 395 | 'or re-enable the Automatic Night Mode in the menu. ' 396 | ) 397 | self.mode_settings.value['mode'] = 'manual' 398 | 399 | success = self.app.refresh() 400 | 401 | if not success: 402 | self.value = not self.value 403 | 404 | self.app.config.state_on.update_state() 405 | 406 | 407 | 408 | 409 | class StateSetting(Setting): 410 | """Stores the last state of application. 411 | 412 | The state after start-up is determined programmatically; 413 | the value set during configuration loading will be ignored. 414 | """ 415 | name = 'state_on' 416 | state = None 417 | 418 | require = { 419 | ModeSettings, 420 | EnableNightMode 421 | } 422 | 423 | @property 424 | def value(self): 425 | if self.mode_settings.mode == 'manual': 426 | return self.enable_night_mode.value 427 | else: 428 | return self.mode_settings.is_active 429 | 430 | @value.setter 431 | def value(self, value): 432 | pass 433 | 434 | def __init__(self, *args, **kwargs): 435 | super().__init__(*args, **kwargs) 436 | # check the state every 60 seconds 437 | # (maybe a bit suboptimal, but the most reliable) 438 | from aqt import mw as main_window 439 | self.timer = QTimer(main_window) 440 | self.timer.setInterval(60 * 100) # 1000 milliseconds 441 | self.timer.timeout.connect(self.maybe_enable_maybe_disable) 442 | 443 | def on_load(self): 444 | if self.value: 445 | self.app.on() 446 | 447 | self.update_state() 448 | self.timer.start() 449 | 450 | def on_save(self): 451 | self.timer.stop() 452 | 453 | def maybe_enable_maybe_disable(self): 454 | if self.value != self.state: 455 | self.app.refresh() 456 | self.update_state() 457 | 458 | def update_state(self): 459 | self.state = self.value 460 | 461 | 462 | 463 | 464 | class DisabledStylers(Setting, MenuAction): 465 | 466 | value = set() 467 | window = None 468 | label = 'Choose what to style' 469 | 470 | def action(self): 471 | from aqt import mw as main_window 472 | 473 | if not self.window: 474 | self.window = StylersSelectorWindow( 475 | main_window, 476 | self.value, 477 | self.app.styles.stylers, 478 | on_update=self.update 479 | ) 480 | self.window.show() 481 | 482 | def update(self): 483 | self.app.refresh(reload=True) 484 | -------------------------------------------------------------------------------- /redesign/color_map.py: -------------------------------------------------------------------------------- 1 | from PyQt5.QtCore import Qt, pyqtSlot as slot 2 | from PyQt5.QtGui import QColor 3 | from PyQt5.QtWidgets import QWidget, QLabel, QGridLayout, QPushButton, QColorDialog, QHBoxLayout, QVBoxLayout 4 | 5 | from .internals import alert 6 | from .gui import create_button, remove_layout, AddonDialog 7 | from .languages import _ 8 | 9 | 10 | class ColorSwatch(QPushButton): 11 | 12 | def __init__(self, parent, color=None, on_color_change=None, name='Color', verify_colors=False): 13 | """ 14 | 15 | Args: 16 | parent: a parent Qt instance 17 | color: the color name or hexadecimal code (in form of a string) 18 | on_color_change: a function or method taking old color and a new one 19 | verify_colors: should the parent be asked if the color is acceptable? 20 | to verify a color parent.is_acceptable(color) will be invoked 21 | """ 22 | QPushButton.__init__(self, color, parent) 23 | self.verify_colors = verify_colors 24 | self.parent = parent 25 | self.color = color 26 | self.name = name 27 | self.callback = on_color_change 28 | 29 | if color: 30 | self.set_color(color) 31 | else: 32 | self.setText(_('(Not specified)')) 33 | 34 | self.clicked.connect(self.pick_color) 35 | 36 | def set_color(self, color): 37 | self.color = color 38 | self.setText(color) 39 | self.setStyleSheet(f'background-color: {self.color}; color: {self.text_color}') 40 | 41 | @property 42 | def text_color(self): 43 | return 'black' if self.qt_color.lightness() > 127 else 'white' 44 | 45 | @property 46 | def qt_color(self): 47 | return QColor(self.color) 48 | 49 | @slot() 50 | def pick_color(self, qt_color=None): 51 | if not qt_color: 52 | qt_color = self.qt_color 53 | 54 | old_color = self.color 55 | qt_color = QColorDialog.getColor( 56 | qt_color, 57 | parent=self, 58 | title=_('Select %s') % _(self.name) 59 | ) 60 | 61 | if qt_color.isValid(): 62 | color = qt_color.name() 63 | if self.verify_colors and not self.parent.is_acceptable(color): 64 | alert(_('This color (%s) is already mapped. Please select a different one.') % color) 65 | return self.pick_color(qt_color=qt_color) 66 | 67 | self.set_color(color) 68 | self.callback(old_color, self.color) 69 | 70 | 71 | class ColorMapping(QWidget): 72 | 73 | def __init__(self, parent, normal_color, night_color): 74 | """ 75 | 76 | Args: 77 | parent: ColorMapWindow instance 78 | normal_color: name or code of code to use in normal mode 79 | night_color: name or code of code to use in night mode 80 | """ 81 | QWidget.__init__(self, parent) 82 | self.parent = parent 83 | self.normal = ColorSwatch(self, normal_color, self.update_normal, 'Normal Mode Color', verify_colors=True) 84 | self.night = ColorSwatch(self, night_color, self.update_night, 'Night Mode Color') 85 | self.grid = QGridLayout() 86 | self.fill_layout() 87 | self.setLayout(self.grid) 88 | 89 | def fill_layout(self): 90 | remove = create_button('Remove', self.remove) 91 | grid = self.grid 92 | grid.addWidget(self.normal, 0, 1, 1, 3) 93 | arrow = QLabel('→') 94 | arrow.setAlignment(Qt.AlignCenter) 95 | grid.addWidget(arrow, 0, 4) 96 | grid.addWidget(self.night, 0, 5, 1, 3) 97 | grid.addWidget(remove, 0, 8) 98 | 99 | @slot() 100 | def remove(self): 101 | self.parent.update(self.normal.color, None, None) 102 | remove_layout(self.grid) 103 | self.parent.mappings.removeWidget(self) 104 | self.deleteLater() 105 | 106 | def update_normal(self, old, new): 107 | night = self.night.color 108 | self.parent.update(old, new, night) 109 | 110 | def update_night(self, old, new): 111 | normal = self.normal.color 112 | self.parent.update(normal, normal, new) 113 | 114 | def is_acceptable(self, color): 115 | return self.parent.is_acceptable(color) 116 | 117 | 118 | class ColorMapWindow(AddonDialog): 119 | 120 | def __init__(self, parent, color_map, title='Customize color swapping', on_update=None): 121 | super().__init__(self, parent, Qt.Window) 122 | self.on_update = on_update 123 | self.color_map = color_map 124 | 125 | self.init_ui(title) 126 | 127 | def init_ui(self, title): 128 | self.setWindowTitle(_(title)) 129 | 130 | btn_add_mapping = create_button('+ Add color mapping', self.on_add) 131 | btn_close = create_button('Close', self.close) 132 | 133 | buttons = QHBoxLayout() 134 | 135 | buttons.addWidget(btn_close) 136 | buttons.addWidget(btn_add_mapping) 137 | buttons.setAlignment(Qt.AlignBottom) 138 | 139 | body = QVBoxLayout() 140 | body.setAlignment(Qt.AlignTop) 141 | 142 | header = QLabel(_( 143 | 'Specify how particular colors on your cards ' 144 | 'should be swapped when the redesign is on.' 145 | )) 146 | header.setAlignment(Qt.AlignCenter) 147 | 148 | mappings = QVBoxLayout() 149 | mappings.setAlignment(Qt.AlignTop) 150 | 151 | for normal_color, night_color in self.color_map.items(): 152 | mapping = ColorMapping(self, normal_color, night_color) 153 | mappings.addWidget(mapping) 154 | 155 | self.mappings = mappings 156 | 157 | body.addWidget(header) 158 | body.addLayout(mappings) 159 | body.addStretch(1) 160 | body.addLayout(buttons) 161 | self.setLayout(body) 162 | 163 | self.setGeometry(300, 300, 350, 300) 164 | self.show() 165 | 166 | @slot() 167 | def on_add(self): 168 | mapping = ColorMapping(self, None, None) 169 | self.mappings.addWidget(mapping) 170 | mapping.normal.pick_color() 171 | mapping.night.pick_color() 172 | 173 | def is_acceptable(self, color): 174 | return color not in self.color_map 175 | 176 | def update(self, old_key, new_key, new_value): 177 | if old_key: 178 | del self.color_map[old_key] 179 | if new_key: 180 | self.color_map[new_key] = new_value 181 | if self.on_update: 182 | self.on_update() 183 | -------------------------------------------------------------------------------- /redesign/config.py: -------------------------------------------------------------------------------- 1 | from aqt import mw 2 | from .internals import Setting 3 | 4 | 5 | class Config: 6 | 7 | def __init__(self, app, prefix=''): 8 | self.app = app 9 | self.prefix = prefix 10 | self.settings = {} 11 | 12 | # has to be separately from __init__ to avoid circular reference 13 | def init_settings(self): 14 | for setting_class in Setting.members: 15 | setting = setting_class(self.app) 16 | self.settings[setting.name] = setting 17 | 18 | def __getattr__(self, attr): 19 | return self.settings[attr] 20 | 21 | def stored_name(self, name): 22 | return self.prefix + name 23 | 24 | def load(self): 25 | for name, setting in self.settings.items(): 26 | key = self.stored_name(name) 27 | value = mw.pm.profile.get(key, setting.default_value) 28 | 29 | setting.value = value 30 | 31 | for setting in self.settings.values(): 32 | setting.on_load() 33 | 34 | def save(self): 35 | """ 36 | Saves configurable variables into profile, so they can 37 | be used to restore previous state after Anki restart. 38 | """ 39 | for name, setting in self.settings.items(): 40 | key = self.stored_name(name) 41 | mw.pm.profile[key] = setting.value 42 | 43 | for setting in self.settings.values(): 44 | setting.on_save() 45 | 46 | 47 | class ConfigValueGetter: 48 | 49 | def __init__(self, config): 50 | self.config = config 51 | 52 | def __getattr__(self, attr): 53 | setting = getattr(self.config, attr) 54 | return setting.value 55 | -------------------------------------------------------------------------------- /redesign/css_class.py: -------------------------------------------------------------------------------- 1 | def inject_css_class(state: bool, html: str): 2 | if state: 3 | javascript = """ 4 | function add_anki_redesign_class(){ 5 | current_classes = document.body.className; 6 | if(current_classes.indexOf("anki_redesign") == -1) 7 | { 8 | document.body.className += " anki_redesign"; 9 | } 10 | } 11 | // explanation of setTimeout use: 12 | // callback defined in _showQuestion of reviewer.js would otherwise overwrite 13 | // the newly set body class; in order to prevent that the function execution 14 | // is being placed on the end of execution queue (hence time = 0) 15 | setTimeout(add_anki_redesign_class, 0) 16 | """ 17 | else: 18 | javascript = """ 19 | function remove_anki_redesign_class(){ 20 | current_classes = document.body.className; 21 | if(current_classes.indexOf("anki_redesign") != -1) 22 | { 23 | document.body.className = current_classes.replace("anki_redesign",""); 24 | } 25 | } 26 | setTimeout(remove_anki_redesign_class, 0) 27 | """ 28 | # script on the beginning of the HTML so it will always be 29 | # before any user-defined, potentially malformed HTML 30 | html = f"" + html 31 | return html 32 | -------------------------------------------------------------------------------- /redesign/gui.py: -------------------------------------------------------------------------------- 1 | from PyQt5.QtWidgets import QPushButton, QDialog 2 | 3 | from .languages import _ 4 | 5 | 6 | class AddonDialog(QDialog): 7 | def __init__(self, *args, **kwargs): 8 | QDialog.__init__(*args, **kwargs) 9 | 10 | 11 | def create_button(name, callback=None): 12 | button = QPushButton(_(name)) 13 | if callback: 14 | button.clicked.connect(callback) 15 | return button 16 | 17 | 18 | def iterate_widgets(layout): 19 | for i in reversed(range(layout.count())): 20 | yield layout.itemAt(i).widget() 21 | 22 | 23 | def remove_layout(layout): 24 | for widget in iterate_widgets(layout): 25 | layout.removeWidget(widget) 26 | widget.deleteLater() 27 | 28 | -------------------------------------------------------------------------------- /redesign/icons.py: -------------------------------------------------------------------------------- 1 | from os import makedirs 2 | from os.path import isfile, dirname, abspath, join 3 | from PyQt5.QtGui import QIcon, QPixmap 4 | from PyQt5.QtWidgets import QStyle 5 | 6 | 7 | def inverted_icon(icon, width=32, height=32, as_image=False): 8 | pixmap = icon.pixmap(width, height) 9 | image = pixmap.toImage() 10 | # image.invertPixels() 11 | if as_image: 12 | return image 13 | new_icon = QIcon(QPixmap.fromImage(image)) 14 | return new_icon 15 | 16 | 17 | class Icons: 18 | 19 | paths = {} 20 | 21 | def __init__(self, mw): 22 | 23 | add_on_path = dirname(abspath(__file__)) 24 | add_on_resources = join(add_on_path, 'user_files') 25 | icons_path = join(add_on_resources, 'icons') 26 | makedirs(icons_path, exist_ok=True) 27 | 28 | icon_path = join(icons_path, 'arrow.png') 29 | 30 | if not isfile(icon_path): 31 | down_arrow_icon = mw.style().standardIcon(QStyle.SP_ArrowDown) 32 | image = inverted_icon(down_arrow_icon, width=16, height=16, as_image=True) 33 | image.save(icon_path) 34 | 35 | arrow_path = icon_path.replace('\\', '/') 36 | 37 | where_to_look_for_arrow_icon = [ 38 | '/usr/share/icons/Adwaita/scalable/actions/pan-down-symbolic.svg', 39 | '/usr/share/icons/gnome/scalable/actions/go-down-symbolic.svg', 40 | '/usr/share/icons/ubuntu-mobile/actions/scalable/dropdown-menu.svg', 41 | '/usr/share/icons/Humanity/actions/16/down.svg', 42 | '/usr/share/icons/Humanity/actions/16/go-down.svg', 43 | '/usr/share/icons/Humanity/actions/16/stock_down.svg', 44 | '/usr/share/icons/nuvola/16x16/actions/arrow-down.png', 45 | '/usr/share/icons/default.kde4/16x16/actions/arrow-down.png' 46 | ] 47 | 48 | for path in where_to_look_for_arrow_icon: 49 | if isfile(path): 50 | arrow_path = path 51 | break 52 | 53 | self.paths['arrow'] = arrow_path 54 | 55 | @property 56 | def arrow(self): 57 | return self.paths['arrow'] 58 | -------------------------------------------------------------------------------- /redesign/internals.py: -------------------------------------------------------------------------------- 1 | import re 2 | from PyQt5 import QtCore 3 | from abc import abstractmethod, ABCMeta 4 | from inspect import isclass 5 | from types import MethodType 6 | 7 | from anki.hooks import wrap 8 | from anki.lang import _ 9 | from aqt.utils import showWarning 10 | 11 | 12 | try: 13 | from_utf8 = QtCore.QString.fromUtf8 14 | except AttributeError: 15 | from_utf8 = lambda s: s 16 | 17 | 18 | def alert(info): 19 | showWarning(_(info)) 20 | 21 | 22 | class PropertyDescriptor: 23 | def __init__(self, value=None): 24 | self.value = value 25 | 26 | def __get__(self, obj, obj_type): 27 | return self.value(obj) 28 | 29 | def __set__(self, obj, value): 30 | self.value = value 31 | 32 | 33 | class css(PropertyDescriptor): 34 | is_css = True 35 | 36 | 37 | def abstract_property(func): 38 | return property(abstractmethod(func)) 39 | 40 | 41 | def snake_case(camel_case): 42 | return re.sub('(?!^)([A-Z]+)', r'_\1', camel_case).lower() 43 | 44 | 45 | class AbstractRegisteringType(ABCMeta): 46 | 47 | def __init__(cls, name, bases, attributes): 48 | super().__init__(name, bases, attributes) 49 | 50 | if not hasattr(cls, 'members'): 51 | cls.members = set() 52 | 53 | cls.members.add(cls) 54 | cls.members -= set(bases) 55 | 56 | 57 | class SnakeNameMixin: 58 | 59 | @property 60 | def name(self): 61 | """Nice looking internal identifier.""" 62 | 63 | return snake_case( 64 | self.__class__.__name__ 65 | if hasattr(self, '__class__') 66 | else self.__name__ 67 | ) 68 | 69 | 70 | class MenuAction(SnakeNameMixin, metaclass=AbstractRegisteringType): 71 | 72 | def __init__(self, app): 73 | self.app = app 74 | 75 | @abstract_property 76 | def label(self): 77 | """Text to be shown on menu entry. 78 | 79 | Use ampersand ('&') to set that the following 80 | character as a menu shortcut for this action. 81 | 82 | Use double ampersand ('&&') to display '&'. 83 | """ 84 | pass 85 | 86 | @property 87 | def checkable(self): 88 | """Add 'checked' sign to menu item when active""" 89 | return False 90 | 91 | @property 92 | def shortcut(self): 93 | """Global shortcut for this menu action. 94 | 95 | The shortcut should be given as a string, like: 96 | shortcut = 'Ctrl+n' 97 | """ 98 | return None 99 | 100 | @abstractmethod 101 | def action(self): 102 | """Callback for menu entry clicking/selection""" 103 | pass 104 | 105 | @property 106 | def is_checked(self): 107 | """Should the menu item be checked (assuming that checkable is True)""" 108 | return bool(self.value) 109 | 110 | 111 | def singleton_creator(old_creator): 112 | def one_to_rule_them_all(cls, *args, **kwargs): 113 | if not cls.instance: 114 | cls.instance = old_creator(cls) 115 | return cls.instance 116 | return one_to_rule_them_all 117 | 118 | 119 | class SingletonMetaclass(AbstractRegisteringType): 120 | 121 | def __init__(cls, name, bases, attributes): 122 | super().__init__(name, bases, attributes) 123 | 124 | # singleton 125 | cls.instance = None 126 | old_creator = cls.__new__ 127 | cls.__new__ = singleton_creator(old_creator) 128 | 129 | 130 | class RequiringMixin: 131 | 132 | require = set() 133 | dependencies = {} 134 | 135 | def __init__(self, app): 136 | for requirement in self.require: 137 | instance = requirement(app) 138 | key = instance.name 139 | self.dependencies[key] = instance 140 | 141 | def __getattr__(self, attr): 142 | if attr in self.dependencies: 143 | return self.dependencies[attr] 144 | 145 | 146 | class Setting(RequiringMixin, SnakeNameMixin, metaclass=SingletonMetaclass): 147 | 148 | def __init__(self, app): 149 | RequiringMixin.__init__(self, app) 150 | self.default_value = self.value 151 | self.app = app 152 | 153 | @abstract_property 154 | def value(self): 155 | """Default value of a setting""" 156 | pass 157 | 158 | def on_load(self): 159 | """Callback called after loading of initial value""" 160 | pass 161 | 162 | def on_save(self): 163 | pass 164 | 165 | def reset(self): 166 | if hasattr(self, 'default_value'): 167 | self.value = self.default_value 168 | 169 | 170 | def decorate_or_call(operator): 171 | def outer_decorator(method_or_value): 172 | if callable(method_or_value): 173 | method = method_or_value 174 | 175 | def decorated(*args, **kwargs): 176 | return operator(method(*args, **kwargs)) 177 | return decorated 178 | else: 179 | return operator(method_or_value) 180 | return outer_decorator 181 | 182 | 183 | @decorate_or_call 184 | def style_tag(some_css): 185 | return '' 186 | 187 | 188 | @decorate_or_call 189 | def percent_escaped(text): 190 | return text.replace('%', '%%') 191 | 192 | 193 | class StylerMetaclass(AbstractRegisteringType): 194 | """ 195 | Makes classes: singletons, work with: 196 | wraps, 197 | appends_in_night_mode, 198 | replaces_in_night_mode 199 | decorators 200 | """ 201 | 202 | def __init__(cls, name, bases, attributes): 203 | super().__init__(name, bases, attributes) 204 | 205 | # singleton 206 | cls.instance = None 207 | old_creator = cls.__new__ 208 | cls.__new__ = singleton_creator(old_creator) 209 | 210 | # additions and replacements 211 | cls.additions = {} 212 | cls.replacements = {} 213 | 214 | target = attributes.get('target', None) 215 | 216 | def callback_maker(wrapper): 217 | def raw_new(*args, **kwargs): 218 | return wrapper(cls.instance, *args, **kwargs) 219 | return raw_new 220 | 221 | for key, attr in attributes.items(): 222 | 223 | if key == 'init': 224 | key = '__init__' 225 | if hasattr(attr, 'wraps'): 226 | 227 | if not target: 228 | raise Exception(f'Asked to wrap "{key}" but target of {name} not defined') 229 | 230 | original = getattr(target, key) 231 | 232 | if type(original) is MethodType: 233 | original = original.__func__ 234 | 235 | new = wrap(original, callback_maker(attr), attr.position) 236 | 237 | # for classes, just add the new function, it will be bound later, 238 | # but instances need some more work: we need to bind! 239 | if not isclass(target): 240 | new = MethodType(new, target) 241 | 242 | cls.replacements[key] = new 243 | 244 | if hasattr(attr, 'appends_in_night_mode'): 245 | if not target: 246 | raise Exception(f'Asked to replace "{key}" but target of {name} not defined') 247 | cls.additions[key] = attr 248 | if hasattr(attr, 'replaces_in_night_mode'): 249 | if not target: 250 | raise Exception(f'Asked to replace "{key}" but target of {name} not defined') 251 | cls.replacements[key] = attr 252 | 253 | # TODO: invoke and cache css? 254 | if hasattr(attr, 'is_css'): 255 | pass 256 | 257 | 258 | def wraps(method=None, position='after'): 259 | """Decorator for methods extending Anki QT methods. 260 | 261 | Args: 262 | method: a function method to be wrapped 263 | position: after, before or around 264 | """ 265 | 266 | if not method: 267 | def wraps_inner(func): 268 | return wraps(method=func, position=position) 269 | return wraps_inner 270 | 271 | method.wraps = True 272 | method.position = position 273 | 274 | return method 275 | 276 | 277 | class appends_in_night_mode(PropertyDescriptor): 278 | appends_in_night_mode = True 279 | 280 | 281 | class replaces_in_night_mode(PropertyDescriptor): 282 | replaces_in_night_mode = True 283 | 284 | 285 | def move_args_to_kwargs(original_function, args, kwargs): 286 | args = list(args) 287 | 288 | import inspect 289 | 290 | signature = inspect.signature(original_function) 291 | i = 0 292 | for name, parameter in signature.parameters.items(): 293 | if i >= len(args): 294 | break 295 | if parameter.default is not inspect._empty: 296 | value = args.pop(i) 297 | kwargs[name] = value 298 | else: 299 | i += 1 300 | return args, kwargs 301 | 302 | -------------------------------------------------------------------------------- /redesign/languages.py: -------------------------------------------------------------------------------- 1 | import gettext 2 | from os import path 3 | 4 | from anki.lang import getLang, _ as fallback_translation 5 | 6 | lang = getLang() 7 | this_dir = path.dirname(path.abspath(__file__)) 8 | locale_dir = path.join(this_dir, 'locale') 9 | trans = gettext.translation('Anki-Night-Mode', locale_dir, languages=[lang], fallback=True) 10 | # See: http://www.loc.gov/standards/iso639-2/php/code_list.php for language codes 11 | 12 | 13 | def _(text): 14 | try: 15 | return trans.gettext(text) 16 | except Exception as e: 17 | print(e) 18 | return fallback_translation(text) 19 | -------------------------------------------------------------------------------- /redesign/menu.py: -------------------------------------------------------------------------------- 1 | from PyQt5.QtGui import QKeySequence 2 | from PyQt5.QtWidgets import QAction, QMenu 3 | 4 | from aqt import mw 5 | 6 | from .languages import _ 7 | 8 | 9 | 10 | 11 | def get_or_create_menu(attribute_name, label): 12 | 13 | if not hasattr(mw, attribute_name): 14 | menu = QMenu(_(label), mw) 15 | setattr(mw, attribute_name, menu) 16 | 17 | mw.form.menubar.insertMenu( 18 | mw.form.menuTools.menuAction(), 19 | menu 20 | ) 21 | else: 22 | menu = getattr(mw, attribute_name) 23 | menu.setTitle(_(label)) 24 | 25 | return menu 26 | 27 | 28 | 29 | 30 | class Menu: 31 | 32 | actions = { 33 | # action name => action 34 | } 35 | 36 | connections = { 37 | # action => callback 38 | } 39 | 40 | def __init__(self, app, menu_name, layout, attach_to=None): 41 | self.menu = QMenu(_(menu_name), mw) 42 | 43 | if attach_to: 44 | attach_to.addMenu(self.menu) 45 | 46 | layout = [ 47 | entry(app) if hasattr(entry, 'action') else entry 48 | for entry in layout 49 | ] 50 | 51 | self.raw_actions = { 52 | entry.name: entry 53 | for entry in layout 54 | if hasattr(entry, 'action') 55 | } 56 | 57 | for action in self.raw_actions.values(): 58 | 59 | self.create_action( 60 | action.name, 61 | _(action.label), 62 | action.action, 63 | checkable=action.checkable, 64 | shortcut=action.shortcut 65 | ) 66 | 67 | self.setup_layout(layout) 68 | self.setup_connections() 69 | 70 | def create_action(self, name, text, callback, checkable=False, shortcut=None): 71 | action = QAction(_(text), mw, checkable=checkable) 72 | 73 | if shortcut: 74 | toggle = QKeySequence(shortcut) 75 | action.setShortcut(toggle) 76 | 77 | if name in self.actions: 78 | message = 'Action {0} already exists'.format(name) 79 | raise Exception(message) 80 | 81 | self.actions[name] = action 82 | self.connections[action] = callback 83 | 84 | def set_checked(self, name, value=True): 85 | self.actions[name].setChecked(value) 86 | 87 | def setup_layout(self, layout): 88 | for entry in layout: 89 | if entry == '-': 90 | self.menu.addSeparator() 91 | else: 92 | action = self.actions[entry.name] 93 | self.menu.addAction(action) 94 | 95 | def setup_connections(self): 96 | for menu_entry, connection in self.connections.items(): 97 | self.connect(menu_entry, connection) 98 | 99 | def connect(self, action, callback): 100 | action.triggered.connect(callback) 101 | 102 | def update_checkboxes(self, settings): 103 | for name, setting in settings.items(): 104 | if name in self.actions and self.raw_actions[name].checkable: 105 | self.set_checked(name, setting.is_checked) 106 | -------------------------------------------------------------------------------- /redesign/meta.json: -------------------------------------------------------------------------------- 1 | {"name": "Redesign", "mod": 1580262316, "disabled": false} 2 | -------------------------------------------------------------------------------- /redesign/mode.py: -------------------------------------------------------------------------------- 1 | from PyQt5.QtCore import Qt, pyqtSlot as slot, QTime 2 | from PyQt5.QtWidgets import QWidget, QLabel, QGridLayout, QHBoxLayout, QVBoxLayout, QTimeEdit 3 | 4 | from .gui import create_button, AddonDialog, iterate_widgets 5 | 6 | 7 | 8 | 9 | class TimeEdit(QWidget): 10 | 11 | def __init__(self, parent, initial_time, label, on_update=lambda x: x): 12 | """ 13 | 14 | Args: 15 | parent: ColorMapWindow instance 16 | """ 17 | QWidget.__init__(self, parent) 18 | self.parent = parent 19 | self.on_update = on_update 20 | self.label = QLabel(label) 21 | self.qt_time = QTime.fromString(initial_time) 22 | self.time_edit = QTimeEdit(self.qt_time) 23 | self.time_edit.timeChanged.connect(self.update) 24 | self.grid = QGridLayout() 25 | self.fill_layout() 26 | self.setLayout(self.grid) 27 | 28 | @property 29 | def time(self): 30 | return self.qt_time.toPyTime().strftime('%H:%M') 31 | 32 | def fill_layout(self): 33 | grid = self.grid 34 | grid.addWidget(self.label, 0, 0) 35 | grid.addWidget(self.time_edit, 1, 0) 36 | 37 | @slot() 38 | def update(self): 39 | self.qt_time = self.time_edit.time() 40 | self.on_update(self.time) 41 | 42 | def update_constraint(self, min_time, max_time): 43 | pass 44 | 45 | 46 | 47 | 48 | class ModeWindow(AddonDialog): 49 | 50 | def __init__(self, parent, settings, title='Manage Redesign', on_update=lambda x: x): 51 | super().__init__(self, parent, Qt.Window) 52 | self.on_update = on_update 53 | self.settings = settings 54 | 55 | self.init_ui(title) 56 | 57 | def init_ui(self, title): 58 | self.setWindowTitle(title) 59 | 60 | btn_close = create_button('Close', self.close) 61 | 62 | buttons = QHBoxLayout() 63 | 64 | buttons.addWidget(btn_close) 65 | buttons.setAlignment(Qt.AlignBottom) 66 | 67 | body = QVBoxLayout() 68 | body.setAlignment(Qt.AlignTop) 69 | 70 | header = QLabel( 71 | 'If you choose an automatic (scheduled) mode ' 72 | 'the "ctrl+n" shortcut and menu checkbox for ' 73 | 'quick toggle will switch between the manual ' 74 | 'and automatic mode (when used for the first ' 75 | 'time).' 76 | ) 77 | header.setWordWrap(True) 78 | 79 | mode_switches = QHBoxLayout() 80 | mode_switches.addWidget(QLabel('Mode:')) 81 | self.manual = create_button('Manual', self.on_set_manual) 82 | self.auto = create_button('Automatic', self.on_set_automatic) 83 | mode_switches.addWidget(self.manual) 84 | mode_switches.addWidget(self.auto) 85 | 86 | time_controls = QHBoxLayout() 87 | time_controls.setAlignment(Qt.AlignTop) 88 | 89 | start_at = TimeEdit(self, self.settings['start_at'], 'From', self.start_update) 90 | end_at = TimeEdit(self, self.settings['end_at'], 'To', self.end_update) 91 | time_controls.addWidget(start_at) 92 | time_controls.addWidget(end_at) 93 | 94 | self.time_controls = time_controls 95 | 96 | self.set_mode(self.settings['mode'], False) 97 | 98 | body.addWidget(header) 99 | body.addStretch(1) 100 | body.addLayout(mode_switches) 101 | body.addLayout(time_controls) 102 | body.addStretch(1) 103 | body.addLayout(buttons) 104 | self.setLayout(body) 105 | 106 | self.setGeometry(300, 300, 470, 255) 107 | self.show() 108 | 109 | def start_update(self, time): 110 | self.set_time('start_at', time) 111 | 112 | def end_update(self, time): 113 | self.set_time('end_at', time) 114 | 115 | def set_time(self, which, time): 116 | self.settings[which] = time 117 | self.on_update() 118 | 119 | @slot() 120 | def on_set_manual(self): 121 | self.set_mode('manual') 122 | 123 | @slot() 124 | def on_set_automatic(self): 125 | self.set_mode('auto') 126 | 127 | def switch_buttons(self, auto): 128 | self.auto.setEnabled(not auto) 129 | self.manual.setEnabled(auto) 130 | self.auto.setChecked(auto) 131 | self.manual.setChecked(not auto) 132 | 133 | def set_mode(self, mode, run_callback=True): 134 | auto = mode == 'auto' 135 | self.settings['mode'] = mode 136 | # time controls are needed only in the 'auto' mode 137 | for widget in iterate_widgets(self.time_controls): 138 | widget.setEnabled(auto) 139 | self.switch_buttons(auto) 140 | if run_callback: 141 | self.on_update() 142 | -------------------------------------------------------------------------------- /redesign/redesign.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Copyright: Developer Nick 3 | # License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html 4 | 5 | """ 6 | 7 | 8 | Welcome to a brand new way of using Anki! This add-on redesigns Anki from the ground up and is based on the code from the Night Mode add-on (https://ankiweb.net/shared/info/1496166067). It was helpful in creating this redesign and I am very grateful to its author. 9 | 10 | Redesign adds a "View" option in the menu bar with options for switching it on and off and modifying select colors. After enabling the redesign, it changes the colors, animations, buttons, and main screens inside Anki. 11 | 12 | 13 | 14 | Acknowledgements: 15 | Special thanks to the Night Mode author, Krassowski, and the contributors to that code: 16 | - b50 (initial compatibility with 2.1), 17 | - ankitest (compatibility with 1508882486), 18 | - omega3 (useful bug reports and suggestions) 19 | - colchizin 20 | - JulyMorning 21 | - nathanmalloy 22 | - rathsky 23 | 24 | Patreon Contributors: 25 | (If you wish to have your name or username displayed here, please let me know.) 26 | - Basiskarten Jura (https://www.basiskarten.de/) 27 | - Others who wished to remain anonymous! 28 | 29 | Copyright: Developer Nick (nickdeveloper.feedback@gmail.com) 30 | License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html except when stated otherwise. 31 | """ 32 | 33 | 34 | 35 | 36 | import traceback 37 | 38 | from anki.hooks import addHook, runHook 39 | from aqt import appVersion 40 | from aqt import mw 41 | 42 | from PyQt5.QtWidgets import QMessageBox 43 | 44 | from .actions_and_settings import * 45 | from .internals import alert 46 | from .config import Config, ConfigValueGetter 47 | from .css_class import inject_css_class 48 | from .icons import Icons 49 | from .menu import get_or_create_menu, Menu 50 | from .stylers import Styler 51 | from .styles import Style, MessageBoxStyle 52 | 53 | __addon_name__ = 'Redesign' 54 | __version__ = '1.2' 55 | __anki_version__ = '2.1' 56 | 57 | 58 | 59 | 60 | if not appVersion.startswith(__anki_version__): 61 | print( 62 | ( 63 | 'Unsupported version of Anki. ' 64 | 'Redesign requires %s to work properly. ' 65 | 'Update to Anki 2.1 or higher to use this add-on.' 66 | ) % __anki_version__ 67 | ) 68 | 69 | 70 | 71 | 72 | # Add your color replacement mappings here - old: new, comma separated 73 | 74 | 75 | 76 | 77 | class StylingManager: 78 | def __init__(self, app): 79 | self.styles = Style.members 80 | self.stylers = [ 81 | styler(app) 82 | for styler in Styler.members 83 | ] 84 | self.config = ConfigValueGetter(app.config) 85 | 86 | @property 87 | def active_stylers(self): 88 | return [ 89 | styler 90 | for styler in self.stylers 91 | if styler.name not in self.config.disabled_stylers 92 | ] 93 | 94 | def replace(self): 95 | for styler in self.active_stylers: 96 | styler.replace_attributes() 97 | 98 | def restore(self): 99 | for styler in self.stylers: 100 | styler.restore_attributes() 101 | 102 | 103 | 104 | 105 | class Redesign: 106 | 107 | menu_layout = [ 108 | EnableNightMode, 109 | EnableInDialogs, 110 | StyleScrollBars, 111 | '-', 112 | #PrimaryColor, 113 | BackgroundColor, 114 | CardColor, 115 | TextColor, 116 | LightColors, 117 | DarkColors, 118 | '-', 119 | #InvertImage, 120 | #InvertLatex, 121 | #TransparentLatex, 122 | '-', 123 | #ModeSettings, 124 | #UserColorMap, 125 | #DisabledStylers, 126 | '-', 127 | About 128 | ] 129 | 130 | def __init__(self): 131 | self.profile_loaded = False 132 | self.config = Config(self, prefix='nm_') 133 | self.config.init_settings() 134 | self.icons = Icons(mw) 135 | self.styles = StylingManager(self) 136 | 137 | view_menu = get_or_create_menu('addon_view_menu', '&View') 138 | self.menu = Menu( 139 | self, 140 | '&Redesign', 141 | self.menu_layout, 142 | attach_to=view_menu 143 | ) 144 | 145 | addHook('unloadProfile', self.save) 146 | # Disabled, uses delay in __init__.py 147 | # addHook('profileLoaded', self.load) 148 | addHook('prepareQA', self.night_class_injection) 149 | addHook('loadNote', self.background_bug_workaround) 150 | 151 | def load(self): 152 | """ 153 | Load configuration from profile, set states of checkable menu objects 154 | and turn on redesign if it were enabled on previous session. 155 | """ 156 | self.config.load() 157 | self.profile_loaded = True 158 | 159 | self.refresh() 160 | self.update_menu() 161 | 162 | runHook("night_mode_config_loaded", self.config) 163 | 164 | 165 | def update_menu(self): 166 | self.menu.update_checkboxes(self.config.settings) 167 | 168 | def save(self): 169 | self.config.save() 170 | 171 | def on(self): 172 | """Turn on redesign.""" 173 | self.styles.replace() 174 | runHook("night_mode_state_changed", True) 175 | 176 | def off(self): 177 | """Turn off redesign.""" 178 | self.styles.restore() 179 | runHook("night_mode_state_changed", False) 180 | 181 | def refresh(self, reload=False): 182 | """ 183 | Refresh display by re-enabling redesign or normal mode, 184 | regenerate customizable css strings. 185 | """ 186 | state = self.config.state_on.value 187 | 188 | if not self.profile_loaded: 189 | alert(ERROR_NO_PROFILE) 190 | return 191 | 192 | try: 193 | if state: 194 | if reload: 195 | self.off() 196 | self.on() 197 | else: 198 | self.off() 199 | except Exception: 200 | alert(ERROR_SWITCH % traceback.format_exc()) 201 | return 202 | 203 | # Reload current screen. 204 | if mw.state == 'review': 205 | mw.moveToState('overview') 206 | mw.moveToState('review') 207 | if mw.state == 'deckBrowser': 208 | mw.deckBrowser.refresh() 209 | if mw.state == 'overview': 210 | mw.overview.refresh() 211 | 212 | # Redraw toolbar (should be always visible). 213 | mw.toolbar.draw() 214 | self.update_menu() 215 | return True 216 | 217 | def about(self): 218 | about_box = self.message_box() 219 | about_box.setText(__addon_name__ + ' ' + __version__ + __doc__) 220 | about_box.setGeometry(300, 300, 250, 150) 221 | about_box.setWindowTitle('About \n' + __addon_name__ + ' ' + __version__) 222 | 223 | about_box.exec_() 224 | 225 | def message_box(self): 226 | box = QMessageBox() 227 | if self.config.state_on.value: 228 | box_style = MessageBoxStyle(self) 229 | box.setStyleSheet(box_style.style) 230 | return box 231 | 232 | def night_class_injection(self, html, card, context): 233 | html = inject_css_class(self.config.state_on.value, html) 234 | return html 235 | 236 | def background_bug_workaround(self, editor): 237 | 238 | if self.config.state_on.value: 239 | javascript = """ 240 | (function bg_bug_workaround() 241 | { 242 | function getTextNodeAtPosition(root, index){ 243 | // Copyright notice: 244 | // 245 | // following function is based on a function created by Pery Mimon: 246 | // https://stackoverflow.com/a/38479462 247 | // and is distributed under CC-BY SA 3.0 license terms: 248 | // https://creativecommons.org/licenses/by-sa/3.0/ 249 | 250 | var lastNode = null; 251 | var lastIndex = null 252 | 253 | var treeWalker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT,function next(elem) { 254 | if(index >= elem.textContent.length){ 255 | lastIndex = index 256 | index -= elem.textContent.length; 257 | lastNode = elem; 258 | return NodeFilter.FILTER_REJECT 259 | } 260 | return NodeFilter.FILTER_ACCEPT; 261 | }); 262 | var c = treeWalker.nextNode(); 263 | return { 264 | node: c ? c : lastNode, 265 | position: c ? index : lastIndex 266 | }; 267 | } 268 | 269 | var regex = /<(span|strong) style="background-color: rgb\(255, 255, 255\);">(.*?)<\/(span|strong)>/gm 270 | 271 | function background_workaround_callback(raw_field) 272 | { 273 | function get_rid_of_background(){ 274 | var field = $(raw_field) 275 | var html = field.html() 276 | 277 | if(html.search(regex) == -1) 278 | return 279 | 280 | var selection = window.getSelection() 281 | var range = selection.getRangeAt(0) 282 | range.setStart(raw_field, 0) 283 | var len = range.toString().length 284 | 285 | field.html(html.replace(regex, '<$1>$2')) 286 | 287 | var range = new Range() 288 | var pos = getTextNodeAtPosition(raw_field, len) 289 | 290 | range.setStart(pos.node, pos.position) 291 | 292 | selection.removeAllRanges() 293 | selection.addRange(range) 294 | } 295 | return get_rid_of_background 296 | } 297 | 298 | var field = $('.field') 299 | 300 | field.on('keydown', function(e){ 301 | var raw_field = this 302 | var get_rid_of_background = background_workaround_callback(raw_field) 303 | 304 | if(e.which === 8 || e.which == 46){ 305 | window.setTimeout(get_rid_of_background, 0) 306 | } 307 | }) 308 | 309 | field.on('paste', function(){ 310 | var raw_field = this 311 | var get_rid_of_background = background_workaround_callback(raw_field) 312 | 313 | window.setTimeout(get_rid_of_background, 100) 314 | }) 315 | 316 | })() 317 | """ 318 | else: 319 | javascript = '' 320 | 321 | editor.web.eval(javascript) 322 | 323 | 324 | ERROR_NO_PROFILE = """Switching to redesign failed: The profile is not loaded yet. 325 | It could be a bug in Anki, or you may have tried to enable the redesign too quickly after starting Anki.""" 326 | 327 | ERROR_SWITCH = """Switching to redesign failed: Something went wrong. 328 | This is NOT a problem with Anki, so you can try contacting the add-on author for help. 329 | 330 | Please provide following traceback when reporting the issue: 331 | %s 332 | """ 333 | -------------------------------------------------------------------------------- /redesign/selector.py: -------------------------------------------------------------------------------- 1 | from PyQt5.QtCore import Qt 2 | from PyQt5.QtWidgets import QLabel, QHBoxLayout, QVBoxLayout, QCheckBox 3 | 4 | from .gui import create_button, AddonDialog 5 | from .languages import _ 6 | 7 | 8 | class StylerCheckButton(QCheckBox): 9 | 10 | def __init__(self, parent, styler): 11 | QCheckBox.__init__(self, _(styler.friendly_name), parent) 12 | self.styler = styler 13 | if styler.is_active: 14 | self.toggle() 15 | self.stateChanged.connect(self.switch_state) 16 | self.parent = parent 17 | 18 | def switch_state(self, state): 19 | self.parent.update(self.styler, state) 20 | 21 | 22 | class StylersSelectorWindow(AddonDialog): 23 | 24 | def __init__(self, parent, disabled_stylers: set, all_stylers, title=_('Choose what to style'), on_update=None): 25 | super().__init__(self, parent, Qt.Window) 26 | self.on_update = on_update 27 | self.disabled_stylers = disabled_stylers 28 | self.all_stylers = all_stylers 29 | 30 | self.stylers_checkboxes = [] 31 | self.stylers_layout = None 32 | self.init_ui(title) 33 | 34 | def init_ui(self, title): 35 | self.setWindowTitle(title) 36 | 37 | btn_close = create_button('Close', self.close) 38 | 39 | buttons = QHBoxLayout() 40 | 41 | buttons.addWidget(btn_close) 42 | buttons.setAlignment(Qt.AlignBottom) 43 | 44 | body = QVBoxLayout() 45 | body.setAlignment(Qt.AlignTop) 46 | 47 | header = QLabel(_( 48 | 'Select which parts of Anki should be displayed ' 49 | 'in eye-friendly, dark colors.\n\n' 50 | 'To disable all dialog windows, ' 51 | 'use the "Enable in dialogs" switch which is available in menu.' 52 | )) 53 | header.setAlignment(Qt.AlignCenter) 54 | 55 | stylers = QVBoxLayout() 56 | stylers.setAlignment(Qt.AlignTop) 57 | 58 | for styler in sorted(self.all_stylers, key=lambda s: s.name): 59 | styler_checkbox = StylerCheckButton(self, styler) 60 | self.stylers_checkboxes.append(styler_checkbox) 61 | stylers.addWidget(styler_checkbox) 62 | 63 | self.stylers_layout = stylers 64 | 65 | checked_boxes = sum(1 for checkbox in self.stylers_checkboxes if checkbox.isChecked()) 66 | check_all = QCheckBox(_('Check/uncheck all'), self) 67 | check_all.setChecked(checked_boxes > len(self.stylers_checkboxes) / 2) 68 | check_all.stateChanged.connect(self.check_uncheck_all) 69 | 70 | body.addWidget(header) 71 | body.addWidget(check_all) 72 | body.addLayout(stylers) 73 | body.addStretch(1) 74 | body.addLayout(buttons) 75 | self.setLayout(body) 76 | 77 | self.setGeometry(300, 300, 350, 300) 78 | self.show() 79 | 80 | def check_uncheck_all(self, state): 81 | for checkbox in self.stylers_checkboxes: 82 | checkbox.setChecked(state) 83 | 84 | def update(self, styler, value): 85 | if value: 86 | self.disabled_stylers.remove(styler.name) 87 | else: 88 | self.disabled_stylers.add(styler.name) 89 | 90 | if self.on_update: 91 | self.on_update() 92 | -------------------------------------------------------------------------------- /redesign/stylers.py: -------------------------------------------------------------------------------- 1 | from PyQt5.QtCore import Qt 2 | from PyQt5 import QtWidgets 3 | 4 | import aqt 5 | from anki.stats import CollectionStats 6 | from aqt import mw, editor, QPixmap 7 | from aqt.addcards import AddCards 8 | from aqt.browser import Browser 9 | from aqt.clayout import CardLayout 10 | from aqt.editcurrent import EditCurrent 11 | from aqt.editor import Editor 12 | from aqt.progress import ProgressManager 13 | from aqt.stats import DeckStats 14 | from .gui import AddonDialog, iterate_widgets 15 | 16 | from .config import ConfigValueGetter 17 | from .css_class import inject_css_class 18 | from .internals import percent_escaped, move_args_to_kwargs, from_utf8, PropertyDescriptor 19 | from .internals import style_tag, wraps, appends_in_night_mode, replaces_in_night_mode, css 20 | from .styles import SharedStyles, ButtonsStyle, ImageStyle, DeckStyle, LatexStyle, DialogStyle 21 | from .internals import SnakeNameMixin, StylerMetaclass, abstract_property 22 | from .internals import RequiringMixin 23 | 24 | 25 | 26 | 27 | customFont = "default"; # Set your desired font here. 28 | # Format is "Font Name With Spaces" (i.e. customFont="Times New Roman";) 29 | # Note: If you want to change this, you need to do so in two files: styles.py and stylers.py 30 | 31 | 32 | 33 | 34 | class Styler(RequiringMixin, SnakeNameMixin, metaclass=StylerMetaclass): 35 | 36 | def __init__(self, app): 37 | RequiringMixin.__init__(self, app) 38 | self.app = app 39 | self.config = ConfigValueGetter(app.config) 40 | self.original_attributes = {} 41 | 42 | @abstract_property 43 | def target(self): 44 | return None 45 | 46 | @property 47 | def is_active(self): 48 | return self.name not in self.config.disabled_stylers 49 | 50 | @property 51 | def friendly_name(self): 52 | name = self.name.replace('_styler', '') 53 | return name.replace('_', ' ').title() 54 | 55 | def get_or_create_original(self, key): 56 | if key not in self.original_attributes: 57 | original = getattr(self.target, key) 58 | self.original_attributes[key] = original 59 | else: 60 | original = self.original_attributes[key] 61 | 62 | return original 63 | 64 | def replace_attributes(self): 65 | try: 66 | for key, addition in self.additions.items(): 67 | original = self.get_or_create_original(key) 68 | setattr(self.target, key, original + addition.value(self)) 69 | 70 | for key, replacement in self.replacements.items(): 71 | self.get_or_create_original(key) 72 | 73 | if isinstance(replacement, PropertyDescriptor): 74 | replacement = replacement.value(self) 75 | 76 | setattr(self.target, key, replacement) 77 | 78 | except (AttributeError, TypeError): 79 | print('Failed to inject style to:', self.target, key, self.name) 80 | raise 81 | 82 | def restore_attributes(self): 83 | for key, original in self.original_attributes.items(): 84 | setattr(self.target, key, original) 85 | 86 | 87 | 88 | 89 | class ToolbarStyler(Styler): 90 | 91 | target = mw.toolbar 92 | require = { 93 | SharedStyles 94 | } 95 | 96 | @appends_in_night_mode 97 | @style_tag 98 | @percent_escaped 99 | def _body(self): 100 | return self.shared.top 101 | 102 | 103 | 104 | 105 | class StyleSetter: 106 | 107 | def __init__(self, target): 108 | self.target = target 109 | 110 | @property 111 | def css(self): 112 | return self.target.styleSheet() 113 | 114 | @css.setter 115 | def css(self, value): 116 | self.target.setStyleSheet(value) 117 | 118 | 119 | 120 | 121 | class MenuStyler(Styler): 122 | target = StyleSetter(mw) 123 | 124 | # Note: this line is commented out for light mode. It affects the menus that pop up like after clicking the gear icon next to each deck on the main screen. 125 | # @appends_in_night_mode 126 | def css(self): 127 | return self.shared.menu 128 | 129 | 130 | 131 | 132 | class ReviewerStyler(Styler): 133 | 134 | target = mw.reviewer 135 | require = { 136 | SharedStyles, 137 | ButtonsStyle 138 | } 139 | 140 | @wraps(position='around') 141 | def _bottomHTML(self, reviewer, _old): 142 | return _old(reviewer) + style_tag(percent_escaped(self.bottom_css)) 143 | 144 | 145 | 146 | @property 147 | def bottom_css(self): 148 | return self.buttons.html + self.shared.colors_replacer + """ 149 | 150 | /* Note: This is the reviewer screen, bottom bar, background color */ 151 | body, #outer{ 152 | background-color:""" + self.config.color_b + """; 153 | border-top-color:""" + self.config.color_b + """; 154 | margin: 0 95px 0 95px; 155 | } 156 | 157 | /* Note: This is the reviewer screen, bottom bar, text color of the plus signs */ 158 | .stattxt{ 159 | color:#bdbdbd; 160 | } 161 | 162 | /* Note: This is the reviewer screen, bottom bar, text color of text (time until next review) located above Again, Hard, Easy, etc. buttons */ 163 | .nobold{ 164 | color:#888; 165 | font-family:%s; 166 | } 167 | """ % (customFont) 168 | 169 | 170 | 171 | 172 | 173 | class ReviewerCards(Styler): 174 | 175 | target = mw.reviewer 176 | require = { 177 | LatexStyle, 178 | ImageStyle 179 | } 180 | 181 | # TODO: it can be implemented with a nice decorator 182 | @wraps(position='around') 183 | def revHtml(self, reviewer, _old): 184 | return _old(reviewer) + style_tag(percent_escaped(self.body)) 185 | 186 | @css 187 | def body(self): 188 | # Invert images and latex if needed 189 | 190 | css_body = """ 191 | .card input 192 | { 193 | background-color:black!important; 194 | border-color:#444!important; 195 | color:"""+ self.config.color_c +"""!important 196 | } 197 | .card input::selection{ 198 | color: """ + self.config.color_t + """; 199 | background: #0864d4 200 | } 201 | .typeGood{ 202 | color:black; 203 | background:#57a957 204 | } 205 | .typeBad{ 206 | color:black; 207 | background:#c43c35 208 | } 209 | .typeMissed{ 210 | color:black; 211 | background:#ccc 212 | } 213 | #answer{ 214 | height:0; 215 | border:0; 216 | border-bottom: 2px solid #333; 217 | border-top: 2px solid black 218 | } 219 | img#star{ 220 | -webkit-filter:invert(0%)!important 221 | } 222 | 223 | # This is the answer text color for cloze cards. 224 | # Good red color: #ef5350 225 | .cloze{ 226 | color:"""+ self.config.color_p +"""!important 227 | } 228 | 229 | a{ 230 | color:#0099CC 231 | } 232 | """ 233 | 234 | card_color = """ 235 | .card{ 236 | color:""" + self.config.color_t + """!important; 237 | } 238 | """ 239 | 240 | css = css_body + card_color + self.shared.user_color_map + self.shared.body_colors 241 | 242 | if self.config.invert_image: 243 | css += self.image.invert 244 | if self.config.invert_latex: 245 | css += self.latex.invert 246 | 247 | return css 248 | 249 | 250 | 251 | 252 | class DeckBrowserStyler(Styler): 253 | 254 | target = mw.deckBrowser 255 | require = { 256 | SharedStyles, 257 | DeckStyle 258 | } 259 | 260 | @appends_in_night_mode 261 | def _body(self): 262 | styles_html = style_tag(percent_escaped(self.deck.style + self.shared.body_colors)) 263 | return inject_css_class(True, styles_html) 264 | 265 | 266 | 267 | 268 | class DeckBrowserBottomStyler(Styler): 269 | 270 | target = mw.deckBrowser.bottom 271 | require = { 272 | DeckStyle 273 | } 274 | 275 | @appends_in_night_mode 276 | def _centerBody(self): 277 | styles_html = style_tag(percent_escaped(self.deck.bottom)) 278 | return inject_css_class(True, styles_html) 279 | 280 | 281 | 282 | 283 | class OverviewStyler(Styler): 284 | 285 | target = mw.overview 286 | require = { 287 | SharedStyles, 288 | ButtonsStyle 289 | } 290 | 291 | @appends_in_night_mode 292 | def _body(self): 293 | styles_html = style_tag(percent_escaped(self.css)) 294 | return inject_css_class(True, styles_html) 295 | 296 | @css 297 | def css(self): 298 | return f""" 299 | {self.buttons.html} 300 | {self.shared.colors_replacer} 301 | {self.shared.body_colors} 302 | .descfont 303 | {{ 304 | color: {self.config.color_t} 305 | }} 306 | """ 307 | 308 | 309 | 310 | 311 | class OverviewBottomStyler(Styler): 312 | 313 | target = mw.overview.bottom 314 | require = { 315 | DeckStyle 316 | } 317 | 318 | @appends_in_night_mode 319 | @style_tag 320 | @percent_escaped 321 | def _centerBody(self): 322 | return self.deck.bottom 323 | 324 | 325 | 326 | 327 | class AnkiWebViewStyler(Styler): 328 | 329 | target = mw.web 330 | require = { 331 | SharedStyles, 332 | ButtonsStyle 333 | } 334 | 335 | @wraps(position='around') 336 | def stdHtml(self, web, *args, **kwargs): 337 | old = kwargs.pop('_old') 338 | 339 | args, kwargs = move_args_to_kwargs(old, [web] + list(args), kwargs) 340 | 341 | kwargs['head'] = kwargs.get('head', '') + style_tag(self.waiting_screen) 342 | 343 | return old(web, *args[1:], **kwargs) 344 | 345 | @css 346 | def waiting_screen(self): 347 | return self.buttons.html + self.shared.body_colors 348 | 349 | 350 | 351 | 352 | class BrowserStyler(Styler): 353 | 354 | target = Browser 355 | require = { 356 | SharedStyles, 357 | ButtonsStyle, 358 | } 359 | 360 | @wraps 361 | def init(self, browser, mw): 362 | 363 | if self.config.enable_in_dialogs: 364 | 365 | basic_css = browser.styleSheet() 366 | global_style = '#' + browser.form.centralwidget.objectName() + '{' + self.shared.colors + '}' 367 | browser.setStyleSheet(self.shared.menu + self.style + basic_css + global_style) 368 | 369 | browser.form.tableView.setStyleSheet(self.table) 370 | browser.form.tableView.horizontalHeader().setStyleSheet(self.table_header) 371 | 372 | browser.form.searchEdit.setStyleSheet(self.search_box) 373 | browser.form.searchEdit.setSizeAdjustPolicy(QtWidgets.QComboBox.SizeAdjustPolicy.AdjustToMinimumContentsLength) 374 | 375 | browser.form.searchButton.setStyleSheet(self.buttons.qt) 376 | browser.form.previewButton.setStyleSheet(self.buttons.qt) 377 | 378 | # TODO: test this 379 | #@wraps 380 | def _renderPreview(self, browser, cardChanged=False): 381 | if browser._previewWindow: 382 | self.app.take_care_of_night_class(web_object=browser._previewWeb) 383 | 384 | @wraps(position='around') 385 | def buildTree(self, browser, _old): 386 | root = _old(browser) 387 | if root: # For Anki 2.1.17++ 388 | return root 389 | # --------------------------- 390 | # For Anki 2.1.15-- 391 | root = browser.sidebarTree 392 | for item in root.findItems('', Qt.MatchContains | Qt.MatchRecursive): 393 | icon = item.icon(0) 394 | pixmap = icon.pixmap(32, 32) 395 | image = pixmap.toImage() 396 | # image.invertPixels() 397 | new_icon = aqt.QIcon(QPixmap.fromImage(image)) 398 | item.setIcon(0, new_icon) 399 | 400 | @wraps 401 | def setupSidebar(self, browser): 402 | browser.sidebarTree.setStyleSheet(self.style) 403 | 404 | 405 | @wraps(position='around') 406 | def _cardInfoData(self, browser, _old): 407 | 408 | rep, cs = _old(browser) 409 | 410 | if self.config.enable_in_dialogs: 411 | rep += style_tag(""" 412 | * 413 | { 414 | """ + self.shared.colors + """ 415 | } 416 | div 417 | { 418 | border-color:#ff0000!important 419 | } 420 | """ + self.shared.colors_replacer + """ 421 | """) 422 | return rep, cs 423 | 424 | 425 | # Sidebar of Browse dialog 426 | @css 427 | def style(self): 428 | return """ 429 | 430 | QSplitter::handle 431 | { 432 | /* handled below as QWidget */ 433 | } 434 | #""" + from_utf8("widget") + """, 435 | 436 | /* SIDEBAR SPECIFICALLY */ 437 | QTreeView 438 | { 439 | margin:20px 0 20px 20px; 440 | border: 0px solid #bdbdbd; 441 | border-right: 1px solid #bdbdbd; 442 | min-width:160px; 443 | font-family:"""+ customFont +"""; 444 | """ + self.shared.colors + """ 445 | } 446 | QTreeView::item:selected:active, QTreeView::branch:selected:active 447 | { 448 | color:#fff; 449 | background-color:"""+ self.config.color_p +"""; 450 | } 451 | /* SELECTED BUT NOT ACTIVE, SO TEXT IS FADED; HAPPENS WHEN YOU SELECT ITEM THEN CLICK AWAY */ 452 | QTreeView::item:selected:!active, QTreeView::branch:selected:!active 453 | { 454 | color: rgba(255, 255, 255, 0.8); 455 | background-color:"""+ self.config.color_p +"""; 456 | } 457 | """ + ( 458 | """ 459 | /* make the splitter light-dark (match all widgets as selecting with QSplitter does not work) */ 460 | QWidget{ 461 | background-color:"""+ self.config.color_b +"""; 462 | color: """ + self.config.color_t + """; 463 | } 464 | /* make sure that no other important widgets - like tags box - are light-dark */ 465 | QGroupBox{ 466 | background-color: """ + self.config.color_b + """; 467 | } 468 | """ 469 | if self.config.style_scroll_bars else 470 | '' 471 | ) 472 | 473 | 474 | 475 | 476 | # Browse styles: 477 | # 1st (QTableView) is table of cards that can be selected. 478 | # 2nd (QHeaderView) is the header of the table with each column header. 479 | @css 480 | def table(self): 481 | return f""" 482 | QTableView 483 | {{ 484 | margin:10px 10px 20px 10px; 485 | border-radius:10px; 486 | border:1px solid #bdbdbd; 487 | selection-color:#fff; 488 | alternate-background-color:#f8f8f8; 489 | gridline-color:{self.config.color_c}; 490 | {self.shared.colors}; 491 | selection-background-color:{self.config.color_p}; 492 | font-family:%s; 493 | }} 494 | """ % (customFont) 495 | 496 | # Background of header behind header text background = QHeaderView; the "color:" is for the currently sorted header's arrow 497 | # Header text and its background = QHeaderView::section 498 | @css 499 | def table_header(self): 500 | return """ 501 | QHeaderView 502 | { 503 | background-color:"""+ self.config.color_b +"""; 504 | border-radius:15px 15px 0px 0px; 505 | color:"""+ self.config.color_p +"""; 506 | } 507 | 508 | QHeaderView::section 509 | { 510 | """ + self.shared.colors + """ 511 | height:32px; 512 | background-color:"""+ self.config.color_b +"""; 513 | border-radius:15px; 514 | font-family:%s; 515 | font-size:14px; 516 | color:#888; 517 | } 518 | """ % (customFont) 519 | 520 | 521 | 522 | 523 | # Search bar = QComboBox 524 | # Search icon = QComboBox::down-arrow 525 | @css 526 | def search_box(self): 527 | return """ 528 | 529 | QComboBox 530 | { 531 | margin:10px 0px 10px 0px; 532 | border:0px solid #bdbdbd; 533 | font-size:14px; 534 | font-family:"""+ customFont +"""; 535 | border-radius:20px; 536 | padding:10px 10px 10px 10px; 537 | """ + self.shared.colors + """ 538 | } 539 | 540 | QComboBox:!editable 541 | { 542 | background:"""+ self.config.color_c +"""; 543 | } 544 | 545 | QComboBox QAbstractItemView 546 | { 547 | border:0px solid #bdbdbd; 548 | border-radius:10px 10px 10px 10px; 549 | """ + self.shared.colors + """ 550 | background:"""+ self.config.color_c +"""; 551 | } 552 | 553 | QComboBox::drop-down, QComboBox::drop-down:editable 554 | { 555 | """ + self.shared.colors + """; 556 | margin-right:20px; 557 | background:"""+ self.config.color_b +"""; 558 | border:0px solid """+ self.config.color_b +"""; 559 | padding:10px 10px 10px 10px; 560 | } 561 | 562 | QComboBox::down-arrow 563 | { 564 | width:15px; 565 | height:15px; 566 | image: url('""" + self.app.icons.arrow + """') 567 | } 568 | """ 569 | 570 | 571 | 572 | 573 | # Allows styling of sidebar in Browse dialog (necessary for Anki 2.1.17 and beyond) 574 | try: 575 | from aqt.browser import SidebarModel 576 | 577 | class SidebarModelStyler(Styler): 578 | 579 | target = SidebarModel 580 | 581 | @wraps(position='around') 582 | def iconFromRef(self, sidebar_model, iconRef, _old): 583 | icon = _old(sidebar_model, iconRef) 584 | if icon: 585 | pixmap = icon.pixmap(32, 32) 586 | image = pixmap.toImage() 587 | image.invertPixels() 588 | new_icon = aqt.QIcon(QPixmap.fromImage(image)) 589 | return new_icon 590 | return icon 591 | except ImportError: 592 | pass 593 | 594 | 595 | 596 | 597 | class AddCardsStyler(Styler): 598 | 599 | target = AddCards 600 | require = { 601 | SharedStyles, 602 | ButtonsStyle, 603 | } 604 | 605 | @wraps 606 | def init(self, add_cards, mw): 607 | if self.config.enable_in_dialogs: 608 | 609 | # style add/history button 610 | add_cards.form.buttonBox.setStyleSheet(self.buttons.qt) 611 | 612 | self.set_style_to_objects_inside(add_cards.form.horizontalLayout, self.buttons.qt) 613 | 614 | # style the single line which has some bright color 615 | add_cards.form.line.setStyleSheet('#' + from_utf8('line') + '{border: 0px solid #333}') 616 | 617 | add_cards.form.fieldsArea.setAutoFillBackground(False) 618 | 619 | @staticmethod 620 | def set_style_to_objects_inside(layout, style): 621 | for widget in iterate_widgets(layout): 622 | widget.setStyleSheet(style) 623 | 624 | 625 | class EditCurrentStyler(Styler): 626 | 627 | target = EditCurrent 628 | require = { 629 | ButtonsStyle, 630 | } 631 | 632 | @wraps 633 | def init(self, edit_current, mw): 634 | if self.config.enable_in_dialogs: 635 | # style close button 636 | edit_current.form.buttonBox.setStyleSheet(self.buttons.qt) 637 | 638 | 639 | class ProgressStyler(Styler): 640 | 641 | target = None 642 | require = { 643 | SharedStyles, 644 | DialogStyle, 645 | ButtonsStyle 646 | } 647 | 648 | def init(self, progress, *args, **kwargs): 649 | if self.config.enable_in_dialogs: 650 | progress.setStyleSheet(self.buttons.qt + self.dialog.style) 651 | 652 | 653 | if hasattr(ProgressManager, 'ProgressNoCancel'): 654 | # before beta 31 655 | class LegacyProgressStyler(Styler): 656 | 657 | target = None 658 | require = { 659 | SharedStyles, 660 | DialogStyle, 661 | ButtonsStyle 662 | } 663 | 664 | def init(self, progress, label='', *args, **kwargs): 665 | if self.config.enable_in_dialogs: 666 | # Set label and its styles explicitly (otherwise styling does not work) 667 | label = aqt.QLabel(label) 668 | progress.setLabel(label) 669 | label.setAlignment(Qt.AlignCenter) 670 | label.setStyleSheet(self.dialog.style) 671 | 672 | progress.setStyleSheet(self.buttons.qt + self.dialog.style) 673 | 674 | class ProgressNoCancel(Styler): 675 | 676 | target = ProgressManager.ProgressNoCancel 677 | require = {LegacyProgressStyler} 678 | 679 | # so this bit is required to enable init wrapping of Qt objects 680 | def init(cls, label='', *args, **kwargs): 681 | aqt.QProgressDialog.__init__(cls, label, *args, **kwargs) 682 | 683 | target.__init__ = init 684 | 685 | @wraps 686 | def init(self, progress, *args, **kwargs): 687 | self.legacy_progress_styler.init(progress, *args, **kwargs) 688 | 689 | 690 | class ProgressCancelable(Styler): 691 | 692 | target = ProgressManager.ProgressCancellable 693 | require = {LegacyProgressStyler} 694 | 695 | @wraps 696 | def init(self, progress, *args, **kwargs): 697 | self.legacy_progress_styler.init(progress, *args, **kwargs) 698 | 699 | else: 700 | # beta 31 or newer 701 | 702 | class ProgressDialog(Styler): 703 | 704 | target = ProgressManager.ProgressDialog 705 | require = {ProgressStyler} 706 | 707 | @wraps 708 | def init(self, progress, *args, **kwargs): 709 | self.progress_styler.init(progress, *args, **kwargs) 710 | 711 | 712 | class StatsWindowStyler(Styler): 713 | 714 | target = DeckStats 715 | 716 | require = { 717 | DialogStyle, 718 | ButtonsStyle 719 | } 720 | 721 | @wraps 722 | def init(self, stats, *args, **kwargs): 723 | if self.config.enable_in_dialogs: 724 | stats.setStyleSheet(self.buttons.qt + self.dialog.style) 725 | 726 | 727 | class StatsReportStyler(Styler): 728 | 729 | target = CollectionStats 730 | 731 | require = { 732 | SharedStyles, 733 | DialogStyle 734 | } 735 | 736 | @appends_in_night_mode 737 | @style_tag 738 | @percent_escaped 739 | def css(self): 740 | return ( 741 | self.shared.user_color_map + self.shared.body_colors + """ 742 | body{background-image: none} 743 | """ 744 | ) 745 | 746 | 747 | class EditorStyler(Styler): 748 | 749 | target = Editor 750 | 751 | require = { 752 | SharedStyles, 753 | DialogStyle, 754 | ButtonsStyle 755 | } 756 | 757 | # TODO: this would make more sense if we add some styling to .editor-btn 758 | def _addButton(self, editor, icon, command, *args, **kwargs): 759 | original_function = kwargs.pop('_old') 760 | button = original_function(editor, icon, command, *args, **kwargs) 761 | return button.replace('