Vala

How do I connect a custom function to the clicked action of a GTK Button?

旧巷老猫 提交于 2019-12-01 21:29:28
I am working my way through the Vala GTK+3 tutorial provided by Elementary OS. I understand that this code: var button_hello = new Gtk.Button.with_label ("Click me!"); button_hello.clicked.connect (() => { button_hello.label = "Hello World!"; button_hello.set_sensitive (false); }); uses a Lambda function to change the button's label when it's clicked. What I want to do is call this function instead: void clicked_button(Gtk.Button sender) { sender.label = "Clicked. Yippee!"; sender.set_sensitive(false); } I've tried this: button.clicked.connect(clicked_button(button)); But I get this error from

Why this function return an (owned) value?

≯℡__Kan透↙ 提交于 2019-12-01 20:53:19
the code from: Genie howto repeat a string N times as an string array Genie howto repeat a string N times as an string array def repeatwithsep (e: string, n: int, separator: string): string var elen = e.length; var slen = separator.length; var a = new StringBuilder.sized ((elen * n) + (slen * (n - 1)) + 1); for var i = 0 to (n - 1) if i != 0 a.append_len (separator, slen) a.append_len (e, elen) return (owned) a.str var a is a local variable, when a goes out of scope, it will be destroyed. why this function return (owned) a.str what is the difference between return a.str return (owned) a.str

Flatpak Meson Not Finding Vala Libraries From Gnome Builder

随声附和 提交于 2019-12-01 06:59:26
From Linux, I'm using Meson (0.44.0) within Gnome Builder (3.26.4) for a console program that will use Gee and GXml. My intent is to write this in Genie. When I use Meson within Gnome Builder it fails but the same succeeds when invoked from the command line using valac (0.38.8) as follows: valac --pkg=gtk+-3.0 --pkg=gee-0.8 --pkg=gxml-0.16 main.gs There is no error from the above. I've tried setting up meson.build with gee and gxml as dependency and alternatively as vala_args . Same error. Checking pkg-config, I get the following: $ pkg-config --libs gxml-0.16 -L/usr/local/lib64 -lgxml-0.16

Flatpak Meson Not Finding Vala Libraries From Gnome Builder

元气小坏坏 提交于 2019-12-01 05:24:04
问题 From Linux, I'm using Meson (0.44.0) within Gnome Builder (3.26.4) for a console program that will use Gee and GXml. My intent is to write this in Genie. When I use Meson within Gnome Builder it fails but the same succeeds when invoked from the command line using valac (0.38.8) as follows: valac --pkg=gtk+-3.0 --pkg=gee-0.8 --pkg=gxml-0.16 main.gs There is no error from the above. I've tried setting up meson.build with gee and gxml as dependency and alternatively as vala_args . Same error.

How can I change the font size of a Gtk.Label in vala?

痞子三分冷 提交于 2019-12-01 00:34:30
I'm a Vala/Gtk newbie and I'm trying to change the font size of a Gtk.Label, but I can't find a good way to do it. I find out that I can use the markup like this : var welcome_message = new Gtk.Label ("<span size='17000'>Hello</span>"); welcome_message.set_use_markup (true); But it seems a little hackish. What is the right way to do it ? You could try with css, I think lately this is the preferred way. Give your label a class, then load a css. If you are going to change the font size of a label, I bet you are also going to customize other things so the css may be useful for you. Thanks

How do Valas closures map to Genie?

*爱你&永不变心* 提交于 2019-11-30 20:53:31
The Vala Tutorial has an example about DBus using anonymous methods . Bus.own_name (BusType.SESSION, "org.example.DemoService", /* name to register */ BusNameOwnerFlags.NONE, /* flags */ on_bus_aquired, /* callback function on registration succeeded */ () => {}, /* callback on name register succeeded */ () => stderr.printf ("Could not acquire name\n")); /* callback on name lost */ I am trying to rewrite this code in Genie, but could not manage to convert the two last lines. The Genie Tutorial only has an example on how to use a closure to define an event handler . f.my_event += def (t, a)

run part of code as root

时光总嘲笑我的痴心妄想 提交于 2019-11-29 16:24:28
I have a package which runs uses Gtk and written in vala.A dialog box or a gui opens after selecting a file.I want this dialog box or gui to run as root so as to open and read the files which don't open with normal users.I have this code static void open_file(string filename) { selected_file = filename; stdout.printf(selected_file); new ProgressWindow(selected_file, {}); } I want to run ProgressWindow to run as root.Is it possible? No. To run as root, it must be in a separate process and you must run that process using pkexec via PolicyKit. Here's a tutorial on PolicyKit in Vala. 来源: https:/

understanding vala compilation warnings

谁说胖子不能爱 提交于 2019-11-29 14:18:47
The compilation warnings below are not so clear to me, appart from the deprecation warhing, but the signature of the method in the valadoc : http://valadoc.org/#!api=gstreamer-1.0/Gst shows no other method signature. the other warning are more obscure. max@max-ubuntu:~/mdev/cr valac --pkg gstreamer-0.10 gstpipe.vala /home/max/dev/main-sandbox/cr/gstpipe.vala.c: In function ‘application_message’: /home/max/dev/main-sandbox/cr/gstpipe.vala.c:64:2: warning: passing argument 1 of ‘_gst_structure_copy0’ discards ‘const’ qualifier from pointer target type [enabled by default] /home/max/dev/main

Vala GUI and logic in C++

旧巷老猫 提交于 2019-11-29 00:14:53
I have a drawing program that uses SDL, written in C++. I would like to create a graphical interface only in Vala and use it to call functions from a program (functions are ready to use and I only want to call them from the GUI). I was looking for solutions as VAPI, and I was thinking of using GObject, but I can not embrace both. Has anyone done similar things and can you suggest me a solution to my problem? If you want to use the C++ code in Vala we prepare them properly. Here's an example. First you have to tell the valac compiler that the function is defined somewhere else. Let's use the

How to repair warning: missing braces around initializer?

我是研究僧i 提交于 2019-11-28 20:05:52
The warning is produced by the c code generated by vala. warning: missing braces around initializer The code works but the warning is annoying. The vala code referenced by the warning is struct Position {uint x; uint y;} private static Position positions[8]; The generated C code is static Position det_positions[8] = {0}; I've tried initializing positions half a dozen different ways but can't seem to get the syntax to satisfy the warning. Is this GCC bug 53119 or is there a way to fix it? apmasell Yes, this appears to be related to GCC bug 53119 . It goes away if you change the C declaration to