Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Components.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def Rename(filename:str, new_name:str)->bool:
Please correct this aspect by extracting the archive.\n")%(old_name)
wx.MessageBox(info, _("Error"), wx.OK|wx.ICON_ERROR)
return False

class CMDComponent(GenericComponent):
"""
"""
Expand Down
1 change: 1 addition & 0 deletions Container.py
Original file line number Diff line number Diff line change
Expand Up @@ -3467,6 +3467,7 @@ def OnExport(self, event):

if path:
try:

### Block is Savable
self.SaveFile(path)

Expand Down
Binary file removed Domain/M1.amd
Binary file not shown.
74 changes: 60 additions & 14 deletions LibraryTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import subprocess
import importlib
import tempfile
import shutil

import Container
import Menu
Expand All @@ -47,6 +48,23 @@
#
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##

###
def Rename(filename, new_label):
""" Do the rename of the filename with new_label.
"""

### if pure python file
if filename.endswith('.py'):
cls = PyComponent
### if .amd or .cmd file
elif zipfile.is_zipfile(filename):
cls = GenericComponent
else:
cls = None

### if cls (.py, .cmd or .amd) and Rename is ok, we updateAll lib
return cls and cls.Rename(filename, new_label)

## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
#
# CLASS DEFIINTION
Expand Down Expand Up @@ -520,7 +538,8 @@ def GetModelList(self, dName):
py_file_list = []

# list of amd and cmd files
devsimpy_file_list = [f for f in os.listdir(dName) if os.path.isfile(os.path.join(dName, f)) and (f[:2] != '__') and (f.endswith(LibraryTree.EXT_LIB_FILE))]

devsimpy_file_list = [f for f in os.listdir(dName) if os.path.isfile(os.path.join(dName, f)) and (f[:2] != '__') and (f.endswith(LibraryTree.EXT_LIB_FILE))] if os.path.exists(dName) else []

return py_file_list + devsimpy_file_list

Expand Down Expand Up @@ -1033,6 +1052,42 @@ def OnDirRename(self, evt):
self.SetItemText(item, new_label)
self.UpdateAll()

###
def OnItemExport(self, evt):
""" Export action has been invoked.
"""

item = self.GetSelection()
filename = self.GetPyData(item)
old_name = os.path.basename(filename)
old_dir_name = os.path.dirname(filename)
old_label, ext= old_name.split('.')

new_name = None

wcd = _('%s Files (*.%s)|*.%s|All files (*)|*')%(ext.upper(), ext, ext)
save_dlg = wx.FileDialog(self,
message = _('Export file as...'),
defaultDir = old_dir_name,
defaultFile = old_name,
wildcard = wcd,
style = wx.SAVE | wx.OVERWRITE_PROMPT)

if save_dlg.ShowModal() == wx.ID_OK:
new_path = os.path.normpath(save_dlg.GetPath())
new_name = os.path.basename(new_path)

save_dlg.Destroy()

if new_name:
### if the new_name and old_name are different or the location is differente.
### we need to rename the file and all of its content !
if old_name != new_name or new_path != old_dir_name:
if shutil.copyfile(filename, new_path) and Rename(new_path, new_name.split('.')[0]):
self.UpdateAll()
else:
sys.stdout.write(_('Export failed!'))

