statable 3.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 (117) hide show
  1. codegen/__init__.py +38 -0
  2. codegen/c_code_generator.py +1752 -0
  3. codegen/code_merger.py +371 -0
  4. codegen/code_templates.py +509 -0
  5. codegen/config.py +167 -0
  6. codegen/enum_generator.py +377 -0
  7. codegen/event_queue_generator.py +303 -0
  8. codegen/interrupt_generator.py +345 -0
  9. codegen/naming_convention.py +171 -0
  10. codegen/osal_generator.py +282 -0
  11. codegen/role_function_generator.py +1244 -0
  12. codegen/sample_data.py +269 -0
  13. codegen/state_actions_generator.py +395 -0
  14. codegen/struct_generator.py +721 -0
  15. codegen/timer_generator.py +299 -0
  16. codegen/transition_generator.py +907 -0
  17. codegen/type_mapper.py +69 -0
  18. codegen/validate/__init__.py +38 -0
  19. codegen/validate/change_actions.py +90 -0
  20. codegen/validate/change_applier.py +416 -0
  21. codegen/validate/clipboard_manager.py +47 -0
  22. codegen/validate/data/__init__.py +30 -0
  23. codegen/validate/data/action_definitions.py +200 -0
  24. codegen/validate/data/keywords.py +46 -0
  25. codegen/validate/data/prompt_templates.py +176 -0
  26. codegen/validate/data/validation_rules.py +205 -0
  27. codegen/validate/items/__init__.py +30 -0
  28. codegen/validate/items/base_validator.py +25 -0
  29. codegen/validate/items/cell_validator.py +275 -0
  30. codegen/validate/items/custom_type_validator.py +75 -0
  31. codegen/validate/items/event_validator.py +78 -0
  32. codegen/validate/items/flag_validator.py +74 -0
  33. codegen/validate/items/interrupt_validator.py +75 -0
  34. codegen/validate/items/queue_validator.py +73 -0
  35. codegen/validate/items/role_function_validator.py +175 -0
  36. codegen/validate/items/state_validator.py +88 -0
  37. codegen/validate/items/timer_validator.py +120 -0
  38. codegen/validate/items/transition_validator.py +113 -0
  39. codegen/validate/items/variable_validator.py +132 -0
  40. codegen/validate/logger.py +52 -0
  41. codegen/validate/models.py +177 -0
  42. codegen/validate/prompt_generator.py +724 -0
  43. codegen/validate/response_parser.py +154 -0
  44. codegen/validate/response_validator.py +275 -0
  45. codegen/validate/validation_dialog.py +322 -0
  46. codegen/validate/validator.py +94 -0
  47. codegen/variable_generator.py +419 -0
  48. statable/__init__.py +71 -0
  49. statable/__main__.py +49 -0
  50. statable/cli.py +251 -0
  51. statable/global_defs.py +256 -0
  52. statable/mermaid_gen.py +144 -0
  53. statable/model.py +426 -0
  54. statable/parser.py +64 -0
  55. statable/sample_data.py +435 -0
  56. statable/shared/__init__.py +24 -0
  57. statable/shared/condition_library.py +63 -0
  58. statable/shared/literal_library.py +66 -0
  59. statable/shared/role_function_library.py +150 -0
  60. statable/state_machine.py +121 -0
  61. statable/xml_io.py +1164 -0
  62. statable-3.1.0.dist-info/METADATA +151 -0
  63. statable-3.1.0.dist-info/RECORD +117 -0
  64. statable-3.1.0.dist-info/WHEEL +5 -0
  65. statable-3.1.0.dist-info/entry_points.txt +2 -0
  66. statable-3.1.0.dist-info/top_level.txt +3 -0
  67. statable_gui/__init__.py +23 -0
  68. statable_gui/action_edit_dialog.py +214 -0
  69. statable_gui/code_generation_dialog.py +486 -0
  70. statable_gui/code_generation_settings_dialog.py +522 -0
  71. statable_gui/common_widgets.py +537 -0
  72. statable_gui/condition_builder_dialog.py +500 -0
  73. statable_gui/condition_edit_dialog.py +123 -0
  74. statable_gui/condition_template_dialog.py +58 -0
  75. statable_gui/config.py +21 -0
  76. statable_gui/dialogs.py +439 -0
  77. statable_gui/event_definition_dialog.py +605 -0
  78. statable_gui/event_delivery_settings_dialog.py +191 -0
  79. statable_gui/event_queue_dialog.py +245 -0
  80. statable_gui/global_defs.py +167 -0
  81. statable_gui/global_defs_dialog.py +796 -0
  82. statable_gui/i18n/__init__.py +118 -0
  83. statable_gui/interrupt_handler_edit_dialog.py +810 -0
  84. statable_gui/layer_settings_dialog.py +180 -0
  85. statable_gui/libcntrl/__init__.py +23 -0
  86. statable_gui/libcntrl/condition_library.py +13 -0
  87. statable_gui/libcntrl/literal_library.py +13 -0
  88. statable_gui/libcntrl/literal_management_dialog.py +185 -0
  89. statable_gui/libcntrl/role_function_edit_dialog.py +145 -0
  90. statable_gui/libcntrl/role_function_library.py +13 -0
  91. statable_gui/literal_definition_dialog.py +62 -0
  92. statable_gui/logger.py +83 -0
  93. statable_gui/main_window.py +1380 -0
  94. statable_gui/matrix_table.py +413 -0
  95. statable_gui/preference_keys.py +18 -0
  96. statable_gui/preferences.py +74 -0
  97. statable_gui/role_function_dialog.py +244 -0
  98. statable_gui/sample_data.py +11 -0
  99. statable_gui/state_actions_dialog.py +398 -0
  100. statable_gui/symbol_picker.py +170 -0
  101. statable_gui/traceball.py +37 -0
  102. statable_gui/transition_editor_direct/__init__.py +15 -0
  103. statable_gui/transition_editor_direct/actions_tab.py +856 -0
  104. statable_gui/transition_editor_direct/code_widget.py +344 -0
  105. statable_gui/transition_editor_direct/coverage_analyzer.py +163 -0
  106. statable_gui/transition_editor_direct/dialog.py +335 -0
  107. statable_gui/transition_editor_direct/draft.py +270 -0
  108. statable_gui/transition_editor_direct/edit_dialogs.py +160 -0
  109. statable_gui/transition_editor_direct/overview_tab.py +173 -0
  110. statable_gui/transition_editor_direct/palette_widget.py +233 -0
  111. statable_gui/transition_editor_direct/relations_edit_dialog.py +156 -0
  112. statable_gui/transition_editor_direct/relations_tab.py +230 -0
  113. statable_gui/transition_editor_direct/system_global_dialog.py +52 -0
  114. statable_gui/transition_editor_direct/transition_actions_dialog.py +109 -0
  115. statable_gui/transition_editor_direct/transitions_tab.py +620 -0
  116. statable_gui/validation_dialog.py +285 -0
  117. statable_gui/widgets.py +1315 -0
