Commit 6b5f2993 authored by Murray Cumming's avatar Murray Cumming
Browse files

Button scripts: Check and warn about pygtk2 instead of crashing.

* glom/libglom/utils.[h|cc]: Add script_check_for_pygtk().
* Makefile_tests.am:
* tests/test_script_check_for_problems.cc: Add a test for the check
function.
* glom/mode_data/box_data.cc: execute_button_script(): Show a
warning dialog, and do not run the script, if it seems to use pygtk.
This should help with but #669196 (alien) and ##661766 (Andre Klapper) .
parent d1a3988b
2012-02-03 Murray Cumming <murrayc@murrayc.com>
Button scripts: Check and warn about pygtk2 instead of crashing.
* glom/libglom/utils.[h|cc]: Add script_check_for_pygtk().
* Makefile_tests.am:
* tests/test_script_check_for_problems.cc: Add a test for the check
function.
* glom/mode_data/box_data.cc: execute_button_script(): Show a
warning dialog, and do not run the script, if it seems to use pygtk.
This should help with but #669196 (alien) and ##661766 (Andre Klapper) .
2012-02-03 Murray Cumming <murrayc@murrayc.com>
ReportBuilder: Add error checking.
......
......@@ -34,6 +34,7 @@ check_PROGRAMS = \
tests/python/test_load_python_library\
tests/python/test_python_module \
tests/test_fake_connection \
tests/test_script_check_for_problems \
tests/test_selfhosting_new_empty \
tests/test_selfhosting_new_empty_change_sysprefs \
tests/test_selfhosting_new_empty_then_users \
......@@ -71,6 +72,7 @@ TESTS = tests/test_document_load \
tests/python/test_load_python_library \
tests/python/test_python_module \
tests/test_fake_connection \
tests/test_script_check_for_problems \
tests/test_selfhosting_new_empty \
tests/test_selfhosting_new_empty_change_sysprefs \
tests/test_selfhosting_new_empty_then_users \
......@@ -220,6 +222,10 @@ tests_test_fake_connection_SOURCES = tests/test_fake_connection.cc
tests_test_fake_connection_LDADD = $(tests_ldadd)
tests_test_fake_connection_CPPFLAGS = $(tests_cppflags)
tests_test_script_check_for_problems_SOURCES = tests/test_script_check_for_problems.cc
tests_test_script_check_for_problems_LDADD = $(tests_ldadd)
tests_test_script_check_for_problems_CPPFLAGS = $(tests_cppflags)
tests_test_selfhosting_new_empty_SOURCES = tests/test_selfhosting_new_empty.cc $(sources_test_selfhosting_utils)
tests_test_selfhosting_new_empty_LDADD = $(tests_ldadd)
tests_test_selfhosting_new_empty_CPPFLAGS = $(tests_cppflags)
......
......@@ -1501,5 +1501,15 @@ LayoutGroup::type_list_items Utils::get_layout_items_plus_primary_key(const Layo
return items_plus_pk;
}
bool Utils::script_check_for_pygtk2(const Glib::ustring& script)
{
//There are probably other code that this will not catch,
//but this is better than nothing.
//TODO: Instead override python's import mechanism somehow?
if(script.find("import pygtk") != std::string::npos)
return false;
return true;
}
} //namespace Glom
......@@ -236,6 +236,12 @@ std::string get_temp_directory_path(const std::string& prefix = std::string());
*/
Glib::ustring get_temp_directory_uri(const std::string& prefix = std::string());
/** @returns true if the script is OK, or
* false if the script uses pygtk2, which would cause a crash,
* because Glom itself uses GTK+ 3.
*/
bool script_check_for_pygtk2(const Glib::ustring& script);
} //namespace Utils
} //namespace Glom
......
......@@ -352,6 +352,14 @@ Glib::ustring Box_Data::get_layout_name() const
void Box_Data::execute_button_script(const sharedptr<const LayoutItem_Button>& layout_item, const Gnome::Gda::Value& primary_key_value)
{
const Glib::ustring script = layout_item->get_script();
if(!Utils::script_check_for_pygtk2(script))
{
Utils::show_ok_dialog(_("Script Uses PyGTK 2"),
_("Glom cannot run this script because it uses pygtk 2, but Glom uses GTK+ 3, and attempting to use pygtk 2 would cause Glom to crash."), *get_app_window(), Gtk::MESSAGE_ERROR);
return;
}
const sharedptr<Field> field_primary_key = get_field_primary_key();
const type_map_fields field_values = get_record_field_values_for_calculation(m_table_name, field_primary_key, primary_key_value);
......@@ -362,7 +370,7 @@ void Box_Data::execute_button_script(const sharedptr<const LayoutItem_Button>& l
AppPythonUICallbacks callbacks;
Glib::ustring error_message;
glom_execute_python_function_implementation(layout_item->get_script(),
glom_execute_python_function_implementation(script,
field_values, //TODO: Maybe use the field's type here.
get_document(),
get_table_name(), field_primary_key, primary_key_value,
......
......@@ -14,7 +14,7 @@
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
71 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
......
/* Glom
*
* Copyright (C) 2012 Openismus GmbH
*
* 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, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <libglom/utils.h>
#include <libglom/init.h>
#include <iostream>
int main()
{
Glom::libglom_init();
Glib::ustring script;
if(!Glom::Utils::script_check_for_pygtk2(script))
{
std::cerr << "script_check_for_pygtk2() failed unexpectedly." << std::endl;
return EXIT_FAILURE;
}
script =
"from gi.repository import Gtk";
if(!Glom::Utils::script_check_for_pygtk2(script))
{
std::cerr << "script_check_for_pygtk2() failed unexpectedly." << std::endl;
return EXIT_FAILURE;
}
script =
"import pygtk\n" \
"pygtk.require('2.0')\n" \
"import gtk";
if(Glom::Utils::script_check_for_pygtk2(script))
{
std::cerr << "script_check_for_pygtk2() succeeded unexpectedly." << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment