[GRASS-SVN] r73434 - in grass/branches/releasebranch_7_6/gui/wxpython: gui_core psmap
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Sep 26 18:59:30 PDT 2018
Author: annakrat
Date: 2018-09-26 18:59:30 -0700 (Wed, 26 Sep 2018)
New Revision: 73434
Modified:
grass/branches/releasebranch_7_6/gui/wxpython/gui_core/wrap.py
grass/branches/releasebranch_7_6/gui/wxpython/psmap/frame.py
Log:
wxGUI/psmap: backport some wxPython4 changes from trunk
Modified: grass/branches/releasebranch_7_6/gui/wxpython/gui_core/wrap.py
===================================================================
--- grass/branches/releasebranch_7_6/gui/wxpython/gui_core/wrap.py 2018-09-26 22:00:45 UTC (rev 73433)
+++ grass/branches/releasebranch_7_6/gui/wxpython/gui_core/wrap.py 2018-09-27 01:59:30 UTC (rev 73434)
@@ -17,6 +17,10 @@
import wx
import wx.lib.buttons as buttons
+try:
+ import wx.lib.agw.customtreectrl as CT
+except ImportError:
+ import wx.lib.customtreectrl as CT
from core.globalvar import gtk3, wxPythonPhoenix
if wxPythonPhoenix:
@@ -99,6 +103,32 @@
wx.Button.SetToolTipString(self, tip)
+class RadioButton(wx.RadioButton):
+ """Wrapper around wx.RadioButton to have more control
+ over the widget on different platforms/wxpython versions"""
+ def __init__(self, *args, **kwargs):
+ wx.RadioButton.__init__(self, *args, **kwargs)
+
+ def SetToolTip(self, tip):
+ if wxPythonPhoenix:
+ wx.RadioButton.SetToolTip(self, tipString=tip)
+ else:
+ wx.RadioButton.SetToolTipString(self, tip)
+
+
+class BitmapButton(wx.BitmapButton):
+ """Wrapper around wx.BitmapButton to have more control
+ over the widget on different platforms/wxpython versions"""
+ def __init__(self, *args, **kwargs):
+ wx.BitmapButton.__init__(self, *args, **kwargs)
+
+ def SetToolTip(self, tip):
+ if wxPythonPhoenix:
+ wx.BitmapButton.SetToolTip(self, tipString=tip)
+ else:
+ wx.BitmapButton.SetToolTipString(self, tip)
+
+
class GenBitmapButton(buttons.GenBitmapButton):
"""Wrapper around GenBitmapButton to have more control
over the widget on different platforms/wxpython versions"""
@@ -151,6 +181,19 @@
wx.StaticBox.SetToolTipString(self, tip)
+class CheckListBox(wx.CheckListBox):
+ """Wrapper around wx.CheckListBox to have more control
+ over the widget on different platforms/wxpython versions"""
+ def __init__(self, *args, **kwargs):
+ wx.CheckListBox.__init__(self, *args, **kwargs)
+
+ def SetToolTip(self, tip):
+ if wxPythonPhoenix:
+ wx.CheckListBox.SetToolTip(self, tipString=tip)
+ else:
+ wx.CheckListBox.SetToolTipString(self, tip)
+
+
class TextCtrl(wx.TextCtrl):
"""Wrapper around wx.TextCtrl to have more control
over the widget on different platforms/wxpython versions"""
@@ -215,6 +258,19 @@
return wx.TreeCtrl.GetPyData(self, item)
+class CustomTreeCtrl(CT.CustomTreeCtrl):
+ """Wrapper around wx.lib.agw.customtreectrl to have more control
+ over the widget on different platforms/wxpython versions"""
+ def __init__(self, *args, **kwargs):
+ CT.CustomTreeCtrl.__init__(self, *args, **kwargs)
+
+ def SetToolTip(self, tip):
+ if wxPythonPhoenix:
+ CT.CustomTreeCtrl.SetToolTip(self, tipString=tip)
+ else:
+ CT.CustomTreeCtrl.SetToolTipString(self, tip)
+
+
class ToolBar(wx.ToolBar):
"""Wrapper around wx.ToolBar to have more control
over the widget on different platforms/wxpython versions"""
@@ -274,6 +330,12 @@
def __init__(self, *args, **kwargs):
super(PseudoDC, self).__init__(*args, **kwargs)
+ def DrawLinePoint(self, pt1, pt2):
+ if wxPythonPhoenix:
+ super(PseudoDC, self).DrawLine(pt1, pt2)
+ else:
+ super(PseudoDC, self).DrawLinePoint(pt1, pt2)
+
def DrawRectangleRect(self, rect):
if wxPythonPhoenix:
super(PseudoDC, self).DrawRectangle(rect=rect)
@@ -289,6 +351,19 @@
super(PseudoDC, self).EndDrawing()
+class ClientDC(wx.ClientDC):
+ """Wrapper around wx.ClientDC to have more control
+ over the widget on different platforms/wxpython versions"""
+ def __init__(self, *args, **kwargs):
+ super(ClientDC, self).__init__(*args, **kwargs)
+
+ def GetFullMultiLineTextExtent(self, string, font=None):
+ if wxPythonPhoenix:
+ return super(ClientDC, self).GetFullMultiLineTextExtent(string, font)
+ else:
+ return super(ClientDC, self).GetMultiLineTextExtent(string, font)
+
+
class Rect(wx.Rect):
"""Wrapper around wx.Rect to have more control
over the widget on different platforms/wxpython versions"""
@@ -319,3 +394,16 @@
wx.CheckBox.SetToolTip(self, tipString=tip)
else:
wx.CheckBox.SetToolTipString(self, tip)
+
+
+class Choice(wx.Choice):
+ """Wrapper around wx.Choice to have more control
+ over the widget on different platforms/wxpython versions"""
+ def __init__(self, *args, **kwargs):
+ wx.Choice.__init__(self, *args, **kwargs)
+
+ def SetToolTip(self, tip):
+ if wxPythonPhoenix:
+ wx.Choice.SetToolTip(self, tipString=tip)
+ else:
+ wx.Choice.SetToolTipString(self, tip)
Modified: grass/branches/releasebranch_7_6/gui/wxpython/psmap/frame.py
===================================================================
--- grass/branches/releasebranch_7_6/gui/wxpython/psmap/frame.py 2018-09-26 22:00:45 UTC (rev 73433)
+++ grass/branches/releasebranch_7_6/gui/wxpython/psmap/frame.py 2018-09-27 01:59:30 UTC (rev 73434)
@@ -39,7 +39,7 @@
from gui_core.forms import GUI
from gui_core.dialogs import HyperlinkDialog
from gui_core.ghelp import ShowAboutDialog
-from gui_core.wrap import PseudoDC
+from gui_core.wrap import ClientDC, PseudoDC, Rect, StockCursor, EmptyBitmap
from psmap.menudata import PsMapMenuData
from gui_core.toolbars import ToolSwitcher
@@ -103,10 +103,10 @@
}
# available cursors
self.cursors = {
- "default": wx.StockCursor(wx.CURSOR_ARROW),
- "cross": wx.StockCursor(wx.CURSOR_CROSS),
- "hand": wx.StockCursor(wx.CURSOR_HAND),
- "sizenwse": wx.StockCursor(wx.CURSOR_SIZENWSE)
+ "default": StockCursor(wx.CURSOR_ARROW),
+ "cross": StockCursor(wx.CURSOR_CROSS),
+ "hand": StockCursor(wx.CURSOR_HAND),
+ "sizenwse": StockCursor(wx.CURSOR_SIZENWSE)
}
# pen and brush
self.pen = {
@@ -855,9 +855,9 @@
if 0 < rotation < pi:
Y = y - H
if rotation == 0:
- return wx.Rect(x, y, *textExtent)
+ return Rect(x, y, *textExtent)
else:
- return wx.Rect(X, Y, abs(W), abs(H)).Inflate(h, h)
+ return Rect(X, Y, abs(W), abs(H)).Inflate(h, h)
def makePSFont(self, textDict):
"""creates a wx.Font object from selected postscript font. To be
@@ -911,13 +911,13 @@
"""Estimates bounding rectangle of text"""
#fontsize = str(fontsize if fontsize >= 4 else 4)
# dc created because of method GetTextExtent, which pseudoDC lacks
- dc = wx.ClientDC(self)
+ dc = ClientDC(self)
fn = self.makePSFont(textDict)
try:
dc.SetFont(fn)
- w, h, lh = dc.GetMultiLineTextExtent(textDict['text'])
+ w, h, lh = dc.GetFullMultiLineTextExtent(textDict['text'])
return (w, h)
except:
return (0, 0)
@@ -1255,7 +1255,7 @@
self.pdcImage = PseudoDC()
self.SetClientSize((700, 510)) # ?
- self._buffer = wx.EmptyBitmap(*self.GetClientSize())
+ self._buffer = EmptyBitmap(*self.GetClientSize())
self.idBoxTmp = wx.NewId()
self.idZoomBoxTmp = wx.NewId()
@@ -1362,7 +1362,7 @@
x = cW / 2 - pW / 2
y = cH / 2 - pH / 2
- self.DrawPaper(wx.Rect(x, y, pW, pH))
+ self.DrawPaper(Rect(x, y, pW, pH))
def modifyRectangle(self, r):
"""Recalculates rectangle not to have negative size"""
@@ -1501,7 +1501,7 @@
else:
self.mouse['use'] = 'zoomout'
- zoomFactor, view = self.ComputeZoom(wx.Rect(0, 0, 0, 0))
+ zoomFactor, view = self.ComputeZoom(Rect(0, 0, 0, 0))
self.Zoom(zoomFactor, view)
self.mouse['use'] = oldUse
@@ -1694,7 +1694,7 @@
self.dragId].type].updateDialog()
elif self.mouse['use'] in ('addPoint', 'addLine', 'addRectangle'):
- endCoordinates = self.CanvasPaperCoordinates(rect=wx.Rect(
+ endCoordinates = self.CanvasPaperCoordinates(rect=Rect(
event.GetX(), event.GetY(), 0, 0), canvasToPaper=True)[:2]
diffX = event.GetX() - self.mouse['begin'][0]
@@ -1710,7 +1710,7 @@
return
beginCoordinates = self.CanvasPaperCoordinates(
- rect=wx.Rect(
+ rect=Rect(
self.mouse['begin'][0],
self.mouse['begin'][1],
0, 0),
@@ -1772,7 +1772,7 @@
if self.mouse['use'] in (
'zoomin', 'zoomout', 'addMap', 'addLine', 'addRectangle'):
self.mouse['end'] = event.GetPosition()
- r = wx.Rect(
+ r = Rect(
self.mouse['begin'][0],
self.mouse['begin'][1],
self.mouse['end'][0] -
@@ -1847,7 +1847,7 @@
if newWidth < 10 or newHeight < 10:
return
- bounds = wx.Rect(x, y, newWidth, newHeight)
+ bounds = Rect(x, y, newWidth, newHeight)
self.Draw(
pen=self.pen['map'],
brush=self.brush['map'],
@@ -1897,7 +1897,7 @@
# update paper coordinates
points[self.currentLinePoint] = self.CanvasPaperCoordinates(
- rect=wx.RectPS(pos, (0, 0)), canvasToPaper=True)[:2]
+ rect=Rect(pos[0], pos[1], 0, 0), canvasToPaper=True)[:2]
self.RedrawSelectBox(self.dragId)
@@ -2149,7 +2149,7 @@
self.Zoom(zoomFactor, view)
def Draw(self, pen, brush, pdc, drawid=None, pdctype='rect',
- bb=wx.Rect(0, 0, 0, 0), lineCoords=None):
+ bb=Rect(0, 0, 0, 0), lineCoords=None):
"""Draw object with given pen and brush.
:param pdc: PseudoDC
@@ -2183,7 +2183,7 @@
if pdctype == 'rectText':
# dc created because of method GetTextExtent, which pseudoDC lacks
- dc = wx.ClientDC(self)
+ dc = ClientDC(self)
font = dc.GetFont()
size = 10
font.SetPointSize(size)
@@ -2191,17 +2191,17 @@
dc.SetFont(font)
pdc.SetFont(font)
text = '\n'.join(self.itemLabels[drawid])
- w, h, lh = dc.GetMultiLineTextExtent(text)
+ w, h, lh = dc.GetFullMultiLineTextExtent(text)
textExtent = (w, h)
- textRect = wx.Rect(0, 0, *textExtent).CenterIn(bb)
+ textRect = Rect(0, 0, *textExtent).CenterIn(bb)
r = map(int, bb)
- while not wx.Rect(*r).ContainsRect(textRect) and size >= 8:
+ while not Rect(*r).ContainsRect(textRect) and size >= 8:
size -= 2
font.SetPointSize(size)
dc.SetFont(font)
pdc.SetFont(font)
textExtent = dc.GetTextExtent(text)
- textRect = wx.Rect(0, 0, *textExtent).CenterIn(bb)
+ textRect = Rect(0, 0, *textExtent).CenterIn(bb)
pdc.SetTextForeground(wx.Colour(100, 100, 100, 200))
pdc.SetBackgroundMode(wx.TRANSPARENT)
pdc.DrawLabel(text=text, rect=textRect)
@@ -2327,7 +2327,7 @@
else:
pdc.DrawRotatedText(textDict['text'], coords[0], coords[1], rot)
- pdc.SetIdBounds(drawId, wx.Rect(*bounds))
+ pdc.SetIdBounds(drawId, Rect(*bounds))
self.Refresh()
pdc.EndDrawing()
@@ -2382,7 +2382,7 @@
iH = iH * self.currScale
x = cW / 2 - iW / 2
y = cH / 2 - iH / 2
- imageRect = wx.Rect(x, y, iW, iH)
+ imageRect = Rect(x, y, iW, iH)
return imageRect
@@ -2404,7 +2404,7 @@
# draw small marks signalizing resizing
if self.instruction[id].type in ('map', 'rectangle'):
controlP = self.pdcObj.GetIdBounds(id).GetBottomRight()
- rect = wx.RectPS(controlP, self.resizeBoxSize)
+ rect = Rect(controlP[0], controlP[1], self.resizeBoxSize[0], self.resizeBoxSize[1])
self.Draw(
pen=self.pen['resize'],
brush=self.brush['resize'],
@@ -2421,9 +2421,9 @@
p2Canvas = self.CanvasPaperCoordinates(
rect=Rect2DPS(p2Paper, (0, 0)), canvasToPaper=False)[:2]
rect = []
- box = wx.RectS(self.resizeBoxSize)
- rect.append(box.CenterIn(wx.RectPS(p1Canvas, wx.Size())))
- rect.append(box.CenterIn(wx.RectPS(p2Canvas, wx.Size())))
+ box = Rect(0, 0, self.resizeBoxSize[0], self.resizeBoxSize[1])
+ rect.append(box.CenterIn(Rect(p1Canvas[0], p1Canvas[1], 0, 0)))
+ rect.append(box.CenterIn(Rect(p2Canvas[0], p2Canvas[1], 0, 0)))
for i, point in enumerate((p1Canvas, p2Canvas)):
self.Draw(
pen=self.pen['resize'],
@@ -2495,11 +2495,11 @@
# Make new off screen bitmap: this bitmap will always have the
# current drawing in it, so it can be used to save the image
# to a file, or whatever.
- self._buffer = wx.EmptyBitmap(width, height)
+ self._buffer = EmptyBitmap(width, height)
# re-render image on idle
self.resize = True
def ScaleRect(self, rect, scale):
"""Scale rectangle"""
- return wx.Rect(rect.GetLeft() * scale, rect.GetTop() * scale,
+ return Rect(rect.GetLeft() * scale, rect.GetTop() * scale,
rect.GetSize()[0] * scale, rect.GetSize()[1] * scale)
More information about the grass-commit
mailing list