@@ -0,0 +1,118 @@
1
+ # statable_gui/i18n/__init__.py
2
+ """Internationalization support for StaTable GUI.
3
+
4
+ Loads .qm translation files from this directory.
5
+
6
+ Supported languages:
7
+ en - English (default, no translation file needed)
8
+ ja - Japanese
9
+ zh_CN - Chinese (Simplified)
10
+
11
+ Usage in gui_main.py or statable_gui/main_window.py:
12
+ from statable_gui.i18n import install_translator
13
+ install_translator(app)
14
+ """
15
+ from __future__ import annotations
16
+
17
+ from pathlib import Path
18
+ from typing import Optional
19
+
20
+ from PySide6.QtCore import (
21
+ QTranslator,
22
+ QLocale,
23
+ QSettings,
24
+ QLibraryInfo,
25
+ )
26
+ from PySide6.QtWidgets import QApplication
27
+
28
+ I18N_DIR = Path(__file__).parent
29
+ DEFAULT_LANG = "en"
30
+ SUPPORTED_LANGUAGES = ["en", "zh_CN"]
31
+ LANG_DISPLAY = {
32
+ "en": "English",
33
+ "zh_CN": "\u7b80\u4f53\u4e2d\u6587",
34
+ }
35
+
36
+
37
+ def available_languages() -> list[str]:
38
+ """Return list of supported language codes."""
39
+ return list(SUPPORTED_LANGUAGES)
40
+
41
+
42
+ def _qm_path(lang: str) -> Path:
43
+ return I18N_DIR / f"statable_{lang}.qm"
44
+
45
+
46
+ def detect_system_language() -> str:
47
+ """Return best-matching language for the current system locale."""
48
+ sys_lang = QLocale.system().name() # e.g. "ja_JP", "zh_CN"
49
+ for lang in SUPPORTED_LANGUAGES:
50
+ if lang == DEFAULT_LANG:
51
+ continue
52
+ short = lang.split("_")[0]
53
+ if sys_lang.startswith(lang) or sys_lang.startswith(short):
54
+ return lang
55
+ return DEFAULT_LANG
56
+
57
+
58
+ def load_preferred_language() -> str:
59
+ """Load user preference from QSettings, fallback to system."""
60
+ settings = QSettings("StaTable", "StaTable")
61
+ lang = settings.value("ui/language", "")
62
+ if lang and lang in SUPPORTED_LANGUAGES:
63
+ return lang
64
+ return detect_system_language()
65
+
66
+
67
+ def save_preferred_language(lang: str) -> None:
68
+ """Persist user preference."""
69
+ if lang not in SUPPORTED_LANGUAGES:
70
+ return
71
+ settings = QSettings("StaTable", "StaTable")
72
+ settings.setValue("ui/language", lang)
73
+
74
+
75
+ def install_translator(app: QApplication,
76
+ lang: Optional[str] = None) -> Optional[QTranslator]:
77
+ """Install translator for the given language.
78
+
79
+ Returns the installed QTranslator (kept alive by reference on app),
80
+ or None if no translation file was loaded (e.g. English).
81
+ """
82
+ if lang is None:
83
+ lang = load_preferred_language()
84
+ if lang not in SUPPORTED_LANGUAGES or lang == DEFAULT_LANG:
85
+ return None
86
+
87
+ qm = _qm_path(lang)
88
+ if not qm.exists():
89
+ return None
90
+
91
+ translator = QTranslator()
92
+ if not translator.load(str(qm)):
93
+ return None
94
+ app.installTranslator(translator)
95
+
96
+ # Install Qt's own translations for built-in dialogs
97
+ qt_tr = QTranslator()
98
+ qt_path = QLibraryInfo.path(QLibraryInfo.TranslationsPath)
99
+ if qt_tr.load(f"qtbase_{lang}", qt_path):
100
+ app.installTranslator(qt_tr)
101
+ # keep reference alive
102
+ translator._qt_translator = qt_tr # noqa: SLF001
103
+
104
+ # keep reference so Python doesn't GC it
105
+ app._statable_translator = translator # noqa: SLF001
106
+ return translator
107
+
108
+
109
+ __all__ = [
110
+ "install_translator",
111
+ "available_languages",
112
+ "detect_system_language",
113
+ "load_preferred_language",
114
+ "save_preferred_language",
115
+ "DEFAULT_LANG",
116
+ "SUPPORTED_LANGUAGES",
117
+ "LANG_DISPLAY",
118
+ ]