2017-02-20 5 views
0

Gladeインタフェースデザイナを使用して作成したPython3/PyGObjectからダイアログウィンドウを実行する際に問題があります。ここでGladeを使用して生成されたPython3/PyGObjectからダイアログを正しく実行する方法

Gtk-Message: GtkDialog mapped without a transient parent. This is discouraged.

:また

AttributeError: Handler button_click_dialog not found

私は過渡親ウィンドウを設定することができ、私は知らない。信号が、私はこのスクリプトを実行しようとすると、私はこのエラーを取得するので、正しく接続されていません http://pastebin.com/yKz3P58s

そして、ここに私のpython3/PyGObjectファイルには、次のとおりです:私の空き地ファイルがある

#!/usr/bin/env python3 

# Gtk imports 
import gi 
gi.require_version("Gtk", "3.0") 
from gi.repository import Gtk 

# Initialize Gtk builder and import UI 
builder = Gtk.Builder() 
builder.add_from_file("windowtest.glade") 

# Get objects from builder 
window = builder.get_object("ButtonWindow") 
dialog = builder.get_object("ButtonDialog") 

class ButtonWindow: 

    def on_delete_window(self, *args): 
    Gtk.main_quit(*args) 

    def button_click_window(self, widget): 
    print("button_click_window") 
    response = dialog.run() 
    if response == Gtk.ResponseType.OK: 
     print("OK") 
    elif response == Gtk.ResponseType.CANCEL: 
     print("CANCEL") 
    dialog.destroy() 


class ButtonDialog: 

    def __init__(self): 
    print("dialog init") 

    def button_click_dialog(self, widget): 
    print("button_click_dialog") 


# Connect signals 
builder.connect_signals(ButtonWindow()) 
builder.connect_signals(ButtonDialog()) 

# Show main window 
window.show_all() 

# Enter main loop 
Gtk.main() 

誰かが私のダイアログの呼び出し/実行/破棄の仕方を理解する助けになることができますか?そして信号をどのように接続すればよいですか?

答えて

0

AttributeError: Handler button_click_dialog not found

問題は、ここで同じビルダーオブジェクトに2つのクラスを接続していることである。

builder.connect_signals(ButtonWindow()) 
builder.connect_signals(ButtonDialog()) 

ですから、ButtonWindowクラスにbutton_click_dialog機能を移動するか、またはあなたが別々にあなたのダイアログを保存しますファイル。


Gtk-Message: GtkDialog mapped without a transient parent. This is discouraged.

ボタンが

def button_click_window(self, widget): 
    print("button_click_window") 
    dialog.set_transient_for(window) 
    response = dialog.run() 
    if response == Gtk.ResponseType.OK: 
     print("OK") 
    elif response == Gtk.ResponseType.CANCEL: 
     print("CANCEL") 
    dialog.destroy() 

をクリックされたときには、ダイアログを呼び出すことができるようにしたい場合は、それはまたdialog.hide()dialog.destroy()から切り替えるには意味をなさないかもしれない例えばset_transient_forを呼び出すことができます数回ではなく1回。

+0

elya5さん、ありがとうございました。私は非常にこれらの2つを自分のファイルに分けることに興味があります。問題は、あなたがそれを説明したように私はそれを試しましたが、私はそれを正しくしませんでした。これを解決する手助けはできますか? windowwindow.py:http://pastebin.com/MW8dRLys windowdialog.py:http://pastebin.com/1nCAUSjc windowtest.glade:変更されていません。 – mursuhaukka

+0

ウィンドウとダイアログを別々の2つのグレイドファイルに入れます – elya5

+0

Ok。ダイアログが別のファイルになったので、ダイアログをインポート、インスタンス化、実行するにはどうすればよいですか?私は前と同じ.pyファイルを持っています。 – mursuhaukka

関連する問題