vrex_help.py :  » GUI » PAGE » page » examples » vrex » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » GUI » PAGE 
PAGE » page » examples » vrex » vrex_help.py
#! /usr/bin/env python
# -*- python -*-

# Time-stamp: <2009-07-06 21:18:35 rozen>

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_Helpm ()
    global w
    global w_win
    if w: # So we have only one instance of window.
        return
    w = Toplevel (root)
    w.title('Vrex Helpm')
    w.geometry('609x626+220+159')
    w_win = Vrex_Helpm (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.option_add('*font', 'helvetica 12')
    root.title('Vrex_Help')
    root.geometry('609x626+220+159')
    w = Vrex_Helpm (root)
    init()
    root.mainloop()



def init():
    pass

def load_vrex_help(o):
    help = '''
One enters the regular expression under test into the top text box,
and the sample which is the subject of the regular expression match
into the middle text box.  One may use the File menu to load files
into the text boxes, one may directly type entries or use the normal
cut and paste facilities of the operating system.

Pressing the Go button causes the match to be attempted.  Also,
colorization is applied to both the regular expression and to the
sample. The regular expression is colorized to show the portions of
the regular expression are to extracted individually. And if the match
is successful the corresponding portions of the sample are displayed
in the same colors.

By selecting one of the row of buttons marked match, 1, 2, ..., 9, the
portions of the sample corresponding to extracted portions are
displayed in the match window.

You can use the File menu to load to save both the regular expression
and the sample.

The Quit Button terminates the program. The File menu also has a Quit
entry that terminates the program.

In normal usage, one loads a sample and a regular expression and
experiments with incrementally changes both and testing by hitting the
go button. When you are satisfied you can save the regular expression
or put it on the clipboard by selecting the characters that make up
the regular expression.

You can also enter a whole file of sample strings using File->Load
Sample. In that case, when you select Go, the regular expression
candidate will be applied to each line individually in the sample and
the sample will be colorized accordingly.  Obviously, you can add
build a set of samples by adding them to the sample window and saving
the sample to a file.
   '''
    o.insert(END, help)



def close():
    root.destroy()

class Vrex_Helpm:
    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.tSc33 = ScrolledText (master)
        self.tSc33.place(relx=0.02,rely=0.02,relheight=0.9,relwidth=0.95)
        self.tSc33.configure(height="3")
        self.tSc33.configure(selectbackground="#c4c4c4")
        self.tSc33.configure(width="10")
        self.tSc33.configure(wrap="none")

        self.but34 = Button (master)
        self.but34.place(relx=0.45,rely=0.93)
        self.but34.configure(activebackground="#f9f9f9")
        self.but34.configure(command=close)
        self.but34.configure(text="Close")

        load_vrex_help(self.tSc33)




# 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()



www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.