#! /usr/bin/env python
# -*- python -*-
import sys
py2 = py30 = py31 = False
version = sys.hexversion
if version >= 0x020600F0 and version < 0x03000000 :
py2 = True # Python 2.6 or 2.7
from Tkinter import *
import ttk
elif version >= 0x03000000 and version < 0x03010000 :
py30 = True
from tkinter import *
import ttk
elif version >= 0x03010000:
py31 = True
from tkinter import *
import tkinter.ttk as ttk
else:
print ("""
You do not have a version of python supporting ttk widgets..
You need a version >= 2.6 to execute PAGE modules.
""")
sys.exit()
'''
If you use the following functions, change the names 'w' and
'w_win'. Use as a template for creating a new Top-level window.
w = None
def create_Vrex_for_Python ()
global w
global w_win
if w: # So we have only one instance of window.
return
w = Toplevel (root)
w.title('Vrex for Python')
w.geometry('609x577+769+138')
w_win = Vrex_for_Python (w)
Template for routine to destroy a top level window.
def destroy():
global w
w.destroy()
w = None
'''
def vp_start_gui():
global val, w, root
root = Tk()
root.title('Vrex_for_Python')
root.geometry('609x577+769+138')
w = Vrex_for_Python (root)
init()
root.mainloop()
def init():
pass
def go():
pass
def help():
pass
def display(p1):
pass
def load_regular_expression():
pass
def load_sample():
pass
def quit():
pass
def save_regular_expression():
pass
def save_sample():
pass
class Vrex_for_Python:
def __init__(self, master=None):
# Set background of toplevel window to match
# current style
style = ttk.Style()
theme = style.theme_use()
default = style.lookup(theme, 'background')
master.configure(background=default)
self.tPa33 = ttk.Panedwindow (master, orient="vertical")
self.tPa33.place(relx=0.02,rely=0.02,relheight=0.49,relwidth=0.96)
self.tPa33.configure(width="585")
self.tPa33.configure(height="280")
self.tPa33_f1 = ttk.Labelframe(height=75, text='Regular Expression')
self.tPa33.add(self.tPa33_f1)
self.tPa33_f2 = ttk.Labelframe(text='Sample')
self.tPa33.add(self.tPa33_f2)
self.__funcid0 = self.tPa33.bind('<Map>', self.__adjust_sash0)
self.tPa33_f1_tSc35 = ScrolledText (self.tPa33_f1)
self.tPa33_f1_tSc35.place(relx=0.04,rely=0.2,relheight=0.75
,relwidth=0.92)
self.tPa33_f1_tSc35.configure(height="3")
self.tPa33_f1_tSc35.configure(selectbackground="#c4c4c4")
self.tPa33_f1_tSc35.configure(width="10")
self.tPa33_f1_tSc35.configure(wrap="none")
self.tPa33_f2_tSc34 = ScrolledText (self.tPa33_f2)
self.tPa33_f2_tSc34.place(relx=0.04,rely=0.08,relheight=0.86
,relwidth=0.92)
self.tPa33_f2_tSc34.configure(height="3")
self.tPa33_f2_tSc34.configure(selectbackground="#c4c4c4")
self.tPa33_f2_tSc34.configure(width="10")
self.m32 = Menu(master,font=('Nimbus Sans L',12,'normal','roman',))
master.configure(menu = self.m32)
self.m32_men33 = Menu(master,tearoff=0,font=('Nimbus Sans L',12,'normal','roman',))
self.m32.add_cascade(label="File",menu=self.m32_men33)
self.m32_men33.add_command(label="Load regular expression",command=load_regular_expression)
self.m32_men33.add_command(label="Save regular expression",command=save_regular_expression)
self.m32_men33.add_separator()
self.m32_men33.add_command(label="Load sample",command=load_sample)
self.m32_men33.add_command(label="Save sample",command=save_sample)
self.m32_men33.add_separator()
self.m32_men33.add_command(label="Quit",command=quit)
self.m32.add_command(label="Help",command=help)
self.but34 = Button (master)
self.but34.place(relx=0.89,rely=0.54)
self.but34.configure(activebackground="#f9f9f9")
self.but34.configure(command=quit)
self.but34.configure(text="Quit")
self.tLa35 = ttk.Labelframe (master)
self.tLa35.place(relx=0.03,rely=0.62,relheight=0.31,relwidth=0.95)
self.tLa35.configure(text="Matches")
self.tLa35.configure(width="580")
self.tLa35.configure(height="180")
self.tLa35_tSc36 = ScrolledText (self.tLa35)
self.tLa35_tSc36.place(relx=0.04,rely=0.13,relheight=0.81,relwidth=0.92)
self.tLa35_tSc36.configure(height="3")
self.tLa35_tSc36.configure(selectbackground="#c4c4c4")
self.tLa35_tSc36.configure(width="10")
self.but32 = Button (master)
self.but32.place(relx=0.17,rely=0.54)
self.but32.configure(activebackground="#f9f9f9")
self.but32.configure(command=lambda:display(0))
self.but32.configure(text="Match")
self.but33 = Button (master)
self.but33.place(relx=0.28,rely=0.54)
self.but33.configure(activebackground="#f9f9f9")
self.but33.configure(command=lambda:display(1))
self.but33.configure(foreground="blue")
self.but33.configure(text="1")
self.but35 = Button (master)
self.but35.place(relx=0.34,rely=0.54)
self.but35.configure(activebackground="#f9f9f9")
self.but35.configure(command=lambda:display(2))
self.but35.configure(foreground="darkgreen")
self.but35.configure(text="2")
self.but36 = Button (master)
self.but36.place(relx=0.39,rely=0.54)
self.but36.configure(activebackground="#f9f9f9")
self.but36.configure(command=lambda:display(0))
self.but36.configure(foreground="magenta")
self.but36.configure(text="3")
self.but37 = Button (master)
self.but37.place(relx=0.45,rely=0.54)
self.but37.configure(activebackground="#f9f9f9")
self.but37.configure(command=lambda:display(4))
self.but37.configure(foreground="sienna")
self.but37.configure(text="4")
self.but38 = Button (master)
self.but38.place(relx=0.51,rely=0.54)
self.but38.configure(activebackground="#f9f9f9")
self.but38.configure(command=lambda:display(5))
self.but38.configure(foreground="purple")
self.but38.configure(text="5")
self.but39 = Button (master)
self.but39.place(relx=0.57,rely=0.54)
self.but39.configure(activebackground="#f9f9f9")
self.but39.configure(command=lambda:display(6))
self.but39.configure(foreground="firebrick")
self.but39.configure(text="6")
self.but40 = Button (master)
self.but40.place(relx=0.62,rely=0.54)
self.but40.configure(activebackground="#f9f9f9")
self.but40.configure(command=lambda:display(7))
self.but40.configure(foreground="deeppink")
self.but40.configure(text="7")
self.but41 = Button (master)
self.but41.place(relx=0.68,rely=0.54)
self.but41.configure(activebackground="#f9f9f9")
self.but41.configure(command=lambda:display(8))
self.but41.configure(foreground="green4")
self.but41.configure(text="8")
self.but42 = Button (master)
self.but42.place(relx=0.74,rely=0.54)
self.but42.configure(activebackground="#f9f9f9")
self.but42.configure(command=lambda:display(9))
self.but42.configure(foreground="deepskyblue1")
self.but42.configure(text="9")
self.but43 = Button (master)
self.but43.place(relx=0.03,rely=0.54)
self.but43.configure(activebackground="#f9f9f9")
self.but43.configure(command=go)
self.but43.configure(text="Go")
def __adjust_sash0(self, event):
paned = event.widget
pos = [75,]
i = 0
for sash in pos:
paned.sashpos(i, sash)
i += 1
paned.unbind('<map>', self.__funcid0)
del self.__funcid0
# The following code is added to facilitate the Scrolled widgets you specified.
class AutoScroll(object):
'''Configure the scrollbars for a widget.'''
def __init__(self, master):
vsb = ttk.Scrollbar(master, orient='vertical', command=self.yview)
hsb = ttk.Scrollbar(master, orient='horizontal', command=self.xview)
self.configure(yscrollcommand=self._autoscroll(vsb),
xscrollcommand=self._autoscroll(hsb))
self.grid(column=0, row=0, sticky='nsew')
vsb.grid(column=1, row=0, sticky='ns')
hsb.grid(column=0, row=1, sticky='ew')
master.grid_columnconfigure(0, weight=1)
master.grid_rowconfigure(0, weight=1)
# Copy geometry methods of master (took from ScrolledText.py)
methods = Pack.__dict__.keys() + Grid.__dict__.keys() \
+ Place.__dict__.keys()
for meth in methods:
if meth[0] != '_' and meth not in ('config', 'configure'):
setattr(self, meth, getattr(master, meth))
@staticmethod
def _autoscroll(sbar):
'''Hide and show scrollbar as needed.'''
def wrapped(first, last):
first, last = float(first), float(last)
if first <= 0 and last >= 1:
sbar.grid_remove()
else:
sbar.grid()
sbar.set(first, last)
return wrapped
def __str__(self):
return str(self.master)
def _create_container(func):
'''Creates a ttk Frame with a given master, and use this new frame to
place the scrollbars and the widget.'''
def wrapped(cls, master, **kw):
container = ttk.Frame(master)
return func(cls, container, **kw)
return wrapped
class ScrolledText(AutoScroll, Text):
'''A standard Tkinter Text widget with scrollbars that will
automatically show/hide as needed.'''
@_create_container
def __init__(self, master, **kw):
Text.__init__(self, master, **kw)
AutoScroll.__init__(self, master)
if __name__ == '__main__':
vp_start_gui()
|