From 39e6740d8c08a90defbd155c6e5d0cc5e658df79 Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Thu, 19 Dec 2013 20:48:59 -0800 Subject: [PATCH] widgets: do not set window modality without a parent Dialogs with a modality of Qt.WindowModal must always have a parent. When these are run from the top-level, e.g. via `git cola grep`, then the parent is `None` and we should not use Qt.WindowModal. Signed-off-by: David Aguilar --- bin/git-cola | 8 ++++---- cola/bookmarks.py | 5 +++-- cola/guicmds.py | 9 --------- cola/widgets/archive.py | 3 ++- cola/widgets/browse.py | 3 ++- cola/widgets/cfgactions.py | 6 +++--- cola/widgets/createbranch.py | 3 ++- cola/widgets/createtag.py | 17 +++++++++++++---- cola/widgets/editremotes.py | 19 ++++++++++++------- cola/widgets/grep.py | 39 ++++++++++++++++++++++++--------------- cola/widgets/main.py | 3 ++- cola/widgets/merge.py | 3 ++- cola/widgets/prefs.py | 4 +++- cola/widgets/remote.py | 19 ++++++++++--------- cola/widgets/stash.py | 6 +++--- 15 files changed, 85 insertions(+), 62 deletions(-) diff --git a/bin/git-cola b/bin/git-cola index 4eed7428..3de494a3 100755 --- a/bin/git-cola +++ b/bin/git-cola @@ -263,7 +263,7 @@ def cmd_grep(args): context = application_init(args) from cola.widgets import grep text = subprocess.list2cmdline(map(core.decode, args.args)) - view = grep.run_grep(text=text, parent=None) + view = grep.new_grep(text=text, parent=None) return application_start(context, view) @@ -308,7 +308,7 @@ def cmd_rebase(args): def cmd_remote(args): context = application_init(args) from cola.widgets import editremotes - view = editremotes.edit() + view = editremotes.new_remote_editor() return application_start(context, view) @@ -328,8 +328,8 @@ def cmd_stash(args): def cmd_tag(args): context = application_init(args) - from cola.widgets.createtag import create_tag - view = create_tag(name=args.name, ref=args.ref, sign=args.sign) + from cola.widgets.createtag import new_create_tag + view = new_create_tag(name=args.name, ref=args.ref, sign=args.sign) return application_start(context, view) diff --git a/cola/bookmarks.py b/cola/bookmarks.py index 7345cc04..c5fb41e2 100644 --- a/cola/bookmarks.py +++ b/cola/bookmarks.py @@ -23,12 +23,13 @@ def manage_bookmarks(): class BookmarksDialog(standard.Dialog): def __init__(self, parent): - standard.Dialog.__init__(self, parent) + standard.Dialog.__init__(self, parent=parent) self.model = settings.Settings() self.resize(494, 238) self.setWindowTitle(N_('Bookmarks')) - self.setWindowModality(Qt.WindowModal) + if parent is not None: + self.setWindowModality(Qt.WindowModal) self.layt = QtGui.QVBoxLayout(self) self.layt.setMargin(defs.margin) self.layt.setSpacing(defs.spacing) diff --git a/cola/guicmds.py b/cola/guicmds.py index c9fd19cd..14f0424f 100644 --- a/cola/guicmds.py +++ b/cola/guicmds.py @@ -14,7 +14,6 @@ from cola.interaction import Interaction from cola.models import main from cola.widgets import completion from cola.widgets.browse import BrowseDialog -from cola.widgets.grep import run_grep from cola.widgets.selectcommits import select_commits @@ -199,14 +198,6 @@ def diff_expression(): difftool.diff_expression(qtutils.active_window(), ref) -def grep(): - """Prompt and use 'git grep' to find the content.""" - widget = run_grep(parent=qtutils.active_window()) - widget.show() - widget.raise_() - return widget - - def open_repo(): """Spawn a new cola session.""" dirname = qtutils.opendir_dialog(N_('Open Git Repository...'), diff --git a/cola/widgets/archive.py b/cola/widgets/archive.py index 32ec06bf..d9ed7b92 100644 --- a/cola/widgets/archive.py +++ b/cola/widgets/archive.py @@ -81,7 +81,8 @@ class GitArchiveDialog(QtGui.QDialog): def __init__(self, ref, shortref=None, parent=None): QtGui.QDialog.__init__(self, parent) - self.setWindowModality(Qt.WindowModal) + if parent is not None: + self.setWindowModality(Qt.WindowModal) # input self.ref = ref diff --git a/cola/widgets/browse.py b/cola/widgets/browse.py index 9f42ac80..ead1c98c 100644 --- a/cola/widgets/browse.py +++ b/cola/widgets/browse.py @@ -466,7 +466,8 @@ class BrowseDialog(QtGui.QDialog): def __init__(self, model, select_file=False, parent=None): QtGui.QDialog.__init__(self, parent) self.setAttribute(Qt.WA_MacMetalStyle) - self.setWindowModality(Qt.WindowModal) + if parent is not None: + self.setWindowModality(Qt.WindowModal) # updated for use by commands self.model = model diff --git a/cola/widgets/cfgactions.py b/cola/widgets/cfgactions.py index 1f545ff2..1b877fe5 100644 --- a/cola/widgets/cfgactions.py +++ b/cola/widgets/cfgactions.py @@ -56,10 +56,9 @@ class GitCommandWidget(standard.Dialog): # Keep us in scope otherwise PyQt kills the widget def __init__(self, title, parent=None): standard.Dialog.__init__(self, parent) - self.resize(720, 420) - self.setWindowTitle(title) - self.setWindowModality(Qt.ApplicationModal) + if parent is not None: + self.setWindowModality(Qt.ApplicationModal) # Construct the process self.proc = QtCore.QProcess(self) @@ -105,6 +104,7 @@ class GitCommandWidget(standard.Dialog): qtutils.connect_button(self.button_abort, self.abortProc) qtutils.connect_button(self.button_close, self.close) + self.resize(720, 420) def set_command(self, command): self.command = command diff --git a/cola/widgets/createbranch.py b/cola/widgets/createbranch.py index 50eebfed..58709f9d 100644 --- a/cola/widgets/createbranch.py +++ b/cola/widgets/createbranch.py @@ -78,9 +78,10 @@ class CreateBranchDialog(Dialog): def __init__(self, model, parent=None): Dialog.__init__(self, parent=parent) - self.setWindowModality(Qt.WindowModal) self.setAttribute(Qt.WA_MacMetalStyle) self.setWindowTitle(N_('Create Branch')) + if parent is not None: + self.setWindowModality(Qt.WindowModal) self.model = model self.opts = CreateOpts(model) diff --git a/cola/widgets/createtag.py b/cola/widgets/createtag.py index a55152d8..4ffa9bde 100644 --- a/cola/widgets/createtag.py +++ b/cola/widgets/createtag.py @@ -13,11 +13,19 @@ from cola.widgets import standard from cola.widgets import text -def create_tag(name='', ref='', sign=False): +def new_create_tag(name='', ref='', sign=False, parent=None): """Entry point for external callers.""" opts = TagOptions(name, ref, sign) - view = CreateTag(opts, qtutils.active_window()) + view = CreateTag(opts, parent=parent) + return view + + +def create_tag(name='', ref='', sign=False): + """Entry point for external callers.""" + view = new_create_tag(name=name, ref=ref, sign=sign, + parent=qtutils.active_window()) view.show() + view.raise_() return view @@ -33,11 +41,12 @@ class TagOptions(object): class CreateTag(standard.Dialog): - def __init__(self, opts, parent): + def __init__(self, opts, parent=None): standard.Dialog.__init__(self, parent=parent) - self.setWindowModality(QtCore.Qt.WindowModal) self.setAttribute(Qt.WA_MacMetalStyle) self.setWindowTitle(N_('Create Tag')) + if parent is not None: + self.setWindowModality(QtCore.Qt.WindowModal) self.opts = opts diff --git a/cola/widgets/editremotes.py b/cola/widgets/editremotes.py index 681205ce..1dc872eb 100644 --- a/cola/widgets/editremotes.py +++ b/cola/widgets/editremotes.py @@ -12,19 +12,24 @@ from cola.widgets import defs from cola.widgets import text -def edit(): - window = RemoteEditor(qtutils.active_window()) - window.show() - window.raise_() - return window +def remote_editor(): + view= new_remote_editor(parent=qtutils.active_window()) + view.show() + view.raise_() + return view + + +def new_remote_editor(parent=None): + return RemoteEditor(parent=parent) class RemoteEditor(QtGui.QDialog): - def __init__(self, parent): + def __init__(self, parent=None): QtGui.QDialog.__init__(self, parent) self.setWindowTitle(N_('Edit Remotes')) - self.setWindowModality(Qt.WindowModal) + if parent is not None: + self.setWindowModality(Qt.WindowModal) self.default_hint = N_('' 'Add and remove remote repositories using the \n' diff --git a/cola/widgets/grep.py b/cola/widgets/grep.py index 37dd75fc..19c588c8 100644 --- a/cola/widgets/grep.py +++ b/cola/widgets/grep.py @@ -15,6 +15,27 @@ from cola.widgets.standard import Dialog from cola.widgets.text import HintedTextView, HintedLineEdit +def grep(): + """Prompt and use 'git grep' to find the content.""" + widget = new_grep(parent=qtutils.active_window()) + widget.show() + widget.raise_() + return widget + + +def new_grep(text=None, parent=None): + widget = Grep(parent=parent) + if text: + widget.search_for(text) + return widget + + +def goto_grep(line): + """Called when Search -> Grep's right-click 'goto' action.""" + filename, line_number, contents = line.split(':', 2) + do(cmds.Edit, [filename], line_number=line_number) + + class GrepThread(QtCore.QThread): def __init__(self, parent): @@ -40,11 +61,12 @@ class GrepThread(QtCore.QThread): class Grep(Dialog): - def __init__(self, parent): + def __init__(self, parent=None): Dialog.__init__(self, parent) self.setAttribute(Qt.WA_MacMetalStyle) - self.setWindowModality(Qt.WindowModal) self.setWindowTitle(N_('Search')) + if parent is not None: + self.setWindowModality(Qt.WindowModal) self.input_label = QtGui.QLabel('git grep') self.input_label.setFont(diff_font()) @@ -310,16 +332,3 @@ class GrepTextView(HintedTextView): # change focus. self.emit(SIGNAL('leave()')) return HintedTextView.keyPressEvent(self, event) - - -def goto_grep(line): - """Called when Search -> Grep's right-click 'goto' action.""" - filename, line_number, contents = line.split(':', 2) - do(cmds.Edit, [filename], line_number=line_number) - - -def run_grep(text=None, parent=None): - widget = Grep(parent) - if text: - widget.search_for(text) - return widget diff --git a/cola/widgets/main.py b/cola/widgets/main.py index 8d4391bc..092d0cf9 100644 --- a/cola/widgets/main.py +++ b/cola/widgets/main.py @@ -46,6 +46,7 @@ from cola.widgets.createtag import create_tag from cola.widgets.createbranch import create_new_branch from cola.widgets.dag import git_dag from cola.widgets.diff import DiffEditor +from cola.widgets.grep import grep from cola.widgets.log import LogWidget from cola.widgets import merge from cola.widgets.prefs import preferences @@ -216,7 +217,7 @@ class MainView(MainWindow): self.manage_bookmarks_action = add_action(self, N_('Bookmarks...'), manage_bookmarks) self.grep_action = add_action(self, - N_('Grep'), guicmds.grep, 'Ctrl+G') + N_('Grep'), grep, 'Ctrl+G') self.merge_local_action = add_action(self, N_('Merge...'), merge.local_merge) diff --git a/cola/widgets/merge.py b/cola/widgets/merge.py index 8e664d4b..ddc31c34 100644 --- a/cola/widgets/merge.py +++ b/cola/widgets/merge.py @@ -40,7 +40,8 @@ class MergeView(QtGui.QDialog): def __init__(self, model, parent=None): QtGui.QDialog.__init__(self, parent) self.model = model - self.setWindowModality(Qt.WindowModal) + if parent is not None: + self.setWindowModality(Qt.WindowModal) self.resize(700, 400) # Widgets diff --git a/cola/widgets/prefs.py b/cola/widgets/prefs.py index dc2a2c57..e082227e 100644 --- a/cola/widgets/prefs.py +++ b/cola/widgets/prefs.py @@ -228,10 +228,12 @@ class SettingsFormWidget(FormWidget): class PreferencesView(standard.Dialog): + def __init__(self, model, parent=None): standard.Dialog.__init__(self, parent=parent) self.setWindowTitle(N_('Preferences')) - self.setWindowModality(QtCore.Qt.WindowModal) + if parent is not None: + self.setWindowModality(QtCore.Qt.WindowModal) self.resize(600, 360) diff --git a/cola/widgets/remote.py b/cola/widgets/remote.py index 9a46c8cf..2eb1d9fa 100644 --- a/cola/widgets/remote.py +++ b/cola/widgets/remote.py @@ -44,7 +44,7 @@ def run(RemoteDialog): model.tags = global_model.tags model.remotes = global_model.remotes parent = qtutils.active_window() - view = RemoteDialog(model, parent) + view = RemoteDialog(model, parent=parent) view.show() return view @@ -117,7 +117,7 @@ class ProgressAnimationThread(QtCore.QThread): class RemoteActionDialog(standard.Dialog): - def __init__(self, model, action, parent): + def __init__(self, model, action, parent=None): """Customizes the dialog based on the remote action """ standard.Dialog.__init__(self, parent=parent) @@ -128,8 +128,9 @@ class RemoteActionDialog(standard.Dialog): self.selected_remotes = [] self.setAttribute(Qt.WA_MacMetalStyle) - self.setWindowModality(Qt.WindowModal) self.setWindowTitle(N_(action)) + if parent is not None: + self.setWindowModality(Qt.WindowModal) self.progress = QtGui.QProgressDialog(self) self.progress.setFont(qtutils.diff_font()) @@ -545,18 +546,18 @@ class RemoteActionDialog(standard.Dialog): # Use distinct classes so that each saves its own set of preferences class Fetch(RemoteActionDialog): - def __init__(self, model, parent): - RemoteActionDialog.__init__(self, model, FETCH, parent) + def __init__(self, model, parent=None): + RemoteActionDialog.__init__(self, model, FETCH, parent=parent) class Push(RemoteActionDialog): - def __init__(self, model, parent): - RemoteActionDialog.__init__(self, model, PUSH, parent) + def __init__(self, model, parent=None): + RemoteActionDialog.__init__(self, model, PUSH, parent=parent) class Pull(RemoteActionDialog): - def __init__(self, model, parent): - RemoteActionDialog.__init__(self, model, PULL, parent) + def __init__(self, model, parent=None): + RemoteActionDialog.__init__(self, model, PULL, parent=parent) def apply_state(self, state): RemoteActionDialog.apply_state(self, state) diff --git a/cola/widgets/stash.py b/cola/widgets/stash.py index 1ab05b79..7aaebf7a 100644 --- a/cola/widgets/stash.py +++ b/cola/widgets/stash.py @@ -30,15 +30,15 @@ def stash(): class StashView(Dialog): def __init__(self, model, parent=None): Dialog.__init__(self, parent=parent) - self.setAttribute(QtCore.Qt.WA_MacMetalStyle) self.model = model self.stashes = [] self.revids = [] self.names = [] - self.setWindowModality(QtCore.Qt.WindowModal) self.setWindowTitle(N_('Stash')) - if parent: + self.setAttribute(QtCore.Qt.WA_MacMetalStyle) + if parent is not None: + self.setWindowModality(QtCore.Qt.WindowModal) self.resize(parent.width(), 420) else: self.resize(700, 420) -- 2.11.4.GIT