[giv] Added giv settings.
- From: Dov Grobgeld <dov src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [giv] Added giv settings.
- Date: Wed, 13 Apr 2011 21:06:27 +0000 (UTC)
commit be2d3af248848e340a8e9e44bf1d3da6e785a8fb
Author: Dov Grobgeld <dov grobgeld gmail com>
Date: Thu Apr 14 00:05:58 2011 +0300
Added giv settings.
.gitignore | 9 +++
ChangeLog | 12 ++++
configure.in | 2 +-
doc/giv-calib-and-measure.png | Bin 0 -> 50395 bytes
giv.wine.nsi.in | 2 +
src/SConscript | 6 ++-
src/giv-settings-editor.gob | 146 +++++++++++++++++++++++++++++++++++++++++
src/giv-settings.gob | 81 +++++++++++++++++++++++
src/giv-win.gob | 83 ++++++++++++++++++++++-
9 files changed, 336 insertions(+), 5 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index dd4a26a..4528758 100644
--- a/.gitignore
+++ b/.gitignore
@@ -39,3 +39,12 @@ src/gtkimageviewer/gtk-image-viewer.h
src/giv
src/plugins/dcmtk/dcmdata/libsrc/mkdictbi
config.h
+/src/giv-settings-editor-private.h
+/src/giv-settings-editor.cc
+/src/giv-settings-editor.h
+/src/giv-settings-private.h
+/src/giv-settings.cc
+/src/giv-settings.h
+/giv.wine.nsi
+*.gz
+/doc/perl-toc.html
diff --git a/ChangeLog b/ChangeLog
index aca7e8f..388ae2b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2011-04-14 Dov Grobgeld <dov grobgeld gmail com>
+
+ * giv.wine.nsi.in : Added gtkrc for more windows look.
+
+2011-04-13 Dov Grobgeld <dov grobgeld gmail com>
+
+ * giv-settings.gob: Created settings for only seeing files of
+ the same type.
+
+ * giv-settings.gob, giv-settings-editor.gob, giv-win.gob :
+ Created persistant settings and an editor.
+
2011-04-12 Dov Grobgeld <dov grobgeld gmail com>
* giv-win.gob, giv-contrast.gob, giv-histo.gob : Moving over a gray level image updates the pointer triangle in the histogram.
diff --git a/configure.in b/configure.in
index 4e8db08..c28aedf 100644
--- a/configure.in
+++ b/configure.in
@@ -5,7 +5,7 @@ AM_CONFIG_HEADER(config.h)
PACKAGE=givwidget
GIVWIDGET_API_VERSION=2.0
-AM_INIT_AUTOMAKE(giv, 0.9.19)
+AM_INIT_AUTOMAKE(giv, 0.9.19beta3)
dnl Use libtool to get shared libraries
LT_PREREQ
diff --git a/doc/giv-calib-and-measure.png b/doc/giv-calib-and-measure.png
new file mode 100644
index 0000000..4837279
Binary files /dev/null and b/doc/giv-calib-and-measure.png differ
diff --git a/giv.wine.nsi.in b/giv.wine.nsi.in
index f411b67..35058f2 100644
--- a/giv.wine.nsi.in
+++ b/giv.wine.nsi.in
@@ -65,6 +65,8 @@ SetOutPath $INSTDIR\etc
File /r \usr\i686-pc-mingw32\sys-root\mingw\etc\gtk-2.0
File /r \usr\i686-pc-mingw32\sys-root\mingw\etc\fonts
File /r \usr\i686-pc-mingw32\sys-root\mingw\etc\pango
+SetOutPath $INSTDIR\etc\gtk-2.0
+File \usr\i686-pc-mingw32\sys-root\mingw\share\themes\MS-Windows\gtk-2.0\gtkrc
# Plugins
SetOutPath $INSTDIR\plugins
diff --git a/src/SConscript b/src/SConscript
index 7e94d8f..22496cb 100644
--- a/src/SConscript
+++ b/src/SConscript
@@ -63,6 +63,8 @@ src_giv_widget = ["giv-widget.cc",
"giv-backstore.cc",
"giv-markup.cc",
"giv_agg_arrowhead.cc",
+ "giv-settings.cc",
+ "giv-settings-editor.cc"
]
env.Library("giv-widget",
@@ -96,7 +98,9 @@ for gob in ("giv-win",
"giv-widget",
"giv-contrast",
"giv-histo",
- "giv-calibrate-dialog"
+ "giv-calibrate-dialog",
+ "giv-settings",
+ "giv-settings-editor",
) :
env.Command([gob + ".cc",
gob + ".h",
diff --git a/src/giv-settings-editor.gob b/src/giv-settings-editor.gob
new file mode 100644
index 0000000..f6de51c
--- /dev/null
+++ b/src/giv-settings-editor.gob
@@ -0,0 +1,146 @@
+//======================================================================
+// giv-settings-editor.gob - A settings editor for giv
+//
+// Dov Grobgeld <dov grobgeld gmail com>
+// Thu Jun 4 15:12:50 2009
+//----------------------------------------------------------------------
+requires 2.0.0
+
+%headertop{
+#include "giv-settings.h"
+#include <gtk/gtk.h>
+#include <stdarg.h>
+#include <stdlib.h>
+%}
+
+%{
+static GtkWidget *hig_like_frame_new(const gchar *label);
+static GtkWidget *entry_new_from_double(double init_val);
+static GtkWidget *entry_new_from_string(const gchar *text);
+static GtkWidget *check_button_new_from_bool(bool init_state);
+static GtkWidget *label_left_new(const gchar *label);
+
+%}
+
+%privateheader{
+%}
+
+class Giv:Settings:Editor from Gtk:Dialog
+{
+ private GObject *giv_settings = NULL destroy { if (giv_settings) g_object_unref(giv_settings); };
+ private GtkWidget *w_button_same_file_type = NULL;
+
+ public GtkWidget*
+ new (GivSettings *giv_settings)
+ {
+ GivSettingsEditor *self = GET_NEW;
+
+ selfp->giv_settings = G_OBJECT(giv_settings);
+ g_object_ref(selfp->giv_settings);
+
+ // Use HIG recommendation using frames without border.
+ GtkWidget *w_frame = hig_like_frame_new("File Browsing");
+
+ gtk_box_pack_start(GTK_BOX(GTK_DIALOG(self)->vbox),
+ w_frame, FALSE, FALSE, 0);
+
+ GtkWidget *w_table = gtk_table_new(8,8,FALSE);
+ gtk_box_pack_start(GTK_BOX(GTK_DIALOG(self)->vbox),
+ w_table, FALSE, FALSE, 0);
+
+ // Whether to hide names
+ int row = 0;
+ gtk_table_attach(GTK_TABLE(w_table),
+ label_left_new("Same type?"),
+ 1, 2,
+ row, row+1,
+ GtkAttachOptions(GTK_FILL|GTK_EXPAND),
+ GtkAttachOptions(0),
+ 0,0);
+
+ selfp->w_button_same_file_type = check_button_new_from_bool(giv_settings->do_same_filetype_on_next);
+ g_object_set(selfp->w_button_same_file_type,
+ "tooltip-markup",
+ "When moving to next and previous file, only visit files of the same file type",
+ NULL);
+
+ gtk_table_attach(GTK_TABLE(w_table),
+ selfp->w_button_same_file_type,
+ 2, 3,
+ row, row+1,
+ GtkAttachOptions(GTK_FILL|GTK_EXPAND),
+ GtkAttachOptions(0),
+ 0,0);
+
+ // Buttons
+ gtk_dialog_add_button(GTK_DIALOG(self),
+ GTK_STOCK_APPLY,
+ GTK_RESPONSE_APPLY);
+ gtk_dialog_add_button(GTK_DIALOG(self),
+ GTK_STOCK_CANCEL,
+ GTK_RESPONSE_CANCEL);
+ gtk_dialog_add_button(GTK_DIALOG(self),
+ GTK_STOCK_OK,
+ GTK_RESPONSE_ACCEPT);
+
+ return GTK_WIDGET(self);
+ }
+
+ public bool get_bool(self,
+ const char *label)
+ {
+ GtkWidget *w_toggle = GTK_WIDGET(g_object_get_data(G_OBJECT(self), label));
+ if (!w_toggle)
+ return FALSE;
+ int state = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w_toggle));
+ return state;
+ }
+
+ public void apply(self)
+ {
+ GIV_SETTINGS(selfp->giv_settings)->do_same_filetype_on_next
+ = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(selfp->w_button_same_file_type));
+ }
+
+}
+
+%{
+static GtkWidget *hig_like_frame_new(const gchar *label)
+{
+ GtkWidget *w_frame = gtk_frame_new(NULL);
+ GtkWidget *w_label = gtk_label_new(NULL);
+ gchar*markup = g_strdup_printf("<b>%s</b>", label);
+
+ gtk_label_set_markup(GTK_LABEL(w_label),
+ markup);
+ g_free(markup);
+ gtk_frame_set_label_widget(GTK_FRAME(w_frame),
+ w_label);
+ // Follow the HIG recommendation
+ gtk_frame_set_shadow_type(GTK_FRAME(w_frame), GTK_SHADOW_NONE);
+
+ return w_frame;
+}
+
+
+static GtkWidget *check_button_new_from_bool(bool init_state)
+{
+ GtkWidget *check_button = gtk_check_button_new();
+
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_button),
+ init_state);
+
+ return check_button;
+}
+
+static GtkWidget *label_left_new(const gchar *label)
+{
+ gchar *markup = g_strdup_printf("%s:", label);
+ GtkWidget *w_label = gtk_label_new(NULL);
+ gtk_label_set_markup(GTK_LABEL(w_label), markup);
+ g_free(markup);
+ gtk_misc_set_alignment(GTK_MISC(w_label), 0, 0.5);
+ return w_label;
+}
+
+%}
diff --git a/src/giv-settings.gob b/src/giv-settings.gob
new file mode 100644
index 0000000..bc3519d
--- /dev/null
+++ b/src/giv-settings.gob
@@ -0,0 +1,81 @@
+//======================================================================
+// giv-settings.gob - Settings for gob
+//
+// Dov Grobgeld <dov grobgeld gmail com>
+// Wed Apr 13 20:06:26 2011
+//----------------------------------------------------------------------
+
+requires 2.0.0
+
+%headertop{
+#include <glib.h>
+%}
+
+%{
+#include <glib/gstdio.h>
+%}
+
+class Giv:Settings from G:Object {
+ public gboolean do_same_filetype_on_next = FALSE;
+ private char *keyfile_path = NULL destroy { g_free(keyfile_path); };
+
+ public GObject *
+ new(const char *keyfile_path)
+ {
+ GivSettings *self = GIV_SETTINGS(GET_NEW);
+ GError *error = NULL;
+ selfp->keyfile_path = g_strdup(keyfile_path);
+
+ GKeyFile *keyfile = g_key_file_new();
+ GKeyFileFlags flags = GKeyFileFlags(0);
+
+ /* Load the GKeyFile from keyfile.conf or return. */
+ if (g_key_file_load_from_file (keyfile,
+ selfp->keyfile_path,
+ flags,
+ &error)) {
+ self->do_same_filetype_on_next = g_key_file_get_boolean(keyfile,
+ "settings",
+ "do_same_filetype_on_next",
+ NULL);
+ }
+ else
+ g_error_free(error);
+ g_key_file_free(keyfile);
+
+ return G_OBJECT(self);
+ }
+
+ public int
+ save_prefs(self)
+ {
+ GKeyFile *keyfile = g_key_file_new();
+ GError *error = NULL;
+
+ g_key_file_set_boolean(keyfile,
+ "settings",
+ "do_same_filetype_on_next",
+ self->do_same_filetype_on_next);
+
+ gchar *data = g_key_file_to_data(keyfile,NULL, NULL);
+ gchar *dirname = g_path_get_dirname(selfp->keyfile_path);
+ if (!g_file_test(dirname,
+ G_FILE_TEST_IS_DIR))
+ g_mkdir_with_parents(dirname, 0755);
+
+ if (g_file_test(dirname,
+ G_FILE_TEST_IS_DIR))
+ g_file_set_contents(selfp->keyfile_path,
+ data,
+ -1,
+ &error);
+ g_free(dirname);
+ g_free(data);
+
+ // Ignore errors
+ if (error) {
+ g_error_free(error);
+ }
+ }
+}
+
diff --git a/src/giv-win.gob b/src/giv-win.gob
index 467309d..5c1c9cd 100644
--- a/src/giv-win.gob
+++ b/src/giv-win.gob
@@ -46,6 +46,8 @@ requires 2.0.0
#include <sys/stat.h>
#include "givregex.h"
#include "giv-calibrate-dialog.h"
+#include "giv-settings.h"
+#include "giv-settings-editor.h"
using namespace std;
using namespace plis;
@@ -104,6 +106,7 @@ static void cb_menu_measure_distance (GtkAction *action, gpointer data);
static void cb_menu_calibrate (GtkAction *action, gpointer data);
static void cb_menu_quiver_zoom (GtkAction *action, gpointer data);
static void cb_menu_default (GtkAction *action, gpointer data);
+static void cb_menu_preferences (GtkAction *action, gpointer data);
static void cb_menu_new_window (GtkAction *action, gpointer data);
static void cb_menu_fill (GtkAction *action, gpointer data);
static void cb_menu_shrink_wrap (GtkAction *action, gpointer data);
@@ -304,7 +307,7 @@ static GtkActionEntry entries[] =
GTK_STOCK_PREFERENCES,
"_Preferences", NULL,
"Preferences",
- G_CALLBACK (cb_menu_default) },
+ G_CALLBACK (cb_menu_preferences) },
{ "FillAction",
NULL,
"_Fill", NULL,
@@ -409,6 +412,7 @@ static gchar *last_export_image_path = NULL;
%privateheader{
#include "giv-mark-tree-dialog.h"
#include "giv-contrast.h"
+#include "giv-settings.h"
#include "dovtk-lasso.h"
%}
@@ -426,6 +430,7 @@ class Giv:Win from Gtk:Window
private GtkWidget *w_balloon_window = NULL;
private GtkWidget *w_balloon_label = NULL;
private GtkWidget *w_scrolled_win;
+ private GtkWidget *w_preferences = NULL;
private GivImage *img_org = NULL
destroy {
if (img_org) {
@@ -509,6 +514,7 @@ class Giv:Win from Gtk:Window
private double pixelsize = 1;
private gchar *pixelsize_unit = NULL;
private double last_measure_distance_in_pixels = -1;
+ private GivSettings *giv_settings = NULL destroy { g_object_unref(giv_settings); };
public GtkWidget *
new (int argc, char *argv[])
@@ -581,6 +587,9 @@ class Giv:Win from Gtk:Window
selfp->filename_list = g_ptr_array_new();
selfp->pixelsize_unit = g_strdup("");
+ gchar *settings_file = g_strdup_printf("%s/.config/Giv/giv.conf", g_get_home_dir());
+ selfp->giv_settings = GIV_SETTINGS(giv_settings_new(settings_file));
+
gtk_window_set_resizable(GTK_WINDOW(self), true);
g_object_set(G_OBJECT(self),
"allow-shrink", TRUE,
@@ -1008,7 +1017,6 @@ class Giv:Win from Gtk:Window
selfp->format = g_strdup("%.1f");
else
selfp->format = g_strdup("%.4g");
- printf("selfp->format =%s\n", selfp->format);
selfp->img_is_mono = giv_check_img_for_mono(selfp->img_org);
@@ -1402,6 +1410,14 @@ class Giv:Win from Gtk:Window
selfp->pixelsize_unit
);
}
+
+ private const gchar *get_filetype_for_index(self,
+ int index)
+ {
+ GPtrArray *string_list = (GPtrArray*)g_ptr_array_index(selfp->filename_list, index);
+ gchar *filename0 = (gchar*)g_ptr_array_index(string_list, 0);
+ return g_strrstr(filename0, ".")+1;
+ }
}
%{
@@ -1555,8 +1571,21 @@ cb_key_press_event (GtkWidget * widget,
"filename_list.size() = %d\n",
selfp->filename_list.size());
#endif
+ // Repeat until we have same file type
+ const gchar *org_type = giv_win_get_filetype_for_index(self,selfp->filename_list_index);
+ int new_index = selfp->filename_list_index;
int s = selfp->filename_list->len;
- int new_index = (selfp->filename_list_index + s + index_delta) % s;
+ while(1) {
+ new_index = (new_index + s + index_delta) % s;
+ if (!selfp->giv_settings->do_same_filetype_on_next)
+ break;
+
+ const gchar *new_type = giv_win_get_filetype_for_index(self,new_index);
+ if (g_ascii_strcasecmp(org_type,new_type)!=0)
+ continue;
+ break;
+ }
+
if (selfp->idle_handle < 0) {
selfp->idle_index = new_index;
selfp->idle_handle = g_idle_add(cb_load_image_when_idle,
@@ -2040,6 +2069,52 @@ cb_menu_info_dialog (GtkAction *action, gpointer data)
return;
}
+static gint
+cb_preferences_response(GtkWidget *dialog,
+ gint response_id,
+ gpointer user_data)
+{
+ GivWin *self = GIV_WIN(user_data);
+
+ if (response_id == GTK_RESPONSE_APPLY
+ || response_id == GTK_RESPONSE_ACCEPT) {
+ giv_settings_editor_apply(GIV_SETTINGS_EDITOR(selfp->w_preferences));
+ giv_settings_save_prefs(GIV_SETTINGS(selfp->giv_settings));
+ }
+
+ if (response_id == GTK_RESPONSE_CANCEL
+ || response_id == GTK_RESPONSE_ACCEPT) {
+ gtk_widget_destroy (selfp->w_preferences);
+ selfp->w_preferences = NULL;
+ }
+
+ return 0;
+}
+
+static void
+cb_menu_preferences (GtkAction *action, gpointer data)
+{
+ GivWin *self = GIV_WIN(data);
+
+ if (selfp->w_preferences)
+ return;
+
+ selfp->w_preferences = giv_settings_editor_new(GIV_SETTINGS(selfp->giv_settings));
+
+ g_signal_connect (selfp->w_preferences,
+ "response",
+ G_CALLBACK (cb_preferences_response),
+ self);
+#if 0
+ g_object_add_weak_pointer(G_OBJECT(selfp->w_preferences),
+ (void**)selfp->w_preferences);
+#endif
+
+ gtk_widget_show_all(selfp->w_preferences);
+
+ return;
+}
+
void
cb_menu_quiver_zoom (GtkAction *action, gpointer data)
{
@@ -2128,6 +2203,7 @@ cb_menu_calibrate (GtkAction *action, gpointer data)
return;
}
+#if 0
void
cb_menu_default (GtkAction *action, gpointer data)
{
@@ -2136,6 +2212,7 @@ cb_menu_default (GtkAction *action, gpointer data)
return;
}
+#endif
static void
cb_menu_fill (GtkAction *action, gpointer data)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]