ich loocking für jede Idee setzen mein ProblemWie Standardantwort auf die Schaltfläche mit add_action_widget in Gtk.Dialog
Bitte sehen Code folgen zu lösen. Es ist eine Demo zu erklären, was ist In der Tat muss ich add_action_widget verwenden, um Button hinzufügen, um Button mit Bild hinzufügen. Wenn ich add_action_widget und add_button Widget mischen, sind nicht die gleiche vertikale Größe und es ist hässlich.
würde ich Gebrauch nur add_action_widget und fähig sein mag gültige Taste als Standardantwort festlegen
#!/usr/bin/env python
# coding: utf-8
#dialog_defaultbutton.py
from gi.repository import Gtk
class boite_stockicon_etiquette:
''' box with STOCK Icon '''
def __init__(self,text, stock_icon=None,sizeicon=Gtk.IconSize.MENU):
# On cree une boite pour la pixmap et l'etiquette
self.box = Gtk.HBox(False, 0)
self.box.set_border_width(2)
# A present l'image.
if stock_icon is not None:
image = Gtk.Image.new_from_stock(stock_id=stock_icon,size=sizeicon)
else:
image = Gtk.Image.new_from_stock(stock_id=Gtk.STOCK_OK,size=sizeicon)
# On cree une etiquette pour le bouton.
etiquette = Gtk.Label(text)
# pack image and label in the box
self.box.pack_start(image, False, False, 3)
self.box.pack_start(etiquette, False, False, 3)
"""image.show()
etiquette.show()"""
def box_xpm(self):
return self.box
class dialogDefaultButton:
""" make button with stock icon"""
def _make_button(self,etiquette=None,stock_icon=None):
boite1= boite_stockicon_etiquette(etiquette,stock_icon=stock_icon)
boite = boite1.box_xpm()
bouton = Gtk.Button()
bouton.add(boite)
return bouton
def __init__(self,text):
self.dialog = Gtk.Dialog(title="Dialog")
self.dialog.set_default_size(400, 300)
self.dialog.set_border_width(10)
self.dialog.add_action_widget(self._make_button(etiquette=u'Valid',stock_icon=Gtk.STOCK_OK),Gtk.ResponseType.OK)
self.dialog.add_action_widget(self._make_button(etiquette=u'Cancel',stock_icon=Gtk.STOCK_CANCEL),Gtk.ResponseType.CANCEL)
#Please test under with True ou False
flag_button_valide_setdefault = False
#if flag_button_valide_setdefault is True the valid button is set like self.dialog.set_default_response(Gtk.ResponseType.OK)
if flag_button_valide_setdefault is not True:
self.dialog.add_action_widget(self._make_button(etiquette=u'Add', stock_icon=Gtk.STOCK_ADD),Gtk.ResponseType.APPLY)
self.dialog.add_action_widget(self._make_button(etiquette=u'Help', stock_icon=Gtk.STOCK_ABOUT),Gtk.ResponseType.HELP)
label = Gtk.Label(text)
content_area = self.dialog.get_content_area()
content_area.add(label)
self.dialog.show_all()
#Here action do not run ok why ?
# Ok only with button created with add_button
def run(self):
while 1:
self.reponse = self.dialog.run()
if self.reponse in [Gtk.ResponseType.OK, Gtk.ResponseType.CANCEL,Gtk.ResponseType.DELETE_EVENT]:
print("OK sa marche button clicked")
print self.reponse
break
else:
print 'Hello'
self.dialog.destroy()
return self.reponse
if __name__ == "__main__":
demo = dialogDefaultButton(text= u'demo of default button depend widget list why?\n\
\n\
if flag_button_valide_setdefault == True , \n\
the valid button is set like self.dialog.set_default_response(Gtk.ResponseType.OK)\n\
if flag_button_valide_setdefault == False \n\
\n\
if somebody could help me to understand what is about !!!!!\n\
in fact I need to have flag_button_valide_setdefault =False\n\
and the valid button set with default response like case of flag==True')
response = demo.run()
if response == Gtk.ResponseType.OK:
print("OK button clicked")
elif response == Gtk.ResponseType.CANCEL:
print("Cancel button clicked")
else:
print("Dialog closed")
zitiert Voraus für Ihre Hilfe