Skip to content

Commit

Permalink
Merge pull request #840 from Giswater/dev-3.5
Browse files Browse the repository at this point in the history
Dev 3.5
  • Loading branch information
edgarfuste authored Nov 25, 2021
2 parents 62e0adc + 05d7867 commit fddc4ca
Show file tree
Hide file tree
Showing 13 changed files with 216 additions and 169 deletions.
4 changes: 4 additions & 0 deletions config/user_params.config
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ _dlg_workspace_manager_width = None
_dlg_workspace_manager_height = None
_dlg_workspace_create_width = None
_dlg_workspace_create_height = None
dlg_load_menu_width = None
dlg_load_menu_height = None

[session.dialogs_position]
dlg_admin_translation_x = None
Expand Down Expand Up @@ -381,6 +383,8 @@ _dlg_workspace_manager_x = None
_dlg_workspace_manager_y = None
_dlg_workspace_create_x = None
_dlg_workspace_create_y = None
dlg_load_menu_x = None
dlg_load_menu_y = None

[session.dialogs_tab]
_dlg_selector_basic = None
Expand Down
5 changes: 1 addition & 4 deletions core/load_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from .ui.ui_manager import GwDialogTextUi, GwSearchUi
from .shared.search import GwSearch
from .utils import tools_gw
from .load_project_menu import GwMenuLoad
from .load_project_check import GwLoadProjectCheck
from .threads.project_layers_config import GwProjectLayersConfig
from .threads.notify import GwNotify
Expand Down Expand Up @@ -111,8 +110,7 @@ def project_read(self, show_warning=True):
global_vars.feature_cat = tools_gw.manage_feature_cat()

# Create menu
load_project_menu = GwMenuLoad()
load_project_menu.read_menu()
tools_gw.create_giswater_menu(True)

# Manage snapping layers
self._manage_snapping_layers()
Expand Down Expand Up @@ -160,7 +158,6 @@ def project_read(self, show_warning=True):
# Call gw_fct_setcheckproject and create GwProjectLayersConfig thread
self._config_layers()


# region private functions

def _check_version_compatibility(self):
Expand Down
8 changes: 5 additions & 3 deletions core/load_project_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,11 @@ def _execute_check_project_function(self, init_project, fields_to_insert):
tools_qgis.show_warning(message)

# Get log folder size
log_folder = os.path.join(global_vars.user_folder_dir, 'log')
size = tools_os.get_folder_size(log_folder)
log_folder_volume = f"{round(size / (1024*1024), 2)} MB"
log_folder_volume = 0
if global_vars.user_folder_dir:
log_folder = os.path.join(global_vars.user_folder_dir, 'log')
size = tools_os.get_folder_size(log_folder)
log_folder_volume = f"{round(size / (1024*1024), 2)} MB"

extras = f'"version":"{plugin_version}"'
extras += f', "fid":101'
Expand Down
208 changes: 104 additions & 104 deletions core/load_project_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self):
self.iface = global_vars.iface


def read_menu(self):
def read_menu(self, project_loaded):
""" """

actions = self.iface.mainWindow().menuBar().actions()
Expand All @@ -45,101 +45,102 @@ def read_menu(self):
icon_path = f"{icon_folder}{os.sep}toolbars{os.sep}utilities{os.sep}99.png"
config_icon = QIcon(icon_path)

# region Toolbar
toolbars_menu = QMenu(f"Toolbars", self.iface.mainWindow().menuBar())
icon_path = f"{icon_folder}{os.sep}dialogs{os.sep}20x20{os.sep}36.png"
toolbars_icon = QIcon(icon_path)
toolbars_menu.setIcon(toolbars_icon)
self.main_menu.addMenu(toolbars_menu)

for toolbar in global_vars.giswater_settings.value(f"toolbars/list_toolbars"):
toolbar_submenu = QMenu(f"{toolbar}", self.iface.mainWindow().menuBar())
toolbars_menu.addMenu(toolbar_submenu)
buttons_toolbar = global_vars.giswater_settings.value(f"toolbars/{toolbar}")
project_exclusive = tools_gw.get_config_parser('project_exclusive', str(global_vars.project_type),
"project", "giswater")
if project_exclusive not in (None, 'None'):
project_exclusive = project_exclusive.replace(' ', '').split(',')

for index_action in buttons_toolbar:

if index_action in project_exclusive:
continue

icon_path = f"{icon_folder}{os.sep}toolbars{os.sep}{toolbar}{os.sep}{index_action}.png"
icon = QIcon(icon_path)
button_def = global_vars.giswater_settings.value(f"buttons_def/{index_action}")
text = ""
if button_def:
text = self._translate(f'{index_action}_text')
parent = self.iface.mainWindow()
ag = QActionGroup(parent)
ag.setProperty('gw_name', 'gw_QActionGroup')
if button_def is None:
continue

