Browse Source

several fixes related to font dialog (#292)

* fix wx depracated warnings

* d.text depends on region, region needs to match widget size

* close file in grass.script.region_env to avoid Py3 ResourceWarning
Anna Petrasova 5 years ago
parent
commit
c3827c8f86
2 changed files with 17 additions and 16 deletions
  1. 5 4
      gui/wxpython/gui_core/dialogs.py
  2. 12 12
      lib/python/script/core.py

+ 5 - 4
gui/wxpython/gui_core/dialogs.py

@@ -53,7 +53,7 @@ from gui_core.widgets import SingleSymbolPanel, GListCtrl, SimpleValidator, MapV
 from core.settings import UserSettings
 from core.debug import Debug
 from gui_core.wrap import SpinCtrl, TextCtrl, Button, CheckListBox, \
-    StaticText, StaticBox, Menu, NewId
+    StaticText, StaticBox, Menu, NewId, EmptyBitmap
 
 
 class SimpleDialog(wx.Dialog):
@@ -2445,7 +2445,7 @@ class DefaultFontDialog(wx.Dialog):
         gridSizer.Add(self.fontlb,
                       flag=wx.EXPAND, pos=(1, 0))
 
-        self.renderfont = wx.StaticBitmap(panel, -1, wx.EmptyBitmapRGBA(100, 50, 255, 255, 255))
+        self.renderfont = wx.StaticBitmap(panel, -1, wx.Bitmap.FromRGBA(100, 50, 255, 255, 255))
         gridSizer.Add(self.renderfont,
                       flag=wx.EXPAND, pos=(2, 0))
 
@@ -2594,10 +2594,11 @@ class DefaultFontDialog(wx.Dialog):
         env['GRASS_RENDER_WIDTH'] = str(size[0])
         env['GRASS_RENDER_HEIGHT'] = str(size[1])
         env['GRASS_RENDER_FILE'] = self.tmp_file
-        ret = RunCommand('d.text', text=text, font=font, align='cc', at='50,50',
+        env['GRASS_REGION'] = grass.region_env(s=0, n=size[1], w=0, e=size[0])
+        ret = RunCommand('d.text', text=text, font=font, align='cc', at='50,60',
                          size=80, color='black', env=env)
         if ret == 0:
             self.renderfont.SetBitmap(wx.Bitmap(self.tmp_file))
         else:
-            self.renderfont.SetBitmap(wx.EmptyBitmapRGBA(size[0], size[1]))
+            self.renderfont.SetBitmap(EmptyBitmap(size[0], size[1]))
         try_remove(self.tmp_file)

+ 12 - 12
lib/python/script/core.py

@@ -1219,18 +1219,18 @@ def region_env(region3d=False, flags=None, env=None, **kwargs):
     gis_env = gisenv(env)
     windfile = os.path.join(gis_env['GISDBASE'], gis_env['LOCATION_NAME'],
                             gis_env['MAPSET'], "WIND")
-    fd = open(windfile, "r")
-    grass_region = ''
-    for line in fd.readlines():
-        key, value = map(lambda x: x.strip(), line.split(":", 1))
-        if kwargs and key not in ('proj', 'zone'):
-            continue
-        if not kwargs and not region3d and \
-                key in ('top', 'bottom', 'cols3', 'rows3',
-                        'depths', 'e-w resol3', 'n-s resol3', 't-b resol'):
-            continue
-
-        grass_region += '%s: %s;' % (key, value)
+    with open(windfile, "r") as fd:
+        grass_region = ''
+        for line in fd.readlines():
+            key, value = map(lambda x: x.strip(), line.split(":", 1))
+            if kwargs and key not in ('proj', 'zone'):
+                continue
+            if not kwargs and not region3d and \
+                    key in ('top', 'bottom', 'cols3', 'rows3',
+                            'depths', 'e-w resol3', 'n-s resol3', 't-b resol'):
+                continue
+
+            grass_region += '%s: %s;' % (key, value)
 
     if not kwargs:  # return current region
         return grass_region