Skip to content

Commit

Permalink
wxGUI/wxpyimgview: Fix wxpyimgview for Python3/wxPython4 (#735)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmszi authored and petrasovaa committed Jul 3, 2020
1 parent d13027f commit 69749ba
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions scripts/wxpyimgview/wxpyimgview_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,19 @@
#% answer: 10
#%end

import sys
import os
import signal
import struct
import numpy
import sys
import time
import signal

import grass.script as grass
from grass.script.setup import set_gui_path

set_gui_path()
from gui_core.wrap import BitmapFromImage

import numpy

import wx

Expand Down Expand Up @@ -78,8 +86,8 @@ def draw(self):
data = app.imgbuf.reshape((app.i_height, app.i_width, 4))
data = data[::, ::, 2::-1]
fn = getattr(data, "tobytes", getattr(data, "tostring"))
image = wx.ImageFromData(app.i_width, app.i_height, fn())
dc.DrawBitmap(wx.BitmapFromImage(image), x0, y0, False)
image = wx.Image(app.i_width, app.i_height, fn())
dc.DrawBitmap(BitmapFromImage(image), x0, y0, False)

def redraw(self, ev):
if self.app.fraction > 0.001:
Expand Down Expand Up @@ -111,7 +119,7 @@ def __init__(self):
def read_bmp_header(self, header):
magic, bmfh, bmih = struct.unpack("2s12s40s10x", header)

if magic != 'BM':
if grass.decode(magic) != 'BM':
raise SyntaxError("Invalid magic number")

size, res1, res2, hsize = struct.unpack("<IHHI", bmfh)
Expand Down Expand Up @@ -140,7 +148,7 @@ def read_bmp_header(self, header):
raise SyntaxError("Invalid image size")

def map_file(self):
f = open(self.image, 'r')
f = open(self.image, 'rb')

header = f.read(self.HEADER_SIZE)
self.read_bmp_header(header)
Expand Down

0 comments on commit 69749ba

Please sign in to comment.