# Check if the class associated to the button definition exists
if hasattr(buttons, button_def):
button_class = getattr(buttons, button_def)
action_function = button_class(icon_path, button_def, text, None, ag)
action = toolbar_submenu.addAction(icon, f"{text}")
shortcut_key = tools_gw.get_config_parser("toolbars_shortcuts", f"{index_action}", "user", "init", prefix=False)
if shortcut_key:
action.setShortcuts(QKeySequence(f"{shortcut_key}"))
global_vars.shortcut_keys.append(shortcut_key)
action.triggered.connect(partial(self._clicked_event, action_function))
else:
tools_log.log_warning(f"Class '{button_def}' not imported in file '{buttons.__file__}'")
# endregion
if project_loaded:
# region Toolbar
toolbars_menu = QMenu(f"Toolbars", self.iface.mainWindow().menuBar())
icon_path = f"{icon_folder}{os.sep}dialogs{os.sep}20x20{os.sep}36.png"
toolbars_icon = QIcon(icon_path)
toolbars_menu.setIcon(toolbars_icon)
self.main_menu.addMenu(toolbars_menu)

for toolbar in global_vars.giswater_settings.value(f"toolbars/list_toolbars"):
toolbar_submenu = QMenu(f"{toolbar}", self.iface.mainWindow().menuBar())
toolbars_menu.addMenu(toolbar_submenu)
buttons_toolbar = global_vars.giswater_settings.value(f"toolbars/{toolbar}")
project_exclusive = tools_gw.get_config_parser('project_exclusive', str(global_vars.project_type),
"project", "giswater")
if project_exclusive not in (None, 'None'):
project_exclusive = project_exclusive.replace(' ', '').split(',')

for index_action in buttons_toolbar:

if index_action in project_exclusive:
continue

# region Actions
actions_menu = QMenu(f"Actions", self.iface.mainWindow().menuBar())
actions_menu.setIcon(config_icon)
self.main_menu.addMenu(actions_menu)

# Action 'Get help'
action_help = actions_menu.addAction(f"Get help")
action_help_shortcut = tools_gw.get_config_parser("actions_shortcuts", f"shortcut_help", "user", "init", prefix=False)
if not action_help_shortcut:
tools_gw.set_config_parser("actions_shortcuts", f"shortcut_help", f"{action_help_shortcut}", "user", "init",
prefix=False)
action_help.setShortcuts(QKeySequence(f"{action_help_shortcut}"))
action_help.triggered.connect(tools_gw.open_dlg_help)

# Action 'Reset dialogs'
action_reset_dialogs = actions_menu.addAction(f"Reset dialogs")
action_reset_dialogs.triggered.connect(self._reset_position_dialog)

# Action 'Reset plugin
action_reset_plugin = actions_menu.addAction(f"Reset plugin")
action_reset_plugin_shortcut = tools_gw.get_config_parser("actions_shortcuts", f"shortcut_reset_plugin",
"user", "init", prefix=False)
if not action_reset_plugin_shortcut:
tools_gw.set_config_parser("actions_shortcuts", f"shortcut_reset_plugin",
f"{action_reset_plugin_shortcut}", "user", "init", prefix=False)
action_reset_plugin.setShortcuts(QKeySequence(f"{action_reset_plugin_shortcut}"))
action_reset_plugin.triggered.connect(self._reset_plugin)

# Action 'Show current selectors'
action_open_selections = actions_menu.addAction(f"Show current selectors")
action_open_selections_shortcut = tools_gw.get_config_parser("actions_shortcuts",
f"shortcut_open_curselectors", "user", "init", prefix=False)
if not action_open_selections_shortcut:
tools_gw.set_config_parser("actions_shortcuts", f"shortcut_open_curselectors",
f"{action_open_selections_shortcut}", "user", "init", prefix=False)
action_open_selections.setShortcuts(QKeySequence(f"{action_open_selections_shortcut}"))
action_open_selections.triggered.connect(self._open_current_selections)

# Action 'Toggle Log DB'
action_set_log_sql = actions_menu.addAction(f"Toggle Log DB")
log_sql_shortcut = tools_gw.get_config_parser("actions_shortcuts", f"shortcut_toggle_log_db", "user", "init", prefix=False)
if not log_sql_shortcut:
tools_gw.set_config_parser("actions_shortcuts", f"shortcut_toggle_log_db", f"{log_sql_shortcut}", "user",
"init", prefix=False)
action_set_log_sql.setShortcuts(QKeySequence(f"{log_sql_shortcut}"))
action_set_log_sql.triggered.connect(self._set_log_sql)
icon_path = f"{icon_folder}{os.sep}toolbars{os.sep}{toolbar}{os.sep}{index_action}.png"
icon = QIcon(icon_path)
button_def = global_vars.giswater_settings.value(f"buttons_def/{index_action}")
text = ""
if button_def:
text = self._translate(f'{index_action}_text')
parent = self.iface.mainWindow()
ag = QActionGroup(parent)
ag.setProperty('gw_name', 'gw_QActionGroup')
if button_def is None:
continue

