├── .gitignore ├── LICENSE ├── README.adoc ├── delicolour ├── __init__.py ├── adjustment_controls.py ├── app_model.py ├── big_colour.py ├── colour.py ├── colour_text_entry.py ├── config.py ├── css_hex_entry.py ├── css_rgb_entry.py ├── fav_colour.py ├── fav_colours.py ├── fine_controls.py ├── main.py ├── main_window.py ├── res │ ├── desat-24.png │ ├── moon-24.png │ ├── sat-24.png │ └── sun-24.png └── scale_entry.py └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | 47 | # Translations 48 | *.mo 49 | *.pot 50 | 51 | # Django stuff: 52 | *.log 53 | 54 | # Sphinx documentation 55 | docs/_build/ 56 | 57 | # PyBuilder 58 | target/ 59 | 60 | # README 61 | README.html 62 | -------------------------------------------------------------------------------- /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.adoc: -------------------------------------------------------------------------------- 1 | // Render with Asciidoctor 2 | 3 | = delicolour 4 | Philippe Proulx 5 | 6 | image:https://img.shields.io/pypi/v/delicolour.svg?label=Latest%20version[link="https://pypi.python.org/pypi/delicolour"] 7 | 8 | **_delicolour_** is a lightweight _colour finder_. 9 | 10 | It has only been tested on Linux. 11 | 12 | image::http://ss.0x3b.org/refixing219.png[delicolour screenshot] 13 | 14 | The goal of delicolour is to have a straightforward user experience for 15 | the task of choosing a colour (mainly for web design), not as advanced 16 | as http://www.gpick.org/[Gpick], yet still useful and responsive. The 17 | core principle is: no tabs or other windows, few clicks, everything 18 | instantaneously accessible from the main window. 19 | 20 | 21 | == Notable features 22 | 23 | * Instant updates (moving one slider or modifying one field updates 24 | the other controls). 25 | * <> showing your two current colours 26 | (called _left_ and _right_). 27 | * Up to four rows of 16 <> at the top 28 | (number of rows and colours per rows is configurable with command-line 29 | options). 30 | * <> (0 to 255). 31 | * <> (0 to 359 for hue and 0 to 100 for saturation and 32 | value). 33 | * Scrollable sliders and entries (hue slider wraps). 34 | * <> (increase/decrease 35 | saturation and lightness) with adjustable increment value. 36 | * <> and <> strings. 37 | * Intelligent copy/paste (paste `\#rrggbb` or `rrggbb` into the hex 38 | text box and decide if you want to prepend the `#` character when 39 | copying). 40 | * Useful <>. 41 | 42 | 43 | == Install 44 | 45 | Make sure you have the dependencies: 46 | 47 | * Python 3 48 | * https://pypi.org/project/colormath/[colormath] 3 49 | * GTK 3 50 | * https://wiki.gnome.org/action/show/Projects/PyGObject[PyGObject] 3 51 | * pip for Python 3 52 | 53 | The package on PyPI is 54 | https://pypi.org/project/delicolour/[`delicolour`]. 55 | 56 | 57 | === Ubuntu 58 | 59 | ---- 60 | $ sudo apt-get install python3-pip python3-gi python3-gi-cairo 61 | $ sudo pip3 install delicolour 62 | ---- 63 | 64 | 65 | === Debian 66 | 67 | ---- 68 | $ sudo apt-get install python3-pip gtk+3.0 python3-gi python3-gi-cairo 69 | $ sudo pip3 install delicolour 70 | ---- 71 | 72 | 73 | === Fedora ≥ 20 74 | 75 | ---- 76 | $ sudo yum install python3-pip gtk3 python3-gobject 77 | $ sudo pip3 install delicolour 78 | ---- 79 | 80 | === Arch Linux 81 | 82 | ---- 83 | $ yay -Sy delicolour 84 | ---- 85 | 86 | 87 | == Usage 88 | 89 | Launch delicolour: 90 | 91 | ---- 92 | delicolour 93 | ---- 94 | 95 | See `delicolour --help` for a list of command-line options. 96 | 97 | 98 | === Interface 99 | 100 | ==== Window title 101 | 102 | ---- 103 | delicolour: #bba6de [#184c99] 104 | ---- 105 | 106 | The window title indicates the two current colours. The one being 107 | currently edited is between `[` and `]`. 108 | 109 | 110 | [[favorite-colours]] 111 | ==== Favorite colours 112 | 113 | image::http://ss.0x3b.org/impercipience71.png[] 114 | 115 | Favorite colours are little squares at the top of the window. 116 | 117 | You can set a favorite colour from the current colour by right-clicking 118 | it or with the <> 119 | **Ctrl**pass:[+]**1** to **Ctrl**pass:[+]**9**. 120 | 121 | You can set the current colour from a favorite colour by left-clicking 122 | it or with the keyboard shortcuts *1* to *9*. 123 | 124 | The `-f`/`--fav-colours-count` and `-F`/`--fav-colours-rows-count` 125 | command-line options control the number of available favorite colours. 126 | Use `--fav-colours-rows-count=0` to disable favorite colours. 127 | 128 | delicolour does not remember favorite colours once you quit it. 129 | 130 | 131 | [[big-colour]] 132 | ==== The big rectangle 133 | 134 | image::http://ss.0x3b.org/poikilothermal774.png[] 135 | 136 | The big rectangle below <> shows the 137 | two current colours. 138 | 139 | A little dot located at the top left or top right corner of the 140 | big rectangle indicates which of the two colours is the one currently 141 | being edited. You can switch to one or the other by clicking the 142 | left or right side of the big rectangle. 143 | 144 | You can set the initial left and right colours when you launch 145 | delicolour with one of: 146 | 147 | * The first positional argument, for example `delicolour fd487e`. This 148 | sets both the left and right colours at the same time. 149 | 150 | * The `-l`/`--left-colour` and `-r`/`--right-colour` command-line 151 | options. 152 | 153 | 154 | [[fine-tuning]] 155 | ==== Fine-tuning controls 156 | 157 | image::http://ss.0x3b.org/unuprightly55.png[] 158 | 159 | With fine-tuning controls, you can modify the current colour using 160 | buttons to finely increment/decrement parameters. 161 | 162 | The control on the left side is the _increment value_. When you press 163 | one of the buttons on the right side, you add/subtract this value 164 | to/from the button's parameter's current value. 165 | 166 | The parameters (buttons), from left to right, are: 167 | 168 | * Decrease saturation (_S_ in HSV) 169 | * Increase saturation 170 | * Decrease lightness (_L_ in HSL) 171 | * Increase lightness 172 | 173 | The increment value also controls the incrementation/decrementation 174 | amount of the sliders when you scroll them with the mouse wheel. 175 | 176 | The `-i`/`--increment` command-line option controls the initial 177 | fine-tuning increment value. 178 | 179 | 180 | [[rgb]] 181 | ==== RGB 182 | 183 | image::http://ss.0x3b.org/stockjobbery593.png[] 184 | 185 | The RGB sliders control the amount of red, green, and blue in the 186 | current colour. 187 | 188 | You can scroll the sliders and text boxes with the mouse wheel. 189 | 190 | 191 | [[hsv]] 192 | ==== HSV 193 | 194 | image::http://ss.0x3b.org/fuzees835.png[] 195 | 196 | The HSV sliders control the hue, saturation, and value or the current 197 | colour. 198 | 199 | You can scroll the sliders and text boxes with the mouse wheel. The hue 200 | slider wraps when you scroll its text box. 201 | 202 | 203 | [[css-hex]] 204 | ==== CSS hex 205 | 206 | image::http://ss.0x3b.org/overglide667.png[] 207 | 208 | The CSS hex text box shows and controls the CSS hexadecimal value of the 209 | current colour. 210 | 211 | You can copy the CSS hex value to the clipboard by clicking the text box 212 | and pressing **Ctrl**pass:[+]**C** (no need to select the whole text). 213 | If the _Copy \#_ option is checked, delicolour preprends a `#` character 214 | to the copied value. 215 | 216 | You can paste a CSS hex value, with or without a `#` prefix, by clicking 217 | the text box and pressing **Ctrl**pass:[+]**V** (no need to select the 218 | whole text). 219 | 220 | If the _Lowercase_ option is checked, delicolour prints the CSS hex 221 | value in lowercase when updating. 222 | 223 | 224 | [[css-rgb]] 225 | ==== CSS RGB 226 | 227 | image::http://ss.0x3b.org/nuzzer45.png[] 228 | 229 | The CSS RGB text box shows and controls the CSS RGB value of the current 230 | colour. 231 | 232 | You can copy the CSS RGB value to the clipboard by clicking the text box 233 | and pressing **Ctrl**pass:[+]**C** (no need to select the whole text). 234 | 235 | You can paste a CSS RGB value, with or without a `#` prefix, by clicking 236 | the text box and pressing **Ctrl**pass:[+]**V** (no need to select the 237 | whole text). 238 | 239 | 240 | [[keyboard-shortcuts]] 241 | === Keyboard shortcuts 242 | 243 | ==== Global shortcuts 244 | 245 | You can always use the following keyboard shortcuts: 246 | 247 | [cols=2*,options="header"] 248 | |=== 249 | |Key 250 | |Action 251 | 252 | |*z* 253 | |Set current colour to black 254 | 255 | |*x* 256 | |Set current colour to white 257 | 258 | |*#* 259 | |Toggle current colour being edited 260 | 261 | |*1* to *9* 262 | |Set current colour from <> 1 to 9 263 | (first row) 264 | 265 | |**Ctrl**pass:[+]**1** to **Ctrl**pass:[+]**9** 266 | |Set <> 1 to 9 (first row) from 267 | current colour 268 | 269 | |*q* 270 | |Decrease saturation 271 | 272 | |*w* 273 | |Increase saturation 274 | 275 | |*-* 276 | |Decrease lightness 277 | 278 | |*=* or *+* 279 | |Increase lightness 280 | |=== 281 | 282 | 283 | ==== RGB shortcuts 284 | 285 | You can use the following keyboard shortcuts when the focus is on one of 286 | the R, G, and B text boxes: 287 | 288 | [cols=2*,options="header"] 289 | |=== 290 | |Key 291 | |Action 292 | 293 | |*r* 294 | | Copy current component value to the R text box 295 | 296 | |*g* 297 | | Copy current component value to the G text box 298 | 299 | |*b* 300 | | Copy current component value to the B text box 301 | |=== 302 | 303 | -------------------------------------------------------------------------------- /delicolour/__init__.py: -------------------------------------------------------------------------------- 1 | __version__ = '1.3.0' 2 | 3 | 4 | def _split_version_suffix(): 5 | return __version__.split('-') 6 | 7 | 8 | def get_version_tuple(): 9 | version, suffix = _split_version_suffix() 10 | parts = version.split('.') 11 | 12 | return (int(parts[0]), int(parts[1]), int(parts[2])) 13 | 14 | 15 | def get_version_suffix(): 16 | return _split_version_suffix()[1] 17 | -------------------------------------------------------------------------------- /delicolour/adjustment_controls.py: -------------------------------------------------------------------------------- 1 | from delicolour import config 2 | from gi.repository import Gtk 3 | from gi.repository import Gdk 4 | from gi.repository import Pango 5 | 6 | 7 | class AdjustmentControls(Gtk.Box): 8 | def __init__(self, minval, maxval, init_adj): 9 | # user callbacks 10 | self._user_on_incr_change = None 11 | 12 | # parameters 13 | self._minval = minval 14 | self._maxval = maxval 15 | 16 | # parent box 17 | super().__init__(spacing=0, homogeneous=False) 18 | self.set_orientation(Gtk.Orientation.HORIZONTAL) 19 | 20 | # controls 21 | self._init_controls() 22 | self._value_lbl.set_text(str(init_adj)) 23 | 24 | @staticmethod 25 | def _new_btn(label, tooltip_text): 26 | btn = Gtk.Button(label=label) 27 | btn.set_tooltip_text(tooltip_text) 28 | btn.set_size_request(30, -1) 29 | btn.set_valign(Gtk.Align.CENTER) 30 | my_style_provider = Gtk.CssProvider() 31 | my_style_provider.load_from_data(b'GtkWidget {padding: 3px;}') 32 | style_context = btn.get_style_context() 33 | style_context.add_provider(my_style_provider, 34 | Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION) 35 | 36 | return btn 37 | 38 | def _init_controls(self): 39 | # label 40 | self._value_lbl = Gtk.Label() 41 | self._value_lbl.modify_font(Pango.FontDescription('sans-serif bold 8')) 42 | self._value_lbl.set_text(str(self._minval)) 43 | self._value_lbl.set_width_chars(2) 44 | self._value_lbl.set_alignment(0, 0.5) 45 | self._value_lbl.set_tooltip_text('Fine-tuning increment') 46 | 47 | # buttons 48 | self._dec_btn = self._new_btn('-', 'Decrement fine-tuning increment') 49 | self._inc_btn = self._new_btn('+', 'Increment fine-tuning increment') 50 | 51 | # set callbacks 52 | self._dec_btn.connect('clicked', self._on_dec) 53 | self._inc_btn.connect('clicked', self._on_inc) 54 | 55 | # alignments 56 | a_pad_left = Gtk.Alignment() 57 | a_pad_left.set_padding(0, 0, config.MAIN_GUTTER_PX, 0) 58 | a_pad_left.add(self._dec_btn) 59 | 60 | # pack into box 61 | self.pack_start(self._value_lbl, False, False, 0) 62 | self.pack_start(a_pad_left, False, False, 0) 63 | self.pack_start(self._inc_btn, False, False, 0) 64 | 65 | def _on_incr_change(self): 66 | if self._user_on_incr_change: 67 | self._user_on_incr_change() 68 | 69 | def _on_inc(self, btn): 70 | val = self.value 71 | 72 | if val == self._maxval: 73 | return 74 | 75 | val += 1 76 | self._value_lbl.set_text(str(val)) 77 | self._on_incr_change() 78 | 79 | def _on_dec(self, btn): 80 | val = self.value 81 | 82 | if val == self._minval: 83 | return 84 | 85 | val -= 1 86 | self._value_lbl.set_text(str(val)) 87 | self._on_incr_change() 88 | 89 | @property 90 | def value(self): 91 | return int(self._value_lbl.get_text()) 92 | 93 | def on_incr_change(self, cb): 94 | self._user_on_incr_change = cb 95 | -------------------------------------------------------------------------------- /delicolour/app_model.py: -------------------------------------------------------------------------------- 1 | from delicolour.colour import Colour 2 | 3 | 4 | class AppModel: 5 | def __init__(self): 6 | self._sel = 1 7 | 8 | @property 9 | def colour(self): 10 | if self.sel == 1: 11 | return self.colour_l 12 | else: 13 | return self.colour_r 14 | 15 | @colour.setter 16 | def colour(self, colour): 17 | copy = colour.copy() 18 | 19 | if self.sel == 1: 20 | self.colour_l = copy 21 | else: 22 | self.colour_r = copy 23 | 24 | @property 25 | def sel(self): 26 | return self._sel 27 | 28 | @sel.setter 29 | def sel(self, sel): 30 | self._sel = sel 31 | 32 | @staticmethod 33 | def get_default(): 34 | model = AppModel() 35 | model.colour_l = Colour.from_rgb(255, 255, 255) 36 | model.colour_r = Colour.from_rgb(0, 0, 0) 37 | model.css_hex_copy_hash = True 38 | model.css_hex_lower = True 39 | model.fine_incr = 1 40 | 41 | return model 42 | 43 | -------------------------------------------------------------------------------- /delicolour/big_colour.py: -------------------------------------------------------------------------------- 1 | import math 2 | from gi.repository import Gtk, Gdk 3 | from delicolour.colour import Colour 4 | 5 | 6 | class BigColour(Gtk.DrawingArea): 7 | def __init__(self, border_radius=4, height=75): 8 | # initial colours 9 | self._colour_l = Colour.from_rgb(0, 0, 0) 10 | self._colour_r = Colour.from_rgb(0, 0, 0) 11 | self._sel = 1 12 | 13 | # save border radius 14 | self._border_radius = border_radius 15 | 16 | # initialize drawing area 17 | super().__init__() 18 | self.set_size_request(0, height) 19 | self.connect('draw', self._on_draw) 20 | 21 | # initialize click action 22 | self.add_events(Gdk.EventMask.BUTTON_PRESS_MASK) 23 | self.connect('button-press-event', self._on_click) 24 | 25 | # user events 26 | self._user_on_sel_change = None 27 | 28 | def _get_size(self): 29 | alloc = self.get_allocation() 30 | 31 | return alloc.width, alloc.height 32 | 33 | def _notify_on_sel_change(self, sel): 34 | if self._user_on_sel_change: 35 | self._user_on_sel_change(sel) 36 | 37 | def _on_click(self, widget, event): 38 | x = int(event.x) 39 | width, height = self._get_size() 40 | 41 | if x < round(width / 2): 42 | self._set_sel(1) 43 | else: 44 | self._set_sel(2) 45 | 46 | self._notify_on_sel_change(self._sel) 47 | 48 | def _on_draw(self, drawing_area, cr): 49 | def do_rect_path(): 50 | # rectangle with rounded corners 51 | cr.arc(width - br - lw, br + lw, br, -0.5 * math.pi, 0) 52 | cr.arc(width - br - lw, height - br - lw, br, 0, 0.5 * math.pi) 53 | cr.arc(br + lw, height - br - lw, br, 0.5 * math.pi, 1 * math.pi) 54 | cr.arc(br + lw, br + lw, br, 1 * math.pi, -0.5 * math.pi) 55 | cr.close_path() 56 | 57 | def do_half_path(): 58 | cr.arc(width - br - lw, br + lw, br, -0.5 * math.pi, 0) 59 | cr.arc(width - br - lw, height - br - lw, br, 0, 0.5 * math.pi) 60 | cr.line_to(round(width / lw) - diag_dist, height - lw) 61 | cr.line_to(round(width / lw) + diag_dist, lw) 62 | cr.close_path() 63 | 64 | def set_source_rgb(colour): 65 | r, g, b = colour.rgb 66 | r /= 255 67 | g /= 255 68 | b /= 255 69 | cr.set_source_rgb(r, g, b) 70 | 71 | def do_dot_path(x, y): 72 | cr.save() 73 | cr.translate(x, y) 74 | cr.scale(dot_rad, dot_rad); 75 | cr.arc(0, 0, 1, 0, 2 * math.pi) 76 | cr.set_source_rgb(0, 0, 0) 77 | cr.restore() 78 | 79 | def draw_sel_dot(): 80 | tr_y = dot_dist 81 | 82 | if self._sel == 1: 83 | tr_x = dot_dist + lw 84 | else: 85 | tr_x = width - dot_dist - lw 86 | 87 | do_dot_path(tr_x, tr_y) 88 | cr.fill() 89 | do_dot_path(tr_x, tr_y) 90 | cr.set_line_width(1) 91 | cr.set_source_rgb(1, 1, 1) 92 | cr.stroke() 93 | 94 | width, height = self._get_size() 95 | br = self._border_radius 96 | lw = 2 97 | dot_rad = 3 98 | dot_dist = 10 99 | diag_dist = 5 100 | 101 | # fill colour 1 102 | set_source_rgb(self._colour_l) 103 | do_rect_path() 104 | cr.fill() 105 | 106 | # fill colour 2 107 | set_source_rgb(self._colour_r) 108 | do_half_path() 109 | cr.fill() 110 | 111 | # stroke around everything 112 | cr.set_line_width(lw) 113 | cr.set_source_rgb(0.3, 0.3, 0.3) 114 | do_rect_path() 115 | cr.stroke() 116 | 117 | # draw selrent dot 118 | draw_sel_dot() 119 | 120 | return False 121 | 122 | def set_colour_l(self, colour): 123 | self._colour_l = colour 124 | self.queue_draw() 125 | 126 | def set_colour_r(self, colour): 127 | self._colour_r = colour 128 | self.queue_draw() 129 | 130 | def set_rgb1(self, r, g, b): 131 | self._colour_l.set_rgb(r, g, b) 132 | self.queue_draw() 133 | 134 | def set_rgb2(self, r, g, b): 135 | self._colour_r.set_rgb(r, g, b) 136 | self.queue_draw() 137 | 138 | def set_sel(self, sel): 139 | self._set_sel(sel) 140 | 141 | def _set_sel(self, sel): 142 | self._sel = sel 143 | self.queue_draw() 144 | 145 | def on_sel_change(self, cb): 146 | self._user_on_sel_change = cb 147 | -------------------------------------------------------------------------------- /delicolour/colour.py: -------------------------------------------------------------------------------- 1 | import re 2 | from colormath.color_objects import sRGBColor 3 | from colormath.color_objects import HSVColor 4 | from colormath.color_objects import HSLColor 5 | from colormath.color_conversions import convert_color 6 | 7 | class Colour: 8 | def __init__(self, r=0, g=0, b=0): 9 | self.set_rgb(r, g, b) 10 | 11 | def __repr__(self): 12 | r, g, b = self.rgb 13 | 14 | return 'Colour({}, {}, {})'.format(r, g, b) 15 | 16 | def set_rgb(self, r, g, b): 17 | self._set_rgb_color(sRGBColor(r, g, b, True)) 18 | 19 | def set_r(self, r): 20 | self._rgb_color.rgb_r = r 21 | self._update_hsv_from_rgb() 22 | 23 | def set_g(self, g): 24 | self._rgb_color.rgb_g = g 25 | self._update_hsv_from_rgb() 26 | 27 | def set_b(self, b): 28 | self._rgb_color.rgb_b = b 29 | self._update_hsv_from_rgb() 30 | 31 | def set_hsv(self, h, s, v): 32 | self._set_hsv_color(HSVColor(h, s, v)) 33 | 34 | def _update_rgb_from_hsv(self): 35 | self._rgb_color = convert_color(self._hsv_color, sRGBColor) 36 | 37 | def _update_hsv_from_rgb(self): 38 | self._hsv_color = convert_color(self._rgb_color, HSVColor) 39 | 40 | @property 41 | def rgb(self): 42 | return self._rgb_color.get_upscaled_value_tuple() 43 | 44 | @property 45 | def hsv(self): 46 | c = self._hsv_color 47 | 48 | return c.hsv_h, c.hsv_s, c.hsv_v 49 | 50 | @property 51 | def hex(self): 52 | r, g, b = self.rgb 53 | 54 | return '{:02x}{:02x}{:02x}'.format(r, g, b) 55 | 56 | def set_from_hex(self, hex_str): 57 | hex_str = hex_str.strip() 58 | 59 | if hex_str.startswith('#'): 60 | hex_str = hex_str[1:] 61 | 62 | if len(hex_str) == 3: 63 | hex_str = '{r}{r}{g}{g}{b}{b}'.format(r=hex_str[0], 64 | g=hex_str[1], 65 | b=hex_str[2]) 66 | 67 | if len(hex_str) != 6: 68 | return 69 | 70 | color = sRGBColor.new_from_rgb_hex(hex_str) 71 | self._set_rgb_color(color) 72 | 73 | def _set_hsv_color(self, hsv): 74 | self._hsv_color = hsv 75 | self._update_rgb_from_hsv() 76 | 77 | def _set_rgb_color(self, rgb): 78 | self._rgb_color = rgb 79 | self._update_hsv_from_rgb() 80 | 81 | @property 82 | def _hsl_color(self): 83 | return convert_color(self._hsv_color, HSLColor) 84 | 85 | def inc_light(self, val): 86 | hsl = self._hsl_color 87 | light = hsl.hsl_l 88 | light += val 89 | 90 | # clip 91 | if light > 1: 92 | light = 1 93 | 94 | hsl.hsl_l = light 95 | self._set_hsv_color(convert_color(hsl, HSVColor)) 96 | 97 | def dec_light(self, val): 98 | hsl = self._hsl_color 99 | light = hsl.hsl_l 100 | light -= val 101 | 102 | # clip 103 | if light < 0: 104 | light = 0 105 | 106 | hsl.hsl_l = light 107 | self._set_hsv_color(convert_color(hsl, HSVColor)) 108 | 109 | def inc_sat(self, val): 110 | sat = self._hsv_color.hsv_s 111 | sat += val 112 | 113 | # clip 114 | if sat > 1: 115 | sat = 1 116 | 117 | self._hsv_color.hsv_s = sat 118 | self._update_rgb_from_hsv() 119 | 120 | def dec_sat(self, val): 121 | sat = self._hsv_color.hsv_s 122 | sat -= val 123 | 124 | # clip 125 | if sat < 0: 126 | sat = 0 127 | 128 | self._hsv_color.hsv_s = sat 129 | self._update_rgb_from_hsv() 130 | 131 | @staticmethod 132 | def _rgb_in_range(r, g, b): 133 | good = True 134 | for val in [r, g, b]: 135 | good &= (val >= 0 and val <= 255) 136 | 137 | return good 138 | 139 | def set_from_css_rgb(self, rgb_str): 140 | rgb_str = rgb_str.strip() 141 | m = re.match(r'^rgb\s*\(\s*(\d+)\s*\,\s*(\d+)\s*\,\s*(\d+)\s*\)$', rgb_str) 142 | 143 | if not m: 144 | return 145 | 146 | r = int(m.group(1)) 147 | g = int(m.group(2)) 148 | b = int(m.group(3)) 149 | 150 | if not Colour._rgb_in_range(r, g, b): 151 | return 152 | 153 | self.set_rgb(r, g, b) 154 | 155 | def get_css_rgb(self): 156 | r, g, b = self.rgb 157 | 158 | return 'rgb({}, {}, {})'.format(r, g, b) 159 | 160 | @staticmethod 161 | def from_rgb(r, g, b): 162 | c = Colour() 163 | c.set_rgb(r, g, b) 164 | 165 | return c 166 | 167 | @staticmethod 168 | def from_hsv(h, s, v): 169 | c = Colour() 170 | c.set_hsv(h, s, v) 171 | 172 | return c 173 | 174 | @staticmethod 175 | def from_hex(hex_str): 176 | c = Colour() 177 | c.set_from_hex(hex_str) 178 | 179 | return c 180 | 181 | @staticmethod 182 | def from_css_rgb(rgb_str): 183 | c = Colour() 184 | c.set_from_css_rgb(rgb_str) 185 | 186 | return c 187 | 188 | def copy(self): 189 | r, g, b = self.rgb 190 | 191 | return Colour.from_rgb(r, g, b) 192 | -------------------------------------------------------------------------------- /delicolour/colour_text_entry.py: -------------------------------------------------------------------------------- 1 | import re 2 | from delicolour import config 3 | from gi.repository import Gtk 4 | from gi.repository import Gdk 5 | from gi.repository import Pango 6 | 7 | 8 | class ColourTextEntry(Gtk.Entry): 9 | def __init__(self, maxlen): 10 | # parameters 11 | self._user_on_change = None 12 | self._clipboard_sel = Gdk.SELECTION_CLIPBOARD 13 | 14 | # build entry 15 | super().__init__() 16 | self.set_max_length(maxlen) 17 | self.modify_font(Pango.FontDescription('monospace bold 8')) 18 | self.set_width_chars(maxlen) 19 | self.set_max_width_chars(maxlen) 20 | self.connect('insert-text', self._on_insert_text) 21 | self._changed_handler = self.connect('changed', self._on_changed) 22 | self.connect('cut-clipboard', self._on_cut) 23 | self.connect('copy-clipboard', self._on_copy) 24 | self.connect('paste-clipboard', self._on_paste) 25 | 26 | def _do_user_on_change(self): 27 | if self._user_on_change: 28 | self._user_on_change() 29 | 30 | def _on_insert_text(self, entry, new_text, new_text_length, 31 | position): 32 | if not self._match_input(new_text): 33 | self.stop_emission('insert-text') 34 | 35 | def _on_changed(self, editable): 36 | if not self._current_text_is_valid(): 37 | # consider nothing changed 38 | return 39 | 40 | # notify user 41 | self._do_user_on_change() 42 | 43 | def _set_clipboard(self): 44 | txt = self._text_to_clipboard() 45 | Gtk.Clipboard.get(self._clipboard_sel).set_text(txt, -1) 46 | 47 | def _get_clipboard(self): 48 | txt = Gtk.Clipboard.get(self._clipboard_sel).wait_for_text() 49 | 50 | if txt is not None: 51 | txt = self._text_from_clipboard(txt) 52 | 53 | return txt 54 | 55 | def _on_cut(self, entry): 56 | self.stop_emission('cut-clipboard') 57 | 58 | def _on_copy(self, entry): 59 | if self._current_text_is_valid(): 60 | self._set_clipboard() 61 | 62 | self.stop_emission('copy-clipboard') 63 | 64 | def _on_paste(self, entry): 65 | text = self._get_clipboard() 66 | 67 | if text is not None: 68 | self.set_text_no_emit(text) 69 | 70 | # notify user 71 | self._do_user_on_change() 72 | 73 | self.stop_emission('paste-clipboard') 74 | 75 | @property 76 | def colour(self): 77 | raise NotImplementedError() 78 | 79 | def set_colour_no_emit(self, colour): 80 | raise NotImplementedError() 81 | 82 | def set_text_no_emit(self, text): 83 | self.handler_block(self._changed_handler) 84 | self.set_text(self._get_real_text(text)) 85 | self.handler_unblock(self._changed_handler) 86 | 87 | def on_change(self, cb): 88 | self._user_on_change = cb 89 | -------------------------------------------------------------------------------- /delicolour/config.py: -------------------------------------------------------------------------------- 1 | MAIN_GUTTER_PX = 8 2 | SMALL_GUTTER_PX = 6 3 | TEXT_COLOUR_R = 0.15 4 | TEXT_COLOUR_G = 0.15 5 | TEXT_COLOUR_B = 0.15 6 | INCR_SPINNER_MIN_VAL = 1 7 | INCR_SPINNER_MAX_VAL = 15 8 | DEF_FAV_COLOURS_COUNT = 12 9 | -------------------------------------------------------------------------------- /delicolour/css_hex_entry.py: -------------------------------------------------------------------------------- 1 | import re 2 | from delicolour import config 3 | from delicolour.colour import Colour 4 | from delicolour.colour_text_entry import ColourTextEntry 5 | from gi.repository import Gtk 6 | from gi.repository import Gdk 7 | from gi.repository import Pango 8 | 9 | 10 | class CssHexEntry(ColourTextEntry): 11 | def __init__(self, lower=True, copy_hash=True): 12 | # parameters 13 | self._lower = lower 14 | self._copy_hash = copy_hash 15 | 16 | # build parent 17 | super().__init__(6) 18 | 19 | def _text_len_is_valid(self, text): 20 | return len(text) in [3, 6] 21 | 22 | def _current_text_is_valid(self): 23 | text = self.get_text() 24 | 25 | return self._text_len_is_valid(text) 26 | 27 | def _match_input(self, text): 28 | return re.search(r'^[0-9a-fA-F]*$', text) 29 | 30 | def _text_to_clipboard(self): 31 | text = self.get_text() 32 | 33 | if self._copy_hash: 34 | text = '#{}'.format(text) 35 | 36 | return text 37 | 38 | def _text_from_clipboard(self, text): 39 | text = text.strip() 40 | 41 | if text.startswith('#'): 42 | text = text[1:] 43 | 44 | if self._text_len_is_valid(text): 45 | return text 46 | 47 | return None 48 | 49 | def _get_real_text(self, text): 50 | text = text.upper() 51 | 52 | if self._lower: 53 | text = text.lower() 54 | 55 | return text 56 | 57 | def set_lower(self, lower): 58 | self._lower = lower 59 | 60 | if self._current_text_is_valid(): 61 | text = self.get_text().upper() 62 | 63 | if lower: 64 | text = text.lower() 65 | 66 | self.set_text_no_emit(text) 67 | 68 | def set_copy_hash(self, copy_hash): 69 | self._copy_hash = copy_hash 70 | 71 | @property 72 | def colour(self): 73 | return Colour.from_hex(self.get_text()) 74 | 75 | def set_colour_no_emit(self, colour): 76 | self.set_text_no_emit(colour.hex) 77 | -------------------------------------------------------------------------------- /delicolour/css_rgb_entry.py: -------------------------------------------------------------------------------- 1 | from delicolour.colour_text_entry import ColourTextEntry 2 | from delicolour.colour import Colour 3 | from gi.repository import Pango 4 | from gi.repository import Gdk 5 | from delicolour import config 6 | from gi.repository import Gtk 7 | import re 8 | 9 | 10 | class CssRgbEntry(ColourTextEntry): 11 | def __init__(self): 12 | super().__init__(18) 13 | 14 | @staticmethod 15 | def _text_is_valid(text): 16 | text = text.lower() 17 | 18 | return re.search(r'^rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$', text) 19 | 20 | def _current_text_is_valid(self): 21 | return self._text_is_valid(self.get_text()) 22 | 23 | def _match_input(self, text): 24 | text = text.lower() 25 | 26 | return re.search(r'^[ rgb()\,0-9]*$', text) 27 | 28 | def _text_to_clipboard(self): 29 | return self.get_text().lower() 30 | 31 | def _text_from_clipboard(self, text): 32 | text = text.lower().strip() 33 | 34 | if self._text_is_valid(text): 35 | return text 36 | 37 | return None 38 | 39 | def _get_real_text(self, text): 40 | return text.lower() 41 | 42 | @property 43 | def colour(self): 44 | return Colour.from_css_rgb(self.get_text()) 45 | 46 | def set_colour_no_emit(self, colour): 47 | self.set_text_no_emit(colour.get_css_rgb()) 48 | -------------------------------------------------------------------------------- /delicolour/fav_colour.py: -------------------------------------------------------------------------------- 1 | import math 2 | from gi.repository import Gtk, Gdk 3 | from delicolour.colour import Colour 4 | 5 | 6 | class FavColour(Gtk.DrawingArea): 7 | def __init__(self, width, height): 8 | # initialize drawing area 9 | super().__init__() 10 | self.set_size_request(width, height) 11 | self.connect('draw', self._on_draw) 12 | 13 | # initialize click action 14 | self.add_events(Gdk.EventMask.BUTTON_PRESS_MASK) 15 | self.connect('button-press-event', self._on_click) 16 | 17 | # user events 18 | self._user_on_click = None 19 | 20 | # set initial color 21 | self.set_colour(Colour.from_rgb(255, 255, 255)) 22 | 23 | def _get_size(self): 24 | alloc = self.get_allocation() 25 | 26 | return alloc.width, alloc.height 27 | 28 | def _notify_on_click(self, event): 29 | if self._user_on_click: 30 | self._user_on_click(event, self) 31 | 32 | def _on_click(self, widget, event): 33 | self._notify_on_click(event) 34 | 35 | def _on_draw(self, drawing_area, cr): 36 | def do_path(): 37 | cr.rectangle(lw, lw, width - 2 * lw, height - 2 * lw) 38 | 39 | def set_source_rgb(colour): 40 | r, g, b = colour.rgb 41 | r /= 255 42 | g /= 255 43 | b /= 255 44 | cr.set_source_rgb(r, g, b) 45 | 46 | width, height = self._get_size() 47 | lw = 2 48 | 49 | # fill colour 1 50 | set_source_rgb(self._colour) 51 | do_path() 52 | cr.fill() 53 | 54 | # stroke around everything 55 | cr.set_line_width(lw) 56 | cr.set_source_rgb(.3, .3, .3) 57 | do_path() 58 | cr.stroke() 59 | 60 | return False 61 | 62 | def set_colour(self, colour): 63 | self._colour = colour 64 | self.set_tooltip_text('#' + self._colour.hex) 65 | self.queue_draw() 66 | 67 | @property 68 | def colour(self): 69 | return self._colour 70 | 71 | def on_click(self, cb): 72 | self._user_on_click = cb 73 | -------------------------------------------------------------------------------- /delicolour/fav_colours.py: -------------------------------------------------------------------------------- 1 | from delicolour.fav_colour import FavColour 2 | from delicolour.colour import Colour 3 | from gi.repository import Gtk, Gdk 4 | from delicolour import config 5 | import math 6 | 7 | 8 | class FavColours(Gtk.Box): 9 | def __init__(self, max_height=(3 * config.MAIN_GUTTER_PX), 10 | fav_colours_count=config.DEF_FAV_COLOURS_COUNT): 11 | super().__init__(spacing=config.MAIN_GUTTER_PX) 12 | self._fav_colours_count = fav_colours_count 13 | self._max_height = max_height 14 | self.connect('realize', self._on_realize) 15 | self._user_on_fav_colour_click = None 16 | 17 | def _get_size(self): 18 | alloc = self.get_allocation() 19 | 20 | return alloc.width, alloc.height 21 | 22 | def _on_realize(self, widget): 23 | width, height = self._get_size() 24 | colours_count = self._fav_colours_count 25 | self._fav_colours = [] 26 | 27 | # remove gutters from total width 28 | width -= (colours_count - 1) * config.MAIN_GUTTER_PX 29 | 30 | # divide remaining width equally 31 | fav_colour_width = round(width / colours_count) 32 | 33 | # clip height if needed 34 | fav_colour_height = fav_colour_width 35 | 36 | if fav_colour_height > self._max_height: 37 | fav_colour_height = self._max_height 38 | 39 | for c in range(colours_count): 40 | fav_colour = FavColour(fav_colour_width, fav_colour_height) 41 | fav_colour.on_click(self._notify_on_fav_colour_click) 42 | self._fav_colours.append(fav_colour) 43 | self.pack_start(fav_colour, False, False, 0) 44 | fav_colour.show() 45 | 46 | @property 47 | def fav_colours(self): 48 | return self._fav_colours 49 | 50 | def _notify_on_fav_colour_click(self, event, fav_colour): 51 | if self._user_on_fav_colour_click: 52 | self._user_on_fav_colour_click(event, fav_colour) 53 | 54 | def on_fav_colour_click(self, cb): 55 | self._user_on_fav_colour_click = cb 56 | -------------------------------------------------------------------------------- /delicolour/fine_controls.py: -------------------------------------------------------------------------------- 1 | import re 2 | from delicolour import config 3 | from gi.repository import Gtk 4 | from gi.repository import Gdk 5 | from gi.repository import Pango 6 | from pkg_resources import resource_filename 7 | from delicolour.adjustment_controls import AdjustmentControls 8 | 9 | 10 | class FineControls(Gtk.Box): 11 | def __init__(self, minval, maxval, init_adj): 12 | # parameters 13 | self._minval = minval 14 | self._maxval = maxval 15 | self._user_on_inc_light = None 16 | self._user_on_dec_light = None 17 | self._user_on_inc_sat = None 18 | self._user_on_dec_sat = None 19 | 20 | # parent box 21 | super().__init__(spacing=0, homogeneous=False) 22 | self.set_orientation(Gtk.Orientation.HORIZONTAL) 23 | 24 | # controls 25 | self._init_controls(init_adj) 26 | 27 | @staticmethod 28 | def _new_fine_control_btn(img_filename, tooltip_text): 29 | img = Gtk.Image() 30 | img.set_from_file(img_filename) 31 | btn = Gtk.Button() 32 | btn.set_tooltip_text(tooltip_text) 33 | btn.add(img) 34 | 35 | return btn 36 | 37 | @staticmethod 38 | def _get_filename(img): 39 | filename = 'res/{}.png'.format(img) 40 | 41 | return resource_filename(__name__, filename) 42 | 43 | def _init_controls(self, init_adj): 44 | new = FineControls._new_fine_control_btn 45 | gfn = self._get_filename 46 | 47 | # buttons 48 | self._inc_light = new(gfn('sun-24'), 'Increase lightness') 49 | self._dec_light = new(gfn('moon-24'), 'Decrease lightness') 50 | self._inc_sat = new(gfn('sat-24'), 'Increase saturation') 51 | self._dec_sat = new(gfn('desat-24'), 'Decrease saturation') 52 | 53 | # set callbacks 54 | self._inc_light.connect('clicked', self._on_inc_light_clicked) 55 | self._dec_light.connect('clicked', self._on_dec_light_clicked) 56 | self._inc_sat.connect('clicked', self._on_inc_sat_clicked) 57 | self._dec_sat.connect('clicked', self._on_dec_sat_clicked) 58 | 59 | # alignments 60 | a_pad_left = Gtk.Alignment() 61 | a_pad_left.set_padding(0, 0, config.MAIN_GUTTER_PX, 0) 62 | a_pad_left.add(self._dec_light) 63 | 64 | # pack into box 65 | self.pack_end(self._inc_light, False, False, 0) 66 | self.pack_end(a_pad_left, False, False, 0) 67 | self.pack_end(self._inc_sat, False, False, 0) 68 | self.pack_end(self._dec_sat, False, False, 0) 69 | 70 | # adjustment controls 71 | self._adj = AdjustmentControls(1, 15, init_adj) 72 | self.pack_start(self._adj, False, False, 0) 73 | 74 | def _on_inc_light_clicked(self, btn): 75 | if self._user_on_inc_light: 76 | self._user_on_inc_light() 77 | 78 | def _on_dec_light_clicked(self, btn): 79 | if self._user_on_dec_light: 80 | self._user_on_dec_light() 81 | 82 | def _on_inc_sat_clicked(self, btn): 83 | if self._user_on_inc_sat: 84 | self._user_on_inc_sat() 85 | 86 | def _on_dec_sat_clicked(self, btn): 87 | if self._user_on_dec_sat: 88 | self._user_on_dec_sat() 89 | 90 | @property 91 | def incr_value(self): 92 | return self._adj.value 93 | 94 | def on_inc_light(self, cb): 95 | self._user_on_inc_light = cb 96 | 97 | def on_dec_light(self, cb): 98 | self._user_on_dec_light = cb 99 | 100 | def on_inc_sat(self, cb): 101 | self._user_on_inc_sat = cb 102 | 103 | def on_dec_sat(self, cb): 104 | self._user_on_dec_sat = cb 105 | 106 | def on_incr_change(self, cb): 107 | self._adj.on_incr_change(cb) 108 | -------------------------------------------------------------------------------- /delicolour/main.py: -------------------------------------------------------------------------------- 1 | import gi 2 | 3 | 4 | # required GI versions/features 5 | gi.require_version('Gtk', '3.0') 6 | 7 | 8 | from delicolour import main_window 9 | from delicolour import config 10 | from gi.repository import Gtk 11 | import delicolour 12 | import argparse 13 | import warnings 14 | import signal 15 | import sys 16 | 17 | 18 | def _perror(msg): 19 | print('Error: ' + str(msg), file=sys.stderr) 20 | sys.exit(1) 21 | 22 | 23 | def _parse_args(): 24 | ap = argparse.ArgumentParser() 25 | 26 | ap.add_argument('maincolour', metavar='MAIN COLOUR', nargs='?', 27 | help='main colour') 28 | ap.add_argument('-f', '--fav-colours-count', action='store', type=int, 29 | metavar='COUNT', default=12, 30 | help='number of fav colours per row (default: 12)') 31 | ap.add_argument('-F', '--fav-colours-rows-count', action='store', type=int, 32 | metavar='COUNT', default=1, 33 | help='number of rows of fav colours (default: 1)') 34 | ap.add_argument('-i', '--increment', action='store', metavar='VALUE', 35 | type=int, default=1, 36 | help='fine-tuning increment (default: 1)') 37 | ap.add_argument('-l', '--left-colour', action='store', metavar='HEX', 38 | help='initial left color (CSS hex)') 39 | ap.add_argument('-r', '--right-colour', action='store', metavar='HEX', 40 | help='initial right color (CSS hex)') 41 | ap.add_argument('-V', '--version', action='version', 42 | version='%(prog)s v{}'.format(delicolour.__version__)) 43 | 44 | # parse args 45 | args = ap.parse_args() 46 | 47 | # validate --fav-colours-count 48 | if args.fav_colours_count < 1 or args.fav_colours_count > 16: 49 | _perror('--fav-colours-count must be in [1, 16] range') 50 | 51 | # validate --fav-colours-rows-count 52 | if args.fav_colours_rows_count < 0 or args.fav_colours_rows_count > 4: 53 | _perror('--fav-colours-rows-count must be in [0, 4] range') 54 | 55 | # validate --increment 56 | mn = config.INCR_SPINNER_MIN_VAL 57 | mx = config.INCR_SPINNER_MAX_VAL 58 | 59 | if args.increment < mn or args.increment > mx: 60 | _perror('--increment must be in [{}, {}] range'.format(mn, mx)) 61 | 62 | return args 63 | 64 | 65 | def run(): 66 | # enable SIGINT (Ctrl+C) 67 | signal.signal(signal.SIGINT, signal.SIG_DFL) 68 | 69 | # see 70 | warnings.filterwarnings('ignore', '.*g_value_get_int.*', Warning) 71 | 72 | # main app 73 | args = _parse_args() 74 | win = main_window.MainWindow(args) 75 | win.connect('delete-event', Gtk.main_quit) 76 | win.show_all() 77 | Gtk.main() 78 | -------------------------------------------------------------------------------- /delicolour/main_window.py: -------------------------------------------------------------------------------- 1 | from delicolour.fine_controls import FineControls 2 | from delicolour.css_hex_entry import CssHexEntry 3 | from delicolour.css_rgb_entry import CssRgbEntry 4 | from delicolour.fav_colours import FavColours 5 | from delicolour.scale_entry import ScaleEntry 6 | from delicolour.big_colour import BigColour 7 | from delicolour.app_model import AppModel 8 | from delicolour.colour import Colour 9 | from gi.repository import Pango 10 | from delicolour import config 11 | from gi.repository import Gtk 12 | from gi.repository import Gdk 13 | from functools import partial 14 | import copy 15 | import enum 16 | 17 | 18 | @enum.unique 19 | class ControlType(enum.Enum): 20 | INIT = -1 21 | HSV = 0 22 | RGB = 1 23 | CSS_HEX = 2 24 | CSS_RGB = 3 25 | 26 | 27 | class MainWindow(Gtk.Window): 28 | def __init__(self, args): 29 | super().__init__(title='delicolour') 30 | self._args = args 31 | self._make_me_nice() 32 | self._init_main_box() 33 | self._init_keyb() 34 | self._model = AppModel.get_default() 35 | self._apply_args() 36 | self._update_view(ControlType.INIT) 37 | 38 | def _apply_arg_init(self, init): 39 | try: 40 | colour = Colour.from_hex(init) 41 | except: 42 | return 43 | 44 | self._model.colour = colour 45 | 46 | def _apply_args(self): 47 | if self._args.maincolour is not None: 48 | try: 49 | colour = Colour.from_hex(self._args.maincolour) 50 | self._model.colour_l = colour 51 | self._model.colour_r = colour.copy() 52 | except: 53 | pass 54 | else: 55 | if self._args.left_colour is not None: 56 | try: 57 | colour = Colour.from_hex(self._args.left_colour) 58 | self._model.colour_l = colour 59 | except: 60 | pass 61 | 62 | if self._args.right_colour is not None: 63 | try: 64 | colour = Colour.from_hex(self._args.right_colour) 65 | self._model.colour_r = colour 66 | except: 67 | pass 68 | 69 | self._model.fine_incr = self._args.increment 70 | 71 | def _make_me_nice(self): 72 | self.set_position(Gtk.WindowPosition.CENTER) 73 | self.set_border_width(round(config.MAIN_GUTTER_PX * 1.5)) 74 | self.set_resizable(False) 75 | 76 | def _init_keyb(self): 77 | self.connect('key_press_event', self._on_key_press) 78 | 79 | def _on_key_press(self, widget, event): 80 | key_name = Gdk.keyval_name(event.keyval) 81 | 82 | if key_name == 'z': 83 | # set to black 84 | self._set_model_rgb(0, 0, 0) 85 | elif key_name == 'x': 86 | # set to white 87 | self._set_model_rgb(255, 255, 255) 88 | elif key_name == 'minus' or key_name == 'KP_Subtract': 89 | # decrease lightness 90 | self._on_dec_light() 91 | elif key_name == 'plus' or key_name == 'equal' or key_name == 'KP_Add': 92 | # increase lightness 93 | self._on_inc_light() 94 | elif key_name == 'q': 95 | # decrease saturation 96 | self._on_dec_sat() 97 | elif key_name == 'w': 98 | # increase saturation 99 | self._on_inc_sat() 100 | elif key_name == 'numbersign': 101 | # swap colours 102 | if self._model.sel == 1: 103 | self._model.sel = 2 104 | else: 105 | self._model.sel = 1 106 | 107 | self._update_view() 108 | elif len(key_name) == 1 and ord(key_name) >= ord('1') and ord(key_name) <= ord('9'): 109 | self._on_number_key(key_name, event) 110 | 111 | def _on_number_key(self, key_name, event): 112 | index = ord(key_name) - ord('1') 113 | fav_colour = self._first_row_fav_colour(index) 114 | 115 | if fav_colour is None: 116 | return 117 | 118 | if event.state == Gdk.ModifierType.CONTROL_MASK: 119 | fav_colour.set_colour(self._model.colour.copy()) 120 | self._update_view() 121 | elif event.state == 0: 122 | if type(self.get_focus()) is Gtk.Entry: 123 | return 124 | 125 | self._model.colour = fav_colour.colour 126 | self._update_view() 127 | 128 | def _first_row_fav_colour(self, index): 129 | if self._args.fav_colours_rows_count == 0: 130 | return 131 | 132 | if index >= self._args.fav_colours_count: 133 | return 134 | 135 | return self._fav_colours.fav_colours[index] 136 | 137 | def _init_main_box(self): 138 | self._main_box = Gtk.Box(spacing=config.MAIN_GUTTER_PX, 139 | homogeneous=False) 140 | self._main_box.set_orientation(Gtk.Orientation.VERTICAL) 141 | self._main_box.set_size_request(320, 0) 142 | self.add(self._main_box) 143 | self._init_all() 144 | 145 | def _init_big_colour(self): 146 | self._big_colour = BigColour() 147 | self._big_colour.on_sel_change(self._on_sel_change) 148 | self._main_box.pack_start(self._big_colour, True, True, 0) 149 | 150 | def _init_fav_colours(self): 151 | fav_colours_count = self._args.fav_colours_count 152 | 153 | for i in range(self._args.fav_colours_rows_count): 154 | fav_colours = FavColours(fav_colours_count=fav_colours_count) 155 | fav_colours.on_fav_colour_click(self._on_fav_colour_click) 156 | self._main_box.pack_start(fav_colours, True, True, 0) 157 | 158 | if i == 0: 159 | self._fav_colours = fav_colours 160 | 161 | def _init_fine_colour_controls(self): 162 | # fine controls 163 | self._fine_controls = FineControls(config.INCR_SPINNER_MIN_VAL, 164 | config.INCR_SPINNER_MAX_VAL, 165 | self._args.increment) 166 | self._main_box.pack_start(self._fine_controls, True, True, 0) 167 | 168 | # set callbacks 169 | self._fine_controls.on_inc_light(self._on_inc_light) 170 | self._fine_controls.on_dec_light(self._on_dec_light) 171 | self._fine_controls.on_inc_sat(self._on_inc_sat) 172 | self._fine_controls.on_dec_sat(self._on_dec_sat) 173 | self._fine_controls.on_incr_change(self._update_model_from_incr) 174 | 175 | def _init_colour_controls(self): 176 | # build controls 177 | self._r_ctrl = ScaleEntry('R', 0, 255, 1, 1, 0.1, 0.3) 178 | self._g_ctrl = ScaleEntry('G', 0, 255, 1, 0, 0.5, 0) 179 | self._b_ctrl = ScaleEntry('B', 0, 255, 1, 0, 0.5, 1) 180 | self._h_ctrl = ScaleEntry('H', 0, 359, 1, wrap=True) 181 | self._s_ctrl = ScaleEntry('S', 0, 100, 1) 182 | self._v_ctrl = ScaleEntry('V', 0, 100, 1) 183 | 184 | # alignments for padding 185 | a1 = Gtk.Alignment() 186 | a1.set_padding(config.MAIN_GUTTER_PX, 0, 0, 0) 187 | a1.add(self._r_ctrl) 188 | a2 = Gtk.Alignment() 189 | a2.set_padding(config.MAIN_GUTTER_PX, 0, 0, 0) 190 | a2.add(self._h_ctrl) 191 | 192 | # register listeners 193 | self._r_ctrl.on_change(self._update_model_from_rgb) 194 | self._g_ctrl.on_change(self._update_model_from_rgb) 195 | self._b_ctrl.on_change(self._update_model_from_rgb) 196 | self._h_ctrl.on_change(self._update_model_from_hsv) 197 | self._s_ctrl.on_change(self._update_model_from_hsv) 198 | self._v_ctrl.on_change(self._update_model_from_hsv) 199 | self._r_ctrl.on_key_press(partial(self._on_scale_entry_key_press, 'r')) 200 | self._g_ctrl.on_key_press(partial(self._on_scale_entry_key_press, 'g')) 201 | self._b_ctrl.on_key_press(partial(self._on_scale_entry_key_press, 'b')) 202 | 203 | # pack 204 | self._main_box.pack_start(a1, True, True, 0) 205 | self._main_box.pack_start(self._g_ctrl, True, True, 0) 206 | self._main_box.pack_start(self._b_ctrl, True, True, 0) 207 | self._main_box.pack_start(a2, True, True, 0) 208 | self._main_box.pack_start(self._s_ctrl, True, True, 0) 209 | self._main_box.pack_start(self._v_ctrl, True, True, 0) 210 | 211 | @staticmethod 212 | def _new_css_entry_hbox(label, entry): 213 | # label 214 | lbl = Gtk.Label() 215 | lbl.modify_font(Pango.FontDescription('sans-serif 8')) 216 | lbl.set_text(label) 217 | lbl.set_width_chars(4) 218 | lbl.set_alignment(0, 0.5) 219 | color = Gdk.Color(red=config.TEXT_COLOUR_R * 65535, 220 | green=config.TEXT_COLOUR_G * 65535, 221 | blue=config.TEXT_COLOUR_B * 65535) 222 | lbl.modify_fg(Gtk.StateType.NORMAL, color) 223 | 224 | # box 225 | hbox = Gtk.Box(spacing=config.MAIN_GUTTER_PX, homogeneous=False) 226 | hbox.props.valign = Gtk.Align.CENTER 227 | hbox.pack_start(lbl, False, False, 0) 228 | hbox.pack_start(entry, False, False, 0) 229 | 230 | return hbox 231 | 232 | @staticmethod 233 | def _new_bool_option_alignment(label): 234 | # option 235 | opt = Gtk.CheckButton(label=label) 236 | opt.modify_font(Pango.FontDescription('sans-serif 8')) 237 | color = Gdk.Color(red=config.TEXT_COLOUR_R * 65535, 238 | green=config.TEXT_COLOUR_G * 65535, 239 | blue=config.TEXT_COLOUR_B * 65535) 240 | opt.modify_fg(Gtk.StateType.NORMAL, color) 241 | 242 | # aligment for extra padding 243 | opt_a = Gtk.Alignment() 244 | opt_a.set_padding(0, 0, config.MAIN_GUTTER_PX, 0) 245 | opt_a.add(opt) 246 | 247 | return opt, opt_a 248 | 249 | def _init_css_entries(self): 250 | # hex entry 251 | self._css_hex_entry = CssHexEntry() 252 | self._css_hex_entry.on_change(self._update_model_from_css_hex) 253 | 254 | # RGB entry 255 | self._css_rgb_entry = CssRgbEntry() 256 | self._css_rgb_entry.on_change(self._update_model_from_css_rgb) 257 | 258 | # hboxes 259 | css_hex_hbox = MainWindow._new_css_entry_hbox('Hex:', self._css_hex_entry) 260 | css_rgb_hbox = MainWindow._new_css_entry_hbox('RGB:', self._css_rgb_entry) 261 | 262 | # add options to hex box 263 | self._css_hex_copy_hash_opt, a1 = MainWindow._new_bool_option_alignment('Copy #') 264 | self._css_hex_copy_hash_opt_toggled_handler = self._css_hex_copy_hash_opt.connect('toggled', self._on_css_hex_copy_hash_toggled) 265 | self._css_hex_lower_opt, a2 = MainWindow._new_bool_option_alignment('Lowercase') 266 | self._css_hex_lower_opt_toggled_handler = self._css_hex_lower_opt.connect('toggled', self._on_css_hex_lower_toggled) 267 | css_hex_hbox.pack_start(a1, False, False, 0) 268 | css_hex_hbox.pack_start(a2, False, False, 0) 269 | 270 | # alignment for hex box 271 | css_hex_a = Gtk.Alignment() 272 | css_hex_a.set_padding(config.MAIN_GUTTER_PX, 0, 0, 0) 273 | css_hex_a.add(css_hex_hbox) 274 | 275 | self._main_box.pack_start(css_hex_a, True, True, 0) 276 | self._main_box.pack_start(css_rgb_hbox, True, True, 0) 277 | 278 | def _init_all(self): 279 | # fav colours 280 | self._init_fav_colours() 281 | 282 | # big colour 283 | self._init_big_colour() 284 | 285 | # fine colour controls 286 | self._init_fine_colour_controls() 287 | 288 | # colour controls 289 | self._init_colour_controls() 290 | 291 | # hex 292 | self._init_css_entries() 293 | 294 | def _on_fav_colour_click(self, event, fav_colour): 295 | if event.button == 1: 296 | self._model.colour = fav_colour.colour 297 | self._update_view() 298 | elif event.button == 3: 299 | fav_colour.set_colour(self._model.colour.copy()) 300 | self._update_view() 301 | 302 | def _on_sel_change(self, sel): 303 | self._model.sel = sel 304 | self._update_view() 305 | 306 | def _on_css_hex_copy_hash_toggled(self, btn): 307 | self._update_model_from_settings() 308 | self._update_view() 309 | 310 | def _on_css_hex_lower_toggled(self, btn): 311 | self._update_model_from_settings() 312 | self._update_view() 313 | 314 | def _on_inc_light(self): 315 | self._model.colour.inc_light(self._model.fine_incr / 100) 316 | self._update_view() 317 | 318 | def _on_dec_light(self): 319 | self._model.colour.dec_light(self._model.fine_incr / 100) 320 | self._update_view() 321 | 322 | def _on_inc_sat(self): 323 | self._model.colour.inc_sat(self._model.fine_incr / 100) 324 | self._update_view() 325 | 326 | def _on_dec_sat(self): 327 | self._model.colour.dec_sat(self._model.fine_incr / 100) 328 | self._update_view() 329 | 330 | def _on_scale_entry_key_press(self, origin, key_name): 331 | if origin == key_name: 332 | return 333 | 334 | r, g, b = self._model.colour.rgb 335 | 336 | if origin == 'r': 337 | origin_value = self._r_ctrl.value 338 | elif origin == 'g': 339 | origin_value = self._g_ctrl.value 340 | elif origin == 'b': 341 | origin_value = self._b_ctrl.value 342 | 343 | if key_name == 'r': 344 | r = origin_value 345 | elif key_name == 'g': 346 | g = origin_value 347 | elif key_name == 'b': 348 | b = origin_value 349 | 350 | self._set_model_rgb(r, g, b) 351 | 352 | def _update_model_from_incr(self): 353 | incr = self._fine_controls.incr_value 354 | self._model.fine_incr = incr 355 | self._update_all_incr() 356 | 357 | def _get_rgb_ctrl_values(self): 358 | r = self._r_ctrl.value 359 | g = self._g_ctrl.value 360 | b = self._b_ctrl.value 361 | 362 | return r, g, b 363 | 364 | def _get_hsv_ctrl_values(self): 365 | h = self._h_ctrl.value 366 | s = self._s_ctrl.value 367 | v = self._v_ctrl.value 368 | 369 | return h, s, v 370 | 371 | def _enable_hsv_events(self, en): 372 | self._h_ctrl.enable_on_change(en) 373 | self._s_ctrl.enable_on_change(en) 374 | self._v_ctrl.enable_on_change(en) 375 | 376 | def _set_model_rgb(self, r, g, b): 377 | self._model.colour.set_rgb(r, g, b) 378 | self._update_view() 379 | 380 | def _update_model_from_rgb(self): 381 | r, g, b = self._get_rgb_ctrl_values() 382 | self._model.colour.set_rgb(r, g, b) 383 | self._update_view(ControlType.RGB) 384 | 385 | def _update_model_from_hsv(self): 386 | h, s, v = self._get_hsv_ctrl_values() 387 | s /= 100 388 | v /= 100 389 | self._model.colour.set_hsv(h, s, v) 390 | self._update_view(ControlType.HSV) 391 | 392 | def _update_model_from_css_hex(self): 393 | colour = self._css_hex_entry.colour 394 | self._model.colour = colour 395 | self._update_view(ControlType.CSS_HEX) 396 | 397 | def _update_model_from_css_rgb(self): 398 | colour = self._css_rgb_entry.colour 399 | self._model.colour = colour 400 | self._update_view(ControlType.CSS_RGB) 401 | 402 | def _update_model_from_settings(self): 403 | self._model.css_hex_copy_hash = self._css_hex_copy_hash_opt.get_active() 404 | self._model.css_hex_lower = self._css_hex_lower_opt.get_active() 405 | self._update_settings() 406 | 407 | def _update_big_colour(self): 408 | self._big_colour.set_colour_l(self._model.colour_l) 409 | self._big_colour.set_colour_r(self._model.colour_r) 410 | self._big_colour.set_sel(self._model.sel) 411 | 412 | def _update_rgb_ctrls(self): 413 | r, g, b = self._model.colour.rgb 414 | self._r_ctrl.set_value_no_emit(r) 415 | self._g_ctrl.set_value_no_emit(g) 416 | self._b_ctrl.set_value_no_emit(b) 417 | 418 | def _update_hsv_ctrls(self): 419 | h, s, v = self._model.colour.hsv 420 | self._h_ctrl.set_value_no_emit(h) 421 | self._s_ctrl.set_value_no_emit(s * 100) 422 | self._v_ctrl.set_value_no_emit(v * 100) 423 | 424 | def _update_css_hex(self): 425 | self._css_hex_entry.set_colour_no_emit(self._model.colour) 426 | 427 | def _update_css_rgb(self): 428 | self._css_rgb_entry.set_colour_no_emit(self._model.colour) 429 | 430 | def _update_settings(self): 431 | self._css_hex_copy_hash_opt.handler_block(self._css_hex_copy_hash_opt_toggled_handler) 432 | self._css_hex_lower_opt.handler_block(self._css_hex_lower_opt_toggled_handler) 433 | self._css_hex_copy_hash_opt.set_active(self._model.css_hex_copy_hash) 434 | self._css_hex_lower_opt.set_active(self._model.css_hex_lower) 435 | self._css_hex_copy_hash_opt.handler_unblock(self._css_hex_copy_hash_opt_toggled_handler) 436 | self._css_hex_lower_opt.handler_unblock(self._css_hex_lower_opt_toggled_handler) 437 | self._css_hex_entry.set_copy_hash(self._model.css_hex_copy_hash) 438 | self._css_hex_entry.set_lower(self._model.css_hex_lower) 439 | 440 | def _update_all_incr(self): 441 | self._r_ctrl.set_page_incr(self._model.fine_incr) 442 | self._g_ctrl.set_page_incr(self._model.fine_incr) 443 | self._b_ctrl.set_page_incr(self._model.fine_incr) 444 | self._h_ctrl.set_page_incr(self._model.fine_incr) 445 | self._s_ctrl.set_page_incr(self._model.fine_incr) 446 | self._v_ctrl.set_page_incr(self._model.fine_incr) 447 | 448 | def _update_title(self): 449 | def get_color_title(colour, sel_colour): 450 | if colour is sel_colour: 451 | fmt = '[#{}]' 452 | else: 453 | fmt = '#{}' 454 | 455 | hx = colour.hex 456 | 457 | if not self._model.css_hex_lower: 458 | hx = hx.upper() 459 | 460 | return fmt.format(hx) 461 | 462 | fmt = 'delicolour: {} {}' 463 | colour_l_title = get_color_title(self._model.colour_l, self._model.colour) 464 | colour_r_title = get_color_title(self._model.colour_r, self._model.colour) 465 | title = fmt.format(colour_l_title, colour_r_title) 466 | self.set_title(title) 467 | 468 | def _update_view(self, focused_ctrl=None): 469 | self._update_title() 470 | self._update_big_colour() 471 | 472 | if focused_ctrl != ControlType.HSV: 473 | self._update_hsv_ctrls() 474 | 475 | if focused_ctrl != ControlType.RGB: 476 | self._update_rgb_ctrls() 477 | 478 | if focused_ctrl != ControlType.CSS_HEX: 479 | self._update_css_hex() 480 | 481 | if focused_ctrl != ControlType.CSS_RGB: 482 | self._update_css_rgb() 483 | 484 | if focused_ctrl == ControlType.INIT: 485 | self._update_settings() 486 | self._update_all_incr() 487 | -------------------------------------------------------------------------------- /delicolour/res/desat-24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eepp/delicolour/9e98f4d3145d0f28901d88b1bb510d2eac3682aa/delicolour/res/desat-24.png -------------------------------------------------------------------------------- /delicolour/res/moon-24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eepp/delicolour/9e98f4d3145d0f28901d88b1bb510d2eac3682aa/delicolour/res/moon-24.png -------------------------------------------------------------------------------- /delicolour/res/sat-24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eepp/delicolour/9e98f4d3145d0f28901d88b1bb510d2eac3682aa/delicolour/res/sat-24.png -------------------------------------------------------------------------------- /delicolour/res/sun-24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eepp/delicolour/9e98f4d3145d0f28901d88b1bb510d2eac3682aa/delicolour/res/sun-24.png -------------------------------------------------------------------------------- /delicolour/scale_entry.py: -------------------------------------------------------------------------------- 1 | import re 2 | from delicolour import config 3 | from gi.repository import Gtk 4 | from gi.repository import Gdk 5 | from gi.repository import Pango 6 | 7 | 8 | _re_key_press = re.compile(r'[a-zA-Z]') 9 | 10 | 11 | class ScaleEntry(Gtk.Box): 12 | def __init__(self, label, minval, maxval, page_incr, 13 | r=config.TEXT_COLOUR_R, g=config.TEXT_COLOUR_G, 14 | b=config.TEXT_COLOUR_B, wrap=False): 15 | # asked colour 16 | color = Gdk.Color(red=r * 65535, green=g * 65535, blue=b * 65535) 17 | 18 | # parameters 19 | self._minval = minval 20 | self._maxval = maxval 21 | self._page_incr = page_incr 22 | self._wrap = wrap 23 | self._user_on_change = None 24 | self._user_on_key_press = None 25 | 26 | # label 27 | lbl = Gtk.Label() 28 | lbl.modify_font(Pango.FontDescription('sans-serif bold 8')) 29 | lbl.set_width_chars(2) 30 | lbl.set_text(label) 31 | lbl.modify_fg(Gtk.StateType.NORMAL, color) 32 | self._label = label 33 | 34 | # entry 35 | self._entry = Gtk.Entry() 36 | self._entry.set_max_length(3) 37 | self._entry.modify_font(Pango.FontDescription('monospace bold 8')) 38 | self._entry.set_width_chars(3) 39 | self._entry.set_max_width_chars(3) 40 | self._entry.set_alignment(1) 41 | self._entry.add_events(Gdk.EventMask.SCROLL_MASK | Gdk.EventMask.SMOOTH_SCROLL_MASK) 42 | self._entry.connect('insert-text', self._on_entry_insert_text) 43 | self._entry.connect('scroll-event', self._on_entry_scroll_event) 44 | self._entry.connect('key-press-event', self._on_entry_key_press) 45 | self._entry_changed_handler = self._entry.connect('changed', self._on_entry_changed) 46 | 47 | # scale 48 | adjustment = Gtk.Adjustment(0, minval, maxval, 1, page_incr, 0) 49 | self._scale = Gtk.HScale() 50 | self._scale.set_adjustment(adjustment) 51 | self._scale.set_draw_value(False) 52 | self._scale.set_min_slider_size(15) 53 | self._scale.connect('change-value', self._on_scale_change_value) 54 | self._scale.set_can_focus(False) 55 | self._scale.set_round_digits(0) 56 | self._scale.set_digits(0) 57 | 58 | # hbox 59 | super().__init__(spacing=config.MAIN_GUTTER_PX, homogeneous=False) 60 | self.set_orientation(Gtk.Orientation.HORIZONTAL) 61 | self.pack_start(lbl, False, False, 0) 62 | self.pack_start(self._scale, True, True, 0) 63 | self.pack_start(self._entry, False, False, 0) 64 | 65 | def set_page_incr(self, page_incr): 66 | self._page_incr = page_incr 67 | ajd = self._scale.get_adjustment() 68 | ajd.set_page_increment(page_incr) 69 | self._scale.set_adjustment(ajd) 70 | 71 | def _do_user_on_change(self): 72 | if self._user_on_change: 73 | self._user_on_change() 74 | 75 | def _do_user_on_key_press(self, key_name): 76 | if self._user_on_key_press: 77 | self._user_on_key_press(key_name) 78 | 79 | def _get_normalized_value(self, value): 80 | if value is None: 81 | value = self.value 82 | 83 | value = int(value) 84 | 85 | # clip? 86 | if value < self._minval: 87 | return self._minval 88 | elif value > self._maxval: 89 | return self._maxval 90 | elif value is None: 91 | return self.value 92 | else: 93 | return value 94 | 95 | def _set_scale_value_no_emit(self, value): 96 | self._scale.set_value(value) 97 | 98 | def _set_entry_value_no_emit(self, value): 99 | txt = str(round(value)) 100 | self._entry.handler_block(self._entry_changed_handler) 101 | self._entry.set_text(txt) 102 | self._entry.handler_unblock(self._entry_changed_handler) 103 | 104 | def _set_ctrl_values_no_emit(self, value): 105 | value = self._get_normalized_value(value) 106 | self._set_entry_value_no_emit(value) 107 | self._set_scale_value_no_emit(value) 108 | 109 | def set_value_no_emit(self, value): 110 | self._set_ctrl_values_no_emit(value) 111 | 112 | @property 113 | def value(self): 114 | return self._scale.get_value() 115 | 116 | def _on_entry_insert_text(self, entry, new_text, new_text_length, 117 | position): 118 | if not re.search(r'^[0-9]*$', new_text): 119 | self._entry.stop_emission('insert-text') 120 | 121 | def _on_entry_changed(self, editable): 122 | text = self._entry.get_text() 123 | 124 | if len(text) == 0: 125 | # consider nothing changed 126 | return 127 | 128 | # value 129 | next_val = self._get_normalized_value(round(float(text))) 130 | 131 | # set scale value 132 | self._set_scale_value_no_emit(next_val) 133 | 134 | # notify user 135 | self._do_user_on_change() 136 | 137 | def _on_entry_scroll_event(self, widget, ev): 138 | value = self.value 139 | y_scroll = ev.get_scroll_deltas()[2] 140 | 141 | if y_scroll < 0: 142 | value += self._page_incr 143 | elif y_scroll > 0: 144 | value -= self._page_incr 145 | 146 | # wrap? 147 | if self._wrap: 148 | value = (value % (self._maxval + 1 - self._minval)) + self._minval 149 | 150 | # set control values 151 | self._set_ctrl_values_no_emit(value) 152 | 153 | # notify user 154 | self._do_user_on_change() 155 | 156 | def _on_entry_key_press(self, widget, event): 157 | key_name = Gdk.keyval_name(event.keyval) 158 | 159 | if _re_key_press.match(key_name): 160 | self._do_user_on_key_press(key_name) 161 | 162 | def _on_scale_change_value(self, scale, scroll, value): 163 | # value 164 | value = self._get_normalized_value(value) 165 | 166 | # set scale value 167 | self._set_scale_value_no_emit(value) 168 | 169 | # set entry value 170 | self._set_entry_value_no_emit(value) 171 | 172 | # notify user 173 | self._do_user_on_change() 174 | 175 | return True 176 | 177 | def on_change(self, cb): 178 | self._user_on_change = cb 179 | 180 | def on_key_press(self, cb): 181 | self._user_on_key_press = cb 182 | 183 | def get_entry(self): 184 | return self._entry 185 | 186 | def get_scale(self): 187 | return self._scale 188 | 189 | def set_focus(self): 190 | self._entry.grab_focus() 191 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import sys 3 | from setuptools import setup 4 | 5 | 6 | # make sure we run Python 3+ here 7 | if sys.version_info.major < 3: 8 | sys.stderr.write('Sorry, eboxbw needs Python 3\n') 9 | sys.exit(1) 10 | 11 | 12 | import delicolour 13 | 14 | 15 | setup(name='delicolour', 16 | version=delicolour.__version__, 17 | description='colour finder', 18 | author='Philippe Proulx', 19 | author_email='eeppeliteloop@gmail.com', 20 | url='https://github.com/eepp/delicolour', 21 | packages=['delicolour'], 22 | package_data={ 23 | 'delicolour': [ 24 | 'res/*.png', 25 | ], 26 | }, 27 | install_requires=[ 28 | 'colormath>=3', 29 | ], 30 | entry_points={ 31 | 'gui_scripts': [ 32 | 'delicolour = delicolour.main:run' 33 | ] 34 | }) 35 | --------------------------------------------------------------------------------