2014-09-27 73 views
1

我正在制作一个界面,您必须先登录才能进入。所以在登录窗口中,我放了一个按钮来打开一个模式窗口(关于对话框)。它工作正常,但只是一次,我的意思是:这个窗口可以打开和关闭,但如果你再试一次,它会失败。我无法意识到为什么和我相当成熟。林间空地代码:MultiWindow错误Glade,Gtk和Python

<?xml version="1.0" encoding="UTF-8"?> 
<!-- Generated with glade 3.16.1 --> 
<interface> 
    <requires lib="gtk+" version="3.10"/> 
<object class="GtkAboutDialog" id="aboutwin"> 
<property name="can_focus">False</property> 
<property name="resizable">False</property> 
<property name="modal">True</property> 
<property name="window_position">center</property> 
<property name="destroy_with_parent">True</property> 
<property name="type_hint">dialog</property> 
<property name="has_resize_grip">False</property> 
<property name="program_name">Movies App</property> 
<property name="version">Version: 0.1</property> 
<property name="authors">Markos Horro Varela 
Breixo Camiña Fernández</property> 
<property name="documenters">Markos Horro Varela 
Breixo Camiña Fernández</property> 
<property name="translator_credits" translatable="yes">Markos Horro Varela 
Breixo Camiña Fernández</property> 
<property name="artists">Markos Horro Varela 
Breixo Camiña Fernández</property> 
<property name="logo_icon_name">video-x-generic</property> 
<property name="license_type">gpl-3-0</property> 
<signal name="close" handler="onDeleteWindow" swapped="no"/> 
<signal name="delete-event" handler="onDeleteWindow" swapped="no"/> 
<child internal-child="vbox"> 
    <object class="GtkBox" id="about"> 
    <property name="can_focus">False</property> 
    <property name="orientation">vertical</property> 
    <property name="spacing">2</property> 
    <child internal-child="action_area"> 
     <object class="GtkButtonBox" id="aboutdialog-action_area1"> 
     <property name="can_focus">False</property> 
     <property name="layout_style">end</property> 
     <signal name="delete-event" handler="onDeleteWindow" swapped="no"/> 
     </object> 
     <packing> 
     <property name="expand">False</property> 
     <property name="fill">True</property> 
     <property name="pack_type">end</property> 
     <property name="position">0</property> 
     </packing> 
    </child> 
    </object> 
