simple_tk.py :  » Development » Python-Twain-Module » twain_1.0.3 » demo » 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 » Development » Python Twain Module 
Python Twain Module » twain_1.0.3 » demo » simple_tk.py
"""simple_tk.py

This is a simple demonstration of the twain module using Tkinter.

This version does not use callbacks. Instead, it polls to check to
see if the image is ready. Callbacks do not work with twainmodule and
Tkinter in python 2.5
"""

from Tkinter import *

from simple_base import TwainBase

import ImageTk # PIL required

import traceback, sys

TITLE="Simple Twain Demo Using Tkinter"

class MainWindow(Frame, TwainBase):
    def __init__(self, title):
        Frame.__init__(self, colormap="new", visual="truecolor")
        self.master.title(title)
        self.master.geometry("500x500+100+100")
        MenuPanel = Frame(self, relief=RAISED, borderwidth=2)
        File = Menubutton(MenuPanel, text="File")
        File.menu = Menu(File)
        File.menu.add_command(label="Connect", command=self.MnuOpenScanner)
        File.menu.add_command(label="Acquire Natively", command=self.MnuAcquireNatively)
        File.menu.add_command(label="Acquire By File", command=self.MnuAcquireByFile)
        File.menu.add('separator')
        File.menu.add_command(label="Exit", command=self.MnuQuit)
        File['menu'] = File.menu
        File.pack(side="left")
        MenuPanel.pack(side="top", fill=X, expand=1)
        self.tk_menuBar(File)
        self.pack(fill="both")
        self.bind('<Destroy>', self.OnQuit)

        self.imageLabel = Label(self)
        self.imageLabel.pack(side="left", fill="both", expand=1)

        # Print out the exception - requires that you run from the command prompt
        sys.excepthook = traceback.print_exception

        # Initialise TWAIN Base class
        self.Initialise()

        # Initialise Idle Timer
        self.after(250, self.OnIdleTimer)

    def MnuQuit(self, event=None):
        self.unbind('<Destroy>')
        self.Terminate()          # Terminate base class
        self.quit()

    def OnQuit(self, event=None):
        self.Terminate()

    def MnuOpenScanner(self, event=None):
        self.OpenScanner(self.winfo_id(), ProductName="Simple Tk Demo")

    def MnuAcquireNatively(self, event=None):
        self.AcquireNatively()

    def MnuAcquireByFile(self, event=None):
        self.AcquireByFile()

    def DisplayImage(self, filename):
        try:
            imagedata = ImageTk.PhotoImage(file=filename)
            self.imageLabel.config(image=imagedata)
            self.imageLabel.pack(side="left", fill="both", expand=1)
            self.master.title(filename)
            # Need to keep this object resident
            self.imagedata= imagedata
        except:
            ei = sys.exc_info()
            traceback.print_exception(ei[0], ei[1], ei[2])
            
    def LogMessage(self, message):
        self.master.title(message)

    def OnIdleTimer(self):
        self.PollForImage()
        self.after(250, self.OnIdleTimer)

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