Exemple #1
0
    def terminate_program(self, save_current_file=False):
        """Run clean-up tasks and exit the program."""

        self.hide()

        if gtk.main_level() > 0:
            gtk.main_quit()

        if prefs['auto load last file'] and self.filehandler.file_loaded:
            prefs['path to last file'] = self.imagehandler.get_real_path()
            prefs['page of last file'] = self.imagehandler.get_current_page()

        else:
            prefs['path to last file'] = ''
            prefs['page of last file'] = 1

        if prefs['hide all'] and self.hide_all_forced and self.fullscreen:
            prefs['hide all'] = False

        self.write_config_files()

        self.filehandler.cleanup()
        self.imagehandler.cleanup()
        self.thumbnailsidebar.clear()
        backend.LibraryBackend().close()

        # This hack is to avoid Python issue #1856.
        for thread in threading.enumerate():
            if thread is not threading.currentThread():
                thread.join()
Exemple #2
0
    def __init__(self, window, file_handler):
        super(_LibraryDialog, self).__init__(type=Gtk.WindowType.TOPLEVEL)

        self._window = window

        self.resize(prefs['lib window width'], prefs['lib window height'])
        self.set_title(_('Library'))
        self.connect('delete_event', self.close)
        self.connect('key-press-event', self._key_press_event)

        self.filter_string = None
        self._file_handler = file_handler
        self._statusbar = Gtk.Statusbar()
        self.backend = library_backend.LibraryBackend()
        self.book_area = library_book_area._BookArea(self)
        self.control_area = library_control_area._ControlArea(self)
        self.collection_area = library_collection_area._CollectionArea(self)

        self.backend.watchlist.new_files_found += self._new_files_found

        table = Gtk.Table(n_rows=2, n_columns=2, homogeneous=False)
        table.attach(self.collection_area, 0, 1, 0, 1, Gtk.AttachOptions.FILL,
            Gtk.AttachOptions.EXPAND|Gtk.AttachOptions.FILL)
        table.attach(self.book_area, 1, 2, 0, 1, Gtk.AttachOptions.EXPAND|Gtk.AttachOptions.FILL,
            Gtk.AttachOptions.EXPAND|Gtk.AttachOptions.FILL)
        table.attach(self.control_area, 0, 2, 1, 2, Gtk.AttachOptions.EXPAND|Gtk.AttachOptions.FILL,
            Gtk.AttachOptions.FILL)

        if prefs['show statusbar']:
            table.attach(self._statusbar, 0, 2, 2, 3, Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)

        self.add(table)
        self.show_all()
        self.present()
Exemple #3
0
    def __init__(self, window, file_handler):
        gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)

        self._window = window

        self.resize(prefs['lib window width'], prefs['lib window height'])
        self.set_title(_('Library'))
        self.connect('delete_event', self.close)
        self.connect('key-press-event', self._key_press_event)

        self.filter_string = None
        self._file_handler = file_handler
        self._statusbar = gtk.Statusbar()
        self._statusbar.set_has_resize_grip(True)
        self.backend = library_backend.LibraryBackend()
        self.book_area = library_book_area._BookArea(self)
        self.control_area = library_control_area._ControlArea(self)
        self.collection_area = library_collection_area._CollectionArea(self)

        self.backend.watchlist.new_files_found += self._new_files_found

        table = gtk.Table(2, 2, False)
        table.attach(self.collection_area, 0, 1, 0, 1, gtk.FILL,
                     gtk.EXPAND | gtk.FILL)
        table.attach(self.book_area, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL,
                     gtk.EXPAND | gtk.FILL)
        table.attach(self.control_area, 0, 2, 1, 2, gtk.EXPAND | gtk.FILL,
                     gtk.FILL)

        if prefs['show statusbar']:
            table.attach(self._statusbar, 0, 2, 2, 3, gtk.FILL, gtk.FILL)

        self.add(table)
        self.show_all()
        self.present()
Exemple #4
0
    def setUp(self):
        # Database file
        fp, self.db = tempfile.mkstemp('.db', 'mcomix-test')
        os.close(fp)

        # Initialize library (path must be patched for testing)
        constants.LIBRARY_DATABASE_PATH = self.db
        self.library = backend.LibraryBackend()

        # Initialize database
        self.library.add_collection("Test")
        self.library.add_collection("Subtest")
        test_col = self.library.get_collection_by_name("Test")
        sub_col = self.library.get_collection_by_name("Subtest")
        test_col.add_collection(sub_col)
        # There is also a collection Recent that is added by default!

        # Add first two archives to no collection, remaining two
        # to subcollections.
        directory = 'test/files/archives'
        zip_archive = unicode(os.path.join(directory, '01-ZIP-Normal.zip'))
        tar_archive = unicode(os.path.join(directory, '02-TAR-Normal.tar'))
        rar_archive = unicode(os.path.join(directory, '03-RAR-Normal.rar'))
        sz_archive = unicode(os.path.join(directory, '04-7Z-Normal.7z'))

        self.library.add_book(zip_archive, None)
        self.library.add_book(tar_archive, None)
        self.library.add_book(rar_archive, test_col.id)
        self.library.add_book(sz_archive, sub_col.id)
