Exemplo n.º 1
0
 def importcpfgproject(self, fname=None):
     if fname is None:
         initialname = os.path.dirname(self.currentSimulation(
         ).fname) if self.currentSimulation().fname else '.'
         fname = QFileDialog.getExistingDirectory(self,
                                                  "Open  Cpfg Project",
                                                  initialname)
         if not fname: return
         fname = str(fname)
     elif not os.path.exists(fname):
         QMessageBox.warning(self, "Inexisting file",
                             "File '" + fname + "' does not exist anymore.",
                             QMessageBox.Ok)
         fname = None
     if fname:
         ind = self.getSimuIndex(fname)
         if not ind is None:
             self.simulations[ind].makeCurrent()
         else:
             self.acquireCR()
             try:
                 self.currentSimulation().saveState()
                 self.createNewLsystem()
                 self.currentSimulation().importcpfgproject(fname)
                 self.currentSimulation().restoreState()
                 self.statusBar().showMessage("Load file '" + fname + "'",
                                              2000)
                 if len(self.simulations
                        ) == 2 and self.simulations[0].isDefault():
                     self.closeDocument(0)
             except:
                 self.graberror()
             self.releaseCR()
Exemplo n.º 2
0
 def openfile(self, fname=None):
     if fname is None:
         initialname = os.path.dirname(self.currentSimulation(
         ).fname) if self.currentSimulation().fname else '.'
         fname = QFileDialog.getOpenFileName(
             self, "Open  L-Py file", initialname,
             "L-Py Files (*.lpy);;All Files (*.*)")
         if not fname: return
         fname = fname[0]
         self.appendInHistory(fname)
     else:
         if not os.path.exists(fname):
             self.removeInHistory(fname)
             QMessageBox.warning(
                 self, "Inexisting file",
                 "File '" + fname + "' does not exist anymore.",
                 QMessageBox.Ok)
             fname = None
         else:
             self.appendInHistory(fname)
     if fname:
         ind = self.getSimuIndex(fname)
         if not ind is None:
             self.simulations[ind].makeCurrent()
         else:
             self.acquireCR()
             self.showfilecontent(fname)
             self.releaseCR()
Exemplo n.º 3
0
    def monitorfile(self):
        if not hasattr(self, 'monitoring'):
            self.monitoring = True
            if not self.fname is None:
                if not os.path.exists(self.fname):
                    answer = QMessageBox.warning(
                        self.lpywidget, "Removed file",
                        "File '" + os.path.basename(self.fname) +
                        "' do not exists anymore. Do you want to keep it in editor ?",
                        QMessageBox.Yes, QMessageBox.No)
                    if answer == QMessageBox.No:
                        self.lpywidget.closeDocument(self.index)
                elif os.stat(self.fname).st_mtime > self.mtime:
                    answer = QMessageBox.warning(
                        self.lpywidget, "File has changed",
                        "File '" + os.path.basename(self.fname) +
                        "' has changed on disk. Do you want to reload it ?",
                        QMessageBox.Yes, QMessageBox.No)
                    if answer == QMessageBox.Yes:
                        self.reload()
                    else:
                        self.mtime = os.stat(self.fname).st_mtime + 1
                self.updateSvnStatus()

            del self.monitoring
Exemplo n.º 4
0
 def edittexture(self, i, initialfile=None):
     fname, ffilter = QFileDialog.getOpenFileName(
         self, "Texture Selection",
         self.lastTextureDir if initialfile is None else initialfile,
         "All files (*.*)")
     if len(fname) == 0: return
     self.lastTextureDir = os.path.dirname(str(fname))
     format = QImageReader.imageFormat(fname)
     if len(format) == 0:
         QMessageBox.warning(self, "Format error!",
                             "Format not supported !")
         self.edittexture(i, initialfile)
     else:
         self.setMaterial(i, ImageTexture(str(fname)))
         self.valueChanged.emit()
Exemplo n.º 5
0
 def importcpfgfile(self, fname=None):
     if fname is None:
         initialname = os.path.dirname(self.currentSimulation(
         ).fname) if self.currentSimulation().fname else '.'
         fname = QFileDialog.getOpenFileName(
             self, "Open  Cpfg File", initialname,
             "Cpfg Files (*.l);;All Files (*.*)")
         if not fname: return
         fname = str(fname[0])
     elif not os.path.exists(fname):
         QMessageBox.warning(self, "Inexisting file",
                             "File '" + fname + "' does not exist anymore.",
                             QMessageBox.Ok)
         fname = None
     if fname:
         self.importcpfgproject(fname)
