-
Notifications
You must be signed in to change notification settings - Fork 0
/
searchdialog.py
75 lines (62 loc) · 2.52 KB
/
searchdialog.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
74
75
# -*- coding: utf-8 -*-
import os
from collections import OrderedDict
from qgis.PyQt.QtWidgets import QDialog, QTabWidget
from qgis.PyQt import uic
from .widget.searchwidget import (
SearchTextWidget,
SearchTibanWidget,
SearchOwnerWidget,
)
from .constants import OTHER_GROUP_NAME
UI_FILE = "dialog.ui"
class SearchDialog(QDialog):
def __init__(self, setting, parent=None):
super(SearchDialog, self).__init__(parent=parent)
directory = os.path.join(os.path.dirname(__file__), "ui")
ui_file = os.path.join(directory, UI_FILE)
uic.loadUi(ui_file, self)
self.init_gui(setting)
def init_gui(self, setting):
self.tab_groups = self.create_tab_groups(setting["SearchTabs"])
# create Page
for tab_setting in setting["SearchTabs"]:
page = self.create_page(tab_setting)
if self.tab_groups:
tab_group_widget = self.tab_groups[
tab_setting.get("group", OTHER_GROUP_NAME)
]
tab_group_widget.addTab(page, tab_setting["Title"])
else:
self.tabWidget.addTab(page, tab_setting["Title"])
self.set_window_title(0)
self.tabWidget.currentChanged.connect(self.set_window_title)
def set_window_title(self, index):
text = self.tabWidget.tabText(index)
self.setWindowTitle("地図検索: " + text)
def create_page(self, setting):
if setting["Title"] == "地番検索":
return SearchTibanWidget(setting)
if setting["Title"] == "所有者検索":
return SearchOwnerWidget(setting)
return SearchTextWidget(setting)
def create_tab_groups(self, search_tabs):
tab_groups = OrderedDict()
for search_tab in search_tabs:
group_name = search_tab.get("group", OTHER_GROUP_NAME)
if group_name not in tab_groups:
group_widget = QTabWidget()
tab_groups[group_name] = group_widget
if len(tab_groups) <= 1 and OTHER_GROUP_NAME in tab_groups:
return {}
for group_name, group_widget in tab_groups.items():
self.tabWidget.addTab(group_widget, group_name)
return tab_groups
def get_widgets(self):
if self.tab_groups:
return [
group_widget.widget(i)
for group_widget in self.tab_groups.values()
for i in range(group_widget.count())
]
return [self.tabWidget.widget(i) for i in range(self.tabWidget.count())]