</child> 
</object> 
<object class="GtkWindow" id="signinwin"> 
<property name="can_focus">False</property> 
<property name="title" translatable="yes">Movie App</property> 
<property name="resizable">False</property> 
<property name="window_position">center</property> 
<property name="has_resize_grip">False</property> 
<signal name="delete-event" handler="onDeleteWindow" swapped="no"/> 
<child> 
    <object class="GtkGrid" id="grid1"> 
    <property name="visible">True</property> 
    <property name="can_focus">False</property> 
    <property name="margin_left">10</property> 
    <property name="margin_right">60</property> 
    <property name="margin_top">10</property> 
    <property name="margin_bottom">10</property> 
    <child> 
     <object class="GtkEntry" id="login"> 
     <property name="visible">True</property> 
     <property name="can_focus">True</property> 
     <property name="margin_right">10</property> 
     <property name="margin_bottom">5</property> 
     <property name="input_purpose">name</property> 
     </object> 
     <packing> 
     <property name="left_attach">2</property> 
     <property name="top_attach">1</property> 
     <property name="width">1</property> 
     <property name="height">1</property> 
     </packing> 
    </child> 
    <child> 
     <object class="GtkEntry" id="pass"> 
     <property name="visible">True</property> 
     <property name="can_focus">True</property> 
     <property name="margin_right">10</property> 
     <property name="margin_top">5</property> 
     <property name="margin_bottom">5</property> 
     <property name="placeholder_text" translatable="yes">************</property> 
     <property name="input_purpose">password</property> 
     </object> 
     <packing> 
     <property name="left_attach">2</property> 
     <property name="top_attach">2</property> 
     <property name="width">1</property> 
     <property name="height">1</property> 
     </packing> 
    </child> 
    <child> 
     <object class="GtkLabel" id="userlabel"> 
     <property name="visible">True</property> 
     <property name="can_focus">False</property> 
     <property name="margin_right">6</property> 
     <property name="label" translatable="yes">User</property> 
     </object> 
     <packing> 
     <property name="left_attach">1</property> 
     <property name="top_attach">1</property> 
     <property name="width">1</property> 
     <property name="height">1</property> 
     </packing> 
    </child> 
    <child> 
     <object class="GtkLabel" id="passlabel"> 
     <property name="visible">True</property> 
     <property name="can_focus">False</property> 
     <property name="margin_right">6</property> 
     <property name="label" translatable="yes">Password</property> 
     </object> 
     <packing> 
     <property name="left_attach">1</property> 
     <property name="top_attach">2</property> 
     <property name="width">1</property> 
     <property name="height">1</property> 
     </packing> 
    </child> 
    <child> 
     <object class="GtkButton" id="button1"> 
     <property name="label" translatable="yes">Sign in</property> 
     <property name="visible">True</property> 
     <property name="can_focus">True</property> 
     <property name="receives_default">True</property> 
     <property name="margin_left">20</property> 
     <property name="margin_right">20</property> 
     </object> 
     <packing> 
     <property name="left_attach">2</property> 
     <property name="top_attach">3</property> 
     <property name="width">1</property> 
     <property name="height">1</property> 
     </packing> 
    </child> 
    <child> 
     <object class="GtkLabel" id="title"> 
     <property name="visible">True</property> 
     <property name="can_focus">False</property> 
     <property name="margin_left">5</property> 
     <property name="margin_right">5</property> 
     <property name="margin_top">5</property> 
     <property name="margin_bottom">5</property> 
     <property name="label" translatable="yes">Movie App</property> 
     </object> 
     <packing> 
     <property name="left_attach">2</property> 
     <property name="top_attach">0</property> 
     <property name="width">1</property> 
     <property name="height">1</property> 
     </packing> 
    </child> 
    <child> 
     <object class="GtkGrid" id="grid2"> 
     <property name="visible">True</property> 
     <property name="can_focus">False</property> 
     <child> 
      <object class="GtkButton" id="policy"> 
      <property name="label" translatable="yes">Policy</property> 
      <property name="visible">True</property> 
      <property name="can_focus">True</property> 
      <property name="receives_default">True</property> 
      <property name="margin_left">30</property> 
      <property name="margin_right">5</property> 
      <property name="margin_top">30</property> 
      <property name="margin_bottom">5</property> 
      </object> 
      <packing> 
      <property name="left_attach">0</property> 
      <property name="top_attach">0</property> 
      <property name="width">1</property> 
      <property name="height">1</property> 
      </packing> 
     </child> 
     <child> 
      <object class="GtkButton" id="aboutus"> 
      <property name="label" translatable="yes">About</property> 
      <property name="visible">True</property> 
      <property name="can_focus">True</property> 
      <property name="receives_default">True</property> 
      <property name="margin_left">5</property> 
      <property name="margin_right">30</property> 
      <property name="margin_top">30</property> 
      <property name="margin_bottom">5</property> 
      <signal name="clicked" handler="onAboutPressed" swapped="no"/> 
      </object> 
      <packing> 
      <property name="left_attach">1</property> 
      <property name="top_attach">0</property> 
      <property name="width">1</property> 
      <property name="height">1</property> 
      </packing> 
     </child> 
     </object> 
     <packing> 
     <property name="left_attach">2</property> 
     <property name="top_attach">4</property> 
     <property name="width">1</property> 
     <property name="height">1</property> 
     </packing> 
    </child> 
    <child> 
     <placeholder/> 
    </child> 
    <child> 
     <placeholder/> 
    </child> 
    <child> 
     <placeholder/> 
    </child> 
    <child> 
     <placeholder/> 
    </child> 
    <child> 
     <placeholder/> 
    </child> 
    <child> 
     <placeholder/> 
    </child> 
    <child> 
     <placeholder/> 
    </child> 
    <child> 
     <placeholder/> 
    </child> 
    </object> 
</child> 
</object> 
</interface> 

而且我的Python代码:

#!/usr/bin/python 

from gi.repository import Gtk 

class Handler(Gtk.Window): 
    def onDeleteWindow(self, *args): 
     self.destroy() 
     Gtk.main_quit(*args) 


    def onAboutPressed(self, button): 
     about = builder.get_object("aboutwin") 
     about.run() 
     about.destroy() 

builder = Gtk.Builder() 
builder.add_from_file("v0.glade") 
builder.connect_signals(Handler()) 

main = builder.get_object("signinwin") 
main.show_all() 

Gtk.main() 
+0

难道我的答案的工作? – tobias47n9e 2014-10-10 08:55:41

+0

如果这解决了您的问题,您可以接受答案或评论答案,如果它不起作用。 – tobias47n9e 2015-02-05 22:00:10

回答

1

