ToolQRCode.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. # ##########################################################
  2. # FlatCAM: 2D Post-processing for Manufacturing #
  3. # File Author: Marius Adrian Stanciu (c) #
  4. # Date: 3/10/2019 #
  5. # MIT Licence #
  6. # ##########################################################
  7. from PyQt5 import QtWidgets, QtCore
  8. from FlatCAMTool import FlatCAMTool
  9. from flatcamGUI.GUIElements import FCDoubleSpinner, EvalEntry, FCCheckBox
  10. from camlib import *
  11. from shapely.geometry import Point
  12. from shapely.geometry.base import *
  13. import math
  14. import io
  15. from datetime import datetime
  16. import logging
  17. import pyqrcode
  18. from lxml import etree as ET
  19. import gettext
  20. import FlatCAMTranslation as fcTranslate
  21. import builtins
  22. fcTranslate.apply_language('strings')
  23. if '_' not in builtins.__dict__:
  24. _ = gettext.gettext
  25. log = logging.getLogger('base')
  26. class QRCode(FlatCAMTool):
  27. toolName = _("QRCode Tool")
  28. def __init__(self, app):
  29. FlatCAMTool.__init__(self, app)
  30. self.app = app
  31. self.canvas = self.app.plotcanvas
  32. self.decimals = 4
  33. self.units = ''
  34. # ## Title
  35. title_label = QtWidgets.QLabel("%s" % self.toolName)
  36. title_label.setStyleSheet("""
  37. QLabel
  38. {
  39. font-size: 16px;
  40. font-weight: bold;
  41. }
  42. """)
  43. self.layout.addWidget(title_label)
  44. def run(self, toggle=True):
  45. self.app.report_usage("QRCode()")
  46. if toggle:
  47. # if the splitter is hidden, display it, else hide it but only if the current widget is the same
  48. if self.app.ui.splitter.sizes()[0] == 0:
  49. self.app.ui.splitter.setSizes([1, 1])
  50. else:
  51. try:
  52. if self.app.ui.tool_scroll_area.widget().objectName() == self.toolName:
  53. # if tab is populated with the tool but it does not have the focus, focus on it
  54. if not self.app.ui.notebook.currentWidget() is self.app.ui.tool_tab:
  55. # focus on Tool Tab
  56. self.app.ui.notebook.setCurrentWidget(self.app.ui.tool_tab)
  57. else:
  58. self.app.ui.splitter.setSizes([0, 1])
  59. except AttributeError:
  60. pass
  61. else:
  62. if self.app.ui.splitter.sizes()[0] == 0:
  63. self.app.ui.splitter.setSizes([1, 1])
  64. FlatCAMTool.run(self)
  65. self.set_tool_ui()
  66. self.app.ui.notebook.setTabText(2, _("QRCode Tool"))
  67. self.execute()
  68. def install(self, icon=None, separator=None, **kwargs):
  69. FlatCAMTool.install(self, icon, separator, shortcut='ALT+Q', **kwargs)
  70. def set_tool_ui(self):
  71. self.units = self.app.ui.general_defaults_form.general_app_group.units_radio.get_value().upper()
  72. def execute(self):
  73. svg_file = io.StringIO('')
  74. svg_class = pyqrcode.QRCode("FlatCAM - 2D - Computer aided PCB Manufacturing Tool")
  75. svg_class.svg(svg_file, scale=4, xmldecl=False)
  76. def obj_init(geo_obj, app_obj):
  77. print(svg_file)
  78. geo_obj.import_svg(svg_file)
  79. with self.app.proc_container.new("Import SVG"):
  80. # Object creation
  81. self.app.new_object('geometry', 'generated_qrcode', obj_init, plot=False)
  82. # # Register recent file
  83. # self.app.file_opened.emit("svg", img)
  84. #
  85. # # GUI feedback
  86. # self.app.inform.emit("Opened: " + img)