Adding Simple Feature to Gnumeric

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Adding Simple Feature to Gnumeric

GnuMeric mailing list
Hi Gnumericers,

I am a long-time user of Gnumeric (10+ years)  so first let me issue a long-overdue 'THANK YOU!' for such a great piece of software.

I have recently become interested in building gnumeric from source and to experiment with adding a feature I would like to use. I have two related questions to that effort

1. BUILD TROUBLE: I cloned the Gnumeric repo from github but I am having some minor build problems. I believe that I have all the necessary packages installed on my Arch Linux distribution to build but am getting problems with libgoffice versions, particularly when running ./configure I get

Package 'libgoffice-0.10' has version '0.10.45', required version is '>= 0.10.46'

I have the most up-to-date version available in the Arch repos 
> pacman -Ss goffice
extra/goffice 0.10.45-1 [installed]
    A GLib/GTK+ set of document-centric objects and charting library

but perhaps there is a fresher version elsewhere. I poked around the Github repo for libgoffice briefly but only saw version 0.10.45 mentioned.

I tried tweaking the requirement in configure.ac from 0.10.46 down to 0.10.45; this allowed me to get a ./configure script that completed (mostly) but on beginning the build with 'make' a number of errors were reported about missing functions which are likely in the newer version of libgoffice such as

