mirror of
https://github.com/nmap/nmap.git
synced 2025-12-09 22:21:29 +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:
@@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# ***********************IMPORTANT NMAP LICENSE TERMS************************
|
||||
# * *
|
||||
@@ -66,10 +65,10 @@ higwidgets/higspinner.py
|
||||
|
||||
__all__ = ['HIGSpinner']
|
||||
|
||||
import gtk
|
||||
import gobject
|
||||
import gi
|
||||
|
||||
from gtkutils import gobject_register
|
||||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository import Gtk, GLib, Gdk, GdkPixbuf
|
||||
|
||||
|
||||
class HIGSpinnerImages:
|
||||
@@ -132,15 +131,15 @@ class HIGSpinnerImages:
|
||||
new_animated = []
|
||||
for p in self.animated_pixbufs:
|
||||
new_animated.append(p.scale_simple(width, height,
|
||||
gtk.gdk.INTERP_BILINEAR))
|
||||
GdkPixbuf.InterpType.BILINEAR))
|
||||
self.animated_pixbufs = new_animated
|
||||
|
||||
for k in self.static_pixbufs:
|
||||
self.static_pixbufs[k] = self.static_pixbufs[k].scale_simple(
|
||||
width, height, gtk.gdk.INTERP_BILINEAR)
|
||||
width, height, GdkPixbuf.InterpType.BILINEAR)
|
||||
|
||||
self.rest_pixbuf = self.rest_pixbuf.scale_simple(
|
||||
width, height, gtk.gdk.INTERP_BILINEAR)
|
||||
width, height, GdkPixbuf.InterpType.BILINEAR)
|
||||
|
||||
self.images_width = width
|
||||
self.images_height = height
|
||||
@@ -156,7 +155,7 @@ class HIGSpinnerCache:
|
||||
self.spinner_images = HIGSpinnerImages()
|
||||
|
||||
# These are on Private member in the C implementation
|
||||
self.icon_theme = gtk.IconTheme()
|
||||
self.icon_theme = Gtk.IconTheme()
|
||||
self.originals = None
|
||||
self.images = None
|
||||
|
||||
@@ -203,7 +202,7 @@ class HIGSpinnerCache:
|
||||
|
||||
def load_animated_from_filename(self, filename, size):
|
||||
# grid_pixbuf is a pixbuf that holds the entire
|
||||
grid_pixbuf = gtk.gdk.pixbuf_new_from_file(filename)
|
||||
grid_pixbuf = GdkPixbuf.Pixbuf.new_from_file(filename)
|
||||
grid_width = grid_pixbuf.get_width()
|
||||
grid_height = grid_pixbuf.get_height()
|
||||
|
||||
@@ -221,7 +220,7 @@ class HIGSpinnerCache:
|
||||
self.load_static_from_filename(filename)
|
||||
|
||||
def load_static_from_filename(self, filename, key_name=None):
|
||||
icon_pixbuf = gtk.gdk.pixbuf_new_from_file(filename)
|
||||
icon_pixbuf = GdkPixbuf.Pixbuf.new_from_file(filename)
|
||||
|
||||
if key_name is None:
|
||||
key_name = filename.split(".")[0]
|
||||
@@ -257,7 +256,7 @@ class HIGSpinnerCache:
|
||||
image_format)
|
||||
|
||||
|
||||
class HIGSpinner(gtk.EventBox):
|
||||
class HIGSpinner(Gtk.EventBox):
|
||||
"""Simple spinner, such as the one found in webbrowsers and file managers.
|
||||
|
||||
You can construct it with the optional parameters:
|
||||
@@ -266,11 +265,11 @@ class HIGSpinner(gtk.EventBox):
|
||||
* height, the height that will be set for the images
|
||||
"""
|
||||
|
||||
__gsignals__ = {'expose-event': 'override',
|
||||
'size-request': 'override'}
|
||||
#__gsignals__ = {'expose-event': 'override',
|
||||
# 'size-request': 'override'}
|
||||
|
||||
def __init__(self):
|
||||
gtk.EventBox.__init__(self)
|
||||
Gtk.EventBox.__init__(self)
|
||||
|
||||
#self.set_events(self.get_events())
|
||||
|
||||
@@ -325,13 +324,13 @@ class HIGSpinner(gtk.EventBox):
|
||||
def start(self):
|
||||
"""Starts the animation"""
|
||||
if self.timer_task == 0:
|
||||
self.timer_task = gobject.timeout_add(self.timeout,
|
||||
self.timer_task = GLib.timeout_add(self.timeout,
|
||||
self.__bump_frame)
|
||||
|
||||
def pause(self):
|
||||
"""Pauses the animation"""
|
||||
if self.timer_task != 0:
|
||||
gobject.source_remove(self.timer_task)
|
||||
GLib.source_remove(self.timer_task)
|
||||
|
||||
self.timer_task = 0
|
||||
self.queue_draw()
|
||||
@@ -359,26 +358,29 @@ class HIGSpinner(gtk.EventBox):
|
||||
|
||||
width = self.current_pixbuf.get_width()
|
||||
height = self.current_pixbuf.get_height()
|
||||
x_offset = (self.allocation.width - width) / 2
|
||||
y_offset = (self.allocation.height - height) / 2
|
||||
x_offset = (self.allocation.width - width) // 2
|
||||
y_offset = (self.allocation.height - height) // 2
|
||||
|
||||
pix_area = gtk.gdk.Rectangle(x_offset + self.allocation.x,
|
||||
y_offset + self.allocation.y,
|
||||
width, height)
|
||||
pix_area = Gdk.Rectangle(x_offset + self.allocation.x,
|
||||
y_offset + self.allocation.y,
|
||||
width, height)
|
||||
|
||||
dest = event.area.intersect(pix_area)
|
||||
|
||||
# If a graphic context doesn't not exist yet, create one
|
||||
if self.gc is None:
|
||||
self.gc = gtk.gdk.GC(self.window)
|
||||
#gc = self.gc
|
||||
|
||||
self.window.draw_pixbuf(self.gc,
|
||||
self.current_pixbuf,
|
||||
dest.x - x_offset - self.allocation.x,
|
||||
dest.y - y_offset - self.allocation.y,
|
||||
dest.x, dest.y,
|
||||
dest.width, dest.height)
|
||||
# # If a graphic context doesn't not exist yet, create one
|
||||
# if self.gc is None:
|
||||
# self.gc = gtk.gdk.GC(self.window)
|
||||
# #gc = self.gc
|
||||
#
|
||||
# cairo = self.window.cairo_create()
|
||||
#
|
||||
#
|
||||
# self.window.draw_pixbuf(self.gc,
|
||||
# self.current_pixbuf,
|
||||
# dest.x - x_offset - self.allocation.x,
|
||||
# dest.y - y_offset - self.allocation.y,
|
||||
# dest.x, dest.y,
|
||||
# dest.width, dest.height)
|
||||
|
||||
def do_size_request(self, requisition):
|
||||
# http://www.pygtk.org/pygtk2reference/class-gtkrequisition.html
|
||||
@@ -386,5 +388,3 @@ class HIGSpinner(gtk.EventBox):
|
||||
# FIXME, this should really come from the pixbuf size + margins
|
||||
requisition.width = self.cache.spinner_images.images_width
|
||||
requisition.height = self.cache.spinner_images.images_height
|
||||
|
||||
gobject_register(HIGSpinner)
|
||||
|
||||
Reference in New Issue
Block a user