Skip to content

Commit

Permalink
Allow switching profile through the GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLastProject committed Dec 26, 2017
1 parent 35596b1 commit e85b060
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
### Added
- Support renaming profiles
- Allow switching profile from the GUI

### Changed
- Profile name is no longer displayed if default
Expand Down
15 changes: 13 additions & 2 deletions pext/__main__.py
Expand Up @@ -1810,6 +1810,7 @@ def __init__(self, config_retriever: ConfigRetriever, parent=None) -> None:

self.engine = QQmlApplicationEngine(self)

# Set QML variables
self.context = self.engine.rootContext()
self.context.setContextProperty(
"applicationVersion", UpdateManager().get_core_version())
Expand All @@ -1822,6 +1823,8 @@ def __init__(self, config_retriever: ConfigRetriever, parent=None) -> None:
"themesPath", os.path.join(self.config_retriever.get_setting('config_path'), 'themes'))

self.context.setContextProperty("currentTheme", Settings.get('theme'))
self.context.setContextProperty("currentProfile", Settings.get('profile'))
self.context.setContextProperty("profiles", ProfileManager(self.config_retriever).list_profiles())

# Load the main UI
self.engine.load(QUrl.fromLocalFile(os.path.join(AppFile.get_path(), 'qml', 'main.qml')))
Expand Down Expand Up @@ -1881,6 +1884,9 @@ def __init__(self, config_retriever: ConfigRetriever, parent=None) -> None:
menu_update_all_themes_shortcut = self.window.findChild(
QObject, "menuUpdateAllThemes")

menu_load_profile_shortcut = self.window.findChild(
QObject, "menuLoadProfile")

menu_sort_module_shortcut = self.window.findChild(
QObject, "menuSortModule")
menu_sort_ascending_shortcut = self.window.findChild(
Expand Down Expand Up @@ -1929,6 +1935,8 @@ def __init__(self, config_retriever: ConfigRetriever, parent=None) -> None:
menu_update_all_themes_shortcut.updateAllThemesRequest.connect(
self._menu_update_all_themes)

menu_load_profile_shortcut.loadProfileRequest.connect(self._menu_switch_profile)

menu_sort_module_shortcut.toggled.connect(self._menu_sort_module)
menu_sort_ascending_shortcut.toggled.connect(self._menu_sort_ascending)
menu_sort_descending_shortcut.toggled.connect(self._menu_sort_descending)
Expand Down Expand Up @@ -2155,12 +2163,13 @@ def _menu_update_all_modules(self) -> None:
]
threading.Thread(target=RunConseq, args=(functions,)).start() # type: ignore

def _menu_restart_pext(self) -> None:
def _menu_restart_pext(self, extra_args=[]) -> None:
# Call _shut_down manually because it isn't called when using os.execv
_shut_down(self,
self.config_retriever)

args = sys.argv[:]
args.extend(extra_args)

args.insert(0, sys.executable)
if sys.platform == 'win32':
Expand All @@ -2174,7 +2183,9 @@ def _menu_switch_theme(self, theme_name: Optional[str]) -> None:

self._menu_restart_pext()

"""Restart Pext after switching theme."""
def _menu_switch_profile(self, profile_name: str) -> None:
self._menu_restart_pext(['--profile={}'.format(profile_name)])

def _menu_install_theme(self, theme_url: str) -> None:
functions = [
{
Expand Down
64 changes: 64 additions & 0 deletions pext/qml/LoadProfileDialog.qml
@@ -0,0 +1,64 @@
/*
Copyright (c) 2017 Sylvia van Os <sylvia@hackerchick.me>
This file is part of Pext
Pext is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import QtQuick 2.3
import QtQuick.Controls 1.2
import QtQuick.Dialogs 1.2
import QtQuick.Layouts 1.0

Dialog {
title: qsTr("Load profile")
standardButtons: StandardButton.Ok | StandardButton.Cancel

property var currentProfile
property var profiles
property var loadRequest

ColumnLayout {
id: columnLayout
width: parent.width

anchors.fill: parent

Label {
text: qsTr("Choose the profile to switch to:")
}

ComboBox {
id: combobox
model: profiles
Layout.fillWidth: true
}

Label {
text: qsTr("Note: Pext will restart to switch profile.")
}
}

Component.onCompleted: {
combobox.currentIndex = profiles.indexOf(currentProfile);
visible = true;
combobox.focus = true;
}

onAccepted: {
loadRequest(combobox.currentText);
}
}

19 changes: 19 additions & 0 deletions pext/qml/main.qml
Expand Up @@ -503,6 +503,25 @@ ApplicationWindow {
}
}

Menu {
title: qsTr("&Profile")

MenuItem {
objectName: "menuLoadProfile"
text: qsTr("Switch profile")

signal loadProfileRequest(string name)

onTriggered: {
var loadProfileDialog = Qt.createComponent("LoadProfileDialog.qml");
loadProfileDialog.createObject(applicationWindow,
{"currentProfile": currentProfile,
"profiles": profiles.sort(),
"loadRequest": loadProfileRequest});
}
}
}

Menu {
title: qsTr("&Settings")

Expand Down

0 comments on commit e85b060

Please sign in to comment.