Tools2QRCodePrefGroupUI.py 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. from PyQt5 import QtWidgets, QtCore
  2. from PyQt5.QtCore import Qt
  3. from flatcamGUI.GUIElements import FCSpinner, RadioSet, FCTextArea, FCEntry
  4. from flatcamGUI.preferences.OptionsGroupUI import OptionsGroupUI
  5. class Tools2QRCodePrefGroupUI(OptionsGroupUI):
  6. def __init__(self, decimals=4, parent=None):
  7. super(Tools2QRCodePrefGroupUI, self).__init__(self)
  8. self.setTitle(str(_("QRCode Tool Options")))
  9. self.decimals = decimals
  10. # ## Parameters
  11. self.qrlabel = QtWidgets.QLabel("<b>%s:</b>" % _("Parameters"))
  12. self.qrlabel.setToolTip(
  13. _("A tool to create a QRCode that can be inserted\n"
  14. "into a selected Gerber file, or it can be exported as a file.")
  15. )
  16. self.layout.addWidget(self.qrlabel)
  17. # ## Grid Layout
  18. grid_lay = QtWidgets.QGridLayout()
  19. self.layout.addLayout(grid_lay)
  20. grid_lay.setColumnStretch(0, 0)
  21. grid_lay.setColumnStretch(1, 1)
  22. # VERSION #
  23. self.version_label = QtWidgets.QLabel('%s:' % _("Version"))
  24. self.version_label.setToolTip(
  25. _("QRCode version can have values from 1 (21x21 boxes)\n"
  26. "to 40 (177x177 boxes).")
  27. )
  28. self.version_entry = FCSpinner()
  29. self.version_entry.set_range(1, 40)
  30. self.version_entry.setWrapping(True)
  31. grid_lay.addWidget(self.version_label, 1, 0)
  32. grid_lay.addWidget(self.version_entry, 1, 1)
  33. # ERROR CORRECTION #
  34. self.error_label = QtWidgets.QLabel('%s:' % _("Error correction"))
  35. self.error_label.setToolTip(
  36. _("Parameter that controls the error correction used for the QR Code.\n"
  37. "L = maximum 7%% errors can be corrected\n"
  38. "M = maximum 15%% errors can be corrected\n"
  39. "Q = maximum 25%% errors can be corrected\n"
  40. "H = maximum 30%% errors can be corrected.")
  41. )
  42. self.error_radio = RadioSet([{'label': 'L', 'value': 'L'},
  43. {'label': 'M', 'value': 'M'},
  44. {'label': 'Q', 'value': 'Q'},
  45. {'label': 'H', 'value': 'H'}])
  46. self.error_radio.setToolTip(
  47. _("Parameter that controls the error correction used for the QR Code.\n"
  48. "L = maximum 7%% errors can be corrected\n"
  49. "M = maximum 15%% errors can be corrected\n"
  50. "Q = maximum 25%% errors can be corrected\n"
  51. "H = maximum 30%% errors can be corrected.")
  52. )
  53. grid_lay.addWidget(self.error_label, 2, 0)
  54. grid_lay.addWidget(self.error_radio, 2, 1)
  55. # BOX SIZE #
  56. self.bsize_label = QtWidgets.QLabel('%s:' % _("Box Size"))
  57. self.bsize_label.setToolTip(
  58. _("Box size control the overall size of the QRcode\n"
  59. "by adjusting the size of each box in the code.")
  60. )
  61. self.bsize_entry = FCSpinner()
  62. self.bsize_entry.set_range(1, 9999)
  63. self.bsize_entry.setWrapping(True)
  64. grid_lay.addWidget(self.bsize_label, 3, 0)
  65. grid_lay.addWidget(self.bsize_entry, 3, 1)
  66. # BORDER SIZE #
  67. self.border_size_label = QtWidgets.QLabel('%s:' % _("Border Size"))
  68. self.border_size_label.setToolTip(
  69. _("Size of the QRCode border. How many boxes thick is the border.\n"
  70. "Default value is 4. The width of the clearance around the QRCode.")
  71. )
  72. self.border_size_entry = FCSpinner()
  73. self.border_size_entry.set_range(1, 9999)
  74. self.border_size_entry.setWrapping(True)
  75. grid_lay.addWidget(self.border_size_label, 4, 0)
  76. grid_lay.addWidget(self.border_size_entry, 4, 1)
  77. # Text box
  78. self.text_label = QtWidgets.QLabel('%s:' % _("QRCode Data"))
  79. self.text_label.setToolTip(
  80. _("QRCode Data. Alphanumeric text to be encoded in the QRCode.")
  81. )
  82. self.text_data = FCTextArea()
  83. self.text_data.setPlaceholderText(
  84. _("Add here the text to be included in the QRCode...")
  85. )
  86. grid_lay.addWidget(self.text_label, 5, 0)
  87. grid_lay.addWidget(self.text_data, 6, 0, 1, 2)
  88. # POLARITY CHOICE #
  89. self.pol_label = QtWidgets.QLabel('%s:' % _("Polarity"))
  90. self.pol_label.setToolTip(
  91. _("Choose the polarity of the QRCode.\n"
  92. "It can be drawn in a negative way (squares are clear)\n"
  93. "or in a positive way (squares are opaque).")
  94. )
  95. self.pol_radio = RadioSet([{'label': _('Negative'), 'value': 'neg'},
  96. {'label': _('Positive'), 'value': 'pos'}])
  97. self.pol_radio.setToolTip(
  98. _("Choose the type of QRCode to be created.\n"
  99. "If added on a Silkscreen Gerber file the QRCode may\n"
  100. "be added as positive. If it is added to a Copper Gerber\n"
  101. "file then perhaps the QRCode can be added as negative.")
  102. )
  103. grid_lay.addWidget(self.pol_label, 7, 0)
  104. grid_lay.addWidget(self.pol_radio, 7, 1)
  105. # BOUNDING BOX TYPE #
  106. self.bb_label = QtWidgets.QLabel('%s:' % _("Bounding Box"))
  107. self.bb_label.setToolTip(
  108. _("The bounding box, meaning the empty space that surrounds\n"
  109. "the QRCode geometry, can have a rounded or a square shape.")
  110. )
  111. self.bb_radio = RadioSet([{'label': _('Rounded'), 'value': 'r'},
  112. {'label': _('Square'), 'value': 's'}])
  113. self.bb_radio.setToolTip(
  114. _("The bounding box, meaning the empty space that surrounds\n"
  115. "the QRCode geometry, can have a rounded or a square shape.")
  116. )
  117. grid_lay.addWidget(self.bb_label, 8, 0)
  118. grid_lay.addWidget(self.bb_radio, 8, 1)
  119. # FILL COLOR #
  120. self.fill_color_label = QtWidgets.QLabel('%s:' % _('Fill Color'))
  121. self.fill_color_label.setToolTip(
  122. _("Set the QRCode fill color (squares color).")
  123. )
  124. self.fill_color_entry = FCEntry()
  125. self.fill_color_button = QtWidgets.QPushButton()
  126. self.fill_color_button.setFixedSize(15, 15)
  127. fill_lay_child = QtWidgets.QHBoxLayout()
  128. fill_lay_child.setContentsMargins(0, 0, 0, 0)
  129. fill_lay_child.addWidget(self.fill_color_entry)
  130. fill_lay_child.addWidget(self.fill_color_button, alignment=Qt.AlignRight)
  131. fill_lay_child.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
  132. fill_color_widget = QtWidgets.QWidget()
  133. fill_color_widget.setLayout(fill_lay_child)
  134. grid_lay.addWidget(self.fill_color_label, 9, 0)
  135. grid_lay.addWidget(fill_color_widget, 9, 1)
  136. # BACK COLOR #
  137. self.back_color_label = QtWidgets.QLabel('%s:' % _('Back Color'))
  138. self.back_color_label.setToolTip(
  139. _("Set the QRCode background color.")
  140. )
  141. self.back_color_entry = FCEntry()
  142. self.back_color_button = QtWidgets.QPushButton()
  143. self.back_color_button.setFixedSize(15, 15)
  144. back_lay_child = QtWidgets.QHBoxLayout()
  145. back_lay_child.setContentsMargins(0, 0, 0, 0)
  146. back_lay_child.addWidget(self.back_color_entry)
  147. back_lay_child.addWidget(self.back_color_button, alignment=Qt.AlignRight)
  148. back_lay_child.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
  149. back_color_widget = QtWidgets.QWidget()
  150. back_color_widget.setLayout(back_lay_child)
  151. grid_lay.addWidget(self.back_color_label, 10, 0)
  152. grid_lay.addWidget(back_color_widget, 10, 1)
  153. # Selection Limit
  154. self.sel_limit_label = QtWidgets.QLabel('%s:' % _("Selection limit"))
  155. self.sel_limit_label.setToolTip(
  156. _("Set the number of selected geometry\n"
  157. "items above which the utility geometry\n"
  158. "becomes just a selection rectangle.\n"
  159. "Increases the performance when moving a\n"
  160. "large number of geometric elements.")
  161. )
  162. self.sel_limit_entry = FCSpinner()
  163. self.sel_limit_entry.set_range(0, 9999)
  164. grid_lay.addWidget(self.sel_limit_label, 11, 0)
  165. grid_lay.addWidget(self.sel_limit_entry, 11, 1)
  166. # self.layout.addStretch()