Commit Graph

345 Commits

Author SHA1 Message Date
Isaiah Odhner
b7d14f02bd Add an empty status bar 2023-04-23 22:22:28 -04:00
Isaiah Odhner
eb3b93d454 Require both clicks to be on the same button for a double click 2023-04-23 21:51:44 -04:00
Isaiah Odhner
8136383bca Return to previous tool after using Magnifier or Pick Color tool 2023-04-23 19:51:12 -04:00
Isaiah Odhner
70cb60218f Close menus if clicking outside the menus 2023-04-23 19:42:49 -04:00
Isaiah Odhner
fc35e34153 Use Binding(...) for all bindings, for easy access to priority/show args 2023-04-23 17:22:12 -04:00
Isaiah Odhner
d411b84605 Fix CharInput blocking Ctrl+A, Ctrl+W, etc. 2023-04-23 17:20:08 -04:00
Isaiah Odhner
cde031f70d Restore Ctrl+C to quit (for now) 2023-04-23 15:42:12 -04:00
Isaiah Odhner
138776456d Combine bindings, using comma separation 2023-04-23 15:41:41 -04:00
Isaiah Odhner
286852616b Remove meta+q binding for Quit
I was going to include meta as an alternative for all shortcuts, for
macOS, but I don't know if this works, and it's a little silly having
just one shortcut with meta like this.
2023-04-23 15:41:41 -04:00
Isaiah Odhner
0e1e43a67b Enable bindings for unimplemented actions
Might as well show the "Not implemented" dialog for keyboard shortcuts.
2023-04-23 15:02:50 -04:00
Isaiah Odhner
f93a884e74 Update the palette when double clicking to edit a color 2023-04-23 14:58:17 -04:00
Isaiah Odhner
1b76caa23e Fix double click detection in color palette
Duh, just use the button press handler.
2023-04-23 14:36:05 -04:00
Isaiah Odhner
22547da2b2 Start making Edit Colors dialog
It's just a larger palette so far.
2023-04-23 14:29:51 -04:00
Isaiah Odhner
e76ce9e721 Fix out of bounds array access for Pick Color tool 2023-04-23 13:50:41 -04:00
Isaiah Odhner
f950c9964b Stamp the selection with Ctrl 2023-04-23 02:14:28 -04:00
Isaiah Odhner
4dc7bc08d6 Make paint.py executable 2023-04-23 01:46:49 -04:00
Isaiah Odhner
031a0a3e72 Implement Select All 2023-04-23 01:24:43 -04:00
Isaiah Odhner
f106cc5c35 Gray out unimplemented menu items 2023-04-23 00:51:29 -04:00
Isaiah Odhner
dbce1434cd Constrain selection so it doesn't go completely outside the document bounds 2023-04-23 00:11:17 -04:00
Isaiah Odhner
cb0db3b6e6 Deselect when clicking outside the canvas 2023-04-23 00:01:57 -04:00
Isaiah Odhner
49bd80b17a Fix out of bounds array access for Free-Form Select 2023-04-22 23:51:12 -04:00
Isaiah Odhner
74dceee2f3 Implement Free-Form Select tool 2023-04-22 23:03:09 -04:00
Isaiah Odhner
42fdbe83d7 Fix unused parameter to erase_region
Why wasn't this reported?
2023-04-22 21:57:58 -04:00
Isaiah Odhner
5d778c1879 Annotate **kwargs as Any 2023-04-22 21:44:05 -04:00
Isaiah Odhner
625324e66b Fix BorderDefinition typing 2023-04-22 21:11:47 -04:00
Isaiah Odhner
2d88529bc0 Guess at how to typecheck this parametric event type 2023-04-22 21:08:38 -04:00
Isaiah Odhner
2c8f79e37a Shorten code and help the type checker understand that this isn't None
dhooo short
2023-04-22 21:08:38 -04:00
Isaiah Odhner
3d419f13b3 Remove unused NAME_MAP code from calculator example 2023-04-22 20:53:13 -04:00
Isaiah Odhner
9f06373cb7 Add a bunch more type checking hints/assertions 2023-04-22 20:51:51 -04:00
Isaiah Odhner
2c8d74808a Add a whole bunch more type checking 2023-04-22 18:54:21 -04:00
Isaiah Odhner
2e839b2564 Clean up unused imports 2023-04-22 17:49:15 -04:00
Isaiah Odhner
a8f174eb8e Fix the last type checking error, and simply --reload-on-changes
Hopefully this makes it more robust as well...
2023-04-22 17:29:41 -04:00
Isaiah Odhner
2827457497 Fix default document size
Broken in "Start type checking code" 1b56d78f70
2023-04-22 14:55:22 -04:00
Isaiah Odhner
da62add6c1 Avoid "possibly unbound" errors 2023-04-22 14:24:49 -04:00
Isaiah Odhner
3b2b383595 Assert a few more specific types 2023-04-22 14:24:49 -04:00
Isaiah Odhner
7cd44c0abe Ignore border_title
I found these "type: ignore" comments where border_title is defined,
and copied 'em!
2023-04-22 13:46:02 -04:00
Isaiah Odhner
27c9646b20 DRY window closing and make type checker happy with an assertion 2023-04-22 13:46:02 -04:00
Isaiah Odhner
065c5be2cb Appease the type checker by using maps of buttons 2023-04-22 13:46:02 -04:00
Isaiah Odhner
77295bd622 Int, innit? Init int 2023-04-22 13:11:23 -04:00
Isaiah Odhner
f7b68c7e7a Now do we enter the land of making code worse for the type checker's benefit? 2023-04-22 02:42:20 -04:00
Isaiah Odhner
1b56d78f70 Start type checking code 2023-04-22 02:31:58 -04:00
Isaiah Odhner
27c95a537c Make mouse_at_start an Offset (consistently)
It was already initially defined as an Offset.
2023-04-22 01:12:48 -04:00
Isaiah Odhner
45fb2eb521 Implement polygon tool 2023-04-22 01:07:20 -04:00
Isaiah Odhner
2c469a5ef3 Draw curve preview also on mouse up and mouse down events
It feels more solid now, but it still disappears if the mouse leaves the canvas.
2023-04-21 23:52:23 -04:00
Isaiah Odhner
4f99b9f6a7 Make eraser tool square
I also have an erase_region method I could use now, alternatively.
2023-04-21 23:45:04 -04:00
Isaiah Odhner
6ce1856ec7 Fix brush/pencil/eraser previews 2023-04-21 23:40:48 -04:00
Isaiah Odhner
55e6ed6caf DRY some curve tool preview stuff 2023-04-21 23:38:11 -04:00
Isaiah Odhner
4d86f783be Implement Curve tool 2023-04-21 23:16:58 -04:00
Isaiah Odhner
18b78cea03 Outside the Ministry of Silly Walks's jurisdiction, it's a squaredance. 2023-04-21 23:16:58 -04:00
Isaiah Odhner
cc0bdf0973 Implement Text tool 2023-04-21 22:12:16 -04:00
Isaiah Odhner
7442480979 Optimize/abbreviate repeated integer division by the magnification level 2023-04-21 20:49:41 -04:00
Isaiah Odhner
d602753117 Refactor get_select_region 2023-04-21 20:18:58 -04:00
Isaiah Odhner
d39f491233 Fix selection while zoomed in 2023-04-21 19:45:01 -04:00
Isaiah Odhner
37cdcdfb13 Implement View > Zoom > Custom Zoom 2023-04-21 19:30:37 -04:00
Isaiah Odhner
cbe40406a6 Fix selection region changing on mouse up
It may be wrong (sometimes), but it shouldn't change (on mouse up)!
That's something (not nothing)!
2023-04-21 19:04:50 -04:00
Isaiah Odhner
5b2e4e0f83 Make warning into an assertion 2023-04-21 18:39:18 -04:00
Isaiah Odhner
612bc3d204 Fix: refresh properly when finishing a selection 2023-04-21 18:35:41 -04:00
Isaiah Odhner
c5c9bd9425 Fix dragging selection a second time: Don't replace image data! 2023-04-21 18:25:45 -04:00
Isaiah Odhner
e98931e8ef Implement Edit > Clear Selection (Delete) 2023-04-21 16:45:20 -04:00
Isaiah Odhner
61d3db4714 Fix undo/redo handling for the Select tool 2023-04-21 16:34:38 -04:00
Isaiah Odhner
1eea87c6c9 Fix error if dragging from off the canvas and releasing mouse over it 2023-04-21 16:07:43 -04:00
Isaiah Odhner
e579b005c0 Note difference between tool.name and tool.get_name() 2023-04-21 16:04:33 -04:00
Isaiah Odhner
9932a84554 And the selection tool is working! 2023-04-21 16:04:33 -04:00
Isaiah Odhner
c6873cdde7 Now it feels like progress... 2023-04-21 15:31:38 -04:00
Isaiah Odhner
bbdfa794fc I feel like I made it worse... 2023-04-21 15:24:45 -04:00
Isaiah Odhner
c3280d20d0 WIP: selection tool 2023-04-21 15:05:41 -04:00
Isaiah Odhner
1d8dec4ba4 Implement selection tool preview 2023-04-21 13:11:39 -04:00
Isaiah Odhner
f69f2f0009 Use messages for selecting tools/colors/characters
It's more code, but hopefully separating concerns will be worth it.
2023-04-21 12:26:07 -04:00
Isaiah Odhner
cf9eb652a0 Fix incorrect (irrelevant) docstring
copy/pasted or AI autocompleted
2023-04-21 12:15:11 -04:00
Isaiah Odhner
8040196f10 WIP: simplify hiding/showing Tools box and Colors box
This works for the ColorsBox, since it's the second element,
but not for the ToolsBox, since it's the first.
2023-04-21 11:45:10 -04:00
Isaiah Odhner
04a99f8a1d Remove type check param from query(); it's only allowed on query_one() 2023-04-21 11:38:20 -04:00
Isaiah Odhner
502a68209d Add type check parameters to DOM queries 2023-04-21 11:35:39 -04:00
Isaiah Odhner
41f192a4d3 Separate foreground/background color selection state
- This works differently to MS Paint. Instead of a color for clearing
  (and for the inside of shapes) and a color for brushing (and the
  outline of shapes), here there's a background and text color for each
  cell, collectively treated like the foreground color in MS Paint.
