Add Basic framework for Bayesian editor dialog

This commit is contained in:
Robert Fewell 2015-11-15 12:56:57 +00:00 committed by John Ralls
parent 079c0c311f
commit 2e4c957d00
8 changed files with 555 additions and 0 deletions

View File

@ -28,6 +28,7 @@ libgnc_gnome_la_SOURCES = \
assistant-hierarchy.c \
assistant-loan.c \
assistant-stock-split.c \
dialog-bayes-editor.c \
dialog-commodities.c \
dialog-fincalc.c \
dialog-find-transactions.c \
@ -81,6 +82,7 @@ noinst_HEADERS = \
assistant-hierarchy.h \
assistant-loan.h \
assistant-stock-split.h \
dialog-bayes-editor.h \
dialog-fincalc.h \
dialog-find-transactions.h \
dialog-find-transactions2.h \

View File

@ -0,0 +1,246 @@
/********************************************************************\
* dialog-bayes-editor.c -- Bayesian and Non Bayesian editor dialog *
* Copyright (C) 2015 Robert Fewell *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
\********************************************************************/
#include "config.h"
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include "dialog-bayes-editor.h"
#include "dialog-utils.h"
#include "gnc-component-manager.h"
#include "gnc-session.h"
#include "gnc-ui-util.h"
#include "qofinstance-p.h"
#define DIALOG_BAYES_CM_CLASS "dialog-bayes-edit"
#define GNC_PREFS_GROUP "dialogs.bayes-editor"
#define IMAP_FRAME_BAYES "import-map-bayes"
#define IMAP_FRAME "import-map"
#define IMAP_FRAME_DESC "desc"
#define IMAP_FRAME_MEMO "memo"
#define IMAP_FRAME_CSV "csv-account-map"
/** Enumeration for the liststore */
enum GncBayesColumn {SOURCE_FULL_ACC, SOURCE_ACCOUNT, BASED_ON, MATCH_STRING,
MAP_FULL_ACC, MAP_ACCOUNT, KVP_PATH, PROBABILITY};
typedef enum
{
BAYES,
NBAYES,
ONLINE
}GncListType;
typedef struct
{
GtkWidget *dialog;
QofSession *session;
GtkWidget *store;
GtkWidget *view;
GncListType type;
GtkWidget *radio_bayes;
GtkWidget *radio_nbayes;
GtkWidget *radio_online;
} BayesDialog;
struct kvp_info
{
GtkTreeModel *store;
Account *source_account;
Account *map_account;
const gchar *based_on;
const gchar *match_string;
const gchar *kvp_path_head;
const gchar *kvp_path;
const gchar *probability;
};
/* This static indicates the debugging module that this .o belongs to. */
static QofLogModule log_module = GNC_MOD_GUI;
void gnc_bayes_dialog_window_destroy_cb (GtkWidget *object, gpointer data);
void gnc_bayes_dialog_close_cb (GtkDialog *dialog, gpointer data);
void gnc_bayes_dialog_response_cb (GtkDialog *dialog, gint response_id, gpointer data);
void
gnc_bayes_dialog_window_destroy_cb (GtkWidget *object, gpointer data)
{
BayesDialog *bayes_dialog = data;
ENTER(" ");
gnc_unregister_gui_component_by_data (DIALOG_BAYES_CM_CLASS, bayes_dialog);
if (bayes_dialog->dialog)
{
gtk_widget_destroy(bayes_dialog->dialog);
bayes_dialog->dialog = NULL;
}
g_free (bayes_dialog);
LEAVE(" ");
}
void
gnc_bayes_dialog_close_cb (GtkDialog *dialog, gpointer data)
{
BayesDialog *bayes_dialog = data;
ENTER(" ");
gnc_close_gui_component_by_data (DIALOG_BAYES_CM_CLASS, bayes_dialog);
LEAVE(" ");
}
void
gnc_bayes_dialog_response_cb (GtkDialog *dialog, gint response_id, gpointer data)
{
BayesDialog *bayes_dialog = data;
switch (response_id)
{
case GTK_RESPONSE_CLOSE:
default:
gnc_close_gui_component_by_data (DIALOG_BAYES_CM_CLASS, bayes_dialog);
return;
}
}
static void
gnc_bayes_dialog_create (GtkWidget *parent, BayesDialog *bayes_dialog)
{
GtkWidget *dialog;
GtkBuilder *builder;
GtkTreeSelection *selection;
ENTER(" ");
builder = gtk_builder_new();
gnc_builder_add_from_file (builder, "dialog-bayes-editor.glade", "list-view");
gnc_builder_add_from_file (builder, "dialog-bayes-editor.glade", "Bayesian Dialog");
dialog = GTK_WIDGET(gtk_builder_get_object (builder, "Bayesian Dialog"));
bayes_dialog->dialog = dialog;
bayes_dialog->session = gnc_get_current_session();
bayes_dialog->type = BAYES;
/* parent */
if (parent != NULL)
gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(parent));
/* Connect the radio buttons...*/
bayes_dialog->radio_bayes = GTK_WIDGET(gtk_builder_get_object (builder, "radio-bayes"));
bayes_dialog->radio_nbayes = GTK_WIDGET(gtk_builder_get_object (builder, "radio-nbayes"));
bayes_dialog->radio_online = GTK_WIDGET(gtk_builder_get_object (builder, "radio-online"));
bayes_dialog->view = GTK_WIDGET(gtk_builder_get_object (builder, "treeview"));
/* Enable alternative line colors */
gtk_tree_view_set_rules_hint (GTK_TREE_VIEW(bayes_dialog->view),TRUE);
/* default to 'close' button */
gtk_dialog_set_default_response (GTK_DIALOG(dialog), GTK_RESPONSE_CLOSE);
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(bayes_dialog->view));
gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, bayes_dialog);
g_object_unref (G_OBJECT(builder));
gnc_restore_window_size (GNC_PREFS_GROUP, GTK_WINDOW(bayes_dialog->dialog));
LEAVE(" ");
}
static void
close_handler (gpointer user_data)
{
BayesDialog *bayes_dialog = user_data;
ENTER(" ");
gnc_save_window_size (GNC_PREFS_GROUP, GTK_WINDOW(bayes_dialog->dialog));
gtk_widget_destroy (GTK_WIDGET(bayes_dialog->dialog));
LEAVE(" ");
}
static void
refresh_handler (GHashTable *changes, gpointer user_data)
{
ENTER(" ");
LEAVE(" ");
}
static gboolean
show_handler (const char *klass, gint component_id,
gpointer user_data, gpointer iter_data)
{
BayesDialog *bayes_dialog = user_data;
ENTER(" ");
if (!bayes_dialog)
{
LEAVE("No data strucure");
return(FALSE);
}
gtk_window_present (GTK_WINDOW(bayes_dialog->dialog));
LEAVE(" ");
return(TRUE);
}
/********************************************************************\
* gnc_bayes_dialog *
* opens a window showing all Bayesian and Non-Bayesian information *
* *
* Args: parent - the parent of the window to be created *
* Return: nothing *
\********************************************************************/
void
gnc_bayes_dialog (GtkWidget *parent)
{
BayesDialog *bayes_dialog;
gint component_id;
ENTER(" ");
if (gnc_forall_gui_components (DIALOG_BAYES_CM_CLASS, show_handler, NULL))
{
LEAVE("Existing dialog raised");
return;
}
bayes_dialog = g_new0 (BayesDialog, 1);
gnc_bayes_dialog_create (parent, bayes_dialog);
component_id = gnc_register_gui_component (DIALOG_BAYES_CM_CLASS,
refresh_handler, close_handler,
bayes_dialog);
gnc_gui_component_set_session (component_id, bayes_dialog->session);
gtk_widget_show (bayes_dialog->dialog);
LEAVE(" ");
}

