Exemplo n.º 1
0
class CentralWidget(QSplitter):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.listWidget = QListWidget(self)
        self.viewer = ViewerWidget(self)
        self.paths = []
        self.names = []
        self.name = ''
        self.mesh = None
        self.grabKeyboard()

        self.listWidget.itemSelectionChanged.connect(
            self.cb_itemSelectionChanged)

        self.initLayout()

    def cb_itemSelectionChanged(self):
        current_row = self.listWidget.currentRow()
        if len(self.paths) > current_row:
            path = self.paths[current_row]
            self.name = self.names[current_row]
            self.mesh = mesh_from_path(path)
            self.viewer.load_mesh(self.mesh)

    def init_load_mesh(self):
        if (len(self.paths) > 0):
            path = self.paths[0]
            self.name = self.names[0]
            self.mesh = mesh_from_path(path)
            self.viewer.load_mesh(self.mesh)

    def keyPressEvent(self, event):
        if event.key() in [16777235, 16777237]:
            self.listWidget.keyPressEvent(event)
        else:
            self.viewer.keyPressEvent(event)

    def keyReleaseEvent(self, event):
        self.viewer.keyReleaseEvent(event)

    def load_folder(self, folder_path):
        self.viewer.release_mesh()
        self.paths = file_paths_from_dir(folder_path)
        self.names = list(map(lambda s: s.split('/')[-1], self.paths))

        self.listWidget.clear()
        self.listWidget.addItems(self.names)

    def initLayout(self):
        self.addWidget(self.listWidget)
        self.addWidget(self.viewer)
        self.setStretchFactor(0, 1)
        self.setStretchFactor(1, 4)
        self.setMinimumHeight(450)
Exemplo n.º 2
0
    def __init__(self, parent=None):
        super().__init__(parent)
        self.listWidget = QListWidget(self)
        self.viewer = ViewerWidget(self)
        self.paths = []
        self.names = []
        self.name = ''
        self.mesh = None
        self.grabKeyboard()

        self.listWidget.itemSelectionChanged.connect(
            self.cb_itemSelectionChanged)

        self.initLayout()
