tagger with number of expected tags. renumbering of hotkeys
This commit is contained in:
@@ -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 ))
|
||||
|
||||
@@ -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("<Escape>", 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<self.numberCurrent:
|
||||
self._next(0)
|
||||
return
|
||||
|
||||
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)])
|
||||
|
||||
for i,l in enumerate(imagelist):
|
||||
print("%s %d"%( l, len(imagelist)-i))
|
||||
clicker = Click(l,opt.tags,opt.sqlfile)
|
||||
sys.stdout.write("%s %d "%( l, len(imagelist)-i))
|
||||
clicker = Click(l,opt.tags,opt.sqlfile,opt.number)
|
||||
#print(clicker.get_tags())
|
||||
|
||||
Reference in New Issue
Block a user