[Mumps2Py:] [158] some user interface improvements. |
[ Thread Index |
Date Index
| More lists.mumps2py.org/discuss Archives
]
Revision: 158
Author: pgallot
Date: 2008-03-07 16:01:34 +0000 (Fri, 07 Mar 2008)
Log Message:
-----------
some user interface improvements.
Modified Paths:
--------------
trunk/mumps2py_ui.pyw
Modified: trunk/mumps2py_ui.pyw
===================================================================
--- trunk/mumps2py_ui.pyw 2008-03-06 00:21:55 UTC (rev 157)
+++ trunk/mumps2py_ui.pyw 2008-03-07 16:01:34 UTC (rev 158)
@@ -71,22 +71,27 @@
lambda event, c = callback, p = popup: (c(p)))
entry_ctl.focus_set()
- def info_window(self, msg_title = "Mumps2py"):
+ def create_scrolled_text(self, root, **kws):
+ """ created a frame with a Text widget with scrollbars"""
+ new_frame = Frame(root, borderwidth = kws.get('borderwidth', 2))
+ new_window = Text(new_frame, width = kws.get('width', 60),
+ font = ("Consolas", 10), wrap = kws.get('wrap', NONE))
+ new_vscroll = Scrollbar(new_frame, command = new_window.yview)
+ new_hscroll = Scrollbar(new_frame, command = new_window.xview, \
+ orient = HORIZONTAL)
+ new_window.configure(yscrollcommand = new_vscroll.set, \
+ xscrollcommand = new_hscroll.set)
+ new_vscroll.pack(side = RIGHT, fill = Y)
+ new_hscroll.pack(side = BOTTOM, fill = X)
+ new_window.pack(side = LEFT, expand = YES)
+ return (new_frame, new_window)
+
+ def info_window(self, msg_title = "Mumps2py", **kws):
""" generic popup for displaying a bunch of Text."""
popup = Toplevel(self.root)
popup.title(msg_title)
popup.transient(self.root)
- f_info = Frame(popup, borderwidth = 2)
- info_window = Text(f_info, width = 60, font = ("Consolas", 10),
- wrap = NONE)
- dvscroll = Scrollbar(f_info, command = info_window.yview)
- dhscroll = Scrollbar(f_info, command = info_window.xview, \
- orient = HORIZONTAL)
- info_window.configure(yscrollcommand = dvscroll.set, \
- xscrollcommand = dhscroll.set)
- dvscroll.pack(side = RIGHT, fill = Y, expand = YES)
- dhscroll.pack(side = BOTTOM, fill = X, expand = YES)
- info_window.pack(side = LEFT, fill = BOTH, expand = YES)
+ f_info, info_window = self.create_scrolled_text(popup, **kws)
f_info.pack(side = TOP, fill = BOTH, expand = YES)
btn = Button(popup, text = "Close", takefocus = YES)
btn.pack(side = BOTTOM)
@@ -94,6 +99,14 @@
btn.bind('<KeyPress-Return>', lambda event, p = popup: (p.destroy()))
return info_window
+ def busy(self, busy_state = True):
+ """ sets a wait cursor """
+ if busy_state:
+ self.root.config(cursor="watch")
+ else:
+ self.root.config(cursor="")
+
+
class Mumps2pyUI(GenericUI):
"""The class which provides the User Interface to Mumps2Py"""
def __init__(self, my_root):
@@ -102,6 +115,8 @@
self.modules = None
self.before_window = None
self.after_window = None
+ self.show_after = True
+ self.current_file = None
self.current_module = None
self.query = { "from": \
@@ -147,6 +162,7 @@
else:
the_module = self.current_module
line_start, line_end = the_module.start, the_module.end
+ self.busy()
self.before_window.delete(0.0, END)
for line in fileinput.input(the_module.input_file):
line_no = fileinput.lineno()
@@ -156,6 +172,7 @@
break
self.before_window.insert(END, line)
fileinput.close()
+ self.busy(False)
def colorize_routine(self):
""" colorize the current module in the 'before' window"""
@@ -203,6 +220,9 @@
def __display_after(self, translation):
"""populate the after window with the translation of the Mumps module"""
+ if not self.show_after:
+ return
+
self.after_window.delete(0.0, END)
for line in translation:
self.after_window.insert(END, line)
@@ -212,6 +232,7 @@
the_module = self.current_module
self.__display_before()
try:
+ self.busy()
mumps2py.parse_routine(the_module)
self.colorize_routine()
translation = mumps2py.translate(the_module)
@@ -220,6 +241,8 @@
self.message(err.error_msg(), "Parse Error")
except mumps2py.TranslationError, err:
self.message(err.error_msg(), "Translation Error")
+ finally:
+ self.busy(False)
def select_mod(self, mod_name):
""" make the selected routine the current routine"""
@@ -227,6 +250,9 @@
for the_module in self.modules:
if the_module.mod_name == mod_name:
self.current_module = the_module
+ self.root.title("Mumps2py: %s: %s" % \
+ (os.path.basename(self.current_file),
+ the_module))
self.process_current_routine()
return
@@ -240,7 +266,8 @@
if not self.modules:
return
- routinelist_window = self.info_window("routines in this file")
+ title = "routines in %s" % os.path.basename(self.current_file)
+ routinelist_window = self.info_window(title, width = 24)
for routine in self.modules:
r_name = str(routine)
routinelist_window.tag_configure(r_name, foreground = 'blue')
@@ -303,6 +330,7 @@
rpt_window = self.info_window(title)
ref_dict = {}
try:
+ self.busy()
input_file = fileinput.input(self.modules[0].input_file)
for the_module in self.modules:
if the_module == self.current_module:
@@ -329,6 +357,7 @@
"Parse Error in " + the_module.mod_name)
finally:
fileinput.close()
+ self.busy(False)
routine_list = ref_dict.keys()
routine_list.sort()
@@ -344,6 +373,7 @@
"""parse from the module containing the line specified by popup"""
start_line = int(self.entry_val.get())
popup.destroy()
+ self.busy()
if self.modules:
for the_module in self.modules:
if the_module.end < start_line:
@@ -353,9 +383,11 @@
except mumps2py.ParseError, err:
self.message(err.error_msg(),
"Parse Error in " + the_module.mod_name)
+ self.busy(False)
def parse_all(self):
"""parse all the modules in a Mumps file"""
+ self.busy()
if self.modules and len(self.modules) > 1:
for the_module in self.modules:
try:
@@ -375,6 +407,7 @@
self.__display_after(translation)
except mumps2py.TranslationError, err:
self.message(err.error_msg(), "Translation Error")
+ self.busy(False)
def parse_for_errors(self):
"""identify all modules that trigger a ParseError"""
@@ -385,6 +418,7 @@
input_file = fileinput.input(f_name)
tstart = time.time()
try:
+ self.busy()
for modcnt, the_module in enumerate(self.modules):
try:
mumps2py.parse_routine(the_module, input_file)
@@ -396,10 +430,9 @@
print time.time() - tstart, "seconds to parse %d routines" % \
modcnt
fileinput.close()
+ self.busy(False)
rpt_window = self.info_window("Errors in " + os.path.basename(f_name))
- #rpt_window.tag_configure('Fail', foreground = 'red',
- # font = ("Consolas", 18))
if len(error_list) == 0:
rpt_window.insert(END, "No parsing errors found.")
return
@@ -438,6 +471,7 @@
modules_list = self.modules
if modules_list:
try:
+ self.busy()
input_file = fileinput.input(modules_list[0].input_file)
tstart = time.time()
for modcnt, the_module in enumerate(modules_list):
@@ -456,6 +490,7 @@
print time.time() - tstart, "seconds to parse %d routines" % \
modcnt
fileinput.close()
+ self.busy(False)
analysis = [(v, k) for k, v in toks.items()]
analysis.sort(reverse = True)
@@ -467,9 +502,12 @@
def file_close(self):
""" clear out all the information for what was just open"""
self.before_window.delete(0.0, END)
- self.after_window.delete(0.0, END)
+ if self.after_window:
+ self.after_window.delete(0.0, END)
self.modules = None
self.current_module = None
+ self.current_file = None
+ self.root.title("Mumps2Py")
def file_open(self):
""" open a file of Mumps code"""
@@ -485,6 +523,8 @@
return
self.file_close()
+ self.current_file = mumps_file
+ self.root.title("Mumps2Py: %s" % os.path.basename(mumps_file))
tstart = time.time()
self.modules = mumps2py.parse_for_routines(mumps_file, m2py_dir)
@@ -671,33 +711,25 @@
menu_bar.pack(fill = X)
self.make_dialog_menus(menu_bar)
- before_frame = Frame(self.root, borderwidth = 2)
- self.before_window = Text(before_frame, width = 60, \
- font = ("Consolas", 10), wrap=NONE)
- bvscroll = Scrollbar(before_frame, command = self.before_window.yview)
- bhscroll = Scrollbar(before_frame, command = self.before_window.xview, \
- orient = HORIZONTAL)
- self.before_window.configure(yscrollcommand = bvscroll.set, \
- xscrollcommand = bhscroll.set)
- bvscroll.pack(side = RIGHT, fill = Y)
- bhscroll.pack(side = BOTTOM, fill = X)
- self.before_window.pack(side = LEFT, expand = YES)
- before_frame.pack(anchor = NW, side = LEFT, expand = YES)
-
- after_frame = Frame(self.root, borderwidth = 2)
- self.after_window = Text(after_frame, width = 60, \
- font = ("Consolas", 10), wrap = NONE)
- avscroll = Scrollbar(after_frame, command = self.after_window.yview)
- ahscroll = Scrollbar(after_frame, command = self.after_window.xview, \
- orient = HORIZONTAL)
- self.after_window.configure(yscrollcommand = avscroll.set, \
- xscrollcommand = ahscroll.set)
- avscroll.pack(side = RIGHT, fill = Y)
- ahscroll.pack(side = BOTTOM, fill = X)
- self.after_window.pack(side = LEFT, expand = YES)
- after_frame.pack(anchor = NE, side = RIGHT, expand = YES)
+ if self.show_after:
+ text_width = 60
+ else:
+ text_width = 120
+ b4_frame, window1 = self.create_scrolled_text(self.root,
+ width = text_width)
+ b4_frame.pack(anchor = NW, side = LEFT, expand = YES)
+ self.before_window = window1
+
+ if self.show_after:
+ after_frame, window2 = self.create_scrolled_text(self.root, \
+ width = text_width)
+
+ after_frame.pack(anchor = NE, side = RIGHT, expand = YES)
+ self.after_window = window2
+
+
UI = Mumps2pyUI(ROOT)
UI.make_dialog()