1
- # ===========================================================================
2
- # This software is subject to the provisions of the Zope Public License,
3
- # Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
4
- # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
5
- # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
6
- # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
7
- # FOR A PARTICULAR PURPOSE.
8
- # ===========================================================================
9
-
10
1
import clr
11
2
import System .Windows .Forms as WinForms
12
3
from System .Threading import Thread , ThreadStart , ApartmentState
@@ -60,18 +51,16 @@ def InitializeComponent(self):
60
51
self .aboutMenu = WinForms .MenuItem ()
61
52
self .menuHelpAbout = WinForms .MenuItem ()
62
53
63
-
64
54
self .richTextBox = WinForms .RichTextBox ()
65
55
self .statusBarPanel1 = WinForms .StatusBarPanel ()
66
56
self .statusBar = WinForms .StatusBar ()
67
57
self .fontDialog = WinForms .FontDialog ()
68
58
self .statusBarPanel1 .BeginInit ()
69
59
70
-
71
60
# ===================================================================
72
61
# File Menu
73
62
# ===================================================================
74
-
63
+
75
64
self .menuFileNew .Text = "&New"
76
65
self .menuFileNew .Shortcut = WinForms .Shortcut .CtrlN
77
66
self .menuFileNew .ShowShortcut = False
@@ -83,7 +72,7 @@ def InitializeComponent(self):
83
72
self .menuFileOpen .ShowShortcut = False
84
73
self .menuFileOpen .Index = 1
85
74
self .menuFileOpen .Click += self .OnClickFileOpen
86
-
75
+
87
76
self .menuFileSave .Text = "&Save"
88
77
self .menuFileSave .Shortcut = WinForms .Shortcut .CtrlS
89
78
self .menuFileSave .ShowShortcut = False
@@ -112,7 +101,6 @@ def InitializeComponent(self):
112
101
113
102
self .fileMenu .MenuItems .AddRange (items )
114
103
115
-
116
104
# ===================================================================
117
105
# Edit menu
118
106
# ===================================================================
@@ -134,7 +122,7 @@ def InitializeComponent(self):
134
122
self .menuEditCut .Shortcut = WinForms .Shortcut .CtrlX
135
123
self .menuEditCut .Index = 3
136
124
self .menuEditCut .Click += self .OnClickEditCut
137
-
125
+
138
126
self .menuEditCopy .Text = "Copy"
139
127
self .menuEditCopy .Shortcut = WinForms .Shortcut .CtrlC
140
128
self .menuEditCopy .Index = 4
@@ -163,7 +151,6 @@ def InitializeComponent(self):
163
151
164
152
self .editMenu .MenuItems .AddRange (items )
165
153
166
-
167
154
# ===================================================================
168
155
# Format Menu
169
156
# ===================================================================
@@ -184,11 +171,10 @@ def InitializeComponent(self):
184
171
185
172
self .formatMenu .MenuItems .AddRange (items )
186
173
187
-
188
174
# ===================================================================
189
175
# About menu
190
176
# ===================================================================
191
-
177
+
192
178
self .menuHelpAbout .Text = "&About"
193
179
self .menuHelpAbout .Index = 0
194
180
self .menuHelpAbout .Click += self .OnClickHelpAbout
@@ -210,19 +196,16 @@ def InitializeComponent(self):
210
196
self .richTextBox .AcceptsTab = 1
211
197
self .richTextBox .Location = System .Drawing .Point (0 , 0 )
212
198
213
-
214
199
self .statusBar .BackColor = System .Drawing .SystemColors .Control
215
200
self .statusBar .Location = System .Drawing .Point (0 , 518 )
216
201
self .statusBar .Size = System .Drawing .Size (775 , 19 )
217
202
self .statusBar .TabIndex = 1
218
203
self .statusBar .ShowPanels = True
219
204
self .statusBar .Panels .Add (self .statusBarPanel1 )
220
205
221
-
222
206
items = (self .fileMenu , self .editMenu , self .formatMenu , self .aboutMenu )
223
207
self .mainMenu .MenuItems .AddRange (items )
224
208
225
-
226
209
self .openFileDialog .Filter = "Text documents|*.txt|RTF document|*.rtf"
227
210
self .openFileDialog .Title = "Open document"
228
211
@@ -231,7 +214,6 @@ def InitializeComponent(self):
231
214
self .saveFileDialog .Title = "Save document"
232
215
self .saveFileDialog .FileName = "Untitled"
233
216
234
-
235
217
self .AutoScaleBaseSize = System .Drawing .Size (5 , 13 )
236
218
self .ClientSize = System .Drawing .Size (775 , 537 )
237
219
self .Menu = self .mainMenu
@@ -244,7 +226,6 @@ def InitializeComponent(self):
244
226
def Dispose (self ):
245
227
self .components .Dispose ()
246
228
WinForms .Form .Dispose (self )
247
-
248
229
249
230
def OnClickFileNew (self , sender , args ):
250
231
self .SaveChangesDialog ()
@@ -265,7 +246,6 @@ def OnClickFileExit(self, sender, args):
265
246
self .SaveChangesDialog ()
266
247
self .Close ()
267
248
268
-
269
249
def OnClickEditUndo (self , sender , args ):
270
250
self .richTextBox .Undo ()
271
251
@@ -284,7 +264,6 @@ def OnClickEditPaste(self, sender, args):
284
264
def OnClickEditSelectAll (self , sender , args ):
285
265
self .richTextBox .SelectAll ()
286
266
287
-
288
267
def OnClickFormatWordWrap (self , sender , args ):
289
268
value = not self .word_wrap
290
269
self .richTextBox .WordWrap = value
@@ -298,7 +277,6 @@ def OnClickFormatFont(self, sender, args):
298
277
def OnClickHelpAbout (self , sender , args ):
299
278
AboutForm ().ShowDialog (self )
300
279
301
-
302
280
def NewDocument (self ):
303
281
self .doctype = 1
304
282
self .richTextBox .Rtf = ''
@@ -327,7 +305,7 @@ def OpenDocument(self):
327
305
stream .Close ()
328
306
329
307
filename = self .filename = filename .lower ()
330
-
308
+
331
309
if filename .endswith ('.rtf' ):
332
310
self .richTextBox .Rtf = data
333
311
self .doctype = 2
@@ -345,10 +323,10 @@ def SaveDocument(self):
345
323
if self .saveFileDialog .ShowDialog () != WinForms .DialogResult .OK :
346
324
return
347
325
filename = self .saveFileDialog .FileName
348
-
326
+
349
327
filename = self .filename = filename .lower ()
350
328
self .Text = 'Python Wordpad - %s' % filename
351
-
329
+
352
330
self .richTextBox .Select (0 , 0 )
353
331
354
332
stream = File .OpenWrite (filename )
@@ -366,17 +344,16 @@ def SaveDocument(self):
366
344
def SaveChangesDialog (self ):
367
345
if self .richTextBox .Modified :
368
346
if WinForms .MessageBox .Show (
369
- "Save changes?" , "Word Pad" ,
370
- WinForms .MessageBoxButtons .OK |
371
- WinForms .MessageBoxButtons .YesNo
372
- ) == WinForms .DialogResult .Yes :
347
+ "Save changes?" , "Word Pad" ,
348
+ WinForms .MessageBoxButtons .OK |
349
+ WinForms .MessageBoxButtons .YesNo
350
+ ) == WinForms .DialogResult .Yes :
373
351
self .SaveDocument ()
374
352
return 1
375
353
return 0
376
354
377
355
378
356
class AboutForm (WinForms .Form ):
379
-
380
357
def __init__ (self ):
381
358
self .InitializeComponent ()
382
359
@@ -406,7 +383,7 @@ def InitializeComponent(self):
406
383
self .ClientSize = System .Drawing .Size (300 , 150 )
407
384
408
385
self .Controls .AddRange ((self .label1 , self .btnClose ))
409
-
386
+
410
387
self .FormBorderStyle = WinForms .FormBorderStyle .FixedDialog
411
388
self .MaximizeBox = 0
412
389
self .MinimizeBox = 0
@@ -435,4 +412,3 @@ def main():
435
412
436
413
if __name__ == '__main__' :
437
414
main ()
438
-
0 commit comments