genie

How to INSERT information into a Sqlite database using Genie Programming Language?

家住魔仙堡 提交于 2019-12-12 02:26:30
问题 This question is a spin off a previous question here in which a database was created. However, when it comes to add information to that dataset I can go manually adding information or going via a programmatically way. The latter is my choice for a didactic reason. The equivalent of what I am trying to do in python is: for x in cursor.execute(sql): lastid = x[0] # Insert data into the instructions table sql = 'INSERT INTO Instructions (recipeID,instructions) VALUES( %s,"Brown hamburger. Stir

Genie howto repeat a string N times as an string array

丶灬走出姿态 提交于 2019-12-11 20:35:41
问题 I write this code, repeatc for repeat char to char array. it works. repeats for repeat string N times to an string array. but repeat string to string array core dumped. A, A, A, AB, AB, AB, *** Error in `./untitled': free(): invalid pointer: 0x0000000000400f3d *** .... .... Aborted (core dumped) why? my code: // --cc='gcc' [indent=4] init var carray = repeatc ('A', 3) for i in carray do stdout.printf ("%c, ", i) // A, A, A stdout.putc ('\n') var sarray = repeats ("AB", 3) for i in sarray do

[genie/vala]: How to Sort using a custom comparator?

余生颓废 提交于 2019-12-11 13:12:38
问题 genie! how to Sort an array (or list) of strings in order of descending length, and in ascending lexicographic order for strings of equal length. my data is datas : array of string = { "cold", "z", "bpples", "pallalala", "apples", "xccv" } 回答1: Genie and Vala's built-in array type is not very friendly since it really a C array underneath. You'd have to use C's qsort function to do it. I would recommend you use a Gee.List instead, which has a nice sort method that takes a comparator: var list

How does string interpolation / string templates work?

…衆ロ難τιáo~ 提交于 2019-12-11 04:15:40
问题 @lf_araujo asked in this question: var dic = new dict of string, string dic["z"] = "23" dic["abc"] = "42" dic["pi"] = "3.141" for k in sorted_string_collection (dic.keys) print (@"$k: $(dic[k])") What is the function of @ in print(@ ... ) and lines_add(@ ...)? As this is applicable to both Genie and Vala, I thought it would be better suited as a stand-alone question. The conceptual question is: How does string interpolation work in Vala and Genie? 回答1: There are two options for string

Differences btw Gtk.Table and Gtk.Grid

删除回忆录丶 提交于 2019-12-10 22:54:16
问题 Althought Gtk.table is deprecated, I am getting better results with it, instead of the recommended Gtk.Grid. It is probably my mistake, but I couldn't find the problem. My aim is to create a Gtk window with a notebook at the top and two buttons below. These buttons should be horizontally aligned. My code with table, works as expected: uses Gtk class TestWindow : Window init // General characteristics of the window title = "Gtk Containers" default_height = 250 default_width = 250 window

The Button.connect syntax in Genie

喜你入骨 提交于 2019-12-10 11:36:18
问题 I want to apply a certain behaviour to a label. When a lateral button is clicked, the corresponding label should rotate 90 degrees. It can be easily done in vala, but I can't discover the particular syntax on genie. The vala code I am trying to reproduce comes from elementary OS getting started guide: hello_button.clicked.connect(() => { hello_label.label = "Hello World!"; hello_button.sensitive = false; }); rotate_button.clicked.connect(() => { rotate_label.angle = 90; rotate_label.label =

How to concatenate two arrays?

泪湿孤枕 提交于 2019-12-08 05:13:17
问题 [indent=4] init x: array of int = {1, 2, 3} y: array of int = {4, 5, 6} z: array of int = x + y The above code produces this error message: concat_arrays.gs:6.23-6.27: error: Incompatible operand z: array of int = x + y The Vala translation doesn't work any better: int main () { int[] x = {1, 2, 3}; int[] y = {4, 5, 6}; int[] z = x + y; return 0; } The error message is: concat_arrays_v.vala:4.15-4.19: error: Incompatible operand int[] z = x + y; What is the correct way to do this? 回答1: Using

How to sort a dict in genie

一个人想着一个人 提交于 2019-12-08 03:54:33
问题 Update Solved the compiling error, now the only problem with the code is how to sort the dict alphabetically for pretty printing. I am refactoring an argument parser from python into Genie, however I found myself stuck in how to sort the items form a dict before appending them to a list. In python it is as simple as: lines.append("Options:") if len(self.options): for name, option in sorted(self.options.items()): lines.append(" %s: %s" % (name, option.values)) else: lines.append(" [none]")

Gee HashMap containing methods as values

隐身守侯 提交于 2019-12-07 03:22:48
问题 I'm trying to fill a Libgee HashMap where each entry has a string as key, and a function as value. Is this possible? I want this sort of thing: var keybindings = new Gee.HashMap<string, function> (); keybindings.set ("<control>h", this.show_help ()); keybindings.set ("<control>q", this.explode ()); so that I can eventually do something like this: foreach (var entry in keybindings.entries) { uint key_code; Gdk.ModifierType accelerator_mods; Gtk.accelerator_parse((string) entry.key, out key

How to concatenate two arrays?

半世苍凉 提交于 2019-12-06 16:58:44
[indent=4] init x: array of int = {1, 2, 3} y: array of int = {4, 5, 6} z: array of int = x + y The above code produces this error message: concat_arrays.gs:6.23-6.27: error: Incompatible operand z: array of int = x + y The Vala translation doesn't work any better: int main () { int[] x = {1, 2, 3}; int[] y = {4, 5, 6}; int[] z = x + y; return 0; } The error message is: concat_arrays_v.vala:4.15-4.19: error: Incompatible operand int[] z = x + y; What is the correct way to do this? Jens Mühlenhoff Using GLib.Array<T> : int main () { int[] x = {1, 2, 3}; int[] y = {4, 5, 6}; Array<int> a = new