Changeset 3136 for trunk/gltext.py


Ignore:
Timestamp:
Oct 23, 2017 11:39:16 AM (4 years ago)
Author:
vondreele
Message:

make GSAS-II python 3.6 compliant & preserve python 2.7 use;changes:
do from future import division, print_function for all GSAS-II py sources
all menu items revised to be py 2.7/3.6 compliant
all wx.OPEN --> wx.FD_OPEN in file dialogs
all integer divides (typically for image pixel math) made explicit with ; ambiguous ones made floats as appropriate
all print "stuff" --> print (stuff)
all print >> pFile,'stuff' --> pFile.writeCIFtemplate('stuff')
all read file opens made explicit 'r' or 'rb'
all cPickle imports made for py2.7 or 3.6 as cPickle or _pickle; test for '2' platform.version_tuple[0] for py 2.7
define cPickleload to select load(fp) or load(fp,encoding='latin-1') for loading gpx files; provides cross compatibility between py 2.7/3.6 gpx files
make dict.keys() as explicit list(dict.keys()) as needed (NB: possible source of remaining py3.6 bugs)
make zip(a,b) as explicit list(zip(a,b)) as needed (NB: possible source of remaining py3.6 bugs)
select unichr/chr according test for '2' platform.version_tuple[0] for py 2.7 (G2pwdGUI * G2plot) for special characters
select wg.EVT_GRID_CELL_CHANGE (classic) or wg.EVT_GRID_CELL_CHANGED (phoenix) in grid Bind
maxint --> maxsize; used in random number stuff
raise Exception,"stuff" --> raise Exception("stuff")
wx 'classic' sizer.DeleteWindows?() or 'phoenix' sizer.Clear(True)
wx 'classic' SetToolTipString?(text) or 'phoenix' SetToolTip?(wx.ToolTip?(text)); define SetToolTipString?(self,text) to handle the choice in plots
status.SetFields? --> status.SetStatusText?
'classic' AddSimpleTool? or 'phoenix' self.AddTool? for plot toolbar; Bind different as well
define GetItemPydata? as it doesn't exist in wx 'phoenix'
allow python versions 2.7 & 3.6 to run GSAS-II
Bind override commented out - no logging capability (NB: remove all logging code?)
all import ContentsValidator? open filename & test if valid then close; filepointer removed from Reader
binary importers (mostly images) test for 'byte' type & convert as needed to satisfy py 3.6 str/byte rules

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gltext.py

    r3000 r3136  
    3030
    3131import wx
     32import struct as st
    3233import OpenGL.GL as GL
     34import platform
    3335
    3436"""
     
    158160        # get a memory dc and assign a temporary bitmap
    159161        dc = wx.MemoryDC()
    160         dc.SelectObject(wx.EmptyBitmap(100, 100))
     162        if 'phoenix' in wx.version():
     163            dc.SelectObject(wx.Bitmap(100, 100))
     164        else:
     165            dc.SelectObject(wx.EmptyBitmap(100, 100))
    161166       
    162167        # set our font
     
    173178        self._text_size = wx.Size(ow,oh)
    174179        self._texture_size = wx.Size(w,h)
    175         bmp = wx.EmptyBitmap(w,h)
     180        if 'phoenix' in wx.version():
     181            bmp = wx.Bitmap(wx.Size(w,h))
     182        else:
     183            bmp = wx.EmptyBitmap(w,h)
    176184       
    177185       
     
    187195            tw, th = dc.GetTextExtent(line)
    188196            if centered:
    189                 x = int(round((w-tw)/2))
     197                x = int(round((w-tw)//2))
    190198            dc.DrawText(line, x, y)
    191199            x = 0
     
    201209        first converting to an image and using wx.Image.GetData().
    202210        """
    203         img   = wx.ImageFromBitmap(bmp)
    204         alpha = img.GetData()
    205        
    206         if isinstance(self._foreground, wx.Colour): 
     211        if 'phoenix' in wx.version():
     212            img = wx.Bitmap.ConvertToImage(bmp)
     213            alpha = img.GetData()
     214        else:
     215            img = wx.ImageFromBitmap(bmp)
     216            alpha = img.GetData()
     217       
     218#        if isinstance(self._foreground, wx.Colour): 
    207219            """
    208220            If we have a static color... 
    209221            """   
    210             r,g,b = self._foreground.Get()
     222        r,g,b = self._foreground.Get()[:3]
     223       
     224        if '2' in platform.python_version_tuple()[0]:
    211225            color = "%c%c%c" % (chr(r), chr(g), chr(b))
    212            
    213             data = ''
    214             for i in xrange(0, len(alpha)-1, 3):
    215                 data += color + alpha[i]
    216        
    217         elif isinstance(self._foreground, wx.Bitmap):
    218             """
    219             If we have a bitmap...
    220             """
    221             bg_img    = wx.ImageFromBitmap(self._foreground)
    222             bg        = bg_img.GetData()
    223             bg_width  = self._foreground.GetWidth()
    224             bg_height = self._foreground.GetHeight()
    225            
    226             data = ''
    227 
    228             for y in xrange(0, h):
    229                 for x in xrange(0, w):
    230                     if (y > (bg_height-1)) or (x > (bg_width-1)):                       
    231                         color = "%c%c%c" % (chr(0),chr(0),chr(0))
    232                     else:
    233                         pos = (x+y*bg_width) * 3
    234                         color = bg[pos:pos+3]
    235                     data += color + alpha[(x+y*w)*3]
     226        else:
     227            color = st.pack('3B',r,g,b)
     228       
     229        data = b''
     230        for i in range(0, len(alpha)-1, 3):
     231            if '2' in platform.python_version_tuple()[0]:
     232                data += (color + str(alpha[i]))
     233            else:
     234                data += (color + st.pack('B',alpha[i]))
     235#        elif isinstance(self._foreground, wx.Bitmap):
     236#            """
     237#            If we have a bitmap...
     238#            """
     239#            bg_img    = wx.ImageFromBitmap(self._foreground)
     240#            bg        = bg_img.GetData()
     241#            bg_width  = self._foreground.GetWidth()
     242#            bg_height = self._foreground.GetHeight()
     243#           
     244#            data = ''
     245#
     246#            for y in range(0, h):
     247#                for x in range(0, w):
     248#                    if (y > (bg_height-1)) or (x > (bg_width-1)):                       
     249#                        color = "%c%c%c" % (chr(0),chr(0),chr(0))
     250#                    else:
     251#                        pos = (x+y*bg_width) * 3
     252#                        color = bg[pos:pos+3]
     253#                    data += color + alpha[(x+y*w)*3]
    236254
    237255
Note: See TracChangeset for help on using the changeset viewer.