- There's no way to select a foreground color yet other than opening
  an image and using the color picker.
2023-04-21 11:25:22 -04:00
Isaiah Odhner
43d213fe46 Rename palette selection area elements 2023-04-21 11:04:30 -04:00
Isaiah Odhner
68d069fa8d Implement View > Zoom > Large Size / Normal Size 2023-04-21 01:40:26 -04:00
Isaiah Odhner
8e82203bb5 Note another attempt at fixing flickering when using the magnifier tool
I tried `refresh(layout=True, repaint=False)` before `_scroll_to`, but no luck.
2023-04-21 00:05:01 -04:00
Isaiah Odhner
51767d05c8 Use a shared class .filename_input 2023-04-20 23:41:59 -04:00
Isaiah Odhner
0f4a154eda Use straightforward properties instead of storing information in IDs
Sure, I'm tacking on these properties, but it's better to tack onto
objects than to tack onto strings. I'm not using a type checker yet,
but this is a better situation for type checking. (I could extend Button
with mini classes within ToolsBox and ColorsBox, if need be, to give
clear ownership of these properties.)
2023-04-20 23:31:29 -04:00
Isaiah Odhner
24076d9af5 Disable focusing tool and color buttons 2023-04-20 23:05:59 -04:00
Isaiah Odhner
1f260aaeef Refactor empty filename handling in Save As to use a negative condition 2023-04-20 22:41:45 -04:00
Isaiah Odhner
a23eeaf1dd Fix handling empty filename input in Open
I added the filename = os.path.join(...) which invalidated the positive
filename check. I could move the check earlier, but a negative check
should do nicely.

