From 59b79b657571950f3bd9c4b4892c8765f626092f Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Sun, 29 Jul 2012 11:27:50 -0400 Subject: [PATCH] ocarina: Begin switching to GtkBuilder for the UI I feel that hand-written UI code is slowing me down, so I'm going to switch to using glade / GtkBuilder to manage the UI as much as possible. So far, I create, show, and destroy a window. Signed-off-by: Bryan Schumaker --- Sconstruct | 2 +- ocarina/Sconscript | 4 ++- ocarina/ocarina.cpp | 60 ++++++++++++++++++++++++++++++--------------- xml/Sconscript | 17 +++++++++++++ xml/ocarina.xml | 11 +++++++++ 5 files changed, 72 insertions(+), 22 deletions(-) create mode 100644 xml/Sconscript create mode 100644 xml/ocarina.xml diff --git a/Sconstruct b/Sconstruct index c39e60cd..4139c588 100644 --- a/Sconstruct +++ b/Sconstruct @@ -42,7 +42,7 @@ def symlink(target, source, env): SConscript(['include/Sconscript']) ocarina = env.Program('bin/ocarina-player', directory(["libsaria", "ocarina"])) oc_link = env.Command("ocarina.bin", "bin/ocarina-player", symlink) -oc_other = app_directory("ocarina", ["scripts", "images"]) +oc_other = app_directory("ocarina", ["scripts", "images", "xml"]) Default([ocarina, oc_link, oc_other]) env.Alias("ocarina", [ocarina, oc_link, oc_other]) diff --git a/ocarina/Sconscript b/ocarina/Sconscript index 0e818fd2..925fa54e 100644 --- a/ocarina/Sconscript +++ b/ocarina/Sconscript @@ -2,6 +2,8 @@ import config config.env.ParseConfig('pkg-config --cflags --libs gtk+-2.0') +config.env.ParseConfig('pkg-config --cflags --libs gmodule-export-2.0') -files = config.get_cpp_files() +#files = config.get_cpp_files() +files = ["ocarina/ocarina.cpp"] Return('files') diff --git a/ocarina/ocarina.cpp b/ocarina/ocarina.cpp index 04bad737..151d04bb 100644 --- a/ocarina/ocarina.cpp +++ b/ocarina/ocarina.cpp @@ -1,15 +1,21 @@ // Copyright (c) 2011 Bryan Schumaker #include #include +#include + +#include + +/*#include #include #include #include #include -#include +#include */ static string lib_path; -static bool using_idle = false; +static GtkBuilder *builder; +//static bool using_idle = false; static void find_exe_path(string &res) { @@ -41,7 +47,7 @@ static void find_lib_path() println("Lib directory? %s", lib_path.c_str()); } -static gboolean idle(gpointer data) +/*static gboolean idle(gpointer data) { libsaria::idle::run_task(); using_idle = (libsaria::idle::size() != 0); @@ -59,41 +65,55 @@ static void idle_add() g_idle_add(idle, NULL); using_idle = true; } -} +} */ -namespace ocarina +string lib_file(string path) { - - string lib_file(string path) - { - string res = lib_path + "/" + path; - println("Expanding to path: " + res); - return res; - } - - void quit() - { - gtk_main_quit(); - } - + string res = lib_path + "/" + path; + println("Expanding to path: " + res); + return res; } +/* static gboolean timeout_poll(gpointer data) { idle_add(); ocarina::body::set_now_playing(); ocarina::body::update_controls(); return TRUE; +}*/ + +GtkWidget *get_widget(const string &name) +{ + GtkWidget *widget = GTK_WIDGET(gtk_builder_get_object(builder, name.c_str())); + if (!widget) + println(name + " is not a widget!"); + return widget; +} + +void connect_signal(const string &name, const string &signal, GCallback func, void *data) +{ + GtkWidget *widget = get_widget(name); + if (widget) + g_signal_connect(widget, signal.c_str(), func, data); } static void init(int argc, char **argv) { gtk_init(&argc, &argv); - ocarina::window::init(); + + builder = gtk_builder_new(); + gtk_builder_add_from_file(builder, lib_file("ocarina.xml").c_str(), NULL); + + /* Connect signals to named widgets */ + connect_signal("MainWindow", "destroy", gtk_main_quit, NULL); + + /* Show any widgets that need showing */ +/* ocarina::window::init(); ocarina::body::init(); ocarina::playlist::init(); ocarina::init_pipe(); - gtk_timeout_add(100, timeout_poll, NULL); + gtk_timeout_add(100, timeout_poll, NULL);*/ } int main(int argc, char **argv) diff --git a/xml/Sconscript b/xml/Sconscript new file mode 100644 index 00000000..9266a099 --- /dev/null +++ b/xml/Sconscript @@ -0,0 +1,17 @@ +#!/usr/bin/python +import shutil +from config import * + +lib = "../lib/" + application + "/%s" + +def copy_xml(target, source, env): + dst = str(target[0].rfile()) + src = str(source[0].rfile()) + shutil.copy(src, dst) + +files = [] +if application == "ocarina": + dst = lib % "ocarina.xml" + files.append(AlwaysBuild(env.Command(dst, "ocarina.xml", copy_xml))) + +Return('files') diff --git a/xml/ocarina.xml b/xml/ocarina.xml new file mode 100644 index 00000000..134b3d5a --- /dev/null +++ b/xml/ocarina.xml @@ -0,0 +1,11 @@ + + + + + True + False + + + + +