tagger remembers custom choices

This commit is contained in:
ville rantanen
2015-02-18 08:57:42 +02:00
parent 20b0fc41e8
commit fbb7aa7d62

View File

@@ -42,29 +42,27 @@ class Click:
self.top=Toplevel(self.root) self.top=Toplevel(self.root)
self.top.bind("<Escape>", self._quit) self.top.bind("<Escape>", self._quit)
self.tagTexts=['Next']+tags self.tagTexts=tags
self.tags=[] self.tags=[]
self.tags.append(Button(self.top,text="[n] Next", command=self._tag_button("n")))
self.root.bind("n", self._tag_key)
for t in range(len(self.tagTexts)): for t in range(len(self.tagTexts)):
return_func=self._tag_button(t) return_func=self._tag_button(t)
if t==0:
self.tags.append(Button(self.top,text="[n] "+self.tagTexts[t], command=return_func))
self.root.bind("n", self._tag_key)
#self.top.bind("n", self._tag_key)
continue
if t<10: if t<10:
self.tags.append(Button(self.top,text="[%d] %s"%(t,self.tagTexts[t]), command=return_func)) self.tags.append(Button(self.top,text="[%d] %s"%(t,self.tagTexts[t]), command=return_func))
self.root.bind(str(t), self._tag_key) self.root.bind(str(t), self._tag_key)
#self.top.bind(str(t), self._tag_key) #self.top.bind(str(t), self._tag_key)
continue continue
self.tags.append(Button(self.top,text=self.tagTexts[t], command=return_func)) self.tags.append(Button(self.top,text=self.tagTexts[t], command=return_func))
for t in range(len(self.tagTexts)): for t in range(len(self.tagTexts)+1):
self.tags[t].pack(fill="both", side="top") self.tags[t].pack(fill="both", side="top")
# custom tag # custom tag
self.tags.append(Entry(self.top)) self.tags.append(Entry(self.top))
self.tags[t+1].pack(fill="both", side="top") self.tags[t+1].pack(fill="both", side="top")
self.tags[t+1].bind("<Return>", self._tag_key)
self.tags.append(Button(self.top, text="Custom", command=self._tag_button("custom"))) self.tags.append(Button(self.top, text="Custom", command=self._tag_button("custom")))
self.tags[t+2].pack(fill="both", side="top") self.tags[t+2].pack(fill="both", side="top")
self.tags[t+1].bind("<Return>", self._tag_key)
self.top.geometry("220x%d+0+0"%(self.root.winfo_screenheight()-150,)) self.top.geometry("220x%d+0+0"%(self.root.winfo_screenheight()-150,))
self._resize_init() self._resize_init()
@@ -76,7 +74,8 @@ class Click:
def _tag_key(self,event): def _tag_key(self,event):
if event.keysym=="n": if event.keysym=="n":
event.keysym=0 self._tag_button("n")()
return
if event.keysym=="Return": if event.keysym=="Return":
self._tag_button("custom")() self._tag_button("custom")()
return return
@@ -85,7 +84,7 @@ class Click:
def _tag_button(self,n): def _tag_button(self,n):
def actual_value(x=n): def actual_value(x=n):
if x==0: if x=="n":
self._next(n) self._next(n)
return return
self._add_tag(x) self._add_tag(x)
@@ -126,11 +125,13 @@ class Click:
sys.exit(0) sys.exit(0)
def _next(self,event): def _next(self,event):
self.root.destroy() self.root.destroy()
def _add_tag(self,x): def _add_tag(self,x):
if x=="custom": if x=="custom":
value=self.tags[ len(self.tags)-2 ].get().strip() value=self.tags[ len(self.tags)-2 ].get().strip()
if value not in self.tagTexts:
self.tagTexts.append(value)
if value=="": if value=="":
return return
else: else:
@@ -166,6 +167,9 @@ class Click:
conn.text_factory=str conn.text_factory=str
db=conn.cursor() db=conn.cursor()
self.db=[db,conn] self.db=[db,conn]
def get_tags(self):
return self.tagTexts
opt=setup_options() opt=setup_options()
@@ -177,4 +181,4 @@ else:
for i,l in enumerate(imagelist): for i,l in enumerate(imagelist):
print("%s %d"%( l, len(imagelist)-i)) print("%s %d"%( l, len(imagelist)-i))
clicker = Click(l,opt.tags,opt.sqlfile) clicker = Click(l,opt.tags,opt.sqlfile)
#print(clicker.get_tags())