Changeset 1002:5e741be6b47c for src/mlx


Ignore:
Timestamp:
07/06/19 13:54:20 (5 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
python3
Phase:
public
Message:

The printing of a briefing works with Gtk 3 (re #347)

Location:
src/mlx/gui
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/gui/common.py

    r999 r1002  
    3434    pass
    3535from gi.repository import Pango
     36from gi.repository import PangoCairo
    3637
    3738import codecs
  • src/mlx/gui/flight.py

    r999 r1002  
    684684        printOperation.set_use_full_page(False)
    685685
    686         result = printOperation.run(Gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG,
     686        result = printOperation.run(Gtk.PrintOperationAction.PRINT_DIALOG,
    687687                                    wizard.gui.mainWindow)
    688688
    689         if result == Gtk.PRINT_OPERATION_RESULT_APPLY:
     689        if result == Gtk.PrintOperationResult.APPLY:
    690690            self._printSettings = printOperation.get_print_settings()
    691         elif result == Gtk.PRINT_OPERATION_RESULT_ERROR:
     691        elif result == Gtk.PrintOperationResult.ERROR:
    692692            errorDialog(xstr("flightsel_print_failed",
    693693                             wizard.gui.mainWindow,
     
    705705
    706706        cr = context.get_cairo_context()
     707
    707708        cr.set_antialias(cairo.ANTIALIAS_GRAY)
    708709
     
    712713        cr.stroke()
    713714
    714         layout = cr.create_layout()
     715        pcr = context.create_pango_context()
     716
     717        layout = Pango.Layout(pcr) # cr.create_layout()
    715718        layout.set_text("Malév VA official briefing")
    716719        font = Pango.FontDescription("sans")
     
    719722        layout.set_font_description(font)
    720723
    721         (_ink, (x0, y0, x1, y1)) = layout.get_extents()
    722         width = float(x1 + 1 - x0) / Pango.SCALE
     724        (_ink, logical) = layout.get_extents()
     725        width = logical.width / Pango.SCALE
    723726
    724727        y = 25 * scale
     
    726729        cr.move_to((context.get_width() - width)/2.0, y)
    727730        cr.set_line_width(0.1 * scale)
    728         cr.layout_path(layout)
     731        PangoCairo.layout_path(cr, layout)
    729732        cr.stroke_preserve()
    730733        cr.fill()
    731734
    732         y += float(y1 + 1 - y0) / Pango.SCALE
     735        y += logical.height / Pango.SCALE
    733736        y += 6 * scale
    734737
    735         layout = cr.create_layout()
     738        layout = Pango.Layout(pcr)
    736739        layout.set_text("%s (%s) részére" %
    737740                        (loginResult.pilotName, loginResult.pilotID))
    738741        font = Pango.FontDescription("sans")
    739742        font.set_size(int(16 * scale * Pango.SCALE))
    740         font.set_weight(450)
     743        font.set_weight(Pango.Weight.MEDIUM)
    741744        layout.set_font_description(font)
    742         (_ink, (x0, y0, x1, y1)) = layout.get_extents()
    743         width = float(x1 + 1 - x0) / Pango.SCALE
     745        (_ink, logical) = layout.get_extents()
     746        width = logical.width / Pango.SCALE
    744747
    745748        cr.move_to((context.get_width() - width)/2.0, y)
    746749        cr.set_line_width(0.1 * scale)
    747         cr.layout_path(layout)
     750        PangoCairo.layout_path(cr, layout)
    748751        cr.stroke_preserve()
    749752        cr.fill()
    750753
    751         y += float(y1 + 1 - y0) / Pango.SCALE
     754        y += logical.height / Pango.SCALE
    752755        y += 4 * scale
    753756
     
    761764        font = Pango.FontDescription("sans")
    762765        font.set_size(int(7 * scale * Pango.SCALE))
    763         font.set_weight(150)
     766        font.set_weight(Pango.Weight.ULTRALIGHT)
    764767
    765768        table = []
     
    793796        totalHeight = 0
    794797        for (label, value) in table:
    795             labelLayout = cr.create_layout()
     798            labelLayout = Pango.Layout(pcr)
    796799            labelLayout.set_text(label)
    797800            labelLayout.set_font_description(font)
    798801
    799             (_ink, (x0, y0, x1, y1)) = labelLayout.get_extents()
    800             maxLabelWidth = max(maxLabelWidth, x1 + 1 - x0)
    801             labelHeight = y1 + 1 - y0
    802 
    803             valueLayout = cr.create_layout()
     802            (_ink, logical) = labelLayout.get_extents()
     803            maxLabelWidth = max(maxLabelWidth, logical.width)
     804            labelHeight = logical.height
     805
     806            valueLayout = Pango.Layout(pcr)
    804807            valueLayout.set_text(value)
    805808            valueLayout.set_font_description(font)
     
    817820            valueLayout.set_width(int(valueWidth * Pango.SCALE))
    818821
    819             (_ink, (x0, y0, x1, y1)) = valueLayout.get_extents()
    820             valueHeight = y1 + 1 - y0
     822            (_ink, logical) = valueLayout.get_extents()
     823            valueHeight = logical.height
    821824
    822825            height = float(max(labelHeight, valueHeight))/Pango.SCALE
     
    837840            cr.move_to(labelX, y)
    838841            cr.set_line_width(0.1)
    839             cr.layout_path(labelLayout)
     842            PangoCairo.layout_path(cr, labelLayout)
    840843            cr.stroke_preserve()
    841844            cr.fill()
     
    843846            cr.move_to(valueX, y)
    844847            cr.set_line_width(0.1)
    845             cr.layout_path(valueLayout)
     848            PangoCairo.layout_path(cr, valueLayout)
    846849            cr.stroke_preserve()
    847850            cr.fill()
Note: See TracChangeset for help on using the changeset viewer.