I present gtkhah, a gtk module for hit-a-hint mouseless navigation of gtk3 applications.
It's been inspired by the various hit-a-hint browser extensions.
Usage at the project homepage. Here's a quick screenshot of Gedit:
Showing posts with label vala. Show all posts
Showing posts with label vala. Show all posts
Sunday, March 23, 2014
Saturday, April 06, 2013
Build Vala applications with Shake build system
I'm going to introduce you a very nice alternative to make: the Shake build system, by setting up a builder for your Vala application project.
First of all, you need to know that Shake is a library written in Haskell, and it's meant to be a better replacement for make. Let's start by installing cabal and then shake:
TL;DR; this is the final Build.hs file:
Just tweak app, sources and packages to match your needs, chmod +x Build.hs then run ./Build.hs .
Explanation.
The words function splits a string by spaces to get a list of strings, e.g. ["file1.vala", "file2.vala", "file3.vala"].
The csources variable maps .vala file names to .c file names. Same goes for cobjects. It's the equivalent of $(subst .vala,.c,$(SOURCES)) you'd do with make.
There it comes the main. The shakeArgs shakeOptions part will run shake with default options. Shake provides handy command line options similar to make, run ./Build.hs -h for help.
The want [app] tells shake we want to build the app object by default. That's equivalent to the usual first make rule all: $(APP).
Then we define how to build the executable app with app *> \out -> do. We tell shake the dependencies with need cobjects. This is similar to $(APP): $(COBJECTS) in make but not equivalent. In shake dependencies are not static like in many other build systems. This is one of the most interesting shake features.
The rest is quite straightforward to understand.
Then we define how to build each .o object with cobjects **> \out -> do. Here the out variable contains the actual .o required to be built, equivalent to $@ in make. Then we need [cfile], in order to simulate %.o: %.c like in make.
One more feature shake has out-of-the-box that make doesn't is how to generate more files from a single command. With make you'd use a .stamp file due to valac generating several .c files out of .vala files. Then use the .stamp as dependency.
With shake instead we consistently define how to build .c files with csources *>> \_ -> do, then shake will do the rest.
The shake project is very active. You can read this tutorial to learn Haskell basics, and the reference docs of shake. The author homepage has links to cool presentations of the shake build system.
First of all, you need to know that Shake is a library written in Haskell, and it's meant to be a better replacement for make. Let's start by installing cabal and then shake:
apt-get install cabal-install cabal update cabal install shake
TL;DR; this is the final Build.hs file:
#!/usr/bin/env runhaskell import Development.Shake import Development.Shake.FilePath import Development.Shake.Sys import Control.Applicative hiding ((*>)) app = "bestValaApp" sources = words "file1.vala file2.vala file3.vala" packages = words "gtk+-3.0 glib-2.0 gobject-2.0" cc = "cc" valac = "valac" pkgconfig = "pkg-config" -- derived csources = map (flip replaceExtension ".c") sources cobjects = map (flip replaceExtension ".o") csources main = shakeArgs shakeOptions $ do want [app] app *> \out -> do need cobjects pkgconfigflags <- pkgConfig $ ["--libs"] ++ packages sys cc "-fPIC -o" [out] pkgconfigflags cobjects cobjects **> \out -> do let cfile = replaceExtension out ".c" need [cfile] pkgconfigflags <- pkgConfig $ ["--cflags"] ++ packages sys cc "-ggdb -fPIC -c -o" [out, cfile] pkgconfigflags csources *>> \_ -> do let valapkgflags = prependEach "--pkg" packages need sources sys valac "-C -g" valapkgflags sources -- utilities prependEach x = foldr (\y a -> x:y:a) [] pkgConfig args = (words . fst) <$> (systemOutput pkgconfig args)
Just tweak app, sources and packages to match your needs, chmod +x Build.hs then run ./Build.hs .
Explanation.
The words function splits a string by spaces to get a list of strings, e.g. ["file1.vala", "file2.vala", "file3.vala"].
The csources variable maps .vala file names to .c file names. Same goes for cobjects. It's the equivalent of $(subst .vala,.c,$(SOURCES)) you'd do with make.
There it comes the main. The shakeArgs shakeOptions part will run shake with default options. Shake provides handy command line options similar to make, run ./Build.hs -h for help.
The want [app] tells shake we want to build the app object by default. That's equivalent to the usual first make rule all: $(APP).
Then we define how to build the executable app with app *> \out -> do. We tell shake the dependencies with need cobjects. This is similar to $(APP): $(COBJECTS) in make but not equivalent. In shake dependencies are not static like in many other build systems. This is one of the most interesting shake features.
The rest is quite straightforward to understand.
Then we define how to build each .o object with cobjects **> \out -> do. Here the out variable contains the actual .o required to be built, equivalent to $@ in make. Then we need [cfile], in order to simulate %.o: %.c like in make.
One more feature shake has out-of-the-box that make doesn't is how to generate more files from a single command. With make you'd use a .stamp file due to valac generating several .c files out of .vala files. Then use the .stamp as dependency.
With shake instead we consistently define how to build .c files with csources *>> \_ -> do, then shake will do the rest.
The shake project is very active. You can read this tutorial to learn Haskell basics, and the reference docs of shake. The author homepage has links to cool presentations of the shake build system.
Thursday, November 22, 2012
Grab focus on Gtk Widget
Many times I had to give focus to a newly created Gtk widget that still had to be mapped to screen. Since widget.grab_focus() does not work if the widget is not displayed on the screen, then I always used an idle source to delay the operation.
Today I noticed that the idle may be too late: if the user is writing something, then some key strokes may be lost because the idle runs slightly after the widget has been mapped. You may think that's imperceptible to the user, but that's not true in some cases.
So I've tried connecting to the map, map-event and show signals (also "after"), without success: the handler is called slightly before the right time thus grab_focus() will not work.
Then I ended up with this working solution, that will grab the focus as soon as the widget is first drawn to the screen:
I still don't know exactly what's the best way to grab focus as soon as the widget can really grab it. So if you have any better idea, please let me know :-)
Today I noticed that the idle may be too late: if the user is writing something, then some key strokes may be lost because the idle runs slightly after the widget has been mapped. You may think that's imperceptible to the user, but that's not true in some cases.
So I've tried connecting to the map, map-event and show signals (also "after"), without success: the handler is called slightly before the right time thus grab_focus() will not work.
Then I ended up with this working solution, that will grab the focus as soon as the widget is first drawn to the screen:
void focus_widget (Widget widget) { // it may be already displayed widget.grab_focus (); // grab focus right after the widget is drawn // for the first time ulong sigid = 0; sigid = widget.draw.connect (() => { widget.grab_focus (); widget.disconnect (sigid); return false; }); }
I still don't know exactly what's the best way to grab focus as soon as the widget can really grab it. So if you have any better idea, please let me know :-)
Thursday, September 08, 2011
Vala language introduction on IRC
Hi,
I've lately held an talk on IRC about the Vala programming language for the Ubuntu App Developer Week. I've introduced the basics of the Vala language and its features.
You can read the log of the talk here.
I've lately held an talk on IRC about the Vala programming language for the Ubuntu App Developer Week. I've introduced the basics of the Vala language and its features.
You can read the log of the talk here.
Saturday, July 09, 2011
Python/Ruby like generators in Vala
Hello,
the post below is copied straight from here.
Here I'll show a cool snippet code making use Vala async functions and iterators for emulating Python/Ruby generators. Creating a generator is as simple as extending the Generator class and implementing the generate() method.
You can find the above code snippet here as well.
the post below is copied straight from here.
Here I'll show a cool snippet code making use Vala async functions and iterators for emulating Python/Ruby generators. Creating a generator is as simple as extending the Generator class and implementing the generate() method.
abstract class Generator{ private bool consumed; private G value; private SourceFunc callback; public Generator () { helper (); } private async void helper () { yield generate (); consumed = true; } protected abstract async void generate (); protected async void feed (G value) { this.value = value; this.callback = feed.callback; yield; } public bool next () { return !consumed; } public G get () { var result = value; callback (); return result; } public Generator<G> iterator () { return this; } } class IntGenerator : Generator<int> { protected override async void generate () { for (int i=0; i < 10; i++) { yield feed (i); } } } void main () { var gen = new IntGenerator (); foreach (var i in gen) { message ("%d", i); } }
You can find the above code snippet here as well.
Saturday, May 14, 2011
Valag 1.2 released
Hello,
I've just released the 1.2 version of Valag, the graph generator for analyzing Vala code trees. Only relevant change is the fact that it now builds against libvala-0.14.
More information and download at the Valag homepage.
I've just released the 1.2 version of Valag, the graph generator for analyzing Vala code trees. Only relevant change is the fact that it now builds against libvala-0.14.
More information and download at the Valag homepage.
Wednesday, February 09, 2011
Rubik's Cube 3D Game in Vala/Clutter
Hello,
I've written a simple program for playing with a Rubik's Cube using Vala and Clutter.
It features:

