Skip to content

Commit

Permalink
Fixed bug in shortcuts #298
Browse files Browse the repository at this point in the history
Numeric shortcuts now supported
Updated testing to remove drop and introduce numeric menus
  • Loading branch information
jarvisteach committed Nov 23, 2017
1 parent 9532bac commit a4d8dfa
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 11 deletions.
8 changes: 8 additions & 0 deletions appJar/appjar.py
Expand Up @@ -8304,6 +8304,7 @@ def addMenuItem(self, title, item, func=None, kind=None, shortcut=None, underlin
a = a.replace("control", "ctrl")
a = a.replace("command", "cmd")
a = a.replace("option", "opt")
a = a.replace("key-", "")

b = b.replace("ctrl", "Control")
b = b.replace("control", "Control")
Expand All @@ -8314,17 +8315,24 @@ def addMenuItem(self, title, item, func=None, kind=None, shortcut=None, underlin
b = b.replace("alt", "Alt")
b = b.replace("shift", "Shift")
b = b.replace("meta", "Meta")
b = b.replace("key", "Key")

if gui.GET_PLATFORM() != gui.MAC:
a = a.replace("cmd", "ctrl")
b = b.replace("Command", "Control")

# try to fix numerics
if b[-1] in "0123456789" and "Key" not in b:
b = b[:-1] + "Key-" + b[-1]

b = "<" + b + ">"
a = a.title()

gui.debug("Adding accelerator: %s", a)
self.widgetManager.verify(self.Widgets.Accelerators, a, array=True)
self.widgetManager.log(self.Widgets.Accelerators, a)
if u is not None and createBinding:
gui.debug("Binding: %s to %s", b, u)
self.topLevel.bind_all(b, u)

if item == "-" or kind == "separator":
Expand Down
2 changes: 2 additions & 0 deletions docs/mkdocs/docs/whatsNew.md
Expand Up @@ -8,6 +8,8 @@
* More [ttk](/pythonTtk) improvements - grouped widgets now work, introduced eternal themes.

* Issues Resolved:
* [#298](https://github.com/jarvisteach/appJar/issues/298) - fixed issue in [menubar shortcuts](/pythonBars/#extra-features/) where numeric shortcuts didn't work.
* [#296](https://github.com/jarvisteach/appJar/issues/296) - two new widgets introduced [turtle](/pythonDevWidgets/#turtle) and [canvas](/pythonDevWidgets/#canvas)
* [#294](https://github.com/jarvisteach/appJar/issues/294) & [#292](https://github.com/jarvisteach/appJar/issues/294) - fixes on [entries](/pythonWidgets/#entry): better handle arrow key presses on mac, defaults work better on secret entries & file/directory entries
* [#290](https://github.com/jarvisteach/appJar/issues/290) - fixed issue showing [AutoEntries](/pythonWidgets/#entry) in [subWindows](/pythonSubWindows)
* [#289](https://github.com/jarvisteach/appJar/issues/289) - new functions to change list in [AutoEntries](/pythonWidgets/#entry)
Expand Down
28 changes: 28 additions & 0 deletions examples/issues/issue298.py
@@ -0,0 +1,28 @@
import sys
sys.path.append("../../")

def menu(btn): print(btn)

from appJar import gui

with gui("Menu Test") as app:
app.label("title", "Menu Test")
app.createMenu("Lets")
app.addMenuItem("Lets", "One", menu, shortcut="Control-a")
app.addMenuItem("Lets", "Two", menu, shortcut="Control-Shift-a")
app.addMenuItem("Lets", "Three", menu, shortcut="Shift-Control-a")
app.addMenuItem("Lets", "Four", menu, shortcut="Alt-Shift-a")
app.addMenuItem("Lets", "Five", menu, shortcut="Shift-Alt-a")

app.createMenu("Nums")
app.addMenuItem("Nums", "1", menu, shortcut="Control-1")
app.addMenuItem("Nums", "2", menu, shortcut="Control-2")
app.addMenuItem("Nums", "3", menu, shortcut="Control-3")
app.addMenuItem("Nums", "4", menu, shortcut="Control-4")
app.addMenuItem("Nums", "5", menu, shortcut="Control-5")
app.addMenuItem("Nums", "Two", menu, shortcut="Control-Shift-1")
app.addMenuItem("Nums", "Three", menu, shortcut="Shift-Control-1")
app.addMenuItem("Nums", "Four", menu, shortcut="Alt-Shift-1")
app.addMenuItem("Nums", "Five", menu, shortcut="Shift-Alt-1")

app.addMenuItem("Punct", "!", menu, shortcut="Ctrl-!")
23 changes: 12 additions & 11 deletions tests/widget_test.py
Expand Up @@ -1673,15 +1673,15 @@ def test_menus():

app.addMenuList("a", LIST_ONE, tester_function)
app.createMenu("MEN2")
app.addMenuItem("MEN2", "MM2", tester_function, shortcut="k", underline=2)
app.addMenuItem("MEN2", "MM2", tester_function, shortcut="Control-k", underline=2)
app.addMenuSeparator("MEN2")
app.addMenuCheckBox("MEN2", "CB2", tester_function, shortcut="c", underline=2)
app.addMenuRadioButton("MEN2", "a", "BB2", tester_function, shortcut="r", underline=2)
app.addMenuCheckBox("MEN2", "CB2", tester_function, shortcut="Control-Shift-c", underline=2)
app.addMenuRadioButton("MEN2", "a", "BB2", tester_function, shortcut="Control-2", underline=2)
app.addMenuRadioButton("MEN2", "a", "BB3", tester_function)
app.addSubMenu("MEN2", "sub1")
app.addMenuItem("sub1", "MMM2", tester_function, shortcut="w", underline=2)
app.addMenuItem("sub1", "MMM2", tester_function, shortcut="Alt-w", underline=2)
app.addMenuSeparator("sub1")
app.addMenuCheckBox("sub1", "CB23", tester_function, shortcut="x", underline=2)
app.addMenuCheckBox("sub1", "CB23", tester_function, shortcut="Alt-Shift-x", underline=2)
app.addMenuRadioButton("sub1", "b", "BB23", tester_function, shortcut="y", underline=2)
app.addMenuRadioButton("sub1", "b", "BB33", tester_function, underline=0)
app.addMenu("PRESS", tester_function, "P", 4)
Expand Down Expand Up @@ -2748,22 +2748,23 @@ def changer(btn=None):
print(btn)

with gui("Simple Demo") as app4:
app4.EXTERNAL_DND = None
app4.label("title", "Simple Props Demo", colspan=3, kind="flash")
app4.label("title2", row=0, column=3, drop=changer)
app4.label("title2", row=0, column=3)
app4.setLabelBg("title", "green")

app4.radio("happy", "Very Happy", row=1, column=0)
app4.radio("happy", "Ambivalent", row=1, column=1, change=changer)
app4.radio("happy", "Miserable", row=1, column=2, selected=True)

app4.message("mess", "Simple Sadness", drop=changer, row=2, rowspan=3)
app4.message("mess", "Simple Sadness", row=2, rowspan=3)
app4.setMessageBg("mess", "pink")

app4.text("mess2", "Simple Happiness", row=2, column=2, rowspan=3, scroll=False, drop=changer)
app4.text("mess2", "Simple Happiness", row=2, column=2, rowspan=3, scroll=False)
app4.text("mess3", "Simple Happiness", row=2, column=2, rowspan=3, scroll=True, change=changer)
app4.setTextAreaBg("mess2", "pink")

app4.image("img", "1_entries.gif", over="1_flash.gif", drop=changer, row=2, column=3, rowspan=7)
app4.image("img", "1_entries.gif", over="1_flash.gif", row=2, column=3, rowspan=7)
app4.image("img5", "1_entries.gif", over="1_flash.gif", submit=changer, row=2, column=3, rowspan=7)
app4.image("img2", "1_entries.gif", over="1_flash.gif", row=2, column=3, rowspan=7, map={"A":[1,1,5,5]}, submit=changer)
app4.image("img3", "1_entries.gif", over="1_flash.gif", row=2, submit=changer, column=3, rowspan=7)
Expand All @@ -2774,7 +2775,7 @@ def changer(btn=None):
app4.check("Cheer", True, row=3, column=1)
app4.check("Cry", row=4, column=1, change=changer)

app4.entry("data", colspan=3, kind="directory", drop=changer)
app4.entry("data", colspan=3, kind="directory")
app4.entry("data2", value="lots of data", colspan=3, focus=True, case="upper", limit=15)
app4.entry("data3", colspan=3, default="france", kind="validation")
app4.entry("data4", value=["a", "aa", "aba", "abc", "abd"], colspan=3, kind="auto", rows=4)
Expand Down Expand Up @@ -2814,7 +2815,7 @@ def changer(btn=None):
app4.option("feelings2", ["happy", "bored", "angry"], kind="ticks", column=0, row=row, change=press)
app4.option("feelings3", ["happy", "bored", "angry"], column=0, row=row, change=press)
app4.spin("feelings", ["happy", "bored", "angry"], change=changer, column=1, row=row, item="angry")
app4.list("feelings", ["happy", "bored", "angry"], drop=changer, column=2, row=row, rows=4, multi=True, group=True, change=press)
app4.list("feelings", ["happy", "bored", "angry"], column=2, row=row, rows=4, multi=True, group=True, change=press)

app4.separator(colspan=3)
app4.spin("vals", 4, endValue=10, colspan=3, pos=3)
Expand Down

0 comments on commit a4d8dfa

Please sign in to comment.