public PythonScriptForm(ScriptingAncestorComponent linkedComponent) { InitializeComponent(); _component = linkedComponent; if (_component != null) { m_texteditor = _component.CreateEditorControl(OnPythonHelp); this.splitContainer.Panel1.Controls.Add(m_texteditor); m_texteditor.Dock = DockStyle.Fill; m_texteditor.Text = _component.Code; m_previous_script = m_texteditor.Text; } versionLabel.Text = Assembly.GetExecutingAssembly().GetName().Version.ToString(); }
public PythonScriptForm(ScriptingAncestorComponent linkedComponent) { InitializeComponent(); this.KeyDown += ScriptForm_KeyDown; this.HelpRequested += rhinoscriptsyntaxHelp; _component = linkedComponent; if (_component != null) { _texteditor = _component.CreateEditorControl(OnPythonHelp); this.splitContainer.Panel1.Controls.Add(_texteditor); _texteditor.Dock = DockStyle.Fill; _texteditor.Text = _component.CodeInput; _hash.HashText(_texteditor.Text); } versionLabel.Text = Assembly.GetExecutingAssembly().GetName().Version.ToString(); }
public static bool FindApplyDocString(string code, ScriptingAncestorComponent component) { var reader = new StringReader(code); string line; for (; ; ) //proceeds to begin of docstrings, or leave method { line = reader.ReadLine(); if (line == null) return false; if (IsEmptyOrFullyCommentedOutLine(line)) continue; if (IsDocStringStart(line)) break; return false; } //strips the docstring start chars line = line.Substring(line.IndexOf(_docStringSeparator) + _docStringSeparator.Length); int firstLevelIndent = GetIndent(line); int secondLevelIndent = -1; string variable = "%description"; StringBuilder result = new StringBuilder(); KeywordType type = KeywordType.Description; do //consumes docstring lines and then leaves { int endSeparator = line.IndexOf(_docStringSeparator); if (endSeparator != -1) line = line.Substring(0, endSeparator); if (IsEmptyLine(line)) { if (endSeparator != -1) break; continue; } int newIndent = GetIndent(line); if (newIndent > firstLevelIndent) { if (secondLevelIndent == -1 || newIndent <= secondLevelIndent) //second level { //we could check for faulty indentation here secondLevelIndent = newIndent; string keyword; if (IsNewKeywordDeclared(line, out keyword)) { var nextType = type; string nextVariable = null; bool match = true; switch (keyword.ToUpperInvariant()) { case "ARG": case "ARGS": case "ARGUMENT": case "ARGUMENTS": case "INPUT": case "INPUTS": nextType = KeywordType.Argument; break; case "RETURN": case "RETURNS": case "OUTPUT": case "OUTPUTS": nextType = KeywordType.Return; break; case "HELP": case "REMARK": case "REMARKS": nextType = KeywordType.Help; nextVariable = "%help"; break; default: match = false; break; } if (match) { Send(variable, ref result, type, component); AddLine(result, line.Substring(line.IndexOf(":") + 1).TrimStart(_toTrim)); variable = nextVariable; type = nextType; } else AddLine(result, line); } else AddLine(result, line); } else //third level { string keyword; if (IsNewKeywordDeclared(line, out keyword) && (variable == null || !variable.StartsWith("%"))) { Send(variable, ref result, type, component); AddLine(result, line.Substring(line.IndexOf(":") + 1).TrimStart(_toTrim)); variable = keyword; } else AddLine(result, line.Trim(_toTrim)); } } else AddLine(result, line); if (endSeparator != -1) break; } while ((line = reader.ReadLine()) != null); Send(variable, ref result, type, component); return true; }
private static void Send(string variable, ref StringBuilder result, KeywordType type, ScriptingAncestorComponent component) { if (variable != null) { switch (type) { case KeywordType.Description: component.Description = result.ToString(); break; case KeywordType.Argument: FindAndDescribe(component.Params.Input, variable, result.ToString()); break; case KeywordType.Return: FindAndDescribe(component.Params.Output, variable, result.ToString()); break; case KeywordType.Help: component.AdditionalHelpFromDocStrings = result.ToString(); break; } result = new StringBuilder(); } }
public static bool FindApplyDocString(string code, ScriptingAncestorComponent component) { var reader = new StringReader(code); string line; for (; ;) //proceeds to begin of docstrings, or leave method { line = reader.ReadLine(); if (line == null) { return(false); } if (IsEmptyOrFullyCommentedOutLine(line)) { continue; } if (IsDocStringStart(line)) { break; } return(false); } //strips the docstring start chars line = line.Substring(line.IndexOf(_docStringSeparator) + _docStringSeparator.Length); int firstLevelIndent = GetIndent(line); int secondLevelIndent = -1; string variable = "%description"; StringBuilder result = new StringBuilder(); KeywordType type = KeywordType.Description; do //consumes docstring lines and then leaves { int endSeparator = line.IndexOf(_docStringSeparator); if (endSeparator != -1) { line = line.Substring(0, endSeparator); } if (IsEmptyLine(line)) { if (endSeparator != -1) { break; } continue; } int newIndent = GetIndent(line); if (newIndent > firstLevelIndent) { if (secondLevelIndent == -1 || newIndent <= secondLevelIndent) //second level { //we could check for faulty indentation here secondLevelIndent = newIndent; string keyword; if (IsNewKeywordDeclared(line, out keyword)) { var nextType = type; string nextVariable = null; bool match = true; switch (keyword.ToUpperInvariant()) { case "ARG": case "ARGS": case "ARGUMENT": case "ARGUMENTS": case "INPUT": case "INPUTS": nextType = KeywordType.Argument; break; case "RETURN": case "RETURNS": case "OUTPUT": case "OUTPUTS": nextType = KeywordType.Return; break; case "HELP": case "REMARK": case "REMARKS": nextType = KeywordType.Help; nextVariable = "%help"; break; default: match = false; break; } if (match) { Send(variable, ref result, type, component); AddLine(result, line.Substring(line.IndexOf(":") + 1).TrimStart(_toTrim)); variable = nextVariable; type = nextType; } else { AddLine(result, line); } } else { AddLine(result, line); } } else //third level { string keyword; if (IsNewKeywordDeclared(line, out keyword) && (variable == null || !variable.StartsWith("%"))) { Send(variable, ref result, type, component); AddLine(result, line.Substring(line.IndexOf(":") + 1).TrimStart(_toTrim)); variable = keyword; } else { AddLine(result, line.Trim(_toTrim)); } } } else { AddLine(result, line); } if (endSeparator != -1) { break; } }while ((line = reader.ReadLine()) != null); Send(variable, ref result, type, component); return(true); }
private static void Send(string variable, ref StringBuilder result, KeywordType type, ScriptingAncestorComponent component) { if (variable != null) { switch (type) { case KeywordType.Description: component.Description = result.ToString(); break; case KeywordType.Argument: FindAndDescribe(component.Params.Input, variable, result.ToString()); break; case KeywordType.Return: FindAndDescribe(component.Params.Output, variable, result.ToString()); break; case KeywordType.Help: component.SpecialPythonHelpContent = result.ToString(); break; } result = new StringBuilder(); } }
public NewComponentIOMarshal(GrasshopperDocument document, ScriptingAncestorComponent component) { _document = document; _objectTable = _document.Objects; _component = component; }
public void Disable() { _showClosePrompt = false; SuspendLayout(); okButton.Enabled = false; testButton.Enabled = false; this.Text += " (disabled)"; mainStatusText.Text = "Window is disabled because linked component was deleted."; _component = null; ResumeLayout(true); }
protected override void OnClosing(CancelEventArgs e) { try { var textHasChanged = m_previous_script != m_texteditor.Text; if (_showClosePrompt && textHasChanged) { var result = MessageBox.Show("Do you want to apply before closing?", "Rhino.Python closing", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (result == DialogResult.Yes) { SetDefinitionValue(false, true); } else if (result == DialogResult.Cancel) { e.Cancel = true; } } } catch (Exception ex) { LastHandleException(ex); } if (!e.Cancel) { if (_component != null) { var attributes = _component.Attributes as PythonComponentAttributes; if (attributes != null) { attributes.DisableLinkedEditor(false); } //we need to remove origin hinting _component.OnDisplayExpired(true); //store last location _component.DefaultEditorLocation = Location; _component.DefaultEditorSize = (WindowState == FormWindowState.Normal) ? Size : RestoreBounds.Size; _component = null; } Grasshopper.Instances.DocumentEditor.Move -= PythonScriptForm_MoveResize; } base.OnClosing(e); }