[ocrfeeder] Add parents to all dialogs
- From: Joaquim Manuel Pereira Rocha <jrocha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ocrfeeder] Add parents to all dialogs
- Date: Sat, 20 Dec 2014 22:40:40 +0000 (UTC)
commit 24825549e4914da730148af4a190179d941d4d1b
Author: Joaquim Rocha <me joaquimrocha com>
Date: Fri Dec 19 14:56:06 2014 +0000
Add parents to all dialogs
src/ocrfeeder/studio/studioBuilder.py | 30 ++++++---
src/ocrfeeder/studio/widgetModeler.py | 14 +++--
src/ocrfeeder/studio/widgetPresenter.py | 108 ++++++++++++++++++++-----------
3 files changed, 100 insertions(+), 52 deletions(-)
---
diff --git a/src/ocrfeeder/studio/studioBuilder.py b/src/ocrfeeder/studio/studioBuilder.py
index 4d597ad..7ef178c 100644
--- a/src/ocrfeeder/studio/studioBuilder.py
+++ b/src/ocrfeeder/studio/studioBuilder.py
@@ -166,7 +166,9 @@ class Studio:
Gdk.threads_leave()
def addImage(self, widget):
- file_open_dialog = widgetPresenter.FileDialog('open', file_filters = [(_('Images'), ['image/*'],
[])])
+ file_open_dialog = widgetPresenter.FileDialog(self.main_window.window,
+ 'open',
+ file_filters = [(_('Images'), ['image/*'], [])])
file_open_dialog.set_select_multiple(True)
if self._last_images_dir:
@@ -215,7 +217,7 @@ class Studio:
dialog_scan.setItemsList([(info_scan, item_scan)])
dialog_scan.run()
else:
- error = widgetPresenter.SimpleDialog(\
+ error = widgetPresenter.SimpleDialog(self.main_window.window,
_("No scanner devices were found"),
_("Error"),
'warning')
@@ -239,7 +241,9 @@ class Studio:
Gdk.threads_leave()
def importPdf(self, widget):
- file_open_dialog = widgetPresenter.FileDialog('open', file_filters = [(_('PDF'),
['application/pdf'], [])])
+ file_open_dialog = widgetPresenter.FileDialog(self.main_window.window,
+ 'open',
+ file_filters = [(_('PDF'), ['application/pdf'], [])])
response = file_open_dialog.run()
files = []
if response == Gtk.ResponseType.OK:
@@ -262,7 +266,8 @@ class Studio:
dialog.destroy()
def addFolder(self, widget):
- file_open_dialog = widgetPresenter.FileDialog('select-folder')
+ file_open_dialog = widgetPresenter.FileDialog(self.main_window.window,
+ 'select-folder')
response = file_open_dialog.run()
if response == Gtk.ResponseType.OK:
filenames = file_open_dialog.get_filenames()
@@ -281,7 +286,8 @@ class Studio:
def exportDialog(self, widget):
format_names = [format[1] for format in self.EXPORT_FORMATS.values()]
- export_dialog = widgetPresenter.ExportDialog(_('Export pages'),
+ export_dialog = widgetPresenter.ExportDialog(self.main_window.window,
+ _('Export pages'),
format_names)
response = export_dialog.run()
if response == Gtk.ResponseType.ACCEPT:
@@ -299,7 +305,8 @@ class Studio:
self.source_images_controler.choosePageSize()
def deleteCurrentPage(self, widget):
- delete_dialog = widgetPresenter.QuestionDialog(_('Are you sure you want to delete the current
image?'))
+ delete_dialog = widgetPresenter.QuestionDialog(self.main_window.window,
+ _('Are you sure you want to delete the current
image?'))
response = delete_dialog.run()
if response == Gtk.ResponseType.YES:
self.source_images_controler.deleteCurrentPage()
@@ -370,7 +377,8 @@ class Studio:
self.setProjectName(project_title)
def clear(self, widget = None):
- dialog = widgetPresenter.QuestionDialog(_('Are you sure you want '
+ dialog = widgetPresenter.QuestionDialog(self.main_window.window,
+ _('Are you sure you want '
'to clear the project?'))
response = dialog.run()
if response == Gtk.ResponseType.YES:
@@ -394,7 +402,8 @@ class Studio:
preferences_dialog.destroy()
def ocrEngines(self, widget = None):
- ocr_dialog = widgetPresenter.OcrManagerDialog(self.ocr_engines_manager)
+ ocr_dialog = widgetPresenter.OcrManagerDialog(self.main_window.window,
+ self.ocr_engines_manager)
ocr_dialog.run()
if ocr_dialog.modified:
ocr_engines = self.ocr_engines_manager.ocr_engines
@@ -425,7 +434,7 @@ class Studio:
pass
def about(self, widget = None):
- about_dialog = widgetPresenter.CustomAboutDialog()
+ about_dialog = widgetPresenter.CustomAboutDialog(self.main_window.window)
if about_dialog.run():
about_dialog.destroy()
@@ -490,7 +499,8 @@ class Studio:
def quit(self, widget = None, data = None):
if not self.project_name and not self.pages_icon_view.isEmpty():
- quit_dialog = widgetPresenter.QuestionDialog('<b>' + _("The project hasn't been saved.") +
'</b>', Gtk.ButtonsType.NONE)
+ quit_dialog = widgetPresenter.QuestionDialog(self.main_window.window,
+ '<b>' + _("The project hasn't been saved.") +
'</b>', Gtk.ButtonsType.NONE)
quit_dialog.format_secondary_text(_('Do you want to save it before closing?'))
quit_dialog.add_buttons(_('Close anyway'), Gtk.ResponseType.NO, Gtk.STOCK_CANCEL,
Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE_AS, Gtk.ResponseType.YES)
response = quit_dialog.run()
diff --git a/src/ocrfeeder/studio/widgetModeler.py b/src/ocrfeeder/studio/widgetModeler.py
index 7361244..7cdf82c 100644
--- a/src/ocrfeeder/studio/widgetModeler.py
+++ b/src/ocrfeeder/studio/widgetModeler.py
@@ -650,7 +650,8 @@ class ImageReviewer_Controler:
project_saver.serialize(project_name)
def openProject(self, clear_current = True):
- open_dialog = FileDialog('open', file_filters = [(_('OCRFeeder Projects'), [], ['*.ocrf'])])
+ open_dialog = FileDialog(self.main_window.window, 'open',
+ file_filters = [(_('OCRFeeder Projects'), [], ['*.ocrf'])])
response = open_dialog.run()
project_file = None
if response == Gtk.ResponseType.OK:
@@ -670,7 +671,8 @@ class ImageReviewer_Controler:
def __askForNumberOfPages(self, title):
# Sync the current reviewer's page with its data
self.__getCurrentReviewer().savePageData()
- export_dialog = PagesToExportDialog(title)
+ export_dialog = PagesToExportDialog(self.main_window.window,
+ title)
pages = self.pages_icon_view.getAllPages()
# When there's only one document loaded or none,
# we don't ask for the number of pages to export
@@ -687,7 +689,7 @@ class ImageReviewer_Controler:
return None
def __askForFileName(self, extension = ''):
- save_dialog = FileDialog('save')
+ save_dialog = FileDialog(self.main_window.window, 'save')
response = save_dialog.run()
if response == Gtk.ResponseType.OK:
file_name = save_dialog.get_filename()
@@ -715,7 +717,8 @@ class ImageReviewer_Controler:
def choosePageSize(self):
current_reviewer = self.__getCurrentReviewer()
current_page = current_reviewer.page
- page_size_dialog = PageSizeDialog((current_page.width, current_page.height))
+ page_size_dialog = PageSizeDialog(self.main_window.window,
+ (current_page.width, current_page.height))
response = page_size_dialog.run()
if response == Gtk.ResponseType.ACCEPT:
size = page_size_dialog.getSize()
@@ -740,7 +743,8 @@ class ImageReviewer_Controler:
def unpaperTool(self):
current_reviewer = self.__getCurrentReviewer()
- unpaper_dialog = UnpaperDialog(current_reviewer,
+ unpaper_dialog = UnpaperDialog(self.main_window.window,
+ current_reviewer,
self.configuration_manager.unpaper,
self.configuration_manager.TEMPORARY_FOLDER)
if unpaper_dialog.run() == Gtk.ResponseType.ACCEPT:
diff --git a/src/ocrfeeder/studio/widgetPresenter.py b/src/ocrfeeder/studio/widgetPresenter.py
index 134bc01..de67316 100644
--- a/src/ocrfeeder/studio/widgetPresenter.py
+++ b/src/ocrfeeder/studio/widgetPresenter.py
@@ -754,7 +754,7 @@ class BoxEditor_DataBox_Controller:
class FileDialog(Gtk.FileChooserDialog):
- def __init__(self, type = 'open', current_folder = '~', filename = None, file_filters = []):
+ def __init__(self, parent, type = 'open', current_folder = '~', filename = None, file_filters = []):
dialog_type = Gtk.FileChooserAction.SAVE
title = _('Save File')
button = Gtk.STOCK_SAVE
@@ -766,8 +766,11 @@ class FileDialog(Gtk.FileChooserDialog):
title = _('Open Folder')
dialog_type = Gtk.FileChooserAction.SELECT_FOLDER
button = Gtk.STOCK_OPEN
- super(FileDialog, self).__init__(title = title, action = dialog_type, buttons = (Gtk.STOCK_CANCEL,
Gtk.ResponseType.CANCEL,
- button,
Gtk.ResponseType.OK))
+ super(FileDialog, self).__init__(title = title, parent = parent,
+ action = dialog_type,
+ buttons = (Gtk.STOCK_CANCEL,
+ Gtk.ResponseType.CANCEL,
+ button, Gtk.ResponseType.OK))
self.set_current_folder(os.path.expanduser(current_folder))
if filename:
self.set_filename(filename)
@@ -783,8 +786,9 @@ class FileDialog(Gtk.FileChooserDialog):
class PagesToExportDialog(Gtk.Dialog):
- def __init__(self, title = None):
+ def __init__(self, parent, title = None):
super(PagesToExportDialog, self).__init__(title,
+ parent = parent,
flags = Gtk.DialogFlags.MODAL,
buttons = (Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT,
Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))
@@ -804,9 +808,14 @@ class PagesToExportDialog(Gtk.Dialog):
class ExportDialog(Gtk.Dialog):
- def __init__(self, title = None, format_choices = []):
- super(ExportDialog, self).__init__(title, flags = Gtk.DialogFlags.MODAL, buttons =
(Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT,
- Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))
+ def __init__(self, parent, title = None, format_choices = []):
+ super(ExportDialog, self).__init__(title, parent = parent,
+ flags = Gtk.DialogFlags.MODAL,
+ buttons = (Gtk.STOCK_CANCEL,
+ Gtk.ResponseType.REJECT,
+
+ Gtk.STOCK_OK,
+ Gtk.ResponseType.ACCEPT))
self.__makeFormatSelectionArea(format_choices)
self.set_icon_from_file(WINDOW_ICON)
@@ -827,9 +836,14 @@ class ExportDialog(Gtk.Dialog):
class PageSizeDialog(Gtk.Dialog):
- def __init__(self, current_page_size):
- super(PageSizeDialog, self).__init__(_('Page size'), flags = Gtk.DialogFlags.MODAL, buttons =
(Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT,
- Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))
+ def __init__(self, parent, current_page_size):
+ super(PageSizeDialog, self).__init__(_('Page size'),
+ parent = parent,
+ flags = Gtk.DialogFlags.MODAL,
+ buttons = (Gtk.STOCK_CANCEL,
+ Gtk.ResponseType.REJECT,
+ Gtk.STOCK_OK,
+ Gtk.ResponseType.ACCEPT))
self.__makePageSizeArea(current_page_size)
self.paper_sizes.connect('changed', self.__changedPageSize, current_page_size)
self.set_icon_from_file(WINDOW_ICON)
@@ -909,8 +923,12 @@ class PageSizeDialog(Gtk.Dialog):
class QuestionDialog(Gtk.MessageDialog):
- def __init__(self, message, buttons = Gtk.ButtonsType.YES_NO):
- super(QuestionDialog, self).__init__(None, message_type = Gtk.MessageType.QUESTION, flags =
Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, buttons = buttons)
+ def __init__(self, parent, message, buttons = Gtk.ButtonsType.YES_NO):
+ super(QuestionDialog, self).__init__(parent = parent,
+ message_type = Gtk.MessageType.QUESTION,
+ flags = Gtk.DialogFlags.MODAL |
+ Gtk.DialogFlags.DESTROY_WITH_PARENT,
+ buttons = buttons)
self.set_icon_from_file(WINDOW_ICON)
self.set_markup(message)
@@ -920,14 +938,17 @@ class WarningDialog(Gtk.MessageDialog):
super(WarningDialog, self).__init__(message_type = Gtk.MessageType.WARNING,
buttons = buttons,
parent = parent)
- self.set_icon_from_file(WINDOW_ICON)
- self.set_markup(message)
class UnpaperDialog(Gtk.Dialog):
- def __init__(self, reviewer , unpaper, temp_dir = '/tmp'):
- super(UnpaperDialog, self).__init__(_('Unpaper Image Processor'), flags = Gtk.DialogFlags.MODAL,
buttons = (Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT,
- Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))
+ def __init__(self, parent, reviewer , unpaper, temp_dir = '/tmp'):
+ super(UnpaperDialog, self).__init__(_('Unpaper Image Processor'),
+ parent = parent,
+ flags = Gtk.DialogFlags.MODAL,
+ buttons = (Gtk.STOCK_CANCEL,
+ Gtk.ResponseType.REJECT,
+ Gtk.STOCK_OK,
+ Gtk.ResponseType.ACCEPT))
self.unpaper_preferences = UnpaperPreferences()
self.reviewer = reviewer
self.unpaper = unpaper
@@ -974,7 +995,7 @@ class UnpaperDialog(Gtk.Dialog):
if os.path.exists(unpapered_image):
unpapered_image = lib.getNonExistingFileName(unpapered_image)
command += ' %s %s' % (name, unpapered_image)
- progress_bar = CommandProgressBarDialog(command, _('Performing Unpaper'), _(u'Performing unpaper.
Please wait…'))
+ progress_bar = CommandProgressBarDialog(self, command, _('Performing Unpaper'), _(u'Performing
unpaper. Please wait…'))
progress_bar.run()
self.unpapered_image = unpapered_image
@@ -1165,11 +1186,13 @@ class UnpaperPreferencesDialog(Gtk.Dialog):
class SimpleDialog(Gtk.MessageDialog):
- def __init__(self, message, title = '', type = 'info'):
+ def __init__(self, parent, message, title = '', type = 'info'):
message_type = Gtk.MessageType.INFO
if type == 'warning':
message_type = Gtk.MessageType.WARNING
- super(SimpleDialog, self).__init__(message_type = message_type, buttons = Gtk.ButtonsType.OK)
+ super(SimpleDialog, self).__init__(parent = parent,
+ message_type = message_type,
+ buttons = Gtk.ButtonsType.OK)
self.set_title(title)
self.set_markup(message)
self.set_icon_from_file(WINDOW_ICON)
@@ -1180,8 +1203,10 @@ class SimpleDialog(Gtk.MessageDialog):
class CommandProgressBarDialog(Gtk.Dialog):
- def __init__(self, command, title = '', label = ''):
- super(CommandProgressBarDialog, self).__init__(_(title), flags = Gtk.DialogFlags.MODAL)
+ def __init__(self, parent, command, title = '', label = ''):
+ super(CommandProgressBarDialog, self).__init__(_(title),
+ parent = parent,
+ flags = Gtk.DialogFlags.MODAL)
self.__makeProgressBar(label)
self.vbox.show_all()
self.command = command
@@ -1206,7 +1231,7 @@ class CommandProgressBarDialog(Gtk.Dialog):
try:
self.process = subprocess.Popen(self.command.split(), stdout = subprocess.PIPE, stderr =
subprocess.STDOUT, bufsize=1)
except:
- warning = SimpleDialog(_('An error occurred!'), _('Error'), 'warning')
+ warning = SimpleDialog(self, _('An error occurred!'), _('Error'), 'warning')
warning.run()
return False
self.timer = GLib.timeout_add(100, self.__pulse)
@@ -1217,7 +1242,7 @@ class CommandProgressBarDialog(Gtk.Dialog):
exit_value = self.process.poll()
if exit_value != None:
if exit_value != 0:
- warning = SimpleDialog(_('An error occurred!'), _('Error'), 'warning')
+ warning = SimpleDialog(self, _('An error occurred!'), _('Error'), 'warning')
warning.run()
self.destroy()
return False
@@ -1457,7 +1482,7 @@ class PreferencesDialog(Gtk.Dialog):
return engines_frame
def __unpaperSelectDialog(self, widget):
- unpaper_select_dialog = FileDialog('open')
+ unpaper_select_dialog = FileDialog(self, 'open')
if unpaper_select_dialog.run() == Gtk.ResponseType.OK:
self.unpaper_entry.set_text(unpaper_select_dialog.get_filename())
unpaper_select_dialog.destroy()
@@ -1709,8 +1734,9 @@ class PreferencesDialog(Gtk.Dialog):
class SystemEnginesDialog(Gtk.Dialog):
- def __init__(self, engines):
+ def __init__(self, parent, engines):
super(SystemEnginesDialog, self).__init__(_('OCR Engines'),
+ parent = parent,
flags = Gtk.DialogFlags.MODAL |
Gtk.DialogFlags.DESTROY_WITH_PARENT,
buttons = (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
@@ -1747,8 +1773,12 @@ class SystemEnginesDialog(Gtk.Dialog):
class OcrManagerDialog(Gtk.Dialog):
- def __init__(self, engines_manager):
- super(OcrManagerDialog, self).__init__(_('OCR Engines'), flags = Gtk.DialogFlags.MODAL, buttons =
(Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE))
+ def __init__(self, parent, engines_manager):
+ super(OcrManagerDialog, self).__init__(_('OCR Engines'),
+ parent = parent,
+ flags = Gtk.DialogFlags.MODAL,
+ buttons = (Gtk.STOCK_CLOSE,
+ Gtk.ResponseType.CLOSE))
self.engines_manager = engines_manager
self.set_size_request(400, -1)
self.list_store = Gtk.ListStore(str)
@@ -1793,7 +1823,7 @@ class OcrManagerDialog(Gtk.Dialog):
selection = self.tree_view.get_selection()
model, iter = selection.get_selected()
if iter:
- delete_dialog = QuestionDialog(_('Are you sure you want to delete this engine?'))
+ delete_dialog = QuestionDialog(self, _('Are you sure you want to delete this engine?'))
response = delete_dialog.run()
if response == Gtk.ResponseType.YES:
self.modified = True
@@ -1814,7 +1844,7 @@ class OcrManagerDialog(Gtk.Dialog):
self.__engine_settings(widget, engine)
def __engine_settings(self, widget, engine = None):
- new_ocr_dialog = OcrSettingsDialog(self.engines_manager, engine)
+ new_ocr_dialog = OcrSettingsDialog(self, self.engines_manager, engine)
quit = False
while not quit:
if new_ocr_dialog.run() == Gtk.ResponseType.ACCEPT:
@@ -1851,7 +1881,7 @@ class OcrManagerDialog(Gtk.Dialog):
info.run()
info.destroy()
return
- engines_dialog = SystemEnginesDialog(engines)
+ engines_dialog = SystemEnginesDialog(self, engines)
response = engines_dialog.run()
if response == Gtk.ResponseType.ACCEPT:
engines = engines_dialog.getChosenEngines()
@@ -1863,12 +1893,16 @@ class OcrManagerDialog(Gtk.Dialog):
class OcrSettingsDialog(Gtk.Dialog):
- def __init__(self, engine_manager, engine = None):
+ def __init__(self, parent, engine_manager, engine = None):
label = _('OCR Engines')
if engine:
label = _('%s engine') % engine.name
- super(OcrSettingsDialog, self).__init__(label, flags = Gtk.DialogFlags.MODAL, buttons =
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
- Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))
+ super(OcrSettingsDialog, self).__init__(label, parent = parent,
+ flags = Gtk.DialogFlags.MODAL,
+ buttons = (Gtk.STOCK_CANCEL,
+ Gtk.ResponseType.CANCEL,
+ Gtk.STOCK_OK,
+ Gtk.ResponseType.ACCEPT))
self.engine_manager = engine_manager
self.engine = engine
self.vbox.add(self.__makeMainArea())
@@ -1968,7 +2002,7 @@ class OcrSettingsDialog(Gtk.Dialog):
self.engine_manager.addNewEngine(engine)
return True
except:
- SimpleDialog(_('Error setting the new engine; please check your engine settings.'),
_('Warning'), 'warning').run()
+ SimpleDialog(self, _('Error setting the new engine; please check your engine settings.'),
_('Warning'), 'warning').run()
print sys.exc_info()
return False
@@ -1990,8 +2024,8 @@ class OcrSettingsDialog(Gtk.Dialog):
class CustomAboutDialog(Gtk.AboutDialog):
- def __init__(self):
- super(CustomAboutDialog, self).__init__()
+ def __init__(self, parent):
+ super(CustomAboutDialog, self).__init__(parent = parent)
self.set_size_request(350, -1)
self.set_name(OCRFEEDER_STUDIO_NAME)
self.set_program_name(OCRFEEDER_STUDIO_NAME)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]