Воркед
This commit is contained in:
1 parent
ac32c55ab9
commit
ee94d8e529
1138 files changed
+55771
-77901
No files matched your search
@@ -0,0 +1,91 @@
|
||||
from PyQt6.QtWidgets import (QWidget, QVBoxLayout, QHBoxLayout,
|
||||
QLabel, QPushButton, QTextEdit, QComboBox)
|
||||
from PyQt6.QtCore import Qt, pyqtSignal
|
||||
from PyQt6.QtGui import QTextCursor
|
||||
from ..styles.style_constants import StyleConstants
|
||||
from ..styles.icons import IconManager, IconType
|
||||
|
||||
class ConsoleWindow(QWidget):
|
||||
"""Окно для консольного вывода"""
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.icon_manager = IconManager.get_instance()
|
||||
self.setup_ui()
|
||||
|
||||
def setup_ui(self):
|
||||
self.setWindowTitle("Консоль")
|
||||
self.resize(600, 400)
|
||||
|
||||
# Основной layout
|
||||
layout = QVBoxLayout(self)
|
||||
layout.setSpacing(StyleConstants.SPACING['md'])
|
||||
layout.setContentsMargins(
|
||||
StyleConstants.SPACING['lg'],
|
||||
StyleConstants.SPACING['lg'],
|
||||
StyleConstants.SPACING['lg'],
|
||||
StyleConstants.SPACING['lg']
|
||||
)
|
||||
|
||||
# Верхняя панель
|
||||
top_panel = QHBoxLayout()
|
||||
|
||||
# Уровень логирования
|
||||
self.log_level = QComboBox()
|
||||
self.log_level.addItems(["INFO", "WARNING", "ERROR", "DEBUG"])
|
||||
top_panel.addWidget(self.log_level)
|
||||
|
||||
# Кнопки
|
||||
clear_btn = QPushButton("Очистить")
|
||||
clear_btn.setIcon(self.icon_manager.get_icon(IconType.DELETE))
|
||||
clear_btn.clicked.connect(self.clear_console)
|
||||
top_panel.addWidget(clear_btn)
|
||||
|
||||
save_btn = QPushButton("Сохранить")
|
||||
save_btn.setIcon(self.icon_manager.get_icon(IconType.SAVE))
|
||||
top_panel.addWidget(save_btn)
|
||||
|
||||
top_panel.addStretch()
|
||||
layout.addLayout(top_panel)
|
||||
|
||||
# Консоль
|
||||
self.console = QTextEdit()
|
||||
self.console.setReadOnly(True)
|
||||
self.console.setStyleSheet(f"""
|
||||
QTextEdit {{
|
||||
background-color: {StyleConstants.COLORS['dark']['background']};
|
||||
color: {StyleConstants.COLORS['dark']['text']};
|
||||
font-family: 'Consolas', monospace;
|
||||
font-size: {StyleConstants.FONTS['size']['md']};
|
||||
padding: {StyleConstants.SPACING['md']}px;
|
||||
border-radius: {StyleConstants.RADIUS['md']}px;
|
||||
}}
|
||||
""")
|
||||
layout.addWidget(self.console)
|
||||
|
||||
# Применяем стили
|
||||
self.setStyleSheet(StyleConstants.get_base_styles('light'))
|
||||
|
||||
def log(self, message: str, level: str = "INFO"):
|
||||
"""Добавление сообщения в консоль"""
|
||||
color = {
|
||||
"INFO": StyleConstants.COLORS['primary'],
|
||||
"WARNING": StyleConstants.COLORS['warning'],
|
||||
"ERROR": StyleConstants.COLORS['error'],
|
||||
"DEBUG": StyleConstants.COLORS['secondary']
|
||||
}.get(level, StyleConstants.COLORS['primary'])
|
||||
|
||||
# Форматируем сообщение
|
||||
formatted_message = f'<span style="color: {color}">[{level}]</span> {message}<br>'
|
||||
|
||||
# Добавляем сообщение в консоль
|
||||
cursor = self.console.textCursor()
|
||||
cursor.movePosition(QTextCursor.MoveOperation.End)
|
||||
cursor.insertHtml(formatted_message)
|
||||
|
||||
# Прокручиваем к последнему сообщению
|
||||
self.console.setTextCursor(cursor)
|
||||
self.console.ensureCursorVisible()
|
||||
|
||||
def clear_console(self):
|
||||
"""Очистка консоли"""
|
||||
self.console.clear()
|
||||
Reference in new issue
Block a user