Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gui: center all popup windows #487

Merged
merged 2 commits into from
Jul 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions securedrop_client/gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@

from gettext import gettext as _
from typing import Dict, List, Optional # noqa: F401
from PyQt5.QtWidgets import QMainWindow, QWidget, QHBoxLayout, QVBoxLayout, QDesktopWidget, \
QApplication
from PyQt5.QtWidgets import QMainWindow, QWidget, QHBoxLayout, QVBoxLayout, QDesktopWidget

from securedrop_client import __version__
from securedrop_client.db import Source, User
Expand Down Expand Up @@ -116,8 +115,14 @@ def show_login(self):
Show the login form.
"""
self.login_dialog = LoginDialog(self)
self.login_dialog.move(
QApplication.desktop().screen().rect().center() - self.rect().center())

# Always display the login dialog centered in the screen.
screen_size = QDesktopWidget().screenGeometry()
login_dialog_size = self.login_dialog.geometry()
x_center = (screen_size.width() - login_dialog_size.width()) / 2
y_center = (screen_size.height() - login_dialog_size.height()) / 2
self.login_dialog.move(x_center, y_center)

self.login_dialog.setup(self.controller)
self.login_dialog.reset()
self.login_dialog.exec()
Expand Down
11 changes: 4 additions & 7 deletions securedrop_client/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ def delete_source(self, event):
self.controller.on_action_requiring_login()
return
else:
messagebox = DeleteSourceMessageBox(self, self.source, self.controller)
messagebox = DeleteSourceMessageBox(self.source, self.controller)
messagebox.launch()


Expand Down Expand Up @@ -917,8 +917,7 @@ def on_toggle_offline(self):
class DeleteSourceMessageBox:
"""Use this to display operation details and confirm user choice."""

def __init__(self, parent, source, controller):
self.parent = parent
def __init__(self, source, controller):
self.source = source
self.controller = controller

Expand All @@ -932,7 +931,7 @@ def launch(self):
"""
message = self._construct_message(self.source)
reply = QMessageBox.question(
self.parent, "", _(message), QMessageBox.Cancel | QMessageBox.Yes, QMessageBox.Cancel)
None, "", _(message), QMessageBox.Cancel | QMessageBox.Yes, QMessageBox.Cancel)

if reply == QMessageBox.Yes:
logger.debug("Deleting source %s" % (self.source.uuid,))
Expand Down Expand Up @@ -1767,9 +1766,7 @@ def __init__(self, source, parent, controller):

super().__init__(self.text, parent)

self.messagebox = DeleteSourceMessageBox(
parent, self.source, self.controller
)
self.messagebox = DeleteSourceMessageBox(self.source, self.controller)
self.triggered.connect(self.trigger)

def trigger(self):
Expand Down
8 changes: 4 additions & 4 deletions tests/gui/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1667,7 +1667,7 @@ def test_ConversationView_add_not_downloaded_file(mocker, homedir, source, sessi

def test_DeleteSourceMessageBox_init(mocker, source):
mock_controller = mocker.MagicMock()
DeleteSourceMessageBox(None, source['source'], mock_controller)
DeleteSourceMessageBox(source['source'], mock_controller)


def test_DeleteSourceMessage_launch_when_user_chooses_cancel(mocker, source):
Expand All @@ -1677,7 +1677,7 @@ def test_DeleteSourceMessage_launch_when_user_chooses_cancel(mocker, source):
mock_message_box_question.return_value = QMessageBox.Cancel
mock_controller = mocker.MagicMock()

delete_source_message_box = DeleteSourceMessageBox(None, source, mock_controller)
delete_source_message_box = DeleteSourceMessageBox(source, mock_controller)

mocker.patch(
"securedrop_client.gui.widgets.QMessageBox.question",
Expand All @@ -1704,7 +1704,7 @@ def test_DeleteSourceMssageBox_launch_when_user_chooses_yes(mocker, source, sess
mock_message_box_question.return_value = QMessageBox.Yes
mock_controller = mocker.MagicMock()

delete_source_message_box = DeleteSourceMessageBox(None, source, mock_controller)
delete_source_message_box = DeleteSourceMessageBox(source, mock_controller)

mocker.patch(
"securedrop_client.gui.widgets.QMessageBox.question",
Expand Down Expand Up @@ -1745,7 +1745,7 @@ def test_DeleteSourceMessageBox_construct_message(mocker, source, session):

mock_controller = mocker.MagicMock()

delete_source_message_box = DeleteSourceMessageBox(None, source, mock_controller)
delete_source_message_box = DeleteSourceMessageBox(source, mock_controller)

message = delete_source_message_box._construct_message(source)

Expand Down