Download and more usage information at the homepage... have fun :)
I've written a simple program for playing with a Rubik's Cube using Vala and Clutter.
It features:
- high simplicity in rotating cube slices and rotating the cube itself in a very natural manner
- shuffle the cube
- autosave the game

Download and more usage information at the homepage... have fun :)
Friday, January 14, 2011
Base64 and Quoted-Printable GConverters for GMua
Hello,
lately I'm writing GMua for educational purposes and for evaluating Vala, whose purpose is to simplify writing Mail User Agents or simple scripts, ala Java Mail.
It currently parses IMAP (not yet complete) and has a graphical interface called Gutt (yes, inspired by Mutt) for testing.
In order to parse MIME parts with base64 or quopri content-transfer-encoding I chose to implement a couple of GConverter (will use GMime a day, maybe when they switch to gio, not yet needed) in Vala that you can find here:
I'm pretty sure there are bugs in these converters, by the way I wanted to share them :)
Sunday, December 19, 2010
Valag 1.1 released, graph generator for the Vala AST
Hello,
Changes since 1.0 version:
- Add --format and --prefix options.
- Update to latest libvala-0.12.
- Bug fixes.
This new version also distributes the xdot.py program as a viewer for the generated graphs.
More information and download at the Valag homepage.
Etichette:
development,
graphviz,
languages,
vala,
valag
Friday, December 17, 2010
Maja - The Vala to Javascript compiler
Hello,
I've just released the first version of Maja, the Vala to Javascript compiler. The mapping is not quite complete but you can do pretty much everything you could do with javascript directly. There are (still incomplete) bindings for the qooxdoo framework and the demo browser is being ported to vala successfully.
Maja can be used in any environments, not only web browsers.
Programming in Vala saves you from lots of type safety troubles (Javascript), lot of typing (Java) and the syntax is really enjoyable as it is quite close to the Javascript model.
Usage and download at the homepage.
Thursday, July 29, 2010
Using Mash with Vala
Hello,
recently Mash has been released. It is a library for reading models in PLY format and creating Clutter actors from them. For reference, Blender is able to export to PLY. It means you can draw your models with Blender and use Clutter as rendering engine.
Clutter is a 3D canvas and animation toolkit while Blender is a 3D modelling suite.
What I've tested so far is porting the Monkey Viewer C example to Vala: code snippet and monkey PLY here.

