WarnDlg.py
Go to the documentation of this file.
00001 ###############################################################################
00002 #
00003 # Package:   RoadNarrows Hekateros Robotic Manipulator Package
00004 #
00005 # Link:      https://github.com/roadnarrows-robotics/hekateros
00006 #
00007 # ROS Node:  hek_*
00008 #
00009 # File:      WarnDlg.py
00010 #
00011 ## \file 
00012 ##
00013 ## $LastChangedDate$
00014 ## $Rev$
00015 ##
00016 ## \brief Pan-Tilt warning dialog.
00017 ##
00018 ## \author Daniel Packard (daniel@roadnarrows.com)
00019 ## \author Robin Knight (robin.knight@roadnarrows.com)
00020 ##  
00021 ## \par Copyright:
00022 ##   (C) 2013-2014.  RoadNarrows LLC.\n
00023 ##   (http://www.roadnarrows.com)\n
00024 ##   All Rights Reserved
00025 ##
00026 # @EulaBegin@
00027 # @EulaEnd@
00028 #
00029 ###############################################################################
00030 
00031 import sys
00032 import os
00033 import time
00034 
00035 from Tkinter import *
00036 from Tkconstants import *
00037 from tkFileDialog import *
00038 import tkFont
00039 
00040 from hekateros_control.Utils import *
00041 
00042 # ------------------------------------------------------------------------------
00043 # Class WarnDlg
00044 # ------------------------------------------------------------------------------
00045 
00046 class WarnDlg(Toplevel):
00047   #
00048   ## \brief Constructor.
00049   ##
00050   ## \param cnf     Configuration dictionary.
00051   ## \param kw      Keyword options.
00052   #
00053   def __init__(self, master=None, cnf={}, **kw):
00054     # initialize dialog data
00055     kw = self.initData(kw)
00056 
00057     Toplevel.__init__(self, master=master, cnf=cnf, **kw)
00058     self.title(self.m_title)
00059 
00060     # create and show widgets
00061     self.createWidgets()
00062 
00063     # allows the enter button to fire either button's action
00064     self.m_bttnCancel.bind('<KeyPress-Return>', func=self.close)
00065 
00066     # center the dialog over parent panel
00067     if master is not None:
00068       self.update_idletasks()
00069       x0 = master.winfo_rootx()
00070       y0 = master.winfo_rooty()
00071       xp = x0 + (master.winfo_width() - self.winfo_width()) / 2 - 8
00072       yp = y0 + (master.winfo_height() - self.winfo_height()) / 2 - 20
00073       glist = [self.winfo_width(), self.winfo_height(), xp, yp]
00074       #self.withdraw() # hide the dialog until position and size is set
00075       self.geometry('{0}x{1}+{2}+{3}'.format(*glist))
00076       #self.deiconify() # now show
00077 
00078     # allows us to customize what happens when the close button is pressed
00079     self.protocol("WM_DELETE_WINDOW", self.close)
00080 
00081     #
00082     # Modal diagle settings.
00083     #
00084     # set the focus on dialog window (needed on Windows)
00085     self.focus_set()
00086 
00087     # make sure events only go to our dialog
00088     self.grab_set()
00089 
00090     # make sure dialog stays on top of its parent window (if needed)
00091     self.transient(master)
00092 
00093     # display the window and wait for it to close
00094     self.wait_window(self)
00095 
00096   #
00097   ## \brief Initialize class state data.
00098   ##
00099   ## \param kw      Keyword options.
00100   ##
00101   ## \return Modified keywords sans this specific class.
00102   ##
00103   def initData(self, kw):
00104     self.m_icons          = {}    # must keep loaded icons referenced
00105     imageLoader = ImageLoader(py_pkg='hekateros_control.images')
00106     if kw.has_key('title'):
00107       self.m_title = kw['title']
00108       del kw['title']
00109     else:
00110       self.m_title = "Warning"
00111     if kw.has_key('image'):
00112       self.m_icons['image'] = imageLoader.load(kw['image'])
00113       del kw['image']
00114     else:
00115       self.m_icons['image'] = None
00116     if self.m_icons['image'] is None:
00117       self.m_icons['image'] = imageLoader.load('icons/icon_warning.png')
00118     if kw.has_key('msg'):
00119       self.m_msg = kw['msg']
00120       del kw['msg']
00121     else:
00122       self.m_msg = "Warn what???"
00123     self.m_result = False
00124     return kw
00125 
00126   #
00127   ## \brief Create gui widgets with supporting data and show.
00128   #
00129   def createWidgets(self):
00130     frame = Frame(self)
00131     frame.grid(row=0, column=0)
00132 
00133     # warning image 
00134     w = Label(frame)
00135     if self.m_icons['image'] is not None:
00136       w = Label(frame)
00137       w['image']  = self.m_icons['image']
00138     w['anchor'] = CENTER
00139     w.grid(row=0, column=0, rowspan=2, sticky=W+N+S)
00140 
00141     # top heading
00142     w = Label(frame)
00143     helv = tkFont.Font(family="Helvetica",size=24,weight="bold")
00144     w['font']   = helv
00145     w['text']   = 'Warning'
00146     w['anchor'] = CENTER
00147     w.grid(row=0, column=1, sticky=E+W)
00148 
00149     row = 1
00150 
00151     # warning message
00152     w = Label(frame)
00153     w['text']   = self.m_msg
00154     w['anchor'] = W
00155     w['justify'] = LEFT
00156     w.grid(row=row, column=1, padx=5, sticky=E+W)
00157 
00158     row += 1
00159 
00160     wframe = Frame(frame)
00161     wframe.grid(row=row, column=1)
00162 
00163     # cancel button
00164     w = Button(wframe, width=10, text='Cancel', command=self.close)
00165     w.grid(row=0, column=0, padx=2, pady=5)
00166     w['anchor']  = CENTER
00167     self.m_bttnCancel = w
00168 
00169     # ok button
00170     w = Button(wframe, width=10, text='Continue', command=self.ok)
00171     w.grid(row=0, column=1, padx=2, pady=5)
00172     w['anchor']  = CENTER
00173     self.m_bttnContinue = w
00174 
00175   #
00176   ## \brief Destroy window callback.
00177   #
00178   def ok(self):
00179     self.m_result = True
00180     self.close()
00181 
00182   #
00183   ## \brief Destroy window callback.
00184   #
00185   def close(self):
00186     self.destroy()


hekateros_control
Author(s): Robin Knight , Daniel Packard
autogenerated on Mon Oct 6 2014 00:36:42