-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from ntoll/ui_core
GUI scaffolding and core functions
- Loading branch information
Showing
28 changed files
with
1,845 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env python3 | ||
from securedrop_client.app import run | ||
|
||
|
||
if __name__ == '__main__': | ||
run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,22 @@ | ||
import gettext | ||
import locale | ||
import os | ||
|
||
|
||
# Configure locale and language. | ||
# Define where the translation assets are to be found. | ||
localedir = os.path.abspath(os.path.join(os.path.dirname(__file__), 'locale')) | ||
try: | ||
# Use the operating system's locale. | ||
current_locale, encoding = locale.getdefaultlocale() | ||
# Get the language code. | ||
language_code = current_locale[:2] | ||
except (TypeError, ValueError): | ||
language_code = 'en' | ||
# DEBUG/TRANSLATE: override the language code here (e.g. to Chinese). | ||
# language_code = 'zh' | ||
gettext.translation('securedrop_client', localedir=localedir, | ||
languages=[language_code], fallback=True).install() | ||
|
||
|
||
__version__ = '0.0.1-alpha.1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
""" | ||
Contains the core UI class for the application. All interactions with the UI | ||
go through an instance of this class. | ||
Copyright (C) 2018 The Freedom of the Press Foundation. | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero 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 Affero General Public License for more details. | ||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
""" | ||
import logging | ||
from PyQt5.QtWidgets import QMainWindow, QWidget, QVBoxLayout, QDesktopWidget | ||
from PyQt5.QtCore import Qt | ||
from securedrop_client import __version__ | ||
from securedrop_client.gui.widgets import ToolBar, MainView, LoginView | ||
from securedrop_client.resources import load_icon | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Window(QMainWindow): | ||
""" | ||
Represents the application's main window that will contain the UI widgets. | ||
All interactions with the UI go through the object created by this class. | ||
""" | ||
|
||
icon = 'icon.png' | ||
|
||
def __init__(self): | ||
""" | ||
Create the default start state. The window contains a root widget into | ||
which is placed: | ||
* A status bar widget at the top, containing curent user / status | ||
information. | ||
* A main-view widget, itself containing a list view for sources and a | ||
place for details / message contents / forms. | ||
""" | ||
super().__init__() | ||
self.setWindowTitle(_("SecureDrop Client {}").format(__version__)) | ||
self.setWindowIcon(load_icon(self.icon)) | ||
self.widget = QWidget() | ||
widget_layout = QVBoxLayout() | ||
self.widget.setLayout(widget_layout) | ||
self.tool_bar = ToolBar(self.widget) | ||
self.main_view = MainView(self.widget) | ||
widget_layout.addWidget(self.tool_bar, 1) | ||
widget_layout.addWidget(self.main_view, 6) | ||
self.setCentralWidget(self.widget) | ||
self.show() | ||
self.autosize_window() | ||
|
||
def setup(self, controller): | ||
""" | ||
Create references to the controller logic and instantiate the various | ||
views used in the UI. | ||
""" | ||
self.controller = controller # Reference the Client logic instance. | ||
self.tool_bar.setup(self, controller) | ||
self.login_view = LoginView(self, self.controller) | ||
|
||
def autosize_window(self): | ||
""" | ||
Ensure the application window takes up 100% of the available screen | ||
(i.e. the whole of the virtualised desktop in Qubes dom) | ||
""" | ||
screen = QDesktopWidget().screenGeometry() | ||
self.resize(screen.width(), screen.height()) | ||
|
||
def show_login(self, error=None): | ||
""" | ||
Show the login form. If an error message is passed in, the login | ||
form will display this too. | ||
""" | ||
self.login_view.reset() | ||
if error: | ||
self.login_view.error(error) | ||
self.main_view.update_view(self.login_view) | ||
|
||
def show_sources(self, sources): | ||
""" | ||
Update the left hand sources list in the UI with the passed in list of | ||
sources. | ||
""" | ||
self.main_view.source_list.update(sources) | ||
|
||
def show_sync(self, updated_on): | ||
""" | ||
Display a message indicating the data-sync state. | ||
""" | ||
if updated_on: | ||
self.main_view.status.setText('Last Sync: ' + | ||
updated_on.humanize()) | ||
else: | ||
self.main_view.status.setText(_('Waiting to Synchronize')) | ||
|
||
def set_logged_in_as(self, username): | ||
""" | ||
Update the UI to show user logged in with username. | ||
""" | ||
self.tool_bar.set_logged_in_as(username) | ||
|
||
def logout(self): | ||
""" | ||
Update the UI to show the user is logged out. | ||
""" | ||
self.tool_bar.set_logged_out() |
Oops, something went wrong.