forked from CSAILVision/LabelMeAnnotationTool
-
Notifications
You must be signed in to change notification settings - Fork 1
/
labelDialog.py
115 lines (97 loc) · 3.49 KB
/
labelDialog.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# -*- coding : utf-8 -*-
#
# Copyright (C) 2011 Michael Pitidis, Hussein Abdulwahid.
#
# This file is part of Labelme.
#
# Labelme is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Labelme is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Labelme. If not, see <http://www.gnu.org/licenses/>.
#
#from PyQt4.QtGui import *
#from PyQt4.QtCore import *
from PySide.QtGui import *
from PySide.QtCore import *
from lib import newIcon, labelValidator
# TODO:
# - Calculate optimal position so as not to go out of screen area.
BB = QDialogButtonBox
validWriteTypes = [u'H', u'P', u'M', u'\uff28', u'\uff30', u'\uff2d']
class LabelDialog(QDialog):
def __init__(self, text="Enter object label", parent=None):
super(LabelDialog, self).__init__(parent)
self.edit = QLineEdit()
self.edit.setText(text)
self.edit.setValidator(labelValidator())
self.edit.editingFinished.connect(self.postProcess)
self.edit.setFixedWidth(600)
layout = QVBoxLayout()
layout.addWidget(self.edit)
self.buttonBox = bb = BB(BB.Ok | BB.Cancel, Qt.Horizontal, self)
bb.button(BB.Ok).setIcon(newIcon('done'))
bb.button(BB.Cancel).setIcon(newIcon('undo'))
bb.accepted.connect(self.validate)
bb.rejected.connect(self.reject)
layout.addWidget(bb)
self.writeTypes = QGroupBox(self)
#self.writeTypes.setExclusive(True)
self.hwr = QRadioButton("&Handwritten")
self.prn = QRadioButton("&Printed")
self.mix = QRadioButton("&Mixed")
#self.writeTypes.addButton(hwr)
#self.writeTypes.addButton(prn)
#self.writeTypes.addButton(mix)
#layout.addWidget(self.writeTypes)
layout.addWidget(self.hwr)
layout.addWidget(self.prn)
layout.addWidget(self.mix)
#vbox.addStretch(100)
#self.writeTypes.setLayout(vbox)
self.setLayout(layout)
def validate(self):
wt = None
if self.hwr.isChecked():
wt = u'H'
if self.prn.isChecked():
wt = u'P'
if self.mix.isChecked():
wt = u'M'
txt = self.edit.text().strip()
if wt and txt:
self.edit.setText(wt + txt)
self.accept()
def cleanWT(self):
if self.mix.isChecked(): self.mix.toggle()
if self.prn.isChecked(): self.prn.toggle()
if self.hwr.isChecked(): self.hwr.toggle()
self.writeTypes.setChecked(False)
self.mix.setChecked(False)
def postProcess(self):
#txt =
#wt = None
##while not wt:
#if self.hwr.isChecked():
#wt = u'H'
#if self.prn.isChecked():
#wt = u'P'
#if self.mix.isChecked():
#wt = u'M'
#if wt : txt = wt + txt
self.edit.setText(self.edit.text().strip())
def popUp(self, text='', move=True):
if len(text) > 1: text = text[1:]
self.edit.setText(text)
self.edit.setSelection(0, len(text))
self.edit.setFocus(Qt.PopupFocusReason)
if move:
self.move(QCursor.pos())
return self.edit.text() if self.exec_() else None