docsetdialog.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. # @Author: Bachir Soussi Chiadmi <bach>
  4. # @Date: 23-05-2017
  5. # @Email: bachir@figureslibres.io
  6. # @Last modified by: bach
  7. # @Last modified time: 03-06-2017
  8. # @License: GPL-V3
  9. import os
  10. # from PyQt5.QtCore import QLine
  11. from PyQt5.QtGui import QIcon, QIntValidator
  12. from PyQt5.QtWidgets import QWidget, QLabel, QDialog, QGroupBox, QDialogButtonBox, QVBoxLayout, QHBoxLayout, QFormLayout, QLineEdit, QComboBox, QSpinBox, QFrame
  13. class DocsetDialog(QDialog):
  14. def __init__(self, parent):
  15. super(DocsetDialog, self).__init__(parent)
  16. self.parent = parent
  17. self.createFormGroupBox()
  18. buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
  19. buttonBox.accepted.connect(self.accept)
  20. buttonBox.rejected.connect(self.reject)
  21. mainLayout = QVBoxLayout()
  22. mainLayout.addWidget(self.formGroupBox)
  23. mainLayout.addWidget(buttonBox)
  24. self.setLayout(mainLayout)
  25. self.setWindowTitle("Document settings")
  26. def createFormGroupBox(self):
  27. ds = self.parent.core.docsettings
  28. self.formGroupBox = QWidget()
  29. vbox = QVBoxLayout()
  30. vbox.setContentsMargins(0,0,0,0)
  31. self.formGroupBox.setLayout(vbox)
  32. topGroupBox = QWidget()
  33. topformlayout = QFormLayout()
  34. topformlayout.setContentsMargins(0,0,0,0)
  35. topGroupBox.setLayout(topformlayout)
  36. vbox.addWidget(topGroupBox)
  37. colsGroupBox = QWidget()
  38. hbox = QHBoxLayout()
  39. hbox.setContentsMargins(0,0,0,0)
  40. colsGroupBox.setLayout(hbox)
  41. vbox.addWidget(colsGroupBox)
  42. leftGroupBox = QGroupBox()
  43. leftformlayout = QFormLayout()
  44. # leftformlayout.setContentsMargins(0,0,0,0)
  45. leftGroupBox.setLayout(leftformlayout)
  46. hbox.addWidget(leftGroupBox)
  47. rightGroupBox = QGroupBox()
  48. rightformlayout = QFormLayout()
  49. # rightformlayout.setContentsMargins(0,0,0,0)
  50. rightGroupBox.setLayout(rightformlayout)
  51. hbox.addWidget(rightGroupBox)
  52. # headers
  53. self.headerOdd = QLineEdit(str(ds['ho']))
  54. topformlayout.addRow(QLabel("Header odd:"), self.headerOdd)
  55. self.headerEven = QLineEdit(str(ds['he']))
  56. topformlayout.addRow(QLabel("Header even:"), self.headerEven)
  57. self.np = NumLineEdit(str(ds['np']),3,True)
  58. leftformlayout.addRow(QLabel("Numbers of Pages:"), self.np)
  59. #
  60. leftformlayout.addRow(Line(self))
  61. #
  62. self.pw = NumLineEdit(str(ds['pw']))
  63. leftformlayout.addRow(QLabel("Page Width (mm):"), self.pw)
  64. self.ph = NumLineEdit(str(ds['ph']))
  65. leftformlayout.addRow(QLabel("Page Height (mm):"), self.ph)
  66. #
  67. leftformlayout.addRow(Line(self))
  68. #
  69. self.mt = NumLineEdit(str(ds['mt']),3)
  70. leftformlayout.addRow(QLabel("Margin Top (mm):"), self.mt)
  71. self.mb = NumLineEdit(str(ds['mb']),3)
  72. leftformlayout.addRow(QLabel("Margin Bottom (mm):"), self.mb)
  73. self.mi = NumLineEdit(str(ds['mi']),3)
  74. leftformlayout.addRow(QLabel("Margin inner (mm):"), self.mi)
  75. self.me = NumLineEdit(str(ds['me']),3)
  76. leftformlayout.addRow(QLabel("Margin external (mm):"), self.me)
  77. #
  78. self.cs = NumLineEdit(str(ds['cs']),3)
  79. rightformlayout.addRow(QLabel("Crop size (mm):"), self.cs)
  80. self.bs = NumLineEdit(str(ds['bs']),3)
  81. rightformlayout.addRow(QLabel("Bleed size (mm):"), self.bs)
  82. #
  83. rightformlayout.addRow(Line(self))
  84. #
  85. self.cn = NumLineEdit(str(ds['cn']),2,True)
  86. rightformlayout.addRow(QLabel("Columns number:"), self.cn)
  87. self.cg = NumLineEdit(str(ds['cg']),2)
  88. rightformlayout.addRow(QLabel("Columns gutters:"), self.cg)
  89. #
  90. self.rn = NumLineEdit(str(ds['rn']),2,True)
  91. rightformlayout.addRow(QLabel("Rows number:"), self.rn)
  92. self.rg = NumLineEdit(str(ds['rg']),2)
  93. rightformlayout.addRow(QLabel("Rows gutters:"), self.rg)
  94. #
  95. rightformlayout.addRow(Line(self))
  96. #
  97. self.lh = NumLineEdit(str(ds['lh']),2,True)
  98. rightformlayout.addRow(QLabel("Line height:"), self.lh)
  99. # self.formGroupBox.setLayout(layout)
  100. class NumLineEdit(QLineEdit):
  101. def __init__(self, parent, ml=5, int=False, mw=60):
  102. super(NumLineEdit, self).__init__(parent)
  103. self.setFixedWidth(mw)
  104. self.setMaxLength(ml)
  105. if int:
  106. self.setValidator(QIntValidator())
  107. else:
  108. # TODO: set float validator
  109. self.setValidator(QIntValidator())
  110. class Line(QFrame):
  111. def __init__(self, parent):
  112. super(Line, self).__init__(parent)
  113. self.setFrameShape(QFrame.HLine)
  114. self.setFrameShadow(QFrame.Sunken)