mirror of
https://github.com/nmap/nmap.git
synced 2025-12-08 21:51:28 +00:00
Merge #2088: Update Zenmap to Python 3 and PyGObject
Note: Ndiff build will be broken until subsequent changes are made. Deprecation warnings will need to be addressed in future changes. Closes #2088
This commit is contained in:
@@ -57,8 +57,12 @@
|
||||
# * *
|
||||
# ***************************************************************************/
|
||||
|
||||
import gi
|
||||
|
||||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository import GdkPixbuf
|
||||
|
||||
import os
|
||||
import gtk
|
||||
import array
|
||||
|
||||
from zenmapCore.Paths import Path
|
||||
@@ -74,8 +78,8 @@ def get_pixels_for_cairo_image_surface(pixbuf):
|
||||
containing the icon pixels of a gtk.gdk.Pixbuf that can be used by
|
||||
cairo.ImageSurface.create_for_data() method.
|
||||
"""
|
||||
data = array.ArrayType('c')
|
||||
format = pixbuf.get_rowstride() / pixbuf.get_width()
|
||||
data = array.array('B')
|
||||
image_format = pixbuf.get_rowstride() // pixbuf.get_width()
|
||||
|
||||
i = 0
|
||||
j = 0
|
||||
@@ -83,16 +87,16 @@ def get_pixels_for_cairo_image_surface(pixbuf):
|
||||
|
||||
b, g, r = pixbuf.get_pixels()[i:i + FORMAT_RGB]
|
||||
|
||||
if format == FORMAT_RGBA:
|
||||
if image_format == FORMAT_RGBA:
|
||||
a = pixbuf.get_pixels()[i + FORMAT_RGBA - 1]
|
||||
elif format == FORMAT_RGB:
|
||||
a = '\xff'
|
||||
elif image_format == FORMAT_RGB:
|
||||
a = 255
|
||||
else:
|
||||
raise TypeError('unknown image format')
|
||||
|
||||
data[j:j + FORMAT_RGBA] = array.ArrayType('c', [r, g, b, a])
|
||||
data[j:j + FORMAT_RGBA] = array.array('B', [r, g, b, a])
|
||||
|
||||
i += format
|
||||
i += image_format
|
||||
j += FORMAT_RGBA
|
||||
|
||||
return (FORMAT_RGBA * pixbuf.get_width(), data)
|
||||
@@ -122,7 +126,7 @@ class Image:
|
||||
|
||||
file = self.get_icon(icon, image_type)
|
||||
self.__cache[icon + image_type] = \
|
||||
gtk.gdk.pixbuf_new_from_file(file)
|
||||
GdkPixbuf.Pixbuf.new_from_file(file)
|
||||
|
||||
return self.__cache[icon + image_type]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user