a-m keys as hotkeys
This commit is contained in:
@@ -24,9 +24,9 @@ def setup_options():
|
|||||||
|
|
||||||
|
|
||||||
class Click:
|
class Click:
|
||||||
def __init__(self, image,tags,sqlfile,number):
|
def __init__(self, image,tags,sqlfile,title,number):
|
||||||
|
|
||||||
self.title="Tagger: "+os.path.basename(image)
|
self.title=title
|
||||||
self.root=Tk()
|
self.root=Tk()
|
||||||
self.root.geometry("1024x768+220+0")
|
self.root.geometry("1024x768+220+0")
|
||||||
self.root.bind("<Escape>", self._quit)
|
self.root.bind("<Escape>", self._quit)
|
||||||
@@ -48,13 +48,13 @@ class Click:
|
|||||||
self.top.bind("<Escape>", self._quit)
|
self.top.bind("<Escape>", self._quit)
|
||||||
self.tagTexts=tags
|
self.tagTexts=tags
|
||||||
self.tags=[]
|
self.tags=[]
|
||||||
self.tags.append(Button(self.top,text="[n] Next", command=self._tag_button("n")))
|
self.tags.append(Button(self.top,text="[z] Next", command=self._tag_button("z")))
|
||||||
self.root.bind("n", self._tag_key)
|
self.root.bind("z", self._tag_key)
|
||||||
for t in range(len(self.tagTexts)):
|
for t in range(len(self.tagTexts)):
|
||||||
return_func=self._tag_button(t+1)
|
return_func=self._tag_button(t+1)
|
||||||
if t<10:
|
if t<34:
|
||||||
self.tags.append(Button(self.top,text="[%d] %s"%(t+1,self.tagTexts[t]), command=return_func))
|
self.tags.append(Button(self.top,text="[%s] %s"%(self._hotkey(t+1),self.tagTexts[t]), command=return_func))
|
||||||
self.root.bind(str(t+1), self._tag_key)
|
self.root.bind(self._hotkey(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))
|
||||||
@@ -77,18 +77,18 @@ class Click:
|
|||||||
self.root.mainloop()
|
self.root.mainloop()
|
||||||
|
|
||||||
def _tag_key(self,event):
|
def _tag_key(self,event):
|
||||||
if event.keysym=="n":
|
if event.keysym=="z":
|
||||||
self._tag_button("n")()
|
self._tag_button("z")()
|
||||||
return
|
return
|
||||||
if event.keysym=="Return":
|
if event.keysym=="Return":
|
||||||
self._tag_button("custom")()
|
self._tag_button("custom")()
|
||||||
return
|
return
|
||||||
thisfunc=self._tag_button(int(event.keysym))
|
thisfunc=self._tag_button(self._yektoh(event.keysym))
|
||||||
thisfunc()
|
thisfunc()
|
||||||
|
|
||||||
def _tag_button(self,n):
|
def _tag_button(self,n):
|
||||||
def actual_value(x=n):
|
def actual_value(x=n):
|
||||||
if x=="n":
|
if x=="z":
|
||||||
self._next(n)
|
self._next(n)
|
||||||
return
|
return
|
||||||
self._add_tag(x)
|
self._add_tag(x)
|
||||||
@@ -178,6 +178,21 @@ class Click:
|
|||||||
def get_tags(self):
|
def get_tags(self):
|
||||||
return self.tagTexts
|
return self.tagTexts
|
||||||
|
|
||||||
|
def _hotkey(self,i):
|
||||||
|
# return string number for 1-9
|
||||||
|
# a-l if i>9
|
||||||
|
if i<10:
|
||||||
|
return str(i)
|
||||||
|
a=i+87
|
||||||
|
if a<122:
|
||||||
|
return chr(a)
|
||||||
|
return
|
||||||
|
def _yektoh(self,a):
|
||||||
|
# return integer, reverse function of _hotkey
|
||||||
|
i=ord(a)-87
|
||||||
|
if i<0:
|
||||||
|
return int(a)
|
||||||
|
return i
|
||||||
|
|
||||||
opt=setup_options()
|
opt=setup_options()
|
||||||
if os.path.isfile(opt.path):
|
if os.path.isfile(opt.path):
|
||||||
@@ -186,6 +201,8 @@ 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):
|
||||||
sys.stdout.write("%s %d "%( l, len(imagelist)-i))
|
(p,b)=os.path.split( os.path.abspath(l) )
|
||||||
clicker = Click(l,opt.tags,opt.sqlfile,opt.number)
|
(f,p)=os.path.split( p )
|
||||||
|
sys.stdout.write("%s/%s %d/%d "%( p,b, i+1,len(imagelist)))
|
||||||
|
clicker = Click(l,opt.tags,opt.sqlfile,"Tagger: %s/%s %d/%d "%( p,b, i+1,len(imagelist)),opt.number)
|
||||||
#print(clicker.get_tags())
|
#print(clicker.get_tags())
|
||||||
|
|||||||
Reference in New Issue
Block a user