-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_ui.py
73 lines (55 loc) · 1.96 KB
/
main_ui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from typing import List, Optional
import enaml
from enaml.qt.qt_application import QtApplication
from ui_filter_data import UiData, UiSource, UiFilter
from ui_popup_model import UiPopupState
from ui_source_adapter import FedstatUiSourceAdapter
def on_save_clicked(self: UiSource, file_path, parent_window):
if not file_path:
return
with enaml.imports():
from grabber_view import NotificationPopup
state = UiPopupState(is_saving=True, is_succeed=False)
NotificationPopup(parent_window, state=state).show()
def callback(result):
state.is_saving = False
state.is_succeed = result
self.adapter.save(self.filters, file_path, callback)
def on_selected(self: UiSource):
self.is_loading = True
self.is_error = False
def callback(filters: Optional[List[UiFilter]], exception: Optional[Exception]):
self.is_loading = False
if filters:
self.filters = filters
if exception:
self.is_error = True
if exception is IOError:
self.error_msg = 'Ошибка сети…'
else:
self.error_msg = 'Неизвестная ошибка…'
self.adapter.load(callback)
def main():
with enaml.imports():
from grabber_view import Main
app = QtApplication()
sources = [
UiSource(
id=57796,
title='Индексы цен на прочую продукцию (затраты, услуги) инвестиционного назначения с 2017 г.',
filters=[],
adapter=FedstatUiSourceAdapter(),
on_save_clicked=on_save_clicked,
on_selected=on_selected,
),
# UiSource(
# id=2,
# title='Мур мур мур',
# filters=[]
# )
]
view = Main(ui_data=UiData(sources=sources, selected_source=sources[0]))
view.show()
app.start()
if __name__ == '__main__':
main()