tagger custom value

This commit is contained in:
q
2015-02-15 21:13:11 +02:00
parent d1c9d120bb
commit 20b0fc41e8

View File

@@ -49,16 +49,22 @@ class Click:
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)
#self.top.bind("n", self._tag_key)
continue
if t<10:
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.top.bind(str(t), self._tag_key)
#self.top.bind(str(t), self._tag_key)
continue
self.tags.append(Button(self.top,text=self.tagTexts[t], command=return_func))
for t in range(len(self.tagTexts)):
self.tags[t].pack(fill="both", side="top")
# custom tag
self.tags.append(Entry(self.top))
self.tags[t+1].pack(fill="both", side="top")
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+1].bind("<Return>", self._tag_key)
self.top.geometry("220x%d+0+0"%(self.root.winfo_screenheight()-150,))
self._resize_init()
@@ -71,6 +77,9 @@ class Click:
def _tag_key(self,event):
if event.keysym=="n":
event.keysym=0
if event.keysym=="Return":
self._tag_button("custom")()
return
thisfunc=self._tag_button(int(event.keysym))
thisfunc()
@@ -120,15 +129,21 @@ class Click:
self.root.destroy()
def _add_tag(self,x):
if x=="custom":
value=self.tags[ len(self.tags)-2 ].get().strip()
if value=="":
return
else:
value=self.tagTexts[x]
self.db[0].execute("SELECT hash FROM list WHERE file = ?",( os.path.realpath( self.image_name), ))
hashes=self.db[0].fetchall()
if len(hashes)==0:
print("Image %s not in database!" % (self.image_name) )
self._next(None)
return
self.db[0].execute("INSERT INTO tags (hash,tag) VALUES (?,?)",( hashes[0][0], self.tagTexts[x] ))
self.db[0].execute("INSERT INTO tags (hash,tag) VALUES (?,?)",( hashes[0][0],value ))
self.db[1].commit()
print("Added %s:%s"%(self.image_name,self.tagTexts[x]))
print("Added %s:%s"%(self.image_name,value))
return
def _print_tags(self):
@@ -157,7 +172,7 @@ opt=setup_options()
if os.path.isfile(opt.path):
imagelist=[opt.path]
else:
imagelist=sorted([f for f in os.listdir(opt.path) if IMGMATCH.match(f)])
imagelist=sorted([os.path.join(opt.path,f) for f in os.listdir(opt.path) if IMGMATCH.match(f)])
for i,l in enumerate(imagelist):
print("%s %d"%( l, len(imagelist)-i))