# endregion
# Check if the class associated to the button definition exists
if hasattr(buttons, button_def):
button_class = getattr(buttons, button_def)
action_function = button_class(icon_path, button_def, text, None, ag)
action = toolbar_submenu.addAction(icon, f"{text}")
shortcut_key = tools_gw.get_config_parser("toolbars_shortcuts", f"{index_action}", "user", "init", prefix=False)
if shortcut_key:
action.setShortcuts(QKeySequence(f"{shortcut_key}"))
global_vars.shortcut_keys.append(shortcut_key)
action.triggered.connect(partial(self._clicked_event, action_function))
else:
tools_log.log_warning(f"Class '{button_def}' not imported in file '{buttons.__file__}'")
# endregion

# region Actions
actions_menu = QMenu(f"Actions", self.iface.mainWindow().menuBar())
actions_menu.setIcon(config_icon)
self.main_menu.addMenu(actions_menu)

# Action 'Get help'
action_help = actions_menu.addAction(f"Get help")
action_help_shortcut = tools_gw.get_config_parser("actions_shortcuts", f"shortcut_help", "user", "init", prefix=False)
if not action_help_shortcut:
tools_gw.set_config_parser("actions_shortcuts", f"shortcut_help", f"{action_help_shortcut}", "user", "init",
prefix=False)
action_help.setShortcuts(QKeySequence(f"{action_help_shortcut}"))
action_help.triggered.connect(tools_gw.open_dlg_help)

# Action 'Reset dialogs'
action_reset_dialogs = actions_menu.addAction(f"Reset dialogs")
action_reset_dialogs.triggered.connect(self._reset_position_dialog)

# Action 'Reset plugin
action_reset_plugin = actions_menu.addAction(f"Reset plugin")
action_reset_plugin_shortcut = tools_gw.get_config_parser("actions_shortcuts", f"shortcut_reset_plugin",
"user", "init", prefix=False)
if not action_reset_plugin_shortcut:
tools_gw.set_config_parser("actions_shortcuts", f"shortcut_reset_plugin",
f"{action_reset_plugin_shortcut}", "user", "init", prefix=False)
action_reset_plugin.setShortcuts(QKeySequence(f"{action_reset_plugin_shortcut}"))
action_reset_plugin.triggered.connect(self._reset_plugin)

# Action 'Show current selectors'
action_open_selections = actions_menu.addAction(f"Show current selectors")
action_open_selections_shortcut = tools_gw.get_config_parser("actions_shortcuts",
f"shortcut_open_curselectors", "user", "init", prefix=False)
if not action_open_selections_shortcut:
tools_gw.set_config_parser("actions_shortcuts", f"shortcut_open_curselectors",
f"{action_open_selections_shortcut}", "user", "init", prefix=False)
action_open_selections.setShortcuts(QKeySequence(f"{action_open_selections_shortcut}"))
action_open_selections.triggered.connect(self._open_current_selections)

# Action 'Toggle Log DB'
action_set_log_sql = actions_menu.addAction(f"Toggle Log DB")
log_sql_shortcut = tools_gw.get_config_parser("actions_shortcuts", f"shortcut_toggle_log_db", "user", "init", prefix=False)
if not log_sql_shortcut:
tools_gw.set_config_parser("actions_shortcuts", f"shortcut_toggle_log_db", f"{log_sql_shortcut}", "user",
"init", prefix=False)
action_set_log_sql.setShortcuts(QKeySequence(f"{log_sql_shortcut}"))
action_set_log_sql.triggered.connect(self._set_log_sql)

# endregion

# region Advanced
action_manage_file = self.main_menu.addAction(f"Advanced")
Expand All @@ -150,16 +151,15 @@ def read_menu(self):
# endregion

# region Open user folder
log_folder = os.path.join(global_vars.user_folder_dir, 'log')
size = tools_os.get_folder_size(log_folder)
log_folder_volume = f"{round(size / (1024 * 1024), 2)} MB"

icon_path = f"{icon_folder}{os.sep}dialogs{os.sep}20x20{os.sep}102.png"
folder_icon = QIcon(icon_path)
action_open_path = self.main_menu.addAction(f"Open folder ({log_folder_volume})")

action_open_path.setIcon(folder_icon)
action_open_path.triggered.connect(self._open_config_path)
if global_vars.user_folder_dir:
log_folder = os.path.join(global_vars.user_folder_dir, 'log')
size = tools_os.get_folder_size(log_folder)
log_folder_volume = f"{round(size / (1024 * 1024), 2)} MB"
icon_path = f"{icon_folder}{os.sep}dialogs{os.sep}20x20{os.sep}102.png"
folder_icon = QIcon(icon_path)
action_open_path = self.main_menu.addAction(f"Open folder ({log_folder_volume})")
action_open_path.setIcon(folder_icon)
action_open_path.triggered.connect(self._open_config_path)
# endregion

self.iface.mainWindow().menuBar().insertMenu(last_action, self.main_menu)
Expand Down
Loading

0 comments on commit fddc4ca

Please sign in to comment.