From a9a4625d9a31bc9694a698cf41e4fa7396d52389 Mon Sep 17 00:00:00 2001 From: q Date: Thu, 14 May 2015 08:56:28 +0300 Subject: [PATCH] a-m keys as hotkeys --- image_list_tagger.py | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/image_list_tagger.py b/image_list_tagger.py index b9aa239..6ab923e 100755 --- a/image_list_tagger.py +++ b/image_list_tagger.py @@ -24,9 +24,9 @@ def setup_options(): 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.geometry("1024x768+220+0") self.root.bind("", self._quit) @@ -48,13 +48,13 @@ class Click: self.top.bind("", self._quit) self.tagTexts=tags self.tags=[] - self.tags.append(Button(self.top,text="[n] Next", command=self._tag_button("n"))) - self.root.bind("n", self._tag_key) + self.tags.append(Button(self.top,text="[z] Next", command=self._tag_button("z"))) + self.root.bind("z", self._tag_key) for t in range(len(self.tagTexts)): return_func=self._tag_button(t+1) - if t<10: - 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) + if t<34: + self.tags.append(Button(self.top,text="[%s] %s"%(self._hotkey(t+1),self.tagTexts[t]), command=return_func)) + self.root.bind(self._hotkey(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)) @@ -77,18 +77,18 @@ class Click: self.root.mainloop() def _tag_key(self,event): - if event.keysym=="n": - self._tag_button("n")() + if event.keysym=="z": + self._tag_button("z")() return if event.keysym=="Return": self._tag_button("custom")() return - thisfunc=self._tag_button(int(event.keysym)) + thisfunc=self._tag_button(self._yektoh(event.keysym)) thisfunc() def _tag_button(self,n): def actual_value(x=n): - if x=="n": + if x=="z": self._next(n) return self._add_tag(x) @@ -178,6 +178,21 @@ class Click: def get_tags(self): 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() 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)]) for i,l in enumerate(imagelist): - sys.stdout.write("%s %d "%( l, len(imagelist)-i)) - clicker = Click(l,opt.tags,opt.sqlfile,opt.number) + (p,b)=os.path.split( os.path.abspath(l) ) + (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())