mirror of
https://github.com/nmap/nmap.git
synced 2026-01-22 22:29:03 +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************************
|
||||
# * *
|
||||
@@ -71,15 +70,17 @@
|
||||
# Add options to the print dialog to control the font, coloring, and anything
|
||||
# else. This might go in a separate Print Setup dialog.
|
||||
|
||||
import gtk
|
||||
import gobject
|
||||
import pango
|
||||
import gi
|
||||
|
||||
MONOSPACE_FONT_DESC = pango.FontDescription("Monospace 12")
|
||||
gi.require_version("Gtk", "3.0")
|
||||
gi.require_version("PangoCairo", "1.0")
|
||||
from gi.repository import Gtk, GLib, Pango, PangoCairo
|
||||
|
||||
MONOSPACE_FONT_DESC = Pango.FontDescription("Monospace 12")
|
||||
|
||||
|
||||
class PrintState (object):
|
||||
"""This is the userdatum passed to gtk.PrintOperation callbacks."""
|
||||
class PrintState(object):
|
||||
"""This is the userdatum passed to Gtk.PrintOperation callbacks."""
|
||||
|
||||
def __init__(self, inventory, entry):
|
||||
"""entry is a ScansListStoreEntry."""
|
||||
@@ -90,7 +91,7 @@ class PrintState (object):
|
||||
# Still running, failed, or cancelled.
|
||||
output = entry.command.get_output()
|
||||
if not output:
|
||||
output = u"\n"
|
||||
output = "\n"
|
||||
self.lines = output.splitlines()
|
||||
|
||||
def begin_print(self, op, context):
|
||||
@@ -98,14 +99,14 @@ class PrintState (object):
|
||||
# Typeset a dummy line to get the exact line height.
|
||||
layout = context.create_pango_layout()
|
||||
layout.set_font_description(MONOSPACE_FONT_DESC)
|
||||
layout.set_text("dummy")
|
||||
layout.set_text("dummy", -1)
|
||||
line = layout.get_line(0)
|
||||
# get_extents()[1][3] is the height of the logical rectangle.
|
||||
line_height = line.get_extents()[1][3] / float(pango.SCALE)
|
||||
# get_extents()[1].height is the height of the logical rectangle.
|
||||
line_height = line.get_extents()[1].height / Pango.SCALE
|
||||
|
||||
page_height = context.get_height()
|
||||
self.lines_per_page = int(page_height / line_height)
|
||||
op.set_n_pages((len(self.lines) - 1) / self.lines_per_page + 1)
|
||||
op.set_n_pages((len(self.lines) - 1) // self.lines_per_page + 1)
|
||||
|
||||
def draw_page(self, op, context, page_nr):
|
||||
this_page_lines = self.lines[
|
||||
@@ -115,21 +116,21 @@ class PrintState (object):
|
||||
# Do no wrapping.
|
||||
layout.set_width(-1)
|
||||
layout.set_font_description(MONOSPACE_FONT_DESC)
|
||||
text = "\n".join(this_page_lines).encode("utf8")
|
||||
layout.set_text(text)
|
||||
text = "\n".join(this_page_lines)
|
||||
layout.set_text(text, -1)
|
||||
|
||||
cr = context.get_cairo_context()
|
||||
cr.show_layout(layout)
|
||||
PangoCairo.show_layout(cr, layout)
|
||||
|
||||
|
||||
def run_print_operation(inventory, entry):
|
||||
op = gtk.PrintOperation()
|
||||
op = Gtk.PrintOperation()
|
||||
state = PrintState(inventory, entry)
|
||||
op.connect("begin-print", state.begin_print)
|
||||
op.connect("draw-page", state.draw_page)
|
||||
try:
|
||||
op.run(gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG, None)
|
||||
except gobject.GError:
|
||||
op.run(Gtk.PrintOperationAction.PRINT_DIALOG, None)
|
||||
except GLib.GError:
|
||||
# Canceling the print operation can result in the error
|
||||
# GError: Error from StartDoc
|
||||
# http://seclists.org/nmap-dev/2012/q4/161
|
||||
|
||||
Reference in New Issue
Block a user