Skip to content

Commit

Permalink
GUI: Update messages, add Tab shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
duangsuse committed May 3, 2019
1 parent 9cccab6 commit 79776fd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
10 changes: 6 additions & 4 deletions VisualGimp/Gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from VisualGimp import __name__ as VISUAL_GIMP

from Util import identitystar, compose, uh, concat_stream, stream_join, infseq
from Util import identitystar, compose, uh, concat_stream, stream_join, infseq, doall, may_slice
from HBoxie import DictFrame

class Gui (Thread):
Expand Down Expand Up @@ -71,7 +71,8 @@ def bind(self):
self.cp_tvar.set(self.CODE_PTR_MESG %self.lastArrowSet)
self.export_code = Entry(self.ui)
self.convert_trace_code = Entry(self.ui)
self.btn_update_codes = Button(self.ui, text = "Compile", command = self.updateConverter, justify=CENTER)
# 我的意思是,如果用户输入 lambda,不就直接是 Compile 了吗? 🤗
self.btn_update_codes = Button(self.ui, text = "📓 Compile", command = self.updateConverter, justify=CENTER)
self.export = Button(self.ui, text = "✔ Export Frame", command = self.do_export)
self.message = StringVar()
self.message_view = Label(self.ui, textvariable=self.message, justify=CENTER, fg="green")
Expand Down Expand Up @@ -146,6 +147,7 @@ def bind_ign(sig, fn):
bind_ign('<Right>', self.refreshFrame)
bind_ign('<Up>', self.crDec)
bind_ign('<Down>', self.crInc)
self.ui.bind('<Tab>', do_ign2(doall(self.updateClicked, self.refreshFrame)))

bind_ign('<Return>', self.do_export)

Expand Down Expand Up @@ -174,7 +176,7 @@ def listener(index, key, oldvalue, newvalue):
try:
evaluated = compose(str, eval)(newvalue)
except Exception as e:
evaluated = str(e)
evaluated = may_slice(str(e), slice(0, 15))
newdict[key] = evaluated
self.message.set('records[{}] = {} evaluated to {}'.format(key, newvalue, evaluated))
field = self.dict_view.ivs[index].b
Expand Down Expand Up @@ -231,7 +233,7 @@ def refreshFrame(self):
self.ds.layer_hide(layer.children[self.trace_ptr_lastshown[key]])

if not self.ds.layer_is_group(layer) or len(layer.children) <= ptr:
self.ds.message('Failed to change cursor for {}: Not a group or length </= index {} '.format(key, ptr))
self.ds.message('Failed to change cursor for {}({}): Not a group or length </= index {} '.format(key, t2n[key], ptr))
self.ds.layer_show(layer.children[ptr])
msg += 'Showing cursor {} @ position {}'.format(layer.name, ptr) + '\n'
self.trace_ptr_lastshown[key] = ptr
Expand Down
23 changes: 23 additions & 0 deletions VisualGimp/Util.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,29 @@ def nseq(x, n):
yield x
n -= 1

def may_slice(ary, ind):
''' if slice in array bound, return array[slice], else return retrofit slice '''
if type(ind) is not slice: return
if type(ary) is not list: return
# start stop /step
start = ind.start
stop = ind.stop
len_list = len(ary)
if start < 0:
# negative: list[-1] = list[len(list) - 1]
if start <= -len_list:
return ary[0:stop]
else:
startovf = start >= len_list
endovf = stop >= len_list
if startovf or endovf:
if startovf and endovf:
return []
elif startovf:
return ary[startovf-len_list:stop]
elif endovf:
return ary[start:-1]

#from multiprocessing.pool import Pool

def ap(f, *args, **kwargs):
Expand Down

0 comments on commit 79776fd

Please sign in to comment.