Exemplo n.º 3
0
    def __init__(self):
        QtGui.QMainWindow.__init__(self)
        self.debug = True

        self.get_verts()
        self.viewer = ViewerWidget(self.verts)
        self.gl_options = args_to_dict(self.viewer.set_options)

        self.widget = QtGui.QWidget()
        self.lyt = QtGui.QVBoxLayout()
        self.widget.setLayout(self.lyt)
        self.setCentralWidget(self.widget)
        self.resize(500, 500)

        #self.get_options()
        self.add_elements()
    def __init__(self, instance):
        gtk.VBox.__init__(self)
        Loggable.__init__(self)

        self.log("Init PreviewWidget")
        self.connect('destroy', self._destroy_cb)

        self.settings = instance.settings
        self.preview_cache = {}
        self.preview_cache_errors = {}

        self.discoverer = gst.pbutils.Discoverer(gst.SECOND)

        #playbin for play pics
        self._unsurePlaybin()
        bus = self.player.get_bus()
        bus.add_signal_watch()
        bus.connect('message', self._bus_message_cb)
        bus.enable_sync_message_emission()
        bus.connect('sync-message::element', self._sync_message_cb)
        bus.connect('message::tag', self._tag_found_cb)
        self.__videosink = self.player.get_property("video-sink")
        self.__fakesink = gst.element_factory_make("fakesink", "fakesink")

        #some global variables for preview handling
        self.is_playing = False
        self.time_format = gst.Format(gst.FORMAT_TIME)
        self.original_dims = (PREVIEW_WIDTH, PREVIEW_HEIGHT)
        self.countinuous_seek = False
        self.current_selected_uri = ""
        self.current_preview_type = ""
        self.description = ""
        self.tags = {}

        # Gui elements:
        # Drawing area for video output
        self.preview_video = ViewerWidget()
        self.preview_video.modify_bg(gtk.STATE_NORMAL, self.preview_video.style.black)
        self.pack_start(self.preview_video, expand=False)

        # An image for images and audio
        self.preview_image = gtk.Image()
        self.preview_image.set_size_request(self.settings.FCpreviewWidth, self.settings.FCpreviewHeight)
        self.preview_image.show()
        self.pack_start(self.preview_image, expand=False)

        # Play button
        self.bbox = gtk.HBox()
        self.play_button = gtk.ToolButton(gtk.STOCK_MEDIA_PLAY)
        self.play_button.connect("clicked", self._on_start_stop_clicked_cb)
        self.bbox.pack_start(self.play_button, expand=False)

        #Scale for position handling
        self.pos_adj = gtk.Adjustment()
        self.seeker = gtk.HScale(self.pos_adj)
        self.seeker.set_update_policy(gtk.UPDATE_DISCONTINUOUS)
        self.seeker.connect('button-press-event', self._on_seeker_press_cb)
        self.seeker.connect('button-release-event', self._on_seeker_press_cb)
        self.seeker.connect('motion-notify-event', self._on_motion_notify_cb)
        self.seeker.set_draw_value(False)
        self.seeker.show()
        self.bbox.pack_start(self.seeker)

        # Zoom buttons
        self.b_zoom_in = gtk.ToolButton(gtk.STOCK_ZOOM_IN)
        self.b_zoom_in.connect("clicked", self._on_zoom_clicked_cb, 1)
        self.b_zoom_out = gtk.ToolButton(gtk.STOCK_ZOOM_OUT)
        self.b_zoom_out.connect("clicked", self._on_zoom_clicked_cb, -1)
        self.bbox.pack_start(self.b_zoom_in, expand=False)
        self.bbox.pack_start(self.b_zoom_out, expand=False)
        self.bbox.show_all()
        self.pack_start(self.bbox, expand=False, fill=False)

        # Label for metadata tags
        self.l_tags = gtk.Label()
        self.l_tags.set_justify(gtk.JUSTIFY_LEFT)
        self.l_tags.set_ellipsize(pango.ELLIPSIZE_END)
        self.l_tags.show()
        self.pack_start(self.l_tags, expand=False, fill=False)

        # Error handling
        vbox = gtk.VBox()
        vbox.set_spacing(SPACING)
        self.l_error = gtk.Label(_("PiTiVi can not preview this file."))
        self.b_details = gtk.Button(_("More info"))
        self.b_details.connect('clicked', self._on_b_details_clicked_cb)
        vbox.pack_start(self.l_error)
        vbox.pack_start(self.b_details, expand=False, fill=False)
        vbox.show()
        self.pack_start(vbox, expand=False, fill=False)
