This package's functionality is very narrowly to add support for the signal connection features of Glade and GtkBuilder objects in Julia.
This package builds on top of the Julia interface to Gtk.
This package can be installed by use of Julia's in-built package manager as the
GtkBuilderAid package. As a result
Pkg.add is usually sufficient to install
A simple example that matches up with the shown GUI is displayed below.
function_table = @GtkFunctionTable begin @guarded function click_ok( widget, user_info) println("OK clicked!") return nothing end @guarded function close_window( widget, window) destroy(window) return nothing end end quickstart(function_table, "com.github.matt5sean", "main_window", "resources/main.ui", nothing)
All of the functions defined in the block starting with
function_table = @GtkFunctionTable are compiled into a Dict mapping the
function names to the functions themselves. This dictionary can then be
used with various methods to make them accessible as handlers for the builder
Note how the handler for
click_ok is filled out directly as
match the code above.
User Data Choices
The arguments to the macro preceding the filename and code block generally
refine how the macro should behave. The most important of these directives are
the user data directives of which there are four. However, user data may also be
set within glade using the
User data field in the
Signals tab of the widget
Glade User data
In cases where the user data is set in glade, the user data type will be
converted to the proper
GObject type. In the code block above this is
demonstrated with the
close_window function which will receive a
type as its user data argument.
Julia Bound User Data
User data may also be bound by modifying the function table.
example_app = GtkApplication("com.github.example", 0) builder = @GtkFunctionTable begin @guarded function click_ok( widget, user_info) println("OK clicked!") return nothing::Void end @guarded function close_window( widget, window) destroy(window) return nothing::Void end end @guarded function activateApp(widget, userdata) app, builder = userdata built = GtkBuilder(filename="$(Pkg.dir("*your_package*"))/resources/main.ui") builder(built, (app, )) win = Gtk.GAccessor.object(built, "main_window") push!(app, win) showall(win) return nothing end signal_connect(activateApp, example_app, :activate, Void, (), false, (example_app, builder)) run(example_app)
There are examples available for examination in this package in the examples directory.
There are a few helper functions added to this package to make certain functionalities easier.
This helper function adds a method to Julia's base
quit function that takes a
GtkApplication object as its first argument and call the C function
g_application_quit on it. This is a very useful function for explicitly
stopping a running application.
This is similar to calling Gtk.jl's
reveal function but rather than causing
the entire widget to be updated only a particular piece of the widget is
revealed by this function. The first argument is a GtkWidget while the
subsequent arguments are the x coordinate, y coordinate, width, and height of
the top-left corner of the rectangular area to update. As an example,
reveal_area(w, 5, 10, 50, 60) would update a 50 pixel by 60 pixel rectangle at
5 pixels from the left side of the widget and 10 pixels from the top of the
This helper function creates a
CairoSurface based on a realized widget with
dimensions matching the widget. The first argument must be the widget for which
the surface is created. A second optional argument, which is
Cairo.CONTENT_COLOR_ALPHA by default, allows choosing the content type of the
Some macros at the first layer of the block processed by the
macro are manually expanded during analysis of that block. The expansion will be
kept and added to the list of signals in the case that the expanded expression
is a function definition. Macros that don't result in function definitions will
be left to expand as they would have otherwise. This expansion works well enough
for simple macros such as the Gtk wrapper library's
@guarded macro but has the
potential to cause complications in more complex macros.
Only functions defined at the level of the block within the macro will be converted to C functions and be enabled as signals. This is partly to give a means to define functions that won't be used as functions.
Calling other functions that are defined within the signal handler block will result in an error in effectively every case. Any functionality that needs to be reused in multiple signals should instead be defined outside of the signal handler block. This behaviour will not be changed for future versions.