EzDevInfo.com

gtk interview questions

Top gtk frequently asked interview questions

What should I choose: GTK+ or Qt? [closed]

Can someone suggest what's the best uses for those libraries today? Is it just GUI, or do they have database, XML, networking, threading, etc support too?

I was reading about them, and considered starting to learning/using one of them.

What is the most common one? What's the difference between them? Why would you choose one over the other?


Source: (StackOverflow)

Ruby bindings for GTK+ 3?

I’ve spent some time learning Ruby, and I wanted to move over to some GUI programming. GNOME 3 is the environment most appealing to me at the moment, so I thought I would have a look at GTK+ 3. However, the GTK+ 3 documentation’s Getting Started examples in C were quite off-putting. Are there less scary Ruby bindings (and Hello World examples) available?

Edit: The GTK+ Language Bindings overview does not leave much room for hope.


Source: (StackOverflow)

Advertisements

How to show a message box from a bash script in linux

I'm writing a few little bash scripts under Ubuntu linux. I want to be able to run them from the GUI without needing a terminal window to enter any input or view any output.

So far the only input required is a password for sudo - and gksudo handles that fine. But I haven't found an easy way to show a message box yet. Is there some kind of 'gkmessage' command available? I'd prefer something present in a default Ubuntu install, but I don't mind installing a new package if necessary.


Source: (StackOverflow)

GLib compile error (ffi.h), but libffi is installed

After a succesful configure, make exits with snipped

gclosure.c:29:17: fatal error: ffi.h: No such file or directory
compilation terminated.

I have libffi installed, and locate ffi.h gives:

/home/luca/gcc4.6/gcc-4.6.0/libffi/include/ffi.h.in
/usr/include/x86_64-linux-gnu/ffi.h
/usr/share/doc/ghc-doc/html/users_guide/ffi.html
/usr/share/doc/libffi5/html/Using-libffi.html

Source: (StackOverflow)

Pango-WARNING **: failed to choose a font, expect ugly output

I'm getting this error when starting anything that uses the Pango library. I'm using Kubuntu 9.10. I've done 'sudo apt-get --reinstall install' on libgtk* libcairo* libpango* and fontconfig, with no luck.

Could someone point me in the right direction? Thanks.


Source: (StackOverflow)

PyGObject GTK+ 3 - Documentation?

PyGObject appears to have no real documentation. This tutorial is as close as it gets. I've been struggling all morning simply trying to find a description of the arguments accepted by the Gtk.Window constructor. It seems I can't do much reflection in Python because everything in PyGObject is dynamically generated.

All I want is to know what arguments I can pass to this constructor! There doesn't appear to be an equivalent of this object in the GTK+ 3 documentation, and reading the source code to figure out the bindings has proven to be an extremely daunting task. Any ideas??


Source: (StackOverflow)

Cabal install gtk failing

I'm trying to install gtk via cabal, however, I'm getting the following type errors when building it

[ 22 of 209] Compiling Graphics.UI.Gtk.Embedding.Plug ( dist/build/Graphics/UI/Gtk/Embedding/Plug.hs, dist/build/Graphics/UI/Gtk/Embedding/Plug.o )

Graphics/UI/Gtk/Embedding/Plug.chs:120:6: error:
    Couldn't match expected type ‘Ptr ()’
                with actual type ‘Maybe DrawWindow’
    In the first argument of ‘gtk_plug_new’, namely
      ‘(fromNativeWindowId (fromMaybe nativeWindowIdNone socketId))’
    In the second argument of ‘($)’, namely
      ‘gtk_plug_new
         (fromNativeWindowId (fromMaybe nativeWindowIdNone socketId))’

Graphics/UI/Gtk/Embedding/Plug.chs:137:6: error:
    Couldn't match expected type ‘Ptr ()’
                with actual type ‘Maybe DrawWindow’
    In the second argument of ‘\ (Display arg1) arg2
                                 -> withForeignPtr arg1
                                    $ \ argPtr1 -> gtk_plug_new_for_display argPtr1 arg2’, namely
      ‘(fromNativeWindowId (fromMaybe nativeWindowIdNone socketId))’
    In the second argument of ‘($)’, namely
      ‘(\ (Display arg1) arg2
          -> withForeignPtr arg1
             $ \ argPtr1 -> gtk_plug_new_for_display argPtr1 arg2)
         display
         (fromNativeWindowId (fromMaybe nativeWindowIdNone socketId))’

