notesmgr 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. notesmgr/__init__.py +5 -0
  2. notesmgr/__main__.py +10 -0
  3. notesmgr/actions.py +86 -0
  4. notesmgr/application.py +93 -0
  5. notesmgr/button_row.py +149 -0
  6. notesmgr/clipboard_linux.py +58 -0
  7. notesmgr/clipboard_macos.py +78 -0
  8. notesmgr/clipboard_tool.py +84 -0
  9. notesmgr/clipboard_windows.py +198 -0
  10. notesmgr/cmd_line.py +63 -0
  11. notesmgr/commands.py +307 -0
  12. notesmgr/config.py +152 -0
  13. notesmgr/config_defaults.py +41 -0
  14. notesmgr/config_editor.py +62 -0
  15. notesmgr/config_files.py +147 -0
  16. notesmgr/console.py +62 -0
  17. notesmgr/descriptions.py +27 -0
  18. notesmgr/dialogs.py +389 -0
  19. notesmgr/editor_command.py +138 -0
  20. notesmgr/errors.py +14 -0
  21. notesmgr/explorer_drag.py +222 -0
  22. notesmgr/explorer_drop.py +195 -0
  23. notesmgr/explorer_font.py +81 -0
  24. notesmgr/explorer_tree.py +148 -0
  25. notesmgr/failure_report.py +92 -0
  26. notesmgr/file_watch.py +115 -0
  27. notesmgr/folder_ops.py +173 -0
  28. notesmgr/main_window.py +474 -0
  29. notesmgr/markdown_render.py +78 -0
  30. notesmgr/menu_bar.py +114 -0
  31. notesmgr/note_blocks.py +511 -0
  32. notesmgr/note_file.py +203 -0
  33. notesmgr/note_fonts.py +189 -0
  34. notesmgr/note_image.py +75 -0
  35. notesmgr/note_ops.py +316 -0
  36. notesmgr/note_panel.py +227 -0
  37. notesmgr/note_table.py +145 -0
  38. notesmgr/note_tags.py +241 -0
  39. notesmgr/note_text.py +62 -0
  40. notesmgr/note_view.py +273 -0
  41. notesmgr/order_file.py +150 -0
  42. notesmgr/project.py +168 -0
  43. notesmgr/project_ops.py +302 -0
  44. notesmgr/py.typed +0 -0
  45. notesmgr/rich_clipboard.py +107 -0
  46. notesmgr/session.py +71 -0
  47. notesmgr/shortcuts.py +131 -0
  48. notesmgr/trash.py +31 -0
  49. notesmgr/version_info.py +78 -0
  50. notesmgr-0.1.0.dist-info/METADATA +299 -0
  51. notesmgr-0.1.0.dist-info/RECORD +55 -0
  52. notesmgr-0.1.0.dist-info/WHEEL +5 -0
  53. notesmgr-0.1.0.dist-info/entry_points.txt +2 -0
  54. notesmgr-0.1.0.dist-info/licenses/LICENSE.txt +22 -0
  55. notesmgr-0.1.0.dist-info/top_level.txt +1 -0