This commit is mostly a dedent, though git may display the diff poorly
due to the shared line window.close()
2023-04-20 22:38:55 -04:00
Isaiah Odhner
2ee021e236 Move expand_directory_tree logic into an EnhancedDirectoryTree class 2023-04-20 22:23:06 -04:00
Isaiah Odhner
9d4cccfe6e Fix type annotation for on_tree_node_highlighted 2023-04-20 22:20:20 -04:00
Isaiah Odhner
15af8f6403 Fix warning icon visibility after the first display
It gets set to `display = False` when unmounting, I think.
2023-04-20 21:01:33 -04:00
Isaiah Odhner
986db57e17 Improve layout inspector with built in css_identifier_styled
It now shows [name=...] if applicable, and styles each part differently.
And it's less code!
2023-04-20 21:01:32 -04:00
Isaiah Odhner
48f0303a54 Refactor create_warning_message_box into MessageBox 2023-04-20 21:01:14 -04:00
Isaiah Odhner
093a314d60 Move bits of warning_message_box that need App back into App 2023-04-20 18:09:49 -04:00
Isaiah Odhner
37ff810616 Move warning_message_box implementation to windows.py 2023-04-20 18:02:07 -04:00
Isaiah Odhner
5e72708fd8 Rename Python class for character selector dialog for consistency
If I want it to be less verbose, I should rename the super-class
from "DialogWindow" to just "Dialog".
2023-04-20 17:42:17 -04:00
Isaiah Odhner
9b3793682d Fix inconsistent CSS ID naming style
I've settled on underscores, for now at least.
Generally I use hyphens.
Built-ins actually use hyphens, like `.-dark-mode`.
Maybe I should be using hyphens.
But for now, consistency is what's important, and I'm using underscores.
2023-04-20 17:26:41 -04:00
Isaiah Odhner
433fa68a21 Refactor anti-garbage-collection Task reference keeping
Now it's really verbose, but I don't have to worry about reusing
the same name twice. Or coming up with new, fun ones.

