2017-09-13 4 views
1

私はpygtkを学び、ドキュメントとチュートリアルの用語の意味を理解しようとしています。gtkウィジェットが独自のウィンドウを持つことはどういう意味ですか?

は、ドキュメント

  1. ボタンオブジェクトによるは独自のウィンドウを持っていませありません。
  2. イベントを受信しないウィジェット(独自のウィンドウを持たないウィジェット)はツールチップでは機能しません。

私は、ツールチップがボタンでは機能しないと判断します。それは間違っていると思われ、下のサンプルコードは間違っているようです。だから、用語の意味について私が理解していないものがありますか?上記の記述は間違っていますか?誰も私がここで紛失しているものを説明することができますget_has_window()メソッドは、ツールチップが機能するかどうかと同じ質問に答えないのでしょうか?

#!/usr/bin/env python 

import pygtk 
pygtk.require('2.0') 
import gtk 

class IsButtonNoWindowWidget: 
    def sillycallback(self, widget, data): 
     print data 
     if widget.get_has_window(): 
      print "Which has a window" 
     else: 
      print "Which does *not* have a window" 

    def __init__(self): 
     # create a properly dismissable top level 
     self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) 
     self.window.connect("destroy", lambda w: gtk.main_quit()) 

     button = gtk.Button("PRESS ME") 
     button.connect("clicked", self.sillycallback, 
         "You have clicked the button") 
     tooltips = gtk.Tooltips() 
     # according to pygtk documentation: 
     # Widgets that do not receive events 
     # (widgets that do not have their own window) 
     # will *not* work with tooltips. 
     tooltips.set_tip(button, "just press me, already!") 
     self.window.add(button) 
     button.show() 
     self.window.show() 

def main(): 
    gtk.main() 
    return 0 

if __name__ == "__main__": 
    IsButtonNoWindowWidget() 
    main() 

答えて

2

私はGtkの内部について専門家がいないので、間違っている可能性があります。私は

  • Gtk.Windowは、ウィンドウマネージャによって「管理」されたトップレベルのウィンドウであり、かつ最大化、閉じるボタンとプログラム名を示しています...いくつかの混乱があると思います。

  • Gtk.gdk.window()(Gdk/Gtk /言語に応じて異なる名前)は、Gdkに適したウィジェットであり、ウィジェットを描画するための領域を提供します。これは、ボタン押下やキー押下などのイベントに対して機密領域を提供します。

Gtk.Labelは有名全くgdk.windowを持っていない、と(あなたがそれを解決するために、その背後Gtk.EventBoxを配置する必要があります)、このようなイベントをキャプチャすることはできません。

Gtk.Button にはGdk.Windowがあり、ボタンの外観はそのウィンドウに描画されます(もちろん、イベント)。ツールチップを表示

はGtk.Widgetの作業であり、そしてGtk.LabelがGtk.Widgetから派生しない(やるGtk.Buttonを行います):

+-- gobject.GObject 
    +-- gtk.Object 
    +-- gtk.Widget 
     +-- gtk.Misc 
     +-- gtk.Label 

+-- gobject.GObject 
    +-- gtk.Object 
    +-- gtk.Widget 
     +-- gtk.Container 
     +-- gtk.Bin 
      +-- gtk.Button 

だから、両方のは、前述したように、ツールチップを表示することができるはずです次のプログラムは示しています

要するに
#!/usr/bin/env python3 
# -*- coding: utf-8 -*- 
# 
# test_label_tooltip.py 
# 
# Copyright 2017 John Coppens <[email protected]> 
# 
# This program is free software; you can redistribute it and/or modify 
# it under the terms of the GNU General Public License as published by 
# the Free Software Foundation; either version 2 of the License, or 
# (at your option) any later version. 
# 
# This program is distributed in the hope that it will be useful, 
# but WITHOUT ANY WARRANTY; without even the implied warranty of 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
# GNU General Public License for more details. 
# 
# You should have received a copy of the GNU General Public License 
# along with this program; if not, write to the Free Software 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
# MA 02110-1301, USA. 
# 
# 


import gi 
gi.require_version('Gtk', '3.0') 
gi.require_version('GooCanvas', '2.0') 
from gi.repository import Gtk, GooCanvas 

class MainWindow(Gtk.Window): 
    def __init__(self): 
     super(MainWindow, self).__init__() 
     self.connect("destroy", lambda x: Gtk.main_quit()) 

     label = Gtk.Label("This is a label", 
        tooltip_text = "This is the label's tooltip") 
     button = Gtk.Label("This is a button", 
        tooltip_text = "This is the button's tooltip") 

     vbox = Gtk.VBox() 
     vbox.pack_start(label, False, False, 3) 
     vbox.pack_start(button, False, False, 3) 

     self.add(vbox) 
     self.show_all() 

    def run(self): 
     Gtk.main() 


def main(args): 
    mainwdw = MainWindow() 
    mainwdw.run() 

    return 0 

if __name__ == '__main__': 
    import sys 
    sys.exit(main(sys.argv)) 

Button's tooltip Label's tooltip

:ツールチップを表示する能力がないDウィジェットがGdk.Windowを持っているかどうかを調べてください。実際には、ツールチップは、私はどちらかそれは独自のGtk.Windowを持っているか、ウィンドウマネージャによって管理されていることを示すことになる疑いがあるトップレベルGtk.Window、外に落ちることができます(私は本当にそれを調査する必要があります):

enter image description here

関連する問題