notesmgr/config.py ADDED
@@ -0,0 +1,152 @@
1
+ #! /usr/local/bin/python3
2
+ """The configuration of notesmgr and the values it accepts."""
3
+
4
+ # Copyright (c) 2026 Tom Björkholm
5
+ # MIT License
6
+
7
+ import sys
8
+ from enum import StrEnum
9
+ from typing import Optional, TextIO
10
+ from config_as_json import CallingMemberValidator, Config, ConfigPath, \
11
+ IntFloatValidator, InvalidConfiguration, MemberValidationStep, \
12
+ ParseConverter, PathOrStr, ReadOldConfiguration, ValidationPlan, \
13
+ ValueTypeValidator
14
+ from notesmgr.config_defaults import default_editor
15
+
16
+ EMPTY_EDITOR = 'The editor command must name a program to start.'
17
+ """What is said about an editor command that holds no command."""
18
+
19
+
20
+ class NoteExtension(StrEnum):
21
+ """Note file extension: MD is .md, TXT is .txt, MD_TXT is .md.txt.
22
+
23
+ The configuration file holds the name of one of these members,
24
+ while the value of the member is the extension itself. MD_TXT is
25
+ the default, because many systems do not recognize .md as a safe
26
+ file type.
27
+ """
28
+
29
+ MD = '.md'
30
+ TXT = '.txt'
31
+ MD_TXT = '.md.txt'
32
+
33
+
34
+ DEFAULT_EXTENSION = NoteExtension.MD_TXT
35
+ """Note file extension that a new configuration starts out with."""
36
+
37
+ DEFAULT_NOTE_SIZE = 25000
38
+ """Characters of a note that are shown when nothing else is said."""
39
+
40
+ MIN_NOTE_SIZE = 2000
41
+ """Fewest characters of a note that may be asked to be shown.
42
+
43
+ A note is meant to be read whole, so a limit small enough to cut a
44
+ short note in two is taken for a misunderstanding rather than a wish.
45
+ """
46
+
47
+ MAX_NOTE_SIZE = 100000
48
+ """Most characters of a note that may be asked to be shown.
49
+
50
+ Reading a note is meant to stay quick, and a window that has to draw
51
+ far more than this is no longer a notes manager to work in.
52
+ """
53
+
54
+
55
+ class OldNotesmgrConfig(ReadOldConfiguration):
56
+ """How a configuration file of an older notesmgr is read.
57
+
58
+ Every member of the configuration has to be named in the file,
59
+ so a file written before a member existed is read with the
60
+ built-in default of that member rather than being refused.
61
+ """
62
+
63
+ def get_missing_path_values(self) -> dict[ConfigPath, object]:
64
+ """Add configuration parameter for things missing in old files.
65
+
66
+ This is only relevant for configuration parameters that
67
+ have been added after the first **released** version of notesmgr.
68
+ """
69
+ return {}
70
+
71
+
72
+ class NotesmgrConfig(Config):
73
+ """How notesmgr edits the notes of a project and what it names them.
74
+
75
+ The editor command is started whenever a note is edited, the
76
+ extension is the one that new notes are given and that a file must
77
+ have to be a note at all, and the size is how much of a note is
78
+ shown before the rest of it is left out.
79
+ """
80
+
81
+ def __init__(self, from_json_data_text: Optional[str] = None,
82
+ from_json_filename: Optional[PathOrStr] = None,
83
+ stderr_file: TextIO = sys.stderr,
84
+ member_name: Optional[str] = None) -> None:
85
+ """Construct the configuration with its default values.
86
+
87
+ Args:
88
+ from_json_data_text: Optional JSON text to parse directly.
89
+ from_json_filename: Optional path to a JSON file to read.
90
+ stderr_file: Stream used for user-facing diagnostics.
91
+ member_name: Path for reaching this object from the top
92
+ level configuration, None for the top level itself.
93
+ """
94
+ self.editor: str = default_editor()
95
+ self.file_extension: NoteExtension = DEFAULT_EXTENSION
96
+ self.max_note_size: int = DEFAULT_NOTE_SIZE
97
+ super().__init__(from_json_data_text=from_json_data_text,
98
+ from_json_filename=from_json_filename,
99
+ stderr_file=stderr_file, member_name=member_name)
100
+
101
+ def _get_read_old_config(self) -> ReadOldConfiguration:
102
+ """Return how a file of an older notesmgr is read."""
103
+ return OldNotesmgrConfig()
104
+
105
+ def parse_converters(self) -> dict[str, ParseConverter]:
106
+ """Return how the name in the file becomes an extension again.
107
+
108
+ Declaring it is also what lets the configuration editor offer
109
+ the extensions to be chosen instead of to be spelled.
110
+ """
111
+ return {'file_extension': Config.get_converter_dict(NoteExtension)}
112
+
113
+ def get_validation_plan(self, stderr_file: TextIO) -> ValidationPlan:
114
+ """Return the checks that every configuration has to pass."""
115
+ _ = stderr_file
116
+ is_text = ValueTypeValidator(str)
117
+ is_extension = ValueTypeValidator(NoteExtension)
118
+ is_command = CallingMemberValidator(method_name='stripped_editor',
119
+ arg_name_value='value',
120
+ normalizing=True)
121
+ is_whole = ValueTypeValidator(int, not_allowed_type=bool)
122
+ in_range = IntFloatValidator(min_value=MIN_NOTE_SIZE,
123
+ max_value=MAX_NOTE_SIZE,
124
+ allowed_values=None)
125
+ return [MemberValidationStep(member_names=['editor'],
126
+ validator=is_text),
127
+ MemberValidationStep(member_names=['editor'],
128
+ validator=is_command),
129
+ MemberValidationStep(member_names=['file_extension'],
130
+ validator=is_extension),
131
+ MemberValidationStep(member_names=['max_note_size'],
132
+ validator=is_whole),
133
+ MemberValidationStep(member_names=['max_note_size'],
134
+ validator=in_range)]
135
+
136
+ def stripped_editor(self, value: object) -> str:
137
+ """Return the editor command without the blanks around it.
138
+
139
+ Args:
140
+ value: The editor command as it was read or typed.
141
+
142
+ Returns:
143
+ The same command with no leading or trailing blanks.
144
+
145
+ Raises:
146
+ InvalidConfiguration: Nothing but blanks was given.
147
+ """
148
+ assert isinstance(value, str)
149
+ command = value.strip()
150
+ if not command:
151
+ raise InvalidConfiguration(EMPTY_EDITOR)
152
+ return command
@@ -0,0 +1,41 @@
1
+ #! /usr/local/bin/python3
2
+ """The values a notesmgr configuration starts out with."""
3
+
4
+ # Copyright (c) 2026 Tom Björkholm
5
+ # MIT License
6
+
7
+ import os
8
+ import shutil
9
+ import sys
10
+
11
+ VISUAL_CODE = 'code'
12
+ """Command that starts Microsoft Visual Studio Code."""
13
+
14
+ VISUAL_CODE_FLAG = ' -n'
15
+ """Flag to open a new window in Microsoft Visual Studio Code."""
16
+
17
+ EDITOR_VARIABLE = 'EDITOR'
18
+ """Environment variable in which a user names a preferred editor."""
19
+
20
+ PLATFORM_EDITORS = {'darwin': 'open', 'win32': 'notepad'}
21
+ """Editor command of the platforms that are known to have one."""
22
+
23
+ OTHER_EDITOR = 'emacs'
24
+ """Editor command used on a platform that is not known here."""
25
+
26
+
27
+ def default_editor() -> str:
28
+ """Return the editor command a new configuration starts out with.
29
+
30
+ Microsoft Visual Studio Code is taken when it is installed, then
31
+ the editor the user has named in the environment, and after that
32
+ whatever the running platform is known to have. A variable that
33
+ holds nothing but blanks names no editor and is passed over.
34
+
35
+ The command carries no arguments, because the name of the note
36
+ file is appended to a command that does not place it itself.
37
+ """
38
+ if shutil.which(VISUAL_CODE) is not None:
39
+ return VISUAL_CODE + VISUAL_CODE_FLAG
40
+ named = os.environ.get(EDITOR_VARIABLE, '').strip()
41
+ return named or PLATFORM_EDITORS.get(sys.platform, OTHER_EDITOR)
@@ -0,0 +1,62 @@
1
+ #! /usr/local/bin/python3
2
+ """Opening the editor of the notesmgr configuration."""
3
+
4
+ # Copyright (c) 2026 Tom Björkholm
5
+ # MIT License
6
+
7
+ import tkinter
8
+ from pathlib import Path
9
+ from typing import Callable, Optional
10
+ from edit_cfg_json_tk import TkEditorPanel
11
+ from notesmgr.config import NotesmgrConfig
12
+ from notesmgr.config_files import user_config_path, user_config_source
13
+ from notesmgr.descriptions import DESCRIPTIONS
14
+
15
+
16
+ def editor_files(config_file: Optional[Path]) -> tuple[Optional[Path], Path]:
17
+ """Return the files that the configuration editor reads and writes.
18
+
19
+ The configuration of a project is read and written in the one
20
+ place it lives. The user wide configuration is read where there is
21
+ one and started from the built-in defaults where there is not,
22
+ while it is written to the file the user asked for either way.
23
+
24
+ Args:
25
+ config_file: The configuration file of the open project, None
26
+ when no project is open.
27
+
28
+ Returns:
29
+ The file to read, None for the built-in defaults, and the file
30
+ to write.
31
+ """
32
+ if config_file is None:
33
+ return user_config_source(), user_config_path()
34
+ return config_file, config_file
35
+
36
+
37
+ def open_config_editor(parent: tkinter.Misc, on_close: Callable[[], None],
38
+ config_file: Optional[Path] = None) -> TkEditorPanel:
39
+ """Open an editor of the configuration in use, over a window.
40
+
41
+ The application owns a Tk main loop already, and a second one
42
+ would be a second Tcl interpreter that no widget of the first can
43
+ reach, so the editor is a panel over the main window rather than
44
+ one of the entry points that own a main loop themselves. It
45
+ returns at once, and on_close says that the session has ended.
46
+
47
+ Args:
48
+ parent: The window that the editor is shown over.
49
+ on_close: Told when the editing session has ended.
50
+ config_file: The configuration file of the open project, None
51
+ for editing the user wide configuration.
52
+
53
+ Returns:
54
+ The panel of the session that was started.
55
+
56
+ Raises:
57
+ ConfigLoadError: The configuration file cannot be edited.
58
+ """
59
+ in_file, out_file = editor_files(config_file)
60
+ return TkEditorPanel(NotesmgrConfig(), parent=parent,
61
+ descriptions=DESCRIPTIONS, in_file=in_file,
62
+ out_file=out_file, on_close=on_close)
@@ -0,0 +1,147 @@
1
+ #! /usr/local/bin/python3
2
+ """Where the user wide configuration of notesmgr is kept."""
3
+
4
+ # Copyright (c) 2026 Tom Björkholm
5
+ # MIT License
6
+
7
+ import io
8
+ import os
9
+ import shutil
10
+ from pathlib import Path
11
+ from typing import Optional
12
+ from notesmgr.config import NotesmgrConfig
13
+ from notesmgr.errors import NotesmgrError
14
+
15
+ CONFIG_VARIABLE = 'NOTESMGR_CFG'
16
+ """Environment variable in which a user names the configuration file."""
17
+
18
+ CONFIG_NAME = '.notesmgr.cfg'
19
+ """Name the user wide configuration has in the home folder."""
20
+
21
+ MISSING = 'There is no configuration file {path}.'
22
+ """What is said about a configuration file that is not there."""
23
+
24
+ NOT_READ = 'The configuration file {path} cannot be used.\n{reason}'
25
+ """What is said about a configuration file that cannot be read."""
26
+
27
+ NOT_WRITTEN = 'The configuration file {path} cannot be written.\n{reason}'
28
+ """What is said about a configuration file that cannot be written."""
29
+
30
+
31
+ def user_config_path() -> Path:
32
+ """Return the file the user wide configuration is written to.
33
+
34
+ The file the environment names is the one the user has asked for,
35
+ whether it is there yet or not, so that it is also where a first
36
+ configuration is written.
37
+ """
38
+ named = os.environ.get(CONFIG_VARIABLE, '').strip()
39
+ return Path(named) if named else Path.home() / CONFIG_NAME
40
+
41
+
42
+ def user_config_source() -> Optional[Path]:
43
+ """Return the user wide configuration file to read, None for none.
44
+
45
+ The file the environment names is read when it is there, and the
46
+ file in the home folder when it is not, so that a variable naming
47
+ a file that does not exist yet leaves the defaults to be used
48
+ rather than making the program refuse to start.
49
+ """
50
+ named = user_config_path()
51
+ if named.is_file():
52
+ return named
53
+ in_home = Path.home() / CONFIG_NAME
54
+ return in_home if in_home.is_file() else None
55
+
56
+
57
+ def copy_to_user_wide(source: Path) -> Path:
58
+ """Copy a project's configuration file to the user wide location.
59
+
60
+ Args:
61
+ source: The project configuration file to copy.
62
+
63
+ Returns:
64
+ The user wide configuration file that was written.
65
+
66
+ Raises:
67
+ OSError: The file could not be read or could not be written.
68
+ """
69
+ target = user_config_path()
70
+ target.parent.mkdir(parents=True, exist_ok=True)
71
+ shutil.copyfile(source, target)
72
+ return target
73
+
74
+
75
+ def config_error(template: str, path: Path, said: str,
76
+ error: Exception) -> NotesmgrError:
77
+ """Return what to raise when a configuration file cannot be used.
78
+
79
+ What the configuration library said while it was failing tells the
80
+ user far more than the exception does, so it is what is shown when
81
+ there is any, and the exception is what is shown when there is not.
82
+
83
+ Args:
84
+ template: What is said about the file, holding path and reason.
85
+ path: The configuration file that could not be used.
86
+ said: What the configuration library reported while failing.
87
+ error: What the configuration library raised.
88
+
89
+ Returns:
90
+ The error to raise, said in words meant for the user.
91
+ """
92
+ reason = said or str(error)
93
+ return NotesmgrError(template.format(path=path, reason=reason))
94
+
95
+
96
+ def read_config_file(path: Path) -> NotesmgrConfig:
97
+ """Return the configuration that a file holds.
98
+
99
+ Args:
100
+ path: The configuration file to read.
101
+
102
+ Returns:
103
+ The configuration it holds.
104
+
105
+ Raises:
106
+ NotesmgrError: There is no such file, or it holds no
107
+ configuration that notesmgr can use.
108
+ """
109
+ if not path.is_file():
110
+ raise NotesmgrError(MISSING.format(path=path))
111
+ said = io.StringIO()
112
+ try:
113
+ return NotesmgrConfig(from_json_filename=path, stderr_file=said)
114
+ except (ValueError, KeyError, OSError) as error:
115
+ raise config_error(NOT_READ, path, said.getvalue(), error) from error
116
+
117
+
118
+ def write_config_file(config: NotesmgrConfig, path: Path) -> None:
119
+ """Write a configuration to a file, replacing what was there.
120
+
121
+ Args:
122
+ config: The configuration to write.
123
+ path: The configuration file to write it to.
124
+
125
+ Raises:
126
+ NotesmgrError: The file cannot be written.
127
+ """
128
+ said = io.StringIO()
129
+ try:
130
+ config.write(path, stderr_file=said)
131
+ except (ValueError, KeyError, OSError) as error:
132
+ raise config_error(NOT_WRITTEN, path, said.getvalue(),
133
+ error) from error
134
+
135
+
136
+ def user_wide_config() -> NotesmgrConfig:
137
+ """Return the user wide configuration, or the built-in defaults.
138
+
139
+ Returns:
140
+ What a new project starts its own configuration out as.
141
+
142
+ Raises:
143
+ NotesmgrError: There is a user wide configuration file and it
144
+ holds no configuration that notesmgr can use.
145
+ """
146
+ source = user_config_source()
147
+ return NotesmgrConfig() if source is None else read_config_file(source)
notesmgr/console.py ADDED
@@ -0,0 +1,62 @@
1
+ #! /usr/local/bin/python3
2
+ """Where notesmgr says what its command line asks it to say."""
3
+
4
+ # Copyright (c) 2026 Tom Björkholm
5
+ # MIT License
6
+
7
+ import io
8
+ import sys
9
+ import tkinter
10
+ from contextlib import ExitStack, contextmanager, redirect_stderr, \
11
+ redirect_stdout
12
+ from tkinter import messagebox
13
+ from typing import Iterator
14
+
15
+ CONSOLE_TITLE = 'notesmgr'
16
+ """What the window showing what the command line said is called."""
17
+
18
+
19
+ def show_said(text: str, failed: bool) -> None:
20
+ """Show in a window of its own what the command line said.
21
+
22
+ Nothing has been shown yet when the command line is read, so the
23
+ window is shown over a root window of its own that is never seen.
24
+
25
+ Args:
26
+ text: What was said, nothing at all meaning no window.
27
+ failed: Whether it says that the command line was refused.
28
+ """
29
+ if not text:
30
+ return
31
+ root = tkinter.Tk()
32
+ root.withdraw()
33
+ show = messagebox.showerror if failed else messagebox.showinfo
34
+ show(title=CONSOLE_TITLE, message=text, parent=root)
35
+ root.destroy()
36
+
37
+
38
+ @contextmanager
39
+ def console_or_window() -> Iterator[None]:
40
+ """Show in a window what is said while there is no console.
41
+
42
+ Windows starts a program that is installed as a graphical one
43
+ with no standard output and no standard error stream, so what the
44
+ command line asks to have said, the help and the errors among it,
45
+ would be lost. It is gathered instead and shown in a window once
46
+ all of it is said, while a stream that is there is written to as
47
+ usual.
48
+ """
49
+ gathered = io.StringIO()
50
+ failed = False
51
+ with ExitStack() as stack:
52
+ if sys.stdout is None:
53
+ stack.enter_context(redirect_stdout(gathered))
54
+ if sys.stderr is None:
55
+ stack.enter_context(redirect_stderr(gathered))
56
+ try:
57
+ yield
58
+ except SystemExit as leaving:
59
+ failed = leaving.code not in (None, 0)
60
+ raise
61
+ finally:
62
+ show_said(gathered.getvalue(), failed)
@@ -0,0 +1,27 @@
1
+ #! /usr/local/bin/python3
2
+ """What notesmgr says about the members of its configuration."""
3
+
4
+ # Copyright (c) 2026 Tom Björkholm
5
+ # MIT License
6
+
7
+ from edit_cfg_json import Descriptions
8
+
9
+ DESCRIPTIONS: Descriptions = {
10
+ ('editor',): ('Command that opens a note for editing. The name of the '
11
+ 'note file replaces {file} in the command, and is added '
12
+ 'at the end of a command that holds no {file}.'),
13
+ ('file_extension',): ('Extension of the note files of a project. The '
14
+ 'configuration file holds the name below, and '
15
+ 'not the extension it stands for.'),
16
+ ('max_note_size',): ('Characters of a note that are shown. A longer '
17
+ 'note is shown only up to here, with a warning '
18
+ 'saying so. Between 2000 and 100000.')}
19
+ """What each member of the configuration is for.
20
+
21
+ Python keeps no docstring of an instance attribute at runtime, so what
22
+ a member is for is said here and read by the configuration editor.
23
+
24
+ The extensions themselves are deliberately not listed here: the editor
25
+ reads them from the type of the member and lists them below its row, so
26
+ naming them here as well would be writing them twice.
27
+ """