Exemplo n.º 6
0
 def recoverPreviousFiles(self):
     from . import lpytmpfile as tf
     import os
     torecover = tf.getPreviousTmpLpyFiles()
     nbrecoverfile = len(torecover)
     if nbrecoverfile > 0:
         answer = QMessageBox.warning(
             self, "Recovery mode",
             "Backup files exist (%s). Do you want to recover ?" %
             nbrecoverfile, QMessageBox.Ok, QMessageBox.Discard)
         recover = (answer == QMessageBox.Ok)
         for f in torecover:
             if recover:
                 self.acquireCR()
                 try:
                     self.currentSimulation().saveState()
                     self.createNewLsystem()
                     self.currentSimulation().importtmpfile(f)
                     self.currentSimulation().restoreState()
                     self.statusBar().showMessage("Load file '" + f + "'",
                                                  2000)
                     if len(self.simulations
                            ) == 2 and self.simulations[0].isDefault():
                         self.closeDocument(0)
                 except:
                     self.graberror()
                 self.releaseCR()
             else:
                 os.remove(f)
Exemplo n.º 7
0
 def closeEvent(self, e):
     self.debugger.endDebug()
     self.viewer.stop()
     settings.saveState(self)
     prompt = False
     if not self.exitWithoutPrompt:
         for simu in self.simulations:
             prompt = (prompt or simu.isEdited())
             if prompt: break
         if not prompt:
             answer = QMessageBox.warning(self, "Quitting",
                                          "Are you sure ?", QMessageBox.Ok,
                                          QMessageBox.Cancel)
             if answer == QMessageBox.Cancel: e.ignore()
             else: e.accept()
         else:
             for simu in reversed(self.simulations):
                 if not simu.close():
                     e.ignore()
                     return
             e.accept()
     else:
         e.accept()
     if e.isAccepted():
         self.interpreter.locals.clear()
Exemplo n.º 8
0
 def open(self, fname):
     self.setFname(fname)
     assert self._fname == fname
     recovery = False
     readname = self.fname
     bckupname = self.getBackupName()
     if bckupname and os.path.exists(bckupname):
         answer = QMessageBox.warning(
             self.lpywidget, "Recovery mode",
             "A backup file '" + os.path.basename(bckupname) +
             "' exists. Do you want to recover ?", QMessageBox.Ok,
             QMessageBox.Discard)
         if answer == QMessageBox.Ok:
             recovery = True
             readname = bckupname
         elif answer == QMessageBox.Discard:
             os.remove(bckupname)
     os.chdir(os.path.dirname(self.fname))
     code = open(readname, 'rU').read()
     self.readonly = (not os.access(fname, os.W_OK))
     self.textedition = recovery
     self.setEdited(recovery)
     self.opencode(code)
     self.mtime = os.stat(self.fname).st_mtime
     self.updateReadOnly()
Exemplo n.º 9
0
 def fileDropEvent(self, pos, fname):
     from openalea.lpy.cpfgcompat.data_import import import_colormap, import_materialmap
     base, ext = os.path.splitext(fname)
     if ext == '.map' or ext == '.mat':
         if ext == '.map':
             newcolors = import_colormap(fname)
         else:
             newcolors = import_materialmap(fname)
         if len(newcolors) > 0:
             self.setMaterials(newcolors)
         else:
             QMessageBox.warning(
                 self, 'Data Error',
                 'Read no data from file "' + os.path.basename(fname) + '"')
     else:
         format = QImageReader.imageFormat(fname)
         if len(format) != 0:
             self.setMaterial(pos, ImageTexture(str(fname)))
             self.valueChanged.emit()
Exemplo n.º 10
0
 def svnUpdate(fname, parent = None):
     global svn_client_gui_parent
     client = get_svn_client()
     svn_client_gui_parent = parent
     import os
     fname = os.path.abspath(fname)
     local_rev = client.info2(fname)[0][1]['rev']
     try:
         rev = client.update(fname)
         if type(rev) is list: rev = rev[0]
         if local_rev.number == rev.number:
             if parent : QMessageBox.question(parent,'Update', 'Your version is already up-to-date : %s' % rev.number)
             return False
         else:
             if parent : QMessageBox.question(parent,'Update', 'Updated at revision %s' % rev.number)
             return True
     except pysvn.ClientError as ce:
         QMessageBox.warning(parent,'Update', ce.message)
         return False
