People
Repo info
Activity
  • May 11 2015 14:08
    GuillaumeGomez commented #71
Russel Winder
@russel
@slomo I tried connecting motion events and key press events to the ComboBox and VolumeButton, but still didn't get execution of the timeout code. :-( I guess I need some advice from a GTK+ and/or gtk-rs expert.
Sebastian Dröge
@sdroege
@russel what does timeout have to do with those two events?
Russel Winder
@russel
I am trying to keep a toolbar visible whilst there is any mouse movement or key presses happening. I haven't found a way other than putting delayed calls onto the event loop and doing a delay count. It is almost working, just not quite as required due to the way the events are being processed.
The advice to explicitly add the event to the widget as well as the window does appear to work. The problem is my algorithm and the event loop scheduling.
Russel Winder
@russel
Let me revise that, the mouse moves over the 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. :-(
matrixbot
@matrixbot
nielsdg rumanbsl: well, your application ID isn't valid
nielsdg "Application identifiers must contain at least one . (period) character (and thus at least two elements).", for example
laurent bernabé
@loloof64
Hi ! What the best way to embed the png files into my application so that it can work as well in debug than in release mode ?
Evgenii Pashkin
@EPashkin
laurent bernabé
@loloof64
thanks @EPashkin I'll look at it right now :smile:
laurent bernabé
@loloof64
It worked :smile: Thank you again :smile:
laurent bernabé
@loloof64
Hi ! Do anybody know how to set the application tooltip, for the relative icon in the system applications bar ?
app_tooltip.png
matrixbot
@matrixbot
oknf it seems to be matched through application-id to desktop file and fetched from there, presuming you are using GtkApplication
laurent bernabé
@loloof64
Thank you :smile: I did not know I could use GtkApplication. I will search for some snippets (even in Python code : easily adaptable to Rust) using it. :smile:
Sebastian Dröge
@sdroege
@loloof64 you could take a look at the code from the rustfest workshop guillaume and i did https://github.com/sdroege/rustfest-rome18-gtk-gst-workshop . it also uses gtk::Application and various other bits and pieces that might be interesting
laurent bernabé
@loloof64
Thank you very much :smile: I will try this evening
Sebastian Dröge
@sdroege
@loloof64 just ask here if you have any questions, or especially if the comments in the code could be improved
José Eduardo Quadrado Correia
@jqcorreia
Hey there! I have a pretty standard use case but I'm struggling with component styling and maybe you guys can help me. The use case is as follows: A background service is running a state machine which feeds messages to the UI. Certain messages should trigger visual changes in the form of color changes. (e.g an OK message would put a label background green). My initial thought was to define 'reusable' classes in css such as '.green' and '.bold' and compose the style by changing the active classes on a given widget. The problem here is that calling add_class (or remove_class) doesn't seem to work after get_style_context().add_provider(CssProvider) call. This being said I have 2 questions: Is this the right way to do this kind of thing? If it is, what am I missing?
laurent bernabé
@loloof64
@sdroege Thank you. I'll point out if any problem :smile:
laurent bernabé
@loloof64
Hi, I tried to set up the system tooltip for my application, based on project https://github.com/sdroege/rustfest-rome18-gtk-gst-workshop, but don't know why the title of my main window does not appear, in the following files
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: &gtk::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

matrixbot
@matrixbot
oknf do you have a desktop file for "com.loloof64.chess_position_trainer" already?
oknf take a look at this as well (if you are under Wayland) https://honk.sigxcpu.org/con/GTK__and_the_application_id.html
laurent bernabé
@loloof64
Thanks for your anwer :smile: . Indeed i have not any desktop file. I am not under wayland either. I'll try your suggestion this evening coming back from work.
Where can I find an example of desktop file ?
matrixbot
@matrixbot
oknf /usr/share/applications
laurent bernabé
@loloof64
Thanks. So it works only on unix likes os ?
Sebastian Dröge
@sdroege
@loloof64 your problem is that the string passed to window.set_title() is not shown in the window or ...?
laurent bernabé
@loloof64
It is not shown on my linux desktop icon of my application.
matrixbot
@matrixbot
oknf sorry, I don't know about win / macos
laurent bernabé
@loloof64
No problem :smile:
@sdroege i am trying something like this
Here code is shown for visual studio code when hovering icon
Sebastian Dröge
@sdroege
ah
desktop file or application name, not sure
glib::set_application_name("blablabla")
laurent bernabé
@loloof64
Thank you :smile: I'll try this evening :smile:
laurent bernabé
@loloof64
@sdroege I tried with glib::set_application_name("Chess Position Trainer"); before the call to gtk::init(), but I did not work
Sebastian Dröge
@sdroege
@loloof64 then you'll have to figure out where it takes the string from :) maybe only the .desktop file, but that requires you to install the application then
laurent bernabé
@loloof64
@sdroege Thank you :smile: So I think one solution is to give a desktop file with the application. Otherwise, that feature is not mandatory for me.
LordZane
@LordZane
Apparently I can set the css class .destructive-action and get a red button? How do I go about that? And does anyone know how to package my app with flatpak? I couldn't get a simple build system with cargo to work
@LordZane for flatpak/build system: take a look at fractal or the gnome podcast application
LordZane
@LordZane
oh haha, no period in the class name, thanks. ill take a look at those
they use meson unfortunately, I was hoping for something more simple
LordZane
@LordZane
So I have a model with some values. How would I render the values differently then the default for a view? E.g., the model is a bool, but render either a blank string, or the string "★"
Stefan Lendl
@stfl
,