浏览代码

iclass + iscatt: fixes for Python3 (#316)

Anna Petrasova 5 年之前
父节点
当前提交
5ae7bb6014

+ 3 - 1
gui/wxpython/iclass/dialogs.py

@@ -579,7 +579,9 @@ class CategoryListCtrl(ListCtrl,
         text_c = wx.Colour(*ContrastColor(back_c))
 
         # if it is in scope of the method, gui falls, using self solved it
-        self.l = wx.ListItemAttr(colText=text_c, colBack=back_c)
+        self.l = wx.ListItemAttr()
+        self.l.SetBackgroundColour(back_c)
+        self.l.SetTextColour(text_c)
         return self.l
 
 

+ 2 - 2
gui/wxpython/iclass/digit.py

@@ -52,7 +52,7 @@ class IClassVDigitWindow(VDigitWindow):
             return
 
         region = grass.region()
-        e, n = self.Pixel2Cell(event.GetPositionTuple())
+        e, n = self.Pixel2Cell(event.GetPosition())
         if not((region['s'] <= n <= region['n'])
                and(region['w'] <= e <= region['e'])):
             GWarning(
@@ -103,7 +103,7 @@ class IClassVDigitWindow(VDigitWindow):
 
     def GetCategoryColor(self, cat):
         """Get color associated with given category"""
-        r, g, b = map(int, self.parent.GetClassColor(cat).split(':'))
+        r, g, b = [int(x) for x in self.parent.GetClassColor(cat).split(':')][:3]
         return wx.Colour(r, g, b)
 
 

+ 1 - 1
gui/wxpython/iclass/frame.py

@@ -870,7 +870,7 @@ class IClassMapFrame(DoubleMapFrame):
         :param value: new value
         :param cat: which category to update
         """
-        if isinstance(value, (types.IntType, types.FloatType)):
+        if isinstance(value, (int, float)):
             tmpFile.write("UPDATE %s SET %s = %d WHERE cat = %d\n" %
                           (table, column, value, cat))
         else:

+ 2 - 2
gui/wxpython/iclass/statistics.py

@@ -138,12 +138,12 @@ class Statistics:
         name = c_char_p()
         I_iclass_statistics_get_name(cStatistics, byref(name))
         if self.name != name.value:
-            set_stats["name"] = name.value
+            set_stats["name"] = grass.decode(name.value)
 
         color = c_char_p()
         I_iclass_statistics_get_color(cStatistics, byref(color))
         if self.color != color.value:
-            set_stats["color"] = color.value
+            set_stats["color"] = grass.decode(color.value)
 
         nbands = c_int()
         I_iclass_statistics_get_nbands(cStatistics, byref(nbands))

+ 1 - 1
gui/wxpython/iclass/toolbars.py

@@ -207,7 +207,7 @@ class IClassToolbar(BaseToolbar):
 
         if cat:
             stat = self.stats_data.GetStatistics(cat)
-            back_c = wx.Colour(*map(int, stat.color.split(':')))
+            back_c = wx.Colour([int(x) for x in stat.color.split(':')])
             text_c = wx.Colour(*ContrastColor(back_c))
         else:
             back_c = wx.SystemSettings.GetColour(wx.SYS_COLOUR_BACKGROUND)

+ 2 - 1
gui/wxpython/iscatt/core_c.py

@@ -24,6 +24,7 @@ except ImportError as e:
     sys.stderr.write(_("Loading ctypes libs failed"))
 
 from core.gcmd import GException
+from grass.script import encode
 
 
 def Rasterize(polygon, rast, region, value):
@@ -207,7 +208,7 @@ def _stringListToCharArr(str_list):
     char_arr = arr()
     for i, st in enumerate(str_list):
         if st:
-            char_arr[i] = st
+            char_arr[i] = encode(st)
         else:
             char_arr[i] = None
 

+ 4 - 2
gui/wxpython/iscatt/dialogs.py

@@ -417,7 +417,9 @@ class SettingsDialog(wx.Dialog):
         gridSizer = wx.GridBagSizer(vgap=1, hgap=1)
 
         row = 0
-        setts = dict(self.colorsSetts.items() + self.sizeSetts.items())
+        setts = dict()
+        setts.update(self.colorsSetts)
+        setts.update(self.sizeSetts)
 
         settsOrder = ["sel_pol", "sel_pol_vertex", "sel_area",
                       "sel_area_opacty", "snap_tresh"]
@@ -449,7 +451,7 @@ class SettingsDialog(wx.Dialog):
                       flag=wx.ALIGN_CENTER_VERTICAL,
                       pos=(row, 0))
 
-        gridSizer.AddGrowableCol(1)
+        gridSizer.AddGrowableCol(0)
         ellPolBoxSizer.Add(gridSizer, flag=wx.EXPAND)
 
         btnSizer = wx.BoxSizer(wx.HORIZONTAL)

+ 3 - 1
gui/wxpython/iscatt/frame.py

@@ -555,7 +555,9 @@ class CategoryListCtrl(ListCtrl,
                 wx.SYS_COLOUR_INACTIVECAPTIONTEXT)
 
         # if it is in scope of the method, gui falls, using self solved it
-        self.l = wx.ListItemAttr(colText=text_c, colBack=back_c)
+        self.l = wx.ListItemAttr()
+        self.l.SetBackgroundColour(back_c)
+        self.l.SetTextColour(text_c)
         return self.l
 
     def OnCategoryRightUp(self, event):

+ 5 - 5
gui/wxpython/iscatt/iscatt_core.py

@@ -34,7 +34,7 @@ from core.gcmd import GException, GError, RunCommand
 
 import grass.script as grass
 
-from core_c import CreateCatRast, ComputeScatts, UpdateCatRast, \
+from iscatt.core_c import CreateCatRast, ComputeScatts, UpdateCatRast, \
     Rasterize, SC_SCATT_DATA, SC_SCATT_CONDITIONS
 
 MAX_SCATT_SIZE = 4100 * 4100
@@ -270,7 +270,7 @@ class CatRastUpdater:
             if not areas_cats[c]:
                 continue
 
-            layer = areas_cats[c].keys()[0]
+            layer = list(areas_cats[c])[0]
             cat = areas_cats[c][layer][0]
 
             if cat in rasterized_cats:
@@ -812,7 +812,7 @@ def idScattToidBands(scatt_id, n_bands):
     band_1 = (int)(
         (2 * n_b1 + 1 - sqrt(((2 * n_b1 + 1) * (2 * n_b1 + 1) - 8 * scatt_id))) / 2)
 
-    band_2 = scatt_id - (band_1 * (2 * n_b1 + 1) - band_1 * band_1) / 2 + band_1 + 1
+    band_2 = int(scatt_id - (band_1 * (2 * n_b1 + 1) - band_1 * band_1) / 2 + band_1 + 1)
 
     return band_1, band_2
 
@@ -826,8 +826,8 @@ def idBandsToidScatt(band_1_id, band_2_id, n_bands):
 
     n_b1 = n_bands - 1
 
-    scatt_id = (
-        band_1_id * (2 * n_b1 + 1) - band_1_id * band_1_id) / 2 + band_2_id - band_1_id - 1
+    scatt_id = int((
+        band_1_id * (2 * n_b1 + 1) - band_1_id * band_1_id) / 2 + band_2_id - band_1_id - 1)
 
     return scatt_id
 

+ 4 - 6
gui/wxpython/iscatt/plots.py

@@ -25,7 +25,7 @@ from copy import deepcopy
 from iscatt.core_c import MergeArrays, ApplyColormap
 from iscatt.dialogs import ManageBusyCursorMixin
 from core.settings import UserSettings
-from gui_core.wrap import Menu
+from gui_core.wrap import Menu, NewId
 
 try:
     import matplotlib
@@ -276,9 +276,7 @@ class ScatterPlotWidget(wx.Panel, ManageBusyCursorMixin):
             self.axes.add_artist(ellip)
             callafter_list.append([self.axes.draw_artist, [ellip]])
 
-            color = map(
-                lambda v: int(v) / 255.0,
-                styles[cat_id]['color'].split(":"))
+            color = [int(v) / 255.0 for v in styles[cat_id]['color'].split(":")[:3]]
 
             ellip = Ellipse(xy=e['pos'],
                             width=e['width'],
@@ -620,8 +618,8 @@ class ScatterPlotContextMenu:
                            lambda event: self.plot.ZoomToExtend()]]
 
             for item in menu_items:
-                item_id = wx.ID_ANY
-                menu.Append(item_id, text=item[1])
+                item_id = NewId()
+                menu.Append(item_id, item[1])
                 menu.Bind(wx.EVT_MENU, item[2], id=item_id)
 
             wx.CallAfter(self.ShowMenu, menu)

+ 4 - 4
gui/wxpython/iscatt/toolbars.py

@@ -73,7 +73,7 @@ class MainToolbar(BaseToolbar):
              lambda event: self.scatt_mgr.AddScattPlot()),
             (None,),
             ("cats_mgr", icons['cats_mgr'],
-             lambda event: self.parent.ShowCategoryPanel(event.Checked()),
+             lambda event: self.parent.ShowCategoryPanel(event.IsChecked()),
              wx.ITEM_CHECK),
             (None,),
             ("pan", icons["pan"],
@@ -105,7 +105,7 @@ class MainToolbar(BaseToolbar):
 
     def SetPloltsMode(self, event, tool_name):
         self.scatt_mgr.modeSet.disconnect(self.ModeSet)
-        if event.Checked() == True:
+        if event.IsChecked():
             for i_tool_data in self._data:
                 i_tool_name = i_tool_data[0]
                 if not i_tool_name or i_tool_name in [
@@ -124,7 +124,7 @@ class MainToolbar(BaseToolbar):
     def ActivateSelectionPolygonMode(self, event):
 
         activated = self.scatt_mgr.ActivateSelectionPolygonMode(
-            event.Checked())
+            event.IsChecked())
         self.parent.ShowPlotEditingToolbar(activated)
 
         i_tool_id = vars(self)['sel_pol_mode']
@@ -217,7 +217,7 @@ class EditingToolbar(BaseToolbar):
 
     def SetMode(self, event, tool_name):
         self.scatt_mgr.modeSet.disconnect(self.ModeSet)
-        if event.Checked() == True:
+        if event.IsChecked():
             for i_tool_data in self._data:
                 i_tool_name = i_tool_data[0]
                 if not i_tool_name: