Sfoglia il codice sorgente

wxGUI: address flake8 undefined variable (#1325)

Anna Petrasova 4 anni fa
parent
commit
f02ee9c6c4

+ 2 - 1
gui/wxpython/.flake8

@@ -9,7 +9,6 @@ ignore =
     E741, # ambiguous variable name 'l'
     F403, # 'from gmodeler.model import *' used; unable to detect undefined names
     F405, # '_' may be undefined, or defined from star imports: gmodeler.model
-    F821, # undefined name '_'
     F841, # local variable 'dc' is assigned to but never used
     E117, # over-indented
     E122, # continuation line missing indentation or outdented
@@ -56,3 +55,5 @@ exclude =
     ctypes,
     pydispatch,
     testsuite,
+builtins =
+    _

+ 0 - 10
gui/wxpython/core/gcmd.py

@@ -335,14 +335,6 @@ def recv_some(p, t=.1, e=1, tr=5, stderr=0):
     return ''.join(y)
 
 
-def send_all(p, data):
-    while len(data):
-        sent = p.send(data)
-        if sent is None:
-            raise Exception(message)
-        data = buffer(data, sent)
-
-
 class Command:
     """Run command in separate thread. Used for commands launched
     on the background.
@@ -511,8 +503,6 @@ class Command:
 
         for type, msg in self.__ProcessStdErr():
             if type == 'ERROR':
-                if _enc:
-                    return unicode(msg, _enc)
                 return msg
 
         return ''

+ 1 - 1
gui/wxpython/core/render.py

@@ -175,7 +175,7 @@ class Layer(object):
                         first = False
             else:
                 self.renderMgr.Render(self.cmd, env)
-        except GException:
+        except GException as e:
             sys.stderr.write(
                 _("Command '%s' failed\n") %
                 self.GetCmd(

+ 2 - 4
gui/wxpython/gcp/manager.py

@@ -1517,13 +1517,11 @@ class GCP(MapFrame, ColumnSorterMixin):
 
         if not sourceMapWin:
             GError(parent=self,
-                   message="%s. %s%s" % (_("source mapwin not defined"),
-                                         os.linesep, err))
+                   message=_("source mapwin not defined"))
 
         if not targetMapWin:
             GError(parent=self,
-                   message="%s. %s%s" % (_("target mapwin not defined"),
-                                         os.linesep, err))
+                   message=_("target mapwin not defined"))
 
         try:
             f = open(self.file['points'], 'r')

+ 2 - 7
gui/wxpython/gui_core/ghelp.py

@@ -24,12 +24,6 @@ import re
 import textwrap
 import sys
 import six
-
-if sys.version_info.major == 2:
-    _unichr = unichr
-else:
-    _unichr = chr
-
 import wx
 from wx.html import HtmlWindow
 try:
@@ -44,6 +38,7 @@ except ImportError:
     from wx import AboutBox
 
 import grass.script as grass
+from grass.exceptions import CalledModuleError
 
 # needed just for testing
 if __name__ == '__main__':
@@ -924,7 +919,7 @@ def _grassDevTeam(start):
         end = date.today().year
 
     return '%(c)s %(start)s-%(end)s by the GRASS Development Team' % {
-        'c': _unichr(169), 'start': start, 'end': end}
+        'c': chr(169), 'start': start, 'end': end}
 
 
 def main():

+ 2 - 19
gui/wxpython/gui_core/goutput.py

@@ -19,7 +19,6 @@ This program is free software under the GNU General Public License
 @author Anna Kratochvilova <kratochanna gmail.com> (refactoring)
 """
 
-import os
 import textwrap
 
 import wx
@@ -32,7 +31,7 @@ if __name__ == '__main__':
     from grass.script.setup import set_gui_path
     set_gui_path()
 
-from core.gcmd import GError, EncodeString
+from core.gcmd import GError
 from core.gconsole   import GConsole, \
     EVT_CMD_OUTPUT, EVT_CMD_PROGRESS, EVT_CMD_RUN, EVT_CMD_DONE, \
     Notification
@@ -671,23 +670,7 @@ class GStc(stc.StyledTextCtrl):
                     self.AddText(seg)
         else:
             self.linePos = self.GetCurrentPos()
-
-            try:
-                self.AddText(txt)
-            except UnicodeDecodeError:
-                # TODO: this might be dead code for Py3, txt is already unicode?
-                enc = UserSettings.Get(
-                    group='atm', key='encoding', subkey='value')
-                if enc:
-                    txt = unicode(txt, enc, errors='replace')
-                elif 'GRASS_DB_ENCODING' in os.environ:
-                    txt = unicode(
-                        txt, os.environ['GRASS_DB_ENCODING'],
-                        errors='replace')
-                else:
-                    txt = EncodeString(txt)
-
-                self.AddText(txt)
+            self.AddText(txt)
 
         # reset output window to read only
         self.SetReadOnly(True)

+ 2 - 4
gui/wxpython/image2target/ii2t_manager.py

@@ -1510,13 +1510,11 @@ class GCP(MapFrame, ColumnSorterMixin):
 
         if not sourceMapWin:
             GError(parent=self,
-                   message="%s. %s%s" % (_("source mapwin not defined"),
-                                         os.linesep, err))
+                   message=_("source mapwin not defined"))
 
         if not targetMapWin:
             GError(parent=self,
-                   message="%s. %s%s" % (_("target mapwin not defined"),
-                                         os.linesep, err))
+                   message=_("target mapwin not defined"))
 
         try:
             f = open(self.file['control_points'], 'r')

File diff suppressed because it is too large
+ 0 - 2063
gui/wxpython/image2target/ii2t_menustrings.py


+ 0 - 6
gui/wxpython/iscatt/controllers.py

@@ -747,12 +747,6 @@ class CategoriesManager:
     def GetCategories(self):
         return self.cats_ids[:]
 
-    def SetCategoryPosition(self):
-        if newindex > oldindex:
-            newindex -= 1
-
-        self.cats_ids.insert(newindex, self.cats_ids.pop(oldindex))
-
     def ExportCatRast(self, cat_id):
 
         cat_attrs = self.GetCategoryAttrs(cat_id)

+ 2 - 2
gui/wxpython/iscatt/frame.py

@@ -28,7 +28,7 @@ import wx.lib.scrolledpanel as scrolled
 import wx.lib.mixins.listctrl as listmix
 
 from core import globalvar
-from core.gcmd import GError
+from core.gcmd import GError, GMessage
 
 from gui_core.dialogs import SetOpacityDialog
 from gui_core.wrap import StaticBox, Menu, ListCtrl
@@ -578,7 +578,7 @@ class CategoryListCtrl(ListCtrl,
         item = menu.Append(wx.ID_ANY, _("Set color"))
         self.Bind(wx.EVT_MENU, self.OnSetColor, item)
 
-        item = menu.Append(item_id, _("Change opacity level"))
+        item = menu.Append(wx.ID_ANY, _("Change opacity level"))
         self.Bind(wx.EVT_MENU, self.OnPopupOpacityLevel, item)
 
         if showed:

+ 2 - 2
gui/wxpython/iscatt/plots.py

@@ -479,7 +479,7 @@ def MergeImg(cats_order, scatts, styles, rend_dt, output_queue):
             vmax = np.amax(masked_cat)
             # totally empty -> no need to render
             if vmax == 0:
-                render_cat_ids[cat_id] = None
+                rend_dt[cat_id] = None
                 continue
 
             cmap = _getColorMap(cat_id, styles)
@@ -1022,7 +1022,7 @@ def imshow(axes, X, cmap=None, norm=None, aspect=None,
     if norm is not None:
         assert(isinstance(norm, mcolors.Normalize))
     if aspect is None:
-        aspect = rcParams['image.aspect']
+        aspect = matplotlib.rcParams['image.aspect']
     axes.set_aspect(aspect)
 
     if extent:

+ 0 - 15
gui/wxpython/location_wizard/wizard.py

@@ -2228,21 +2228,6 @@ class SummaryPage(TitledPage):
 
         self.lprojection.SetLabel(label)
 
-    def OnFinish(self, event):
-        dlg = wx.MessageDialog(
-            parent=self.wizard,
-            message=_("Do you want to create GRASS location <%s>?") %
-            location,
-            caption=_("Create new location?"),
-            style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
-
-        if dlg.ShowModal() == wx.ID_NO:
-            dlg.Destroy()
-            event.Veto()
-        else:
-            dlg.Destroy()
-            event.Skip()
-
 
 class LocationWizard(wx.Object):
     """Start wizard here and finish wizard here

+ 1 - 1
gui/wxpython/modules/colorrules.py

@@ -675,7 +675,7 @@ class ColorTable(wx.Frame):
 
         if os.path.exists(path):
             dlgOw = wx.MessageDialog(
-                parent,
+                self,
                 message=_(
                     "File <%s> already already exists. "
                     "Do you want to overwrite it?") %

+ 2 - 4
gui/wxpython/photo2image/ip2i_manager.py

@@ -861,13 +861,11 @@ class GCP(MapFrame, ColumnSorterMixin):
 
         if not sourceMapWin:
             GError(parent=self,
-                   message="%s. %s%s" % (_("source mapwin not defined"),
-                                         os.linesep, err))
+                   message=_("source mapwin not defined"))
 
         if not targetMapWin:
             GError(parent=self,
-                   message="%s. %s%s" % (_("target mapwin not defined"),
-                                         os.linesep, err))
+                   message=_("target mapwin not defined"))
 
         try:
             f = open(self.file['points'], 'r')

+ 1 - 1
gui/wxpython/psmap/utils.py

@@ -27,7 +27,7 @@ except ImportError:
     havePILImage = False
 
 import grass.script as grass
-from core.gcmd import RunCommand
+from core.gcmd import RunCommand, GError
 
 
 class Rect2D(wx.Rect2D):

+ 0 - 7
gui/wxpython/rlisetup/sampling_frame.py

@@ -29,13 +29,6 @@ from core.gcmd import RunCommand
 import grass.script.core as grass
 from core import gcmd
 
-try:
-    from grass.lib.gis import *
-    from grass.lib.vector import *
-    from grass.lib.raster import *
-except ImportError:
-    pass
-
 from core.giface import StandaloneGrassInterface
 from mapwin.base import MapWindowProperties
 from mapwin.buffered import BufferedMapWindow

+ 1 - 0
gui/wxpython/vdigit/mapwindow.py

@@ -26,6 +26,7 @@ from core.debug import Debug
 from mapwin.buffered import BufferedMapWindow
 from core.settings import UserSettings
 from core.utils import ListOfCatsToRange
+from core.units import ConvertValue as UnitsConvertValue
 from core.globalvar import QUERYLAYER
 from vdigit.dialogs import VDigitCategoryDialog, VDigitZBulkDialog, VDigitDuplicatesDialog
 from gui_core import gselect

+ 1 - 0
gui/wxpython/vnet/dialogs.py

@@ -26,6 +26,7 @@ This program is free software under the GNU General Public License
 
 import os
 import sys
+import math
 import six
 
 if sys.version_info.major >= 3:

+ 1 - 0
gui/wxpython/vnet/vnet_core.py

@@ -19,6 +19,7 @@ This program is free software under the GNU General Public License
 @author Eliska Kyzlikova <eliska.kyzlikova gmail.com> (turn costs support)
 """
 
+import math
 import six
 from grass.script.utils import try_remove
 from grass.script import core as grass

+ 1 - 0
gui/wxpython/vnet/vnet_data.py

@@ -23,6 +23,7 @@ This program is free software under the GNU General Public License
 @author Eliska Kyzlikova <eliska.kyzlikova gmail.com> (turn costs support)
 """
 import os
+import math
 import six
 from copy import deepcopy
 

+ 2 - 0
gui/wxpython/vnet/widgets.py

@@ -28,6 +28,8 @@ from wx.lib.mixins.listctrl import ColumnSorterMixin, \
     ListCtrlAutoWidthMixin
 
 from core import globalvar
+from core.gcmd import GError
+from gui_core.widgets import FloatValidator, IntegerValidator
 from gui_core.wrap import (
     BitmapFromImage, Button, ComboBox, ListCtrl, Panel, StaticBox,
     StaticText, TextCtrl, CheckListCtrlMixin

+ 1 - 0
gui/wxpython/wxplot/base.py

@@ -19,6 +19,7 @@ import os
 import six
 
 import wx
+from random import randint
 
 import wx.lib.plot as plot
 from core.globalvar import ICONDIR