ProjectController.py
changeset 2521 48ebcbe7f19b
parent 2492 7dd551ac2fa0
parent 2512 69cef4e37ef9
child 2594 f1e182818434
equal deleted inserted replaced
2493:0ad5e616d37f 2521:48ebcbe7f19b
    38 import tempfile
    38 import tempfile
    39 from threading import Timer
    39 from threading import Timer
    40 from datetime import datetime
    40 from datetime import datetime
    41 from weakref import WeakKeyDictionary
    41 from weakref import WeakKeyDictionary
    42 from functools import reduce
    42 from functools import reduce
       
    43 from distutils.dir_util import copy_tree
    43 from six.moves import xrange
    44 from six.moves import xrange
    44 
    45 
    45 import wx
    46 import wx
    46 
    47 
    47 import features
    48 import features
   553             dialog = wx.MessageDialog(
   554             dialog = wx.MessageDialog(
   554                 self.AppFrame, message, _("Error"), wx.OK | wx.ICON_ERROR)
   555                 self.AppFrame, message, _("Error"), wx.OK | wx.ICON_ERROR)
   555             dialog.ShowModal()
   556             dialog.ShowModal()
   556             return False
   557             return False
   557         else:
   558         else:
   558             plc_file = os.path.join(new_project_path, "plc.xml")
   559             if not CheckPathPerm(new_project_path):
   559             if os.path.isfile(plc_file):
   560                 dialog = wx.MessageDialog(
   560                 message = (
   561                     self.AppFrame,
   561                     _("Selected directory already contains another project. Overwrite? \n"))
   562                     _('No write permissions in selected directory! \n'),
       
   563                     _("Error"), wx.OK | wx.ICON_ERROR)
       
   564                 dialog.ShowModal()
       
   565                 return False
       
   566             if not os.path.isdir(new_project_path) or len(os.listdir(new_project_path)) > 0:
       
   567                 plc_file = os.path.join(new_project_path, "plc.xml")
       
   568                 if os.path.isfile(plc_file):
       
   569                     message = _("Selected directory already contains another project. Overwrite? \n")
       
   570                 else:
       
   571                     message = _("Selected directory isn't empty. Continue? \n")
   562                 dialog = wx.MessageDialog(
   572                 dialog = wx.MessageDialog(
   563                     self.AppFrame, message, _("Error"), wx.YES_NO | wx.ICON_ERROR)
   573                     self.AppFrame, message, _("Error"), wx.YES_NO | wx.ICON_ERROR)
   564                 answer = dialog.ShowModal()
   574                 answer = dialog.ShowModal()
   565                 return answer == wx.ID_YES
   575                 return answer == wx.ID_YES
   566         return True
   576         return True
   569         if self.CheckProjectPathPerm(False):
   579         if self.CheckProjectPathPerm(False):
   570             if from_project_path is not None:
   580             if from_project_path is not None:
   571                 old_projectfiles_path = self._getProjectFilesPath(
   581                 old_projectfiles_path = self._getProjectFilesPath(
   572                     from_project_path)
   582                     from_project_path)
   573                 if os.path.isdir(old_projectfiles_path):
   583                 if os.path.isdir(old_projectfiles_path):
   574                     shutil.copytree(old_projectfiles_path,
   584                     copy_tree(old_projectfiles_path,
   575                                     self._getProjectFilesPath(self.ProjectPath))
   585                               self._getProjectFilesPath(self.ProjectPath))
   576             self.SaveXMLFile(os.path.join(self.ProjectPath, 'plc.xml'))
   586             self.SaveXMLFile(os.path.join(self.ProjectPath, 'plc.xml'))
   577             result = self.CTNRequestSave(from_project_path)
   587             result = self.CTNRequestSave(from_project_path)
   578             if result:
   588             if result:
   579                 self.logger.write_error(result)
   589                 self.logger.write_error(result)
   580 
   590 
  1497                                     self.DebugValuesBuffers,
  1507                                     self.DebugValuesBuffers,
  1498                                     debug_vars):
  1508                                     debug_vars):
  1499                                 IECdebug_data = self.IECdebug_datas.get(
  1509                                 IECdebug_data = self.IECdebug_datas.get(
  1500                                     IECPath, None)
  1510                                     IECPath, None)
  1501                                 if IECdebug_data is not None and value is not None:
  1511                                 if IECdebug_data is not None and value is not None:
  1502                                     forced = IECdebug_data[2:4] == [
  1512                                     forced = (IECdebug_data[2] == "Forced") \
  1503                                         "Forced", value]
  1513                                         and (value is not None) and \
       
  1514                                         (IECdebug_data[3] is not None)
       
  1515 
  1504                                     if not IECdebug_data[4] and len(values_buffer) > 0:
  1516                                     if not IECdebug_data[4] and len(values_buffer) > 0:
  1505                                         values_buffer[-1] = (value, forced)
  1517                                         values_buffer[-1] = (value, forced)
  1506                                     else:
  1518                                     else:
  1507                                         values_buffer.append((value, forced))
  1519                                         values_buffer.append((value, forced))
  1508                             self.DebugTicks.append(debug_tick)
  1520                             self.DebugTicks.append(debug_tick)