Graphics/UI/Gtk/Embedding/Plug.chs:151:3: error:
    Couldn't match type ‘Ptr ()’ with ‘Maybe DrawWindow’
    Expected type: IO (Maybe DrawWindow)
      Actual type: IO (Ptr ())
    In the second argument of ‘($)’, namely
      ‘(\ (Plug arg1)
          -> withForeignPtr arg1 $ \ argPtr1 -> gtk_plug_get_id argPtr1)
         (toPlug self)’
    In the expression:
      liftM toNativeWindowId
      $ (\ (Plug arg1)
           -> withForeignPtr arg1 $ \ argPtr1 -> gtk_plug_get_id argPtr1)
          (toPlug self)
Failed to install gtk-0.13.9
cabal: Error: some packages failed to install:
gtk-0.13.9 failed during the building phase. The exception was:
ExitFailure 1

To install this package, you need "gtk2hsC2hs" and the type errors are in .chs files, which presumably are generated from the gtk2hsC2hs tool. Is this a known problem with gtk2hsC2hs? Has anyone else been able to build this package? Anyone know of a solution?

I'm on Mac OS X Yosemite (10.10.4)

$ gtk2hsC2hs --version
C->Haskell Compiler, version 0.13.13 (gtk2hs branch) "Bin IO", 27 May 2012

$ cabal --version
cabal-install version 1.22.6.0
using version 1.22.4.0 of the Cabal library 

I've done a cabal update, so all my packages appear to be up to date. I've also tried building some of the older versions available from hackage, but I'm getting the same errors.

Edit

The errors in the generated files, seem to all deal with the FFI imports that are getting generated by gtk2hsC2hs. At the bottom of the file, I'm getting

foreign import ccall unsafe "gtk_plug_new"
  gtk_plug_new :: ((Ptr ()) -> (IO (Ptr Widget)))

It seems to consistently mix up Ptr() with Maybe DrawWindow. So is the generated type Ptr() incorrect, or is the usage of it incorrect?


Source: (StackOverflow)

What does g_signal_connect_swapped() do?

According to GObject reference

g_signal_connect_swapped(instance, detailed_signal, c_handler, data); connects a GCallback function to a signal for a particular object. The instance on which the signal is emitted and data will be swapped when calling the handler.

I don't quite get what this means. Does this mean that the data will point to the object pointed to byinstance and instance will point to the object that was pointed to by data or am I making a mistake here?

If former is the case then what is the logic behind this?


Source: (StackOverflow)

How to install gtk development dependencies on Ubuntu?

I have the code from GTK tutorial in base.c.

I am working on Ubuntu and when I compile using

$ gcc base.c -o base `pkg-config --cflags --libs gtk+-2.0` 

I get the following error

Package gtk+-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtk+-2.0.pc' to the PKG_CONFIG_PATH environment variable
No package 'gtk+-2.0' found
base.c:1:20: fatal error: gtk/gtk.h: No such file or directory compilation terminated.

Being new to linux, can someone help me in setting up the environment so that I can compile/run the program successfully?


Source: (StackOverflow)

GTK implementation of MessageBox

I have been trying to implement Win32's MessageBox using GTK. The app using SDL/OpenGL, so this isn't a GTK app.

I handle the initialisation (gtk_init) sort of stuff inside the MessageBox function as follows:

