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