View File

@ -0,0 +1,28 @@
/********************************************************************\
* dialog-bayes-editor.h -- Bayesian and Non Bayesian editor dialog *
* Copyright (C) 2015 Robert Fewell *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
\********************************************************************/
#ifndef DIALOG_BAYES_EDITOR_H
#define DIALOG_BAYES_EDITOR_H
void gnc_bayes_dialog (GtkWidget *parent);
#endif

View File

@ -39,6 +39,7 @@
#include "gnc-plugin-basic-commands.h"
#include "gnc-ui-util.h"
#include "dialog-bayes-editor.h"
#include "dialog-book-close.h"
#include "dialog-file-access.h"
#include "dialog-fincalc.h"
@ -88,6 +89,7 @@ static void gnc_main_window_cmd_tools_financial_calculator (GtkAction *action, G
static void gnc_main_window_cmd_tools_close_book (GtkAction *action, GncMainWindowActionData *data);
static void gnc_main_window_cmd_tools_find_transactions (GtkAction *action, GncMainWindowActionData *data);
static void gnc_main_window_cmd_tools_price_editor (GtkAction *action, GncMainWindowActionData *data);
static void gnc_main_window_cmd_tools_bayes_editor (GtkAction *action, GncMainWindowActionData *data);
static void gnc_main_window_cmd_tools_commodity_editor (GtkAction *action, GncMainWindowActionData *data);
static void gnc_main_window_cmd_help_totd (GtkAction *action, GncMainWindowActionData *data);
@ -201,6 +203,11 @@ static GtkActionEntry gnc_plugin_actions [] =
N_("Close the Book at the end of the Period"),
G_CALLBACK (gnc_main_window_cmd_tools_close_book)
},
{
"ToolsBayesEditorAction", NULL, N_("_Bayesian Editor"), NULL,
N_("View and edit Bayesian and Non Bayesian values"),
G_CALLBACK (gnc_main_window_cmd_tools_bayes_editor)
},
/* Help menu */
@ -602,6 +609,14 @@ gnc_main_window_cmd_actions_close_books (GtkAction *action, GncMainWindowActionD
}
#endif /* CLOSE_BOOKS_ACTUALLY_WORKS */
static void
gnc_main_window_cmd_tools_bayes_editor (GtkAction *action, GncMainWindowActionData *data)
{
gnc_set_busy_cursor(NULL, TRUE);
gnc_bayes_dialog (NULL);
gnc_unset_busy_cursor(NULL);
}
static void
gnc_main_window_cmd_tools_price_editor (GtkAction *action, GncMainWindowActionData *data)
{

View File

@ -1,6 +1,7 @@
<schemalist gettext-domain="@GETTEXT_PACKAGE@">
<schema id="org.gnucash.dialogs" path="/org/gnucash/dialogs/">
<child name="account" schema="org.gnucash.dialogs.account"/>
<child name="bayes-editor" schema="org.gnucash.dialogs.bayes-editor"/>
<child name="preferences" schema="org.gnucash.dialogs.preferences"/>
<child name="price-editor" schema="org.gnucash.dialogs.price-editor"/>
<child name="pricedb-editor" schema="org.gnucash.dialogs.pricedb-editor"/>
@ -30,6 +31,16 @@
</key>
</schema>
<schema id="org.gnucash.dialogs.bayes-editor" path="/org/gnucash/dialogs/bayes-editor/">
<key type="(iiii)" name="last-geometry">
<default>(-1,-1,-1,-1)</default>
<summary>Last window position and size</summary>
<description>This setting describes the size and position of the window when it was last closed.
The numbers are the X and Y coordinates of the top left corner of the window
followed by the width and height of the window.</description>
</key>
</schema>
<schema id="org.gnucash.dialogs.preferences" path="/org/gnucash/dialogs/preferences/">
<key name="last-geometry" type="(iiii)">
<default>(-1,-1,-1,-1)</default>

View File

@ -4,6 +4,7 @@ gtkbuilder_DATA = \
assistant-hierarchy.glade \
assistant-loan.glade \
assistant-stock-split.glade \
dialog-bayes-editor.glade \
dialog-commodities.glade \
dialog-fincalc.glade \
dialog-lot-viewer.glade \

View File

@ -0,0 +1,251 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="2.16"/>
<!-- interface-naming-policy toplevel-contextual -->
<object class="GtkListStore" id="list-view">
<columns>
<!-- column-name source_account_name -->
<column type="gchararray"/>
<!-- column-name source_account -->
<column type="gpointer"/>
<!-- column-name based_on -->
<column type="gchararray"/>
<!-- column-name match_string -->
<column type="gchararray"/>
<!-- column-name map_account_name -->
<column type="gchararray"/>
<!-- column-name map_account -->
<column type="gpointer"/>
<!-- column-name kvp_path -->
<column type="gchararray"/>
<!-- column-name probability -->
<column type="gchararray"/>
</columns>
</object>
<object class="GtkDialog" id="Bayesian Dialog">
<property name="can_focus">False</property>
<property name="border_width">6</property>
<property name="title" translatable="yes">Bayesian Editor</property>
<property name="modal">True</property>
<property name="default_width">600</property>
<property name="default_height">400</property>
<property name="type_hint">dialog</property>
<signal name="destroy" handler="gnc_bayes_dialog_window_destroy_cb" swapped="no"/>
<signal name="response" handler="gnc_bayes_dialog_response_cb" swapped="no"/>
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox2">
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">What type of data to display?</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child internal-child="action_area">
<object class="GtkHButtonBox" id="dialog-action_area1">
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="remove_button">
<property name="label">gtk-remove</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="close_button">
<property name="label">gtk-close</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="has_default">True</property>
<property name="receives_default">False</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="hbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">5</property>
<child>
<object class="GtkRadioButton" id="radio-bayes">
<property name="label" translatable="yes">Bayesian</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkRadioButton" id="radio-nbayes">
<property name="label" translatable="yes">Non-Bayesian</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
<property name="group">radio-bayes</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkRadioButton" id="radio-online">
<property name="label" translatable="yes">Online ID</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
<property name="group">radio-bayes</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow2">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">automatic</property>
<property name="vscrollbar_policy">automatic</property>
<child>
<object class="GtkTreeView" id="treeview">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">list-view</property>
<child>
<object class="GtkTreeViewColumn" id="source_account_name">
<property name="resizable">True</property>
<property name="title" translatable="yes">Source Account Name</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext3"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="based_on">
<property name="resizable">True</property>
<property name="title" translatable="yes">Based On</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext4"/>
<attributes>
<attribute name="text">2</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="match">
<property name="resizable">True</property>
<property name="title" translatable="yes">Match String</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext1"/>
<attributes>
<attribute name="text">3</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="map_account_name">
<property name="resizable">True</property>
<property name="title" translatable="yes">Map Account Name</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext2"/>
<attributes>
<attribute name="text">4</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="probability">
<property name="resizable">True</property>
<property name="title" translatable="yes">Probability Value</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext5"/>
<attributes>
<attribute name="text">7</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="ypad">5</property>
<property name="label" translatable="yes">You may select multiple rows and then press remove button...</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">4</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="-10">remove_button</action-widget>
<action-widget response="-6">close_button</action-widget>
</action-widgets>
</object>
</interface>

View File

@ -56,6 +56,7 @@
<menuitem name="ToolsCommodityEditor" action="ToolsCommodityEditorAction"/>
<menuitem name="ToolsFinancialCalculator" action="ToolsFinancialCalculatorAction"/>
<menuitem name="ToolsBookClose" action="ToolsBookCloseAction"/>
<menuitem name="ToolsBayesEditor" action="ToolsBayesEditorAction"/>
</placeholder>
</menu>