我使用Glade创建了custom GtkFileChooserDialog
。 Modal
属性已标记。
我还有GtkFileChooserButton
使用此GtkFileChooserDialog
作为其对话框:
class ImgChooserBttWithCapture(Gtk.FileChooserButton):
"""
The custom Gtk.FileChooserButton and Gtt.FileChooserDialog with a button for call capture app
"""
def __init__(self, cap_app_path):
self.builder = Gtk.Builder.new_from_file(
UIS_PATH + 'images_chooser_dialog.xml')
self.chooser_dialog = self.builder.get_object('icd_photo_chsrdialog')
super().__init__(dialog=self.chooser_dialog)
self.cap_app_path = cap_app_path
self.set_title('Selecione uma imagem')
self.set_halign(Gtk.Align.START)
self.set_valign(Gtk.Align.FILL)
self.set_hexpand(True)
self.set_tooltip_text('Clique para escolher uma nova imagem')
self.set_local_only(False)
handlers = {'onCaptureButtonClicked': self._on_capture_button_clicked}
self.builder.connect_signals(handlers)
def _on_capture_button_clicked(self, button):
try:
subprocess.call([self.cap_app_path])
except (subprocess.CalledProcessError, subprocess.TimeoutExpired, FileNotFoundError) as ex:
self.builder.add_from_file(UIS_PATH + 'information_window.xml')
msg_dialog = self.builder.get_object('iw_messagedialog')
msg_dialog.set_title('Erro')
msg_dialog.set_markup(
'<span size="12000"><b>Não foi possível abrir o aplicativo</b></span>')
msg_dialog.format_secondary_markup(
'O aplicativo de captura não está disponível.\nVerifique o caminho para o aplicativo de caputura em configurações.\n' + '<span foreground="red"><u>' + str(ex) + '</u></span>')
msg_dialog.set_property('message-type', Gtk.MessageType.ERROR)
msg_dialog.set_transient_for(self.chooser_dialog)
self.builder.get_object('iw_message_image').set_from_file(
'views/uis/images/message_error.png')
msg_dialog.run()
msg_dialog.destroy()
但是,当我点击按钮时,对话框不是模态的,也就是说,我可以与其他窗口进行交互。
答案 0 :(得分:0)
grabbing指针会为你工作吗?
class Demo {
public static void main(String[] args) throws IOException {
Person person = new Person(42);
try {
System.out.println(person.getMoney());
person.addToShoppingBag(new Groceries(12));
person.addToShoppingBag(new Groceries(20));
person.addToShoppingBag(new Groceries(5));
System.out.println(person.getMoney());
System.out.println(person.getShoppingBag());
person.getShoppingBag().add(new Groceries(1));
} catch (UnsupportedOperationException e) {
e.printStackTrace();
}
try {
person.addToShoppingBag(new Groceries(66));
} catch (IllegalStateException e) {
e.printStackTrace();
}
}
}
class Person {
private List<Groceries> shoppingBag = new ArrayList<>();
private int money;
public Person(int money) {
this.money = money;
}
public List<Groceries> getShoppingBag() {
List<Groceries> bag = ImmutableList.copyOf(shoppingBag);
return bag;
}
public void addToShoppingBag(Groceries groceries) {
if (0 > money - groceries.getPrice()) {
throw new IllegalStateException("You have not enough money!");
}
shoppingBag.add(groceries);
money -= groceries.getPrice();
}
private void addMoney(int amout) {
money += amout;
}
public int getMoney() {
return money;
}
}
class Groceries {
private int price;
public Groceries(int price) {
this.price = price;
}
public int getPrice() {
return price;
}
@Override
public String toString() {
return "Groceries{" +
"price=" + price +
'}';
}
}