Subject: [Thuban-list] Problem with Thuban in Ubuntu

From: "Samuel Mesa" <[email-masked]>
Date: Tue, 24 Apr 2007 10:32:50 -0500

Greetings from Colombia. I am using Thuban v1.2.0 but I have the
following problems

1. When modifying the properties of a layer and  when opening the
projection window

Error:

'ascii' codec can't decode byte 0xc3 in position 10: ordinal not in range(128)

Thank you very much

-- 
  |\__
(:> __)(
  |/

Soluciones Geoinformáticas Libres
http://geotux.tuxfamily.org/

---

From: Didrik Pinte <[email-masked]>
Date: Tue, 24 Apr 2007 17:56:43 +0200

> 'ascii' codec can't decode byte 0xc3 in position 10: ordinal not in range(128)

Hi Samuel,

This is a problem related to the default encoding of Ubuntu and the
encoding support in Thuban. 

It seems they are remaining encoding bugs in the Thuban code.

Can you be a bit more precise on the error message. Generally Thuban
displays a nice box with lots of information on the error that was
generated.

We will try to fix this as soon as we have your entire error message.

Didrik

---

From: "Samuel Mesa" <[email-masked]>
Date: Tue, 24 Apr 2007 12:14:50 -0500

Hi Didrik, the bug reported in Thuban is the following one:

For the projection of layers

***********************
Se activó una excepción no manejada:
'ascii' codec can't decode byte 0xc3 in position 8: ordinal not in range(128)
(por favior informe del error utilizando
http://thuban.intevation.org/bugtracker.html)

Traceback (most recent call last):
 File "/usr/lib/thuban/Thuban/UI/mainwindow.py", line 297, in invoke_command
   command.Execute(self.Context())
 File "/usr/lib/thuban/Thuban/UI/command.py", line 121, in Execute
   apply(self.function, (context,) + self.args + args, kw)
 File "/usr/lib/thuban/Thuban/UI/mainwindow.py", line 1071, in call_method
   apply(getattr(context.mainwindow, methodname), args)
 File "/usr/lib/thuban/Thuban/UI/mainwindow.py", line 779, in LayerProjection
   _("Layer Projection: %s") % layer.Title(), layer)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
8: ordinal not in range(128)
****************

For the classification of the simbology

***************
Se activó una excepción no manejada:
'ascii' codec can't decode byte 0xc3 in position 10: ordinal not in range(128)
(por favior informe del error utilizando
http://thuban.intevation.org/bugtracker.html)

Traceback (most recent call last):
 File "/usr/lib/thuban/Thuban/UI/classgen.py", line 221, in OnOK
   if genSel in (GENCOMBOSTR_UNIFORM,          \
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
10: ordinal not in range(128)
****************

It is wonderful that with Python this tool GIS is being developed

-- 
  |\__
(:> __)(
  |/

---

From: Bernhard Reiter <[email-masked]>
Date: Tue, 24 Apr 2007 20:11:01 +0200

Hi Samuel,

On Tuesday 24 April 2007 19:14, Samuel Mesa wrote:
> the bug reported in Thuban is the following one:
>
> 'ascii' codec can't decode byte 0xc3 in position 8: ordinal not in
> range(128) (por favior informe del error utilizando
>  File "/usr/lib/thuban/Thuban/UI/mainwindow.py", line 297, in
> invoke_command command.Execute(self.Context())
>  File "/usr/lib/thuban/Thuban/UI/mainwindow.py", line 779, in
> LayerProjection _("Layer Projection: %s") % layer.Title(), layer)

This seems to have to do with the title of your layer.
What kind of title does it have?
Could you provide an example Thuban session file 
with this layer for reproduction?

(Best is to add both to the issue tracker on 
http://wald.intevation.org/projects/thuban/

Can you also add the contents of the about dialog
and which locale you are running?
On a command line try:
   locales

> 'ascii' codec can't decode byte 0xc3 in position 10: ordinal not in
> range(128) (por favior informe del error utilizando

genSel is the result of self.genChoice.GetString(index)
hmm, given that you will probably use the Spanish translation
this would be msgstr "DistribuciÃ³n Uniforme" of course this cannot be
decoded to ascii.
Ah, I can reproduce this one with the German localisation.

> It is wonderful that with Python this tool GIS is being developed

Thanks for your feedback and the problem report!
Bernhard

-- 
Managing Director - Owner: www.intevation.net       (Free Software Company)
Germany Coordinator: fsfeurope.org. Coordinator: www.Kolab-Konsortium.com.
Intevation GmbH, Osnabrück, DE; Amtsgericht Osnabrück, HRB 18998
Geschäftsführer Frank Koormann, Bernhard Reiter, Dr. Jan-Oliver Wagner

---

From: Bernhard Reiter <[email-masked]>
Date: Wed, 25 Apr 2007 02:37:15 +0200

Hi Samuel,

On Tuesday 24 April 2007 17:32, Samuel Mesa wrote:
> I am using Thuban v1.2.0 but I have the following problems
>
> range(128)

thanks for the reports. The problems are fixed in SVN and will
be released with the next version.

You can try the attached patch, it should apply nicely even
on installed files.

BTW: Is there an Ubuntu package for Thuban 1.2.0 or did you build it yourself?

Best,
Bernhard

-- 
Managing Director - Owner: www.intevation.net       (Free Software Company)
Germany Coordinator: fsfeurope.org. Coordinator: www.Kolab-Konsortium.com.
Intevation GmbH, Osnabrück, DE; Amtsgericht Osnabrück, HRB 18998
Geschäftsführer Frank Koormann, Bernhard Reiter, Dr. Jan-Oliver Wagner
Index: Thuban/UI/__init__.py
===================================================================
--- Thuban/UI/__init__.py	(Revision 2758)
+++ Thuban/UI/__init__.py	(Arbeitskopie)
@@ -1,11 +1,15 @@
-# Copyright (c) 2001, 2002, 2003, 2005 by Intevation GmbH
+# Copyright (c) 2001, 2002, 2003, 2005, 2007 by Intevation GmbH
 # Authors:
-# Bernhard Herzog <[email-masked]>
+# Bernhard Herzog <[email-masked]>  2001, 2002, 2003, 2005
+# Bernhard Reiter <[email-masked]> 2007
 #
 # This program is free software under the GPL (>=v2)
 # Read the file COPYING coming with Thuban for details.

+
+_wx_can_be_imported = False
+
 _locale = None
 def install_wx_translation():
     """Install the wx translation function in Thuban.
@@ -14,10 +18,12 @@
     Thuban/__init__.py
     """
     global _locale
+    global _wx_can_be_imported
     import Thuban
     if not Thuban.translation_function_installed():
         # Only import wx modules when we actually can install the
         # function so that the test suite can inhibit this
+        _wx_can_be_imported = True
         import wx
         wx.Locale_AddCatalogLookupPathPrefix(Thuban._message_dir)
         _locale = wx.Locale(wx.LANGUAGE_DEFAULT)
@@ -75,3 +81,29 @@

 install_wx_translation()
+
+# We define a function that will return the internal representation
+# for a value returned from wxString.
+# This depends on if we have a unicode build and which encoding we run.
+internal_from_wxstring = lambda x: x  # identity
+
+def install_internal_from_wxstring():
+    """Install the needed internal_from_wxstring() function.
+
+    For unicode builds wxString will return a unicode object according to
+    the wxPython documentation (looked up in changelog coming with 2.6.3)
+    we need to convert this back to internal, unless we use unicode objects
+    internally already.
+
+    Otherwise no conversion will need to be done.
+    """
+    global _wx_can_be_imported
+    global internal_from_wxstring
+
+    if _wx_can_be_imported:
+        import Thuban
+        import wx
+        if wx.USE_UNICODE == 1 and Thuban.get_internal_encoding != "unicode":
+            internal_from_wxstring = lambda x : Thuban.internal_from_unicode(x)
+
+install_internal_from_wxstring()
Index: Thuban/UI/classgen.py
===================================================================
--- Thuban/UI/classgen.py	(Revision 2758)
+++ Thuban/UI/classgen.py	(Arbeitskopie)
@@ -25,6 +25,7 @@
 
 from Thuban.Model.layer import SHAPETYPE_ARC
 from Thuban.Model.range import Range
+from Thuban.UI import internal_from_wxstring
 from Thuban.UI.common import ThubanBeginBusyCursor, ThubanEndBusyCursor
 
 import classifier, resource
@@ -213,7 +214,7 @@
 
         assert index != -1, "button should be disabled!"
 
-        genSel = self.genChoice.GetString(index)
+        genSel = internal_from_wxstring(self.genChoice.GetString(index))
         clazz, genPanel = self.genChoice.GetClientData(index)
 
         propPanel = self.propPanel
Index: Thuban/UI/mainwindow.py
===================================================================
--- Thuban/UI/mainwindow.py	(Revision 2758)
+++ Thuban/UI/mainwindow.py	(Arbeitskopie)
@@ -29,6 +29,7 @@
 from Thuban.Model.session import create_empty_session
 from Thuban.Model.layer import Layer, RasterLayer
 from Thuban.Model.postgisdb import PostGISShapeStore, has_postgis_support
+from Thuban.UI import internal_from_wxstring
 from wx.lib.dialogs import MultipleChoiceDialog
 
 import view
@@ -514,8 +515,8 @@
             self.canvas.Destroy()
             self.Destroy()
 
-    def SetMap(self, map):
-        self.canvas.SetMap(map)
+    def SetMap(self, mymap):
+        self.canvas.SetMap(mymap)
         self.update_title()
 
         dialog = self.FindRegisteredDock("legend")
@@ -551,7 +552,6 @@
         name = "dbmanagement"
         dialog = self.get_open_dialog(name)
         if dialog is None:
-            map = self.canvas.Map()
             dialog = DBFrame(self, name, self.application.Session())
             self.add_dialog(name, dialog)
             dialog.Show()
@@ -564,11 +564,11 @@
                            _("All Files (*.*)") + "|*.*",
                            wx.OPEN | wx.MULTIPLE)
         if dlg.ShowModal() == wx.ID_OK:
-            filenames = dlg.GetPaths()
+            filenames = map(internal_from_wxstring, dlg.GetPaths())
             for filename in filenames:
                 title = os.path.splitext(os.path.basename(filename))[0]
-                map = self.canvas.Map()
-                has_layers = map.HasLayers()
+                mymap = self.canvas.Map()
+                has_layers = mymap.HasLayers()
                 try:
                     store = self.application.Session().OpenShapefile(filename)
                 except IOError:
@@ -577,7 +577,7 @@
                                        _("Can't open the file '%s'.")%filename)
                 else:
                     layer = Layer(title, store)
-                    map.AddLayer(layer)
+                    mymap.AddLayer(layer)
                     if not has_layers:
                         # if we're adding a layer to an empty map, fit the
                         # new map to the window
@@ -590,10 +590,10 @@
                            self.application.Path("data"), "", "*.*",
                            wx.OPEN)
         if dlg.ShowModal() == wx.ID_OK:
-            filename = dlg.GetPath()
+            filenames = map(internal_from_wxstring, dlg.GetPaths())
             title = os.path.splitext(os.path.basename(filename))[0]
-            map = self.canvas.Map()
-            has_layers = map.HasLayers()
+            mymap = self.canvas.Map()
+            has_layers = mymap.HasLayers()
             try:
                 layer = RasterLayer(title, filename)
             except IOError:
@@ -601,7 +601,7 @@
                 self.RunMessageBox(_("Add Image Layer"),
                                    _("Can't open the file '%s'.") % filename)
             else:
-                map.AddLayer(layer)
+                mymap.AddLayer(layer)
                 if not has_layers:
                     # if we're adding a layer to an empty map, fit the
                     # new map to the window
@@ -631,10 +631,10 @@
                                    % dbtable)
                 return
 
-            map = self.canvas.Map()
+            mymap = self.canvas.Map()
 
-            has_layers = map.HasLayers()
-            map.AddLayer(layer)
+            has_layers = mymap.HasLayers()
+            mymap.AddLayer(layer)
             if not has_layers:
                 self.canvas.FitMapToWindow()
 
@@ -759,9 +759,9 @@
         dialog = self.get_open_dialog(name)
 
         if dialog is None:
-            map = self.canvas.Map()
+            mymap = self.canvas.Map()
             dialog = projdialog.ProjFrame(self, name,
-                     _("Map Projection: %s") % map.Title(), map)
+                     _("Map Projection: %s") % mymap.Title(), mymap)
             self.add_dialog(name, dialog)
             dialog.Show()
         dialog.Raise()
@@ -774,7 +774,6 @@
         dialog = self.get_open_dialog(name)
 
         if dialog is None:
-            map = self.canvas.Map()
             dialog = projdialog.ProjFrame(self, name,
                      _("Layer Projection: %s") % layer.Title(), layer)
             self.add_dialog(name, dialog)
@@ -1035,7 +1034,7 @@
                 # FIXME: bring dialog to front?
                 pass
 
-    def title_changed(self, map):
+    def title_changed(self, mymap):
         """Subscribed to the canvas' TITLE_CHANGED messages"""
         self.update_title()
 
@@ -1052,9 +1051,9 @@
         class this usually only means that a different map has been set
         or the current map's title has changed.
         """
-        map = self.Map()
-        if map is not None:
-            title = _("Thuban - %s") % (map.Title(),)
+        mymap = self.Map()
+        if mymap is not None:
+            title = _("Thuban - %s") % (mymap.Title(),)
         else:
             title = _("Thuban")
         self.SetTitle(title)
@@ -1127,9 +1126,9 @@
     """Return true iff theres a visible map in the mainwindow.
 
     A visible map is a map with at least one visible layer."""
-    map = context.mainwindow.Map()
-    if map is not None:
-        for layer in map.Layers():
+    mymap = context.mainwindow.Map()
+    if mymap is not None:
+        for layer in mymap.Layers():
             if layer.Visible():
                 return True
     return False

---

From: Didrik Pinte <[email-masked]>
Date: Wed, 25 Apr 2007 08:59:19 +0200

> For the projection of layers

Great, this sounds clear.
	
> For the classification of the simbology

I will investigate on this too. I have enough information to correct the
problem.

Didrik

Ps : don't forget to send the mail to the thuban-list

---

From: Didrik Pinte <[email-masked]>
Date: Wed, 25 Apr 2007 09:02:11 +0200

Bernard,

Sorry for the noise, I did not see your mails before answering ;-)

This is all related to utf-8 encoding. 

Do we open a little bug in the tracker ? Or add it to bug [#118] (
http://wald.intevation.org/tracker/index.php?func=detail&aid=118&group_id=6&atid=105)

Didrik

---

From: Bernhard Reiter <[email-masked]>
Date: Wed, 25 Apr 2007 10:49:41 +0200

Didrik,

> http://wald.intevation.org/tracker/index.php?func=detail&aid=118&group_id=6

the problem is different from [#118] as there we are dealing with an input 
towards Thuban that we cannot reliably know the encoding of.

I have thought about and written an Thuban Enhancement Proposal and send
to thuban-devel@. I think this should be discussed next.

Best,
Bernhard