File: drDynamicDrScriptDialog.py

package info (click to toggle)
drpython 161-3.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,588 kB
  • ctags: 1,470
  • sloc: python: 15,817; sh: 358; makefile: 43
file content (100 lines) | stat: -rw-r--r-- 3,772 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#	Programmer:	Daniel Pozmanter
#	E-mail:		drpython@bluebottle.com
#	Note:		You must reply to the verification e-mail to get through.
#
#	Copyright 2003-2005 Daniel Pozmanter
#
#	Distributed under the terms of the GPL (GNU Public License)
#
#    DrPython is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
	
#Dynamic DrScript Dialog

import os.path
import wx
import drScrolledMessageDialog
from drText import DrText

class drDynamicDrScriptDialog(wx.Dialog):

	def __init__(self, parent, text):
		wx.Dialog.__init__(self, parent, -1, ("Dynamic DrScript"), wx.DefaultPosition, wx.Size(600, 400), wx.DEFAULT_DIALOG_STYLE | wx.MAXIMIZE_BOX | wx.THICK_FRAME | wx.RESIZE_BORDER)
				
		self.theSizer = wx.BoxSizer(wx.VERTICAL)

		self.parent = parent
		
		self.txtScript = DrText(self, -1, self.parent, 1)
		self.txtScript.SetText(text)
		self.txtScript.SetupPrefsDocument()
		self.theSizer.Add(self.txtScript, 9, wx.EXPAND)
		
		self.commandSizer = wx.BoxSizer(wx.HORIZONTAL)
				
		self.btnClose = wx.Button(self, 101, "&Close")
		self.btnOk = wx.Button(self, 102, "&Ok")
		self.theSizer.Add(wx.StaticText(self, -1, ""), 0, wx.ALIGN_CENTER | wx.SHAPED)
		self.commandSizer.Add(self.btnClose, 0,  wx.SHAPED | wx.ALIGN_CENTER)
		self.commandSizer.Add(wx.StaticText(self, -1, "   "), 0, wx.ALIGN_CENTER | wx.SHAPED)
		self.commandSizer.Add(self.btnOk, 0,  wx.SHAPED | wx.ALIGN_CENTER)
		self.theSizer.Add(self.commandSizer, 0, wx.SHAPED | wx.ALIGN_CENTER)
		self.btnOk.SetDefault()

		self.SetAutoLayout(True)
		self.SetSizer(self.theSizer)
		
		self.Bind(wx.EVT_CLOSE, self.OnCloseW)
		self.Bind(wx.EVT_BUTTON,  self.OnbtnClose, id=101)
		self.Bind(wx.EVT_BUTTON,  self.OnbtnOk, id=102)		

		self.parent.LoadDialogSizeAndPosition(self, 'dynamicdrscriptdialog.sizeandposition.dat')

	def OnCloseW(self, event):
		self.parent.SaveDialogSizeAndPosition(self, 'dynamicdrscriptdialog.sizeandposition.dat')
		if event is not None:
			event.Skip()
			
	def OnbtnClose(self, event):
		self.Close(1)
		
	def OnbtnOk(self, event):
		value = self.txtScript.GetText()
		if (value.find("DrFilename") > -1):
			value = value.replace("DrFilename", "self.parent.txtDocument.filename")
		if (value.find("DrScript") > -1):
			value = value.replace("DrScript", "self.parent.DrScript")
		if (value.find("DrDocument") > -1):
			value = value.replace("DrDocument", "self.parent.txtDocument")
		if (value.find("DrPrompt") > -1):
			value = value.replace("DrPrompt", "self.parent.txtPrompt")
		if (value.find("DrFrame") > -1):
			value = value.replace("DrFrame", "self.parent")
			
		try:
			#Bug-Report/Fix (Submitted, Edited) Franz Steinhausier
			value = value.replace('\r', '\n')
			code = compile((value + '\n'), "Dynamic DrScript", 'exec')
		except:
			drScrolledMessageDialog.ShowMessage(self.parent, ("Error compiling dynamic script."), "Error", wx.DefaultPosition, wx.Size(550,300)) 
			return
		
		try:
			exec(code)
		except:
			drScrolledMessageDialog.ShowMessage(self.parent, ("Error running dynamic script."), "Error", wx.DefaultPosition, wx.Size(550,300))
			return
			
	def GetText(self):
		return self.txtScript.GetText()