[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r7487 - trunk/gnue-forms/src/uidrivers/win32
From: |
johannes |
Subject: |
[gnue] r7487 - trunk/gnue-forms/src/uidrivers/win32 |
Date: |
Tue, 26 Apr 2005 10:27:05 -0500 (CDT) |
Author: johannes
Date: 2005-04-26 10:27:03 -0500 (Tue, 26 Apr 2005)
New Revision: 7487
Added:
trunk/gnue-forms/src/uidrivers/win32/dialogs.py
Log:
Added AboutBox based on pywin.mfc
Added: trunk/gnue-forms/src/uidrivers/win32/dialogs.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/win32/dialogs.py 2005-04-25 20:53:04 UTC
(rev 7486)
+++ trunk/gnue-forms/src/uidrivers/win32/dialogs.py 2005-04-26 15:27:03 UTC
(rev 7487)
@@ -0,0 +1,216 @@
+# GNU Enterprise Forms - Win32 UI Driver - UI specific dialogs
+#
+# Copyright 2001-2005 Free Software Foundation
+#
+# 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
+# License as published by the Free Software Foundation; either
+# version 2, or (at your option) any later version.
+#
+# GNU Enterprise is distributed in the hope that it will be
+# useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+# PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with program; see the file COPYING. If not,
+# write to the Free Software Foundation, Inc., 59 Temple Place
+# - Suite 330, Boston, MA 02111-1307, USA.
+#
+# $Id$
+
+import win32ui
+import win32con
+import win32gui
+import textwrap
+
+from pywin.mfc import dialog
+
+from gnue.forms import VERSION
+
+# =============================================================================
+# About Box
+# =============================================================================
+
+class AboutBox (dialog.Dialog):
+
+ def __init__ (self, name, appversion, formversion, author, description):
+ """
+ """
+
+ print "Creating new dialog for", name, appversion
+ self.__lastId = 1000
+ self.__boxes = []
+ self.__labels = []
+ self.__contents = []
+
+ # Window frame and title
+ title = u_("About %s") % name
+ template = [[title, (0, 0, 300, 186), win32con.DS_MODALFRAME | \
+ win32con.WS_POPUP | win32con.WS_VISIBLE | win32con.WS_CAPTION | \
+ win32con.WS_SYSMENU | win32con.DS_SETFONT, None, (8, 'MS Sans Serif')]]
+
+ # Upper box with info about GNUe Forms
+ template.append (self.__addBox (u_('GNUe Forms'), 8, 48))
+ template.append (self.__addLabel (self.__labels, u_('Version:'), 20))
+ template.append (self.__addLabel (self.__labels, u_('Driver:'), 34))
+
+ template.append (self.__addLabel (self.__contents, appversion, 20))
+ template.append (self.__addLabel (self.__contents, 'win32', 34))
+
+ # Lower box with info about the form currently displayed
+ template.append (self.__addBox (u_('Form Information'), 56, 98))
+ template.append (self.__addLabel (self.__labels, u_('Name:'), 74))
+ template.append (self.__addLabel (self.__labels, u_('Version:'), 88))
+ template.append (self.__addLabel (self.__labels, u_('Author:'), 102))
+ template.append (self.__addLabel (self.__labels, u_('Description:'), 116))
+
+ template.append (self.__addLabel (self.__contents, name, 74))
+ template.append (self.__addLabel (self.__contents, formversion, 88))
+ template.append (self.__addLabel (self.__contents, author, 102))
+ descr = '\n'.join (textwrap.wrap (description))
+ template.append (self.__addLabel (self.__contents, descr, 116))
+
+ # Ok Button
+ template.append (['button', "Ok", win32con.IDOK, (121, 162, 56, 15),
+ win32con.WS_CHILD | win32con.WS_VISIBLE | win32con.WS_TABSTOP | \
+ win32con.BS_PUSHBUTTON | win32con.BS_DEFPUSHBUTTON])
+
+ print "nearly done"
+ dialog.Dialog.__init__ (self, template)
+ print "constructor finished"
+
+
+ # ---------------------------------------------------------------------------
+ # Finalize the dialog's initialization
+ # ---------------------------------------------------------------------------
+
+ def OnInitDialog (self):
+ """
+ Recalculate sizes of all labels and boxes.
+ """
+
+ print "running on Init ..."
+ dialog.Dialog.OnInitDialog (self)
+
+ # Create a LOGFONT structure for the current font in use
+ hFont = win32gui.GetObject (self.SendMessage (win32con.WM_GETFONT, 0, 0))
+ newFont = win32ui.CreateFont ( \
+ {'name' : hFont.lfFaceName,
+ 'height' : hFont.lfHeight,
+ 'width' : hFont.lfWidth,
+ 'charset' : hFont.lfCharSet,
+ 'weight' : hFont.lfWeight,
+ 'italic' : hFont.lfItalic,
+ 'underline' : hFont.lfUnderline,
+ 'pitch and family': hFont.lfPitchAndFamily})
+
+ # Use this font in the device context of the dialog
+ dc = self.GetDC ()
+ of = dc.SelectObject (newFont)
+
+ # Stretch all labels in the left column and calculate the widest label
+ maxW = 0
+ flags = win32con.SWP_NOMOVE | win32con.SWP_NOOWNERZORDER | \
+ win32con.SWP_NOZORDER | win32con.SWP_SHOWWINDOW
+
+ for (ix, itemId) in enumerate (self.__labels):
+ item = self.GetDlgItem (itemId)
+ text = item.GetWindowText ()
+ (width, height) = dc.GetTextExtent (text)
+ maxW = max (maxW, width)
+
+ item.SetWindowPos (0, (0, 0, width, height), flags)
+
+
+ # Reposition and stretch all labels in the second column
+ right = 0
+ flags = win32con.SWP_NOOWNERZORDER | \
+ win32con.SWP_NOZORDER | win32con.SWP_SHOWWINDOW
+
+ for (ix, itemId) in enumerate (self.__contents):
+ item = self.GetDlgItem (itemId)
+ text = item.GetWindowText ()
+ if '\n' in text:
+ width = max ([dc.GetTextExtent (p) [0] for p in text.split ('\n')])
+ height = sum ([dc.GetTextExtent (p) [1] for p in text.split ('\n')])
+ else:
+ (width, height) = dc.GetTextExtent (text)
+
+ (left, top, w, h) = self.ScreenToClient (item.GetWindowRect ())
+ left = maxW + 40
+
+ item.SetWindowPos (0, (left, top, width, height), flags)
+ right = max ((left + width), right)
+
+ # Now stretch all boxes to fit the newly calculated width
+ right += 8
+ flags = win32con.SWP_NOMOVE | win32con.SWP_NOOWNERZORDER | \
+ win32con.SWP_NOZORDER | win32con.SWP_SHOWWINDOW
+ for itemId in self.__boxes:
+ item = self.GetDlgItem (itemId)
+ (left, top, r, bottom) = self.ScreenToClient (item.GetWindowRect ())
+ item.SetWindowPos (0, (0, 0, right, bottom - top), flags)
+
+ # Resize the dialog itself to the new width
+ right += 24
+
+ (l, top, r, bottom) = self.ScreenToClient (self.GetWindowRect ())
+ self.SetWindowPos (0, (0, 0, right, bottom - top), flags)
+
+ # Re-Center the Ok button
+ flags = win32con.SWP_NOOWNERZORDER | win32con.SWP_NOZORDER | \
+ win32con.SWP_SHOWWINDOW | win32con.SWP_NOSIZE
+ item = self.GetDlgItem (win32con.IDOK)
+ (l, t, r, b) = self.ScreenToClient (item.GetWindowRect ())
+ left = right / 2 - (r - l) / 2
+ item.SetWindowPos (0, (left, t, 0, 0), flags)
+
+ print "leaving on init"
+ return 1
+
+
+ # ---------------------------------------------------------------------------
+ # Create a resource definition for a label
+ # ---------------------------------------------------------------------------
+
+ def __addLabel (self, collection, label, row):
+
+ s = win32con.WS_CHILD | win32con.WS_VISIBLE
+ self.__lastId += 1
+ collection.append (self.__lastId)
+ return ['Static', label, self.__lastId, (16, row, 5, 14), s]
+
+
+ # ---------------------------------------------------------------------------
+ # Create a resource sequence for a labeled box
+ # ---------------------------------------------------------------------------
+
+ def __addBox (self, label, top, height):
+
+ self.__boxes.append (self.__nextId ())
+ style = win32con.WS_CHILD | win32con.WS_VISIBLE | win32con.WS_TABSTOP | \
+ win32con.BS_GROUPBOX
+ return ['button', label, self.__boxes [-1], (6, top, 282, height), style]
+
+
+ # ---------------------------------------------------------------------------
+ # Get another control id
+ # ---------------------------------------------------------------------------
+
+ def __nextId (self):
+
+ self.__lastId += 1
+ return self.__lastId
+
+
+if __name__ == '__main__':
+ desc = "This is a quite long description of the application.\n" \
+ "It also contains newlines as well as a lot of text. This text " \
+ "get's continued in the third line too.\n" \
+ "And here comes the rest. Here we go."
+ #desc = "Hey boyz, that thingy is quite complicated"
+ x = AboutBox ('Foobar', '1.0', '0.5.2', 'Frodo', desc)
+ x.DoModal ()
Property changes on: trunk/gnue-forms/src/uidrivers/win32/dialogs.py
___________________________________________________________________
Name: svn:keywords
+ Id
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r7487 - trunk/gnue-forms/src/uidrivers/win32,
johannes <=