andrej@1565: #!/usr/bin/env python andrej@1565: # -*- coding: utf-8 -*- andrej@1565: andrej@1628: # This file is part of Beremiz, a Integrated Development Environment for andrej@1628: # programming IEC 61131-3 automates supporting plcopen standard and CanFestival. andrej@1628: # This file is based on code written for Whyteboard project. andrej@1628: # andrej@1565: # Copyright (c) 2009, 2010 by Steven Sproat andrej@1628: # Copyright (c) 2016 by Andrey Skvortsov andrej@1565: # andrej@1628: # See COPYING file for copyrights details. andrej@1565: # andrej@1628: # This program is free software; you can redistribute it and/or andrej@1628: # modify it under the terms of the GNU General Public License andrej@1628: # as published by the Free Software Foundation; either version 2 andrej@1628: # of the License, or (at your option) any later version. andrej@1628: # andrej@1628: # This program is distributed in the hope that it will be useful, andrej@1628: # but WITHOUT ANY WARRANTY; without even the implied warranty of andrej@1628: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the andrej@1628: # GNU General Public License for more details. andrej@1628: # andrej@1628: # You should have received a copy of the GNU General Public License andrej@1628: # along with this program; if not, write to the Free Software andrej@1628: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. andrej@1628: # 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@1881: andrej@1881: from __future__ import absolute_import andrej@1565: import os andrej@1565: import wx andrej@1565: from wx.lib.agw.hyperlink import HyperLinkCtrl 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@1589: description.Wrap(400) 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@1612: close = wx.Button(self, id=wx.ID_CANCEL, 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: 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: 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@1736: 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)