actions list
This commit is contained in:
parent
a922331793
commit
27ea6e903e
|
@ -33,8 +33,10 @@ class PythonJSBridge(QObject):
|
|||
data = None
|
||||
if command == KompasCommand.OPEN_KOMPAS:
|
||||
data = self.kompas.get_open_documents()
|
||||
if command == KompasCommand.GET_AVAILABLE_ACTIONS:
|
||||
data = self.kompas.get_available_actions()
|
||||
|
||||
return json.dumps(data)
|
||||
return json.dumps(data, ensure_ascii=False)
|
||||
|
||||
def send_event_to_js(self, event_type: str, data: dict):
|
||||
self.emitter.onEvent.emit(event_type, data)
|
1
enums.py
1
enums.py
|
@ -2,6 +2,7 @@ from enum import Enum
|
|||
|
||||
class KompasCommand(str, Enum):
|
||||
OPEN_KOMPAS = "open_kompas"
|
||||
GET_AVAILABLE_ACTIONS = "get_available_actions"
|
||||
|
||||
@classmethod
|
||||
def has_value(cls, value):
|
||||
|
|
8
main.py
8
main.py
|
@ -7,23 +7,17 @@ from PyQt6.QtCore import QUrl, QThread
|
|||
|
||||
from config import MAIN_URL
|
||||
from bridge import PythonJSBridge
|
||||
from parser.main import KompasDocumentParser
|
||||
|
||||
|
||||
class KompasWorker(QThread):
|
||||
def run(self):
|
||||
pythoncom.CoInitialize()
|
||||
self.parser = KompasDocumentParser()
|
||||
|
||||
|
||||
class BrowserWindow(QMainWindow):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setWindowTitle("QT6 Браузер")
|
||||
self.resize(1000, 800)
|
||||
|
||||
self.kompas_thread = KompasWorker()
|
||||
self.kompas_thread.start()
|
||||
self.resize(1366, 768)
|
||||
|
||||
container = QWidget()
|
||||
layout = QVBoxLayout()
|
||||
|
|
|
@ -22,6 +22,7 @@ class KompasDocumentParser:
|
|||
"""Инициализация API КОМПАС версий 5 и 7"""
|
||||
try:
|
||||
import pythoncom
|
||||
|
||||
pythoncom.CoInitialize()
|
||||
|
||||
# Получаем API версии 5
|
||||
|
@ -62,7 +63,9 @@ class KompasDocumentParser:
|
|||
|
||||
for i in range(docs_collection.Count):
|
||||
try:
|
||||
doc = docs_collection.Item(i + 1) # Индексация с 1
|
||||
doc = docs_collection.Item(i) # Индексация с 1
|
||||
if doc is None:
|
||||
continue
|
||||
|
||||
documents.append(
|
||||
{
|
||||
|
@ -76,3 +79,56 @@ class KompasDocumentParser:
|
|||
print(f"Ошибка при обработке документа #{i + 1}: {e}")
|
||||
|
||||
return documents
|
||||
|
||||
# --- Заглушки для действий ---
|
||||
|
||||
def get_all_sheets(self):
|
||||
"""Заглушка: Извлечение данных о листовых деталях"""
|
||||
pass
|
||||
|
||||
def save_to_iges(self):
|
||||
"""Заглушка: Экспорт в IGES"""
|
||||
pass
|
||||
|
||||
def collect_statistics(self):
|
||||
"""Заглушка: Сбор статистики по элементам, гибам и сваркам"""
|
||||
pass
|
||||
|
||||
def export_to_raster(self):
|
||||
"""Заглушка: Экспорт в растровый формат"""
|
||||
pass
|
||||
|
||||
def get_available_actions(self):
|
||||
"""
|
||||
Возвращает список доступных действий и допустимые типы документов
|
||||
Формат: { action_key: { 'label': str, 'allowed_types': list } }
|
||||
"""
|
||||
# Допустимые типы документов
|
||||
ALLOWED_TYPES_3D = [
|
||||
self.constants.ksDocumentPart,
|
||||
self.constants.ksDocumentAssembly,
|
||||
]
|
||||
ALLOWED_TYPES_2D = [
|
||||
self.constants.ksDocumentDrawing,
|
||||
self.constants.ksDocumentFragment,
|
||||
]
|
||||
ALLOWED_TYPES_SPEC = [self.constants.ksDocumentSpecification]
|
||||
ALLOWED_TYPES_ALL = ALLOWED_TYPES_3D + ALLOWED_TYPES_2D + ALLOWED_TYPES_SPEC
|
||||
return {
|
||||
"iges": {
|
||||
"label": "Сохранить как IGES",
|
||||
"allowed_types": ALLOWED_TYPES_3D,
|
||||
},
|
||||
"stats": {
|
||||
"label": "Собрать статистику по элементам",
|
||||
"allowed_types": ALLOWED_TYPES_3D,
|
||||
},
|
||||
"export_pdf": {
|
||||
"label": "Экспортировать в PDF",
|
||||
"allowed_types": ALLOWED_TYPES_2D + ALLOWED_TYPES_SPEC,
|
||||
},
|
||||
"project_support": {
|
||||
"label": "Создать чертежи деталей",
|
||||
"allowed_types": ALLOWED_TYPES_3D,
|
||||
},
|
||||
}
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
# kompas_worker.py
|
||||
from PyQt6.QtCore import QObject, pyqtSignal
|
||||
import pythoncom
|
||||
from parser.main import KompasDocumentParser
|
||||
|
||||
|
||||
class KompasWorker(QObject):
|
||||
result_ready = pyqtSignal(object)
|
||||
error_occurred = pyqtSignal(str)
|
||||
|
||||
def run_kompas(self):
|
||||
try:
|
||||
# Инициализируем COM правильно
|
||||
pythoncom.CoInitializeEx(pythoncom.COINIT_APARTMENTTHREADED)
|
||||
|
||||
# Выполняем работу с КОМПАС
|
||||
parser = KompasDocumentParser()
|
||||
documents = parser.get_open_documents()
|
||||
|
||||
# Отправляем результат обратно
|
||||
self.result_ready.emit(documents)
|
||||
except Exception as e:
|
||||
import traceback
|
||||
error_msg = f"[Ошибка] {e}\n{traceback.format_exc()}"
|
||||
self.error_occurred.emit(error_msg)
|
||||
finally:
|
||||
pythoncom.CoUninitialize()
|
Loading…
Reference in New Issue