andrej@1565: #!/usr/bin/env python andrej@1565: # -*- coding: utf-8 -*- andrej@1565: andrej@1565: # Copyright (c) 2009, 2010 by Steven Sproat andrej@1565: # andrej@1565: # GNU General Public Licence (GPL) andrej@1565: # andrej@1565: # Whyteboard is free software; you can redistribute it and/or modify it under andrej@1565: # the terms of the GNU General Public License as published by the Free Software andrej@1565: # Foundation; either version 3 of the License, or (at your option) any later andrej@1565: # version. andrej@1565: # Whyteboard is distributed in the hope that it will be useful, but WITHOUT andrej@1565: # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS andrej@1565: # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more andrej@1565: # details. andrej@1565: # You should have received a copy of the GNU General Public License along with andrej@1565: # Whyteboard; if not, write to the Free Software Foundation, Inc., 59 Temple andrej@1565: # Place, Suite 330, Boston, MA 02111-1307 USA andrej@1565: andrej@1565: andrej@1565: """ andrej@1565: This module contains classes extended from wx.Dialog used by the GUI. andrej@1565: """ andrej@1565: andrej@1565: import os andrej@1565: import sys andrej@1565: import time andrej@1565: import wx andrej@1565: from wx.lib.agw.hyperlink import HyperLinkCtrl andrej@1565: andrej@1565: andrej@1565: #---------------------------------------------------------------------- andrej@1565: andrej@1565: class AboutDialog(wx.Dialog): andrej@1565: """ andrej@1565: A replacement About Dialog for Windows, as it uses a generic frame that andrej@1565: well...sucks. andrej@1565: """ andrej@1565: def __init__(self, parent, info): andrej@1565: title = _("About") + " " + info.Name andrej@1565: wx.Dialog.__init__(self, parent, title=title) andrej@1565: self.info = info andrej@1565: andrej@1565: if parent and parent.GetIcon(): andrej@1565: self.SetIcon(parent.GetIcon()) andrej@1565: andrej@1565: image = None andrej@1565: if self.info.Icon: andrej@1565: bitmap = wx.BitmapFromIcon(self.info.Icon) andrej@1565: image = wx.StaticBitmap(self, bitmap=bitmap) andrej@1565: andrej@1565: name = wx.StaticText(self, label="%s %s" % (info.Name, info.Version)) andrej@1565: description = wx.StaticText(self, label=info.Description) andrej@1565: copyright = wx.StaticText(self, label=info.Copyright) andrej@1565: url = HyperLinkCtrl(self, label=info.WebSite[0], URL=info.WebSite[1]) andrej@1565: andrej@1565: font = name.GetClassDefaultAttributes().font andrej@1565: font.SetWeight(wx.FONTWEIGHT_BOLD) andrej@1565: font.SetPointSize(18) andrej@1565: name.SetFont(font) andrej@1565: andrej@1565: credits = wx.Button(self, id=wx.ID_ABOUT, label=_("C&redits")) andrej@1565: license = wx.Button(self, label=_("&License")) andrej@1565: close = wx.Button(self, id=wx.ID_CLOSE, label=_("&Close")) andrej@1565: andrej@1565: btnSizer = wx.BoxSizer(wx.HORIZONTAL) andrej@1565: btnSizer.Add(credits, flag=wx.CENTER | wx.LEFT | wx.RIGHT, border=5) andrej@1565: btnSizer.Add(license, flag=wx.CENTER | wx.RIGHT, border=5) andrej@1565: btnSizer.Add(close, flag=wx.CENTER | wx.RIGHT, border=5) andrej@1565: andrej@1565: sizer = wx.BoxSizer(wx.VERTICAL) andrej@1565: if image: andrej@1565: sizer.Add(image, flag=wx.CENTER | wx.TOP | wx.BOTTOM, border=5) andrej@1565: sizer.Add(name, flag=wx.CENTER | wx.BOTTOM, border=10) andrej@1565: sizer.Add(description, flag=wx.CENTER | wx.BOTTOM, border=10) andrej@1565: sizer.Add(copyright, flag=wx.CENTER | wx.BOTTOM, border=10) andrej@1565: sizer.Add(url, flag=wx.CENTER | wx.BOTTOM, border=15) andrej@1565: sizer.Add(btnSizer, flag=wx.CENTER | wx.BOTTOM, border=5) andrej@1565: andrej@1565: container = wx.BoxSizer(wx.VERTICAL) andrej@1565: container.Add(sizer, flag=wx.ALL, border=10) andrej@1565: self.SetSizer(container) andrej@1565: self.Layout() andrej@1565: self.Fit() andrej@1565: self.Centre() andrej@1565: self.Show(True) andrej@1565: self.SetEscapeId(close.GetId()) andrej@1565: andrej@1565: credits.Bind(wx.EVT_BUTTON, self.on_credits) andrej@1565: license.Bind(wx.EVT_BUTTON, self.on_license) andrej@1565: close.Bind(wx.EVT_BUTTON, lambda evt: self.Destroy()) andrej@1565: andrej@1565: def on_license(self, event): andrej@1565: LicenseDialog(self, self.info) andrej@1565: andrej@1565: def on_credits(self, event): andrej@1565: CreditsDialog(self, self.info) andrej@1565: andrej@1565: andrej@1565: #---------------------------------------------------------------------- andrej@1565: andrej@1565: class CreditsDialog(wx.Dialog): andrej@1565: def __init__(self, parent, info): andrej@1565: wx.Dialog.__init__(self, parent, title=_("Credits"), size=(475, 320), andrej@1565: style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER) andrej@1565: andrej@1565: if parent and parent.GetIcon(): andrej@1565: self.SetIcon(parent.GetIcon()) andrej@1565: andrej@1565: self.SetMinSize((300, 200)) andrej@1565: notebook = wx.Notebook(self) andrej@1565: close = wx.Button(self, id=wx.ID_CLOSE, label=_("&Close")) andrej@1565: close.SetDefault() andrej@1565: andrej@1565: developer = wx.TextCtrl(notebook, style=wx.TE_READONLY | wx.TE_MULTILINE) andrej@1565: translators = wx.TextCtrl(notebook, style=wx.TE_READONLY | wx.TE_MULTILINE) andrej@1565: andrej@1565: developer.SetValue(u'\n'.join(info.Developers)) andrej@1565: translators.SetValue(u'\n'.join(info.Translators)) andrej@1565: andrej@1565: notebook.AddPage(developer, text=_("Written by")) andrej@1565: notebook.AddPage(translators, text=_("Translated by")) andrej@1565: andrej@1565: btnSizer = wx.BoxSizer(wx.HORIZONTAL) andrej@1565: btnSizer.Add(close) andrej@1565: andrej@1565: sizer = wx.BoxSizer(wx.VERTICAL) andrej@1565: sizer.Add(notebook, 1, wx.EXPAND | wx.ALL, 10) andrej@1565: sizer.Add(btnSizer, flag=wx.ALIGN_RIGHT | wx.RIGHT | wx.BOTTOM, border=10) andrej@1565: self.SetSizer(sizer) andrej@1565: self.Layout() andrej@1565: self.Show() andrej@1565: self.SetEscapeId(close.GetId()) andrej@1565: andrej@1565: close.Bind(wx.EVT_BUTTON, lambda evt: self.Destroy()) andrej@1565: andrej@1565: andrej@1565: #---------------------------------------------------------------------- andrej@1565: andrej@1565: class LicenseDialog(wx.Dialog): andrej@1565: def __init__(self, parent, info): andrej@1565: wx.Dialog.__init__(self, parent, title=_("License"), size=(500, 400), andrej@1565: style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER) andrej@1565: andrej@1565: if parent and parent.GetIcon(): andrej@1565: self.SetIcon(parent.GetIcon()) andrej@1565: andrej@1565: self.SetMinSize((400, 300)) andrej@1565: close = wx.Button(self, id=wx.ID_CLOSE, label=_("&Close")) andrej@1565: andrej@1565: ctrl = wx.TextCtrl(self, style=wx.TE_READONLY | wx.TE_MULTILINE) andrej@1565: ctrl.SetValue(info.License) andrej@1565: andrej@1565: btnSizer = wx.BoxSizer(wx.HORIZONTAL) andrej@1565: btnSizer.Add(close) andrej@1565: andrej@1565: sizer = wx.BoxSizer(wx.VERTICAL) andrej@1565: sizer.Add(ctrl, 1, wx.EXPAND | wx.ALL, 10) andrej@1565: sizer.Add(btnSizer, flag=wx.ALIGN_RIGHT | wx.RIGHT | wx.BOTTOM, border=10) andrej@1565: self.SetSizer(sizer) andrej@1565: self.Layout() andrej@1565: self.Show() andrej@1565: self.SetEscapeId(close.GetId()) andrej@1565: andrej@1565: close.Bind(wx.EVT_BUTTON, lambda evt: self.Destroy()) andrej@1565: andrej@1565: #---------------------------------------------------------------------- andrej@1565: andrej@1565: def ShowAboutDialog(parent, info): andrej@1565: if os.name == "nt": andrej@1565: AboutDialog(parent, info) andrej@1565: else: andrej@1565: wx.AboutBox(info)