Пример #1
0
    def __init__(self, asset, app):
        Gtk.Window.__init__(self)
        self._asset = asset
        self.app = app

        self.set_title(_("Preview"))
        self.set_type_hint(Gdk.WindowTypeHint.UTILITY)
        self.set_transient_for(app.gui)

        self._previewer = PreviewWidget(app.settings, minimal=True)
        self.add(self._previewer)
        self._previewer.preview_uri(self._asset.get_id())
        self._previewer.show()

        self.connect("focus-out-event", self._leave_preview_cb)
Пример #2
0
    def showImportSourcesDialog(self):
        """Pop up the "Import Sources" dialog box"""
        if self._importDialog:
            return

        chooser_action = Gtk.FileChooserAction.OPEN
        dialogtitle = _("Select One or More Files")

        close_after = Gtk.CheckButton(label=_("Close after importing files"))
        close_after.set_active(self.app.settings.closeImportDialog)

        self._importDialog = Gtk.FileChooserDialog(title=dialogtitle,
                                                   transient_for=None,
                                                   action=chooser_action)

        self._importDialog.set_icon_name("pitivi")
        self._importDialog.add_buttons(_("Cancel"), Gtk.ResponseType.CANCEL,
                                       _("Add"), Gtk.ResponseType.OK)
        self._importDialog.props.extra_widget = close_after
        self._importDialog.set_default_response(Gtk.ResponseType.OK)
        self._importDialog.set_select_multiple(True)
        self._importDialog.set_modal(True)
        self._importDialog.set_transient_for(self.app.gui)
        self._importDialog.set_current_folder(
            self.app.settings.lastImportFolder)
        self._importDialog.connect('response', self._dialogBoxResponseCb)
        previewer = PreviewWidget(self.app.settings)
        self._importDialog.set_preview_widget(previewer)
        self._importDialog.set_use_preview_label(False)
        self._importDialog.connect('update-preview',
                                   previewer.add_preview_request)
        # Filter for the "known good" formats by default
        filt_supported = Gtk.FileFilter()
        filt_known = Gtk.FileFilter()
        filt_supported.set_name(_("Supported file formats"))
        for category, mime_types in SUPPORTED_FILE_FORMATS.items():
            for mime in mime_types:
                filt_supported.add_mime_type(category + "/" + mime)
                filt_known.add_mime_type(category + "/" + mime)
        # Also allow showing known but not reliable demuxers
        filt_known.set_name(_("All known file formats"))
        for fullmime in OTHER_KNOWN_FORMATS:
            filt_known.add_mime_type(fullmime)
        # ...and allow the user to override our whitelists
        default = Gtk.FileFilter()
        default.set_name(_("All files"))
        default.add_pattern("*")
        self._importDialog.add_filter(filt_supported)
        self._importDialog.add_filter(filt_known)
        self._importDialog.add_filter(default)
        self._importDialog.show()