https://docs.python.org/3/library/asyncio-task.html#asyncio.create_task

> Important: Save a reference to the result of this function, to avoid a task disappearing mid-execution. The event loop only keeps weak references to tasks. A task that isn’t referenced elsewhere may get garbage collected at any time, even before it’s done. For reliable “fire-and-forget” background tasks, gather them in a collection:
>
> background_tasks = set()
>
> for i in range(10):
>     task = asyncio.create_task(some_coro(param=i))
>
>     # Add task to the set. This creates a strong reference.
>     background_tasks.add(task)
>
>     # To prevent keeping references to finished tasks forever,
>     # make each task remove its own reference from the set after
>     # completion:
>     task.add_done_callback(background_tasks.discard)
2023-04-20 17:18:55 -04:00
Isaiah Odhner
2a2b29e30e Use a shared CSS class for styling Open/Save As dialogs 2023-04-20 16:47:11 -04:00
Isaiah Odhner
5b20caf118 Add basic help window 2023-04-20 16:27:46 -04:00
Isaiah Odhner
3235ebcf26 Implement About Paint dialog 2023-04-20 16:27:41 -04:00
Isaiah Odhner
a33dd153ce I tried to fix flickering when using magnifier tool
- Move `self.canvas.magnification = self.magnification` up. It happens,
  due to internal call_after_refresh, and should happen, before scroll.
- Remove note about other code in JS Paint, I think it's not needed.
- Note my attempts at fixing flicker, which were unsuccessful, so that
  I don't try the exact same things later, and feel stupid,
  and so I don't accrue so many branches.
2023-04-20 15:39:33 -04:00
Isaiah Odhner
896f43e7ed Fix one canvas refresh not using magnification 2023-04-20 15:13:14 -04:00
Isaiah Odhner
1740e39301 Fix canvas size not updating
I actually added this before, and then thought it wasn't needed for some reason.
2023-04-20 14:54:20 -04:00
Isaiah Odhner
56ad762819 Fix mismatch between file opening behavior of Open dialog vs CLI arg 2023-04-20 14:51:06 -04:00
Isaiah Odhner
c3763523bd Visually debug IndexError...
The canvas size isn't getting updated (fully) when loading a document.
2023-04-20 14:45:11 -04:00
Isaiah Odhner
5958ba348b OK maybe this isn't so robust... 2023-04-20 14:42:51 -04:00
Isaiah Odhner
51c370dc24 Instead of clearing, prevent filling filename input in Open dialog
Prevent the filename input from being populated in the first place,
instead of resetting after its unintentionally populated when the
directory tree is expanded.