我不能告诉你到底是什么错误的,但它可能是您分配了错误的信号格莱德。我将关闭事件从GtkDialog - >关闭切换到GtkDialog - >响应。当你需要的时候只获得AboutDialog可能会更好,所以我把它放到它自己的类中。我也是个初学者,但现在的代码应该工作:

#!/usr/bin/python 

from gi.repository import Gtk 

class AboutDialog: 
    def __init__(self): 
     self.builder = Gtk.Builder() 
     self.builder.add_objects_from_file("v0.glade", ("aboutwin", "")) 
     self.ab = self.builder.get_object("aboutwin") 
     self.builder.connect_signals(self) 

    def on_aboutdialog_response(self, widget, signal): 
     print("About close with button or (x)") 
     self.ab.hide() 

    def run(self): 
     self.ab.run() 

class MainHandler(Gtk.Window): 
    def on_delete_window(self, widget, signal): 
     print("Main window closed") 
     Gtk.main_quit() 

    def on_about_pressed(self, button): 
     print("Run About Dialog") 
     about = AboutDialog() 
     about.run() 

def main(): 
    builder = Gtk.Builder() 
    builder.add_objects_from_file("v0.glade", ("signinwin", "")) 
    builder.connect_signals(MainHandler()) 

    main = builder.get_object("signinwin") 
    main.show_all() 

    Gtk.main() 

if __name__ == "__main__": 
     main() 
<?xml version="1.0" encoding="UTF-8"?> 
<!-- Generated with glade 3.16.1 --> 
<interface> 
    <requires lib="gtk+" version="3.10"/> 
    <object class="GtkAboutDialog" id="aboutwin"> 
    <property name="can_focus">False</property> 
    <property name="resizable">False</property> 
    <property name="modal">True</property> 
    <property name="window_position">center</property> 
    <property name="destroy_with_parent">True</property> 
    <property name="type_hint">dialog</property> 
    <property name="has_resize_grip">False</property> 
    <property name="program_name">Movies App</property> 
    <property name="version">Version: 0.1</property> 
    <property name="authors">Markos Horro Varela 
Breixo Camiña Fernández</property> 
    <property name="documenters">Markos Horro Varela 
Breixo Camiña Fernández</property> 
    <property name="translator_credits" translatable="yes">Markos Horro Varela 
Breixo Camiña Fernández</property> 
    <property name="artists">Markos Horro Varela 