That is going to be awesome, stay tuned!
recently Mash has been released. It is a library for reading models in PLY format and creating Clutter actors from them. For reference, Blender is able to export to PLY. It means you can draw your models with Blender and use Clutter as rendering engine.
Clutter is a 3D canvas and animation toolkit while Blender is a 3D modelling suite.
What I've tested so far is porting the Monkey Viewer C example to Vala: code snippet and monkey PLY here.

That is going to be awesome, stay tuned!
Mipsdis MIPS32 disassembler
Hello,
I've written a MIPS32 (Release 2) disassembler for ELF files. It is not a simple disassembler, it's mostly made for reverse engineering proprietary boxes for educational purposes. It has been successfully tested on Vodafone Station which has Broadcom binaries. These boxes don't have a sections table, therefore normal disassemblers don't work. Mipsdis instead will guess the bounds of those sections (most important ones are TEXT and RODATA for strings).
This console program outputs a friendly assembly code, whose each instruction is commented (comments copied directly from the mips specification). It also features labels for branches and symbol resolution for strings, global variables and functions.
More information and downloads here.
I've written a MIPS32 (Release 2) disassembler for ELF files. It is not a simple disassembler, it's mostly made for reverse engineering proprietary boxes for educational purposes. It has been successfully tested on Vodafone Station which has Broadcom binaries. These boxes don't have a sections table, therefore normal disassemblers don't work. Mipsdis instead will guess the bounds of those sections (most important ones are TEXT and RODATA for strings).
This console program outputs a friendly assembly code, whose each instruction is commented (comments copied directly from the mips specification). It also features labels for branches and symbol resolution for strings, global variables and functions.
More information and downloads here.
Friday, April 02, 2010
Valagtkdoc 1.0
Hello,
yes... this is the nth program I'm writing in this period. I hope this is the last one :)
Valagtkdoc is a tool that integrates Vala with GTK-Doc for documentation generation.
You can find download and example usage at the homepage.
I think it's far from being perfect, and actually I haven't tried integrating it with autotools, but it shouldn't be that hard. Unfortunately, you have to somehow break the gtk-doc rule "do not run it manually" because valagtkdoc goes in the middle between gtkdoc-scan and gtkdoc-mkdb.
If anybody has a better solution, please tell me :)
yes... this is the nth program I'm writing in this period. I hope this is the last one :)
Valagtkdoc is a tool that integrates Vala with GTK-Doc for documentation generation.
You can find download and example usage at the homepage.
I think it's far from being perfect, and actually I haven't tried integrating it with autotools, but it shouldn't be that hard. Unfortunately, you have to somehow break the gtk-doc rule "do not run it manually" because valagtkdoc goes in the middle between gtkdoc-scan and gtkdoc-mkdb.
If anybody has a better solution, please tell me :)
Etichette:
development,
gtk,
gtkdoc,
vala,
valagtkdoc
Sunday, March 14, 2010
Vala and Graphviz
Hello,
it's often useful for Vala hackers to have a graphical representation of the code tree and control flow blocks. Therefore I've created a simple application called Valag which generates four types of diagrams using Graphviz for each state of the Vala compiler.
This is the first release, there're many things to fix and enhance (like command line options) but it is working quite good already to give support when hacking Vala.
Homepage, screenshots and download here.
it's often useful for Vala hackers to have a graphical representation of the code tree and control flow blocks. Therefore I've created a simple application called Valag which generates four types of diagrams using Graphviz for each state of the Vala compiler.
This is the first release, there're many things to fix and enhance (like command line options) but it is working quite good already to give support when hacking Vala.
Homepage, screenshots and download here.
Etichette:
development,
gnome,
graphviz,
vala,
valag
Thursday, February 04, 2010
Vala 0.7.10 released
Hello,
I'm lately following the Vala development and finally we got a new release with plenty of bug fixes and enhancements which makes Vala even more interesting and usable as general purpose language.
Here's the announcement.
I'd like to point you to the new Vala journal, a good resource to stay tuned with Vala changes periodically.
News:
* Support coalescing operator ??.
* Support to_string and bitwise complement with enums.
* Return handler id when connecting signal handlers.
* Support struct comparison.
* Support constructor chaining in structs.
* Enforce protected member restrictions.
* Improve performance of flow analysis.
* Support automatic line continuations in Genie.
* Improvements to the .gir reader and writer.
* Add --enable-mem-profiler commandline option.
* Many bug fixes and binding updates.
Sunday, January 24, 2010
Fetch web page with Vala and Soup
Hello,
I'm lately using the Vala language widely. I find it a great and well designed language.
You may know I'm the maintainer of Freespeak. This program is written in Python. Now I'm rewriting it in Vala, both for providing a good and really simple API in C and for learning Vala.
I will now paste a snippet from the new freespeak code that I use for creating a cancellable asyncronous operation for fetching a web page using libsoup either with a GET or a POST method.
Here's the snippet at refactory.
Subscribe to:
Posts (Atom)