Nip it in the bud. Head it off at the pass. Stop it at the source.

It still needs this new flag to be cleared on a timer, but at least this
timer is near the code for the other timers it needs to trigger after.

Explicitly set filename for Save As dialog, which SHOULD be populated.
2023-04-20 14:42:51 -04:00
Isaiah Odhner
801c147d4c Clear filename input in Open dialog, which gets set unintentionally 2023-04-20 13:00:05 -04:00
Isaiah Odhner
ec4d044f8a Handle FileNotFoundError coming from os.path.samefile 2023-04-20 12:08:03 -04:00
Isaiah Odhner
61d1532552 Prevent multiple character selector dialogs from opening at once 2023-04-20 11:54:42 -04:00
Isaiah Odhner
74c4af1a5b Refactor meta character mapping to use match 2023-04-20 01:26:00 -04:00
Isaiah Odhner
7cdb35a4ae Start defining an enlarged view for certain characters 2023-04-20 01:25:43 -04:00
Isaiah Odhner
b955aaf361 Input or pick character to draw with 2023-04-20 01:21:06 -04:00
Isaiah Odhner
8727ed27de Use .dialog_window, already specified in one place, instead of .dialog, scattered about 2023-04-20 00:28:45 -04:00
Isaiah Odhner
29bc94efbc Ignore RuntimeError "cannot join current thread" 2023-04-19 21:45:18 -04:00
Isaiah Odhner
ac10d5e500 Tweak error messages to use colons for clarity 2023-04-19 21:34:29 -04:00
Isaiah Odhner
c659418240 Clean up attempt at more optimal color inverting
I don't want to bother importing Rich's Color class in addition to
Textual's Color class.

This also doesn't work, which might be the fastest if it worked:

    style.color.triplet.red = 255 - style.color.triplet.red
    style.color.triplet.green = 255 - style.color.triplet.green
    style.color.triplet.blue = 255 - style.color.triplet.blue
    style.bgcolor.triplet.red = 255 - style.bgcolor.triplet.red
    style.bgcolor.triplet.green = 255 - style.bgcolor.triplet.green
    style.bgcolor.triplet.blue = 255 - style.bgcolor.triplet.blue
2023-04-19 21:20:10 -04:00
Isaiah Odhner
bf16e60509 Clean up old magnifier preview approach 2023-04-19 21:14:07 -04:00
Isaiah Odhner
bd8ebad377 Implement magnifier preview 2023-04-19 21:08:59 -04:00
Isaiah Odhner
0026c06268 Fix inconsistent indentation 2023-04-19 19:58:07 -04:00
Isaiah Odhner
9120d49546 Implement the magnifier tool 2023-04-19 19:44:57 -04:00
Isaiah Odhner
ad6d799db9 Note reset command to recover from bad terminal state 2023-04-19 19:09:02 -04:00
Isaiah Odhner
dd5e646dfe Prompt to save changes before reloading program 2023-04-19 16:00:43 -04:00
Isaiah Odhner
509618c1be Try to clean up the file change observer when restarting
This is all theoretical.
2023-04-19 15:19:27 -04:00
Isaiah Odhner
140ff15ff1 Restart the app on changes 2023-04-19 14:27:12 -04:00
Isaiah Odhner
7b0eaff108 Reload the app with F2, not F4
I'm dumb, I forgot the app uses F4.
2023-04-19 02:45:55 -04:00
Isaiah Odhner
dfa4212548 Fix terminal state after reloading and exiting 2023-04-19 02:23:29 -04:00
Isaiah Odhner
f4075282ce Reload the app with F4 2023-04-19 02:08:01 -04:00
Isaiah Odhner
655d42e414 Change shortcut label for exiting
Alt+F4 is handled by the window manager, we can't handle it.
2023-04-19 00:37:59 -04:00
Isaiah Odhner
4cbafea3cb Show accelerators/shortcuts in menus 2023-04-18 23:34:05 -04:00
Isaiah Odhner
1659f2d75b Improve error handling for saving files 2023-04-18 18:56:29 -04:00
Isaiah Odhner
b8c7e0eb72 Add all of the menu items from MS Paint 2023-04-18 18:56:29 -04:00
Isaiah Odhner
ac8c3819cf Some things aren't translated yet 2023-04-18 18:55:45 -04:00
Isaiah Odhner
c5f7c9f387 Rename "Rectangular Select" to "Select" to match MS Paint and for localization 2023-04-18 18:55:45 -04:00
Isaiah Odhner
f1a4b9736e Improve error handling for saving and loading files 2023-04-18 18:55:45 -04:00
Isaiah Odhner
fcf44a8b94 Handle errors when saving a file 2023-04-18 18:55:44 -04:00
Isaiah Odhner
e715a28e59 Fix error when hitting OK button with no callback 2023-04-18 04:04:46 -04:00
Isaiah Odhner
8c4a5bf583 Handle errors when opening a file 2023-04-18 04:04:46 -04:00
Isaiah Odhner
2d3f05ff12 Rename "Redo" to "Repeat" to match MS Paint and for localization 2023-04-18 03:48:47 -04:00
Isaiah Odhner
a9fd9d090c Enable localization! 2023-04-18 03:31:47 -04:00
Isaiah Odhner
5e994fbc91 Move command line argument parsing to the top
This will make it possible to load localization data for a language
defined by a command-line argument, throughout the program.