class PreviewWidget(gtk.VBox, Loggable):

    def __init__(self, instance):
        gtk.VBox.__init__(self)
        Loggable.__init__(self)

        self.log("Init PreviewWidget")
        self.connect('destroy', self._destroy_cb)

        self.settings = instance.settings
        self.preview_cache = {}
        self.preview_cache_errors = {}

        self.discoverer = gst.pbutils.Discoverer(gst.SECOND)

        #playbin for play pics
        self._unsurePlaybin()
        bus = self.player.get_bus()
        bus.add_signal_watch()
        bus.connect('message', self._bus_message_cb)
        bus.enable_sync_message_emission()
        bus.connect('sync-message::element', self._sync_message_cb)
        bus.connect('message::tag', self._tag_found_cb)
        self.__videosink = self.player.get_property("video-sink")
        self.__fakesink = gst.element_factory_make("fakesink", "fakesink")

        #some global variables for preview handling
        self.is_playing = False
        self.time_format = gst.Format(gst.FORMAT_TIME)
        self.original_dims = (PREVIEW_WIDTH, PREVIEW_HEIGHT)
        self.countinuous_seek = False
        self.current_selected_uri = ""
        self.current_preview_type = ""
        self.description = ""
        self.tags = {}

        # Gui elements:
        # Drawing area for video output
        self.preview_video = ViewerWidget()
        self.preview_video.modify_bg(gtk.STATE_NORMAL, self.preview_video.style.black)
        self.pack_start(self.preview_video, expand=False)

        # An image for images and audio
        self.preview_image = gtk.Image()
        self.preview_image.set_size_request(self.settings.FCpreviewWidth, self.settings.FCpreviewHeight)
        self.preview_image.show()
        self.pack_start(self.preview_image, expand=False)

        # Play button
        self.bbox = gtk.HBox()
        self.play_button = gtk.ToolButton(gtk.STOCK_MEDIA_PLAY)
        self.play_button.connect("clicked", self._on_start_stop_clicked_cb)
        self.bbox.pack_start(self.play_button, expand=False)

        #Scale for position handling
        self.pos_adj = gtk.Adjustment()
        self.seeker = gtk.HScale(self.pos_adj)
        self.seeker.set_update_policy(gtk.UPDATE_DISCONTINUOUS)
        self.seeker.connect('button-press-event', self._on_seeker_press_cb)
        self.seeker.connect('button-release-event', self._on_seeker_press_cb)
        self.seeker.connect('motion-notify-event', self._on_motion_notify_cb)
        self.seeker.set_draw_value(False)
        self.seeker.show()
        self.bbox.pack_start(self.seeker)

        # Zoom buttons
        self.b_zoom_in = gtk.ToolButton(gtk.STOCK_ZOOM_IN)
        self.b_zoom_in.connect("clicked", self._on_zoom_clicked_cb, 1)
        self.b_zoom_out = gtk.ToolButton(gtk.STOCK_ZOOM_OUT)
        self.b_zoom_out.connect("clicked", self._on_zoom_clicked_cb, -1)
        self.bbox.pack_start(self.b_zoom_in, expand=False)
        self.bbox.pack_start(self.b_zoom_out, expand=False)
        self.bbox.show_all()
        self.pack_start(self.bbox, expand=False, fill=False)

        # Label for metadata tags
        self.l_tags = gtk.Label()
        self.l_tags.set_justify(gtk.JUSTIFY_LEFT)
        self.l_tags.set_ellipsize(pango.ELLIPSIZE_END)
        self.l_tags.show()
        self.pack_start(self.l_tags, expand=False, fill=False)

        # Error handling
        vbox = gtk.VBox()
        vbox.set_spacing(SPACING)
        self.l_error = gtk.Label(_("PiTiVi can not preview this file."))
        self.b_details = gtk.Button(_("More info"))
        self.b_details.connect('clicked', self._on_b_details_clicked_cb)
        vbox.pack_start(self.l_error)
        vbox.pack_start(self.b_details, expand=False, fill=False)
        vbox.show()
        self.pack_start(vbox, expand=False, fill=False)

    def _unsurePlaybin(self):
        try:
            self.player = gst.element_factory_make("playbin2", "preview-player")
        except:
            self.player = gst.element_factory_make("playbin", "preview-player")

    def setMinimal(self):
        self.remove(self.l_tags)
        self.b_zoom_in.hide()
        self.b_zoom_out.hide()
        # Allow expanding/filling and pack the video preview below the controls
        self.set_child_packing(self.preview_video, True, True, 0, gtk.PACK_END)

    def add_preview_request(self, dialogbox):
        """add a preview request """
        uri = dialogbox.get_preview_uri()
        if uri is None or not uri_is_valid(uri):
            return
        self.previewUri(uri)

    def previewUri(self, uri):
        self.log("Preview request for " + uri)
        self.clear_preview()
        self.current_selected_uri = uri
        if uri in self.preview_cache:  # Already discovered
            self.log(uri + " already in cache")
            self.show_preview(uri, None)
        elif uri in self.preview_cache_errors:
            self.log(uri + " already in error cache")
            self.show_error(uri)
        else:
            self.log("Call discoverer for " + uri)
            try:
                info = self.discoverer.discover_uri(uri)
            except Exception, e:
                if e is not None:
                    self.preview_cache_errors[uri] = e
                    if self.current_selected_uri == uri:
                        self.show_error(uri)
                    return

            if self.current_selected_uri == uri:
                self.show_preview(uri, info)
