mainwindow: connect button to actions

Connect:

- add plugin dialog
- open file dialog
- about dialog
This commit is contained in:
Stéphane Cerveau 2021-11-15 18:52:16 +01:00
parent 12e7958886
commit bdd183075e
2 changed files with 167 additions and 21 deletions

View file

@ -2,6 +2,122 @@
<!-- Generated with glade 3.38.2 --> <!-- Generated with glade 3.38.2 -->
<interface> <interface>
<requires lib="gtk+" version="3.24"/> <requires lib="gtk+" version="3.24"/>
<object class="GtkAboutDialog" id="dialog-about">
<property name="can-focus">False</property>
<property name="type-hint">dialog</property>
<property name="program-name">GstPipelineStudio</property>
<property name="authors">Stéphane Cerveau</property>
<property name="logo-icon-name">image-missing</property>
<child internal-child="vbox">
<object class="GtkBox">
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox">
<property name="can-focus">False</property>
<property name="layout-style">end</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
</object>
<object class="GtkDialog" id="dialog-add-plugin">
<property name="can-focus">False</property>
<property name="default-width">320</property>
<property name="default-height">260</property>
<property name="type-hint">dialog</property>
<child internal-child="vbox">
<object class="GtkBox">
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox">
<property name="can-focus">False</property>
<property name="layout-style">end</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="shadow-type">in</property>
<child>
<object class="GtkTreeView">
<property name="visible">True</property>
<property name="can-focus">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection"/>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
<object class="GtkFileChooserDialog" id="dialog-open-file">
<property name="can-focus">False</property>
<property name="type-hint">dialog</property>
<child internal-child="vbox">
<object class="GtkBox">
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox">
<property name="can-focus">False</property>
<property name="layout-style">end</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
</object>
<object class="GtkApplicationWindow" id="mainwindow"> <object class="GtkApplicationWindow" id="mainwindow">
<property name="can-focus">False</property> <property name="can-focus">False</property>
<property name="border-width">6</property> <property name="border-width">6</property>
@ -219,7 +335,7 @@
<property name="can-focus">False</property> <property name="can-focus">False</property>
<property name="layout-style">start</property> <property name="layout-style">start</property>
<child> <child>
<object class="GtkButton" id="button-add"> <object class="GtkButton" id="button-add-plugin">
<property name="label">gtk-add</property> <property name="label">gtk-add</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">True</property> <property name="can-focus">True</property>
@ -234,7 +350,7 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkButton" id="button-open"> <object class="GtkButton" id="button-open-file">
<property name="label">gtk-open</property> <property name="label">gtk-open</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">True</property> <property name="can-focus">True</property>
@ -269,13 +385,13 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkButton"> <object class="GtkButton" id="button-pause">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">True</property> <property name="can-focus">True</property>
<property name="receives-default">True</property> <property name="receives-default">True</property>
<property name="always-show-image">True</property> <property name="always-show-image">True</property>
<child> <child>
<object class="GtkImage" id="button-pause"> <object class="GtkImage">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">False</property> <property name="can-focus">False</property>
<property name="stock">gtk-media-pause</property> <property name="stock">gtk-media-pause</property>
@ -289,13 +405,13 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkButton"> <object class="GtkButton" id="button-stop">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">True</property> <property name="can-focus">True</property>
<property name="receives-default">True</property> <property name="receives-default">True</property>
<property name="always-show-image">True</property> <property name="always-show-image">True</property>
<child> <child>
<object class="GtkImage" id="button-stop"> <object class="GtkImage">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">False</property> <property name="can-focus">False</property>
<property name="stock">gtk-media-stop</property> <property name="stock">gtk-media-stop</property>
@ -309,12 +425,12 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkButton"> <object class="GtkButton" id="button-clear">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">True</property> <property name="can-focus">True</property>
<property name="receives-default">True</property> <property name="receives-default">True</property>
<child> <child>
<object class="GtkImage" id="button-clear"> <object class="GtkImage">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">False</property> <property name="can-focus">False</property>
<property name="stock">gtk-clear</property> <property name="stock">gtk-clear</property>
@ -358,6 +474,7 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">False</property> <property name="can-focus">False</property>
<property name="vexpand">True</property> <property name="vexpand">True</property>
<property name="homogeneous">True</property>
<child> <child>
<object class="GtkScrolledWindow"> <object class="GtkScrolledWindow">
<property name="visible">True</property> <property name="visible">True</property>

