//-///////////////////////////////////////////////////////////////////////
            //-///////////////////////////////////////////////////////////////////////

            public DirWatcher(FileChangeWatcher owner, string dir)
            {
                _fileNames = new HashSet <string>();

                _watcher = new FileSystemWatcher(dir);
                _watcher.NotifyFilter = NotifyFilters.LastWrite;
                _watcher.Changed     += this.HandleChanged;

                _owner = owner;
            }
Exemple #2
0
        //-///////////////////////////////////////////////////////////////////////
        //-///////////////////////////////////////////////////////////////////////

        private void StopScript()
        {
            if (_fileChangeWatcher != null)
            {
                _fileChangeWatcher.Changed -= this.HandleFileChangeWatcherChanged;

                _fileChangeWatcher.Dispose();
                _fileChangeWatcher = null;
            }

            _scriptEngine     = null;
            _objectOperations = null;
            _pydoodleModule   = null;
            _scriptScope      = null;
            _scriptSource     = null;
            _scriptException  = null;
            _scriptFileName   = null;
            _scriptState      = ScriptState.NoneLoaded;
        }
Exemple #3
0
        //-///////////////////////////////////////////////////////////////////////
        //-///////////////////////////////////////////////////////////////////////

        public MainForm(Main main)
        {
            InitializeComponent();

            _main = main;
            _main.RecentFileListChanged += this.HandleRebuildRecentFilesList;
            HandleRebuildRecentFilesList(null, null);

            _graphicsPanel = null;
            _textPanel     = null;
            _tweaksPanel   = null;

            PostLoadPanels();

            _fileChangeWatcher = null;

            StopScript();

            if (_main.LastFile != null)
            {
                RunScript(_main.LastFile, true, false);
            }
        }
Exemple #4
0
        //-///////////////////////////////////////////////////////////////////////
        //-///////////////////////////////////////////////////////////////////////

        private void RunScript(string fileName, bool loadLayoutForScript, bool mayKeepValues)
        {
            List <SavedAttrValue> savedAttrValues = null;

            if (mayKeepValues)
            {
                if (_scriptFileName != null)
                {
                    if (Misc.AreFileNamesEqual(fileName, _scriptFileName))
                    {
                        savedAttrValues = _pydoodleModule.GetSavedAttrValues();
                    }
                }
            }

            SaveStateForScript();

            StopScript();

            //
            if (loadLayoutForScript)
            {
                LoadLayoutForScript(fileName);
            }

            LoadStateForScript(fileName);

            // Initialise basic script stuff.
            Dictionary <string, object> options = new Dictionary <string, object>();

            options["Debug"] = true;

            _scriptEngine = Python.CreateEngine(options);

            Stream       tmp       = new TextPanel.WriteStream(_textPanel);
            StreamWriter tmpWriter = new StreamWriter(tmp);

            _scriptEngine.Runtime.IO.SetOutput(tmp, tmpWriter);
            _scriptEngine.Runtime.IO.SetErrorOutput(tmp, tmpWriter);

            _objectOperations = _scriptEngine.CreateOperations();

            // Add pydoodle module.
            _pydoodleModule = new pydoodleModule(_scriptEngine, this, savedAttrValues);

            // Reset panels.
            _tweaksPanel.Reset();
            _textPanel.ClearText();

            // Fiddle with python module search paths. Replace "." with the path to the loaded script.
            string filePath = Misc.GetPathDirectoryName(fileName);

            if (filePath != null)
            {
                List <string> paths = new List <string>(_scriptEngine.GetSearchPaths());

                paths.Remove(".");
                paths.Insert(0, filePath);

                _scriptEngine.SetSearchPaths(paths);
            }

            //
            _main.OnRecentFileUsed(fileName);

            // go!
            _scriptFileName = fileName;
            _scriptScope    = _scriptEngine.CreateScope();
            _scriptSource   = _scriptEngine.CreateScriptSourceFromFile(_scriptFileName);
            _scriptState    = ScriptState.RunGlobal;

            TickPython(null);

            List <string> moduleFileNames = Misc.GetModuleFileNames(_scriptEngine);

            // If it's broken already, the module file names list might not
            // include the module that threw the exception. So, try to find that
            // from the exception. Also, always add the script file name.
            if (_scriptState == ScriptState.Borked)
            {
                foreach (DynamicStackFrame stackFrame in Misc.GetScriptExceptionDynamicStackFrames(_scriptException))
                {
                    moduleFileNames.Add(stackFrame.GetFileName());
                }

                moduleFileNames.Add(_scriptFileName);
            }

            // Watch for further changes.
            _fileChangeWatcher          = new FileChangeWatcher(moduleFileNames);
            _fileChangeWatcher.Changed += this.HandleFileChangeWatcherChanged;
        }