Changeset 863:4c7bfec09347


Ignore:
Timestamp:
06/18/17 17:44:54 (7 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

The briefing can be printed from the program (re #307)

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • locale/en/mlx.po

    r859 r863  
    465465
    466466msgid "flightsel_save"
    467 msgstr "_Save flight"
     467msgstr "_Save flight..."
    468468
    469469msgid "flightsel_save_tooltip"
     
    471471"Click here to save the currently selected flight into a "
    472472"file that can be loaded later."
     473
     474msgid "flightsel_print"
     475msgstr "Print _briefing..."
     476
     477msgid "flightsel_print_tooltip"
     478msgstr ""
     479"Click here to print the briefing for the currently selected flight."
     480
     481msgid "flightsel_print_failed"
     482msgstr "Printing failed"
    473483
    474484msgid "flightsel_save_title"
  • locale/hu/mlx.po

    r859 r863  
    471471"Kattints ide az éppen kiválasztott járatnak fájlba mentéséhez. "
    472472"A fájl később visszatölthető, és így a járat offline is teljesíthető lesz."
     473
     474msgid "flightsel_print"
     475msgstr "_Eligazítás nyomtatása..."
     476
     477msgid "flightsel_print_tooltip"
     478msgstr ""
     479"Kattints ide az éppen kiválasztott járat eligazításának a kinyomtatásához."
     480
     481msgid "flightsel_print_failed"
     482msgstr "A nyomtatás nem sikerült"
    473483
    474484msgid "flightsel_save_title"
  • src/mlx/gui/common.py

    r858 r863  
    637637#------------------------------------------------------------------------------
    638638
    639 def errroDialog(message, parent = None, secondary = None,
     639def errorDialog(message, parent = None, secondary = None,
    640640                title = WINDOW_TITLE_BASE):
    641641    """Display an error dialog box with the given message."""
     
    655655def communicationErrorDialog(parent = None, title = WINDOW_TITLE_BASE):
    656656    """Display a communication error dialog."""
    657     errroDialog(xstr("error_communication"), parent = parent,
     657    errorDialog(xstr("error_communication"), parent = parent,
    658658                secondary = xstr("error_communication_secondary"),
    659659                title = title)
  • src/mlx/gui/flight.py

    r860 r863  
     1# -*- encoding: utf-8 -*-
    12
    23from mlx.gui.common import *
     
    471472        flightButtonBox.pack_start(alignment, False, False, 0)
    472473
    473         saveButtonAlignment = gtk.Alignment(xscale=0.5, yscale=0.0,
    474                                             xalign=0.0, yalign=0.0)
     474        flightButtonWidthAlignment = gtk.Alignment(xscale=0.5, yscale=0.0,
     475                                                   xalign=0.0, yalign=0.0)
     476        flightButtonWidthBox = gtk.VBox()
     477
    475478        self._saveButton = gtk.Button(xstr("flightsel_save"))
    476479        self._saveButton.set_use_underline(True)
     
    479482        self._saveButton.connect("clicked", self._saveClicked)
    480483
    481         saveButtonAlignment.add(self._saveButton)
    482 
    483         flightButtonBox.pack_start(saveButtonAlignment, False, False, 4)
     484        flightButtonWidthBox.pack_start(self._saveButton, True, True, 4)
     485
     486        self._printButton = gtk.Button(xstr("flightsel_print"))
     487        self._printButton.set_use_underline(True)
     488        self._printButton.set_sensitive(False)
     489        self._printButton.set_tooltip_text(xstr("flightsel_print_tooltip"))
     490        self._printButton.connect("clicked", self._printClicked)
     491
     492        flightButtonWidthBox.pack_start(self._printButton, True, True, 4)
     493
     494
     495        flightButtonWidthAlignment.add(flightButtonWidthBox)
     496        flightButtonBox.pack_start(flightButtonWidthAlignment, False, False, 0)
    484497
    485498        mainBox.pack_start(flightButtonBox, True, True, 0)
     
    514527        self._pendingFlightsWindow.connect("delete-event",
    515528                                           self._deletePendingFlightsWindow)
     529
     530        self._printSettings = None
    516531
    517532    def activate(self):
     
    631646                dialog.hide()
    632647
     648    def _printClicked(self, button):
     649        """Called when the Print briefing button is clicked."""
     650        wizard = self._wizard
     651        flight = self._getSelectedFlight()
     652
     653        printOperation = gtk.PrintOperation()
     654        if self._printSettings is not None:
     655            printOperation.set_print_settings(self._printSettings)
     656
     657        printOperation.set_n_pages(1)
     658        printOperation.set_show_progress(True)
     659        printOperation.connect("draw_page", self._drawBriefing)
     660
     661        name = "MAVA Briefing %s %s %s" % (wizard.loginResult.pilotID,
     662                                           flight.callsign,
     663                                           flight.departureTime.strftime("%Y-%m-%d %H:%M"))
     664        printOperation.set_job_name(name)
     665        printOperation.set_export_filename(name)
     666        printOperation.set_use_full_page(False)
     667
     668        result = printOperation.run(gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG,
     669                                    wizard.gui.mainWindow)
     670
     671        if result == gtk.PRINT_OPERATION_RESULT_APPLY:
     672            self._printSettings = printOperation.get_print_settings()
     673        elif result == gtk.PRINT_OPERATION_RESULT_ERROR:
     674            errorDialog(xstr("flightsel_print_failed",
     675                             wizard.gui.mainWindow,
     676                             secondary = printOperation.get_error()))
     677
     678    def _drawBriefing(self, printOperation, context, pageNumber):
     679        """Draw the briefing."""
     680        wizard = self._wizard
     681        loginResult = wizard.loginResult
     682        flight=self._getSelectedFlight()
     683
     684        print "DPI", context.get_dpi_x(), context.get_dpi_y()
     685
     686        scale = context.get_dpi_x() / 72.0
     687
     688        cr = context.get_cairo_context()
     689        cr.set_antialias(cairo.ANTIALIAS_GRAY)
     690
     691        cr.set_source_rgb(0.0, 0.0, 0.0)
     692        cr.set_line_width(2.0 * scale)
     693        cr.rectangle(0, 0, context.get_width(), context.get_height())
     694        cr.stroke()
     695
     696        layout = cr.create_layout()
     697        layout.set_text(u"Malév VA official briefing")
     698        font = pango.FontDescription("sans")
     699        font.set_size(int(32 * scale * pango.SCALE))
     700        font.set_weight(pango.WEIGHT_NORMAL)
     701        layout.set_font_description(font)
     702
     703        (_ink, (x0, y0, x1, y1)) = layout.get_extents()
     704        width = float(x1 + 1 - x0) / pango.SCALE
     705
     706        y = 25 * scale
     707
     708        cr.move_to((context.get_width() - width)/2.0, y)
     709        cr.set_line_width(0.1 * scale)
     710        cr.layout_path(layout)
     711        cr.stroke_preserve()
     712        cr.fill()
     713
     714        y += float(y1 + 1 - y0) / pango.SCALE
     715        y += 6 * scale
     716
     717        layout = cr.create_layout()
     718        layout.set_text(u"%s (%s) részére" %
     719                        (loginResult.pilotName, loginResult.pilotID))
     720        font = pango.FontDescription("sans")
     721        font.set_size(int(16 * scale * pango.SCALE))
     722        font.set_weight(450)
     723        layout.set_font_description(font)
     724        (_ink, (x0, y0, x1, y1)) = layout.get_extents()
     725        width = float(x1 + 1 - x0) / pango.SCALE
     726
     727        cr.move_to((context.get_width() - width)/2.0, y)
     728        cr.set_line_width(0.1 * scale)
     729        cr.layout_path(layout)
     730        cr.stroke_preserve()
     731        cr.fill()
     732
     733        y += float(y1 + 1 - y0) / pango.SCALE
     734        y += 4 * scale
     735
     736        cr.move_to(0, y)
     737        cr.line_to(context.get_width(), y)
     738        cr.set_line_width(1.0 * scale)
     739        cr.stroke()
     740
     741        y += 20 * scale
     742
     743        font = pango.FontDescription("sans")
     744        font.set_size(int(7 * scale * pango.SCALE))
     745        font.set_weight(150)
     746
     747        table = []
     748        table.append(("Flight", flight.callsign))
     749        table.append(("Date", flight.date))
     750        table.append(("Aircraft",
     751                      aircraftNames[flight.aircraftType] + ", Lajstrom: " +
     752                      flight.tailNumber))
     753        table.append(("DOW",
     754                      str(acft.getClass(flight.aircraftType).dow) + " kgs"))
     755        table.append(("From", flight.departureICAO))
     756        table.append(("To", flight.arrivalICAO))
     757        table.append(("ETD (UTC)", flight.departureTime.strftime("%H:%M:%S")))
     758        table.append(("ETA (UTC)", flight.arrivalTime.strftime("%H:%M:%S")))
     759        table.append(("Crew", str(flight.numCrew)))
     760        table.append(("Pass", str(flight.numPassengers)))
     761        table.append(("Bag", str(flight.bagWeight)))
     762        table.append(("Mail", str(flight.mailWeight)))
     763        table.append(("Route", flight.route))
     764
     765        tableY = y
     766        tableX = 15 * scale
     767        labelFill = 5 * scale
     768        labelValueFill = 25 * scale
     769        valueFill = 5 * scale
     770        labelX = tableX + labelFill
     771        tableWidth = context.get_width() * 55 / 100 - tableX
     772
     773        labelLayouts = []
     774        maxLabelWidth = 0
     775        totalHeight = 0
     776        for (label, value) in table:
     777            labelLayout = cr.create_layout()
     778            labelLayout.set_text(label)
     779            labelLayout.set_font_description(font)
     780
     781            (_ink, (x0, y0, x1, y1)) = labelLayout.get_extents()
     782            maxLabelWidth = max(maxLabelWidth, x1 + 1 - x0)
     783            labelHeight = y1 + 1 - y0
     784
     785            valueLayout = cr.create_layout()
     786            valueLayout.set_text(value)
     787            valueLayout.set_font_description(font)
     788
     789            labelLayouts.append((labelLayout, valueLayout, labelHeight))
     790
     791        maxLabelWidth = maxLabelWidth / pango.SCALE
     792
     793        valueX = labelX + labelValueFill + maxLabelWidth
     794
     795        layouts = []
     796        valueWidth = tableWidth - \
     797            (labelFill + maxLabelWidth + labelValueFill + valueFill)
     798        for (labelLayout, valueLayout, labelHeight) in labelLayouts:
     799            valueLayout.set_width(int(valueWidth * pango.SCALE))
     800
     801            (_ink, (x0, y0, x1, y1)) = valueLayout.get_extents()
     802            valueHeight = y1 + 1 - y0
     803
     804            height = float(max(labelHeight, valueHeight))/pango.SCALE
     805            layouts.append((labelLayout, valueLayout, height))
     806
     807        rowIndex = 0
     808        for (labelLayout, valueLayout, height) in layouts:
     809            if (rowIndex%2)==0:
     810                cr.set_source_rgb(0.85, 0.85, 0.85)
     811            else:
     812                cr.set_source_rgb(0.9, 0.9, 0.9)
     813
     814            cr.rectangle(tableX, y-2*scale, tableWidth, height + 4 * scale)
     815            cr.fill()
     816
     817            cr.set_source_rgb(0.0, 0.0, 0.0)
     818
     819            cr.move_to(labelX, y)
     820            cr.set_line_width(0.1)
     821            cr.layout_path(labelLayout)
     822            cr.stroke_preserve()
     823            cr.fill()
     824
     825            cr.move_to(valueX, y)
     826            cr.set_line_width(0.1)
     827            cr.layout_path(valueLayout)
     828            cr.stroke_preserve()
     829            cr.fill()
     830
     831            y += height
     832            y += 4 * scale
     833
     834            rowIndex += 1
     835
     836        cr.set_source_rgb(0.0, 0.0, 0.0)
     837        cr.set_line_width(1.0 * scale)
     838        cr.rectangle(tableX, tableY - 2 * scale, tableWidth, y - tableY)
     839        cr.stroke()
     840
     841        cr.move_to(valueX - 5 * scale, tableY - 2 * scale)
     842        cr.line_to(valueX - 5 * scale, y - 2 * scale)
     843        cr.stroke()
     844
    633845    def _refreshClicked(self, button):
    634846        """Called when the refresh button is clicked."""
     
    645857        """Called when the selection is changed."""
    646858        self._saveButton.set_sensitive(len(indexes)==1)
     859        self._printButton.set_sensitive(len(indexes)==1)
    647860        self._updateNextButton()
    648861
Note: See TracChangeset for help on using the changeset viewer.