int MessageBox(HWND hwnd, const char* text, const char* caption, UINT type)
{
    GtkWidget *window = NULL;
    GtkWidget *dialog = NULL;

    gtk_init(&gtkArgc, &gtkArgv);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(delete_event), NULL);
    g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(destroy), NULL);
    // gcallback calls gtk_main_quit()
    gtk_init_add((GtkFunction)gcallback, NULL);

    if (type & MB_YESNO) {
        dialog = gtk_message_dialog_new(GTK_WINDOW(window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, text);
    } else {
        dialog = gtk_message_dialog_new(GTK_WINDOW(window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, text);
    }

    gtk_window_set_title(GTK_WINDOW(dialog), caption);
    gint result = gtk_dialog_run(GTK_DIALOG(dialog));

    gtk_main();

    gtk_widget_destroy(dialog);

    if (type & MB_YESNO) {
        switch (result) {
        default:
        case GTK_RESPONSE_DELETE_EVENT:
        case GTK_RESPONSE_NO:
            return IDNO;
            break;
        case GTK_RESPONSE_YES:
            return IDYES;
            break;
        }
    }

    return IDOK;
} 

Now, I am by no means an experienced GTK programmer, and I realise that I'm probably doing something(s) horribly wrong.

However, my problem is that the last dialog popped up with this function stays around until the process exits. Any ideas?


Source: (StackOverflow)

Why use glib functions?

While programming in C and GTK+, why is it "better" to use g_strdup_printf, g_free, g_strcmp0 etc... and fellow glib functions?


Source: (StackOverflow)

Vala (C#-like language) compiles to C?

I'm a C# developer who stumbled across a new programming language for linux called vala. It has almost exactly the same syntax as C#, which is awesome. I never really was a big fan of Mono. This allows programmers to write GTK+ apps in a C# style language. My question is: Does vala get compiled into C?


Source: (StackOverflow)

Adding a slider to AppIndicator (Ubuntu 11.04)

I'm trying to add a slider to an AppIndicator similar to what the Sound Menu has.

I've looked through the code of the Sound Menu and found that I should be using libido-0.1.

Here's what I have so far:

indicator_menu = gtk_menu_new();
ido_slider_widget = ido_scale_menu_item_new_with_range("BRIGHTNESS", IDO_RANGE_STYLE_DEFAULT,  0, 0, 100, 1);
ido_scale_menu_item_set_primary_label(IDO_SCALE_MENU_ITEM(ido_slider_widget), "BRIGHTNESS");
ido_scale_menu_item_set_style(IDO_SCALE_MENU_ITEM(ido_slider_widget), IDO_SCALE_MENU_ITEM_STYLE_LABEL);
ido_scale_menu_item_set_primary_label(IDO_SCALE_MENU_ITEM(ido_slider_widget), " - ");
ido_scale_menu_item_set_secondary_label(IDO_SCALE_MENU_ITEM(ido_slider_widget), " + ");

GtkMenuItem *menu_slider_item = GTK_MENU_ITEM(ido_slider_widget);

gtk_menu_append(indicator_menu, GTK_WIDGET(menu_slider_item));
gtk_menu_append(indicator_menu, gtk_menu_item_new_with_label("dfdsfds"));

gtk_widget_show_all(indicator_menu);
gtk_widget_show_all(ido_slider_widget);

app_indicator_set_menu(indicator, GTK_MENU(indicator_menu));

All I see is a '-' symbol in the menu, how do I fix this?


Source: (StackOverflow)

Gigantic Tabs in Eclipse on Ubuntu

EDIT: For anyone coming to this question through searching, you can install a Gnome Theme called Clearlooks Compact to shorten your tabs in Eclipse. This will free up a lot of screen space. You can also check out the answer below to learn how to make the tabs more horizontally compact.


Short version: How do I make a short version of Eclipse's tabs & toolbars in Ubuntu?

I've been looking around for a fix to this on Google, but to no avail. With any GTK theme, I still have this same issue and it's very, very annoying--to the point where I've stopped using Eclipse in favor of gEdit. However, after running pylint from a terminal too. many. times. I've decided I need to find a solution to this issues with Eclipse so I can have PyDev back. Here's what the tabs look like:

alt text

As you can see, not only are the tabs exaggerated, but the toolbar is, too: so is the toolbar on the bottom; so are the tabs in the bottom pane. Overall, it's eating up a lot of screen space, which is a hard item to come by on a 17" screen. Any suggestions/fixes?


Source: (StackOverflow)

GTK+ or Qt under Windows

I was wondering which one should I consider if I need the software to be used on both platforms, WIN and Linux and why?


Source: (StackOverflow)