Exemplo n.º 11
0
 def pastematerial(self):
     if self.clipboard is None or not self.lenSelection() in [
             1, len(self.clipboard)
     ]:
         QMessageBox.warning(
             self, 'Copy error',
             'Cannot copy materials ! Source and target are inconsistents')
     else:
         if self.lenSelection() == 1:
             sel = self.selectionbegin
             if self.cutaction == True:
                 sourceindices = [i[0] for i in self.clipboard]
                 if sel in sourceindices:
                     sel = min(sourceindices)
                     sourceindices.pop(sourceindices.index(sel))
                 for i in reversed(sourceindices):
                     self.delMaterial(i)
                     if i < sel:
                         sel -= 1
             print('Copy ', self.clipboard[0][0], 'to', sel)
             self.setMaterial(sel, self.clipboard[0][1].deepcopy())
             for i, color in reversed(self.clipboard[1:]):
                 self.insertMaterial(sel + 1, color.deepcopy())
             self.setSelection(sel, sel + len(self.clipboard) - 1)
         else:
             for color, pos in zip(self.clipboard, self.getSelection()):
                 self.setMaterial(pos, color[1].deepcopy())
             if self.cutaction == True:
                 iminus = 0
                 for pos, color in reversed(self.clipboard):
                     if not self.isInSelection(pos):
                         self.delMaterial(pos)
                         if pos < self.selectionbegin:
                             iminus -= 1
                 self.setSelection(self.selectionbegin - iminus,
                                   self.selectionend - iminus)
         self.cutaction = None
         self.clipboard = None
         self.valueChanged.emit()
     self.menuselection = None
     self.updateGL()
Exemplo n.º 12
0
 def close(self):
     if self._edited:
         if not self.isCurrent():
             self.makeCurrent()
         answer = QMessageBox.warning(self.lpywidget,self.getShortName(),"Do you want to save this document ?",
                                     QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel, QMessageBox.Save)
         if answer == QMessageBox.Save: self.save()
         elif answer == QMessageBox.Cancel: return False
         elif answer == QMessageBox.Discard:
             bckupname = self.getBackupName()
             if bckupname and os.path.exists(bckupname): os.remove(bckupname)
     return True
Exemplo n.º 13
0
 def svnIsUpToDate( fname, parent = None, silent = False):
     import os
     global svn_client_gui_parent
     client = get_svn_client()
     svn_client_gui_parent = parent
     import os
     fname = os.path.abspath(fname)
     local_entry_list = client.info2(fname)[0]
     current_entry = local_entry_list[1]
     current_rev = current_entry['rev']
     try:
         server_entry_list = client.info2(fname,revision = pysvn.Revision( pysvn.opt_revision_kind.head ))[0]
         server_entry = server_entry_list[1]
         server_rev = server_entry['last_changed_rev']
         if current_rev.number < server_rev.number:
             if not silent and parent:
                 changelogs = client.log(fname,revision_start = server_rev, revision_end = current_rev)
                 msg = os.path.basename(fname) +'\nA new version of the model exists : %s (current=%s).\n' % (server_rev.number,current_rev.number)
                 for log in changelogs:
                     msg += " - [%s][%s] '%s'\n" % (log.revision.number,log.author,log.message)
                 msg += "Status : "+str(svnFileTextStatus(fname))
                 QMessageBox.question(parent,'Up-to-date',msg )
             return False
         else:
             if not silent and parent:
                 msg = os.path.basename(fname) +'\nYour version is up-to-date.\nRevision: %s.\n' % (current_rev.number)
                 if server_entry['last_changed_date']:
                     import time
                     msg += 'Last changed date : %s\n' % time.asctime(time.gmtime(server_entry['last_changed_date']))
                 if server_entry['last_changed_author']:
                     msg += 'Last changed author : %s\n' % server_entry['last_changed_author']
                 msg += "Status : "+str(svnFileTextStatus(fname))
                 QMessageBox.question(parent,'Up-to-date', msg)                
             return True
     except pysvn.ClientError as ce:
         if not silent and parent: 
             QMessageBox.warning(parent,'Up-to-date', ce.message)
             return True
         else:
             raise ce
Exemplo n.º 14
0
 def error_match(self, pos_beg, pos_end, dest, rule, args, exc_info):
     self.print_src(pos_beg, pos_end)
     self.print_dest(dest)
     self.ruleView.setText(
         str(rule.lineno) + ': ' + rule.name() + ' --> raise exception!')
     self.addMarker(rule.lineno)
     self.updateArgs(dict(list(zip(rule.parameterNames(), args))))
     tb.print_exception(*exc_info)
     self.lpywidget.errorEvent(exc_info)
     errmsg = self.lpywidget.getErrorMessage(exc_info)
     res = QMessageBox.warning(self.lpywidget, "Exception", errmsg,
                               QMessageBox.Abort, QMessageBox.Ignore)
     self.delMarker()
     if res == QMessageBox.Ignore:
         return True
     else:
         return False
Exemplo n.º 15
0
 def errorMessage(self, msg):
     return QMessageBox.warning(self, "Exception", msg, QMessageBox.Ok)