Пример #3
0
    def showImportSourcesDialog(self):
        """Pop up the "Import Sources" dialog box"""
        if self._importDialog:
            return

        chooser_action = Gtk.FileChooserAction.OPEN
        dialogtitle = _("Select One or More Files")

        close_after = Gtk.CheckButton(_("Close after importing files"))
        close_after.set_active(self.app.settings.closeImportDialog)

        self._importDialog = Gtk.FileChooserDialog(dialogtitle, None,
                                           chooser_action,
                                           (Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE,
                                            Gtk.STOCK_ADD, Gtk.ResponseType.OK))
        self._importDialog.set_icon_name("pitivi")
        self._importDialog.props.extra_widget = close_after
        self._importDialog.set_default_response(Gtk.ResponseType.OK)
        self._importDialog.set_select_multiple(True)
        self._importDialog.set_modal(False)
        self._importDialog.set_current_folder(self.app.settings.lastImportFolder)
        self._importDialog.connect('response', self._dialogBoxResponseCb)
        self._importDialog.connect('close', self._dialogBoxCloseCb)
        pw = PreviewWidget(self.app)
        self._importDialog.set_preview_widget(pw)
        self._importDialog.set_use_preview_label(False)
        self._importDialog.connect('update-preview', pw.add_preview_request)
        # Filter for the "known good" formats by default
        filt_supported = Gtk.FileFilter()
        filt_known = Gtk.FileFilter()
        filt_supported.set_name(_("Supported file formats"))
        for category in SUPPORTED_FILE_FORMATS:
            # Category can be "video", "audio", "image", "application"
            for mime in SUPPORTED_FILE_FORMATS[category]:
                filt_supported.add_mime_type(category + "/" + mime)
                filt_known.add_mime_type(category + "/" + mime)
        # Also allow showing known but not reliable demuxers
        filt_known.set_name(_("All known file formats"))
        for fullmime in OTHER_KNOWN_FORMATS:
            filt_known.add_mime_type(fullmime)
        # ...and allow the user to override our whitelists
        default = Gtk.FileFilter()
        default.set_name(_("All files"))
        default.add_pattern("*")
        self._importDialog.add_filter(filt_supported)
        self._importDialog.add_filter(filt_known)
        self._importDialog.add_filter(default)
        self._importDialog.show()
Пример #4
0
    def __init__(self, asset, app):
        Gtk.Window.__init__(self)
        self._asset = asset
        self.app = app

        self.set_title(_("Preview"))
        self.set_type_hint(Gdk.WindowTypeHint.UTILITY)
        self.set_transient_for(app.gui)

        self._previewer = PreviewWidget(app.settings, minimal=True)
        self.add(self._previewer)
        self._previewer.preview_uri(self._asset.get_id())
        self._previewer.show()

        self.connect("focus-out-event", self._leavePreviewCb)
        self.connect("key-press-event", self._keyPressCb)
Пример #5
0
 def __setup_file_chooser(uri, settings):
     chooser = Gtk.FileChooserWidget(action=Gtk.FileChooserAction.OPEN)
     chooser.set_select_multiple(False)
     previewer = PreviewWidget(settings, discover_sync=True)
     chooser.set_preview_widget(previewer)
     chooser.set_use_preview_label(False)
     chooser.connect("update-preview", previewer.update_preview_cb)
     chooser.set_current_folder(settings.lastProjectFolder)
     # Use a Gtk FileFilter to only show files with the same extension
     # Note that splitext gives us the extension with the ".", no need to
     # add it inside the filter string.
     unused_filename, extension = os.path.splitext(uri)
     filter_ = Gtk.FileFilter()
     # Translators: this is a format filter in a filechooser. Ex: "AVI files"
     filter_.set_name(_("%s files") % extension)
     filter_.add_pattern("*%s" % extension.lower())
     filter_.add_pattern("*%s" % extension.upper())
     default = Gtk.FileFilter()
     default.set_name(_("All files"))
     default.add_pattern("*")
     chooser.add_filter(filter_)
     chooser.add_filter(default)
     return chooser
