GTK4 で Clipboard を使うテスト。
文字列のコピペはできた、ただし自分のインスタンス内のみで。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | #!/usr/bin/env python3 import gi gi.require_version( 'Gtk' , '4.0' ) #gi.require_version('Gdk', '4.0') # not need from gi.repository import Gtk, Gdk class TestWindow(Gtk.ApplicationWindow): ''' GTK4 Clipboard @ String Copy This Code is Instance Only ''' def __init__( self , app): Gtk.ApplicationWindow.__init__( self , application = app) self .clip = self .props.display.get_primary_clipboard() print ( self .clip) #=> GdkWaylandPrimary (GdkClipboard) ''' self.clip = self.get_clipboard() self.clip = self.props.display.get_clipboard() display = Gdk.Display.get_default() self.clip = display.get_primary_clipboard() self.clip = display.get_clipboard() # local is All True... print(self.clip.props.local) ''' self .clip. set ( 'スズキのバイクはカッコイイ' ) print ( self .clip.get_formats().to_string()) #=> { gchararray, text/plain;charset=utf-8, text/plain } # #self.clip.set_text('No GIR Binding') # Error! # self .clip.read_text_async( None , self .read_text_async_cb) # self .label = Gtk.Label(label = 'Motor Cycle' ) self .set_child( self .label) self .set_default_size( 400 , 100 ) self .present() def read_text_async_cb( self , clip, res): text = clip.read_text_finish(res) self .label.set_label(text) class TestApplication(Gtk.Application): def __init__( self ): Gtk.Application.__init__( self , application_id = 'org.suzuki.katana' ) def do_activate( self ): TestWindow( self ) app = TestApplication() app.run() |
何をどうやっても local Property が True になってしまう。
False にしないと Gedit 等の外部インスタンスとはコピペできない。
バグなのか?
他にやらないといけないことがあるのか?
それと set_text 等がバインドされていないのはどうなんだ?
set で文字列を渡したら普通にセットできたけど「ん?」って感じ。
バイナリの転送は GdkContentProvider でいいのかな?