print_options_dialog.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. """
  2. Print Options Dialog
  3. Dialog for selecting print options before printing a report.
  4. """
  5. from PyQt5.QtWidgets import (QDialog, QVBoxLayout, QHBoxLayout, QLabel,
  6. QPushButton, QRadioButton, QButtonGroup, QGroupBox)
  7. from PyQt5.QtCore import Qt
  8. from PyQt5.QtGui import QFont
  9. class PrintOptionsDialog(QDialog):
  10. """
  11. Dialog for selecting print options.
  12. Allows user to choose whether to include visualizations in print.
  13. """
  14. def __init__(self, parent=None):
  15. """Initialize the print options dialog."""
  16. super().__init__(parent)
  17. self.setWindowTitle("Print Options")
  18. self.setModal(True)
  19. self.setMinimumWidth(400)
  20. self.setMinimumHeight(250)
  21. self.include_visualizations = True # Default: include visualizations
  22. self.init_ui()
  23. def init_ui(self):
  24. """Initialize the UI components."""
  25. layout = QVBoxLayout(self)
  26. layout.setContentsMargins(20, 20, 20, 20)
  27. layout.setSpacing(15)
  28. # Title
  29. title = QLabel("Print Report")
  30. title_font = QFont("Arial", 14, QFont.Bold)
  31. title.setFont(title_font)
  32. layout.addWidget(title)
  33. # Description
  34. description = QLabel("How would you like to print this report?")
  35. description.setStyleSheet("color: #555; font-size: 12px;")
  36. layout.addWidget(description)
  37. # Options group
  38. options_group = QGroupBox("Print Options")
  39. options_layout = QVBoxLayout()
  40. # Button group for radio buttons
  41. self.button_group = QButtonGroup()
  42. # Option 1: Include visualizations
  43. self.include_viz_radio = QRadioButton("Include All Visualizations (Recommended)")
  44. self.include_viz_radio.setChecked(True)
  45. self.include_viz_radio.setStyleSheet("font-size: 12px; padding: 8px;")
  46. self.button_group.addButton(self.include_viz_radio, 0)
  47. options_layout.addWidget(self.include_viz_radio)
  48. # Description for option 1
  49. desc1 = QLabel(" • Prints all analysis results and visualizations\n"
  50. " • Best for comprehensive reports\n"
  51. " • May span multiple pages")
  52. desc1.setStyleSheet("color: #777; font-size: 11px; margin-left: 25px; margin-bottom: 10px;")
  53. options_layout.addWidget(desc1)
  54. # Option 2: Text only
  55. self.text_only_radio = QRadioButton("Text Only (Compact)")
  56. self.text_only_radio.setStyleSheet("font-size: 12px; padding: 8px;")
  57. self.button_group.addButton(self.text_only_radio, 1)
  58. options_layout.addWidget(self.text_only_radio)
  59. # Description for option 2
  60. desc2 = QLabel(" • Prints analysis results and text data only\n"
  61. " • More compact format\n"
  62. " • Faster to print")
  63. desc2.setStyleSheet("color: #777; font-size: 11px; margin-left: 25px; margin-bottom: 15px;")
  64. options_layout.addWidget(desc2)
  65. options_group.setLayout(options_layout)
  66. layout.addWidget(options_group)
  67. layout.addStretch()
  68. # Button layout
  69. button_layout = QHBoxLayout()
  70. button_layout.addStretch()
  71. # Cancel button
  72. cancel_btn = QPushButton("Cancel")
  73. cancel_btn.setMinimumWidth(100)
  74. cancel_btn.setStyleSheet("""
  75. QPushButton {
  76. padding: 8px 16px;
  77. background-color: #95a5a6;
  78. color: white;
  79. font-weight: bold;
  80. border-radius: 4px;
  81. border: none;
  82. }
  83. QPushButton:hover {
  84. background-color: #7f8c8d;
  85. }
  86. """)
  87. cancel_btn.clicked.connect(self.reject)
  88. button_layout.addWidget(cancel_btn)
  89. # Print button
  90. print_btn = QPushButton("Print")
  91. print_btn.setMinimumWidth(100)
  92. print_btn.setStyleSheet("""
  93. QPushButton {
  94. padding: 8px 16px;
  95. background-color: #27ae60;
  96. color: white;
  97. font-weight: bold;
  98. border-radius: 4px;
  99. border: none;
  100. }
  101. QPushButton:hover {
  102. background-color: #229954;
  103. }
  104. """)
  105. print_btn.clicked.connect(self.accept)
  106. button_layout.addWidget(print_btn)
  107. layout.addLayout(button_layout)
  108. def get_include_visualizations(self) -> bool:
  109. """
  110. Get whether visualizations should be included.
  111. Returns:
  112. bool: True if visualizations should be included, False for text only
  113. """
  114. return self.include_viz_radio.isChecked()