Unfortunately this separates the usage of the arguments from their
definitions by a wide margin, making it harder to edit, especially
with AI autocomplete. For now. I could refactor things, either move
the bulk of this file to separate files, or define a configure_app
function up top to use down below.
2023-04-18 03:31:47 -04:00
Isaiah Odhner
8971122581 Wrap strings in _() function for localization 2023-04-18 03:31:47 -04:00
Isaiah Odhner
973f67240d WIP: i18n
Giving up on the python translation of the RC file parsing and pre-processing for now, in favor of simply parsing the JS files already generated, which is a much simpler task.
2023-04-18 03:31:47 -04:00
Isaiah Odhner
baf804f2b1 Fix: use title argument in warning_message_box 2023-04-18 03:08:58 -04:00
Isaiah Odhner
b4468d3a76 Update some comments about ANSI I/O 2023-04-18 02:55:11 -04:00
Isaiah Odhner
87f8faf956 Use choices option for expressing --theme 2023-04-18 01:06:45 -04:00
Isaiah Odhner
6fbcbf9ec3 Refactor ync flag to button_types argument, to support OK-only dialogs 2023-04-17 23:32:20 -04:00
Isaiah Odhner
d950295df7 Simply close the Open dialog if you select the open file 2023-04-17 23:09:13 -04:00
Isaiah Odhner
8ec24a8fdc Prompt to save changes when unloading a document
- Confirm discarding changes for Open, New, or Exit, including for
  exit via Ctrl+C which was previously handled by a built-in binding.
- Await Save As dialog closing, including when Save triggers Save As.
  This is my first time using asynchronous features in Python,
  (as far as I remember,) so it's a bit messy.
- Make DialogWindow callback also for Cancel, which means all
  DialogWindow usage sites care what button is selected.
- Send RequestClose event for Esc key.
2023-04-17 23:09:13 -04:00
Isaiah Odhner
0125374bba Ctrl+MMB to colorize without adding borders to inspect layout without modifying it 2023-04-17 03:12:30 -04:00
Isaiah Odhner
4ee5efe85c Make a filled Unicode warning icon with a border 2023-04-17 03:12:30 -04:00
Isaiah Odhner
a948d7d945 Note parallelogram candidates for eraser icon 2023-04-17 01:57:27 -04:00
Isaiah Odhner
22a251276b Use Unicode for warning icon text art 2023-04-17 01:45:20 -04:00
Isaiah Odhner
5c289e05a8 Add dev helper to inspect layout 2023-04-17 01:21:19 -04:00
Isaiah Odhner
357b68d624 Show file name only, not full path, in Header 2023-04-16 21:12:44 -04:00
Isaiah Odhner
728b4c53b9 Fix Open/Save As dialog starting location when file opened with relative path
The directory tree wasn't expanded because it was searching for e.g.
LICENSE.txt at the root of the filesystem (or perhaps AS the root?)
2023-04-16 21:12:03 -04:00