Breixo Camiña Fernández</property> 
    <property name="logo_icon_name">video-x-generic</property> 
    <property name="license_type">gpl-3-0</property> 
    <signal name="response" handler="on_aboutdialog_response" swapped="no"/> 
    <child internal-child="vbox"> 
     <object class="GtkBox" id="aboutgrid"> 
     <property name="can_focus">False</property> 
     <property name="orientation">vertical</property> 
     <property name="spacing">2</property> 
     <child internal-child="action_area"> 
      <object class="GtkButtonBox" id="aboutdialog-action_area1"> 
      <property name="can_focus">False</property> 
      <property name="layout_style">end</property> 
      </object> 
      <packing> 
      <property name="expand">False</property> 
      <property name="fill">True</property> 
      <property name="pack_type">end</property> 
      <property name="position">0</property> 
      </packing> 
     </child> 
     </object> 
    </child> 
    </object> 
    <object class="GtkWindow" id="signinwin"> 
    <property name="can_focus">False</property> 
    <property name="title" translatable="yes">Movie App</property> 
    <property name="resizable">False</property> 
    <property name="window_position">center</property> 
    <property name="has_resize_grip">False</property> 
    <signal name="delete-event" handler="on_delete_window" swapped="no"/> 
    <child> 
     <object class="GtkGrid" id="grid1"> 
     <property name="visible">True</property> 
     <property name="can_focus">False</property> 
     <property name="margin_left">10</property> 
     <property name="margin_right">60</property> 
     <property name="margin_top">10</property> 
     <property name="margin_bottom">10</property> 
     <child> 
      <object class="GtkEntry" id="login"> 
      <property name="visible">True</property> 
      <property name="can_focus">True</property> 
      <property name="margin_right">10</property> 
      <property name="margin_bottom">5</property> 
      <property name="input_purpose">name</property> 
      </object> 
      <packing> 
      <property name="left_attach">2</property> 
      <property name="top_attach">1</property> 
      <property name="width">1</property> 
      <property name="height">1</property> 
      </packing> 
     </child> 
     <child> 
      <object class="GtkEntry" id="pass"> 
      <property name="visible">True</property> 
      <property name="can_focus">True</property> 
      <property name="margin_right">10</property> 
      <property name="margin_top">5</property> 
      <property name="margin_bottom">5</property> 
      <property name="placeholder_text" translatable="yes">************</property> 
      <property name="input_purpose">password</property> 
      </object> 
      <packing> 
      <property name="left_attach">2</property> 
      <property name="top_attach">2</property> 
      <property name="width">1</property> 
      <property name="height">1</property> 
      </packing> 
     </child> 
     <child> 
      <object class="GtkLabel" id="userlabel"> 
      <property name="visible">True</property> 
      <property name="can_focus">False</property> 
      <property name="margin_right">6</property> 
      <property name="label" translatable="yes">User</property> 
      </object> 
      <packing> 
      <property name="left_attach">1</property> 
      <property name="top_attach">1</property> 
      <property name="width">1</property> 
      <property name="height">1</property> 
      </packing> 
     </child> 
     <child> 
      <object class="GtkLabel" id="passlabel"> 
      <property name="visible">True</property> 
      <property name="can_focus">False</property> 
      <property name="margin_right">6</property> 
      <property name="label" translatable="yes">Password</property> 
      </object> 
      <packing> 
      <property name="left_attach">1</property> 
      <property name="top_attach">2</property> 
      <property name="width">1</property> 
      <property name="height">1</property> 
      </packing> 
     </child> 
     <child> 
      <object class="GtkButton" id="button1"> 
      <property name="label" translatable="yes">Sign in</property> 
      <property name="visible">True</property> 
      <property name="can_focus">True</property> 
      <property name="receives_default">True</property> 
      <property name="margin_left">20</property> 
      <property name="margin_right">20</property> 
      </object> 
      <packing> 
      <property name="left_attach">2</property> 
      <property name="top_attach">3</property> 
      <property name="width">1</property> 
      <property name="height">1</property> 
      </packing> 
     </child> 
     <child> 
      <object class="GtkLabel" id="title"> 
      <property name="visible">True</property> 
      <property name="can_focus">False</property> 
      <property name="margin_left">5</property> 
      <property name="margin_right">5</property> 
      <property name="margin_top">5</property> 
      <property name="margin_bottom">5</property> 
      <property name="label" translatable="yes">Movie App</property> 
      </object> 
      <packing> 
      <property name="left_attach">2</property> 
      <property name="top_attach">0</property> 
      <property name="width">1</property> 
      <property name="height">1</property> 
      </packing> 
     </child> 
     <child> 
      <object class="GtkGrid" id="grid2"> 
      <property name="visible">True</property> 
      <property name="can_focus">False</property> 
      <child> 
       <object class="GtkButton" id="policy"> 
       <property name="label" translatable="yes">Policy</property> 
       <property name="visible">True</property> 
       <property name="can_focus">True</property> 
       <property name="receives_default">True</property> 
       <property name="margin_left">30</property> 
       <property name="margin_right">5</property> 
       <property name="margin_top">30</property> 
       <property name="margin_bottom">5</property> 
       </object> 
       <packing> 
       <property name="left_attach">0</property> 
       <property name="top_attach">0</property> 
       <property name="width">1</property> 
       <property name="height">1</property> 
       </packing> 
      </child> 
      <child> 
       <object class="GtkButton" id="aboutus"> 
       <property name="label" translatable="yes">About</property> 
       <property name="visible">True</property> 
       <property name="can_focus">True</property> 
       <property name="receives_default">True</property> 
       <property name="margin_left">5</property> 
       <property name="margin_right">30</property> 
       <property name="margin_top">30</property> 
       <property name="margin_bottom">5</property> 
       <signal name="clicked" handler="on_about_pressed" swapped="no"/> 
       </object> 
       <packing> 
       <property name="left_attach">1</property> 
       <property name="top_attach">0</property> 
       <property name="width">1</property> 
       <property name="height">1</property> 
       </packing> 
      </child> 
      </object> 
      <packing> 
      <property name="left_attach">2</property> 
      <property name="top_attach">4</property> 
      <property name="width">1</property> 
      <property name="height">1</property> 
      </packing> 
     </child> 
     <child> 
      <placeholder/> 
     </child> 
     <child> 
      <placeholder/> 
     </child> 
     <child> 
      <placeholder/> 
     </child> 
     <child> 
      <placeholder/> 
     </child> 
     <child> 
      <placeholder/> 
     </child> 
     <child> 
      <placeholder/> 
     </child> 
     <child> 
      <placeholder/> 
     </child> 
     <child> 
      <placeholder/> 
     </child> 
     </object> 
    </child> 
    </object> 
</interface>