codis 1.1.1__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.
- codis-1.1.1.dist-info/METADATA +194 -0
- codis-1.1.1.dist-info/RECORD +329 -0
- codis-1.1.1.dist-info/WHEEL +5 -0
- codis-1.1.1.dist-info/entry_points.txt +5 -0
- codis-1.1.1.dist-info/licenses/LICENSE +21 -0
- codis-1.1.1.dist-info/top_level.txt +2 -0
- run.py +190 -0
- src/__init__.py +1 -0
- src/__main__.py +81 -0
- src/_app_build.py +1507 -0
- src/_app_editor.py +1274 -0
- src/_app_kui.py +825 -0
- src/_app_lsp.py +625 -0
- src/_app_recovery.py +189 -0
- src/_app_settings.py +1385 -0
- src/_app_tools.py +2471 -0
- src/_app_webpreview.py +126 -0
- src/_font_safety.py +127 -0
- src/_shells.py +172 -0
- src/app.py +1488 -0
- src/chat/__init__.py +1 -0
- src/chat/adapters/__init__.py +33 -0
- src/chat/adapters/base.py +209 -0
- src/chat/adapters/discord.py +190 -0
- src/chat/adapters/http.py +78 -0
- src/chat/adapters/irc.py +360 -0
- src/chat/adapters/matrix.py +219 -0
- src/chat/adapters/mattermost.py +178 -0
- src/chat/adapters/mqtt.py +165 -0
- src/chat/adapters/slack.py +204 -0
- src/chat/adapters/telegram.py +117 -0
- src/chat/adapters/ws.py +154 -0
- src/chat/adapters/xmpp.py +337 -0
- src/chat/history.py +76 -0
- src/chat/models.py +207 -0
- src/chat/probe.py +79 -0
- src/chat/session.py +446 -0
- src/chat/util.py +125 -0
- src/collab/__init__.py +1 -0
- src/collab/net.py +411 -0
- src/collab/ot.py +311 -0
- src/collab/session.py +141 -0
- src/collab/tk_adapter.py +134 -0
- src/config.py +335 -0
- src/constants.py +2552 -0
- src/dep_catalog.py +446 -0
- src/diff/__init__.py +1 -0
- src/diff/engine.py +247 -0
- src/dpi.py +30 -0
- src/editor/__init__.py +1 -0
- src/editor/_pane_lsp.py +2937 -0
- src/editor/_pane_utils.py +171 -0
- src/editor/autocomplete.py +607 -0
- src/editor/code_folding.py +836 -0
- src/editor/color_preview.py +382 -0
- src/editor/complexity_lens.py +281 -0
- src/editor/diff_pane.py +623 -0
- src/editor/file_watcher.py +144 -0
- src/editor/focus_block.py +236 -0
- src/editor/heatmap.py +141 -0
- src/editor/inlay_hints.py +366 -0
- src/editor/inline_blame.py +429 -0
- src/editor/kdocs.py +3376 -0
- src/editor/large_file.py +488 -0
- src/editor/ligatures.py +180 -0
- src/editor/line_numbers.py +598 -0
- src/editor/minimap.py +691 -0
- src/editor/multi_cursor.py +269 -0
- src/editor/pane.py +2082 -0
- src/editor/rhythm.py +206 -0
- src/editor/save_hooks.py +43 -0
- src/editor/smart_selection.py +425 -0
- src/editor/smart_tips.py +719 -0
- src/editor/snippets.py +411 -0
- src/editor/sticky_note_gutter.py +410 -0
- src/editor/sticky_scroll.py +385 -0
- src/editor/suggest.py +464 -0
- src/editor/text_transforms.py +310 -0
- src/editor/vim_mode.py +1074 -0
- src/events/__init__.py +84 -0
- src/events/bus.py +427 -0
- src/events/correlator.py +244 -0
- src/events/kinds.py +125 -0
- src/events/pipeline.py +264 -0
- src/events/stream.py +416 -0
- src/events/window.py +204 -0
- src/extcompat/__init__.py +19 -0
- src/extcompat/code/__init__.py +13 -0
- src/extcompat/code/consent.py +162 -0
- src/extcompat/code/host.py +353 -0
- src/extcompat/code/hosts/py_host.py +763 -0
- src/extcompat/code/locate.py +105 -0
- src/extcompat/code/manager.py +325 -0
- src/extcompat/code/permissions.py +154 -0
- src/extcompat/code/sandbox.py +60 -0
- src/extcompat/colors.py +131 -0
- src/extcompat/common.py +184 -0
- src/extcompat/cson.py +269 -0
- src/extcompat/formats/__init__.py +22 -0
- src/extcompat/formats/_tm.py +189 -0
- src/extcompat/formats/_util.py +31 -0
- src/extcompat/formats/base16.py +66 -0
- src/extcompat/formats/brackets.py +172 -0
- src/extcompat/formats/eclipse.py +193 -0
- src/extcompat/formats/emacs.py +361 -0
- src/extcompat/formats/geany.py +147 -0
- src/extcompat/formats/generic.py +184 -0
- src/extcompat/formats/gtksource.py +117 -0
- src/extcompat/formats/helix.py +91 -0
- src/extcompat/formats/jetbrains.py +343 -0
- src/extcompat/formats/kate.py +130 -0
- src/extcompat/formats/micro.py +131 -0
- src/extcompat/formats/nano.py +111 -0
- src/extcompat/formats/notepadpp.py +140 -0
- src/extcompat/formats/pulsar.py +165 -0
- src/extcompat/formats/pyides.py +163 -0
- src/extcompat/formats/sublime.py +340 -0
- src/extcompat/jsonc.py +65 -0
- src/extcompat/lessish.py +128 -0
- src/extcompat/manager.py +122 -0
- src/extcompat/market/__init__.py +63 -0
- src/extcompat/market/sources.py +211 -0
- src/extcompat/model.py +88 -0
- src/extcompat/net.py +228 -0
- src/extcompat/openvsx.py +63 -0
- src/extcompat/readers.py +362 -0
- src/extcompat/registry.py +73 -0
- src/extcompat/safexml.py +63 -0
- src/extcompat/sexp.py +187 -0
- src/extcompat/sources.py +105 -0
- src/extcompat/store.py +276 -0
- src/extcompat/textmate.py +214 -0
- src/extcompat/themes.py +487 -0
- src/extcompat/yamlite.py +294 -0
- src/fileio.py +94 -0
- src/fs_ops.py +106 -0
- src/i18n.py +233 -0
- src/ia/__init__.py +1 -0
- src/ia/actions.py +295 -0
- src/ia/approval_gate.py +672 -0
- src/ia/checkpoints.py +308 -0
- src/ia/context_builder.py +921 -0
- src/ia/dialdiff.py +408 -0
- src/ia/iaspace.py +2078 -0
- src/ia/pair.py +296 -0
- src/ia/providers.py +954 -0
- src/ia/session.py +335 -0
- src/ia/toolbox.py +2524 -0
- src/launcher_actions.py +204 -0
- src/lint/__init__.py +1 -0
- src/lint/manager.py +1058 -0
- src/locales/.translate_manifest.json +64170 -0
- src/locales/de.json +4936 -0
- src/locales/en.json +4936 -0
- src/locales/es.json +4936 -0
- src/locales/fr.json +4936 -0
- src/locales/it.json +4936 -0
- src/locales/ja.json +4936 -0
- src/locales/ko.json +4936 -0
- src/locales/nl.json +4936 -0
- src/locales/pl.json +4936 -0
- src/locales/pt-BR.json +4936 -0
- src/locales/ru.json +4936 -0
- src/locales/tr.json +4936 -0
- src/locales/uk.json +4936 -0
- src/locales/zh-CN.json +4936 -0
- src/lsp/__init__.py +26 -0
- src/lsp/client.py +2300 -0
- src/lsp/dap_client.py +480 -0
- src/lsp/edits.py +84 -0
- src/lsp/framing.py +73 -0
- src/lsp/protocol.py +931 -0
- src/main.py +260 -0
- src/memtrim.py +91 -0
- src/plugins/__init__.py +1 -0
- src/plugins/api.py +1761 -0
- src/plugins/loader.py +571 -0
- src/plugins/process_runner.py +519 -0
- src/plugins/registry.py +342 -0
- src/plugins/safety.py +367 -0
- src/plugins/startup.py +195 -0
- src/plugins/store.py +1178 -0
- src/proc_registry.py +278 -0
- src/pyexec.py +394 -0
- src/recovery.py +259 -0
- src/stall_trace.py +92 -0
- src/standalone.py +1070 -0
- src/startup_profile.py +35 -0
- src/syntax/__init__.py +1 -0
- src/syntax/highlighter.py +776 -0
- src/syntax/patterns.py +584 -0
- src/system_profile.py +430 -0
- src/terminal/backends.py +658 -0
- src/terminal/internal.py +346 -0
- src/terminal/keys.py +138 -0
- src/terminal/palette.py +67 -0
- src/terminal/session.py +283 -0
- src/terminal/shells.py +79 -0
- src/terminal/view.py +489 -0
- src/terminal/vt.py +870 -0
- src/textfmt.py +22 -0
- src/theme/__init__.py +1 -0
- src/theme/base.py +1281 -0
- src/theme/colors.py +49 -0
- src/theme/manager.py +602 -0
- src/theme/utils.py +312 -0
- src/toolbox.py +329 -0
- src/trash_core.py +531 -0
- src/ui/__init__.py +1 -0
- src/ui/_perf_utils.py +285 -0
- src/ui/_persistence_utils.py +93 -0
- src/ui/accessibility.py +843 -0
- src/ui/activity_bar.py +860 -0
- src/ui/app_embed.py +434 -0
- src/ui/archive_panel.py +608 -0
- src/ui/bookmarks.py +314 -0
- src/ui/breadcrumb.py +383 -0
- src/ui/calculator_panel.py +982 -0
- src/ui/calendar_panel.py +1218 -0
- src/ui/chat_panel.py +1271 -0
- src/ui/chat_profile_dialog.py +278 -0
- src/ui/chat_render.py +128 -0
- src/ui/clock_panel.py +810 -0
- src/ui/code_outline.py +364 -0
- src/ui/code_runner.py +729 -0
- src/ui/code_stats.py +546 -0
- src/ui/collab_panel.py +1009 -0
- src/ui/color_picker.py +547 -0
- src/ui/command_palette.py +452 -0
- src/ui/cursor_manager.py +750 -0
- src/ui/custom_keywords_panel.py +413 -0
- src/ui/debug_panel.py +1037 -0
- src/ui/dependency_graph.py +692 -0
- src/ui/diff_panel.py +381 -0
- src/ui/docs_panel.py +514 -0
- src/ui/doom_embed.py +349 -0
- src/ui/dropdown.py +321 -0
- src/ui/easter_eggs.py +979 -0
- src/ui/env_manager.py +666 -0
- src/ui/extcode_bridge.py +215 -0
- src/ui/extcode_dialogs.py +412 -0
- src/ui/extcompat_dialog.py +583 -0
- src/ui/file_timeline.py +319 -0
- src/ui/file_tree.py +1208 -0
- src/ui/find_in_files.py +1355 -0
- src/ui/flowchart_panel.py +727 -0
- src/ui/formatter_panel.py +490 -0
- src/ui/git_auth.py +763 -0
- src/ui/git_clone_dialog.py +487 -0
- src/ui/git_panel.py +1483 -0
- src/ui/grab_safe.py +84 -0
- src/ui/internal_python_dialog.py +98 -0
- src/ui/k_ui/__init__.py +1305 -0
- src/ui/k_ui/_bgrenderer.py +317 -0
- src/ui/k_ui/_colors.py +213 -0
- src/ui/k_ui/_dock.py +545 -0
- src/ui/k_ui/_easter.py +290 -0
- src/ui/k_ui/_engine.py +5448 -0
- src/ui/k_ui/_perf.py +333 -0
- src/ui/k_ui/_tkutil.py +7 -0
- src/ui/k_ui/_tooltip.py +365 -0
- src/ui/k_ui/_widgets.py +1204 -0
- src/ui/k_ui/_world.py +837 -0
- src/ui/key_remapper.py +856 -0
- src/ui/launcher.py +1252 -0
- src/ui/lazy_panel.py +73 -0
- src/ui/macro_recorder.py +610 -0
- src/ui/menu_bar.py +898 -0
- src/ui/output_panel.py +321 -0
- src/ui/paint_canvas.py +1000 -0
- src/ui/paint_engine.py +535 -0
- src/ui/paint_panel.py +888 -0
- src/ui/panel_detach.py +112 -0
- src/ui/performance_panel.py +861 -0
- src/ui/pip_manager.py +1758 -0
- src/ui/plugin_panel.py +1586 -0
- src/ui/pomodoro_panel.py +447 -0
- src/ui/problems.py +566 -0
- src/ui/process_manager.py +1657 -0
- src/ui/project_templates.py +775 -0
- src/ui/recovery_dialog.py +122 -0
- src/ui/regex_playground.py +304 -0
- src/ui/remote_adapters.py +1398 -0
- src/ui/remote_browser.py +1224 -0
- src/ui/remote_profile_dialog.py +342 -0
- src/ui/render_panel.py +1293 -0
- src/ui/rest_client.py +549 -0
- src/ui/scratchpad.py +548 -0
- src/ui/search_bar.py +1274 -0
- src/ui/settings_editor.py +3349 -0
- src/ui/settings_window.py +1554 -0
- src/ui/snippets_panel.py +597 -0
- src/ui/sql_studio.py +1815 -0
- src/ui/status_bar.py +438 -0
- src/ui/tab_bar.py +654 -0
- src/ui/task_manager.py +1773 -0
- src/ui/terminal.py +525 -0
- src/ui/theme_preview_panel.py +851 -0
- src/ui/thread_safe_tk.py +152 -0
- src/ui/time_tracker.py +574 -0
- src/ui/tkbind.py +43 -0
- src/ui/todo_panel.py +358 -0
- src/ui/toolbox_panels.py +658 -0
- src/ui/trash_manager.py +657 -0
- src/ui/ui_scale.py +294 -0
- src/ui/ux_enhancements.py +41 -0
- src/ui/web_preview.py +397 -0
- src/ui/webdev.py +630 -0
- src/ui/welcome.py +567 -0
- src/ui/window_embed.py +1500 -0
- src/ui/wizard.py +1550 -0
- src/ui/workspace_switcher.py +418 -0
- src/ui/workspace_trust.py +370 -0
- src/ui/zen_audio.py +354 -0
- src/ui/zen_media.py +2271 -0
- src/ui/zen_media_client.py +303 -0
- src/ui/zen_media_host.py +329 -0
- src/ui/zen_player.py +907 -0
- src/ui/zen_player_widgets.py +700 -0
- src/updater/__init__.py +11 -0
- src/updater/assets.py +145 -0
- src/updater/backup.py +101 -0
- src/updater/channel.py +221 -0
- src/updater/dialog.py +492 -0
- src/updater/integrity.py +111 -0
- src/updater/manager.py +727 -0
- src/updater/result.py +114 -0
- src/venv_runtime.py +531 -0
- src/workspace_state.py +25 -0
|
@@ -0,0 +1,775 @@
|
|
|
1
|
+
"""Codis - Project Templates.
|
|
2
|
+
|
|
3
|
+
Cria novos projetos a partir de templates pré-definidos ou customizados.
|
|
4
|
+
Templates são pastas com arquivos e um `template.json` de metadados.
|
|
5
|
+
|
|
6
|
+
Features
|
|
7
|
+
--------
|
|
8
|
+
- 10+ templates embutidos (Python, FastAPI, Flask, CLI, JS, TS, React, etc.)
|
|
9
|
+
- Templates customizados: salve qualquer pasta como template
|
|
10
|
+
- Variáveis de substituição: {{project_name}}, {{author}}, {{year}}, ...
|
|
11
|
+
- Preview da estrutura antes de criar
|
|
12
|
+
- Suporte a comandos pós-criação (ex: git init, pip install)
|
|
13
|
+
- Atalho: Ferramentas -> 📋 Novo Projeto a partir de Template
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
import contextlib
|
|
19
|
+
import json
|
|
20
|
+
import re
|
|
21
|
+
import shutil
|
|
22
|
+
import tkinter as tk
|
|
23
|
+
from datetime import datetime
|
|
24
|
+
from pathlib import Path
|
|
25
|
+
from tkinter import filedialog, messagebox
|
|
26
|
+
from typing import Any
|
|
27
|
+
|
|
28
|
+
from src.constants import CONFIG_DIR, FONT_MONO, FONT_UI
|
|
29
|
+
from src.i18n import _t
|
|
30
|
+
from src.ui.grab_safe import safe_grab_set
|
|
31
|
+
|
|
32
|
+
_TEMPLATES_DIR = CONFIG_DIR / "templates"
|
|
33
|
+
|
|
34
|
+
_BUILTIN_TEMPLATES: list[dict[str, Any]] = [
|
|
35
|
+
{
|
|
36
|
+
"id": "python_basic",
|
|
37
|
+
"label": _t("tmpl.label.python_basic"),
|
|
38
|
+
"description": _t("tmpl.desc.python_basic"),
|
|
39
|
+
"category": "Python",
|
|
40
|
+
"files": {
|
|
41
|
+
"{{project_name}}.py": (
|
|
42
|
+
'"""{{project_name}} - {{description}}\n\nAutor: {{author}}\nData: {{year}}\n"""\n'
|
|
43
|
+
"from __future__ import annotations\n\nimport argparse\nimport logging\nimport sys\n\n"
|
|
44
|
+
'logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s")\n'
|
|
45
|
+
"logger = logging.getLogger(__name__)\n\n\ndef parse_args() -> argparse.Namespace:\n"
|
|
46
|
+
' p = argparse.ArgumentParser(description="{{description}}")\n'
|
|
47
|
+
' p.add_argument("--verbose", "-v", action="store_true")\n'
|
|
48
|
+
" return p.parse_args()\n\n\ndef main(args: argparse.Namespace) -> int:\n"
|
|
49
|
+
" if args.verbose:\n logging.getLogger().setLevel(logging.DEBUG)\n"
|
|
50
|
+
' logger.info("{{project_name}} iniciado")\n return 0\n\n\n'
|
|
51
|
+
'if __name__ == "__main__":\n sys.exit(main(parse_args()))\n'
|
|
52
|
+
),
|
|
53
|
+
"README.md": "# {{project_name}}\n\n{{description}}\n\n## Uso\n\n```bash\npython {{project_name}}.py\n```\n",
|
|
54
|
+
"requirements.txt": "# Dependências\n",
|
|
55
|
+
".gitignore": "__pycache__/\n*.py[cod]\n*.egg-info/\ndist/\nbuild/\n.venv/\n",
|
|
56
|
+
},
|
|
57
|
+
"post_commands": [],
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"id": "python_package",
|
|
61
|
+
"label": _t("tmpl.label.python_package"),
|
|
62
|
+
"description": _t("tmpl.desc.python_package"),
|
|
63
|
+
"category": "Python",
|
|
64
|
+
"files": {
|
|
65
|
+
"pyproject.toml": (
|
|
66
|
+
'[build-system]\nrequires = ["setuptools>=68"]\nbuild-backend = "setuptools.backends.legacy:build"\n\n'
|
|
67
|
+
'[project]\nname = "{{project_name}}"\nversion = "0.1.0"\ndescription = "{{description}}"\n'
|
|
68
|
+
'authors = [{name = "{{author}}"}]\nrequires-python = ">=3.11"\n'
|
|
69
|
+
),
|
|
70
|
+
"src/{{project_name}}/__init__.py": '"""{{project_name}} - {{description}}"""\n\n__version__ = "0.1.0"\n',
|
|
71
|
+
"src/{{project_name}}/main.py": 'def main() -> None:\n print("Hello from {{project_name}}")\n\n\nif __name__ == "__main__":\n main()\n',
|
|
72
|
+
"tests/__init__.py": "",
|
|
73
|
+
"tests/test_main.py": 'from {{project_name}}.main import main\n\n\ndef test_main(capsys):\n main()\n out, _ = capsys.readouterr()\n assert "{{project_name}}" in out\n',
|
|
74
|
+
"README.md": "# {{project_name}}\n\n{{description}}\n\n## Instalação\n\n```bash\npip install -e .\n```\n",
|
|
75
|
+
".gitignore": "__pycache__/\n*.py[cod]\ndist/\nbuild/\n.venv/\n*.egg-info/\n",
|
|
76
|
+
},
|
|
77
|
+
"post_commands": [],
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"id": "fastapi",
|
|
81
|
+
"label": _t("tmpl.label.fastapi"),
|
|
82
|
+
"description": _t("tmpl.desc.fastapi"),
|
|
83
|
+
"category": "Python",
|
|
84
|
+
"files": {
|
|
85
|
+
"main.py": (
|
|
86
|
+
"from fastapi import FastAPI\nfrom app.routers import items\n\n"
|
|
87
|
+
'app = FastAPI(title="{{project_name}}", version="0.1.0")\n\n'
|
|
88
|
+
'app.include_router(items.router)\n\n\n@app.get("/")\nasync def root():\n return {"message": "{{project_name}}"}\n'
|
|
89
|
+
),
|
|
90
|
+
"app/__init__.py": "",
|
|
91
|
+
"app/routers/__init__.py": "",
|
|
92
|
+
"app/routers/items.py": (
|
|
93
|
+
"from fastapi import APIRouter\nfrom pydantic import BaseModel\n\n"
|
|
94
|
+
'router = APIRouter(prefix="/items", tags=["items"])\n\n\n'
|
|
95
|
+
"class Item(BaseModel):\n name: str\n price: float\n\n\n"
|
|
96
|
+
'@router.get("/")\nasync def list_items():\n return []\n\n\n'
|
|
97
|
+
'@router.post("/")\nasync def create_item(item: Item):\n return item\n'
|
|
98
|
+
),
|
|
99
|
+
"requirements.txt": "fastapi>=0.111\nuvicorn[standard]>=0.29\npydantic>=2.7\n",
|
|
100
|
+
"README.md": "# {{project_name}}\n\n{{description}}\n\n## Executar\n\n```bash\nuvicorn main:app --reload\n```\n",
|
|
101
|
+
".gitignore": "__pycache__/\n*.py[cod]\n.venv/\n.env\n",
|
|
102
|
+
},
|
|
103
|
+
"post_commands": [],
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
"id": "flask",
|
|
107
|
+
"label": _t("tmpl.label.flask"),
|
|
108
|
+
"description": _t("tmpl.desc.flask"),
|
|
109
|
+
"category": "Python",
|
|
110
|
+
"files": {
|
|
111
|
+
"app/__init__.py": (
|
|
112
|
+
"from flask import Flask\nfrom .views import main\n\n\n"
|
|
113
|
+
"def create_app():\n app = Flask(__name__)\n"
|
|
114
|
+
" app.register_blueprint(main)\n return app\n"
|
|
115
|
+
),
|
|
116
|
+
"app/views.py": (
|
|
117
|
+
'from flask import Blueprint, render_template\n\nmain = Blueprint("main", __name__)\n\n\n'
|
|
118
|
+
'@main.route("/")\ndef index():\n return render_template("index.html", title="{{project_name}}")\n'
|
|
119
|
+
),
|
|
120
|
+
"app/templates/index.html": (
|
|
121
|
+
"<!DOCTYPE html>\n<html>\n<head><title>{{ title }}</title></head>\n"
|
|
122
|
+
"<body><h1>{{ title }}</h1></body>\n</html>\n"
|
|
123
|
+
),
|
|
124
|
+
"run.py": 'from app import create_app\n\napp = create_app()\n\nif __name__ == "__main__":\n app.run(debug=True)\n',
|
|
125
|
+
"requirements.txt": "flask>=3.0\n",
|
|
126
|
+
"README.md": "# {{project_name}}\n\n{{description}}\n\n## Executar\n\n```bash\npython run.py\n```\n",
|
|
127
|
+
".gitignore": "__pycache__/\n*.py[cod]\n.venv/\n.env\ninstance/\n",
|
|
128
|
+
},
|
|
129
|
+
"post_commands": [],
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
"id": "cli_tool",
|
|
133
|
+
"label": _t("tmpl.label.cli_tool"),
|
|
134
|
+
"description": _t("tmpl.desc.cli_tool"),
|
|
135
|
+
"category": "Python",
|
|
136
|
+
"files": {
|
|
137
|
+
"{{project_name}}.py": (
|
|
138
|
+
'"""{{project_name}} - {{description}}"""\nimport typer\nfrom rich.console import Console\nfrom rich import print\n\n'
|
|
139
|
+
'app = typer.Typer(help="{{description}}")\nconsole = Console()\n\n\n'
|
|
140
|
+
'@app.command()\ndef main(\n name: str = typer.Argument(help="Nome"),\n'
|
|
141
|
+
' verbose: bool = typer.Option(False, "--verbose", "-v"),\n) -> None:\n'
|
|
142
|
+
' """Executa o comando principal."""\n console.print(f"[bold green]{{project_name}}[/] - olá, {name}!")\n\n\n'
|
|
143
|
+
'if __name__ == "__main__":\n app()\n'
|
|
144
|
+
),
|
|
145
|
+
"requirements.txt": "typer>=0.12\nrich>=13\n",
|
|
146
|
+
"README.md": "# {{project_name}}\n\n{{description}}\n\n## Uso\n\n```bash\npython {{project_name}}.py --help\n```\n",
|
|
147
|
+
".gitignore": "__pycache__/\n*.py[cod]\n.venv/\n",
|
|
148
|
+
},
|
|
149
|
+
"post_commands": [],
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
"id": "node_basic",
|
|
153
|
+
"label": _t("tmpl.label.node_basic"),
|
|
154
|
+
"description": _t("tmpl.desc.node_basic"),
|
|
155
|
+
"category": "JavaScript",
|
|
156
|
+
"files": {
|
|
157
|
+
"package.json": (
|
|
158
|
+
'{{\n "name": "{{project_name_kebab}}",\n "version": "0.1.0",\n'
|
|
159
|
+
' "description": "{{description}}",\n "type": "module",\n'
|
|
160
|
+
' "main": "src/index.js",\n "scripts": {{\n'
|
|
161
|
+
' "start": "node src/index.js",\n "dev": "node --watch src/index.js"\n'
|
|
162
|
+
" }}\n}}\n"
|
|
163
|
+
),
|
|
164
|
+
"src/index.js": '// {{project_name}} - {{description}}\n\nconsole.log("Hello from {{project_name}}");\n',
|
|
165
|
+
"README.md": "# {{project_name}}\n\n{{description}}\n\n## Uso\n\n```bash\nnpm start\n```\n",
|
|
166
|
+
".gitignore": "node_modules/\ndist/\n.env\n",
|
|
167
|
+
},
|
|
168
|
+
"post_commands": [],
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
"id": "typescript_basic",
|
|
172
|
+
"label": _t("tmpl.label.typescript_basic"),
|
|
173
|
+
"description": _t("tmpl.desc.typescript_basic"),
|
|
174
|
+
"category": "TypeScript",
|
|
175
|
+
"files": {
|
|
176
|
+
"package.json": (
|
|
177
|
+
'{{\n "name": "{{project_name_kebab}}",\n "version": "0.1.0",\n'
|
|
178
|
+
' "scripts": {{\n "build": "tsc",\n "start": "ts-node src/index.ts",\n'
|
|
179
|
+
' "dev": "ts-node-dev src/index.ts"\n }},\n'
|
|
180
|
+
' "devDependencies": {{\n "typescript": "^5",\n "ts-node": "^10",\n "@types/node": "^20"\n }}\n}}\n'
|
|
181
|
+
),
|
|
182
|
+
"tsconfig.json": (
|
|
183
|
+
'{{\n "compilerOptions": {{\n "target": "ES2022",\n "module": "commonjs",\n'
|
|
184
|
+
' "strict": true,\n "outDir": "./dist",\n "rootDir": "./src"\n }},\n'
|
|
185
|
+
' "include": ["src"]\n}}\n'
|
|
186
|
+
),
|
|
187
|
+
"src/index.ts": '// {{project_name}} - {{description}}\n\nconst greeting: string = "Hello from {{project_name}}";\nconsole.log(greeting);\n',
|
|
188
|
+
"README.md": "# {{project_name}}\n\n{{description}}\n\n## Uso\n\n```bash\nnpm install\nnpm run dev\n```\n",
|
|
189
|
+
".gitignore": "node_modules/\ndist/\n.env\n",
|
|
190
|
+
},
|
|
191
|
+
"post_commands": [],
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
"id": "data_science",
|
|
195
|
+
"label": _t("tmpl.label.data_science"),
|
|
196
|
+
"description": _t("tmpl.desc.data_science"),
|
|
197
|
+
"category": "Python",
|
|
198
|
+
"files": {
|
|
199
|
+
"notebooks/.gitkeep": "",
|
|
200
|
+
"data/raw/.gitkeep": "",
|
|
201
|
+
"data/processed/.gitkeep": "",
|
|
202
|
+
"src/__init__.py": "",
|
|
203
|
+
"src/data.py": "import pandas as pd\nfrom pathlib import Path\n\nDATA_DIR = Path(__file__).parent.parent / 'data'\n\n\ndef load_raw(name: str) -> pd.DataFrame:\n return pd.read_csv(DATA_DIR / 'raw' / name)\n",
|
|
204
|
+
"requirements.txt": "pandas>=2\nnumpy>=1.26\nmatplotlib>=3.8\nseaborn>=0.13\njupyterlab>=4\nscikit-learn>=1.4\n",
|
|
205
|
+
"README.md": "# {{project_name}}\n\n{{description}}\n\n## Setup\n\n```bash\npip install -r requirements.txt\njupyterlab\n```\n",
|
|
206
|
+
".gitignore": "__pycache__/\n*.py[cod]\n.venv/\ndata/raw/*\n!data/raw/.gitkeep\n*.ipynb_checkpoints/\n",
|
|
207
|
+
},
|
|
208
|
+
"post_commands": [],
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
"id": "mkdocs",
|
|
212
|
+
"label": _t("tmpl.label.mkdocs"),
|
|
213
|
+
"description": _t("tmpl.desc.mkdocs"),
|
|
214
|
+
"category": "Docs",
|
|
215
|
+
"files": {
|
|
216
|
+
"mkdocs.yml": (
|
|
217
|
+
"site_name: {{project_name}}\nsite_description: {{description}}\n\ntheme:\n"
|
|
218
|
+
" name: material\n palette:\n scheme: slate\n\nnav:\n"
|
|
219
|
+
" - Home: index.md\n - Início Rápido: quickstart.md\n"
|
|
220
|
+
),
|
|
221
|
+
"docs/index.md": "# {{project_name}}\n\n{{description}}\n",
|
|
222
|
+
"docs/quickstart.md": "# Início Rápido\n\nInstruções rápidas de uso.\n",
|
|
223
|
+
"requirements.txt": "mkdocs>=1.5\nmkdocs-material>=9\n",
|
|
224
|
+
".gitignore": "site/\n",
|
|
225
|
+
},
|
|
226
|
+
"post_commands": [],
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
"id": "makefile_c",
|
|
230
|
+
"label": _t("tmpl.label.makefile_c"),
|
|
231
|
+
"description": _t("tmpl.desc.makefile_c"),
|
|
232
|
+
"category": "C/C++",
|
|
233
|
+
"files": {
|
|
234
|
+
"Makefile": (
|
|
235
|
+
"CC = gcc\nCFLAGS = -Wall -Wextra -std=c17 -Iinclude\nSRC = $(wildcard src/*.c)\n"
|
|
236
|
+
"OBJ = $(SRC:.c=.o)\nBIN = {{project_name}}\n\n"
|
|
237
|
+
"all: $(BIN)\n\n$(BIN): $(OBJ)\n\t$(CC) -o $@ $^\n\n"
|
|
238
|
+
"clean:\n\trm -f $(OBJ) $(BIN)\n\n.PHONY: all clean\n"
|
|
239
|
+
),
|
|
240
|
+
"src/main.c": '#include <stdio.h>\n#include "{{project_name}}.h"\n\nint main(void) {\n printf("Hello from {{project_name}}\\n");\n return 0;\n}\n',
|
|
241
|
+
"include/{{project_name}}.h": "#pragma once\n\nvoid hello(void);\n",
|
|
242
|
+
"README.md": "# {{project_name}}\n\n{{description}}\n\n## Build\n\n```bash\nmake\n./{{project_name}}\n```\n",
|
|
243
|
+
".gitignore": "*.o\n{{project_name}}\nbuild/\n",
|
|
244
|
+
},
|
|
245
|
+
"post_commands": [],
|
|
246
|
+
},
|
|
247
|
+
]
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
def _apply_vars(text: str, vars_: dict[str, str]) -> str:
|
|
251
|
+
"""Substitui {{var}} no texto pelas variáveis fornecidas."""
|
|
252
|
+
for key, value in vars_.items():
|
|
253
|
+
text = text.replace("{{" + key + "}}", value)
|
|
254
|
+
return text
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def _make_vars(project_name: str, author: str, description: str) -> dict[str, str]:
|
|
258
|
+
"""Gera o dicionário de variáveis de substituição."""
|
|
259
|
+
kebab = re.sub(r"[^a-z0-9]+", "-", project_name.lower()).strip("-")
|
|
260
|
+
snake = re.sub(r"[^a-z0-9]+", "_", project_name.lower()).strip("_")
|
|
261
|
+
return {
|
|
262
|
+
"project_name": project_name,
|
|
263
|
+
"project_name_kebab": kebab,
|
|
264
|
+
"project_name_snake": snake,
|
|
265
|
+
"author": author,
|
|
266
|
+
"description": description,
|
|
267
|
+
"year": str(datetime.now().year),
|
|
268
|
+
"date": datetime.now().strftime("%Y-%m-%d"),
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
class TemplateStore:
|
|
273
|
+
"""Gerencia templates embutidos e customizados."""
|
|
274
|
+
|
|
275
|
+
def __init__(self) -> None:
|
|
276
|
+
_TEMPLATES_DIR.mkdir(parents=True, exist_ok=True)
|
|
277
|
+
self._custom: list[dict[str, Any]] = []
|
|
278
|
+
self._load_custom()
|
|
279
|
+
|
|
280
|
+
def _load_custom(self) -> None:
|
|
281
|
+
for meta_file in _TEMPLATES_DIR.glob("*/template.json"):
|
|
282
|
+
with contextlib.suppress(OSError, json.JSONDecodeError):
|
|
283
|
+
meta = json.loads(meta_file.read_text(encoding="utf-8"))
|
|
284
|
+
meta["_dir"] = str(meta_file.parent)
|
|
285
|
+
self._custom.append(meta)
|
|
286
|
+
|
|
287
|
+
def all_templates(self) -> list[dict[str, Any]]:
|
|
288
|
+
"""Retorna a lista de todos os templates disponíveis."""
|
|
289
|
+
return _BUILTIN_TEMPLATES + self._custom
|
|
290
|
+
|
|
291
|
+
def create_project(
|
|
292
|
+
self,
|
|
293
|
+
template: dict[str, Any],
|
|
294
|
+
dest: Path,
|
|
295
|
+
vars_: dict[str, str],
|
|
296
|
+
) -> list[str]:
|
|
297
|
+
"""Cria o projeto no diretório `dest`. Retorna lista de arquivos criados."""
|
|
298
|
+
dest.mkdir(parents=True, exist_ok=True)
|
|
299
|
+
created: list[str] = []
|
|
300
|
+
|
|
301
|
+
if "_dir" in template:
|
|
302
|
+
src_dir = Path(template["_dir"])
|
|
303
|
+
for src_path in src_dir.rglob("*"):
|
|
304
|
+
if src_path.name == "template.json":
|
|
305
|
+
continue
|
|
306
|
+
rel = src_path.relative_to(src_dir)
|
|
307
|
+
rel_str = _apply_vars(str(rel), vars_)
|
|
308
|
+
dst_path = dest / rel_str
|
|
309
|
+
if src_path.is_dir():
|
|
310
|
+
dst_path.mkdir(parents=True, exist_ok=True)
|
|
311
|
+
else:
|
|
312
|
+
dst_path.parent.mkdir(parents=True, exist_ok=True)
|
|
313
|
+
raw = src_path.read_bytes()
|
|
314
|
+
try:
|
|
315
|
+
content = _apply_vars(raw.decode("utf-8"), vars_)
|
|
316
|
+
dst_path.write_text(content, encoding="utf-8")
|
|
317
|
+
except UnicodeDecodeError:
|
|
318
|
+
dst_path.write_bytes(raw)
|
|
319
|
+
created.append(str(dst_path.relative_to(dest)))
|
|
320
|
+
else:
|
|
321
|
+
for rel_path, content in template.get("files", {}).items():
|
|
322
|
+
rel_path_expanded = _apply_vars(rel_path, vars_)
|
|
323
|
+
content_expanded = _apply_vars(content, vars_)
|
|
324
|
+
file_path = dest / rel_path_expanded
|
|
325
|
+
file_path.parent.mkdir(parents=True, exist_ok=True)
|
|
326
|
+
file_path.write_text(content_expanded, encoding="utf-8")
|
|
327
|
+
created.append(rel_path_expanded)
|
|
328
|
+
|
|
329
|
+
return created
|
|
330
|
+
|
|
331
|
+
def save_folder_as_template(
|
|
332
|
+
self,
|
|
333
|
+
src: Path,
|
|
334
|
+
meta: dict[str, str],
|
|
335
|
+
) -> Path:
|
|
336
|
+
"""Salva uma pasta como template customizado."""
|
|
337
|
+
tid = re.sub(r"[^a-z0-9_]", "_", meta["id"].lower())
|
|
338
|
+
out = _TEMPLATES_DIR / tid
|
|
339
|
+
if out.exists():
|
|
340
|
+
shutil.rmtree(out)
|
|
341
|
+
shutil.copytree(str(src), str(out))
|
|
342
|
+
meta_file = out / "template.json"
|
|
343
|
+
meta_file.write_text(
|
|
344
|
+
json.dumps(meta, indent=2, ensure_ascii=False), encoding="utf-8"
|
|
345
|
+
)
|
|
346
|
+
self._custom.clear()
|
|
347
|
+
self._load_custom()
|
|
348
|
+
return out
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
class ProjectTemplateDialog(tk.Toplevel):
|
|
352
|
+
"""Diálogo de criação de projeto a partir de template.
|
|
353
|
+
|
|
354
|
+
Abre em Ferramentas -> 📋 Novo Projeto a partir de Template.
|
|
355
|
+
"""
|
|
356
|
+
|
|
357
|
+
def __init__(
|
|
358
|
+
self,
|
|
359
|
+
parent: tk.Widget,
|
|
360
|
+
tmgr: Any,
|
|
361
|
+
store: TemplateStore,
|
|
362
|
+
on_open: Any,
|
|
363
|
+
cfg: Any,
|
|
364
|
+
) -> None:
|
|
365
|
+
t = tmgr.theme
|
|
366
|
+
super().__init__(parent)
|
|
367
|
+
self.title(_t("tmpl.window_title"))
|
|
368
|
+
self.configure(bg=t.floating_bg)
|
|
369
|
+
self.geometry("820x580")
|
|
370
|
+
self.minsize(640, 440)
|
|
371
|
+
self.transient(parent)
|
|
372
|
+
safe_grab_set(self)
|
|
373
|
+
|
|
374
|
+
self._tmgr = tmgr
|
|
375
|
+
self._store = store
|
|
376
|
+
self._on_open = on_open
|
|
377
|
+
self._cfg = cfg
|
|
378
|
+
self._selected: dict[str, Any] | None = None
|
|
379
|
+
self._category_var = tk.StringVar(value=_t("tmpl.category_all"))
|
|
380
|
+
|
|
381
|
+
self._build(t)
|
|
382
|
+
self._populate()
|
|
383
|
+
self._center(parent)
|
|
384
|
+
|
|
385
|
+
def _build(self, t: Any) -> None:
|
|
386
|
+
tk.Frame(self, bg=t.accent, height=2).pack(fill="x")
|
|
387
|
+
|
|
388
|
+
hdr = tk.Frame(self, bg=t.floating_bg)
|
|
389
|
+
hdr.pack(fill="x", padx=14, pady=(10, 4))
|
|
390
|
+
tk.Label(
|
|
391
|
+
hdr,
|
|
392
|
+
text="📋 Novo Projeto a partir de Template",
|
|
393
|
+
bg=t.floating_bg,
|
|
394
|
+
fg=t.t_func,
|
|
395
|
+
font=(FONT_UI, 12, "bold"),
|
|
396
|
+
).pack(side="left")
|
|
397
|
+
|
|
398
|
+
save_btn = tk.Label(
|
|
399
|
+
hdr,
|
|
400
|
+
text=_t("tmpl.save_as_btn"),
|
|
401
|
+
bg=t.btn_bg,
|
|
402
|
+
fg=t.fg,
|
|
403
|
+
font=(FONT_UI, 8),
|
|
404
|
+
cursor="hand2",
|
|
405
|
+
padx=8,
|
|
406
|
+
pady=3,
|
|
407
|
+
relief="flat",
|
|
408
|
+
)
|
|
409
|
+
save_btn.pack(side="right")
|
|
410
|
+
save_btn.bind("<Button-1>", lambda _: self._save_as_template())
|
|
411
|
+
|
|
412
|
+
cat_frame = tk.Frame(self, bg=t.floating_bg)
|
|
413
|
+
cat_frame.pack(fill="x", padx=14, pady=(0, 4))
|
|
414
|
+
tk.Label(
|
|
415
|
+
cat_frame,
|
|
416
|
+
text=_t("templates.field_category", "Categoria:"),
|
|
417
|
+
bg=t.floating_bg,
|
|
418
|
+
fg=t.fg_muted,
|
|
419
|
+
font=(FONT_UI, 8),
|
|
420
|
+
).pack(side="left")
|
|
421
|
+
|
|
422
|
+
categories = ["Todos"] + sorted(
|
|
423
|
+
{t_["category"]
|
|
424
|
+
for t_ in self._store.all_templates() if t_.get("category")}
|
|
425
|
+
)
|
|
426
|
+
for cat in categories:
|
|
427
|
+
rb = tk.Radiobutton(
|
|
428
|
+
cat_frame,
|
|
429
|
+
text=cat,
|
|
430
|
+
variable=self._category_var,
|
|
431
|
+
value=cat,
|
|
432
|
+
bg=t.floating_bg,
|
|
433
|
+
fg=t.fg,
|
|
434
|
+
selectcolor=t.editor_bg,
|
|
435
|
+
activebackground=t.floating_bg,
|
|
436
|
+
font=(FONT_UI, 8),
|
|
437
|
+
command=self._populate,
|
|
438
|
+
)
|
|
439
|
+
rb.pack(side="left", padx=4)
|
|
440
|
+
|
|
441
|
+
body = tk.Frame(self, bg=t.floating_bg)
|
|
442
|
+
body.pack(fill="both", expand=True, padx=14, pady=4)
|
|
443
|
+
|
|
444
|
+
left = tk.Frame(body, bg=t.floating_bg, width=310)
|
|
445
|
+
left.pack(side="left", fill="both")
|
|
446
|
+
left.pack_propagate(False)
|
|
447
|
+
|
|
448
|
+
vsb = tk.Scrollbar(left, orient="vertical")
|
|
449
|
+
self._listbox = tk.Listbox(
|
|
450
|
+
left,
|
|
451
|
+
bg=t.editor_bg,
|
|
452
|
+
fg=t.fg,
|
|
453
|
+
selectbackground=t.sel_bg,
|
|
454
|
+
selectforeground=t.sel_fg,
|
|
455
|
+
font=(FONT_UI, 9),
|
|
456
|
+
relief="flat",
|
|
457
|
+
bd=0,
|
|
458
|
+
activestyle="none",
|
|
459
|
+
highlightthickness=0,
|
|
460
|
+
yscrollcommand=vsb.set,
|
|
461
|
+
)
|
|
462
|
+
vsb.config(command=self._listbox.yview)
|
|
463
|
+
vsb.pack(side="right", fill="y")
|
|
464
|
+
self._listbox.pack(fill="both", expand=True)
|
|
465
|
+
self._listbox.bind("<<ListboxSelect>>", self._on_select)
|
|
466
|
+
|
|
467
|
+
sep = tk.Frame(body, bg=t.border, width=1)
|
|
468
|
+
sep.pack(side="left", fill="y", padx=8)
|
|
469
|
+
|
|
470
|
+
right = tk.Frame(body, bg=t.floating_bg)
|
|
471
|
+
right.pack(side="left", fill="both", expand=True)
|
|
472
|
+
|
|
473
|
+
self._desc_lbl = tk.Label(
|
|
474
|
+
right,
|
|
475
|
+
text="",
|
|
476
|
+
bg=t.floating_bg,
|
|
477
|
+
fg=t.fg,
|
|
478
|
+
font=(FONT_UI, 9),
|
|
479
|
+
wraplength=360,
|
|
480
|
+
justify="left",
|
|
481
|
+
anchor="nw",
|
|
482
|
+
)
|
|
483
|
+
self._desc_lbl.pack(anchor="w", pady=(0, 6))
|
|
484
|
+
|
|
485
|
+
fields_frame = tk.Frame(right, bg=t.floating_bg)
|
|
486
|
+
fields_frame.pack(fill="x")
|
|
487
|
+
|
|
488
|
+
ew = {
|
|
489
|
+
"bg": t.input_bg,
|
|
490
|
+
"fg": t.fg,
|
|
491
|
+
"insertbackground": t.cursor,
|
|
492
|
+
"relief": "flat",
|
|
493
|
+
"bd": 0,
|
|
494
|
+
"font": (FONT_MONO, 10),
|
|
495
|
+
"highlightthickness": 1,
|
|
496
|
+
"highlightbackground": t.border,
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
self._vars: dict[str, tk.StringVar] = {}
|
|
500
|
+
labels = [
|
|
501
|
+
("name", "Nome do Projeto", _t("tmpl.name_default")),
|
|
502
|
+
("author", "Autor", self._cfg.get("user_name", "") if self._cfg else ""),
|
|
503
|
+
("description", "Descrição", _t("tmpl.desc_default")),
|
|
504
|
+
("dest", _t("templates.field_dest", "Pasta de destino:"), str(Path.home())),
|
|
505
|
+
]
|
|
506
|
+
for key, label, default in labels:
|
|
507
|
+
row = tk.Frame(fields_frame, bg=t.floating_bg)
|
|
508
|
+
row.pack(fill="x", pady=3)
|
|
509
|
+
tk.Label(
|
|
510
|
+
row,
|
|
511
|
+
text=label + ":",
|
|
512
|
+
bg=t.floating_bg,
|
|
513
|
+
fg=t.fg_muted,
|
|
514
|
+
font=(FONT_UI, 8),
|
|
515
|
+
width=18,
|
|
516
|
+
anchor="w",
|
|
517
|
+
).pack(side="left")
|
|
518
|
+
var = tk.StringVar(value=default)
|
|
519
|
+
self._vars[key] = var
|
|
520
|
+
entry = tk.Entry(row, textvariable=var, **ew, width=26)
|
|
521
|
+
entry.pack(side="left", fill="x", expand=True)
|
|
522
|
+
|
|
523
|
+
if key == "dest":
|
|
524
|
+
browse = tk.Label(
|
|
525
|
+
row,
|
|
526
|
+
text="📂",
|
|
527
|
+
bg=t.btn_bg,
|
|
528
|
+
fg=t.fg,
|
|
529
|
+
font=(FONT_UI, 9),
|
|
530
|
+
cursor="hand2",
|
|
531
|
+
padx=4,
|
|
532
|
+
pady=1,
|
|
533
|
+
relief="flat",
|
|
534
|
+
)
|
|
535
|
+
browse.pack(side="left", padx=2)
|
|
536
|
+
browse.bind("<Button-1>", lambda _: self._browse_dest())
|
|
537
|
+
|
|
538
|
+
tk.Label(
|
|
539
|
+
right,
|
|
540
|
+
text=_t("tmpl.files_preview"),
|
|
541
|
+
bg=t.floating_bg,
|
|
542
|
+
fg=t.fg_muted,
|
|
543
|
+
font=(FONT_UI, 8),
|
|
544
|
+
).pack(anchor="w", pady=(8, 2))
|
|
545
|
+
|
|
546
|
+
self._preview = tk.Text(
|
|
547
|
+
right,
|
|
548
|
+
bg=t.editor_bg,
|
|
549
|
+
fg=t.fg,
|
|
550
|
+
font=(FONT_MONO, 8),
|
|
551
|
+
relief="flat",
|
|
552
|
+
bd=0,
|
|
553
|
+
state="disabled",
|
|
554
|
+
height=7,
|
|
555
|
+
wrap="none",
|
|
556
|
+
cursor="arrow",
|
|
557
|
+
padx=4,
|
|
558
|
+
pady=4,
|
|
559
|
+
)
|
|
560
|
+
self._preview.pack(fill="both", expand=True)
|
|
561
|
+
|
|
562
|
+
tk.Frame(self, bg=t.border, height=1).pack(fill="x", padx=14)
|
|
563
|
+
|
|
564
|
+
foot = tk.Frame(self, bg=t.floating_bg)
|
|
565
|
+
foot.pack(fill="x", padx=14, pady=8)
|
|
566
|
+
|
|
567
|
+
self._status = tk.Label(
|
|
568
|
+
foot, text="", bg=t.floating_bg, fg=t.fg_muted, font=(FONT_UI, 8)
|
|
569
|
+
)
|
|
570
|
+
self._status.pack(side="left")
|
|
571
|
+
|
|
572
|
+
for text, cmd, primary in (
|
|
573
|
+
(_t("tmpl.create_btn"), self._create_project, True),
|
|
574
|
+
(_t("tmpl.close"), self.destroy, False),
|
|
575
|
+
):
|
|
576
|
+
btn = tk.Label(
|
|
577
|
+
foot,
|
|
578
|
+
text=text,
|
|
579
|
+
bg=t.btn_primary if primary else t.btn_bg,
|
|
580
|
+
fg=t.btn_primary_fg if primary else t.fg,
|
|
581
|
+
font=(FONT_UI, 9, "bold" if primary else "normal"),
|
|
582
|
+
cursor="hand2",
|
|
583
|
+
padx=12,
|
|
584
|
+
pady=4,
|
|
585
|
+
relief="flat",
|
|
586
|
+
)
|
|
587
|
+
btn.pack(side="right", padx=3)
|
|
588
|
+
btn.bind("<Button-1>", lambda _, c=cmd: c())
|
|
589
|
+
|
|
590
|
+
self._filtered: list[dict[str, Any]] = []
|
|
591
|
+
|
|
592
|
+
def _populate(self) -> None:
|
|
593
|
+
cat = self._category_var.get()
|
|
594
|
+
self._listbox.delete(0, "end")
|
|
595
|
+
self._filtered = [
|
|
596
|
+
t_
|
|
597
|
+
for t_ in self._store.all_templates()
|
|
598
|
+
if cat == "Todos" or t_.get("category") == cat
|
|
599
|
+
]
|
|
600
|
+
for t_ in self._filtered:
|
|
601
|
+
self._listbox.insert("end", f" {t_['label']}")
|
|
602
|
+
|
|
603
|
+
def _on_select(self, _e: Any = None) -> None:
|
|
604
|
+
sel = self._listbox.curselection()
|
|
605
|
+
if not sel or sel[0] >= len(self._filtered):
|
|
606
|
+
return
|
|
607
|
+
self._selected = self._filtered[sel[0]]
|
|
608
|
+
self._desc_lbl.config(text=self._selected.get("description", ""))
|
|
609
|
+
self._update_preview()
|
|
610
|
+
|
|
611
|
+
def _update_preview(self) -> None:
|
|
612
|
+
if not self._selected:
|
|
613
|
+
return
|
|
614
|
+
files = self._selected.get("files", {})
|
|
615
|
+
lines = []
|
|
616
|
+
if "_dir" in self._selected:
|
|
617
|
+
src = Path(self._selected["_dir"])
|
|
618
|
+
for p in sorted(src.rglob("*")):
|
|
619
|
+
if p.name == "template.json":
|
|
620
|
+
continue
|
|
621
|
+
rel = p.relative_to(src)
|
|
622
|
+
prefix = "📁 " if p.is_dir() else " 📄 "
|
|
623
|
+
lines.append(f" {prefix}{rel}")
|
|
624
|
+
else:
|
|
625
|
+
for path in sorted(files.keys()):
|
|
626
|
+
lines.append(f" 📄 {path}")
|
|
627
|
+
|
|
628
|
+
self._preview.config(state="normal")
|
|
629
|
+
self._preview.delete("1.0", "end")
|
|
630
|
+
self._preview.insert("1.0", "\n".join(lines))
|
|
631
|
+
self._preview.config(state="disabled")
|
|
632
|
+
|
|
633
|
+
def _browse_dest(self) -> None:
|
|
634
|
+
path = filedialog.askdirectory(
|
|
635
|
+
parent=self, title=_t("tmpl.dest_dialog_title"))
|
|
636
|
+
if path:
|
|
637
|
+
self._vars["dest"].set(path)
|
|
638
|
+
|
|
639
|
+
def _create_project(self) -> None:
|
|
640
|
+
if not self._selected:
|
|
641
|
+
self._status.config(text=_t("tmpl.no_select"))
|
|
642
|
+
return
|
|
643
|
+
|
|
644
|
+
name = self._vars["name"].get().strip()
|
|
645
|
+
author = self._vars["author"].get().strip()
|
|
646
|
+
desc = self._vars["description"].get().strip()
|
|
647
|
+
dest_base = Path(self._vars["dest"].get().strip())
|
|
648
|
+
|
|
649
|
+
if not name:
|
|
650
|
+
self._status.config(text=_t("tmpl.no_name"))
|
|
651
|
+
return
|
|
652
|
+
|
|
653
|
+
dest = dest_base / name
|
|
654
|
+
if dest.exists() and not messagebox.askyesno(
|
|
655
|
+
_t("tmpl.overwrite_title"),
|
|
656
|
+
f"'{dest}' já existe. Sobrescrever arquivos?",
|
|
657
|
+
parent=self,
|
|
658
|
+
):
|
|
659
|
+
return
|
|
660
|
+
|
|
661
|
+
vars_ = _make_vars(name, author, desc)
|
|
662
|
+
|
|
663
|
+
try:
|
|
664
|
+
created = self._store.create_project(self._selected, dest, vars_)
|
|
665
|
+
self._status.config(
|
|
666
|
+
text=_t("tmpl.created_status", n=len(created), name=dest.name)
|
|
667
|
+
)
|
|
668
|
+
except Exception as exc:
|
|
669
|
+
messagebox.showerror(_t("tmpl.err_create"), str(exc), parent=self)
|
|
670
|
+
return
|
|
671
|
+
|
|
672
|
+
if messagebox.askyesno(
|
|
673
|
+
_t("tmpl.open_prompt_title"),
|
|
674
|
+
f"Projeto criado em:\n{dest}\n\nAbrir agora no Codis?",
|
|
675
|
+
parent=self,
|
|
676
|
+
):
|
|
677
|
+
self.destroy()
|
|
678
|
+
self._on_open(dest)
|
|
679
|
+
|
|
680
|
+
def _save_as_template(self) -> None:
|
|
681
|
+
t = self._tmgr.theme
|
|
682
|
+
src = filedialog.askdirectory(
|
|
683
|
+
parent=self, title=_t("templates.select_folder"))
|
|
684
|
+
if not src:
|
|
685
|
+
return
|
|
686
|
+
|
|
687
|
+
dlg = tk.Toplevel(self)
|
|
688
|
+
dlg.title(_t("tmpl.save_title"))
|
|
689
|
+
dlg.configure(bg=t.floating_bg)
|
|
690
|
+
dlg.geometry("380x260")
|
|
691
|
+
dlg.transient(self)
|
|
692
|
+
safe_grab_set(dlg)
|
|
693
|
+
dlg.resizable(False, False)
|
|
694
|
+
|
|
695
|
+
ew = {
|
|
696
|
+
"bg": t.input_bg,
|
|
697
|
+
"fg": t.fg,
|
|
698
|
+
"insertbackground": t.cursor,
|
|
699
|
+
"relief": "flat",
|
|
700
|
+
"bd": 0,
|
|
701
|
+
"font": (FONT_MONO, 10),
|
|
702
|
+
"highlightthickness": 1,
|
|
703
|
+
"highlightbackground": t.border,
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
meta_vars: dict[str, tk.StringVar] = {}
|
|
707
|
+
for key, label, default in [
|
|
708
|
+
("id", _t("tmpl.save_field_id"), Path(
|
|
709
|
+
src).name.lower().replace(" ", "_")),
|
|
710
|
+
("label", _t("tmpl.save_field_label"), Path(src).name),
|
|
711
|
+
("description", "Descrição", ""),
|
|
712
|
+
("category", _t("tmpl.save_field_cat"),
|
|
713
|
+
_t("tmpl.save_category_custom")),
|
|
714
|
+
]:
|
|
715
|
+
row = tk.Frame(dlg, bg=t.floating_bg)
|
|
716
|
+
row.pack(fill="x", padx=14, pady=4)
|
|
717
|
+
tk.Label(
|
|
718
|
+
row,
|
|
719
|
+
text=label + ":",
|
|
720
|
+
bg=t.floating_bg,
|
|
721
|
+
fg=t.fg_muted,
|
|
722
|
+
font=(FONT_UI, 8),
|
|
723
|
+
width=14,
|
|
724
|
+
anchor="w",
|
|
725
|
+
).pack(side="left")
|
|
726
|
+
var = tk.StringVar(value=default)
|
|
727
|
+
meta_vars[key] = var
|
|
728
|
+
tk.Entry(row, textvariable=var, **ew).pack(
|
|
729
|
+
side="left", fill="x", expand=True
|
|
730
|
+
)
|
|
731
|
+
|
|
732
|
+
def _do_save() -> None:
|
|
733
|
+
meta = {k: v.get().strip() for k, v in meta_vars.items()}
|
|
734
|
+
if not meta["id"]:
|
|
735
|
+
return
|
|
736
|
+
try:
|
|
737
|
+
self._store.save_folder_as_template(Path(src), meta)
|
|
738
|
+
dlg.destroy()
|
|
739
|
+
self._populate()
|
|
740
|
+
self._status.config(
|
|
741
|
+
text=_t("tmpl.saved_status", label=meta["label"]))
|
|
742
|
+
except Exception as exc:
|
|
743
|
+
messagebox.showerror(
|
|
744
|
+
_t("templates.err_title", "Erro ao criar projeto"),
|
|
745
|
+
str(exc),
|
|
746
|
+
parent=dlg,
|
|
747
|
+
)
|
|
748
|
+
|
|
749
|
+
btn_row = tk.Frame(dlg, bg=t.floating_bg)
|
|
750
|
+
btn_row.pack(pady=10)
|
|
751
|
+
for text, cmd, primary in (
|
|
752
|
+
(_t("tmpl.save_btn"), _do_save, True),
|
|
753
|
+
(_t("tmpl.cancel"), dlg.destroy, False),
|
|
754
|
+
):
|
|
755
|
+
btn = tk.Label(
|
|
756
|
+
btn_row,
|
|
757
|
+
text=text,
|
|
758
|
+
bg=t.btn_primary if primary else t.btn_bg,
|
|
759
|
+
fg=t.btn_primary_fg if primary else t.fg,
|
|
760
|
+
font=(FONT_UI, 9),
|
|
761
|
+
cursor="hand2",
|
|
762
|
+
padx=10,
|
|
763
|
+
pady=4,
|
|
764
|
+
relief="flat",
|
|
765
|
+
)
|
|
766
|
+
btn.pack(side="left", padx=4)
|
|
767
|
+
btn.bind("<Button-1>", lambda _, c=cmd: c())
|
|
768
|
+
|
|
769
|
+
def _center(self, parent: tk.Widget) -> None:
|
|
770
|
+
self.update_idletasks()
|
|
771
|
+
with contextlib.suppress(tk.TclError):
|
|
772
|
+
px, py = parent.winfo_rootx(), parent.winfo_rooty()
|
|
773
|
+
pw, ph = parent.winfo_width(), parent.winfo_height()
|
|
774
|
+
w, h = self.winfo_width(), self.winfo_height()
|
|
775
|
+
self.geometry(f"+{px + (pw - w) // 2}+{py + (ph - h) // 2}")
|