|
1 | 1 | import dearpygui.dearpygui as dpg |
2 | | -from ._extractionTab import refreshContourExtractionTranslations, showContourExtraction |
3 | | -from ._filteringTab import refreshFilteringTranslations, showFiltering |
4 | | -from ._meshTab import refreshMeshTranslations, showMeshGeneration |
5 | | -from ._processingTab import refreshProcessingTranslations, showProcessing |
6 | | -from ._thresholdingTab import refreshThresholdingTranslations, showThresholding |
7 | | -from ._interpolationTab import refreshInterpolationTranslations, showInterpolation |
8 | | -from ._theme import applyTheme |
| 2 | + |
9 | 3 | from . import strings |
| 4 | +from ._extractionTab import showContourExtraction |
| 5 | +from ._filteringTab import showFiltering |
| 6 | +from ._interpolationTab import showInterpolation |
| 7 | +from ._meshTab import showMeshGeneration |
| 8 | +from ._processingTab import showProcessing |
| 9 | +from ._theme import DEFAULT_THEME, apply_theme, bind_startup_themes |
| 10 | +from ._thresholdingTab import showThresholding |
| 11 | + |
| 12 | + |
| 13 | +VIEWPORT_WIDTH = 1120 |
| 14 | +VIEWPORT_HEIGHT = 720 |
| 15 | +VIEWPORT_MIN_WIDTH = 980 |
| 16 | +VIEWPORT_MIN_HEIGHT = 680 |
10 | 17 |
|
11 | | -""" |
12 | | - A classe Interface é responsável por gerar os elementos visuais do programa. |
13 | | - O uso da biblioteca DearPyGUI faz com que seja possível executar o programa em windows ou linux |
14 | | - e ainda utilizar dos benefícios da acerelação de hardware. |
15 | | -""" |
16 | | -class Interface: |
17 | 18 |
|
18 | | - """ |
19 | | - Define os parâmetros e inicia a função Show. |
20 | | - """ |
| 19 | +class Interface: |
21 | 20 | def __init__(self, callbacks) -> None: |
22 | 21 | self.callbacks = callbacks |
| 22 | + self.selected_locale = strings.get_locale() |
| 23 | + self.selected_theme = DEFAULT_THEME |
| 24 | + self.main_initialized = False |
23 | 25 | self.show() |
24 | | - pass |
25 | 26 |
|
26 | | - """ |
27 | | - Cria o contexto e a janela do DPG e invoca a função showTabBar para a renderização de cada uma das tabs e seus conteúdos. |
28 | | - """ |
29 | 27 | def show(self): |
30 | 28 | dpg.create_context() |
31 | | - dpg.create_viewport(title=strings.t("app.title"), width=900, height=600, min_height=600, min_width=900) |
| 29 | + dpg.create_viewport( |
| 30 | + title=strings.t("app.title"), |
| 31 | + width=VIEWPORT_WIDTH, |
| 32 | + height=VIEWPORT_HEIGHT, |
| 33 | + min_width=VIEWPORT_MIN_WIDTH, |
| 34 | + min_height=VIEWPORT_MIN_HEIGHT, |
| 35 | + ) |
| 36 | + |
| 37 | + apply_theme(self.selected_theme) |
| 38 | + self.showStartupScreen() |
32 | 39 |
|
33 | | - with dpg.window(tag="Main"): |
34 | | - applyTheme() |
35 | | - with dpg.group(horizontal=True): |
36 | | - dpg.add_text(strings.t("app.language"), tag="languageLabel") |
37 | | - dpg.add_combo( |
38 | | - strings.available_locales(), |
39 | | - default_value=strings.get_locale(), |
40 | | - width=140, |
41 | | - tag="languageSelector", |
42 | | - callback=self.changeLocale, |
43 | | - ) |
44 | | - self.showTabBar() |
45 | | - self.createSaveImageDialog() |
46 | | - pass |
47 | | - |
48 | 40 | dpg.setup_dearpygui() |
49 | 41 | dpg.show_viewport() |
50 | | - dpg.set_primary_window("Main", True) |
| 42 | + dpg.set_primary_window("Startup", True) |
51 | 43 | dpg.start_dearpygui() |
52 | 44 | dpg.destroy_context() |
53 | | - pass |
54 | 45 |
|
55 | | - """ |
56 | | - Responsável pela invocação das tabs individuais. |
57 | | - """ |
| 46 | + def showStartupScreen(self): |
| 47 | + with dpg.window( |
| 48 | + tag="Startup", |
| 49 | + no_title_bar=True, |
| 50 | + no_resize=True, |
| 51 | + no_move=True, |
| 52 | + no_collapse=True, |
| 53 | + width=VIEWPORT_WIDTH, |
| 54 | + height=VIEWPORT_HEIGHT, |
| 55 | + pos=(0, 0), |
| 56 | + ): |
| 57 | + dpg.add_spacer(height=90) |
| 58 | + with dpg.group(horizontal=True): |
| 59 | + dpg.add_spacer(width=330) |
| 60 | + with dpg.child_window(tag="startupCard", width=460, height=420, border=True): |
| 61 | + dpg.add_text(strings.t("startup.eyebrow"), tag="startupEyebrow") |
| 62 | + dpg.add_spacer(height=6) |
| 63 | + dpg.add_text(strings.t("app.title"), tag="startupAppTitle") |
| 64 | + dpg.add_text(strings.t("startup.subtitle"), tag="startupSubtitle", wrap=410) |
| 65 | + dpg.add_separator() |
| 66 | + dpg.add_text(strings.t("startup.language"), tag="startupLanguageLabel") |
| 67 | + dpg.add_combo( |
| 68 | + strings.available_locales(), |
| 69 | + default_value=self.selected_locale, |
| 70 | + width=-1, |
| 71 | + tag="startupLanguageSelector", |
| 72 | + callback=self.changeStartupLocale, |
| 73 | + ) |
| 74 | + dpg.add_text(strings.t("startup.theme"), tag="startupThemeLabel") |
| 75 | + dpg.add_combo( |
| 76 | + strings.option_labels("theme"), |
| 77 | + default_value=strings.option_label("theme", self.selected_theme), |
| 78 | + width=-1, |
| 79 | + tag="startupThemeSelector", |
| 80 | + callback=self.changeStartupTheme, |
| 81 | + ) |
| 82 | + dpg.add_spacer(height=10) |
| 83 | + dpg.add_button( |
| 84 | + tag="startupEnterButton", |
| 85 | + width=-1, |
| 86 | + label=strings.t("startup.enter"), |
| 87 | + callback=self.launchMainApp, |
| 88 | + ) |
| 89 | + |
| 90 | + bind_startup_themes() |
| 91 | + |
| 92 | + def launchMainApp(self, sender=None, app_data=None): |
| 93 | + if self.main_initialized: |
| 94 | + return |
| 95 | + |
| 96 | + self.main_initialized = True |
| 97 | + apply_theme(self.selected_theme) |
| 98 | + self.showMainWindow() |
| 99 | + dpg.set_primary_window("Main", True) |
| 100 | + dpg.delete_item("Startup") |
| 101 | + |
| 102 | + def showMainWindow(self): |
| 103 | + with dpg.window(tag="Main"): |
| 104 | + self.showTabBar() |
| 105 | + self.createSaveImageDialog() |
| 106 | + |
58 | 107 | def showTabBar(self): |
59 | 108 | with dpg.tab_bar(): |
60 | 109 | self.showTabs() |
61 | | - pass |
62 | | - |
63 | | - """ |
64 | | - Cria as diferentes tabs do programa e chama o método show<Tab> para popular cada uma das abas. |
65 | | - Processing: Importação e Cropping da imagem. |
66 | | - Filtering: Ajustes em níveis de cor, brilho, contraste e blurring na imagem. |
67 | | - Thresholding: Ajustes na binarização da imagem. Para que a binarização ocorra a imagem é automaticamente convertida para tons de cinza. |
68 | | - Contour Extraction: Extrai o contorno dos objetos presentes na imagem binarizada. Permite a exportação do arquivo .txt com os dados do contorno. |
69 | | - Mesh Generation: Gera a malha e possibilita as configurações necessária para método matemáticos com os pontos resultantes da aba anterior. Permite a importação de novos pontos. |
70 | | - """ |
| 110 | + |
71 | 111 | def showTabs(self): |
72 | | - dpg.add_texture_registry(show=False, tag='textureRegistry') |
| 112 | + dpg.add_texture_registry(show=False, tag="textureRegistry") |
73 | 113 | with dpg.tab(tag="processingTab", label=strings.t("app.tabs.processing")): |
74 | 114 | showProcessing(self.callbacks) |
75 | | - pass |
76 | 115 | with dpg.tab(tag="filteringTab", label=strings.t("app.tabs.filtering")): |
77 | 116 | showFiltering(self.callbacks) |
78 | | - pass |
79 | 117 | with dpg.tab(tag="thresholdingTab", label=strings.t("app.tabs.thresholding")): |
80 | 118 | showThresholding(self.callbacks) |
81 | | - pass |
82 | 119 | with dpg.tab(tag="contourExtractionTab", label=strings.t("app.tabs.contour_extraction")): |
83 | 120 | showContourExtraction(self.callbacks) |
84 | | - pass |
85 | 121 | with dpg.tab(tag="interpolationTab", label=strings.t("app.tabs.interpolation")): |
86 | 122 | showInterpolation(self.callbacks) |
87 | | - pass |
88 | 123 | with dpg.tab(tag="meshGenerationTab", label=strings.t("app.tabs.mesh_generation")): |
89 | 124 | showMeshGeneration(self.callbacks) |
90 | | - pass |
91 | 125 | self.callbacks.imageProcessing.disableAllTags() |
92 | | - pass |
93 | 126 |
|
94 | 127 | def createSaveImageDialog(self): |
95 | | - with dpg.window(label=strings.t("common.export_image_as_file"), modal=False, show=False, tag="exportImageAsFile", no_title_bar=False, min_size=[600,255]): |
| 128 | + with dpg.window( |
| 129 | + label=strings.t("common.export_image_as_file"), |
| 130 | + modal=False, |
| 131 | + show=False, |
| 132 | + tag="exportImageAsFile", |
| 133 | + no_title_bar=False, |
| 134 | + min_size=[600, 255], |
| 135 | + ): |
96 | 136 | dpg.add_text(strings.t("common.enter_file_name"), tag="exportImageDialogFileNameLabel") |
97 | 137 | dpg.add_input_text(tag="imageNameExportAsFile") |
98 | 138 | dpg.add_separator() |
99 | 139 | dpg.add_text(strings.t("common.enter_file_name_before_directory"), tag="exportImageDialogDirectoryHint") |
100 | | - dpg.add_button(tag="exportImageDialogSelectDirectory", width=-1, label=strings.t("common.select_directory"), callback=self.callbacks.imageProcessing.exportImageDirectorySelector) |
101 | | - dpg.add_file_dialog(directory_selector=True, min_size=[400,300], show=False, tag='exportImageDirectorySelector', id="exportImageDirectorySelector", callback=lambda sender, app_data: self.callbacks.imageProcessing.exportImageSelectDirectory(sender, app_data)) |
| 140 | + dpg.add_button( |
| 141 | + tag="exportImageDialogSelectDirectory", |
| 142 | + width=-1, |
| 143 | + label=strings.t("common.select_directory"), |
| 144 | + callback=self.callbacks.imageProcessing.exportImageDirectorySelector, |
| 145 | + ) |
| 146 | + dpg.add_file_dialog( |
| 147 | + directory_selector=True, |
| 148 | + min_size=[400, 300], |
| 149 | + show=False, |
| 150 | + tag="exportImageDirectorySelector", |
| 151 | + id="exportImageDirectorySelector", |
| 152 | + callback=lambda sender, app_data: self.callbacks.imageProcessing.exportImageSelectDirectory(sender, app_data), |
| 153 | + ) |
102 | 154 | dpg.add_separator() |
103 | 155 | dpg.add_text(strings.fmt("file_name", value=""), tag="exportImageFileName") |
104 | 156 | dpg.add_text(strings.fmt("full_path", value=""), tag="exportImageFilePath") |
105 | 157 | with dpg.group(horizontal=True): |
106 | | - dpg.add_button(tag="exportImageDialogSave", label=strings.t("common.save"), width=-1, callback=self.callbacks.imageProcessing.exportImageAsFile) |
107 | | - dpg.add_button(tag="exportImageDialogCancel", label=strings.t("common.cancel"), width=-1, callback=lambda: dpg.configure_item("exportImageAsFile", show=False)) |
| 158 | + dpg.add_button( |
| 159 | + tag="exportImageDialogSave", |
| 160 | + label=strings.t("common.save"), |
| 161 | + width=-1, |
| 162 | + callback=self.callbacks.imageProcessing.exportImageAsFile, |
| 163 | + ) |
| 164 | + dpg.add_button( |
| 165 | + tag="exportImageDialogCancel", |
| 166 | + label=strings.t("common.cancel"), |
| 167 | + width=-1, |
| 168 | + callback=lambda: dpg.configure_item("exportImageAsFile", show=False), |
| 169 | + ) |
108 | 170 | dpg.add_text(strings.t("common.missing_file_name_or_directory"), tag="exportImageError", show=False) |
109 | 171 |
|
110 | | - def changeLocale(self, sender=None, app_data=None): |
111 | | - old_locale = strings.get_locale() |
112 | | - strings.set_locale(app_data) |
113 | | - self.refreshTranslations(old_locale) |
| 172 | + def changeStartupLocale(self, sender=None, app_data=None): |
| 173 | + self.selected_locale = strings.set_locale(app_data) |
| 174 | + self.refreshStartupTranslations() |
| 175 | + |
| 176 | + def changeStartupTheme(self, sender=None, app_data=None): |
| 177 | + self.selected_theme = strings.option_key("theme", app_data) |
| 178 | + apply_theme(self.selected_theme) |
| 179 | + bind_startup_themes() |
114 | 180 |
|
115 | | - def refreshTranslations(self, old_locale=None): |
| 181 | + def refreshStartupTranslations(self): |
116 | 182 | dpg.set_viewport_title(strings.t("app.title")) |
117 | | - dpg.set_value("languageLabel", strings.t("app.language")) |
118 | | - dpg.configure_item("processingTab", label=strings.t("app.tabs.processing")) |
119 | | - dpg.configure_item("filteringTab", label=strings.t("app.tabs.filtering")) |
120 | | - dpg.configure_item("thresholdingTab", label=strings.t("app.tabs.thresholding")) |
121 | | - dpg.configure_item("contourExtractionTab", label=strings.t("app.tabs.contour_extraction")) |
122 | | - dpg.configure_item("interpolationTab", label=strings.t("app.tabs.interpolation")) |
123 | | - dpg.configure_item("meshGenerationTab", label=strings.t("app.tabs.mesh_generation")) |
124 | | - |
125 | | - dpg.configure_item("exportImageAsFile", label=strings.t("common.export_image_as_file")) |
126 | | - dpg.set_value("exportImageDialogFileNameLabel", strings.t("common.enter_file_name")) |
127 | | - dpg.set_value("exportImageDialogDirectoryHint", strings.t("common.enter_file_name_before_directory")) |
128 | | - dpg.configure_item("exportImageDialogSelectDirectory", label=strings.t("common.select_directory")) |
129 | | - dpg.configure_item("exportImageDialogSave", label=strings.t("common.save")) |
130 | | - dpg.configure_item("exportImageDialogCancel", label=strings.t("common.cancel")) |
131 | | - dpg.set_value("exportImageError", strings.t("common.missing_file_name_or_directory")) |
132 | | - |
133 | | - refreshProcessingTranslations() |
134 | | - refreshFilteringTranslations() |
135 | | - refreshThresholdingTranslations(old_locale) |
136 | | - refreshContourExtractionTranslations(old_locale) |
137 | | - refreshInterpolationTranslations(old_locale) |
138 | | - refreshMeshTranslations(old_locale) |
139 | | - self.callbacks.refreshTranslations(old_locale) |
| 183 | + dpg.set_value("startupEyebrow", strings.t("startup.eyebrow")) |
| 184 | + dpg.set_value("startupAppTitle", strings.t("app.title")) |
| 185 | + dpg.set_value("startupSubtitle", strings.t("startup.subtitle")) |
| 186 | + dpg.set_value("startupLanguageLabel", strings.t("startup.language")) |
| 187 | + dpg.set_value("startupThemeLabel", strings.t("startup.theme")) |
| 188 | + dpg.configure_item("startupThemeSelector", items=strings.option_labels("theme")) |
| 189 | + dpg.set_value("startupThemeSelector", strings.option_label("theme", self.selected_theme)) |
| 190 | + dpg.configure_item("startupEnterButton", label=strings.t("startup.enter")) |
0 commit comments