ComboBox and VolumeButton are not causing calls to the timeout function. So the add_event and connect_key_press_event and connect_motion_notify_eventcalls are not adding the events to the event loop. Only the window events are happening. :-(
nielsdg "Application identifiers must contain at least one . (period) character (and thus at least two elements).", for example
gtk::Application and various other bits and pieces that might be interesting
extern crate shakmaty;
extern crate gtk;
extern crate gdk;
extern crate gio;
extern crate glib;
extern crate cairo;
extern crate gdk_pixbuf;
use gio::prelude::*;
mod chess_position_trainer;
use chess_position_trainer::graphic::main_window::{MainWindow};
fn main() {
if gtk::init().is_err() {
println!("Failed to initialize GTK.");
return;
}
let application = gtk::Application::new("com.loloof64.chess_position_trainer", gio::ApplicationFlags::empty())
.expect("Failed to initialize application !");
application.connect_startup(|application| {
let main_window = MainWindow::new(application);
application.connect_activate(move |_| {
main_window.show();
});
});
application.run(&Vec::new());
}main.rs
use gtk::prelude::*;
use gtk::{ApplicationWindow, Button, Image, Box as GtkBox, Orientation};
use gdk_pixbuf::Pixbuf;
use gio::MemoryInputStream;
use glib::Bytes;
use chess_position_trainer::graphic::{ChessBoard, load_image};
pub struct MainWindow
{
window: ApplicationWindow,
}
impl MainWindow
{
pub fn new(application: >k::Application) -> MainWindow
{
let mut main_window = MainWindow {
window: gtk::ApplicationWindow::new(application)
};
main_window.initialize();
main_window
}
pub fn show(&self)
{
self.window.show_all();
}
fn initialize(&mut self)
{
self.set_size_and_title();
self.set_icon();
let chessboard = ChessBoard::new_from_default()
.expect("Failed to intialize the chessboard !");
let reverse_board_button = Button::new();
let reverse_board_button_image = Image::new_from_pixbuf(
&load_image(
include_bytes!("../../resources/UpDown.png"),
20,
).expect("Could not find UpDown image !")
);
reverse_board_button.set_image(&reverse_board_button_image);
reverse_board_button.connect_clicked({
let chessboard = chessboard.clone();
move |_button|{
chessboard.borrow_mut().reverse();
}
});
let buttons_hbox = GtkBox::new(
Orientation::Horizontal,
20,
);
buttons_hbox.pack_start(
&reverse_board_button,
true,
false,
10,
);
let window_vbox = GtkBox::new(
Orientation::Vertical,
0,
);
window_vbox.pack_start(
&buttons_hbox,
false,
false,
10,
);
window_vbox.pack_start(
chessboard.borrow().get_drawing_area(),
true,
true,
0,
);
self.window.add(&window_vbox);
self.window.connect_delete_event(|_, _| {
gtk::main_quit();
Inhibit(false)
});
}
fn set_size_and_title(&mut self){
self.window.set_title("Chess Position Trainer");
let window_width = 50i32 * 9;
self.window.set_default_size(window_width, window_width + 65);
}
fn set_icon(&mut self){
let icon_stream = MemoryInputStream::new_from_bytes(
&Bytes::from_static(include_bytes!("../../resources/Chess_ql.png"))
);
let icon_pixbuf = Pixbuf::new_from_stream(&icon_stream, None);
let icon = match icon_pixbuf {
Ok(icon) => icon,
Err(e) => {
println!("Failed to get icon ! ({})", e);
return;
}
};
self.window.set_icon(&icon);
}
}main_window.rs
oknf take a look at this as well (if you are under Wayland) https://honk.sigxcpu.org/con/GTK__and_the_application_id.html
glib::set_application_name("blablabla")