переделал приложение, сделал нормальное отображение информации, поменял вид
This commit is contained in:
parent
310ecb6fda
commit
864af4e1b4
Binary file not shown.
Binary file not shown.
173
app.py
173
app.py
|
@ -2,156 +2,123 @@ from kivy.app import App
|
||||||
from kivy.uix.button import Button
|
from kivy.uix.button import Button
|
||||||
from kivy.uix.label import Label
|
from kivy.uix.label import Label
|
||||||
from kivy.uix.boxlayout import BoxLayout
|
from kivy.uix.boxlayout import BoxLayout
|
||||||
|
from kivy.uix.scrollview import ScrollView
|
||||||
from kivy.core.window import Window
|
from kivy.core.window import Window
|
||||||
from kivy.clock import Clock
|
from kivy.clock import Clock
|
||||||
from export_opened_to_raster import export_opened_to_raster # Импорт функции обработки
|
from kivy.metrics import dp
|
||||||
from save_to_iges import save_opened_to_iges # Импорт функции сохранения в IGES
|
from kivy.properties import StringProperty
|
||||||
from get_all_sheets import get_all_sheets # Импорт функции для получения всех листов
|
from export_opened_to_raster import export_opened_to_raster
|
||||||
from project_support import project_support # Импорт функции Project Support
|
from save_to_iges import save_opened_to_iges
|
||||||
|
from get_all_sheets import get_all_sheets
|
||||||
|
from project_support import project_support
|
||||||
|
|
||||||
|
class ScrollableLabel(ScrollView):
|
||||||
|
text = StringProperty('')
|
||||||
|
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
|
self.label = Label(
|
||||||
|
size_hint_y=None,
|
||||||
|
font_size=dp(18),
|
||||||
|
halign='left',
|
||||||
|
valign='top',
|
||||||
|
padding=(dp(15), dp(15)),
|
||||||
|
markup=True
|
||||||
|
)
|
||||||
|
self.label.bind(
|
||||||
|
texture_size=self._update_label_size,
|
||||||
|
width=lambda *x: setattr(self.label, 'text_size', (self.width, None))
|
||||||
|
)
|
||||||
|
self.bind(
|
||||||
|
width=lambda *x: setattr(self.label, 'text_size', (self.width, None))
|
||||||
|
)
|
||||||
|
self.add_widget(self.label)
|
||||||
|
|
||||||
|
def _update_label_size(self, instance, size):
|
||||||
|
instance.size = (self.width, size[1])
|
||||||
|
|
||||||
|
def on_text(self, instance, value):
|
||||||
|
self.label.text = value
|
||||||
|
|
||||||
|
class KompasApp(App):
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
self.title = "Kompas Saver" # Установка заголовка окна
|
||||||
|
|
||||||
class MyApp(App):
|
|
||||||
def build(self):
|
def build(self):
|
||||||
# Устанавливаем размер окна (подходит для ПК)
|
|
||||||
Window.size = (800, 600)
|
Window.size = (800, 600)
|
||||||
|
|
||||||
# Главный контейнер (горизонтальный)
|
|
||||||
main_layout = BoxLayout(orientation='horizontal', spacing=10, padding=10)
|
main_layout = BoxLayout(orientation='horizontal', spacing=10, padding=10)
|
||||||
|
|
||||||
# Левая панель (на одну треть экрана)
|
# Левая панель (кнопки)
|
||||||
left_panel = BoxLayout(orientation='vertical', size_hint=(0.3, 1), spacing=10)
|
left_panel = BoxLayout(orientation='vertical', size_hint=(0.3, 1), spacing=10)
|
||||||
|
|
||||||
# Заголовок
|
|
||||||
header = Label(text="Kompas Saver", size_hint=(1, 0.1), font_size=24, bold=True)
|
header = Label(text="Kompas Saver", size_hint=(1, 0.1), font_size=24, bold=True)
|
||||||
|
|
||||||
# Кнопки слева
|
|
||||||
button1 = Button(text="Создать PDF", on_press=self.process_kompas)
|
button1 = Button(text="Создать PDF", on_press=self.process_kompas)
|
||||||
button2 = Button(text="Сохранить в IGES", on_press=self.save_to_iges)
|
button2 = Button(text="Сохранить в IGES", on_press=self.save_to_iges)
|
||||||
button3 = Button(text="Get All Sheets", on_press=self.get_all_sheets)
|
button3 = Button(text="Get all sheets", on_press=self.get_all_sheets)
|
||||||
button4 = Button(text="Project Support", on_press=self.project_support)
|
button4 = Button(text="Создать чертеж 3D модели", on_press=self.project_support)
|
||||||
|
|
||||||
# Добавляем заголовок и кнопки в левую панель
|
|
||||||
left_panel.add_widget(header)
|
left_panel.add_widget(header)
|
||||||
left_panel.add_widget(button1)
|
left_panel.add_widget(button1)
|
||||||
left_panel.add_widget(button2)
|
left_panel.add_widget(button2)
|
||||||
left_panel.add_widget(button3)
|
left_panel.add_widget(button3)
|
||||||
left_panel.add_widget(button4)
|
left_panel.add_widget(button4)
|
||||||
|
|
||||||
# Правая панель (пространство для контента)
|
# Правая панель (прокручиваемый текст)
|
||||||
self.right_panel = BoxLayout(orientation='vertical', size_hint=(0.7, 1))
|
self.right_panel = BoxLayout(orientation='vertical', size_hint=(0.7, 1))
|
||||||
self.right_panel.add_widget(Label(text="Выберите действие", font_size=18))
|
self.scroll_label = ScrollableLabel()
|
||||||
|
self.right_panel.add_widget(self.scroll_label)
|
||||||
|
|
||||||
# Добавляем левую и правую панели в главный контейнер
|
|
||||||
main_layout.add_widget(left_panel)
|
main_layout.add_widget(left_panel)
|
||||||
main_layout.add_widget(self.right_panel)
|
main_layout.add_widget(self.right_panel)
|
||||||
|
|
||||||
return main_layout
|
return main_layout
|
||||||
|
|
||||||
def show_content(self, instance):
|
def update_output(self, text):
|
||||||
# Очищаем правую панель
|
self.scroll_label.text = text
|
||||||
self.right_panel.clear_widgets()
|
|
||||||
|
|
||||||
# Добавляем контент в зависимости от нажатой кнопки
|
|
||||||
if instance.text == "Кнопка 4":
|
|
||||||
content = Label(text="Контент для Кнопки 4", font_size=18)
|
|
||||||
|
|
||||||
self.right_panel.add_widget(content)
|
|
||||||
|
|
||||||
def process_kompas(self, instance):
|
def process_kompas(self, instance):
|
||||||
# Очищаем правую панель
|
self.update_output("Конвертация в PDF...\n")
|
||||||
self.right_panel.clear_widgets()
|
Clock.schedule_once(lambda dt: self._run_export(), 0.2)
|
||||||
|
|
||||||
# Добавляем сообщение о начале обработки
|
def _run_export(self):
|
||||||
self.right_panel.add_widget(Label(text="Обработка документов КОМПАС...", font_size=18))
|
|
||||||
|
|
||||||
# Запускаем обработку в отдельном потоке (чтобы не блокировать интерфейс)
|
|
||||||
Clock.schedule_once(lambda dt: self.run_kompas_processing(), 0.1)
|
|
||||||
|
|
||||||
def run_kompas_processing(self):
|
|
||||||
try:
|
try:
|
||||||
# Вызываем функцию обработки документов КОМПАС
|
|
||||||
result = export_opened_to_raster()
|
result = export_opened_to_raster()
|
||||||
|
self.update_output(result)
|
||||||
# Обновляем правую панель с результатом
|
|
||||||
self.right_panel.clear_widgets()
|
|
||||||
self.right_panel.add_widget(Label(text=result, font_size=18))
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# В случае ошибки выводим сообщение
|
self.update_output(f"[color=ff3333]Ошибка: {str(e)}[/color]")
|
||||||
self.right_panel.clear_widgets()
|
|
||||||
self.right_panel.add_widget(Label(text=f"Ошибка: {e}", font_size=18))
|
|
||||||
|
|
||||||
def save_to_iges(self, instance):
|
def save_to_iges(self, instance):
|
||||||
# Очищаем правую панель
|
self.update_output("Экспорт в IGES...")
|
||||||
self.right_panel.clear_widgets()
|
Clock.schedule_once(lambda dt: self._run_save_iges(), 0.2)
|
||||||
|
|
||||||
# Добавляем сообщение о начале сохранения
|
def _run_save_iges(self):
|
||||||
self.right_panel.add_widget(Label(text="Сохранение документов в IGES...", font_size=18))
|
|
||||||
|
|
||||||
# Запускаем сохранение в отдельном потоке (чтобы не блокировать интерфейс)
|
|
||||||
Clock.schedule_once(lambda dt: self.run_save_to_iges(), 0.1)
|
|
||||||
|
|
||||||
def run_save_to_iges(self):
|
|
||||||
try:
|
try:
|
||||||
# Вызываем функцию сохранения в IGES
|
|
||||||
result = save_opened_to_iges()
|
result = save_opened_to_iges()
|
||||||
|
self.update_output(result)
|
||||||
# Обновляем правую панель с результатом
|
|
||||||
self.right_panel.clear_widgets()
|
|
||||||
self.right_panel.add_widget(Label(text=result, font_size=18))
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# В случае ошибки выводим сообщение
|
self.update_output(f"[color=ff3333]Ошибка: {str(e)}[/color]")
|
||||||
self.right_panel.clear_widgets()
|
|
||||||
self.right_panel.add_widget(Label(text=f"Ошибка: {e}", font_size=18))
|
|
||||||
|
|
||||||
def get_all_sheets(self, instance):
|
def get_all_sheets(self, instance):
|
||||||
# Очищаем правую панель
|
self.update_output("Получение списка листов...")
|
||||||
self.right_panel.clear_widgets()
|
Clock.schedule_once(lambda dt: self._run_get_sheets(), 0.2)
|
||||||
|
|
||||||
# Добавляем сообщение о начале анализа
|
def _run_get_sheets(self):
|
||||||
self.right_panel.add_widget(Label(text="Анализ документов...", font_size=18))
|
|
||||||
|
|
||||||
# Запускаем анализ в отдельном потоке (чтобы не блокировать интерфейс)
|
|
||||||
Clock.schedule_once(lambda dt: self.run_get_all_sheets(), 0.1)
|
|
||||||
|
|
||||||
def run_get_all_sheets(self):
|
|
||||||
try:
|
try:
|
||||||
# Вызываем функцию для получения всех листов
|
|
||||||
result = get_all_sheets()
|
result = get_all_sheets()
|
||||||
|
self.update_output(result)
|
||||||
# Обновляем правую панель с результатом
|
|
||||||
self.right_panel.clear_widgets()
|
|
||||||
self.right_panel.add_widget(Label(text=result, font_size=18))
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# В случае ошибки выводим сообщение
|
self.update_output(f"[color=ff3333]Ошибка: {str(e)}[/color]")
|
||||||
self.right_panel.clear_widgets()
|
|
||||||
self.right_panel.add_widget(Label(text=f"Ошибка: {e}", font_size=18))
|
|
||||||
|
|
||||||
def project_support(self, instance):
|
def project_support(self, instance):
|
||||||
# Очищаем правую панель
|
self.update_output("Project Support...")
|
||||||
self.right_panel.clear_widgets()
|
Clock.schedule_once(lambda dt: self._run_project_support(), 0.2)
|
||||||
|
|
||||||
# Добавляем сообщение о начале поддержки проекта
|
def _run_project_support(self):
|
||||||
self.right_panel.add_widget(Label(text="Поддержка проекта...", font_size=18))
|
|
||||||
|
|
||||||
# Запускаем поддержку проекта в отдельном потоке (чтобы не блокировать интерфейс)
|
|
||||||
Clock.schedule_once(lambda dt: self.run_project_support(), 0.1)
|
|
||||||
|
|
||||||
def run_project_support(self):
|
|
||||||
try:
|
try:
|
||||||
# Вызываем функцию поддержки проекта
|
|
||||||
result = project_support()
|
result = project_support()
|
||||||
|
self.update_output(result)
|
||||||
# Обновляем правую панель с результатом
|
|
||||||
self.right_panel.clear_widgets()
|
|
||||||
self.right_panel.add_widget(Label(text=result, font_size=18))
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# В случае ошибки выводим сообщение
|
self.update_output(f"[color=ff3333]Ошибка: {str(e)}[/color]")
|
||||||
self.right_panel.clear_widgets()
|
|
||||||
self.right_panel.add_widget(Label(text=f"Ошибка: {e}", font_size=18))
|
|
||||||
|
|
||||||
# Запуск приложения
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
MyApp().run()
|
KompasApp().run()
|
|
@ -768,7 +768,7 @@
|
||||||
[],
|
[],
|
||||||
False,
|
False,
|
||||||
False,
|
False,
|
||||||
1742562368,
|
1742809051,
|
||||||
[('runw.exe',
|
[('runw.exe',
|
||||||
'c:\\projects\\3knopki\\.venv\\Lib\\site-packages\\PyInstaller\\bootloader\\Windows-64bit-intel\\runw.exe',
|
'c:\\projects\\3knopki\\.venv\\Lib\\site-packages\\PyInstaller\\bootloader\\Windows-64bit-intel\\runw.exe',
|
||||||
'EXECUTABLE')],
|
'EXECUTABLE')],
|
||||||
|
|
Binary file not shown.
|
@ -2,11 +2,18 @@
|
||||||
import pythoncom
|
import pythoncom
|
||||||
from win32com.client import Dispatch, gencache
|
from win32com.client import Dispatch, gencache
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
def save_opened_to_iges():
|
def save_opened_to_iges():
|
||||||
try:
|
try:
|
||||||
# Получи API интерфейсов версии 5
|
# Инициализация COM системы
|
||||||
|
pythoncom.CoInitialize()
|
||||||
|
|
||||||
|
# Получаем API интерфейсы
|
||||||
api5_module = gencache.EnsureModule("{0422828C-F174-495E-AC5D-D31014DBBE87}", 0, 1, 0)
|
api5_module = gencache.EnsureModule("{0422828C-F174-495E-AC5D-D31014DBBE87}", 0, 1, 0)
|
||||||
|
if api5_module is None:
|
||||||
|
raise Exception("Не удалось загрузить API Kompas 5")
|
||||||
|
|
||||||
api5_api = api5_module.KompasObject(
|
api5_api = api5_module.KompasObject(
|
||||||
Dispatch("Kompas.Application.5")._oleobj_.QueryInterface(
|
Dispatch("Kompas.Application.5")._oleobj_.QueryInterface(
|
||||||
api5_module.KompasObject.CLSID, pythoncom.IID_IDispatch
|
api5_module.KompasObject.CLSID, pythoncom.IID_IDispatch
|
||||||
|
@ -14,6 +21,9 @@ def save_opened_to_iges():
|
||||||
)
|
)
|
||||||
|
|
||||||
module = gencache.EnsureModule("{69AC2981-37C0-4379-84FD-5DD2F3C0A520}", 0, 1, 0)
|
module = gencache.EnsureModule("{69AC2981-37C0-4379-84FD-5DD2F3C0A520}", 0, 1, 0)
|
||||||
|
if module is None:
|
||||||
|
raise Exception("Не удалось загрузить API Kompas 7")
|
||||||
|
|
||||||
api = module.IKompasAPIObject(
|
api = module.IKompasAPIObject(
|
||||||
Dispatch("Kompas.Application.7")._oleobj_.QueryInterface(
|
Dispatch("Kompas.Application.7")._oleobj_.QueryInterface(
|
||||||
module.IKompasAPIObject.CLSID, pythoncom.IID_IDispatch
|
module.IKompasAPIObject.CLSID, pythoncom.IID_IDispatch
|
||||||
|
@ -25,8 +35,12 @@ def save_opened_to_iges():
|
||||||
).constants
|
).constants
|
||||||
|
|
||||||
application = module.IApplication(api)
|
application = module.IApplication(api)
|
||||||
|
|
||||||
application.Visible = True
|
application.Visible = True
|
||||||
|
|
||||||
|
result = []
|
||||||
|
ext = "igs"
|
||||||
|
saved_files = 0
|
||||||
|
|
||||||
for i in range(application.Documents.Count):
|
for i in range(application.Documents.Count):
|
||||||
try:
|
try:
|
||||||
doc = application.Documents.Open(i)
|
doc = application.Documents.Open(i)
|
||||||
|
@ -34,8 +48,13 @@ def save_opened_to_iges():
|
||||||
if doc_type in [k_constants.ksDocumentPart, k_constants.ksDocumentAssembly]:
|
if doc_type in [k_constants.ksDocumentPart, k_constants.ksDocumentAssembly]:
|
||||||
doc.Active = True
|
doc.Active = True
|
||||||
doc_path = doc.Path
|
doc_path = doc.Path
|
||||||
doc_name = "-".join(doc.Name.split(".")[:-1])
|
doc_name = os.path.splitext(doc.Name)[0]
|
||||||
print(f"Попытка сохранить {doc_name}")
|
|
||||||
|
save_path = os.path.join(doc_path, ext)
|
||||||
|
os.makedirs(save_path, exist_ok=True)
|
||||||
|
|
||||||
|
filename = f"{doc_name}.{ext}"
|
||||||
|
full_path = os.path.normpath(os.path.join(save_path, filename))
|
||||||
|
|
||||||
doc_3d = module.IKompasDocument3D(doc)
|
doc_3d = module.IKompasDocument3D(doc)
|
||||||
doc_api5 = api5_api.ActiveDocument3D()
|
doc_api5 = api5_api.ActiveDocument3D()
|
||||||
|
@ -44,22 +63,24 @@ def save_opened_to_iges():
|
||||||
save_params.Init()
|
save_params.Init()
|
||||||
save_params.format = k_constants.ksConverterToIGES
|
save_params.format = k_constants.ksConverterToIGES
|
||||||
|
|
||||||
ext = "igs"
|
|
||||||
|
|
||||||
path = f"{doc_path}{ext}/"
|
|
||||||
filename = f"{doc_name}.{ext}"
|
|
||||||
full_path = "".join([path, filename])
|
|
||||||
|
|
||||||
if not os.path.exists(path):
|
|
||||||
os.makedirs(path)
|
|
||||||
|
|
||||||
doc_api5.SaveAsToAdditionFormat(full_path, save_params)
|
doc_api5.SaveAsToAdditionFormat(full_path, save_params)
|
||||||
print(f"Файл {doc_name} сохранен как IGES: {full_path}")
|
saved_files += 1
|
||||||
|
result.append(f"Успешно сохранено: {full_path}")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Ошибка при обработке документа {i}: {e}")
|
result.append(f"Ошибка при обработке документа {i} ({doc.Name}): {str(e)}")
|
||||||
|
|
||||||
return "Сохранение в IGES завершено."
|
if saved_files > 0:
|
||||||
|
result.insert(0, f"\nУспешно сохранено файлов: {saved_files}")
|
||||||
|
else:
|
||||||
|
result.append("Не найдено подходящих документов для сохранения")
|
||||||
|
|
||||||
|
return "\n".join(result)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return f"Произошла ошибка: {e}"
|
return f"Критическая ошибка: {str(e)}"
|
||||||
|
finally:
|
||||||
|
pythoncom.CoUninitialize()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print(save_opened_to_iges())
|
Loading…
Reference in New Issue