From 2b30f5085a17701a916c2434e911905a9adce0a2 Mon Sep 17 00:00:00 2001 From: q Date: Thu, 14 May 2015 07:43:03 +0300 Subject: [PATCH] tagger with number of expected tags. renumbering of hotkeys --- image_list.py | 2 +- image_list_tagger.py | 23 +++++++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/image_list.py b/image_list.py index 1ac6c2c..18654c1 100755 --- a/image_list.py +++ b/image_list.py @@ -265,7 +265,7 @@ def print_tag(options): hash=file2hash(conn.cursor(), os.path.realpath(options.tag)) if hash==None: print("Image not found "+os.path.realpath(options.tag)) - return + sys.exit(1) db=conn.cursor() db.execute("SELECT DISTINCT tag FROM tags WHERE hash = ?",(hash,)) print( ",".join( row[0] for row in db )) diff --git a/image_list_tagger.py b/image_list_tagger.py index a9a7529..b9aa239 100755 --- a/image_list_tagger.py +++ b/image_list_tagger.py @@ -14,6 +14,8 @@ def setup_options(): help="SQL file name to use [%(default)s]") parser.add_argument("-t",action="store",dest="tags",default="thisIsGood,thisIsBad", 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='?') options=parser.parse_args() @@ -22,7 +24,7 @@ def setup_options(): class Click: - def __init__(self, image,tags,sqlfile): + def __init__(self, image,tags,sqlfile,number): self.title="Tagger: "+os.path.basename(image) self.root=Tk() @@ -30,6 +32,8 @@ class Click: self.root.bind("", self._quit) self.root.title(self.title) + self.numberLimit=number + self.numberCurrent=1 self.image = Image.open(image) self.image_name = image 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.root.bind("n", self._tag_key) for t in range(len(self.tagTexts)): - return_func=self._tag_button(t) + return_func=self._tag_button(t+1) 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.tags.append(Button(self.top,text="[%d] %s"%(t+1,self.tagTexts[t]), command=return_func)) + self.root.bind(str(t+1), 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)+1): + for t in range(len(self.tags)): self.tags[t].pack(fill="both", side="top") # custom tag self.tags.append(Entry(self.top)) @@ -135,7 +139,7 @@ class Click: if value=="": return 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), )) hashes=self.db[0].fetchall() 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[1].commit() print("Added %s:%s"%(self.image_name,value)) + self.numberCurrent+=1 + if self.numberLimit>0 and self.numberLimit