Gtk3视频捕获拖放不起作用

时间:2019-04-23 16:53:11

标签: python python-3.x drag-and-drop gtk3

我有一个用Python 3编写并使用拖放功能的程序。我想制作视频教程。但是,当视频捕获正常工作时,Drop失败。捕获程序似乎拦截了一些信号。

我尝试了几个程序(Jing和其他程序),但结果相同。我正在用一个非常简单的Python脚本进行测试。捕获工作时,通常不会显示放置位置的线不会出现。 get_data和Received_data函数不会启动。 我在Windows 8中。我尚未在Linux中进行测试。

下面是我的python3测试代码。

#!/usr/bin/env python

# example treeviewdnd.py modified

from gi.repository import Gtk, Gdk, Pango, GObject

class TreeViewDnDExample:

    TARGETS = [
        ('MY_TREE_MODEL_ROW', Gtk.TargetFlags.SAME_WIDGET, 0),
        ('text/plain', 0, 1),
        ('TEXT', 0, 2),
        ('STRING', 0, 3),
        ]
    # close the window and quit
    def delete_event(self, widget, event, data=None):
        Gtk.main_quit()
        return False

    def clear_selected(self, button):
        selection = self.treeview.get_selection()
        model, iter = selection.get_selected()
        if iter:
            model.remove(iter)
        return

    def __init__(self):
        # Create a new window
        self.window = Gtk.Window()

        self.window.set_title("URL Cache")

        self.window.set_size_request(200, 200)

        self.window.connect("delete_event", self.delete_event)

        self.scrolledwindow = Gtk.ScrolledWindow()
        self.vbox = Gtk.VBox()
        self.hbox = Gtk.HButtonBox()
        self.vbox.pack_start(self.scrolledwindow, True, True, 0)
        self.vbox.pack_start(self.hbox, False, True, 0)
        self.b0 = Gtk.Button('Clear All')
        self.b1 = Gtk.Button('Clear Selected')
        self.hbox.pack_start(self.b0, True, True, 0)
        self.hbox.pack_start(self.b1, True, True, 0)

        # create a liststore with one string column to use as the model
        self.liststore = Gtk.ListStore(str)
        for a in "abcd" :
            self.liststore.append([a])

        # create the TreeView using liststore
        self.treeview = Gtk.TreeView(self.liststore)

       # create a CellRenderer to render the data
        self.cell = Gtk.CellRendererText()

        # create the TreeViewColumns to display the data
        self.tvcolumn = Gtk.TreeViewColumn('URL', self.cell, text=0)

        # add columns to treeview
        self.treeview.append_column(self.tvcolumn)
        self.b0.connect_object('clicked', Gtk.ListStore.clear, self.liststore)
        self.b1.connect('clicked', self.clear_selected)
        # make treeview searchable
        self.treeview.set_search_column(0)

        # Allow sorting on the column
        self.tvcolumn.set_sort_column_id(0)

        # Allow enable drag and drop of rows including row move
        self.treeview.enable_model_drag_source( Gdk.ModifierType.BUTTON1_MASK,
                                                self.TARGETS,
                                                Gdk.DragAction.DEFAULT|
                                                Gdk.DragAction.MOVE)
        self.treeview.enable_model_drag_dest(self.TARGETS,
                                             Gdk.DragAction.DEFAULT)
        self.treeview.drag_dest_add_text_targets()
        self.treeview.drag_source_add_text_targets()

        self.treeview.connect("drag_data_get", self.drag_data_get_data)
        self.treeview.connect("drag_data_received",
                              self.drag_data_received_data)

        self.scrolledwindow.add(self.treeview)
        self.window.add(self.vbox)
        self.window.show_all()

    def drag_data_get_data(self, treeview, context, selection, target_id,
                           etime):
        print("drag get data")
        treeselection = treeview.get_selection()
        model, iter = treeselection.get_selected()
        data = bytes(model.get_value(iter, 0), "utf-8")
        selection.set(selection.get_target(), 8, data)

    def drag_data_received_data(self, treeview, context, x, y, selection,
                                info, etime):
        print("received")


def main():
    Gtk.main()

if __name__ == "__main__":
    treeviewdndex = TreeViewDnDExample()
    main()

1 个答案:

答案 0 :(得分:0)

由于在Windows中找不到该问题的答案,因此解决方案是在视频捕获程序效果不一样的Linux机器上启动该程序。甚至可以使用VNCViewer连接到Linux计算机,并在Windows框中进行捕获。出于演示目的,这已足够。 但是我仍然想知道是什么阻止Gtk-Windows接收drop事件。