Menu

[r163]: / plugins / myProject.py  Maximize  Restore  History

Download this file

171 lines (154 with data), 6.6 kB

  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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# Programmer: Antonio Barbosa
# E-mail: ab@jn.pt
# Note: Initial Release 22 Fev 2006
#
#Plugin
#myProject
import wx
import drScrolledMessageDialog
from drSourceBrowser import drSourceBrowserPanel
import drPrefsFile
import os.path
def OnAbout(DrFrame):
Version = "0.0.2"
NameAndVersion = "Simple Project: " + Version + "\n"
AboutString = NameAndVersion + "By Antonio Barbosa"
drScrolledMessageDialog.ShowMessage(DrFrame, AboutString, "About")
def OnHelp(DrFrame):
HelpString = """myProject
History:
0.0.1 22 Fev 2006
0.0.2 10 Fev 2007
"""
drScrolledMessageDialog.ShowMessage(DrFrame, HelpString, "Help")
def OnPreferences(DrFrame):
DrFrame.ShowMessage("Nothing to configure ... ;)")
def Plugin(DrFrame):
def myProject (event):
if os.path.exists(myprefsfile):
f = open(myprefsfile, 'r')
s = f.readline()
lastproject = s.rstrip()
lastproject = s.split('/')[-1].split('.')[0]
f.close()
else:
lastproject=None
ID_SAVE = DrFrame.GetNewId() //wx.NewId()
ID_LOAD = DrFrame.GetNewId() //wx.NewId()
ID_LAST = DrFrame.GetNewId() //wx.NewId()
menu = wx.Menu()
menu.Append(ID_SAVE, "Save Project")
DrFrame.Bind(wx.EVT_MENU, OnSaveProject, id=ID_SAVE)
menu.Append(ID_LOAD, "Load Project")
DrFrame.Bind(wx.EVT_MENU, OnLoadProject, id=ID_LOAD)
if lastproject is not None:
menu.Append(ID_LAST, "Load %s" %lastproject)
DrFrame.Bind(wx.EVT_MENU, LoadLast, id=ID_LAST)
(x,y) = DrFrame.ScreenToClient(wx.GetMousePosition())
DrFrame.PopupMenu(menu, (x,y+40))
menu.Destroy()
def LoadLast(event):
OnLoadProject(None,True)
def OnLoadProject(event,default=False):
try:
projectfilename=''
if default==False:
dlg = wx.FileDialog(DrFrame, "Load Project", "", "", DrFrame.projectwildcard, wx.OPEN|wx.HIDE_READONLY)
if DrFrame.ddirectory:
try:
d = DrFrame.ddirectory
dlg.SetDirectory(d)
except:
DrFrame.ShowMessage(("Error Setting Default Directory To: " + d), "DrPython Error")
if dlg.ShowModal() == wx.ID_OK:
projectfilename = dlg.GetPath().replace("\\", '/')
dlg.Destroy()
else:
f = open(myprefsfile, 'r')
s = f.readline()
projectfilename = s.rstrip()
f.close()
if os.path.exists(projectfilename)==False:
return
DrFrame.OnCloseAllDocuments(None)
f = file(projectfilename, 'r')
text = f.read()
f.close()
filenames = drPrefsFile.ExtractPreferenceFromText(text, "Files").rstrip().split('\n')
#check for existing files
if filenames and filenames[0] != '':
fnames = []
for i in range (len(filenames)):
if os.path.exists(filenames[i]):
fnames.append (filenames[i])
else:
ActiveDocument -= 1
DrFrame.ShowMessage("File does not exist: " + filenames[i], "Projects")
filenames = fnames
#Load the Files
l = len(filenames)
if l > 0 and len(filenames[0]) > 0:
old = DrFrame.txtDocument.filename
x = 1
if l > 1:
filename = filenames[0].replace("\\", "/")
DrFrame.OpenFile(filename, len(old) > 0)
while x < l:
filename = filenames[x].replace("\\", "/")
DrFrame.OpenFile(filename, True)
x = x + 1
if l <= 1:
filename = filenames[0].replace("\\", "/")
if old or DrFrame.txtDocument.GetModify():
DrFrame.OpenFile(filename, True)
else:
DrFrame.OpenFile(filename, False)
else:
DrFrame.ShowMessage("No File in Project: " + projectfilename, "Projects")
ActiveDocument = 0
DrFrame.documentnotebook.SetSelection (ActiveDocument)
DrFrame.documentnotebook.SetTab()
DrFrame.txtDocument.SetFocus()
DrFrame.SetStatusText(projectfilename, 2)
# Save Prefs
f = open(myprefsfile, 'w')
f.write(projectfilename + '\n')
f.close()
except :
DrFrame.ShowMessage("Error Reading Project" , "Read Project Error")
def OnSaveProject(event):
dlg = wx.FileDialog(DrFrame, "Save Project As", "", "", DrFrame.projectwildcard, wx.SAVE|wx.OVERWRITE_PROMPT)
if DrFrame.ddirectory:
try:
d = DrFrame.ddirectory
dlg.SetDirectory(d)
except:
DrFrame.ShowMessage(("Error Setting Default Directory To: " + d), "DrPython Error")
if dlg.ShowModal() == wx.ID_OK:
projectfilename = dlg.GetPath().replace("\\", "/")
try:
f = file(projectfilename, 'w')
f.write("<Files>")
x = 0
for document in DrFrame.txtDocumentArray:
if document.filename:
f.write(document.filename + '\n')
f.write("</Files>\n")
f.close()
DrFrame.SetStatusText(projectfilename, 2)
# Save Prefs
f = open(myprefsfile, 'w')
f.write(projectfilename + '\n')
f.close()
except:
DrFrame.ShowMessage(("Error Saving: " + projectfilename), "DrPython Error")
dlg.Destroy()
#------------------------------------------------------------------------------------
myprefsfile = DrFrame.pluginsdatdirectory + "/myproject.log"
DrFrame.projectwildcard = "DrPython Project File (*.prj)|*.prj|All Files (*)|*"
DrFrame.LoadPluginShortcuts('myProject')
ID_MYPROJECT = DrFrame.GetNewId()
DrFrame.programmenu.AppendSeparator()
DrFrame.programmenu.Append(ID_MYPROJECT, "MyProject", " MyProject")
DrFrame.Bind(wx.EVT_MENU, myProject, id=ID_MYPROJECT)
DrFrame.AddPluginFunction("myProject", "myProject", myProject)