124 lines
4.5 KiB
Python
124 lines
4.5 KiB
Python
from kivy.app import App
|
|
from kivy.uix.button import Button
|
|
from kivy.uix.label import Label
|
|
from kivy.uix.boxlayout import BoxLayout
|
|
from kivy.uix.scrollview import ScrollView
|
|
from kivy.core.window import Window
|
|
from kivy.clock import Clock
|
|
from kivy.metrics import dp
|
|
from kivy.properties import StringProperty
|
|
from export_opened_to_raster import export_opened_to_raster
|
|
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" # Установка заголовка окна
|
|
|
|
def build(self):
|
|
Window.size = (800, 600)
|
|
main_layout = BoxLayout(orientation='horizontal', spacing=10, padding=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)
|
|
button1 = Button(text="Создать PDF", on_press=self.process_kompas)
|
|
button2 = Button(text="Сохранить в IGES", on_press=self.save_to_iges)
|
|
button3 = Button(text="Get all sheets", on_press=self.get_all_sheets)
|
|
button4 = Button(text="Projects Support", on_press=self.project_support)
|
|
|
|
left_panel.add_widget(header)
|
|
left_panel.add_widget(button1)
|
|
left_panel.add_widget(button2)
|
|
left_panel.add_widget(button3)
|
|
left_panel.add_widget(button4)
|
|
|
|
# Правая панель (прокручиваемый текст)
|
|
self.right_panel = BoxLayout(orientation='vertical', size_hint=(0.7, 1))
|
|
self.scroll_label = ScrollableLabel()
|
|
self.right_panel.add_widget(self.scroll_label)
|
|
|
|
main_layout.add_widget(left_panel)
|
|
main_layout.add_widget(self.right_panel)
|
|
return main_layout
|
|
|
|
def update_output(self, text):
|
|
self.scroll_label.text = text
|
|
|
|
def process_kompas(self, instance):
|
|
self.update_output("Конвертация в PDF...\n")
|
|
Clock.schedule_once(lambda dt: self._run_export(), 0.2)
|
|
|
|
def _run_export(self):
|
|
try:
|
|
result = export_opened_to_raster()
|
|
self.update_output(result)
|
|
except Exception as e:
|
|
self.update_output(f"[color=ff3333]Ошибка: {str(e)}[/color]")
|
|
|
|
def save_to_iges(self, instance):
|
|
self.update_output("Экспорт в IGES...")
|
|
Clock.schedule_once(lambda dt: self._run_save_iges(), 0.2)
|
|
|
|
def _run_save_iges(self):
|
|
try:
|
|
result = save_opened_to_iges()
|
|
self.update_output(result)
|
|
except Exception as e:
|
|
self.update_output(f"[color=ff3333]Ошибка: {str(e)}[/color]")
|
|
|
|
def get_all_sheets(self, instance):
|
|
self.update_output("Получение списка листов...")
|
|
Clock.schedule_once(lambda dt: self._run_get_sheets(), 0.2)
|
|
|
|
def _run_get_sheets(self):
|
|
try:
|
|
result = get_all_sheets()
|
|
self.update_output(result)
|
|
except Exception as e:
|
|
self.update_output(f"[color=ff3333]Ошибка: {str(e)}[/color]")
|
|
|
|
def project_support(self, instance):
|
|
self.update_output("Project Support...")
|
|
Clock.schedule_once(lambda dt: self._run_project_support(), 0.2)
|
|
|
|
def _run_project_support(self):
|
|
try:
|
|
result = project_support()
|
|
self.update_output(result)
|
|
except Exception as e:
|
|
self.update_output(f"[color=ff3333]Ошибка: {str(e)}[/color]")
|
|
|
|
if __name__ == '__main__':
|
|
KompasApp().run() |