Skip to content

Commit 5499ddc

Browse files
committed
qtvcp -copy panel: update to check for the qtvcp/screens or panels path
In most cases the screen or panel files should be in the config folder but in qtvcp/screens or qtvcp/panels copying qt_vismach files will also look for obj file folder and copy it too.
1 parent 82334f5 commit 5499ddc

File tree

1 file changed

+84
-18
lines changed

1 file changed

+84
-18
lines changed

share/qtvcp/panels/copy/copy_handler.py

Lines changed: 84 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,26 @@ def applyClicked(self):
6868
basename = self.w.lineEdit.text()
6969
if basename == '': basename = self.w.comboBox.currentText()
7070

71+
# VCP panel
7172
if self.w.radiobutton_vcp.isChecked():
7273
path = os.path.join(self.paths.PANELDIR, self.w.comboBox.currentText())
74+
75+
# vismach
7376
elif self.w.radiobutton_vismach.isChecked():
74-
self.copySingleFile(self.paths.VISMACHDIR, self.w.filemanager.textLine.text(),
77+
self.copyVismachFiles(self.paths.VISMACHDIR, self.w.filemanager.textLine.text(),
7578
basename, self.w.comboBox.currentText() )
79+
80+
# check for vismach object directory
81+
objname = self.w.comboBox.currentText().strip('.py')
82+
objname = objname + '_obj'
83+
objpath = os.path.join(self.paths.VISMACHDIR, objname)
84+
objbasename = basename.strip('.py') + '_obj'
85+
if os.path.exists(objpath):
86+
self.copyVismachFiles(self.paths.VISMACHDIR, self.w.filemanager.textLine.text(),
87+
objbasename, objname )
7688
return
89+
90+
# screen
7791
else:
7892
path = os.path.join(self.paths.SCREENDIR, self.w.comboBox.currentText())
7993

@@ -106,46 +120,77 @@ def list_vcp_files(self):
106120
def list_vismach_files(self):
107121
self.w.comboBox.clear()
108122
for i in sorted(self.paths.find_vismach_files()):
109-
self.w.comboBox.addItem(i)
123+
if '.py' in i:
124+
self.w.comboBox.addItem(i)
110125

111126
def makedirs(self, dest):
112127
if not os.path.exists(dest):
113128
os.makedirs(dest)
114129

115-
def copySingleFile(self, src, dest, baseName, fileName):
130+
def copyVismachFiles(self, src, dest, baseName, fileName):
116131
rtn = self.confirmDialog(dest, baseName)
117132
if not rtn: return
118133

119134
fromPath = os.path.join(src, fileName)
120135
toPath = os.path.join(dest, baseName)
121-
136+
print(fromPath, toPath)
122137
# make any needed directory
123138
if not os.path.exists(os.path.dirname(toPath)):
124139
self.makedirs(os.path.dirname(toPath))
125140

126141
if not os.path.exists(toPath):
127-
shutil.copyfile(fromPath, toPath)
142+
if os.path.isfile(fromPath):
143+
shutil.copy(fromPath, toPath)
144+
# probably vismach object folder
145+
elif os.path.isdir(fromPath):
146+
shutil.copytree(fromPath, toPath)
128147

129148
def copyFilesWithCheck(self, src, dest, baseName, srcDirName):
130-
# combine the user pick destination path and base name directory
131-
dest = os.path.join(dest, baseName)
132149

133-
# confirm the changes
134-
rtn = self.confirmDialog(dest,baseName)
150+
# make a copy of the user pick destination path
151+
ndest = os.path.join(dest)
152+
153+
# check for lack of standard folders in path
154+
folder = ''
155+
if self.w.radiobutton_vcp.isChecked():
156+
folder = 'panels'
157+
elif self.w.radiobutton_screen.isChecked():
158+
folder = 'screens'
159+
if not folder in dest:
160+
r = self.confirmPathDialog('qtvcp/' + folder)
161+
if r:
162+
if not 'qtvcp' in dest:
163+
dest = os.path.join(dest, 'qtvcp')
164+
if not folder in dest:
165+
dest = os.path.join(dest, folder)
166+
# overwrite with the new path
167+
ndest = dest
168+
if os.path.exists(dest):
169+
self.w.filemanager.updateDirectoryView(dest)
170+
171+
# confirm user wants to copy
172+
rtn = self.confirmDialog(ndest, baseName)
135173
if not rtn: return
136174

175+
# add in the basename
176+
ndest = os.path.join(ndest, baseName)
177+
137178
# make any needed initial directory
138-
if not os.path.exists(os.path.dirname(dest)):
139-
self.makedirs(os.path.dirname(dest))
179+
if not os.path.exists(os.path.dirname(ndest)):
180+
self.makedirs(os.path.dirname(ndest))
181+
182+
# update the file manager path
183+
if os.path.exists(dest):
184+
self.w.filemanager.updateDirectoryView(dest)
140185

141186
# walk the folder and copy everything
142187
for path, dirs, filenames in os.walk(src):
143188
if dirs == []:
144-
destDir = path.replace(src,dest)
189+
destDir = path.replace(src,ndest)
145190
self.makedirs(destDir)
146191
else:
147192
for directory in dirs:
148-
destDir = path.replace(src,dest)
193+
destDir = path.replace(src,ndest)
149194
self.makedirs(os.path.join(destDir, directory))
150195

151196
for sfile in filenames:
@@ -158,19 +203,40 @@ def copyFilesWithCheck(self, src, dest, baseName, srcDirName):
158203
dfile = sfile
159204

160205
srcFile = os.path.join(path, sfile)
161-
destFile = os.path.join(path.replace(src, dest), dfile)
206+
destFile = os.path.join(path.replace(src, ndest), dfile)
162207

163208
shutil.copy(srcFile, destFile)
164209

210+
# last confirm before copying -check for file overwriting
165211
def confirmDialog(self, srcPath, name):
166212
dest = os.path.join(srcPath, name)
167-
213+
info = 'Copy {} Code?'.format(name)
168214
if os.path.exists(dest):
169-
info = "Will Overwrite Existing Directory / Files!"
215+
title = "Confirm: Will Overwrite Existing Files!"
170216
else:
171-
info = None
217+
title = 'Please Confirm:'
218+
rtn = self.w.messageDialog_.showdialog(
219+
title,
220+
more_info=info,
221+
details=' To Folder:\n {}'.format(dest),
222+
display_type='YESNO',
223+
icon=QMessageBox.Information, pinname=None,
224+
focus_text=None,
225+
focus_color=None,
226+
play_alert=None,
227+
nblock=False,
228+
use_exec =True)
229+
if not rtn:
230+
return False
231+
return True
232+
233+
# confirm that qyvc/screens or panels is not needed in path
234+
def confirmPathDialog(self, srcPath):
235+
dest = os.path.join(srcPath)
236+
info = "Destination does not have {} folders in path. This is the usual way for qtvcp to find them. Do you wish to add the folders".format(srcPath)
237+
title = 'Add {} to Path?'.format(srcPath)
172238
rtn = self.w.messageDialog_.showdialog(
173-
'Copy {} Code?'.format(name),
239+
title,
174240
more_info=info,
175241
details=' To Folder:\n {}'.format(dest),
176242
display_type='YESNO',

0 commit comments

Comments
 (0)