Exemple #5
0
    def terminate_program(self):
        """Run clean-up tasks and exit the program."""

        self.hide()

        if gtk.main_level() > 0:
            gtk.main_quit()

        if prefs['auto load last file'] and self.filehandler.file_loaded:
            prefs['path to last file'] = self.imagehandler.get_real_path()
            prefs['page of last file'] = self.imagehandler.get_current_page()

        else:
            prefs['path to last file'] = ''
            prefs['page of last file'] = 1

        if prefs['hide all'] and self.hide_all_forced and self.fullscreen:
            prefs['hide all'] = False

        self.write_config_files()

        self.filehandler.close_file()
        if main_dialog._dialog is not None:
            main_dialog._dialog.close()
        backend.LibraryBackend().close()

        # This hack is to avoid Python issue #1856.
        for thread in threading.enumerate():
            if thread is not threading.currentThread():
                log.debug('Waiting for thread %s to finish before exit',
                          thread)
                thread.join()
Exemple #6
0
    def test_reopen(self):
        self.lastread.set_page(self.archive1, 1)
        self.lastread.set_page(self.archive2, 2)
        self.assertEqual(1, self.lastread.get_page(self.archive1))
        self.assertEqual(2, self.lastread.get_page(self.archive2))

        self.backend.close()
        self.backend = backend.LibraryBackend()
        self.lastread = last_read_page.LastReadPage(self.backend)
        self.lastread.set_enabled(True)

        self.assertEqual(1, self.lastread.get_page(self.archive1),
                'Page should be remembered after shutdown')
        self.assertEqual(2, self.lastread.get_page(self.archive2),
                'Page should be remembered after shutdown')
Exemple #7
0
    def setUp(self):
        # Database file
        fp, self.db = tempfile.mkstemp('.db', 'mcomix-test')
        os.close(fp)
        constants.LIBRARY_DATABASE_PATH = self.db

        # Dummy archive (files are checked for existance)
        self.archive1 = os.path.abspath(u'test/files/archives/01-ZIP-Normal.zip')
        self.archive2 = os.path.abspath(u'test/files/archives/02-TAR-Normal.tar')

        # Library backend
        self.backend = backend.LibraryBackend()

        self.lastread = last_read_page.LastReadPage(self.backend)
        self.lastread.set_enabled(True)
Exemple #8
0
    def __init__(self, window):
        #: Indicates if files/archives are currently loaded/loading.
        self.file_loaded = False
        self.file_loading = False
        #: Indicate if files/archives load has failed.
        self.file_load_failed = False
        #: None if current file is not an archive, or unrecognized format.
        self.archive_type = None

        #: Either path to the current archive, or first file in image list.
        #: This is B{not} the path to the currently open page.
        self._current_file = None
        #: Reference to L{MainWindow}.
        self._window = window
        #: Path to opened archive file, or directory containing current images.
        self._base_path = None
        #: Temporary directory used for extracting archives.
        self._tmp_dir = tempfile.mkdtemp(prefix=u'mcomix.', suffix=os.sep)
        #: If C{True}, no longer wait for files to get extracted.
        self._stop_waiting = False
        #: List of comment files inside of the currently opened archive.
        self._comment_files = []
        #: Mapping of absolute paths to archive path names.
        self._name_table = {}
        #: Archive extractor.
        self._extractor = archive_extractor.Extractor()
        self._extractor.file_extracted += self._extracted_file
        self._extractor.contents_listed += self._listed_contents
        #: Condition to wait on when extracting archives and waiting on files.
        self._condition = None
        #: Provides a list of available files/archives in the open directory.
        self._file_provider = None
        #: Keeps track of the last read page in archives
        self.last_read_page = last_read_page.LastReadPage(
            backend.LibraryBackend())
        #: Regexp used for determining which archive files are images.
        self._image_re = constants.SUPPORTED_IMAGE_REGEX
        #: Regexp used for determining which archive files are comment files.
        self._comment_re = None
        self.update_comment_extensions()
        #: Forces call to window.draw_image (if loading is delayed by user interaction)
        self._must_call_draw = False

        self.last_read_page.set_enabled(bool(prefs['store recent file info']))
Exemple #9
0
    def terminate_program(self):
        '''Run clean-up tasks and exit the program.'''

        self.hide()

        if Gtk.main_level() > 0:
            Gtk.main_quit()

        if prefs['auto load last file'] and self.filehandler.file_loaded:
            path = self.imagehandler.get_real_path()
            path = tools.relpath2root(
                path, abs_fallback=prefs['portable allow abspath'])

            if not path:
                # path is None, means running in portable mode
                # and currect image is out of same mount point
                # so do not save as last file
                prefs['path to last file'] = ''
                prefs['page of last file'] = 1
            else:
                prefs['path to last file'] = self.imagehandler.get_real_path()
                prefs[
                    'page of last file'] = self.imagehandler.get_current_page(
                    )

        else:
            prefs['path to last file'] = ''
            prefs['page of last file'] = 1

        if prefs['hide all'] and self.hide_all_forced and self.fullscreen:
            prefs['hide all'] = False

        self.write_config_files()

        self.filehandler.close_file()
        if main_dialog._dialog is not None:
            main_dialog._dialog.close()
        backend.LibraryBackend().close()
        self.slideshow.stop()