예제 #1
0
파일: lpystudio.py 프로젝트: jvail/lpy
 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()
예제 #2
0
파일: lpystudio.py 프로젝트: jvail/lpy
 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()
예제 #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
예제 #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()
예제 #5
0
파일: lpystudio.py 프로젝트: jvail/lpy
 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()
예제 #6
0
파일: lpystudio.py 프로젝트: jvail/lpy
 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)
예제 #7
0
파일: lpystudio.py 프로젝트: jvail/lpy
 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)
예제 #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()
예제 #9
0
파일: svnmanip.py 프로젝트: jvail/lpy
 def svnFileCommit(fname, msg = None, parent = None):
     import os
     fname = os.path.abspath(fname)
     if not isSvnAddedFile(fname) and not svnIsUpToDate(fname, parent, True):
         QMessageBox.question(parent,'Update first', repr(os.path.basename(fname))+' is not up to date.\nUpdate first.')
         return
     if msg is None :
         if parent is None:
             msg = ''
         else:
             ok, msg = get_log(parent, 'SVN Commit - '+os.path.basename(fname))
             if not ok: return
     client = get_svn_client()
     cwd = os.getcwd()
     os.chdir(os.path.dirname(fname))
     res = client.checkin(fname,msg)
     os.chdir(cwd)
     return res
예제 #10
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()
예제 #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()
예제 #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
예제 #13
0
파일: lpystudio.py 프로젝트: jvail/lpy
 def check_lpy_update(self, silent=False):
     import openalea.lpy.__version__ as lv
     import os, time
     if not silent or (
         (self.svnLastDateChecked + 7 * 24 * 60 * 60) < time.time()):
         self.svnLastDateChecked = time.time()
         officialversion, offverstring = self.retrieve_official_lpy_version(
         )
         officialdevversion, offverdevstring = self.retrieve_official_lpy_version(
             'fredboudon')
         if get_version_majorminor(lv.__version_number__) < officialversion:
             QMessageBox.information(
                 self, "Lpy Update",
                 "Your version is " + lv.LPY_VERSION_STR +
                 ".\nA new release version of lpy seems available on github :"
                 + offverstring + "\n.")
         elif get_version_majorminor(
                 lv.__version_number__) < officialdevversion:
             QMessageBox.information(
                 self, "Lpy Update",
                 "Your version is " + lv.LPY_VERSION_STR +
                 ".\nA new develop version of lpy seems available on github :"
                 + offverdevstring + "\n.")
         elif not silent:
             QMessageBox.information(
                 self, "Lpy Update", "Your version is " +
                 lv.LPY_VERSION_STR + ".\nYou are up-to-date!")
         else:
             self.statusBar().showMessage("L-Py " + lv.LPY_VERSION_STR +
                                          " is up-to-date.")
예제 #14
0
파일: lpystudio.py 프로젝트: jvail/lpy
    def errorEvent(self, exc_info, errmsg, displayDialog):
        if self.withinterpreter:
            self.interpreterDock.show()

        t, v, trb = exc_info
        stacksummary = list(reversed(tb.extract_tb(trb)))
        print(len(stacksummary))
        for fid, frame in enumerate(stacksummary):
            print(frame.filename)
            if 'openalea/lpy' in frame.filename:
                stacksummary = stacksummary[:fid]
                break
        print(len(stacksummary))
        self.lastexception = v
        if t == SyntaxError:
            errorfile = v.filename
            lineno = v.lineno
        else:
            if len(stacksummary) > 0:
                st = stacksummary[0]
                errorfile = st.filename
                lineno = st.lineno
            else:
                errorfile = None
                lineno = None
        fnames = ['<string>', self.currentSimulation().getBaseName()]

        if errorfile in fnames:
            self.codeeditor.hightlightError(lineno)

        def showErrorOnFile():
            docid = self.findDocumentId(errorfile)
            if docid:
                self.showDocumentAt(errorfile, lineno)
            else:
                self.showfilecontent(errorfile)
            self.codeeditor.hightlightError(lineno)

        if displayDialog:
            dialog = QMessageBox(
                QMessageBox.Warning, "Exception",
                (os.path.basename(errorfile) + ':' if errorfile else '') +
                (str(lineno) + ':' if lineno else '') + errmsg, QMessageBox.Ok,
                self)
            if errorfile and (not errorfile in fnames):
                showbutton = dialog.addButton("Show file",
                                              QMessageBox.ApplyRole)
                showbutton.clicked.connect(showErrorOnFile)
            if len(stacksummary) > 0:
                dialog.setDetailedText(errmsg + '\n\n' +
                                       '\n'.join(tb.format_list(stacksummary)))
            dialog.exec_()
예제 #15
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
예제 #16
0
파일: svnmanip.py 프로젝트: jvail/lpy
 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
예제 #17
0
파일: svnmanip.py 프로젝트: jvail/lpy
 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
예제 #18
0
파일: svnmanip.py 프로젝트: jvail/lpy
 def ssl_server_trust_prompt(trust_dict ):
     if svn_client_gui_parent is None: return True, True, True
     msg = 'The authenticity of host "%s" can\' t be established.\nRSA key fingerprint is %s.\nValid from %s to %s.\nCertified by %s.\nAccept ?'
     msg = msg % (trust_dict['hostname'], trust_dict['finger_print'],trust_dict['valid_from'],trust_dict['valid_until'],trust_dict['issuer_dname'])
     ok = QMessageBox.question(svn_client_gui_parent,'RSA Authentification of '+trust_dict['realm'], msg, QMessageBox.Ok,QMessageBox.Cancel )
     return ok == QMessageBox.Ok, True, True
예제 #19
0
 def errorMessage(self, msg):
     return QMessageBox.warning(self, "Exception", msg, QMessageBox.Ok)