def _save_prefs_clicked(self):
     """Advanced preferences editor saved"""
     if not Config.replace(
             self._prefs_editor.toPlainText()) or not Config.save():
         QtWidgets.QMessageBox.critical(
             App.get_window(), App.get_name(),
             f'Could not save the configuration "{Config.get("path/config")}"!'
         )
 def add_plugin(self):
     """Add the chosen plugin or show a message"""
     message = self._add_plugin()
     if message is not None:
         QtWidgets.QMessageBox().critical(App.get_window(), App.get_name(),
                                          message)
     else:
         window = App.get_window()
         window.set_view(self.get_plugins_panel())
         window.remove_view(self)
Exemplo n.º 3
0
 def on_load(self):
     """Load static elements within the panel"""
     self.attach_ui_elements()
     (username, password) = App.open_credential_dialog()
     if not self._permissions.can_modify_roles(username):
         QtWidgets.QMessageBox().critical(
             App.get_window(), App.get_name(),
             'Cannot delete the default role, it is the role everyone has by default!'
         )
         App.get_window().remove_view(self)
     self._user = username
 def apply(self):
     errorMessage = None
     if self._addNewRole:
         errorMessage = self._add_new_role()
     else:
         errorMessage = self._edit_existing_role()
     if errorMessage is None:
         self._popup.accept()
     else:
         QtWidgets.QMessageBox().critical(App.get_window(), App.get_name(),
                                          errorMessage)
Exemplo n.º 5
0
 def delete_role(self):
     """removes the role from the list"""
     currentRole = self._get_current_role()
     if currentRole == 'default':
         QtWidgets.QMessageBox().critical(
             App.get_window(), App.get_name(),
             'Cannot delete the default role, it is the role everyone has by default!'
         )
         return
     self._permissions.delete_role(self._user, currentRole)
     self.load_roles()
     self.edit_button.setEnabled(False)
     self.delete_button.setEnabled(False)
Exemplo n.º 6
0
 def _handle_double_clicked(self, item):
     """Handle double clicking of a file (open it with another program)."""
     path = self.tree_view.get_selected_path()
     if not os.path.isdir(path):
         try:
             if platform.system() == 'Darwin':
                 subprocess.run(['open', path])
             elif platform.system() == 'Windows':
                 os.startfile(path)
             else:
                 subprocess.run(['xdg-open', path])
         except Exception as e:
             Logger.warning(f'MEG RepoPanel: {e}')
             Logger.warning(f'MEG RepoPanel: Could not open the file {path}')
             QtWidgets.QMessageBox.warning(App.get_window(), App.get_name(), f'Could not open file "{path}"')
Exemplo n.º 7
0
 def popup_view(self, panel, resizable=False):
     """Popup a dialog containing a panel."""
     if panel is None or self._current_popup is not None:
         return QtWidgets.QDialog.Rejected
     # Create a dialog window to popup
     dialog = QtWidgets.QDialog(None, QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowTitleHint | QtCore.Qt.WindowCloseButtonHint)
     dialog.setModal(True)
     dialog.setSizeGripEnabled(resizable)
     # Set the current popup
     self._current_popup = dialog
     # Set dialog layout
     layout = QtWidgets.QGridLayout()
     layout.setContentsMargins(0, 0, 0, 0)
     dialog.setLayout(layout)
     # Add the panel widgets to the popup
     widgets = panel.get_widgets()
     layout.addWidget(widgets)
     widgets.setParent(dialog)
     # Set the dialog icon
     icon = panel.get_icon()
     dialog.setWindowIcon(icon if icon else QtWidgets.QIcon(App.get_icon()))
     title = panel.get_title()
     # Set the dialog title
     dialog.setWindowTitle(title if title else App.get_name())
     previous_panel = self._current_panel
     # Hide the current panel
     if previous_panel is not None:
         previous_panel.on_hide()
     # Make the panel the current
     self._current_panel = panel
     # Show the panel
     panel.on_show()
     # Show the dialog
     if not resizable:
         dialog.setFixedSize(dialog.size())
     result = dialog.exec_()
     # Hide the panel
     panel.on_hide()
     # Remove the popup
     self._current_popup = None
     # Restore the previous panel to current
     self._current_panel = previous_panel
     # Show the previous panel
     if previous_panel is not None:
         previous_panel.on_show()
     return result
Exemplo n.º 8
0
 def _handle_double_click(self, item):
     """Handle a double click."""
     repo_path = None
     try:
         repo_path = item.text(1)
         repo_url = item.text(2)
         # Open or clone the repo
         repo = GitManager.open_or_clone(repo_path, repo_url)
         # Create the repository panel
         App.get_window().push_view(RepoPanel(repo))
     except Exception as e:
         Logger.warning(f'MEG UIManager: {e}')
         Logger.warning(
             f'MEG UIManager: Could not load repository "{repo_path}"')
         # Popup
         QtWidgets.QMessageBox.warning(
             App.get_window(), App.get_name(),
             f'Could not load repository "{repo_path}"')