stf-parse.c: In function ‘do_check_date’:
stf-parse.c:1843:13: error: implicit declaration of function ‘go_format_has_year’; did you mean ‘go_format_has_hour’? [-Werror=implicit-function-declaration]
 1843 |  has_all = (go_format_has_year (fmt) &&
      |             ^~~~~~~~~~~~~~~~~~
      |             go_format_has_hour

This makes me think I likely need a newer version of libgoffice. Any advice folks could offer me about about how to build properly would be appreciated.

2. FEATURE ADVICE: The feature I would like to add is as follows
  - Select a cell range with the mouse
  - Select a menu item titled something like 'Replace Blank Cells'
  - A dialog prompts for text that will be filled into all of the empty cells in the range
  - Cells with contents already will not be affected
I am a teacher and do grade calculations on student grades; often when I download the grades, items that they skipped come in as blank cells. While I could mangle some CSV files for this, it would be handy to have a 'Replace Blank Cells' feature.

If there is a way to do this already in Gnumeric, please let me know. I experimented with the Search/Replace options but couldn't get anything to stick for blank cells.

I have been examining the Plugins architecture for Gnumeric and am considering writing the feature as a plugin as it can be 'optionally' enabled.  The provided demo plugin 'uihello' provides a good line of attack on how to add items to menus and trigger code to run.  However, I would very much like advice on whether this is an appropriate mechanism or if a better one exists. 

I have not yet done a deep dive into code to single out the APIs as I'd like to be able to build the code first but I'll likely have some follow-up questions once I get over the immediate hurdles.

Thanks again for any help and for the outstanding work you've all done over the years.
Cheers,
Chris Kauffman

_______________________________________________
gnumeric-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gnumeric-list
Reply | Threaded
Open this post in threaded view
|

Re: Adding Simple Feature to Gnumeric

Morten Welinder-2
To build Gnumeric from github you will need Goffice from github.

You could probably hack around it ("#define go_format_has_year(fmt)
0")  if you don't mind potential problems with text import.

Search and replace never sees empty cells so it won't do what you need.
Python scripting -- see test/t3001-introspection-simple.py -- certainly can.

M.
_______________________________________________
gnumeric-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gnumeric-list
Reply | Threaded
Open this post in threaded view
|

[patch] improve versatility and reliability of

GnuMeric mailing list
Hi --

The following patch should be self-explanatory.
If not, I can provide more details........

commit 97036896b311675bad3615c2767b76ccb0fcea1c
Author: John Denker <[hidden email]>
Date:   Wed Aug 21 15:09:54 2019 -0700

    allow tests to work a lot better when invoked from
    somewhere other than the test directory,
    e.g. when invoked as ./gnumeric/test/<whatever>.pl

diff --git a/test/GnumericTest.pm b/test/GnumericTest.pm
index 0de6467c4..47c3f8baa 100644
--- a/test/GnumericTest.pm
+++ b/test/GnumericTest.pm
@@ -23,22 +23,30 @@ $| = 1;
 use vars qw($topsrc $top_builddir $samples $default_subtests $default_corpus $PERL $PYTHON $verbose);
 use vars qw($ssconvert $ssindex $sstest $ssdiff $ssgrep $gnumeric);
 use vars qw($normalize_gnumeric);
+use File::Spec;
+use File::Basename;
 
 $PYTHON = undef;
 
 $PERL = $Config{'perlpath'};
 $PERL .= $Config{'_exe'} if $^O ne 'VMS' && $PERL !~ m/$Config{'_exe'}$/i;
 
-if ($0 eq '-e') {
-    # Running as "perl -e '...'", so no idea about where we are
-    $topsrc = '.';
-} else {
-    $topsrc = $0;
-    $topsrc =~ s|/[^/]+$|/..|;
-    $topsrc =~ s|/test/\.\.$||;
-}
+# Note that if we were invoked via perl -e script, then
+#  $0 will be '-e', and $fullname will be the current directory,
+#  which is a good guess for $topsrc but not guaranteed correct.
+my $fullname =  File::Spec->rel2abs($0);
+
+# directory containing the test script:
+my $dirname  = dirname($fullname);
+
+# Assuming we are in the gnumeric/test directory,
+# the parent thereof should be the gnumeric directory:
+$topsrc = $dirname;
+$topsrc =~ s'/test/?$'';        # otherwise just use the current directory
+
+# AFAICT this is just another name for the same thing:
+$top_builddir = $topsrc;
 
-$top_builddir = "..";
 $samples = "$topsrc/samples"; $samples =~ s{^\./+}{};
 $ssconvert = "$top_builddir/src/ssconvert";
 $ssindex = "$top_builddir/src/ssindex";
@@ -680,7 +688,7 @@ sub test_roundtrip {
  die "Failed to produce $file_filtered\n" unless -r $file_filtered;
  &junkfile ($file_filtered) unless $keep;
     }
-    
+
     my $tmp1 = "$tmp.$newext";
     unlink $tmp1;
     &junkfile ($tmp1) unless $keep;
@@ -927,7 +935,7 @@ sub setup_python_environment {
     $ENV{$v} = ($ENV{$v} || '') eq '' ? $dir : $dir . ':' . $ENV{$v};
 
     $ENV{'PYTHONPATH'} = "$topsrc/introspection";
-    
+
     # Don't litter
     $ENV{'PYTHONDONTWRITEBYTECODE'} = 1;
 

_______________________________________________
gnumeric-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gnumeric-list
Reply | Threaded
Open this post in threaded view
|

Re: [patch] improve versatility and reliability of

Morten Welinder-2
This breaks "make distcheck" for me.

[...]
test -d "gnumeric-1.12.46" || mkdir "gnumeric-1.12.46"
cp: cannot stat
'.//home/welinder/gnome/gnumeric/samples/regress.gnumeric': No such
file or directory




+# AFAICT this is just another name for the same thing:
+$top_builddir = $topsrc;

Not during distcheck.  Anything written by the compilation will go
into the build directory while src can remain readonly.  I don't think
that's related to the distcheck failure, though.

M.
_______________________________________________
gnumeric-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gnumeric-list
Reply | Threaded
Open this post in threaded view
|

Re: [patch] improve versatility and reliability of some test scripts

GnuMeric mailing list
On 8/21/19 4:16 PM, Morten Welinder wrote:

> This breaks "make distcheck" for me.

My bad. Sorry to cause trouble, and thanks for your patience.

Here is a more conservative approach to alleviating the problem.
It appears that $topsrc and $top_builddir are being used in
inconsistent ways.  I don't see any way to impose a consistent
meaning on them in a way that would fix old bugs without
introducing new bugs.  So instead I defined a new variable
$abs_builddir and used it in places where it was easy to
figure out what meaning was needed.

There is no reason to expect that all test scripts can now
be invoked from outside the test directory, but /some/ can.

Legacy situations such as "make" and "make distcheck" should
be unaffected.

commit 5b06783deec17f4961a59f91d37f28bad0a7bd46
Author: John Denker <[hidden email]>
Date:   Thu Aug 22 00:33:36 2019 -0700

    allow some test scripts to be invoked via nontrivial filespecs, e.g
      cd /some/where/gnumeric
      ./test/t3001*.pl
    without having to cd to the test directory

diff --git a/test/GnumericTest.pm b/test/GnumericTest.pm
index 0de6467c4..40a2e0691 100644
--- a/test/GnumericTest.pm
+++ b/test/GnumericTest.pm
@@ -1,7 +1,7 @@
 package GnumericTest;
 use strict;
 use Exporter;
-use File::Basename qw(fileparse);
+use File::Basename qw(fileparse dirname);
 use Config;
 use XML::Parser;
 
@@ -20,7 +20,7 @@ $| = 1;
    $subtests $samples corpus $PERL $PYTHON);
 @GnumericTest::EXPORT_OK = qw(junkfile);
 
-use vars qw($topsrc $top_builddir $samples $default_subtests $default_corpus $PERL $PYTHON $verbose);
+use vars qw($topsrc $top_builddir $abs_builddir $samples $default_subtests $default_corpus $PERL $PYTHON $verbose);
 use vars qw($ssconvert $ssindex $sstest $ssdiff $ssgrep $gnumeric);
 use vars qw($normalize_gnumeric);
 
@@ -39,14 +39,17 @@ if ($0 eq '-e') {
 }
 
 $top_builddir = "..";
-$samples = "$topsrc/samples"; $samples =~ s{^\./+}{};
-$ssconvert = "$top_builddir/src/ssconvert";
-$ssindex = "$top_builddir/src/ssindex";
-$sstest = "$top_builddir/src/sstest";
-$ssdiff = "$top_builddir/src/ssdiff";
-$ssgrep = "$top_builddir/src/ssgrep";
-$gnumeric = "$top_builddir/src/gnumeric";
-$normalize_gnumeric = "$PERL $topsrc/test/normalize-gnumeric";
+# make_absolute($0) is probably /some/where/gnumeric/test/script.pl
+$abs_builddir = dirname(dirname(make_absolute($0)));   # /some/where/gnumeric
+
+$samples = "$abs_builddir/samples";
+$ssconvert = "$abs_builddir/src/ssconvert";
+$ssindex = "$abs_builddir/src/ssindex";
+$sstest = "$abs_builddir/src/sstest";
+$ssdiff = "$abs_builddir/src/ssdiff";
+$ssgrep = "$abs_builddir/src/ssgrep";
+$gnumeric = "$abs_builddir/src/gnumeric";
+$normalize_gnumeric = "$PERL $abs_builddir/test/normalize-gnumeric";
 $verbose = 0;
 $default_subtests = '*';
 my $subtests = undef;
@@ -680,7 +683,7 @@ sub test_roundtrip {
  die "Failed to produce $file_filtered\n" unless -r $file_filtered;
  &junkfile ($file_filtered) unless $keep;
     }
-    
+
     my $tmp1 = "$tmp.$newext";
     unlink $tmp1;
     &junkfile ($tmp1) unless $keep;
@@ -911,23 +914,23 @@ sub make_absolute {
 # -----------------------------------------------------------------------------
 
 sub setup_python_environment {
-    $PYTHON = `grep '^#define PYTHON_INTERPRETER ' $top_builddir/gnumeric-config.h 2>&1`;
+    $PYTHON = `grep '^#define PYTHON_INTERPRETER ' $abs_builddir/gnumeric-config.h 2>&1`;
     chomp $PYTHON;
     $PYTHON =~ s/^[^"]*"(.*)"\s*$/$1/;
     &report_skip ("Missing python interpreter") unless -x $PYTHON;
 
     # Make sure we load introspection preferentially from build directory
     my $v = 'GI_TYPELIB_PATH';
-    my $dir = "$top_builddir/src";
+    my $dir = "$abs_builddir/src";
     $ENV{$v} = ($ENV{$v} || '') eq '' ? $dir : $dir . ':' . $ENV{$v};
 
     # Ditto for shared libraries
     $v = 'LD_LIBRARY_PATH';
-    $dir = "$top_builddir/src/.libs";
+    $dir = "$abs_builddir/src/.libs";
     $ENV{$v} = ($ENV{$v} || '') eq '' ? $dir : $dir . ':' . $ENV{$v};
 
-    $ENV{'PYTHONPATH'} = "$topsrc/introspection";
-    
+    $ENV{'PYTHONPATH'} = "$abs_builddir/introspection";
+
     # Don't litter
     $ENV{'PYTHONDONTWRITEBYTECODE'} = 1;
 
_______________________________________________
gnumeric-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gnumeric-list
Reply | Threaded
Open this post in threaded view
|

Re: Adding Simple Feature to Gnumeric

GnuMeric mailing list
In reply to this post by Morten Welinder-2
Thanks for the tips, Morten. I will do some work in the next few days to compile current Git versions of Goffice, GSL (suggested by Andreas) and Gnumeric together. 

In the meantime, I got distracted by your suggestion of using Python scripting to address the problem which also seems like a viable mechanism. The python API is very solid, exposing all the C functions I have seen and allowing exploration using the Tools->Plugins->Python Console via things like '>>> dir(Gnm)' to see what functions and fields are exposed. I have been stumbled a bit on finding an exact angle of attack so I will ask a couple questions.

1. Is there any way to access a notion of the 'currently active sheet'?  I have found by going through the Python 'Gnm.App' (the global 'GnmApp *app' field from src/application.c I expect) one can access the list of workbooks via 
  >>> wb=Gnm.App.workbook_get_by_index(0)
and other function. This leads to access to sheets managed by the Gnumeric instance.
The ideal behavior for me is to 
- select an area of Cells on a Sheet 
- apply some functionality cells in the selected area.  
This requires some notion of the most recently used or 'active' Sheet/Workbook, functionality which I can't seem to find.  Perhaps it's not present at all in the global program state due to such accesses being through the GTK GUI and thus not tracked by the internal model of Gnumeric but any insight on how one might figure this out would be appreciated.

2. Ideally I would like this 'replace blank cells' functionality to have a GUI interface perhaps implemented using the Plugin architecture.  In the plugins/ source directory, I see examples of (A) C plugins with similar ideas, (B) a plugin to load python code using C (python-loader), and (C) cell functions written in python (py-func). I don't see any pure python plugins with GUIs. 
Is it possible to write a Python plugin that will have a GUI menu (like in the plugins/uihello directory, perhaps using some of the XML files there) and operate on cells or would this require use of the C interface?

Cheers,
Chris

On Wed, Aug 21, 2019 at 12:51 PM Morten Welinder <[hidden email]> wrote:
To build Gnumeric from github you will need Goffice from github.

You could probably hack around it ("#define go_format_has_year(fmt)
0")  if you don't mind potential problems with text import.

Search and replace never sees empty cells so it won't do what you need.
Python scripting -- see test/t3001-introspection-simple.py -- certainly can.

M.

_______________________________________________
gnumeric-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gnumeric-list