Пример #6
0
class PreviewAssetWindow(Gtk.Window):
    """Window for previewing a video or audio asset.

    Args:
        asset (GES.UriClipAsset): The asset to be previewed.
        app (Pitivi): The app.
    """
    def __init__(self, asset, app):
        Gtk.Window.__init__(self)
        self._asset = asset
        self.app = app

        self.set_title(_("Preview"))
        self.set_type_hint(Gdk.WindowTypeHint.UTILITY)
        self.set_transient_for(app.gui)

        self._previewer = PreviewWidget(app.settings, minimal=True)
        self.add(self._previewer)
        self._previewer.preview_uri(self._asset.get_id())
        self._previewer.show()

        self.connect("focus-out-event", self._leave_preview_cb)

    def preview(self):
        """Shows the window and starts the playback."""
        width, height = self._calculate_preview_window_size()
        self.resize(width, height)
        # Setting the position of the window only works if it's currently hidden
        # otherwise, after the resize the position will not be readjusted
        self.set_position(Gtk.WindowPosition.CENTER_ON_PARENT)
        self.show()

        self._previewer.play()
        # Hack so that we really really force the "utility" window to be
        # focused
        self.present()

    def _calculate_preview_window_size(self):
        info = self._asset.get_info()
        video_streams = info.get_video_streams()
        if not video_streams:
            # There is no video/image stream. This is an audio file.
            # Resize to the minimum and let the window manager deal with it.
            return 1, 1
        # For videos and images, automatically resize the window
        # Try to keep it 1:1 if it can fit within 85% of the parent window
        video = video_streams[0]
        img_width = video.get_natural_width()
        img_height = video.get_natural_height()
        mainwindow_width, mainwindow_height = self.app.gui.get_size()
        max_width = 0.85 * mainwindow_width
        max_height = 0.85 * mainwindow_height

        controls_height = self._previewer.bbox.get_preferred_size()[0].height
        if img_width < max_width and (img_height +
                                      controls_height) < max_height:
            # The video is small enough, keep it 1:1
            return img_width, img_height + controls_height
        else:
            # The video is too big, size it down
            # TODO: be smarter, figure out which (width, height) is bigger
            new_height = max_width * img_height / img_width
            return int(max_width), int(new_height + controls_height)

    def _leave_preview_cb(self, window, unused):
        self.destroy()
        return True
Пример #7
0
class PreviewAssetWindow(Gtk.Window):
    """Window for previewing a video or audio asset.

    Args:
        asset (GES.UriClipAsset): The asset to be previewed.
        app (Pitivi): The app.
    """

    def __init__(self, asset, app):
        Gtk.Window.__init__(self)
        self._asset = asset
        self.app = app

        self.set_title(_("Preview"))
        self.set_type_hint(Gdk.WindowTypeHint.UTILITY)
        self.set_transient_for(app.gui)

        self._previewer = PreviewWidget(app.settings, minimal=True)
        self.add(self._previewer)
        self._previewer.preview_uri(self._asset.get_id())
        self._previewer.show()

        self.connect("focus-out-event", self._leavePreviewCb)
        self.connect("key-press-event", self._keyPressCb)

    def preview(self):
        """Shows the window and starts the playback."""
        width, height = self._calculatePreviewWindowSize()
        self.resize(width, height)
        # Setting the position of the window only works if it's currently hidden
        # otherwise, after the resize the position will not be readjusted
        self.set_position(Gtk.WindowPosition.CENTER_ON_PARENT)
        self.show()

        self._previewer.play()
        # Hack so that we really really force the "utility" window to be
        # focused
        self.present()

    def _calculatePreviewWindowSize(self):
        info = self._asset.get_info()
        video_streams = info.get_video_streams()
        if not video_streams:
            # There is no video/image stream. This is an audio file.
            # Resize to the minimum and let the window manager deal with it.
            return 1, 1
        # For videos and images, automatically resize the window
        # Try to keep it 1:1 if it can fit within 85% of the parent window
        video = video_streams[0]
        img_width = video.get_square_width()
        img_height = video.get_height()
        mainwindow_width, mainwindow_height = self.app.gui.get_size()
        max_width = 0.85 * mainwindow_width
        max_height = 0.85 * mainwindow_height

        controls_height = self._previewer.bbox.get_preferred_size()[0].height
        if img_width < max_width and (img_height + controls_height) < max_height:
            # The video is small enough, keep it 1:1
            return img_width, img_height + controls_height
        else:
            # The video is too big, size it down
            # TODO: be smarter, figure out which (width, height) is bigger
            new_height = max_width * img_height / img_width
            return int(max_width), int(new_height + controls_height)

    def _leavePreviewCb(self, window, unused):
        self.destroy()
        return True

    def _keyPressCb(self, unused_widget, event):
        if event.keyval in (Gdk.KEY_Escape, Gdk.KEY_Q, Gdk.KEY_q):
            self.destroy()
        elif event.keyval == Gdk.KEY_space:
            self._previewer.togglePlayback()
        return True