genius r657 - in trunk: . src
- From: jirka svn gnome org
- To: svn-commits-list gnome org
- Subject: genius r657 - in trunk: . src
- Date: Wed, 4 Jun 2008 08:52:35 +0000 (UTC)
Author: jirka
Date: Wed Jun 4 08:52:34 2008
New Revision: 657
URL: http://svn.gnome.org/viewvc/genius?rev=657&view=rev
Log:
Wed Jun 04 03:51:25 2008 Jiri (George) Lebl <jirka 5z com>
* src/gnome-genius.c: figure out a way to work around VTE nonsense,
one way to get at current absolute row is by checking the cursor
location and assuming it is on the last line. Improve
monitoring by using a text buffer and allow to turn off the
automatic updates. Full answer is now wrapped if not a matrix.
Don't set icon if it doesn't exist to avoid warning. Don't try
to use readline helper from current dir if not in dev dir.
Modified:
trunk/ChangeLog
trunk/NEWS
trunk/src/gnome-genius.c
Modified: trunk/NEWS
==============================================================================
--- trunk/NEWS (original)
+++ trunk/NEWS Wed Jun 4 08:52:34 2008
@@ -2,7 +2,10 @@
Syntax and semantical changes are marked with CHANGE:
-* Add IsMersennePrime, MersennePrimeExponents, IsDefined, undefine
+* Add "Save Console Output" menu item to save console contents
+* Add "Monitor a Variable" menu item to continuously monitor a single
+ variable
+* Add IsMersennePrimeExponent, MersennePrimeExponents, IsDefined, undefine
* QuadraticFormula built in and more numerically stable
* CHANGE: It's Fibonacci in correct spelling, short name is still fib
* Calling internal functions is now slightly faster
Modified: trunk/src/gnome-genius.c
==============================================================================
--- trunk/src/gnome-genius.c (original)
+++ trunk/src/gnome-genius.c Wed Jun 4 08:52:34 2008
@@ -187,22 +187,16 @@
static FILE *torlfp = NULL;
static int fromrl;
-static int forvte[2];
-
-static GIOChannel *forvte0_ch;
-
-
static char *torlfifo = NULL;
static char *fromrlfifo = NULL;
static char *arg0 = NULL;
-static gboolean feed_to_vte (GIOChannel *source, GIOCondition condition, gpointer data);
static void new_callback (GtkWidget *menu_item, gpointer data);
static void open_callback (GtkWidget *w);
static void save_callback (GtkWidget *w);
static void save_all_cb (GtkWidget *w);
-/* static void save_console_cb (GtkWidget *w); */
+static void save_console_cb (GtkWidget *w);
static void save_as_callback (GtkWidget *w);
static void close_callback (GtkWidget *menu_item, gpointer data);
static void load_cb (GtkWidget *w);
@@ -253,10 +247,8 @@
GNOMEUIINFO_MENU_CLOSE_ITEM (close_callback, NULL),
GNOMEUIINFO_SEPARATOR,
GNOMEUIINFO_ITEM_STOCK(N_("_Load and Run..."),N_("Load and execute a file in genius"), load_cb, GTK_STOCK_OPEN),
- /*
GNOMEUIINFO_SEPARATOR,
- GNOMEUIINFO_ITEM_STOCK(N_("Save Console _Output..."),N_("Save what is visible on the console (including scrollback) to a text file"), save_console_cb, GTK_STOCK_SAVE),
- */
+ GNOMEUIINFO_ITEM_STOCK(N_("Save Console Ou_tput..."),N_("Save what is visible on the console (including scrollback) to a text file"), save_console_cb, GTK_STOCK_SAVE),
GNOMEUIINFO_SEPARATOR,
GNOMEUIINFO_MENU_EXIT_ITEM (quitapp,NULL),
GNOMEUIINFO_END,
@@ -540,6 +532,7 @@
gboolean always_textbox,
const char *textbox_title,
gboolean bind_response,
+ gboolean wrap,
const char *s)
{
GtkWidget *mb;
@@ -587,6 +580,14 @@
tv = gtk_text_view_new ();
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (tv));
gtk_text_view_set_editable (GTK_TEXT_VIEW (tv), FALSE);
+
+ if (wrap)
+ gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (tv),
+ GTK_WRAP_CHAR);
+ else
+ gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (tv),
+ GTK_WRAP_NONE);
+
gtk_text_buffer_create_tag (buffer, "foo",
"editable", FALSE,
"family", "monospace",
@@ -865,7 +866,10 @@
typedef struct {
guint tm;
GelToken *var;
- GtkWidget *label;
+ GtkWidget *tv;
+ GtkTextBuffer *buf;
+ GtkWidget *updatecb;
+ GelOutput *out;
} MonitorData;
static void
@@ -873,6 +877,7 @@
{
MonitorData *md = data;
g_source_remove (md->tm);
+ gel_output_unref (md->out);
g_free (md);
}
@@ -880,25 +885,32 @@
monitor_timeout (gpointer data)
{
MonitorData *md = data;
- GString *str;
+ char *s;
GSList *li;
GelEFunc *func;
+ GtkTextIter iter;
+ GtkTextIter iter_end;
+ gboolean any_matrix = FALSE;
+
+ if ( ! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (md->updatecb)))
+ return TRUE;
+
+ /* get iterator */
+ gtk_text_buffer_get_iter_at_offset (md->buf, &iter, 0);
- str = g_string_new ("");
-
if (md->var == NULL ||
md->var->refs == NULL) {
- g_string_append_printf (str, _("%s undefined"), md->var->token);
+ s = g_strdup_printf (_("%s undefined"), md->var->token);
+ gtk_text_buffer_insert_with_tags_by_name
+ (md->buf, &iter, s, -1, "value", NULL);
+ g_free (s);
} else {
int vars = 0;
- GelOutput *out;
- out = gel_output_new ();
- gel_output_setup_string (out, 0, NULL);
for (li = md->var->refs; li != NULL; li = li->next) {
- /* this must be our function */
func = li->data;
- if (func->type != GEL_VARIABLE_FUNC ||
+ if ((func->type != GEL_VARIABLE_FUNC &&
+ func->type != GEL_USER_FUNC) ||
func->id == NULL ||
func->id->parameter ||
func->id->protected_ ||
@@ -906,27 +918,67 @@
func->data.user == NULL)
continue;
- gel_print_etree (out, func->data.user, FALSE /*no toplevel, keep this short*/);
+ /* This is a hack: it fakes the pretty
+ * output routine to add a newline when printing
+ * a matrix */
+ gel_output_string (md->out, "\n ");
+ gel_output_clear_string (md->out);
+
+ if (func->data.user->type == MATRIX_NODE)
+ any_matrix = TRUE;
+ gel_pretty_print_etree (md->out, func->data.user);
if (vars > 0)
- g_string_append (str, "\n");
+ gtk_text_buffer_insert_with_tags_by_name
+ (md->buf, &iter, "\n", -1,
+ "value", NULL);
if (func->context == 0)
- g_string_append (str, "(global) ");
+ /* printed before a global variable */
+ s = g_strdup (_("(global) "));
else
- g_string_append_printf (str, "(context %d)", func->context);
+ /* printed before local variable in certain
+ * context */
+ s = g_strdup_printf (_("(context %d) "),
+ func->context);
+ gtk_text_buffer_insert_with_tags_by_name
+ (md->buf, &iter, s, -1, "context", NULL);
+ g_free (s);
- g_string_append_printf (str, "%s = %s", md->var->token,
- gel_output_peek_string (out));
- gel_output_clear_string (out);
+ gtk_text_buffer_insert_with_tags_by_name
+ (md->buf, &iter, md->var->token, -1,
+ "variable", NULL);
+ gtk_text_buffer_insert_with_tags_by_name
+ (md->buf, &iter, " = ", -1,
+ "value", NULL);
+
+ gtk_text_buffer_insert_with_tags_by_name
+ (md->buf, &iter,
+ gel_output_peek_string (md->out), -1,
+ "value", NULL);
+
+ gel_output_clear_string (md->out);
vars ++;
}
-
- gel_output_unref (out);
+ if (vars == 0) {
+ s = g_strdup_printf (_("%s not a user variable"),
+ md->var->token);
+ gtk_text_buffer_insert_with_tags_by_name
+ (md->buf, &iter, s, -1, "value", NULL);
+ g_free (s);
+ }
}
- gtk_label_set_text (GTK_LABEL (md->label), str->str);
- g_string_free (str, TRUE);
+ /* matrices look better unwrapped */
+ if (any_matrix)
+ gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (md->tv), GTK_WRAP_NONE);
+ else
+ gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (md->tv), GTK_WRAP_CHAR);
+
+ /* delete everything left over */
+ gtk_text_buffer_get_iter_at_offset (md->buf, &iter_end, -1);
+ gtk_text_buffer_delete (md->buf, &iter, &iter_end);
+
return TRUE;
}
@@ -935,10 +987,13 @@
{
GtkWidget *d;
MonitorData *md;
+ GtkWidget *sw;
char *s;
md = g_new0 (MonitorData, 1);
md->var = d_intern (var);
+ md->out = gel_output_new ();
+ gel_output_setup_string (md->out, 0, NULL);
s = g_strdup_printf (_("Monitoring: %s"), var);
d = gtk_dialog_new_with_buttons
@@ -949,13 +1004,53 @@
NULL);
g_free (s);
+ gtk_dialog_set_has_separator (GTK_DIALOG (d), FALSE);
+
g_signal_connect (G_OBJECT (d), "response",
G_CALLBACK (gtk_widget_destroy),
NULL);
- md->label = gtk_label_new ("*");
+ sw = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
+ GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_AUTOMATIC);
+ gtk_box_pack_start (GTK_BOX (GTK_DIALOG (d)->vbox),
+ sw,
+ TRUE, TRUE, 0);
+
+
+ md->tv = gtk_text_view_new ();
+ gtk_text_view_set_editable (GTK_TEXT_VIEW (md->tv), FALSE);
+ md->buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (md->tv));
+
+ gtk_text_buffer_create_tag (md->buf, "variable",
+ "editable", FALSE,
+ "family", "monospace",
+ "weight", PANGO_WEIGHT_BOLD,
+ NULL);
+
+ gtk_text_buffer_create_tag (md->buf, "context",
+ "editable", FALSE,
+ "family", "monospace",
+ "style", PANGO_STYLE_ITALIC,
+ NULL);
+
+ gtk_text_buffer_create_tag (md->buf, "value",
+ "editable", FALSE,
+ "family", "monospace",
+ NULL);
+
+ gtk_container_add (GTK_CONTAINER (sw), md->tv);
+
+ md->updatecb = gtk_check_button_new_with_label
+ (_("Update continuously"));
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (d)->vbox),
- md->label, FALSE, FALSE, 0);
+ md->updatecb,
+ FALSE, FALSE, 0);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (md->updatecb), TRUE);
+
+ gtk_window_set_default_size
+ (GTK_WINDOW (d), 270, 150);
md->tm = g_timeout_add (1500,
monitor_timeout,
@@ -1017,13 +1112,19 @@
GelOutput *out;
const char *s;
GelEFunc *ans;
+ gboolean wrap;
out = gel_output_new ();
gel_output_setup_string (out, 0, NULL);
ans = d_lookup_only_global (d_intern ("Ans"));
+
+ wrap = TRUE;
+
if (ans != NULL) {
if (ans->type == GEL_VARIABLE_FUNC) {
+ if (ans->data.user->type == MATRIX_NODE)
+ wrap = FALSE;
gel_pretty_print_etree (out, ans->data.user);
} else {
/* ugly? maybe! */
@@ -1041,6 +1142,7 @@
TRUE /*always textbox*/,
_("Full Answer") /*textbox_title*/,
TRUE /*bind_response*/,
+ wrap /* wrap */,
ve_sure_string (s));
gel_output_unref (out);
@@ -1061,6 +1163,7 @@
FALSE /*always textbox*/,
NULL /*textbox_title*/,
TRUE /*bind_response*/,
+ FALSE /* wrap */,
errors->str);
g_string_free(errors,TRUE);
errors=NULL;
@@ -1159,6 +1262,7 @@
FALSE /*always textbox*/,
NULL /*textbox_title*/,
TRUE /*bind_response*/,
+ FALSE /* wrap */,
infos->str);
g_string_free (infos, TRUE);
infos = NULL;
@@ -3139,7 +3243,6 @@
* no good way to get at the buffer currently. We'd have to just keep the
* buffer ourselves over again. That is stupid. At some point we must get rid of
* VTE, then we can implement this sucker. */
-#if 0
static gboolean
always_selected (VteTerminal *terminal, glong column, glong row, gpointer data)
@@ -3153,7 +3256,7 @@
char *s;
char *base;
char *output;
- char *outputr;
+ glong row, column;
int sz;
if (response != GTK_RESPONSE_OK) {
@@ -3182,22 +3285,19 @@
return;
}
- /* this is moronic! VTE has an idiotic API */
+ /* this is moronic! VTE has an idiotic API, there is no
+ * way to find out what the proper row range is! */
+ vte_terminal_get_cursor_position (VTE_TERMINAL (term),
+ &column, &row);
output = vte_terminal_get_text_range (VTE_TERMINAL (term),
- MAX(lines_printed-genius_setup.scrollback-1, 0),
+ MAX(row-genius_setup.scrollback+1, 0),
0,
- lines_printed,
+ row,
VTE_TERMINAL (term)->column_count - 1,
always_selected,
NULL,
NULL);
- outputr = output;
- while (*outputr == '\n')
- outputr++;
- sz = strlen (outputr);
- while (sz > 0 &&
- outputr[sz-1] == '\n')
- sz--;
+ sz = strlen (output);
if ( ! save_contents_vfs (s, output, sz)) {
char *err = g_strdup_printf (_("<b>Cannot save file</b>\n"
@@ -3257,7 +3357,6 @@
gtk_widget_show (fs);
}
-#endif
static void
@@ -3610,29 +3709,11 @@
g_free(s);
}
-static gboolean
-feed_to_vte (GIOChannel *source, GIOCondition condition, gpointer data)
-{
- if (condition & G_IO_IN) {
- int fd = g_io_channel_unix_get_fd (source);
- int size;
- char buf[256];
- while ((size = read (fd, buf, 256)) > 0 ||
- errno == EINTR) {
- if (size > 0)
- feed_to_vte_from_string (buf, size);
- }
- }
-
- return TRUE;
-}
-
static void
output_notify_func (GelOutput *output)
{
const char *s = gel_output_peek_string (output);
if (s != NULL) {
- feed_to_vte (forvte0_ch, G_IO_IN, NULL);
feed_to_vte_from_string ((char *)s, strlen (s));
gel_output_clear_string (output);
}
@@ -3706,7 +3787,8 @@
foo = NULL;
- if (access ("./genius-readline-helper-fifo", X_OK) == 0)
+ if (genius_in_dev_dir &&
+ access ("./genius-readline-helper-fifo", X_OK) == 0)
foo = g_strdup ("./genius-readline-helper-fifo");
file = g_build_filename (libexecdir, "genius-readline-helper-fifo",
@@ -3744,6 +3826,7 @@
FALSE /*always textbox*/,
NULL /*textbox_title*/,
FALSE /*bind_response*/,
+ FALSE /*wrap*/,
_("Can't execute genius-readline-helper-fifo!\n"));
gtk_dialog_run (GTK_DIALOG (d));
@@ -4141,17 +4224,8 @@
/* GNOME_PARAM_POPT_TABLE, options, */
NULL);
- if (pipe (forvte) < 0)
- g_error ("Can't pipe");
-
setup_rl_fifos ();
- fcntl (forvte[0], F_SETFL, O_NONBLOCK);
-
- forvte0_ch = g_io_channel_unix_new (forvte[0]);
- g_io_add_watch_full (forvte0_ch, G_PRIORITY_DEFAULT, G_IO_IN | G_IO_HUP | G_IO_ERR,
- feed_to_vte, NULL, NULL);
-
main_out = gel_output_new();
gel_output_setup_string (main_out, 80, get_term_width);
gel_output_set_notify (main_out, output_notify_func);
@@ -4172,7 +4246,8 @@
"apps",
"gnome-genius.png",
NULL);
- gtk_window_set_default_icon_from_file (file, NULL);
+ if (access (file, F_OK) == 0)
+ gtk_window_set_default_icon_from_file (file, NULL);
g_free (file);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]