-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui_mapinfotable.py
More file actions
96 lines (75 loc) · 3.02 KB
/
gui_mapinfotable.py
File metadata and controls
96 lines (75 loc) · 3.02 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import sys
from PyQt5.QtWidgets import QApplication, QAbstractItemView, QHBoxLayout, QTableWidget, QTableWidgetItem, QHeaderView
from PyQt5.QtCore import Qt
import re
import webbrowser
STRING_MAPINFO_KEY = ["실제 주소",
"다음 맵",
"다음 로드뷰",
"네이버 맵"]
def is_link(string):
url_pattern = re.compile(
r'^(?:http|ftp)s?://' # http:// or https:// or ftp://
# domain...
r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|'
r'localhost|' # localhost...
r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ipv4
r'(?::\d+)?' # optional port
r'(?:/?|[/?]\S+)$', re.IGNORECASE)
return re.match(url_pattern, string) is not None
class MapInfoTable(QTableWidget):
def __init__(self):
super().__init__()
self.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
self.horizontalHeader().setHidden(True)
self.verticalHeader().setHidden(True)
self.setEditTriggers(QTableWidget.NoEditTriggers)
self.setSelectionMode(QAbstractItemView.SingleSelection)
hbox = QHBoxLayout()
self.setLayout(hbox)
self.itemDoubleClicked.connect(self.try_open_link)
self.clear_table()
def clear_table(self):
self.set_mapinfo(["", "", "", ""], [])
def set_mapinfo(self, datalist, epsg):
self.epsg = epsg
self.datalist = datalist
self._update_table(datalist)
def _update_table(self, datalist):
self.clear()
self.setRowCount(5)
self.setColumnCount(3)
for index, data in enumerate(datalist):
if index == 0:
self.setItem(
int(0), 0, QTableWidgetItem(str(STRING_MAPINFO_KEY[index])))
self.setItem(
int(1), 0, QTableWidgetItem(str(data)))
self.setSpan(0, 0, 1, 3)
self.setSpan(1, 0, 1, 3)
else:
row = int(index + 1)
self.setItem(
row, 0, QTableWidgetItem(str(STRING_MAPINFO_KEY[index])))
self.setItem(
row, 1, QTableWidgetItem(str(data)))
self.setItem(
row, 2, QTableWidgetItem())
self.setSpan(row, 1, 1, 2)
noeditable_list = [self.item(2, 1), self.item(3, 1), self.item(4, 1)]
for target in noeditable_list:
target.setFlags(target.flags() & ~Qt.ItemIsEditable)
def try_open_link(self, item):
content = item.data(Qt.DisplayRole)
if content and is_link(content):
webbrowser.open(content)
if __name__ == '__main__':
app = QApplication(sys.argv)
from network import get_mapinfo_from_pnu
apikey = "A65F7069-061D-378F-B2D1-5E635A17BA43"
pnu = "4377034032102800000"
l, b = get_mapinfo_from_pnu(apikey, pnu)
table_widget = MapInfoTable()
table_widget.set_mapinfo(l, b)
table_widget.show()
sys.exit(app.exec_())