tagger with number of expected tags. renumbering of hotkeys

This commit is contained in:
q
2015-05-14 07:43:03 +03:00
parent afe6861bdf
commit 2b30f5085a
2 changed files with 16 additions and 9 deletions

View File

@@ -265,7 +265,7 @@ def print_tag(options):
hash=file2hash(conn.cursor(), os.path.realpath(options.tag)) hash=file2hash(conn.cursor(), os.path.realpath(options.tag))
if hash==None: if hash==None:
print("Image not found "+os.path.realpath(options.tag)) print("Image not found "+os.path.realpath(options.tag))
return sys.exit(1)
db=conn.cursor() db=conn.cursor()
db.execute("SELECT DISTINCT tag FROM tags WHERE hash = ?",(hash,)) db.execute("SELECT DISTINCT tag FROM tags WHERE hash = ?",(hash,))
print( ",".join( row[0] for row in db )) print( ",".join( row[0] for row in db ))

View File

@@ -14,6 +14,8 @@ def setup_options():
help="SQL file name to use [%(default)s]") help="SQL file name to use [%(default)s]")
parser.add_argument("-t",action="store",dest="tags",default="thisIsGood,thisIsBad", parser.add_argument("-t",action="store",dest="tags",default="thisIsGood,thisIsBad",
help="Comma separated list of tags") help="Comma separated list of tags")
parser.add_argument("-n",action="store",type=int,dest="number",default=0,
help="Number of tags expected. 0 is any amount.")
parser.add_argument('path', action="store",default='.', nargs='?') parser.add_argument('path', action="store",default='.', nargs='?')
options=parser.parse_args() options=parser.parse_args()
@@ -22,7 +24,7 @@ def setup_options():
class Click: class Click:
def __init__(self, image,tags,sqlfile): def __init__(self, image,tags,sqlfile,number):
self.title="Tagger: "+os.path.basename(image) self.title="Tagger: "+os.path.basename(image)
self.root=Tk() self.root=Tk()
@@ -30,6 +32,8 @@ class Click:
self.root.bind("<Escape>", self._quit) self.root.bind("<Escape>", self._quit)
self.root.title(self.title) self.root.title(self.title)
self.numberLimit=number
self.numberCurrent=1
self.image = Image.open(image) self.image = Image.open(image)
self.image_name = image self.image_name = image
self.img_copy= self.image.copy() self.img_copy= self.image.copy()
@@ -47,14 +51,14 @@ class Click:
self.tags.append(Button(self.top,text="[n] Next", command=self._tag_button("n"))) self.tags.append(Button(self.top,text="[n] Next", command=self._tag_button("n")))
self.root.bind("n", self._tag_key) 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+1)
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+1,self.tagTexts[t]), command=return_func))
self.root.bind(str(t), self._tag_key) self.root.bind(str(t+1), 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)+1): for t in range(len(self.tags)):
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))
@@ -135,7 +139,7 @@ class Click:
if value=="": if value=="":
return return
else: else:
value=self.tagTexts[x] value=self.tagTexts[x-1]
self.db[0].execute("SELECT hash FROM list WHERE file = ?",( os.path.realpath( self.image_name), )) self.db[0].execute("SELECT hash FROM list WHERE file = ?",( os.path.realpath( self.image_name), ))
hashes=self.db[0].fetchall() hashes=self.db[0].fetchall()
if len(hashes)==0: if len(hashes)==0:
@@ -145,6 +149,9 @@ class Click:
self.db[0].execute("INSERT INTO tags (hash,tag) VALUES (?,?)",( hashes[0][0],value )) self.db[0].execute("INSERT INTO tags (hash,tag) VALUES (?,?)",( hashes[0][0],value ))
self.db[1].commit() self.db[1].commit()
print("Added %s:%s"%(self.image_name,value)) print("Added %s:%s"%(self.image_name,value))
self.numberCurrent+=1
if self.numberLimit>0 and self.numberLimit<self.numberCurrent:
self._next(0)
return return
def _print_tags(self): def _print_tags(self):
@@ -179,6 +186,6 @@ else:
imagelist=sorted([os.path.join(opt.path,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): for i,l in enumerate(imagelist):
print("%s %d"%( l, len(imagelist)-i)) sys.stdout.write("%s %d "%( l, len(imagelist)-i))
clicker = Click(l,opt.tags,opt.sqlfile) clicker = Click(l,opt.tags,opt.sqlfile,opt.number)
#print(clicker.get_tags()) #print(clicker.get_tags())