mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
Start extracting ui.tktile.menubar.
In the process made tkconst common to ui.tktile as well. ui.tktile will be a common namespace for code common to the tk and tile UIs.
This commit is contained in:
parent
69e1dd75bc
commit
4d6dac1316
8 changed files with 156 additions and 302 deletions
|
@ -54,111 +54,7 @@ from solverdialog import connect_game_solver_dialog
|
||||||
|
|
||||||
from tkconst import TOOLBAR_BUTTONS
|
from tkconst import TOOLBAR_BUTTONS
|
||||||
|
|
||||||
|
from pysollib.ui.tktile.menubar import createToolbarMenu, MfxMenubar, MfxMenu
|
||||||
# ************************************************************************
|
|
||||||
# *
|
|
||||||
# ************************************************************************
|
|
||||||
|
|
||||||
def createToolbarMenu(menubar, menu):
|
|
||||||
tearoff = menu.cget('tearoff')
|
|
||||||
## data_dir = os.path.join(menubar.app.dataloader.dir, 'images', 'toolbar')
|
|
||||||
## submenu = MfxMenu(menu, label=n_('Style'), tearoff=tearoff)
|
|
||||||
## for f in os.listdir(data_dir):
|
|
||||||
## d = os.path.join(data_dir, f)
|
|
||||||
## if os.path.isdir(d) and os.path.exists(os.path.join(d, 'small')):
|
|
||||||
## name = f.replace('_', ' ').capitalize()
|
|
||||||
## submenu.add_radiobutton(label=name,
|
|
||||||
## variable=menubar.tkopt.toolbar_style,
|
|
||||||
## value=f, command=menubar.mOptToolbarStyle)
|
|
||||||
submenu = MfxMenu(menu, label=n_('Compound'), tearoff=tearoff)
|
|
||||||
for comp, label in COMPOUNDS:
|
|
||||||
submenu.add_radiobutton(
|
|
||||||
label=label, variable=menubar.tkopt.toolbar_compound,
|
|
||||||
value=comp, command=menubar.mOptToolbarCompound)
|
|
||||||
menu.add_separator()
|
|
||||||
menu.add_radiobutton(label=n_("Hide"),
|
|
||||||
variable=menubar.tkopt.toolbar, value=0,
|
|
||||||
command=menubar.mOptToolbar)
|
|
||||||
menu.add_radiobutton(label=n_("Top"),
|
|
||||||
variable=menubar.tkopt.toolbar, value=1,
|
|
||||||
command=menubar.mOptToolbar)
|
|
||||||
menu.add_radiobutton(label=n_("Bottom"),
|
|
||||||
variable=menubar.tkopt.toolbar, value=2,
|
|
||||||
command=menubar.mOptToolbar)
|
|
||||||
menu.add_radiobutton(label=n_("Left"),
|
|
||||||
variable=menubar.tkopt.toolbar, value=3,
|
|
||||||
command=menubar.mOptToolbar)
|
|
||||||
menu.add_radiobutton(label=n_("Right"),
|
|
||||||
variable=menubar.tkopt.toolbar, value=4,
|
|
||||||
command=menubar.mOptToolbar)
|
|
||||||
## menu.add_separator()
|
|
||||||
## menu.add_radiobutton(label=n_("Small icons"),
|
|
||||||
## variable=menubar.tkopt.toolbar_size, value=0,
|
|
||||||
## command=menubar.mOptToolbarSize)
|
|
||||||
## menu.add_radiobutton(label=n_("Large icons"),
|
|
||||||
## variable=menubar.tkopt.toolbar_size, value=1,
|
|
||||||
## command=menubar.mOptToolbarSize)
|
|
||||||
menu.add_separator()
|
|
||||||
submenu = MfxMenu(menu, label=n_('Visible buttons'), tearoff=tearoff)
|
|
||||||
for w in TOOLBAR_BUTTONS:
|
|
||||||
submenu.add_checkbutton(label=_(w.capitalize()),
|
|
||||||
variable=menubar.tkopt.toolbar_vars[w],
|
|
||||||
command=lambda m=menubar, w=w: m.mOptToolbarConfig(w))
|
|
||||||
|
|
||||||
|
|
||||||
# ************************************************************************
|
|
||||||
# *
|
|
||||||
# ************************************************************************
|
|
||||||
|
|
||||||
class MfxMenubar(Tkinter.Menu):
|
|
||||||
addPath = None
|
|
||||||
|
|
||||||
def __init__(self, master, **kw):
|
|
||||||
self.name = kw["name"]
|
|
||||||
tearoff = 0
|
|
||||||
self.n = kw["tearoff"] = int(kw.get("tearoff", tearoff))
|
|
||||||
Tkinter.Menu.__init__(self, master, **kw)
|
|
||||||
|
|
||||||
def labeltoname(self, label):
|
|
||||||
#print label, type(label)
|
|
||||||
name = re.sub(r"[^0-9a-zA-Z]", "", label).lower()
|
|
||||||
label = _(label)
|
|
||||||
underline = label.find('&')
|
|
||||||
if underline >= 0:
|
|
||||||
label = label.replace('&', '')
|
|
||||||
return name, label, underline
|
|
||||||
|
|
||||||
def add(self, itemType, cnf={}):
|
|
||||||
label = cnf.get("label")
|
|
||||||
if label:
|
|
||||||
name = cnf.get('name')
|
|
||||||
if name:
|
|
||||||
del cnf['name'] # TclError: unknown option "-name"
|
|
||||||
else:
|
|
||||||
name, label, underline = self.labeltoname(label)
|
|
||||||
cnf["underline"] = cnf.get("underline", underline)
|
|
||||||
cnf["label"] = label
|
|
||||||
if name and self.addPath:
|
|
||||||
path = str(self._w) + "." + name
|
|
||||||
self.addPath(path, self, self.n, cnf.get("menu"))
|
|
||||||
Tkinter.Menu.add(self, itemType, cnf)
|
|
||||||
self.n = self.n + 1
|
|
||||||
|
|
||||||
|
|
||||||
class MfxMenu(MfxMenubar):
|
|
||||||
def __init__(self, master, label, underline=None, **kw):
|
|
||||||
if 'name' in kw:
|
|
||||||
name, label_underline = kw['name'], -1
|
|
||||||
else:
|
|
||||||
name, label, label_underline = self.labeltoname(label)
|
|
||||||
kwdefault(kw, name=name)
|
|
||||||
MfxMenubar.__init__(self, master, **kw)
|
|
||||||
if underline is None:
|
|
||||||
underline = label_underline
|
|
||||||
if master:
|
|
||||||
master.add_cascade(menu=self, name=name, label=label, underline=underline)
|
|
||||||
|
|
||||||
|
|
||||||
# ************************************************************************
|
# ************************************************************************
|
||||||
# * - create menubar
|
# * - create menubar
|
||||||
# * - update menubar
|
# * - update menubar
|
||||||
|
|
|
@ -54,111 +54,7 @@ from solverdialog import connect_game_solver_dialog
|
||||||
|
|
||||||
from tkconst import TOOLBAR_BUTTONS
|
from tkconst import TOOLBAR_BUTTONS
|
||||||
|
|
||||||
|
from pysollib.ui.tktile.menubar import createToolbarMenu, MfxMenubar, MfxMenu
|
||||||
# ************************************************************************
|
|
||||||
# *
|
|
||||||
# ************************************************************************
|
|
||||||
|
|
||||||
def createToolbarMenu(menubar, menu):
|
|
||||||
tearoff = menu.cget('tearoff')
|
|
||||||
## data_dir = os.path.join(menubar.app.dataloader.dir, 'images', 'toolbar')
|
|
||||||
## submenu = MfxMenu(menu, label=n_('Style'), tearoff=tearoff)
|
|
||||||
## for f in os.listdir(data_dir):
|
|
||||||
## d = os.path.join(data_dir, f)
|
|
||||||
## if os.path.isdir(d) and os.path.exists(os.path.join(d, 'small')):
|
|
||||||
## name = f.replace('_', ' ').capitalize()
|
|
||||||
## submenu.add_radiobutton(label=name,
|
|
||||||
## variable=menubar.tkopt.toolbar_style,
|
|
||||||
## value=f, command=menubar.mOptToolbarStyle)
|
|
||||||
submenu = MfxMenu(menu, label=n_('Compound'), tearoff=tearoff)
|
|
||||||
for comp, label in COMPOUNDS:
|
|
||||||
submenu.add_radiobutton(
|
|
||||||
label=label, variable=menubar.tkopt.toolbar_compound,
|
|
||||||
value=comp, command=menubar.mOptToolbarCompound)
|
|
||||||
menu.add_separator()
|
|
||||||
menu.add_radiobutton(label=n_("Hide"),
|
|
||||||
variable=menubar.tkopt.toolbar, value=0,
|
|
||||||
command=menubar.mOptToolbar)
|
|
||||||
menu.add_radiobutton(label=n_("Top"),
|
|
||||||
variable=menubar.tkopt.toolbar, value=1,
|
|
||||||
command=menubar.mOptToolbar)
|
|
||||||
menu.add_radiobutton(label=n_("Bottom"),
|
|
||||||
variable=menubar.tkopt.toolbar, value=2,
|
|
||||||
command=menubar.mOptToolbar)
|
|
||||||
menu.add_radiobutton(label=n_("Left"),
|
|
||||||
variable=menubar.tkopt.toolbar, value=3,
|
|
||||||
command=menubar.mOptToolbar)
|
|
||||||
menu.add_radiobutton(label=n_("Right"),
|
|
||||||
variable=menubar.tkopt.toolbar, value=4,
|
|
||||||
command=menubar.mOptToolbar)
|
|
||||||
## menu.add_separator()
|
|
||||||
## menu.add_radiobutton(label=n_("Small icons"),
|
|
||||||
## variable=menubar.tkopt.toolbar_size, value=0,
|
|
||||||
## command=menubar.mOptToolbarSize)
|
|
||||||
## menu.add_radiobutton(label=n_("Large icons"),
|
|
||||||
## variable=menubar.tkopt.toolbar_size, value=1,
|
|
||||||
## command=menubar.mOptToolbarSize)
|
|
||||||
menu.add_separator()
|
|
||||||
submenu = MfxMenu(menu, label=n_('Visible buttons'), tearoff=tearoff)
|
|
||||||
for w in TOOLBAR_BUTTONS:
|
|
||||||
submenu.add_checkbutton(label=_(w.capitalize()),
|
|
||||||
variable=menubar.tkopt.toolbar_vars[w],
|
|
||||||
command=lambda m=menubar, w=w: m.mOptToolbarConfig(w))
|
|
||||||
|
|
||||||
|
|
||||||
# ************************************************************************
|
|
||||||
# *
|
|
||||||
# ************************************************************************
|
|
||||||
|
|
||||||
class MfxMenubar(Tkinter.Menu):
|
|
||||||
addPath = None
|
|
||||||
|
|
||||||
def __init__(self, master, **kw):
|
|
||||||
self.name = kw["name"]
|
|
||||||
tearoff = 0
|
|
||||||
self.n = kw["tearoff"] = int(kw.get("tearoff", tearoff))
|
|
||||||
Tkinter.Menu.__init__(self, master, **kw)
|
|
||||||
|
|
||||||
def labeltoname(self, label):
|
|
||||||
#print label, type(label)
|
|
||||||
name = re.sub(r"[^0-9a-zA-Z]", "", label).lower()
|
|
||||||
label = _(label)
|
|
||||||
underline = label.find('&')
|
|
||||||
if underline >= 0:
|
|
||||||
label = label.replace('&', '')
|
|
||||||
return name, label, underline
|
|
||||||
|
|
||||||
def add(self, itemType, cnf={}):
|
|
||||||
label = cnf.get("label")
|
|
||||||
if label:
|
|
||||||
name = cnf.get('name')
|
|
||||||
if name:
|
|
||||||
del cnf['name'] # TclError: unknown option "-name"
|
|
||||||
else:
|
|
||||||
name, label, underline = self.labeltoname(label)
|
|
||||||
cnf["underline"] = cnf.get("underline", underline)
|
|
||||||
cnf["label"] = label
|
|
||||||
if name and self.addPath:
|
|
||||||
path = str(self._w) + "." + name
|
|
||||||
self.addPath(path, self, self.n, cnf.get("menu"))
|
|
||||||
Tkinter.Menu.add(self, itemType, cnf)
|
|
||||||
self.n = self.n + 1
|
|
||||||
|
|
||||||
|
|
||||||
class MfxMenu(MfxMenubar):
|
|
||||||
def __init__(self, master, label, underline=None, **kw):
|
|
||||||
if 'name' in kw:
|
|
||||||
name, label_underline = kw['name'], -1
|
|
||||||
else:
|
|
||||||
name, label, label_underline = self.labeltoname(label)
|
|
||||||
kwdefault(kw, name=name)
|
|
||||||
MfxMenubar.__init__(self, master, **kw)
|
|
||||||
if underline is None:
|
|
||||||
underline = label_underline
|
|
||||||
if master:
|
|
||||||
master.add_cascade(menu=self, name=name, label=label, underline=underline)
|
|
||||||
|
|
||||||
|
|
||||||
# ************************************************************************
|
# ************************************************************************
|
||||||
# * - create menubar
|
# * - create menubar
|
||||||
# * - update menubar
|
# * - update menubar
|
||||||
|
|
|
@ -1,92 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
# -*- mode: python; coding: utf-8; -*-
|
|
||||||
##---------------------------------------------------------------------------##
|
|
||||||
##
|
|
||||||
## Copyright (C) 1998-2003 Markus Franz Xaver Johannes Oberhumer
|
|
||||||
## Copyright (C) 2003 Mt. Hood Playing Card Co.
|
|
||||||
## Copyright (C) 2005-2009 Skomoroh
|
|
||||||
##
|
|
||||||
## This program is free software: you can redistribute it and/or modify
|
|
||||||
## it under the terms of the GNU General Public License as published by
|
|
||||||
## the Free Software Foundation, either version 3 of the License, or
|
|
||||||
## (at your option) any later version.
|
|
||||||
##
|
|
||||||
## This program is distributed in the hope that it will be useful,
|
|
||||||
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
## GNU General Public License for more details.
|
|
||||||
##
|
|
||||||
## You should have received a copy of the GNU General Public License
|
|
||||||
## along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
##
|
|
||||||
##---------------------------------------------------------------------------##
|
|
||||||
|
|
||||||
__all__ = ['EVENT_HANDLED',
|
|
||||||
'EVENT_PROPAGATE',
|
|
||||||
'CURSOR_DRAG',
|
|
||||||
'CURSOR_WATCH',
|
|
||||||
'CURSOR_DOWN_ARROW',
|
|
||||||
'ANCHOR_CENTER',
|
|
||||||
'ANCHOR_N',
|
|
||||||
'ANCHOR_NW',
|
|
||||||
'ANCHOR_NE',
|
|
||||||
'ANCHOR_S',
|
|
||||||
'ANCHOR_SW',
|
|
||||||
'ANCHOR_SE',
|
|
||||||
'ANCHOR_W',
|
|
||||||
'ANCHOR_E',
|
|
||||||
'TOOLBAR_BUTTONS',
|
|
||||||
]
|
|
||||||
|
|
||||||
# imports
|
|
||||||
import Tkinter
|
|
||||||
|
|
||||||
from pysollib.mygettext import _, n_
|
|
||||||
|
|
||||||
# ************************************************************************
|
|
||||||
# * constants
|
|
||||||
# ************************************************************************
|
|
||||||
|
|
||||||
EVENT_HANDLED = "break"
|
|
||||||
EVENT_PROPAGATE = None
|
|
||||||
|
|
||||||
CURSOR_DRAG = "hand1"
|
|
||||||
CURSOR_WATCH = "watch"
|
|
||||||
CURSOR_DOWN_ARROW = 'sb_down_arrow'
|
|
||||||
|
|
||||||
ANCHOR_CENTER = Tkinter.CENTER
|
|
||||||
ANCHOR_N = Tkinter.N
|
|
||||||
ANCHOR_NW = Tkinter.NW
|
|
||||||
ANCHOR_NE = Tkinter.NE
|
|
||||||
ANCHOR_S = Tkinter.S
|
|
||||||
ANCHOR_SW = Tkinter.SW
|
|
||||||
ANCHOR_SE = Tkinter.SE
|
|
||||||
ANCHOR_W = Tkinter.W
|
|
||||||
ANCHOR_E = Tkinter.E
|
|
||||||
|
|
||||||
COMPOUNDS = (
|
|
||||||
##(Tkinter.BOTTOM, 'bottom'),
|
|
||||||
##(Tkinter.CENTER, 'center'),
|
|
||||||
##(Tkinter.RIGHT, 'right'),
|
|
||||||
(Tkinter.NONE, n_('Icons only')),
|
|
||||||
(Tkinter.TOP, n_('Text below icons')),
|
|
||||||
(Tkinter.LEFT, n_('Text beside icons')),
|
|
||||||
('text', n_('Text only')),
|
|
||||||
)
|
|
||||||
|
|
||||||
TOOLBAR_BUTTONS = (
|
|
||||||
"new",
|
|
||||||
"restart",
|
|
||||||
"open",
|
|
||||||
"save",
|
|
||||||
"undo",
|
|
||||||
"redo",
|
|
||||||
"autodrop",
|
|
||||||
"shuffle",
|
|
||||||
"pause",
|
|
||||||
"statistics",
|
|
||||||
"rules",
|
|
||||||
"quit",
|
|
||||||
"player",
|
|
||||||
)
|
|
||||||
|
|
22
pysollib/ui/__init__.py
Normal file
22
pysollib/ui/__init__.py
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- mode: python; coding: utf-8; -*-
|
||||||
|
##---------------------------------------------------------------------------##
|
||||||
|
##
|
||||||
|
## Copyright (C) 1998-2003 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
## Copyright (C) 2003 Mt. Hood Playing Card Co.
|
||||||
|
## Copyright (C) 2005-2009 Skomoroh
|
||||||
|
##
|
||||||
|
## This program is free software: you can redistribute it and/or modify
|
||||||
|
## it under the terms of the GNU General Public License as published by
|
||||||
|
## the Free Software Foundation, either version 3 of the License, or
|
||||||
|
## (at your option) any later version.
|
||||||
|
##
|
||||||
|
## This program is distributed in the hope that it will be useful,
|
||||||
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
## GNU General Public License for more details.
|
||||||
|
##
|
||||||
|
## You should have received a copy of the GNU General Public License
|
||||||
|
## along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
##
|
||||||
|
##---------------------------------------------------------------------------##
|
22
pysollib/ui/tktile/__init__.py
Normal file
22
pysollib/ui/tktile/__init__.py
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- mode: python; coding: utf-8; -*-
|
||||||
|
##---------------------------------------------------------------------------##
|
||||||
|
##
|
||||||
|
## Copyright (C) 1998-2003 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
## Copyright (C) 2003 Mt. Hood Playing Card Co.
|
||||||
|
## Copyright (C) 2005-2009 Skomoroh
|
||||||
|
##
|
||||||
|
## This program is free software: you can redistribute it and/or modify
|
||||||
|
## it under the terms of the GNU General Public License as published by
|
||||||
|
## the Free Software Foundation, either version 3 of the License, or
|
||||||
|
## (at your option) any later version.
|
||||||
|
##
|
||||||
|
## This program is distributed in the hope that it will be useful,
|
||||||
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
## GNU General Public License for more details.
|
||||||
|
##
|
||||||
|
## You should have received a copy of the GNU General Public License
|
||||||
|
## along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
##
|
||||||
|
##---------------------------------------------------------------------------##
|
109
pysollib/ui/tktile/menubar.py
Normal file
109
pysollib/ui/tktile/menubar.py
Normal file
|
@ -0,0 +1,109 @@
|
||||||
|
import re
|
||||||
|
import Tkinter
|
||||||
|
|
||||||
|
from pysollib.mfxutil import kwdefault
|
||||||
|
from pysollib.mygettext import _, n_
|
||||||
|
|
||||||
|
from tkconst import EVENT_HANDLED, EVENT_PROPAGATE, CURSOR_WATCH, COMPOUNDS
|
||||||
|
from tkconst import TOOLBAR_BUTTONS
|
||||||
|
|
||||||
|
def createToolbarMenu(menubar, menu):
|
||||||
|
tearoff = menu.cget('tearoff')
|
||||||
|
## data_dir = os.path.join(menubar.app.dataloader.dir, 'images', 'toolbar')
|
||||||
|
## submenu = MfxMenu(menu, label=n_('Style'), tearoff=tearoff)
|
||||||
|
## for f in os.listdir(data_dir):
|
||||||
|
## d = os.path.join(data_dir, f)
|
||||||
|
## if os.path.isdir(d) and os.path.exists(os.path.join(d, 'small')):
|
||||||
|
## name = f.replace('_', ' ').capitalize()
|
||||||
|
## submenu.add_radiobutton(label=name,
|
||||||
|
## variable=menubar.tkopt.toolbar_style,
|
||||||
|
## value=f, command=menubar.mOptToolbarStyle)
|
||||||
|
submenu = MfxMenu(menu, label=n_('Compound'), tearoff=tearoff)
|
||||||
|
for comp, label in COMPOUNDS:
|
||||||
|
submenu.add_radiobutton(
|
||||||
|
label=label, variable=menubar.tkopt.toolbar_compound,
|
||||||
|
value=comp, command=menubar.mOptToolbarCompound)
|
||||||
|
menu.add_separator()
|
||||||
|
menu.add_radiobutton(label=n_("Hide"),
|
||||||
|
variable=menubar.tkopt.toolbar, value=0,
|
||||||
|
command=menubar.mOptToolbar)
|
||||||
|
menu.add_radiobutton(label=n_("Top"),
|
||||||
|
variable=menubar.tkopt.toolbar, value=1,
|
||||||
|
command=menubar.mOptToolbar)
|
||||||
|
menu.add_radiobutton(label=n_("Bottom"),
|
||||||
|
variable=menubar.tkopt.toolbar, value=2,
|
||||||
|
command=menubar.mOptToolbar)
|
||||||
|
menu.add_radiobutton(label=n_("Left"),
|
||||||
|
variable=menubar.tkopt.toolbar, value=3,
|
||||||
|
command=menubar.mOptToolbar)
|
||||||
|
menu.add_radiobutton(label=n_("Right"),
|
||||||
|
variable=menubar.tkopt.toolbar, value=4,
|
||||||
|
command=menubar.mOptToolbar)
|
||||||
|
## menu.add_separator()
|
||||||
|
## menu.add_radiobutton(label=n_("Small icons"),
|
||||||
|
## variable=menubar.tkopt.toolbar_size, value=0,
|
||||||
|
## command=menubar.mOptToolbarSize)
|
||||||
|
## menu.add_radiobutton(label=n_("Large icons"),
|
||||||
|
## variable=menubar.tkopt.toolbar_size, value=1,
|
||||||
|
## command=menubar.mOptToolbarSize)
|
||||||
|
menu.add_separator()
|
||||||
|
submenu = MfxMenu(menu, label=n_('Visible buttons'), tearoff=tearoff)
|
||||||
|
for w in TOOLBAR_BUTTONS:
|
||||||
|
submenu.add_checkbutton(label=_(w.capitalize()),
|
||||||
|
variable=menubar.tkopt.toolbar_vars[w],
|
||||||
|
command=lambda m=menubar, w=w: m.mOptToolbarConfig(w))
|
||||||
|
|
||||||
|
|
||||||
|
# ************************************************************************
|
||||||
|
# *
|
||||||
|
# ************************************************************************
|
||||||
|
|
||||||
|
class MfxMenubar(Tkinter.Menu):
|
||||||
|
addPath = None
|
||||||
|
|
||||||
|
def __init__(self, master, **kw):
|
||||||
|
self.name = kw["name"]
|
||||||
|
tearoff = 0
|
||||||
|
self.n = kw["tearoff"] = int(kw.get("tearoff", tearoff))
|
||||||
|
Tkinter.Menu.__init__(self, master, **kw)
|
||||||
|
|
||||||
|
def labeltoname(self, label):
|
||||||
|
#print label, type(label)
|
||||||
|
name = re.sub(r"[^0-9a-zA-Z]", "", label).lower()
|
||||||
|
label = _(label)
|
||||||
|
underline = label.find('&')
|
||||||
|
if underline >= 0:
|
||||||
|
label = label.replace('&', '')
|
||||||
|
return name, label, underline
|
||||||
|
|
||||||
|
def add(self, itemType, cnf={}):
|
||||||
|
label = cnf.get("label")
|
||||||
|
if label:
|
||||||
|
name = cnf.get('name')
|
||||||
|
if name:
|
||||||
|
del cnf['name'] # TclError: unknown option "-name"
|
||||||
|
else:
|
||||||
|
name, label, underline = self.labeltoname(label)
|
||||||
|
cnf["underline"] = cnf.get("underline", underline)
|
||||||
|
cnf["label"] = label
|
||||||
|
if name and self.addPath:
|
||||||
|
path = str(self._w) + "." + name
|
||||||
|
self.addPath(path, self, self.n, cnf.get("menu"))
|
||||||
|
Tkinter.Menu.add(self, itemType, cnf)
|
||||||
|
self.n = self.n + 1
|
||||||
|
|
||||||
|
|
||||||
|
class MfxMenu(MfxMenubar):
|
||||||
|
def __init__(self, master, label, underline=None, **kw):
|
||||||
|
if 'name' in kw:
|
||||||
|
name, label_underline = kw['name'], -1
|
||||||
|
else:
|
||||||
|
name, label, label_underline = self.labeltoname(label)
|
||||||
|
kwdefault(kw, name=name)
|
||||||
|
MfxMenubar.__init__(self, master, **kw)
|
||||||
|
if underline is None:
|
||||||
|
underline = label_underline
|
||||||
|
if master:
|
||||||
|
master.add_cascade(menu=self, name=name, label=label, underline=underline)
|
||||||
|
|
||||||
|
|
1
setup.py
1
setup.py
|
@ -78,6 +78,7 @@ kw = {
|
||||||
'pysollib.tk',
|
'pysollib.tk',
|
||||||
'pysollib.tile',
|
'pysollib.tile',
|
||||||
'pysollib.pysolgtk',
|
'pysollib.pysolgtk',
|
||||||
|
'pysollib.ui',
|
||||||
'pysollib.games',
|
'pysollib.games',
|
||||||
'pysollib.games.special',
|
'pysollib.games.special',
|
||||||
'pysollib.games.ultra',
|
'pysollib.games.ultra',
|
||||||
|
|
Loading…
Add table
Reference in a new issue