Exemplo n.º 6
0
            def __init__(self, parent=None):
                super(ViewerWindow, self).__init__(parent)
                self.viewer = ViewerWidget(self)

                self.setCentralWidget(self.viewer)
Exemplo n.º 7
0
class ViewerWindow(QtGui.QMainWindow):
    def __init__(self):
        QtGui.QMainWindow.__init__(self)
        self.debug = True

        self.get_verts()
        self.viewer = ViewerWidget(self.verts)
        self.gl_options = args_to_dict(self.viewer.set_options)

        self.widget = QtGui.QWidget()
        self.lyt = QtGui.QVBoxLayout()
        self.widget.setLayout(self.lyt)
        self.setCentralWidget(self.widget)
        self.resize(500, 500)

        #self.get_options()
        self.add_elements()

    def get_verts(self):
        self.random_data = RandomData()
        self.random_options = self.random_data.options.keys()

        #vertex_data, color_data = triangle_data()
        #vertex_data, color_data = square_data()
        vertex_data, color_data = cube_data()

        #raw_data = self.random_data.get_data(self.random_options[0])
        #vertex_data, color_data = random_data_to_vertex_data(raw_data)
        self.vertex_data = vertex_data
        self.color_data = color_data

        self.verts = OpenGlVerts(vertex_data, color_data)
        self.vert_options = args_to_dict(self.verts.draw)

    def add_options(self, options, name):
        option_lyt = QtGui.QVBoxLayout()
        option_lyt.addStretch()

        label = QtGui.QLabel()
        label.setText(name + '\n----------')
        option_lyt.addWidget(label)

        for name in sorted(options.keys()):
            value = options[name]

            if type(value) == bool:
                check = QtGui.QCheckBox()
                check.setText(name)
                check.setChecked(value)
                check.stateChanged.connect(
                    lambda x, check=check, options=options: self.
                    change_bool_option(check, options))

                option_lyt.addWidget(check)
            elif type(value) == int or type(value) == float:
                spin_lyt = QtGui.QHBoxLayout()

                label = QtGui.QLabel()
                label.setText(name)

                if type(value) == int:
                    spin = QtGui.QSpinBox()
                else:
                    spin = QtGui.QDoubleSpinBox()

                spin.setValue(value)
                spin.valueChanged.connect(
                    lambda x, label=label, spin=spin, options=options: self.
                    change_numeric_option(label, spin, options))

                spin_lyt.addWidget(spin)
                spin_lyt.addWidget(label)
                option_lyt.addLayout(spin_lyt)

        return option_lyt

    def add_elements(self):
        h_lyt = QtGui.QHBoxLayout()
        h_lyt.addWidget(self.viewer)

        option_lyt = QtGui.QVBoxLayout()
        option_lyt.addStretch()

        gl_option_lyt = self.add_options(self.gl_options, 'openGL options')
        option_lyt.addLayout(gl_option_lyt)

        vert_option_lyt = self.add_options(self.vert_options, 'Vert rendering')
        option_lyt.addLayout(vert_option_lyt)

        h_lyt.addLayout(option_lyt)

        h_lyt.setStretch(0, 1)
        self.lyt.addLayout(h_lyt)

        combo = QtGui.QComboBox()
        self.combo = combo
        combo.addItems(self.random_options)
        combo.currentIndexChanged.connect(self.update_data)
        self.lyt.addWidget(combo)

    def change_bool_option(self, check, options):
        option = check.text()
        value = check.isChecked()
        options[option] = value
        self.update_options()

    def change_numeric_option(self, label, spin, options):
        option = label.text()
        value = spin.value()
        options[option] = value
        self.update_options()

    def update_options(self):
        self.viewer.vert_options = self.vert_options
        self.viewer.gl_options = self.gl_options
        self.viewer.update()
        if self.debug:
            print self.vert_options
            print self.gl_options

    def update_data(self):
        option = self.combo.currentText()
        print option
        raw_data = self.random_data.get_data(option)
        vertex_data, color_data = random_data_to_vertex_data(raw_data)
        self.verts.set_data(vertex_data, color_data)
        self.verts.bind_data()
        # update viewer
        self.viewer.update()