Skip to content

Commit

Permalink
Added margins when printing
Browse files Browse the repository at this point in the history
  • Loading branch information
daxartio committed Apr 24, 2018
1 parent 219301e commit 3e024b1
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 9 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2018-04-24 v1.1.1

+ Added margins when printing

## 2018-04-17 v1.1.0

+ SFR (http://www.sportsystem.ru) timekeeping system support on Windows (only last model U5a with HID Interface). Thanks to Alexander Kurdumov for support and equipment sample.
Expand Down
4 changes: 4 additions & 0 deletions changelog_ru.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Список изменений

## 2018-04-24 v1.1.1

+ Добавлены поля при печати

## 2018-04-17 v1.1.0

+ Поддержка чтения чипов системы электронной отметки SFR на Windows, http://www.sportsystem.ru. (Выражаем благодарность Александру Курдюмову за поддержку)
Expand Down
15 changes: 15 additions & 0 deletions languages/ru_RU/LC_MESSAGES/sportorg.po
Original file line number Diff line number Diff line change
Expand Up @@ -1545,6 +1545,21 @@ msgstr "Открыть WDB файл"
msgid "Save WDB file"
msgstr "Сохранить WDB файл"

msgid "Margins"
msgstr "Поля"

msgid "Left"
msgstr "Слева"

msgid "Top"
msgstr "Сверху"

msgid "Right"
msgstr "Справа"

msgid "Bottom"
msgstr "Снизу"

#~ msgid "Auto connect to station"
#~ msgstr "Автоматическое подключение станции SPORTident"

Expand Down
4 changes: 2 additions & 2 deletions sportorg.iss
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "SportOrg"
#define MyAppVersion "v1.1.0"
#define MyVersionInfoVersion "1.1.0.0"
#define MyAppVersion "v1.1.1"
#define MyVersionInfoVersion "1.1.1.0"
#define MyAppPublisher "Danil Akhtarov, Sergei Kobelev"
#define MyAppURL "http://sportorg.o-ural.ru/"
#define MyAppExeName "SportOrg.exe"
Expand Down
2 changes: 1 addition & 1 deletion sportorg/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from sportorg.core.version import Version

NAME = 'SportOrg'
VERSION = Version(1, 1, 0, 0, 'v')
VERSION = Version(1, 1, 1, 0, 'v')
DEBUG = True


Expand Down
26 changes: 25 additions & 1 deletion sportorg/gui/dialogs/print_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from PyQt5 import QtPrintSupport
from PyQt5.QtGui import QIcon
from PyQt5.QtPrintSupport import QPrinter, QPrintDialog, QAbstractPrintDialog
from PyQt5.QtWidgets import QFormLayout, QLabel, QDialog, QPushButton, QCheckBox, QDialogButtonBox
from PyQt5.QtWidgets import QFormLayout, QLabel, QDialog, QPushButton, QCheckBox, QDialogButtonBox, QGroupBox, \
QDoubleSpinBox

from sportorg import config
from sportorg.core.template import get_templates
Expand Down Expand Up @@ -75,6 +76,19 @@ def select_custom_path():
self.print_splits_checkbox = QCheckBox(_('Print splits'))
self.layout.addRow(self.print_splits_checkbox)

self.margin_group_box = QGroupBox(_('Margins'))
self.margin_layout = QFormLayout()
self.item_margin_left = QDoubleSpinBox()
self.margin_layout.addRow(QLabel(_('Left')), self.item_margin_left)
self.item_margin_top = QDoubleSpinBox()
self.margin_layout.addRow(QLabel(_('Top')), self.item_margin_top)
self.item_margin_right = QDoubleSpinBox()
self.margin_layout.addRow(QLabel(_('Right')), self.item_margin_right)
self.item_margin_bottom = QDoubleSpinBox()
self.margin_layout.addRow(QLabel(_('Bottom')), self.item_margin_bottom)
self.margin_group_box.setLayout(self.margin_layout)
self.layout.addRow(self.margin_group_box)

self.set_values()

def cancel_changes():
Expand Down Expand Up @@ -122,6 +136,11 @@ def set_values(self):
if template:
self.item_template.setCurrentText(template)

self.item_margin_left.setValue(obj.get_setting('print_margin_left', 5.0))
self.item_margin_top.setValue(obj.get_setting('print_margin_top', 5.0))
self.item_margin_right.setValue(obj.get_setting('print_margin_right', 5.0))
self.item_margin_bottom.setValue(obj.get_setting('print_margin_bottom', 5.0))

def select_printer(self):
try:
printer = QtPrintSupport.QPrinter()
Expand All @@ -141,3 +160,8 @@ def apply_changes_impl(self):
obj.set_setting('split_printer', split_printer)
obj.set_setting('split_printout', self.print_splits_checkbox.isChecked())
obj.set_setting('split_template', self.item_template.currentText())

obj.set_setting('print_margin_left', self.item_margin_left.value())
obj.set_setting('print_margin_top', self.item_margin_top.value())
obj.set_setting('print_margin_right', self.item_margin_right.value())
obj.set_setting('print_margin_bottom', self.item_margin_bottom.value())
9 changes: 8 additions & 1 deletion sportorg/modules/printing/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@ def split_printout(result):
template = get_text_from_file(template_path, **spl.get_dict_printout(person))
if not printer:
raise NoPrinterSelectedException('No printer selected')
print_html(printer, template)
print_html(
printer,
template,
obj.get_setting('print_margin_left', 5.0),
obj.get_setting('print_margin_top', 5.0),
obj.get_setting('print_margin_right', 5.0),
obj.get_setting('print_margin_bottom', 5.0),
)
18 changes: 14 additions & 4 deletions sportorg/modules/printing/printing.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@


class PrintProcess(Process):
def __init__(self, printer_name, html):
def __init__(self, printer_name, html, left=5.0, top=5.0, right=5.0, bottom=5.0):
super().__init__()
self.printer_name = printer_name
self.html = html
self.margin_left = left
self.margin_top = top
self.margin_right = right
self.margin_bottom = bottom

def run(self):
try:
Expand All @@ -36,7 +40,13 @@ def run(self):
text_document = QTextDocument()

printer.setFullPage(True)
printer.setPageMargins(1, 1, 1, 1, QPrinter.Millimeter)
printer.setPageMargins(
self.margin_left,
self.margin_top,
self.margin_right,
self.margin_bottom,
QPrinter.Millimeter
)

page_size = QSizeF()
page_size.setHeight(printer.height())
Expand All @@ -50,8 +60,8 @@ def run(self):
logging.error(str(e))


def print_html(printer_name, html):
thread = PrintProcess(printer_name, html)
def print_html(printer_name, html, left=5.0, top=5.0, right=5.0, bottom=5.0):
thread = PrintProcess(printer_name, html, left, top, right, bottom)
thread.start()
logging.info('printing poccess started')

Expand Down

0 comments on commit 3e024b1

Please sign in to comment.