"""mems.instrument.client.tk.button_frame

Displays a row of various action buttons.
"""

# created 2002/01/23, AMK

__revision__ = "$Id: button_frame.py,v 1.3 2002/03/18 17:06:18 akuchlin Exp $"

import string
import Tkinter, Pmw, tkSimpleDialog

class ButtonFrame(Tkinter.Frame):
    def __init__ (self,client,*args):
        apply(Tkinter.Frame.__init__,(self,) + args)

        self.client = client

        msgdict = { 'error': (1, 5, 0, ''),
                    'info':  (2, 5, 0, ''),
                    'state': (3, 0, 0, '') }
	self.message_line = Pmw.MessageBar(self,
                                           entry_width=40,
                                           entry_relief=Tkinter.FLAT,
                                           labelpos=None,
                                           messagetypes=msgdict
                                           )
        self.message_line.message('state', '')
	self.connection_line = Pmw.MessageBar(self,
                                           entry_width=40,
                                           entry_relief=Tkinter.FLAT,
                                           labelpos=None,
                                           messagetypes= msgdict
                                              )
        self.connection_line.message('state', 'Not connected')
                            
        
        f1 = Tkinter.Frame(self)
	for i in ['Take', 'Cede', 'Reload']:
	    method = getattr(self, string.lower(i) + '_clicked')
	    button = Tkinter.Button(f1, text=i, command = method)
            button.pack(side=Tkinter.LEFT)
            setattr(self, string.lower(i)+'Button', button)

        f2 = Tkinter.Frame(self)
	for i in ['Small', 'Medium', 'Large']:
	    method = getattr(self, string.lower(i) + '_clicked')
	    button = Tkinter.Button(f2, text=i, command=method)
            button.pack(side=Tkinter.LEFT)
            setattr(self, string.lower(i)+'Button', button)

        f3 = Tkinter.Frame(self)
	for i in ['Save', 'Email']:
	    method = getattr(self, string.lower(i) + '_clicked')
	    button = Tkinter.Button(f3, text=i, command = method,
                                    state=Tkinter.DISABLED)
            button.pack(side=Tkinter.LEFT)
            setattr(self, string.lower(i)+'Button', button)

        self.connection_line.pack(side=Tkinter.TOP, anchor=Tkinter.W)
        f1.pack(side=Tkinter.TOP, anchor=Tkinter.W)
        f2.pack(side=Tkinter.TOP, anchor=Tkinter.W)
        f3.pack(side=Tkinter.TOP, anchor=Tkinter.W)
        self.message_line.pack(side=Tkinter.TOP)

    def status (self, status, msg):
        self.message_line.message(status, msg)
        
    def take_clicked (self):
        self.client.send_message('take')

    def cede_clicked (self):
        self.client.send_message('cede')

    def save_clicked (self):
        comments = tkSimpleDialog.askstring("Saving Image:",
                                            "Enter comments on the image:")
        if comments is None: return
        self.client.send_message('hires send %s' % comments)

    def email_clicked (self):
        email = tkSimpleDialog.askstring("E-mailing Image:",
                                         "Enter your e-mail address:")
        if email is None: return
        self.client.send_message('email address=%s' % email)

    def reload_clicked (self):
        self.client.move()
        
    def small_clicked (self):
        self.client.send_message('image x=270 y=201')
    def medium_clicked (self): 
        self.client.send_message('image x=320 y=240')
    def large_clicked (self): 
        self.client.send_message('image x=801 y=600')

