From 13f5b071027e5aed0f9ae5eec88f4095f2246f98 Mon Sep 17 00:00:00 2001 From: necoro <> Date: Tue, 24 Apr 2007 14:36:36 +0000 Subject: added dialogs to warn you when the queue is running on quitting portato --- portato/gui/gtk/dialogs.py | 6 + portato/gui/gtk/glade/portato.glade | 383 ++++++++++++++++++------------------ portato/gui/gtk/windows.py | 11 ++ portato/gui/gui_helper.py | 62 +++--- portato/gui/qt/dialogs.py | 3 + portato/gui/qt/windows.py | 12 ++ 6 files changed, 263 insertions(+), 214 deletions(-) (limited to 'portato/gui') diff --git a/portato/gui/gtk/dialogs.py b/portato/gui/gtk/dialogs.py index f6573ef..24d1a20 100644 --- a/portato/gui/gtk/dialogs.py +++ b/portato/gui/gtk/dialogs.py @@ -12,6 +12,12 @@ import gtk +def queue_not_empty_dialog(): + dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_QUESTION, gtk.BUTTONS_OK_CANCEL, "There are some packages in the emerge queue and/or an emerge process is running.\nDo you really want to quit?") + ret = dialog.run() + dialog.destroy() + return ret + def io_ex_dialog (io_ex): string = io_ex.strerror if io_ex.filename: diff --git a/portato/gui/gtk/glade/portato.glade b/portato/gui/gtk/glade/portato.glade index 0ac888e..2443bd1 100644 --- a/portato/gui/gtk/glade/portato.glade +++ b/portato/gui/gtk/glade/portato.glade @@ -6,6 +6,7 @@ 2 GTK_WIN_POS_CENTER + True @@ -401,49 +402,73 @@ 4 2 - + True - 1 - True - - - True - True - Installed - True - - - - False - - + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC - + True - True - Masked - True - - - False - 1 - + + + 2 + 2 + 3 + 5 + 5 + + + + + True - - True - True - Testing - True - - - - False - 2 - + + + 1 + 2 + GTK_FILL + 5 + + + + + True + GTK_JUSTIFY_CENTER + True + + + 2 + GTK_FILL + + 10 + + + + + True + True + <span foreground='red'><b>MISSING KEYWORD</b></span> + True + + + 1 + 2 + 1 + 2 + GTK_FILL + + + + + True + True + <b>Installed, but not in portage anymore</b> + True + 1 2 @@ -507,79 +532,55 @@ - - True - True - <b>Installed, but not in portage anymore</b> - True - - - 1 - 2 - 1 - 2 - GTK_FILL - - - - - True - True - <span foreground='red'><b>MISSING KEYWORD</b></span> - True - - - 1 - 2 - 1 - 2 - GTK_FILL - - - - - True - GTK_JUSTIFY_CENTER - True - - - 2 - GTK_FILL - - 10 - - - - + True + 1 + True - + + True + True + Installed + True + + + + False + - - - 1 - 2 - GTK_FILL - 5 - - - - - True - GTK_POLICY_AUTOMATIC - GTK_POLICY_AUTOMATIC - + True + True + Masked + True + + + False + 1 + + + + + True + True + Testing + True + + + + False + 2 + + 1 2 - 2 - 3 - 5 - 5 + 1 + 2 + GTK_FILL @@ -1090,186 +1091,186 @@ - + True + 0 + 5 + <u><i>Masking Keywords</i></u> + True + True - 1 - 2 - 3 - 4 + 7 + 8 + 5 - + True 0 - File name to use, if package.use is a directory: + 5 + <u><i>Testing Keywords</i></u> + True True - 3 - 4 + 4 + 5 + 5 - + True - Add only exact version to package.use - True + 0 + 5 + <u><i>Use-Flags</i></u> + True + True + + + 1 + 2 + 6 + + + + + True + + + True + 0 + GTK_SHADOW_OUT + + + True + 0 + <u>You may use the following placeholders:</u> + +<i>$(cat)</i>: category +<i>$(pkg)</i>: package name +<i>$(cat-1)/$(cat-2)</i>: first/second part of the category + True + + + + + + label_item + + + + 2 - 2 - 3 - + True - Add only exact version to package.keywords + Add only exact version to package.mask/package.unmask True 2 - 5 - 6 + 8 + 9 - + True 0 - File name to use, if package.keywords is a directory: + File name to use, if package.mask/package.unmask is a directory: True - 6 - 7 + 9 + 10 - + True 1 2 - 6 - 7 + 9 + 10 - + True 1 2 - 9 - 10 + 6 + 7 - + True 0 - File name to use, if package.mask/package.unmask is a directory: + File name to use, if package.keywords is a directory: True - 9 - 10 + 6 + 7 - + True - Add only exact version to package.mask/package.unmask + Add only exact version to package.keywords True 2 - 8 - 9 + 5 + 6 - + True - - - True - 0 - GTK_SHADOW_OUT - - - True - 0 - <u>You may use the following placeholders:</u> - -<i>$(cat)</i>: category -<i>$(pkg)</i>: package name -<i>$(cat-1)/$(cat-2)</i>: first/second part of the category - True - - - - - - label_item - - - - + Add only exact version to package.use + True 2 + 2 + 3 - - True - 0 - 5 - <u><i>Use-Flags</i></u> - True - True - - - 1 - 2 - 6 - - - - + True 0 - 5 - <u><i>Testing Keywords</i></u> - True + File name to use, if package.use is a directory: True - 4 - 5 - 5 + 3 + 4 - + True - 0 - 5 - <u><i>Masking Keywords</i></u> - True - True - 7 - 8 - 5 + 1 + 2 + 3 + 4 diff --git a/portato/gui/gtk/windows.py b/portato/gui/gtk/windows.py index 5aeceed..12b7a58 100644 --- a/portato/gui/gtk/windows.py +++ b/portato/gui/gtk/windows.py @@ -1115,6 +1115,17 @@ class MainWindow (Window): def cb_copy_clicked (self, action): self.console.copy_clipboard() + def cb_delete (self, *args): + """Looks whether we really want to quit.""" + if not self.queue.is_empty(): + ret = queue_not_empty_dialog() + if ret == gtk.RESPONSE_CANCEL: + return True + else: + self.queue.kill_emerge() + + return False + def cb_destroy (self, widget): """Calls main_quit().""" gtk.main_quit() diff --git a/portato/gui/gui_helper.py b/portato/gui/gui_helper.py index 5cc2ee6..656b83a 100644 --- a/portato/gui/gui_helper.py +++ b/portato/gui/gui_helper.py @@ -272,6 +272,9 @@ class EmergeQueue: self.unmergequeue = [] # for emerge -C self.oneshotmerge = [] # for emerge --oneshot + # the emerge process + self.process = None + # dictionaries with data about the packages in the queue self.iters = {} # iterator in the tree self.deps = {} # all the deps of the package @@ -361,7 +364,7 @@ class EmergeQueue: while self.tree.iter_has_parent(it): it = self.tree.parent_iter(it) self.remove_with_children(it) - raise e + raise # add iter subIt = self.tree.append(it, self.tree.build_append_value(cpv, oneshot = oneshot, update = update, version = uVersion)) @@ -378,7 +381,7 @@ class EmergeQueue: except backend.BlockedException, e: # BlockedException occured -> delete current tree and re-raise exception debug("Something blocked:", e[0]) self.remove_with_children(subIt) - raise e + raise def append (self, cpv, unmerge = False, update = False, forceUpdate = False, unmask = False, oneshot = False): """Appends a cpv either to the merge queue or to the unmerge-queue. @@ -437,26 +440,27 @@ class EmergeQueue: @type oneshot: boolean""" if not oneshot: - self.mergequeue.append(cpv) + if cpv not in self.mergequeue: + self.mergequeue.append(cpv) else: - self.oneshotmerge.append(cpv) + if cpv not in self.oneshotmerge: + self.oneshotmerge.append(cpv) - def _update_packages(self, packages, process = None): + def _update_packages(self, packages): """This updates the packages-list. It simply makes the db to rebuild the specific category. @param packages: The packages which we emerged. - @type packages: list of cpvs - @param process: The process we have to wait for before we can do our work. - @type process: subprocess.Popen""" + @type packages: list of cpvs""" old_title = self.console.get_window_title() - if process: - while process.poll() == None: - if self.title_update : - title = self.console.get_window_title() - if title != old_title: - self.title_update(title) - time.sleep(0.5) + while self.process and self.process.poll() is None: + if self.title_update : + title = self.console.get_window_title() + if title != old_title: + self.title_update(title) + time.sleep(0.5) + + self.process = None if self.title_update: self.title_update(None) @@ -495,7 +499,7 @@ class EmergeQueue: self.process = Popen(command+options+packages, stdout = slave, stderr = STDOUT, shell = False) # start thread waiting for the stop of emerge - Thread(name="Emerge-Thread", target=self._update_packages, args=(packages+self.deps.keys(), self.process)).start() + Thread(name="Emerge-Thread", target=self._update_packages, args=(packages+self.deps.keys(),)).start() # remove for i in it: @@ -596,13 +600,16 @@ class EmergeQueue: def kill_emerge (self): """Kills the emerge process.""" - try: - os.kill(self.process.pid, signal.SIGTERM) - debug("Process should be killed") - except AttributeError: - debug("AttributeError occured ==> process not exisiting - ignore") - except OSError: - debug("OSError occured ==> process already stopped - ignore") + if self.process is not None: + try: + os.kill(self.process.pid, signal.SIGTERM) + debug("Process should be killed") + except AttributeError: + debug("AttributeError occured ==> process not exisiting - ignore") + except OSError: + debug("OSError occured ==> process already stopped - ignore") + + self.process = None def remove_with_children (self, it, removeNewFlags = True): """Convenience function which removes all children of an iterator and than the iterator itself. @@ -665,3 +672,12 @@ class EmergeQueue: self.unmergequeue.remove(cpv) self.tree.remove(it) + + def is_empty (self): + """Checks whether the current queue is empty and not working. Therefore it looks, whether the queues are empty, + and the process is not running. + + @returns: True if everything is empty and the process is not running. + @rtype: bool""" + + return not (self.mergequeue or self.unmergequeue or self.oneshotmerge or self.process) diff --git a/portato/gui/qt/dialogs.py b/portato/gui/qt/dialogs.py index 7b5609e..6a80164 100644 --- a/portato/gui/qt/dialogs.py +++ b/portato/gui/qt/dialogs.py @@ -12,6 +12,9 @@ from PyQt4.QtGui import QMessageBox +def queue_not_empty_dialog(parent): + return QMessageBox.question(parent, "Portato", "There are some packages in the emerge queue and/or an emerge process is running.\nDo you really want to quit?", QMessageBox.Ok | QMessageBox.Cancel) + def io_ex_dialog (parent, ex): string = ex.strerror if ex.filename: diff --git a/portato/gui/qt/windows.py b/portato/gui/qt/windows.py index 3fa93cf..edb1873 100644 --- a/portato/gui/qt/windows.py +++ b/portato/gui/qt/windows.py @@ -852,3 +852,15 @@ class MainWindow (Window): def cb_pkg_list_selected (self, index, prev): if not index is None: self.pkgDetails.update(self.selCatName+"/"+str(index.text()), self.queue) + + def closeEvent (self, event): + if not self.queue.is_empty(): + ret = queue_not_empty_dialog(self) + if ret == Qt.QMessageBox.Cancel: + event.ignore() + return + else: + self.queue.kill_emerge() + + event.accept() + -- cgit v1.2.3-54-g00ecf