View file

@ -2,8 +2,8 @@ use gtk::cairo::Context;
use gtk::glib; use gtk::glib;
use gtk::prelude::*; use gtk::prelude::*;
use gtk::{ use gtk::{
AboutDialog, AccelFlags, AccelGroup, ApplicationWindow, Builder, DrawingArea, EventBox, AboutDialog, AccelFlags, AccelGroup, ApplicationWindow, Builder, Button, Dialog, DrawingArea,
MenuItem, Viewport, WindowPosition, EventBox, FileChooserDialog, MenuItem, ResponseType, Viewport, WindowPosition,
}; };
use std::cell::RefCell; use std::cell::RefCell;
use std::rc::Rc; use std::rc::Rc;
@ -59,6 +59,46 @@ pub fn build_ui(application: &gtk::Application) {
let quit: MenuItem = builder.object("menu-quit").expect("Couldn't get window"); let quit: MenuItem = builder.object("menu-quit").expect("Couldn't get window");
let about: MenuItem = builder.object("menu-about").expect("Couldn't get window"); let about: MenuItem = builder.object("menu-about").expect("Couldn't get window");
let about_dialog: AboutDialog = builder.object("dialog-about").expect("Couldn't get window");
about.connect_activate(move |_| {
about_dialog.show();
});
// Create a dialog to select GStreamer elements.
let add_button: Button = builder
.object("button-add-plugin")
.expect("Couldn't get app_button");
let add_dialog: Dialog = builder
.object("dialog-add-plugin")
.expect("Couldn't get window");
add_button.connect_clicked(glib::clone!(@weak window => move |_| {
// entry.set_text("Clicked!");
add_dialog.connect_response(|dialog, _| dialog.close());
add_dialog.show_all();
}));
// Create a dialog to open a file
let open_button: Button = builder
.object("button-open-file")
.expect("Couldn't get app_button");
let open_dialog: FileChooserDialog = builder
.object("dialog-open-file")
.expect("Couldn't get window");
open_button.connect_clicked(glib::clone!(@weak window => move |_| {
// entry.set_text("Clicked!");
open_dialog.connect_response(|dialog, _| dialog.close());
open_dialog.add_buttons(&[
("Open", ResponseType::Ok),
("Cancel", ResponseType::Cancel)
]);
open_dialog.set_select_multiple(true);
open_dialog.connect_response(|open_dialog, response| {
if response == ResponseType::Ok {
let files = open_dialog.filenames();
println!("Files: {:?}", files);
}
open_dialog.close();
});
open_dialog.show_all();
}));
let accel_group = AccelGroup::new(); let accel_group = AccelGroup::new();
window.add_accel_group(&accel_group); window.add_accel_group(&accel_group);
@ -72,15 +112,4 @@ pub fn build_ui(application: &gtk::Application) {
// different values on different platforms. // different values on different platforms.
let (key, modifier) = gtk::accelerator_parse("<Primary>Q"); let (key, modifier) = gtk::accelerator_parse("<Primary>Q");
quit.add_accelerator("activate", &accel_group, key, modifier, AccelFlags::VISIBLE); quit.add_accelerator("activate", &accel_group, key, modifier, AccelFlags::VISIBLE);
about.connect_activate(move |_| {
let p = AboutDialog::new();
p.set_authors(&["gtk-rs developers"]);
p.set_website_label(Some("gtk-rs"));
p.set_website(Some("http://gtk-rs.org"));
p.set_authors(&["gtk-rs developers"]);
p.set_title("About!");
p.set_transient_for(Some(&window));
p.show_all();
});
} }