Fixed resizing issue

Fixed resizing of traffic and weather maps - problem was in initial display.
This commit is contained in:
markjfine 2021-05-10 14:09:36 -04:00 committed by GitHub
parent 84b9ef05ce
commit 95bdf15d8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -295,15 +295,18 @@ class NRSC5_DUI(object):
data = GLib.Bytes.new(img.tobytes()) data = GLib.Bytes.new(img.tobytes())
return GdkPixbuf.Pixbuf.new_from_bytes(data, GdkPixbuf.Colorspace.RGB, 'A' in img.getbands(),8, img.width, img.height, len(img.getbands())*img.width) return GdkPixbuf.Pixbuf.new_from_bytes(data, GdkPixbuf.Colorspace.RGB, 'A' in img.getbands(),8, img.width, img.height, len(img.getbands())*img.width)
def did_resize(self):
result = False
width, height = self.mainWindow.get_size()
if (self.width != width) or (self.height != height):
self.width = width
self.height = height
result = True
return result
def on_cover_resize(self, container): def on_cover_resize(self, container):
global mapDir global mapDir
#width, height = self.mainWindow.get_size() if (self.did_resize()):
if True:
#if (self.width != width) or (self.height != height):
#self.width = width
#self.height = height
if (self.coverImage != "") and (self.coverImage[-5:] != "/aas/"):
self.showArtwork(self.coverImage) self.showArtwork(self.coverImage)
img_size = min(self.alignmentMap.get_allocated_height(), self.alignmentMap.get_allocated_width()) - 12 img_size = min(self.alignmentMap.get_allocated_height(), self.alignmentMap.get_allocated_width()) - 12
@ -501,9 +504,11 @@ class NRSC5_DUI(object):
# now display it by simulating a window resize # now display it by simulating a window resize
#self.height = 0 #self.height = 0
#self.width = 0 #self.width = 0
self.on_cover_resize(self.mainWindow) #self.on_cover_resize(self.mainWindow)
self.showArtwork(self.coverImage)
def showArtwork(self, art): def showArtwork(self, art):
if (art != "") and (art[-5:] != "/aas/"):
img_size = min(self.alignmentCover.get_allocated_height(), self.alignmentCover.get_allocated_width()) - 12 img_size = min(self.alignmentCover.get_allocated_height(), self.alignmentCover.get_allocated_width()) - 12
self.pixbuf = GdkPixbuf.Pixbuf.new_from_file(art) self.pixbuf = GdkPixbuf.Pixbuf.new_from_file(art)
self.pixbuf = self.pixbuf.scale_simple(img_size, img_size, GdkPixbuf.InterpType.BILINEAR) self.pixbuf = self.pixbuf.scale_simple(img_size, img_size, GdkPixbuf.InterpType.BILINEAR)
@ -849,11 +854,14 @@ class NRSC5_DUI(object):
def on_radMap_toggled(self, btn): def on_radMap_toggled(self, btn):
global mapDir global mapDir
if (btn.get_active()): if (btn.get_active()):
img_size = min(self.alignmentMap.get_allocated_height(), self.alignmentMap.get_allocated_width()) - 12
if (img_size < 200):
img_size = 200
if (btn == self.radMapTraffic): if (btn == self.radMapTraffic):
self.mapData["mapMode"] = 0 self.mapData["mapMode"] = 0
mapFile = os.path.join(mapDir, "TrafficMap.png") mapFile = os.path.join(mapDir, "TrafficMap.png")
if (os.path.isfile(mapFile)): # check if map exists if (os.path.isfile(mapFile)): # check if map exists
mapImg = Image.open(mapFile).resize((200,200), Image.LANCZOS) # scale map to fit window mapImg = Image.open(mapFile).resize((img_size, img_size), Image.LANCZOS) # scale map to fit window
self.imgMap.set_from_pixbuf(imgToPixbuf(mapImg)) # convert image to pixbuf and display self.imgMap.set_from_pixbuf(imgToPixbuf(mapImg)) # convert image to pixbuf and display
else: else:
self.imgMap.set_from_icon_name("MISSING_IMAGE", Gtk.IconSize.DIALOG) # display missing image if file is not found self.imgMap.set_from_icon_name("MISSING_IMAGE", Gtk.IconSize.DIALOG) # display missing image if file is not found
@ -861,7 +869,7 @@ class NRSC5_DUI(object):
elif (btn == self.radMapWeather): elif (btn == self.radMapWeather):
self.mapData["mapMode"] = 1 self.mapData["mapMode"] = 1
if (os.path.isfile(self.mapData["weatherNow"])): if (os.path.isfile(self.mapData["weatherNow"])):
mapImg = Image.open(self.mapData["weatherNow"]).resize((200,200), Image.LANCZOS) # scale map to fit window mapImg = Image.open(self.mapData["weatherNow"]).resize((img_size, img_size), Image.LANCZOS) # scale map to fit window
self.imgMap.set_from_pixbuf(imgToPixbuf(mapImg)) # convert image to pixbuf and display self.imgMap.set_from_pixbuf(imgToPixbuf(mapImg)) # convert image to pixbuf and display
else: else:
self.imgMap.set_from_icon_name("MISSING_IMAGE", Gtk.IconSize.DIALOG) # display missing image if file is not found self.imgMap.set_from_icon_name("MISSING_IMAGE", Gtk.IconSize.DIALOG) # display missing image if file is not found