Skip to content
This repository has been archived by the owner on Feb 14, 2018. It is now read-only.

Commit

Permalink
[MixMaster] Fix crash when using Tcl 8.6
Browse files Browse the repository at this point in the history
Tcl/Tk changed some operations which previously resulted in undefined behavior
into errors, including one case that occurred when updating the "Mixtures" menu
in MixMaster.

MixMaster now modifies the existing Menu when adding an item, rather than
completely regenerating it, which avoids this problem.

Cherry-pick of trunk r3162.

git-svn-id: https://cantera.googlecode.com/svn/cantera/branches/2.1@3163 02a645c2-efd0-11dd-984d-ab748d24aa7e
  • Loading branch information
speth committed Sep 15, 2014
1 parent 9598c73 commit ac35faa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 32 deletions.
55 changes: 25 additions & 30 deletions interfaces/cython/cantera/mixmaster/ControlPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,40 +106,35 @@ def make_menu(name, menubar, lst):
button=Menubutton(menubar, text=name, width=nc+4, padx=3,pady=1)
button.pack(side=LEFT)
menu = Menu(button,tearoff=FALSE)
m = menu
i = 0
for entry in lst:
i += 1
if entry == 'separator':
menu.add_separator({})
elif isinstance(entry, list):
for num in entry:
menu.entryconfig(num,state=DISABLED)
elif not isinstance(entry[1], list):
if i == 20:
i = 0
submenu = Menu(button,tearoff=FALSE)
m.add_cascade(label='More...',
menu=submenu)
m = submenu
if len(entry) == 2 or entry[2] == 'command':
m.add_command(label=entry[0],
command=entry[1])
elif entry[2] == 'check':
entry[3].set(0)
if len(entry) >= 5: val = entry[4]
else: val = 1
m.add_checkbutton(label=entry[0],
command=entry[1],
variable = entry[3],
onvalue=val)
else:
submenu=make_menu(entry[0], menu, entry[1])
m.add_cascade(label=entry[0],
menu=submenu)
add_menu_item(menu, entry)
button['menu']=menu
return button

def add_menu_item(menu, entry):
if entry == 'separator':
menu.add_separator({})
elif isinstance(entry, list):
for num in entry:
menu.entryconfig(num,state=DISABLED)
elif not isinstance(entry[1], list):
if len(entry) == 2 or entry[2] == 'command':
menu.add_command(label=entry[0],
command=entry[1])
elif entry[2] == 'check':
entry[3].set(0)
if len(entry) >= 5: val = entry[4]
else: val = 1
menu.add_checkbutton(label=entry[0],
command=entry[1],
variable = entry[3],
onvalue=val)
else:
submenu=make_menu(entry[0], menu, entry[1])
menu.add_cascade(label=entry[0],
menu=submenu)


def menuitem_state(button, *statelist):
for menu in button.children.keys():
if isinstance(button.children[menu], Menu):
Expand Down
4 changes: 2 additions & 2 deletions interfaces/cython/cantera/mixmaster/MechManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from Tkinter import *

from .ControlPanel import ControlWindow
from .ControlPanel import make_menu, menuitem_state
from .ControlPanel import make_menu, menuitem_state, add_menu_item
#from Cantera.Examples.Tk import _mechdir
import os

Expand Down Expand Up @@ -52,9 +52,9 @@ def addMechanism(self, name, mech):
self.mechanisms.append((name, mech))
il = len(self.mechanisms)
self.mlist[-1] = (name, self.setMechanism, 'check', self.mechindx, il)
add_menu_item(list(self.mechmenu.children.values())[0], self.mlist[-1])
self.mlist.append([])

self.mechmenu = make_menu('Mixtures', self, self.mlist)
self.mechindx.set(il)
self.mechmenu.grid(row=0,column=0,sticky=W)

Expand Down

0 comments on commit ac35faa

Please sign in to comment.