###
def OnItemRename(self, evt):
""" Rename action has been invoked.
Expand All @@ -1056,21 +1111,12 @@ def OnItemRename(self, evt):

### path of file
filename = self.GetItemPyData(item)

### if pure python file
if filename.endswith('.py'):
cls = PyComponent
### if .amd or .cmd file
elif zipfile.is_zipfile(filename):
cls = GenericComponent

### Rename the filename with new_label
if Rename(filename, new_label):
self.UpdateAll()
else:
cls = None

### if cls (.py, .cmd or .amd) and Rename is ok, we updateAll lib
if cls and not cls.Rename(filename, new_label):
sys.stdout.write(_('Rename failed!'))
else:
self.UpdateAll()

###
def OnItemDocumentation(self, evt):
Expand Down
5 changes: 5 additions & 0 deletions Menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
ID_IMPORT_LIB = wx.NewIdRef()
ID_EDIT_LIB = wx.NewIdRef()
ID_RENAME_LIB = wx.NewIdRef()
ID_EXPORT_LIB = wx.NewIdRef()
ID_RENAME_DIR_LIB = wx.NewIdRef()
ID_REFRESH_LIB = wx.NewIdRef()
ID_MCC_LIB = wx.NewIdRef()
Expand Down Expand Up @@ -779,16 +780,19 @@ def __init__(self, parent):

edit = wx.MenuItem(self, ID_EDIT_LIB, _('Edit'), _('Edit selected module'))
rename = wx.MenuItem(self, ID_RENAME_LIB, _('Rename'), _('Rename selected module'))
export = wx.MenuItem(self, ID_EXPORT_LIB, _('Export'), _('Rename selected module'))
doc = wx.MenuItem(self, wx.NewIdRef(), _('Documentation'), _('Documentation of selected library'))
update = wx.MenuItem(self, ID_UPDATE_LIB, _('Update'), _('Update selected module'))

edit.SetBitmap(wx.Bitmap(os.path.join(ICON_PATH_16_16,'edit.png')))
rename.SetBitmap(wx.Bitmap(os.path.join(ICON_PATH_16_16,'rename.png')))
export.SetBitmap(wx.Bitmap(os.path.join(ICON_PATH_16_16,'export.png')))
doc.SetBitmap(wx.Bitmap(os.path.join(ICON_PATH_16_16,'doc.png')))
update.SetBitmap(wx.Bitmap(os.path.join(ICON_PATH_16_16,'db_refresh2.png')))

AppendItem(edit)
AppendItem(rename)
AppendItem(export)
AppendItem(doc)
AppendItem(update)

Expand All @@ -797,6 +801,7 @@ def __init__(self, parent):

self.Bind(wx.EVT_MENU, parent.OnItemEdit, id = ID_EDIT_LIB) # put before the popUpMenu
self.Bind(wx.EVT_MENU, parent.OnItemRename, id = ID_RENAME_LIB) # put before the popUpMenu
self.Bind(wx.EVT_MENU, parent.OnItemExport, id = ID_EXPORT_LIB) # put before the popUpMenu
self.Bind(wx.EVT_MENU, parent.OnItemDocumentation, id = doc.GetId()) # put before the popUpMenu
self.Bind(wx.EVT_MENU, parent.OnItemRefresh, id = ID_UPDATE_LIB) # put before the popUpMenu

Expand Down
8 changes: 3 additions & 5 deletions Mixins/Savable.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,15 @@ def Save(self, obj_dumped, fileName = None)->bool:
zf.Update(replace_files = [fn, python_path, image_path])
else:
zf.Create(add_files = [fn, python_path, image_path])

os.remove(fn)

## abs path of the directory that contains the file to export (str() to avoid unicode)
newExportPath = str(os.path.dirname(fileName))

mainW = getTopLevelWindow()
### if export on local directory, we insert the path in the config file

### if export on local directory, we insert the path in the config file
if os.path.basename(DOMAIN_PATH) not in newExportPath.split(os.sep):
### update of .devsimpy config file
mainW.exportPathsList = eval(mainW.cfg.Read("exportPathsList"))
Expand Down Expand Up @@ -303,9 +304,6 @@ def Load(self, obj_loaded, fileName = None):
j = 6 if fileName.endswith(DumpZipFile.ext[-1]) else 4
L.insert(j, 'middle')

else:
print(L,obj_loaded.dump_attributes)

try:
### assign dumped attributs
for i, attr in enumerate(obj_loaded.dump_attributes):
Expand Down
Loading