[ocrfeeder] Make the MainWindow a Gtk.Window subclass
- From: Joaquim Manuel Pereira Rocha <jrocha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ocrfeeder] Make the MainWindow a Gtk.Window subclass
- Date: Mon, 22 Dec 2014 00:12:47 +0000 (UTC)
commit a60f83c887b7d7d51d1f45fd431b87dda09c2794
Author: Joaquim Rocha <me joaquimrocha com>
Date: Sun Dec 21 10:40:01 2014 +0000
Make the MainWindow a Gtk.Window subclass
src/ocrfeeder/studio/studioBuilder.py | 37 +++++++++++++++----------------
src/ocrfeeder/studio/widgetModeler.py | 24 ++++++++++----------
src/ocrfeeder/studio/widgetPresenter.py | 28 +++++++++++-----------
3 files changed, 44 insertions(+), 45 deletions(-)
---
diff --git a/src/ocrfeeder/studio/studioBuilder.py b/src/ocrfeeder/studio/studioBuilder.py
index 7ef178c..f7b1e2f 100644
--- a/src/ocrfeeder/studio/studioBuilder.py
+++ b/src/ocrfeeder/studio/studioBuilder.py
@@ -166,7 +166,7 @@ class Studio:
Gdk.threads_leave()
def addImage(self, widget):
- file_open_dialog = widgetPresenter.FileDialog(self.main_window.window,
+ file_open_dialog = widgetPresenter.FileDialog(self.main_window,
'open',
file_filters = [(_('Images'), ['image/*'], [])])
file_open_dialog.set_select_multiple(True)
@@ -183,8 +183,7 @@ class Studio:
file_open_dialog.destroy()
def importFromScanner(self, widget):
- dialog = widgetPresenter.QueuedEventsProgressDialog(\
- self.main_window.window)
+ dialog = widgetPresenter.QueuedEventsProgressDialog(self.main_window)
item_obtain = AsyncItem(lib.obtainScanners,(),
self.__obtainScannersFinishedCb,(dialog,))
info_obtain = (_('Obtaining scanners'), _(u'Please wait…'))
@@ -196,7 +195,7 @@ class Studio:
device = None
if len(devices) > 1:
scanner_chooser_dialog = widgetPresenter.ScannerChooserDialog(\
- self.main_window.window,
+ self.main_window,
devices)
Gdk.threads_enter()
response = scanner_chooser_dialog.run()
@@ -210,14 +209,14 @@ class Studio:
device = devices[0][0]
if device:
dialog_scan = widgetPresenter.QueuedEventsProgressDialog(\
- self.main_window.window)
+ self.main_window)
item_scan = AsyncItem(lib.scan,(device,),
self.__scanFinishedCb,(dialog_scan,))
info_scan = (_('Scanning'), _(u'Please wait…'))
dialog_scan.setItemsList([(info_scan, item_scan)])
dialog_scan.run()
else:
- error = widgetPresenter.SimpleDialog(self.main_window.window,
+ error = widgetPresenter.SimpleDialog(self.main_window,
_("No scanner devices were found"),
_("Error"),
'warning')
@@ -241,7 +240,7 @@ class Studio:
Gdk.threads_leave()
def importPdf(self, widget):
- file_open_dialog = widgetPresenter.FileDialog(self.main_window.window,
+ file_open_dialog = widgetPresenter.FileDialog(self.main_window,
'open',
file_filters = [(_('PDF'), ['application/pdf'], [])])
response = file_open_dialog.run()
@@ -251,7 +250,7 @@ class Studio:
file_open_dialog.destroy()
for file_name in files:
dialog = widgetPresenter.QueuedEventsProgressDialog(
- self.main_window.window)
+ self.main_window)
item = AsyncItem(lib.convertPdfToImages,
(file_name,
self.configuration_manager.TEMPORARY_FOLDER),
@@ -266,7 +265,7 @@ class Studio:
dialog.destroy()
def addFolder(self, widget):
- file_open_dialog = widgetPresenter.FileDialog(self.main_window.window,
+ file_open_dialog = widgetPresenter.FileDialog(self.main_window,
'select-folder')
response = file_open_dialog.run()
if response == Gtk.ResponseType.OK:
@@ -286,7 +285,7 @@ class Studio:
def exportDialog(self, widget):
format_names = [format[1] for format in self.EXPORT_FORMATS.values()]
- export_dialog = widgetPresenter.ExportDialog(self.main_window.window,
+ export_dialog = widgetPresenter.ExportDialog(self.main_window,
_('Export pages'),
format_names)
response = export_dialog.run()
@@ -305,7 +304,7 @@ class Studio:
self.source_images_controler.choosePageSize()
def deleteCurrentPage(self, widget):
- delete_dialog = widgetPresenter.QuestionDialog(self.main_window.window,
+ delete_dialog = widgetPresenter.QuestionDialog(self.main_window,
_('Are you sure you want to delete the current
image?'))
response = delete_dialog.run()
if response == Gtk.ResponseType.YES:
@@ -377,7 +376,7 @@ class Studio:
self.setProjectName(project_title)
def clear(self, widget = None):
- dialog = widgetPresenter.QuestionDialog(self.main_window.window,
+ dialog = widgetPresenter.QuestionDialog(self.main_window,
_('Are you sure you want '
'to clear the project?'))
response = dialog.run()
@@ -392,7 +391,7 @@ class Studio:
self.source_images_controler.spellCheck(locale.getdefaultlocale()[0])
def preferences(self, widget = None):
- parent = self.main_window.window
+ parent = self.main_window
preferences_dialog = widgetPresenter.PreferencesDialog(parent,
self.configuration_manager,
self.ocr_engines_manager.ocr_engines)
@@ -402,7 +401,7 @@ class Studio:
preferences_dialog.destroy()
def ocrEngines(self, widget = None):
- ocr_dialog = widgetPresenter.OcrManagerDialog(self.main_window.window,
+ ocr_dialog = widgetPresenter.OcrManagerDialog(self.main_window,
self.ocr_engines_manager)
ocr_dialog.run()
if ocr_dialog.modified:
@@ -412,7 +411,7 @@ class Studio:
def warnNoOCREngines(self):
lib.debug('No OCR engines found')
- dialog = Gtk.MessageDialog(self.main_window.window,
+ dialog = Gtk.MessageDialog(self.main_window,
Gtk.DialogFlags.MODAL |
Gtk.DialogFlags.DESTROY_WITH_PARENT,
Gtk.MessageType.INFO)
@@ -434,12 +433,12 @@ class Studio:
pass
def about(self, widget = None):
- about_dialog = widgetPresenter.CustomAboutDialog(self.main_window.window)
+ about_dialog = widgetPresenter.CustomAboutDialog(self.main_window)
if about_dialog.run():
about_dialog.destroy()
def showHelpContents(self, widget = None):
- Gtk.show_uri(self.main_window.window.get_screen(),
+ Gtk.show_uri(self.main_window.get_screen(),
'ghelp:ocrfeeder',
Gtk.get_current_event_time())
@@ -471,7 +470,7 @@ class Studio:
names = []
for migration in manual_update:
names.append(migration['engine'].name)
- dialog = Gtk.MessageDialog(self.main_window.window,
+ dialog = Gtk.MessageDialog(self.main_window,
Gtk.DialogFlags.MODAL |
Gtk.DialogFlags.DESTROY_WITH_PARENT,
Gtk.MessageType.WARNING)
@@ -499,7 +498,7 @@ 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(self.main_window.window,
+ quit_dialog = widgetPresenter.QuestionDialog(self.main_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)
diff --git a/src/ocrfeeder/studio/widgetModeler.py b/src/ocrfeeder/studio/widgetModeler.py
index 520105c..942e5d1 100644
--- a/src/ocrfeeder/studio/widgetModeler.py
+++ b/src/ocrfeeder/studio/widgetModeler.py
@@ -327,7 +327,7 @@ class ImageReviewer_Controler:
if not self.__addImage(image_path_list[index], index == 0):
debug('Failed to load image "%s"' % image_path_list[index])
return
- dialog = QueuedEventsProgressDialog(self.main_window.window)
+ dialog = QueuedEventsProgressDialog(self.main_window)
for index in range(0, item_list_length):
image_path = image_path_list[index]
item = AsyncItem(self.__imagePreProcessing,
@@ -391,7 +391,7 @@ class ImageReviewer_Controler:
def deskewCurrentImage(self, widget):
reviewer = self.__getCurrentReviewer()
- dialog = QueuedEventsProgressDialog(self.main_window.window)
+ dialog = QueuedEventsProgressDialog(self.main_window)
item = AsyncItem(self.__deskewImage,
(reviewer.path_to_image,),
self.__deskewCurrentImageFinishedCb,
@@ -466,7 +466,7 @@ class ImageReviewer_Controler:
image_reviewer.performOcrForSelectedBoxes()
def __confirmOveritePossibilityByRecognition(self):
- confirm_recognition = Gtk.MessageDialog(self.main_window.window,
+ confirm_recognition = Gtk.MessageDialog(self.main_window,
message_type = Gtk.MessageType.QUESTION,
buttons = Gtk.ButtonsType.YES_NO,
flags = Gtk.DialogFlags.MODAL |
@@ -488,7 +488,7 @@ class ImageReviewer_Controler:
self.__confirmOveritePossibilityByRecognition() != Gtk.ResponseType.YES:
return
page = image_reviewer.page
- dialog = QueuedEventsProgressDialog(self.main_window.window)
+ dialog = QueuedEventsProgressDialog(self.main_window)
item = AsyncItem(self.__performRecognitionForPage,
(page,),
self.__performRecognitionForPageFinishedCb,
@@ -499,7 +499,7 @@ class ImageReviewer_Controler:
def recognizeDocument(self):
pages = self.pages_icon_view.getAllPages()
- dialog = QueuedEventsProgressDialog(self.main_window.window)
+ dialog = QueuedEventsProgressDialog(self.main_window)
items = []
i = 1
total = len(pages)
@@ -606,7 +606,7 @@ class ImageReviewer_Controler:
document_generator.save()
def __askPdfFromScratch(self):
- ask_pdf_type_dialog = Gtk.MessageDialog(self.main_window.window,
+ ask_pdf_type_dialog = Gtk.MessageDialog(self.main_window,
Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
buttons = Gtk.ButtonsType.OK_CANCEL)
ask_pdf_type_dialog.set_markup(_('What kind of PDF document do you '
@@ -650,7 +650,7 @@ class ImageReviewer_Controler:
project_saver.serialize(project_name)
def openProject(self, clear_current = True):
- open_dialog = FileDialog(self.main_window.window, 'open',
+ open_dialog = FileDialog(self.main_window, 'open',
file_filters = [(_('OCRFeeder Projects'), [], ['*.ocrf'])])
response = open_dialog.run()
project_file = None
@@ -671,7 +671,7 @@ class ImageReviewer_Controler:
def __askForNumberOfPages(self, title):
# Sync the current reviewer's page with its data
self.__getCurrentReviewer().savePageData()
- export_dialog = PagesToExportDialog(self.main_window.window,
+ export_dialog = PagesToExportDialog(self.main_window,
title)
pages = self.pages_icon_view.getAllPages()
# When there's only one document loaded or none,
@@ -689,7 +689,7 @@ class ImageReviewer_Controler:
return None
def __askForFileName(self, extension = ''):
- save_dialog = FileDialog(self.main_window.window, 'save')
+ save_dialog = FileDialog(self.main_window, 'save')
response = save_dialog.run()
if response == Gtk.ResponseType.OK:
file_name = save_dialog.get_filename()
@@ -717,7 +717,7 @@ class ImageReviewer_Controler:
def choosePageSize(self):
current_reviewer = self.__getCurrentReviewer()
current_page = current_reviewer.page
- page_size_dialog = PageSizeDialog(self.main_window.window,
+ page_size_dialog = PageSizeDialog(self.main_window,
(current_page.width, current_page.height))
response = page_size_dialog.run()
if response == Gtk.ResponseType.ACCEPT:
@@ -743,7 +743,7 @@ class ImageReviewer_Controler:
def unpaperTool(self):
current_reviewer = self.__getCurrentReviewer()
- unpaper_dialog = UnpaperDialog(self.main_window.window,
+ unpaper_dialog = UnpaperDialog(self.main_window,
current_reviewer,
self.configuration_manager.unpaper,
self.configuration_manager.TEMPORARY_FOLDER)
@@ -808,7 +808,7 @@ class ImageReviewer_Controler:
def spellCheck(self, locale):
current_reviewer = self.__getCurrentReviewer()
- SpellCheckerDialog(self.main_window.window, current_reviewer, locale)
+ SpellCheckerDialog(self.main_window, current_reviewer, locale)
def updateOcrEngines(self, ocr_engines):
n_pages = self.notebook.get_n_pages()
diff --git a/src/ocrfeeder/studio/widgetPresenter.py b/src/ocrfeeder/studio/widgetPresenter.py
index 5bdb281..4c5976c 100644
--- a/src/ocrfeeder/studio/widgetPresenter.py
+++ b/src/ocrfeeder/studio/widgetPresenter.py
@@ -38,12 +38,12 @@ import Queue
import time
_ = gettext.gettext
-class MainWindow:
+class MainWindow(Gtk.Window):
def __init__(self):
- self.window = Gtk.Window(Gtk.WindowType.TOPLEVEL)
- self.window.set_size_request(800, 600)
- self.window.set_icon_from_file(WINDOW_ICON)
+ Gtk.Window.__init__(self, Gtk.WindowType.TOPLEVEL)
+ self.set_size_request(800, 600)
+ self.set_icon_from_file(WINDOW_ICON)
self.main_box = Gtk.VBox()
self.main_box.show()
@@ -56,7 +56,7 @@ class MainWindow:
self.main_area.show()
self.main_box.pack_end(self.main_area, True, True, 0)
- self.window.add(self.main_box)
+ self.add(self.main_box)
self.main_area_left = Gtk.ScrolledWindow()
self.main_area_left.get_accessible().set_name(_('Pages'))
self.main_area_left.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
@@ -70,14 +70,14 @@ class MainWindow:
self.main_area.pack2(self.notebook, False, False)
self.action_group = None
- self.window.show()
+ self.show()
def setTitle(self, new_title):
- self.window.set_title(new_title)
+ self.set_title(new_title)
def setHeader(self, menu_items, tool_items):
ui_manager = Gtk.UIManager()
accel_group = ui_manager.get_accel_group()
- self.window.add_accel_group(accel_group)
+ self.add_accel_group(accel_group)
action_group = Gtk.ActionGroup('MainWindow')
action_group.add_actions([('File', None, _('_File')),
('Quit', Gtk.STOCK_QUIT, _('_Quit'), None, _('Exit the program'),
menu_items['exit']),
@@ -186,7 +186,7 @@ class MainWindow:
self.spellchecker_menu.set_sensitive(False)
def setDestroyEvent(self, function):
- self.window.connect('delete-event', function)
+ self.connect('delete-event', function)
def setNumberOfPages(self, nr_images):
if not self.action_group:
@@ -2051,10 +2051,10 @@ class SpellCheckerDialog():
def __init__(self, parent, current_reviewer, language):
self.builder = Gtk.Builder()
self.builder.add_from_file(OCRFEEDER_SPELLCHECKER_UI)
- self.window = self.builder.get_object('check_spelling_window')
- self.window.set_transient_for(parent)
+ self = self.builder.get_object('check_spelling_window')
+ self.set_transient_for(parent)
self.builder.connect_signals(self)
- self.window.present()
+ self.present()
self.reviewer = current_reviewer
self.text = self.reviewer.editor.box_editor.getText()
self.dictButtons = {'change_button':self.builder.get_object('change_button'),
@@ -2123,10 +2123,10 @@ class SpellCheckerDialog():
self.__next()
def close_button_clicked_cb(self, widget):
- self.window.destroy()
+ self.destroy()
def check_spelling_window_delete_event_cb(self, widget, data):
- self.window.destroy()
+ self.destroy()
def __set_no_more(self):
self.misspelled_word.set_text('')
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]