[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r7536 - trunk/gnue-forms/src/uidrivers/win32
From: |
btami |
Subject: |
[gnue] r7536 - trunk/gnue-forms/src/uidrivers/win32 |
Date: |
Fri, 6 May 2005 16:49:29 -0500 (CDT) |
Author: btami
Date: 2005-05-06 16:49:28 -0500 (Fri, 06 May 2005)
New Revision: 7536
Modified:
trunk/gnue-forms/src/uidrivers/win32/UIdriver.py
trunk/gnue-forms/src/uidrivers/win32/common.py
trunk/gnue-forms/src/uidrivers/win32/dialog.py
trunk/gnue-forms/src/uidrivers/win32/dialogs.py
Log:
new ExceptionDisplay dialog with cut and paste traceback support
Modified: trunk/gnue-forms/src/uidrivers/win32/UIdriver.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/win32/UIdriver.py 2005-05-06 17:59:47 UTC
(rev 7535)
+++ trunk/gnue-forms/src/uidrivers/win32/UIdriver.py 2005-05-06 21:49:28 UTC
(rev 7536)
@@ -1,7 +1,7 @@
# This file is part of GNU Enterprise.
#
# GNU Enterprise is free software; you can redistribute it
-# and/or modify it under the terms of the GNU General Public
+# and/or modify it under the terms of the GNU GPublic
# License as published by the Free Software Foundation; either
# version 2, or (at your option) any later version.
#
@@ -50,8 +50,14 @@
#from gnue.forms.uidrivers.wx.UIWXSplashScreen import *
from gnue.forms.uidrivers.win32.widgets._base import *
from gnue.forms.uidrivers.win32.common import textEncode
+from gnue.forms.uidrivers.win32.dialog import BaseDialog
from gnue.forms.uidrivers.win32 import dialogs
+
+EDIT = 0x0081
+STATIC = 0x0082
+BUTTON = 0x0080
+
def OnWMVScroll(hwnd, msg, wParam, lParam, widget):
return widget.OnWMVScroll(hwnd, msg, wParam, lParam)
@@ -194,7 +200,7 @@
self.textWidth = int(maxWidth+maxLeading) # The pixel width of text
inside a widget
self.textHeight = int(maxHeight+maxDescent) # The pixel height of text
inside a widget
- self.widgetWidth = self.textWidth # The pixel width of a 1
char widget (for things like buttons)
+ self.widgetWidth = self.textWidthxxx # The pixel width of a 1
char widget (for things like buttons)
self.widgetHeight = self.textHeight + 5 # The pixel height of a 1
char widget (for things like buttons)
#
@@ -377,22 +383,17 @@
def _getInput (self, title, fields, cancel = True):
dialog = dialogs.InputDialog (title, fields, cancel)
- try:
- dialog.DoModal ()
- return dialog.inputData
-
- finally:
- dialog.Destroy ()
+ dialog.DoModal ()
# ---------------------------------------------------------------------------
# Show an exception
- # TODO: please implement a better dialog box, i.e. add a button for
- # detail-display and so on
# ---------------------------------------------------------------------------
- def _showException (self, group, name, message, detail):
- self.showMessage (detail, kind = 'Error')
+ def _showException (self, group, name, message, detail):
+
+ dialog = ExceptionDisplay (group, name, message, detail)
+ dialog.DoModal ()
# ---------------------------------------------------------------------------
@@ -402,3 +403,173 @@
def _showAbout (self, name, appversion, formversion, author, description):
d = dialogs.AboutBox (name, appversion, formversion, author, description)
d.DoModal ()
+
+
+# =============================================================================
+# This class implements a dialog for displaying exceptions
+# =============================================================================
+
+class ExceptionDisplay (BaseDialog):
+
+ _TITLE = {'system' : _("GNUe Internal System Error"),
+ 'admin' : _("GNUe Unexpected Error"),
+ 'application': _("GNUe Application Error")}
+
+ _FORMAT = {
+ 'system': u_("An unexpected internal error has occured:\r\n%s.\r\n"
+ "This means you have found a bug in GNU Enterprise. "
+ "Please report it to address@hidden"),
+ 'admin': u_("An unexpected error has occured:\r\n%s.\r\n"
+ "Please contact your system administrator."),
+ 'application': u_("An unexpected error has occured:\r\n%s.\r\n"
+ "Please contact your system administrator.")}
+
+ # ---------------------------------------------------------------------------
+ # Constructor
+ # ---------------------------------------------------------------------------
+
+ def __init__ (self, group, name, message, detail):
+
+ BaseDialog.__init__(self, self._TITLE.get (group, _('Error')), cancel =
False, ok = False)
+
+ self.detail = detail.replace('\n','\r\n')
+
+ cs = win32con.WS_CHILD | win32con.WS_VISIBLE
+ position = (0, 0, 0, 0)
+
+# self.iconID = ID = getNextId()
+# s = cs | win32con.SS_ICON | win32con.WS_BORDER
+# self.template.append([STATIC, 'icon', ID, (0,0,32,32), s])
+
+ self.messageID = ID = getNextId()
+ s = cs | win32con.SS_LEFT
+ self.template.append([STATIC, textEncode(self._FORMAT.get (group, "%s") %
message), \
+ ID, position, s])
+
+ s = cs | win32con.WS_TABSTOP | win32con.BS_DEFPUSHBUTTON
+ self.template.append([BUTTON, textEncode(u_('Close')), win32con.IDCLOSE,
(0, 0, 56, 15), s])
+
+ self.detailsID = ID = getNextId()
+ s = cs | win32con.WS_TABSTOP | win32con.BS_PUSHBUTTON
+ self.template.append([BUTTON, textEncode(u_('>> Details')), ID, (0, 0, 56,
15), s])
+
+ self.detailID = ID = getNextId()
+ s = cs | win32con.ES_MULTILINE | win32con.ES_READONLY |
win32con.WS_TABSTOP \
+ | win32con.ES_AUTOVSCROLL | win32con.WS_VSCROLL
+ es = win32con.WS_EX_STATICEDGE
+ self.template.append([EDIT, textEncode(self.detail), ID, position, s, es])
+
+ self._showsDetail = False
+
+
+ def OnInitDialog(self, hwnd, msg, wparam, lparam):
+ BaseDialog.OnInitDialog(self, hwnd, msg, wparam, lparam)
+
+ item = win32gui.GetDlgItem(self.hwnd, self.detailID)
+ win32gui.EnableWindow(item, 0)
+
+# ico = win32gui.LoadImage(0, win32con.IDI_WARNING, win32con.IMAGE_ICON, 0,
0, win32con.LR_DEFAULTSIZE)
+# ico = win32gui.LoadIcon(0, win32con.IDI_WARNING)
+# bmCtrl = win32gui.GetDlgItem(self.hwnd, self.iconID)
+# win32gui.SendMessage(bmCtrl, win32con.STM_SETICON, win32con.IMAGE_ICON,
ico)
+
+ self.Recalculate()
+
+
+ def OnCommand(self, hwnd, msg, wparam, lparam):
+ id = win32api.LOWORD(wparam)
+ if id == win32con.IDCLOSE:
+ win32gui.EndDialog(hwnd, 1)
+ elif id == self.detailsID:
+ self._showsDetail = not self._showsDetail
+ if self._showsDetail:
+ item = win32gui.GetDlgItem(self.hwnd, self.detailID)
+ win32gui.EnableWindow(item, 1)
+ win32gui.SetDlgItemText(hwnd, id, u_("<< Details"))
+ self.Recalculate()
+ else:
+ item = win32gui.GetDlgItem(self.hwnd, self.detailID)
+ win32gui.EnableWindow(item, 0)
+ win32gui.SetDlgItemText(hwnd, id, u_(">> Details"))
+ self.Recalculate()
+
+
+ def Recalculate(self):
+ border = 10
+
+ dlgWidth = self.Width(self.detailsID) + self.Width(win32con.IDCLOSE) + 20
+ dlgWidth = max(dlgWidth, self.Width(self.messageID))
+ if self._showsDetail:
+ dlgWidth = max(dlgWidth, self.Width(self.detailID))
+
+ ypos = border
+
+ self.SetPosition(self.messageID, border, ypos)
+ ypos += self.Height(self.messageID) + 10
+
+ if self._showsDetail:
+ self.SetPosition(self.detailID, border, ypos)
+ ypos += self.Height(self.detailID) + 10
+ else:
+ dlgItem = win32gui.GetDlgItem(self.hwnd, self.detailID)
+ win32gui.SetWindowPos(dlgItem, 0, 0, 0, 0, 0, 0)
+
+ self.SetPosition(self.detailsID, dlgWidth + 2*border \
+ - self.Width(self.detailsID) -4, ypos + 15)
+
+ self.SetPosition(win32con.IDCLOSE, dlgWidth + 2*border \
+ - self.Width(self.detailsID) \
+ - self.Width(win32con.IDCLOSE) -8, ypos + 15)
+
+ ypos += self.Height(win32con.IDCLOSE) + border
+
+ # resize the dialog
+ win32gui.SetWindowPos(self.hwnd, 0,
+ 0, 0,
+ dlgWidth + 2*border + 10, ypos + 45,
+ win32con.SWP_NOACTIVATE | win32con.SWP_NOZORDER \
+ | win32con.SWP_NOMOVE)
+
+ # center the dialog
+ centerWindow(self.hwnd)
+
+
+ def Width(self, id):
+ item = win32gui.GetDlgItem(self.hwnd, id)
+ if id == self.messageID or id == self.detailID:
+ text = win32gui.GetWindowText(item)
+ # GetWindowText has only 512 byte buffer, sigh...
+ if id == self.detailID:
+ text = self.detail
+ if '\r\n' in text:
+ w = max ([self.dc.GetTextExtent(t) [0] for t in text.split ('\r\n')])
+ else:
+ w, h = self.dc.GetTextExtent(text)
+ return w + 40
+ else:
+ l,t,r,b = win32gui.GetWindowRect(item)
+ return r-l
+
+
+ def Height(self, id):
+ item = win32gui.GetDlgItem(self.hwnd, id)
+ if id == self.messageID or id == self.detailID:
+ text = win32gui.GetWindowText(item)
+ if id == self.detailID:
+ text = self.detail
+ if '\r\n' in text:
+ h = sum ([self.dc.GetTextExtent(t) [1] for t in text.split ('\r\n')])
+ else:
+ w, h = self.dc.GetTextExtent(text)
+ return h
+ else:
+ l,t,r,b = win32gui.GetWindowRect(item)
+ return b-t
+
+
+ def SetPosition(self, id, x, y):
+ item = win32gui.GetDlgItem(self.hwnd, id)
+ win32gui.SetWindowPos(item, 0,
+ x, y,
+ self.Width(id), self.Height(id),
+ win32con.SWP_NOACTIVATE | win32con.SWP_NOZORDER)
Modified: trunk/gnue-forms/src/uidrivers/win32/common.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/win32/common.py 2005-05-06 17:59:47 UTC
(rev 7535)
+++ trunk/gnue-forms/src/uidrivers/win32/common.py 2005-05-06 21:49:28 UTC
(rev 7536)
@@ -46,7 +46,7 @@
l,t,r,b = win32gui.GetWindowRect(hwnd)
dt_l, dt_t, dt_r, dt_b = win32gui.GetWindowRect(desktop)
center_x, center_y = win32gui.ClientToScreen( desktop, ( (dt_r-dt_l)/2,
(dt_b-dt_t)/2) )
- win32gui.MoveWindow(hwnd, center_x-(r/2), center_y-(b/2), r-l, b-t, 0)
+ win32gui.MoveWindow(hwnd, center_x-(r/2), center_y-(b/2), r-l, b-t, 1)
def textEncode(u_string):
Modified: trunk/gnue-forms/src/uidrivers/win32/dialog.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/win32/dialog.py 2005-05-06 17:59:47 UTC
(rev 7535)
+++ trunk/gnue-forms/src/uidrivers/win32/dialog.py 2005-05-06 21:49:28 UTC
(rev 7536)
@@ -39,7 +39,7 @@
class BaseDialog:
- def __init__ (self, title, cancel = False):
+ def __init__ (self, title, cancel = False, ok = True):
win32gui.InitCommonControls()
self.hinst = win32api.GetModuleHandle(None)
@@ -47,7 +47,6 @@
win32con.WM_COMMAND: self.OnCommand,
win32con.WM_INITDIALOG: self.OnInitDialog,
win32con.WM_CLOSE: self.OnClose,
- win32con.WM_CTLCOLORSTATIC: self.OnCtlColorStatic,
}
dlgClassName = self._RegisterWndClass()
@@ -58,7 +57,8 @@
self.template = [ [textEncode(title), (0, 0, 120, 20), style, None, \
(8, "MS Sans Serif"), None, dlgClassName], ]
- self.template.append ([BUTTON, _("Ok"), win32con.IDOK, (0, 0, 56, 15),
+ if ok:
+ self.template.append ([BUTTON, _("Ok"), win32con.IDOK, (0, 0, 56, 15),
win32con.WS_CHILD | win32con.WS_VISIBLE | \
win32con.WS_TABSTOP | win32con.BS_DEFPUSHBUTTON])
if cancel:
@@ -107,8 +107,6 @@
elif id == win32con.IDCANCEL:
win32gui.EndDialog(hwnd, 0)
- def OnCtlColorStatic(self, hwnd, msg, wparam, lparam):
- pass
def _RegisterWndClass(self):
className = "GNUe dialog"
Modified: trunk/gnue-forms/src/uidrivers/win32/dialogs.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/win32/dialogs.py 2005-05-06 17:59:47 UTC
(rev 7535)
+++ trunk/gnue-forms/src/uidrivers/win32/dialogs.py 2005-05-06 21:49:28 UTC
(rev 7536)
@@ -99,6 +99,7 @@
@param cancel: If True add a Cancel button to the dialog
"""
BaseDialog.__init__(self, title, cancel)
+ self.message_map [win32con.WM_CTLCOLORSTATIC] = self.OnCtlColorStatic
self.fields = fields
self.inputData = {}
@@ -123,7 +124,8 @@
def AddControl(self, field):
label, name, ftype, default, master, elements = field
cs = win32con.WS_CHILD | win32con.WS_VISIBLE
-
+ es = win32con.WS_EX_STATICEDGE
+
position = (0, 0, 0, 0)
if ftype == 'label' or ftype == 'warning':
ID = getNextId()
@@ -142,10 +144,10 @@
self.controlsName [ID] = name
ID = getNextId()
- s = cs | win32con.WS_TABSTOP | win32con.WS_BORDER
+ s = cs | win32con.WS_TABSTOP #| win32con.WS_BORDER
if ftype == 'password':
s = s | win32con.ES_PASSWORD
- self.template.append([EDIT, default, ID, position, s])
+ self.template.append([EDIT, default, ID, position, s,es])
self.__inputs.append (ID)
elif ftype == 'image':
@@ -417,7 +419,8 @@
win32gui.SetWindowPos (item, 0, 0, 0, right, bottom - top, flags)
# Resize the dialog itself to the new width
- right += 24
+ right += 24
+ flags = win32con.SWP_NOACTIVATE | win32con.SWP_NOZORDER
win32gui.SetWindowPos (self.hwnd, 0, 0, 0, right, maxBottom + 100, flags)
# Re-Center the Ok button
@@ -430,9 +433,9 @@
left = right / 2 - (r - l) / 2
win32gui.SetWindowPos (item, 0, left, maxBottom + 25, 0, 0, flags)
- return 1
+ centerWindow(hwnd)
+
-
# ---------------------------------------------------------------------------
# Create a resource definition for a label
# ---------------------------------------------------------------------------
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r7536 - trunk/gnue-forms/src/uidrivers/win32,
btami <=