commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

r6047 - trunk/gnue-forms/src/uidrivers/win32


From: btami
Subject: r6047 - trunk/gnue-forms/src/uidrivers/win32
Date: Fri, 23 Jul 2004 04:35:47 -0500 (CDT)

Author: btami
Date: 2004-07-23 04:35:46 -0500 (Fri, 23 Jul 2004)
New Revision: 6047

Modified:
   trunk/gnue-forms/src/uidrivers/win32/ErrorHandler.py
   trunk/gnue-forms/src/uidrivers/win32/UIdriver.py
Log:
implemented native MessabeBox()

Modified: trunk/gnue-forms/src/uidrivers/win32/ErrorHandler.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/win32/ErrorHandler.py        2004-07-23 
09:14:22 UTC (rev 6046)
+++ trunk/gnue-forms/src/uidrivers/win32/ErrorHandler.py        2004-07-23 
09:35:46 UTC (rev 6047)
@@ -39,7 +39,7 @@
 
   print
 
-  flags = win32con.MB_OK | win32con.MB_ICONERROR | win32con.MB_SYSTEMMODAL
+  flags = win32con.MB_OK | win32con.MB_ICONERROR | win32con.MB_TASKMODAL
   win32gui.MessageBox(0, _('Unable to start GNUe Forms:') + '\n\n %s' % 
errortext , 'GNUe Forms' , flags )
 
   sys.exit()

Modified: trunk/gnue-forms/src/uidrivers/win32/UIdriver.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/win32/UIdriver.py    2004-07-23 09:14:22 UTC 
(rev 6046)
+++ trunk/gnue-forms/src/uidrivers/win32/UIdriver.py    2004-07-23 09:35:46 UTC 
(rev 6047)
@@ -29,7 +29,9 @@
 
 import sys
 import string
+import types
 
+from gnue.common.apps import i18n
 from gnue.forms.uidrivers._base import Exceptions
 
 try:
@@ -83,18 +85,30 @@
 # All UIs must provide this class
 #
 class GFUserInterface(commonToolkit.GFUserInterface):
-  _wndclass = None
+
+  _MBOX_KIND = {'Info'    : {'type'   : win32con.MB_ICONINFORMATION,
+                             'buttons': win32con.MB_OK},
+                'Warning' : {'type'   : win32con.MB_ICONWARNING,
+                             'buttons': win32con.MB_OK},
+                'Question': {'type'   : win32con.MB_ICONQUESTION,
+                             'buttons': win32con.MB_YESNO},
+                'Error'   : {'type'   : win32con.MB_ICONERROR,
+                             'buttons': win32con.MB_OK}}
 
-  _message_map = {
-    win32con.WM_VSCROLL : OnWMVScroll,
-    win32con.WM_MENUSELECT : OnWMMenuselect,
-    win32con.WM_NOTIFY : OnWMNotify,
-    win32con.WM_DESTROY : OnWMDestroy,
-    win32con.WM_CLOSE : OnWMClose,
-    win32con.WM_SIZE : OnWMSize,
-    win32con.WM_COMMAND : OnWMCommand,
-    }
+  _RESPONSE = {win32con.IDOK    : True,
+               win32con.IDYES   : True,
+               win32con.IDNO    : False,
+               win32con.IDCANCEL: None }
+
+  _message_map = { win32con.WM_VSCROLL    : OnWMVScroll,
+                   win32con.WM_MENUSELECT : OnWMMenuselect,
+                   win32con.WM_NOTIFY     : OnWMNotify,
+                   win32con.WM_DESTROY    : OnWMDestroy,
+                   win32con.WM_CLOSE      : OnWMClose,
+                   win32con.WM_SIZE       : OnWMSize,
+                   win32con.WM_COMMAND    : OnWMCommand }
 
+  _wndclass = None
 
   def _wndproc(self, hwnd, msg, wParam, lParam):
     try:
@@ -112,13 +126,9 @@
   def initialize(self):
 
     self._disabledColour = afxres.AFX_IDC_COLOR_LIGHTGRAY
-
     self._win32app = getWin32App()
-
-    ################################################################
-    # win32 Specifics
-    ################################################################
-    win32gui.InitCommonControls()
+    win32gui.InitCommonControls()
+    
     try:
       icon = win32gui.LoadImage(0, sys.prefix+'\py.ico', win32con.IMAGE_ICON,
                                           0, 0, win32con.LR_LOADFROMFILE | 
win32con.LR_DEFAULTSIZE)
@@ -293,24 +303,34 @@
     except AttributeError:
       pass
 
+
+  def messageBox (self, message, kind = 'Info', title = None, cancel = False):
+    """
+    This function creates a message box of a given kind and returns True, False
+    or None depending on the button pressed.
+    @param message: the text of the messagebox
+    @param kind: type of the message box. Valid types are 'Info', 'Warning',
+        'Question', 'Error'
+    @param title: title of the message box
+    @param cancel: If True a cancel button will be added to the dialog
+    @return: True if the Ok-, Close-, or Yes-button was pressed, False if the
+        No-button was pressed or None if the Cancel-button was pressed.
+    """
+    mbRec  = self._MBOX_KIND.get (kind)
+    flags = win32con.MB_TASKMODAL | mbRec['type'] | mbRec['buttons']
 
-  #############################################################################
-  #
-  # Internal Event Processors
-  #
-  # Processes the events from the widget set
-  #
+    if title is not None and len (title):
+      if isinstance (title, types.StringType):
+        title = unicode (title, i18n.encoding)
 
+    cButtons = [win32con.MB_OKCANCEL, win32con.MB_YESNOCANCEL]
+
+    if cancel and not mbRec ['buttons'] in cButtons:
+      if mbRec ['buttons'] == win32con.MB_OK:
+        flags = flags | win32con.MB_OKCANCEL
+      elif mbRec ['buttons'] == win32con.MB_YESNO:
+        flags = flags | win32con.MB_YESNOCANCEL
+
+    res = win32gui.MessageBox(0, message, title, flags)
 
-  #
-  # closeTrap
-  #
-  # intercepts the applications closure and generates an event to the form 
requesting
-  # closure.  Allows the form to control closure.  If the form approves it'll 
send
-  # back an event closing the application
-  #`
-  def closeTrap(self,event):
-    if event.CanVeto():
-      self.dispatchEvent('requestEXIT',_form=self._form)
-    else:
-      event.Destroy()
+    return self._RESPONSE [res]





reply via email to

[Prev in Thread] Current Thread [Next in Thread]