Exemplo n.º 9
0
 def __init__(self, **kwargs):
     """UI manager constructor."""
     # Load window resource if needed
     if UIManager.__widgets is None:
         # Load the resource setup from the package
         UIManager.__widgets = uic.loadUiType(pkg_resources.resource_filename(__name__, UIManager.UI_FILE))
     # Initialize the super class
     super().__init__(**kwargs)
     # Setup window resource
     UIManager.__widgets[0]().setupUi(self)
     # Set the window panel stack
     self._panels = []
     self._current_panel = None
     self._current_popup = None
     # Set handler for closing a panel
     self._panel = self.findChild(QtWidgets.QTabWidget, 'panelwidget')
     self._panel.tabCloseRequested.connect(self.remove_view_by_index)
     self._panel.currentChanged.connect(self._show_view_by_index)
     # Get status widget
     self._statusbar = self.findChild(QtWidgets.QStatusBar, 'statusbar')
     # Set handlers for main buttons
     # TODO: Add more handlers for these
     self._action_clone = self.findChild(QtWidgets.QAction, 'action_Clone')
     self._action_clone.triggered.connect(App.open_clone_panel)
     self._action_open = self.findChild(QtWidgets.QAction, 'action_Open')
     self._action_open.triggered.connect(App.open_repo_panel)
     self._action_quit = self.findChild(QtWidgets.QAction, 'action_Quit')
     self._action_quit.triggered.connect(App.quit)
     self._action_about = self.findChild(QtWidgets.QAction, 'action_About')
     self._action_about.triggered.connect(App.open_about)
     self._action_preferences = self.findChild(QtWidgets.QAction, 'action_Preferences')
     self._action_preferences.triggered.connect(App.open_prefs_panel)
     self._action_manage_plugins = self.findChild(QtWidgets.QAction, 'action_Manage_Plugins')
     self._action_manage_plugins.triggered.connect(App.open_plugins_panel)
     # Set the default title
     self.set_title()
     # Set the icon
     icon_path = App.get_icon()
     if icon_path is not None:
         self.setWindowIcon(QtGui.QIcon(icon_path))
     # Restore the state from the configuration if needed
     window_state = Config.get('window/state', 'none')
     state = self.windowState()
     if window_state == 'maximized':
         state &= ~(QtCore.Qt.WindowMinimized | QtCore.Qt.WindowFullScreen)
         state |= QtCore.Qt.WindowMaximized
     elif window_state == 'minimized':
         state &= ~(QtCore.Qt.WindowMaximized | QtCore.Qt.WindowFullScreen)
         state |= QtCore.Qt.WindowMinimized
     elif window_state == 'fullscreen':
         state &= ~(QtCore.Qt.WindowMinimized | QtCore.Qt.WindowMaximized)
         state |= QtCore.Qt.WindowFullScreen
     self.setWindowState(state)
     # Restore the window geometry from the configuration if needed
     geometry = Config.get('window/geometry', None)
     if isinstance(geometry, list) and len(geometry) == 4:
         self.setGeometry(geometry[0], geometry[1], geometry[2], geometry[3])
 def on_show(self):
     self._popup = App.get_window().get_current_popup()
     self._role_name_edit.setText(self._role)
     self._role_name_edit.setEnabled(
         self._role !=
         'default')  # cannot change the name of the default role
     self._add_locks_box.setChecked(
         self._permissions.does_role_have_permission(
             self._role, 'roles_add_locks'))
     self._remove_locks_box.setChecked(
         self._permissions.does_role_have_permission(
             self._role, 'roles_remove_locks'))
     self._modify_files_box.setChecked(
         self._permissions.does_role_have_permission(
             self._role, 'roles_write'))
     self._grant_permissions_box.setChecked(
         self._permissions.does_role_have_permission(
             self._role, 'roles_grant'))
     self._modify_roles_box.setChecked(
         self._permissions.does_role_have_permission(
             self._role, 'roles_modify_roles'))
Exemplo n.º 11
0
 def clone(self):
     """Clone the repository."""
     # Setup repository
     username = None
     password = None
     if self.enter_credentials_radio.isChecked():
         (username, password) = App.open_credential_dialog()
     elif self.use_stored_credentials_radio.isChecked():
         pass
         # TODO
     repo_url = self.server_text_edit.text()
     repo_path = self.directory
     # TODO: Handle username+password
     # Set the config
     repo = GitManager.clone(repo_url, repo_path)
     if repo is not None:
         App.save_repo_entry(repo_path, repo_url)
         App.get_window().push_view(RepoPanel(repo))
     else:
         Logger.warning(f'MEG UIManager: Could not clone repo "{repo_url}"')
         QtWidgets.QMessageBox.warning(
             App.get_window(), App.get_name(),
             f'Could not clone the repo "{repo_url}"')
Exemplo n.º 12
0
 def _update_title(self, title):
     App.get_window().set_title(self)
Exemplo n.º 13
0
 def __init__(self, **kwargs):
     """MainPanel constructor."""
     super().__init__(App.get_icon(), **kwargs)
Exemplo n.º 14
0
 def open_add_plugin(self):
     """"Open the new plugin window"""
     App.get_window().push_view(self.get_add_plugin_panel())
Exemplo n.º 15
0
 def visible(self):
     """Panel is visible."""
     return self in App.get_window().get_panels()
Exemplo n.º 16
0
 def cancel(self):
     """closes the panel"""
     App.get_window().remove_view(self)
Exemplo n.º 17
0
 def open_add_role(self):
     """Opens the panel to add a new role"""
     App.get_window().popup_view(
         ui.RoleEditPanel(self._user, self._permissions, 'new role', True))
Exemplo n.º 18
0
 def on_close(self):
     """Closing the panel."""
     # Hide the add plugins panel when the plugins panel is hidden
     App.get_window().remove_view(self.get_add_plugin_panel())
Exemplo n.º 19
0
 def manage_roles(self):
     """Manage roles for the given repo"""
     if self._repo is not None:
         App.open_manage_roles(self._repo)
Exemplo n.º 20
0
 def open_edit_role(self):
     """Opens the panel to edit a specific role"""
     currentRole = self._get_current_role()
     App.get_window().popup_view(
         ui.RoleEditPanel(self._user, self._permissions, currentRole,
                          False))