dialogs/AboutDialog.py
changeset 1565 894f31f8ca64
child 1589 a5fd07db1db6
equal deleted inserted replaced
1564:8ffd0b52c2c7 1565:894f31f8ca64
       
     1 #!/usr/bin/env python
       
     2 # -*- coding: utf-8 -*-
       
     3 
       
     4 # Copyright (c) 2009, 2010 by Steven Sproat
       
     5 #
       
     6 # GNU General Public Licence (GPL)
       
     7 #
       
     8 # Whyteboard is free software; you can redistribute it and/or modify it under
       
     9 # the terms of the GNU General Public License as published by the Free Software
       
    10 # Foundation; either version 3 of the License, or (at your option) any later
       
    11 # version.
       
    12 # Whyteboard is distributed in the hope that it will be useful, but WITHOUT
       
    13 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
       
    14 # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
       
    15 # details.
       
    16 # You should have received a copy of the GNU General Public License along with
       
    17 # Whyteboard; if not, write to the Free Software Foundation, Inc., 59 Temple
       
    18 # Place, Suite 330, Boston, MA  02111-1307  USA
       
    19 
       
    20 
       
    21 """
       
    22 This module contains classes extended from wx.Dialog used by the GUI.
       
    23 """
       
    24 
       
    25 import os
       
    26 import sys
       
    27 import time
       
    28 import wx
       
    29 from wx.lib.agw.hyperlink import HyperLinkCtrl
       
    30 
       
    31 
       
    32 #----------------------------------------------------------------------
       
    33 
       
    34 class AboutDialog(wx.Dialog):
       
    35     """
       
    36     A replacement About Dialog for Windows, as it uses a generic frame that
       
    37     well...sucks.
       
    38     """
       
    39     def __init__(self, parent, info):
       
    40         title = _("About") + " " + info.Name
       
    41         wx.Dialog.__init__(self, parent, title=title)
       
    42         self.info = info
       
    43 
       
    44         if parent and parent.GetIcon():
       
    45             self.SetIcon(parent.GetIcon())
       
    46 
       
    47         image = None
       
    48         if self.info.Icon:
       
    49             bitmap = wx.BitmapFromIcon(self.info.Icon)
       
    50             image = wx.StaticBitmap(self, bitmap=bitmap)
       
    51 
       
    52         name = wx.StaticText(self, label="%s %s" % (info.Name, info.Version))
       
    53         description = wx.StaticText(self, label=info.Description)
       
    54         copyright = wx.StaticText(self, label=info.Copyright)
       
    55         url = HyperLinkCtrl(self, label=info.WebSite[0], URL=info.WebSite[1])
       
    56 
       
    57         font = name.GetClassDefaultAttributes().font
       
    58         font.SetWeight(wx.FONTWEIGHT_BOLD)
       
    59         font.SetPointSize(18)
       
    60         name.SetFont(font)
       
    61 
       
    62         credits = wx.Button(self, id=wx.ID_ABOUT, label=_("C&redits"))
       
    63         license = wx.Button(self, label=_("&License"))
       
    64         close = wx.Button(self, id=wx.ID_CLOSE, label=_("&Close"))
       
    65 
       
    66         btnSizer = wx.BoxSizer(wx.HORIZONTAL)
       
    67         btnSizer.Add(credits, flag=wx.CENTER | wx.LEFT | wx.RIGHT, border=5)
       
    68         btnSizer.Add(license, flag=wx.CENTER | wx.RIGHT, border=5)
       
    69         btnSizer.Add(close, flag=wx.CENTER | wx.RIGHT, border=5)
       
    70 
       
    71         sizer = wx.BoxSizer(wx.VERTICAL)
       
    72         if image:
       
    73             sizer.Add(image, flag=wx.CENTER | wx.TOP | wx.BOTTOM, border=5)
       
    74         sizer.Add(name, flag=wx.CENTER | wx.BOTTOM, border=10)
       
    75         sizer.Add(description, flag=wx.CENTER | wx.BOTTOM, border=10)
       
    76         sizer.Add(copyright, flag=wx.CENTER | wx.BOTTOM, border=10)
       
    77         sizer.Add(url, flag=wx.CENTER | wx.BOTTOM, border=15)
       
    78         sizer.Add(btnSizer, flag=wx.CENTER | wx.BOTTOM, border=5)
       
    79 
       
    80         container = wx.BoxSizer(wx.VERTICAL)
       
    81         container.Add(sizer, flag=wx.ALL, border=10)
       
    82         self.SetSizer(container)
       
    83         self.Layout()
       
    84         self.Fit()
       
    85         self.Centre()
       
    86         self.Show(True)
       
    87         self.SetEscapeId(close.GetId())
       
    88 
       
    89         credits.Bind(wx.EVT_BUTTON, self.on_credits)
       
    90         license.Bind(wx.EVT_BUTTON, self.on_license)
       
    91         close.Bind(wx.EVT_BUTTON, lambda evt: self.Destroy())
       
    92 
       
    93     def on_license(self, event):
       
    94         LicenseDialog(self, self.info)
       
    95 
       
    96     def on_credits(self, event):
       
    97         CreditsDialog(self, self.info)
       
    98 
       
    99 
       
   100 #----------------------------------------------------------------------
       
   101 
       
   102 class CreditsDialog(wx.Dialog):
       
   103     def __init__(self, parent, info):
       
   104         wx.Dialog.__init__(self, parent, title=_("Credits"), size=(475, 320),
       
   105                            style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
       
   106 
       
   107         if parent and parent.GetIcon():
       
   108             self.SetIcon(parent.GetIcon())
       
   109 
       
   110         self.SetMinSize((300, 200))
       
   111         notebook = wx.Notebook(self)
       
   112         close = wx.Button(self, id=wx.ID_CLOSE, label=_("&Close"))
       
   113         close.SetDefault()
       
   114 
       
   115         developer = wx.TextCtrl(notebook, style=wx.TE_READONLY | wx.TE_MULTILINE)
       
   116         translators = wx.TextCtrl(notebook, style=wx.TE_READONLY | wx.TE_MULTILINE)
       
   117 
       
   118         developer.SetValue(u'\n'.join(info.Developers))
       
   119         translators.SetValue(u'\n'.join(info.Translators))
       
   120 
       
   121         notebook.AddPage(developer, text=_("Written by"))
       
   122         notebook.AddPage(translators, text=_("Translated by"))
       
   123 
       
   124         btnSizer = wx.BoxSizer(wx.HORIZONTAL)
       
   125         btnSizer.Add(close)
       
   126 
       
   127         sizer = wx.BoxSizer(wx.VERTICAL)
       
   128         sizer.Add(notebook, 1, wx.EXPAND | wx.ALL, 10)
       
   129         sizer.Add(btnSizer, flag=wx.ALIGN_RIGHT | wx.RIGHT | wx.BOTTOM, border=10)
       
   130         self.SetSizer(sizer)
       
   131         self.Layout()
       
   132         self.Show()
       
   133         self.SetEscapeId(close.GetId())
       
   134 
       
   135         close.Bind(wx.EVT_BUTTON, lambda evt: self.Destroy())
       
   136 
       
   137 
       
   138 #----------------------------------------------------------------------
       
   139 
       
   140 class LicenseDialog(wx.Dialog):
       
   141     def __init__(self, parent, info):
       
   142         wx.Dialog.__init__(self, parent, title=_("License"), size=(500, 400),
       
   143                            style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
       
   144 
       
   145         if parent and parent.GetIcon():
       
   146             self.SetIcon(parent.GetIcon())
       
   147 
       
   148         self.SetMinSize((400, 300))
       
   149         close = wx.Button(self, id=wx.ID_CLOSE, label=_("&Close"))
       
   150 
       
   151         ctrl = wx.TextCtrl(self, style=wx.TE_READONLY | wx.TE_MULTILINE)
       
   152         ctrl.SetValue(info.License)
       
   153 
       
   154         btnSizer = wx.BoxSizer(wx.HORIZONTAL)
       
   155         btnSizer.Add(close)
       
   156 
       
   157         sizer = wx.BoxSizer(wx.VERTICAL)
       
   158         sizer.Add(ctrl, 1, wx.EXPAND | wx.ALL, 10)
       
   159         sizer.Add(btnSizer, flag=wx.ALIGN_RIGHT | wx.RIGHT | wx.BOTTOM, border=10)
       
   160         self.SetSizer(sizer)
       
   161         self.Layout()
       
   162         self.Show()
       
   163         self.SetEscapeId(close.GetId())
       
   164 
       
   165         close.Bind(wx.EVT_BUTTON, lambda evt: self.Destroy())
       
   166 
       
   167 #----------------------------------------------------------------------
       
   168 
       
   169 def ShowAboutDialog(parent, info):
       
   170     if os.name == "nt":
       
   171         AboutDialog(parent, info)
       
   172     else:
       
   173         wx.AboutBox(info)