-
-
Notifications
You must be signed in to change notification settings - Fork 89
/
FormScript.vb
1696 lines (1407 loc) · 116 KB
/
FormScript.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Imports System.IO
Imports System.Text
Imports Microsoft.Scripting.Hosting
Imports System.Drawing.Text
Imports System.Linq
Imports System.Reflection
Imports FarsiLibrary.Win
Imports System.Threading
Imports Python.Runtime
Imports System.Threading.Tasks
Imports DWSIM.SharedClasses.DWSIM.Flowsheet
Imports IronPython.Hosting
Imports DWSIM.Interfaces
Imports DWSIM.SharedClassesCSharp.FilePicker
Imports Microsoft.Scripting.Utils
Imports PythonConsoleControl
<System.Serializable()> Public Class FormScript
Inherits WeifenLuo.WinFormsUI.Docking.DockContent
Public fc As FormFlowsheet
Private CurrentlyDebugging As Boolean = False
Private DebuggingPaused As Boolean = False
Private CancelDebugToken As CancellationTokenSource
Private ShouldUpdateSnippets As Boolean = True
Private Sub FormVBScript_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load
ExtensionMethods.ChangeDefaultFont(Me)
Using g1 = Me.CreateGraphics()
Settings.DpiScale = g1.DpiX / 96.0
Me.ToolStrip1.AutoSize = False
Me.ToolStrip1.Size = New Size(ToolStrip1.Width, 28 * Settings.DpiScale)
Me.ToolStrip1.ImageScalingSize = New Size(20 * Settings.DpiScale, 20 * Settings.DpiScale)
For Each item In Me.ToolStrip1.Items
If TryCast(item, ToolStripButton) IsNot Nothing Then
DirectCast(item, ToolStripButton).Size = New Size(ToolStrip1.ImageScalingSize.Width, ToolStrip1.ImageScalingSize.Height)
End If
Next
Me.ToolStrip1.Invalidate()
End Using
AddHandler fc.FormSurface.FlowsheetSurface.StatusUpdate, Sub(sender2, e2)
ShouldUpdateSnippets = True
End Sub
' Get the installed fonts collection.
Dim installed_fonts As New InstalledFontCollection
' Get an array of the system's font familiies.
Dim font_families() As FontFamily = installed_fonts.Families()
' Display the font families.
For Each font_family As FontFamily In font_families
tscb1.Items.Add(font_family.Name)
Next
tscb2.Items.AddRange(New Object() {6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16})
tscb2.SelectedItem = 10
If tscb1.Items.Contains("Consolas") Then
tscb1.SelectedItem = "Consolas"
ElseIf tscb1.Items.Contains("Courier New") Then
tscb1.SelectedItem = "Courier New"
ElseIf tscb1.Items.Contains("Ubuntu Mono") Then
tscb1.SelectedItem = "Ubuntu Mono"
ElseIf tscb1.Items.Contains("FreeMono") Then
tscb1.SelectedItem = "FreeMono"
Else
tscb1.SelectedIndex = 0
End If
'load existing scripts
For Each s As Script In fc.ScriptCollection.Values
InsertScriptTab(s)
Next
Dim snippets = SharedClasses.Scripts.IronPythonSnippets.GetSnippets()
For Each group1 In snippets.GroupBy(Function(x) x.Category1)
Dim tsmi = New ToolStripMenuItem() With {.Text = group1.Key}
tsbInsertSnippet.DropDownItems.Add(tsmi)
For Each group2 In group1.GroupBy(Function(x2) x2.Category2)
Dim tsmi2 = New ToolStripMenuItem() With {.Text = group2.Key}
tsmi.DropDownItems.Add(tsmi2)
For Each snippet In group2
Dim tsmi3 = New ToolStripMenuItem() With {.Text = snippet.Name & " (" & snippet.Scope & ")", .Tag = snippet.Snippet}
AddHandler tsmi3.Click, Sub()
If Not DWSIM.App.IsRunningOnMono Then
Dim scontrol As ScriptEditorControl = DirectCast(TabStripScripts.SelectedItem.Controls(0).Controls(0), ScriptEditorControl)
scontrol.txtScript.InsertText(scontrol.txtScript.CurrentPosition, tsmi3.Tag.ToString)
Else
Dim scontrol As ScriptEditorControlMono = DirectCast(TabStripScripts.SelectedItem.Controls(0).Controls(0), ScriptEditorControlMono)
scontrol.txtScript.Text = scontrol.txtScript.Text.Insert(scontrol.txtScript.SelectionStart, tsmi3.Tag.ToString)
End If
End Sub
tsmi2.DropDownItems.Add(tsmi3)
Next
Next
Next
End Sub
Private Sub FloatToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles FloatToolStripMenuItem.Click, DocumentToolStripMenuItem.Click,
DockLeftToolStripMenuItem.Click, DockLeftAutoHideToolStripMenuItem.Click,
DockRightAutoHideToolStripMenuItem.Click, DockRightToolStripMenuItem.Click,
DockTopAutoHideToolStripMenuItem.Click, DockTopToolStripMenuItem.Click,
DockBottomAutoHideToolStripMenuItem.Click, DockBottomToolStripMenuItem.Click
For Each ts As ToolStripMenuItem In dckMenu.Items
ts.Checked = False
Next
sender.Checked = True
Select Case sender.Name
Case "FloatToolStripMenuItem"
Me.DockState = WeifenLuo.WinFormsUI.Docking.DockState.Float
Case "DocumentToolStripMenuItem"
Me.DockState = WeifenLuo.WinFormsUI.Docking.DockState.Document
Case "DockLeftToolStripMenuItem"
Me.DockState = WeifenLuo.WinFormsUI.Docking.DockState.DockLeft
Case "DockLeftAutoHideToolStripMenuItem"
Me.DockState = WeifenLuo.WinFormsUI.Docking.DockState.DockLeftAutoHide
Case "DockRightAutoHideToolStripMenuItem"
Me.DockState = WeifenLuo.WinFormsUI.Docking.DockState.DockRightAutoHide
Case "DockRightToolStripMenuItem"
Me.DockState = WeifenLuo.WinFormsUI.Docking.DockState.DockRight
Case "DockBottomAutoHideToolStripMenuItem"
Me.DockState = WeifenLuo.WinFormsUI.Docking.DockState.DockBottomAutoHide
Case "DockBottomToolStripMenuItem"
Me.DockState = WeifenLuo.WinFormsUI.Docking.DockState.DockBottom
Case "DockTopAutoHideToolStripMenuItem"
Me.DockState = WeifenLuo.WinFormsUI.Docking.DockState.DockTopAutoHide
Case "DockTopToolStripMenuItem"
Me.DockState = WeifenLuo.WinFormsUI.Docking.DockState.DockTop
Case "HiddenToolStripMenuItem"
Me.DockState = WeifenLuo.WinFormsUI.Docking.DockState.Hidden
End Select
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRun.Click
If Not Me.TabStripScripts.SelectedItem Is Nothing Then
If DWSIM.App.IsRunningOnMono Then
Dim script = DirectCast(Me.TabStripScripts.SelectedItem.Controls(0).Controls(0), ScriptEditorControlMono).txtScript.Text
Dim interp = DirectCast(Me.TabStripScripts.SelectedItem.Controls(0).Controls(0), ScriptEditorControlMono).cbPythonEngine.SelectedIndex
If interp = 0 Then
RunScript_IronPython("", script, fc, Nothing)
Else
RunScript_PythonNET("", script, fc)
End If
Else
Dim script = DirectCast(Me.TabStripScripts.SelectedItem.Controls(0).Controls(0), ScriptEditorControl).txtScript.Text
Dim interp = DirectCast(Me.TabStripScripts.SelectedItem.Controls(0).Controls(0), ScriptEditorControl).cbPythonEngine.SelectedIndex
If interp = 0 Then
RunScript_IronPython("", script, fc, Nothing)
Else
RunScript_PythonNET("", script, fc)
End If
End If
End If
End Sub
Public Shared Sub RunScript_IronPython(scripttitle As String, scripttext As String, fsheet As FormFlowsheet, debuggingstep As Action(Of IronPython.Runtime.Exceptions.TraceBackFrame))
fsheet.PythonPreprocessor?.Invoke(scripttext)
Dim scope As Microsoft.Scripting.Hosting.ScriptScope
Dim engine As Microsoft.Scripting.Hosting.ScriptEngine
Dim opts As New Dictionary(Of String, Object)()
opts("Frames") = Microsoft.Scripting.Runtime.ScriptingRuntimeHelpers.True
If debuggingstep IsNot Nothing Then
opts("Debug") = Microsoft.Scripting.Runtime.ScriptingRuntimeHelpers.True
End If
engine = IronPython.Hosting.Python.CreateEngine(opts)
Dim paths(My.Settings.ScriptPaths.Count - 1) As String
Dim paths0 = engine.GetSearchPaths().ToList()
My.Settings.ScriptPaths.CopyTo(paths, 0)
paths0.AddRange(paths)
paths0.Add(Path.Combine(My.Application.Info.DirectoryPath, "Lib"))
Try
engine.SetSearchPaths(paths0)
Catch ex As Exception
End Try
engine.Runtime.LoadAssembly(GetType(System.String).Assembly)
engine.Runtime.LoadAssembly(GetType(Thermodynamics.BaseClasses.ConstantProperties).Assembly)
engine.Runtime.LoadAssembly(GetType(Drawing.SkiaSharp.GraphicObjects.GraphicObject).Assembly)
engine.Runtime.LoadAssembly(GetType(Drawing.SkiaSharp.GraphicsSurface).Assembly)
If My.Application.CommandLineMode Then
engine.Runtime.IO.SetOutput(Console.OpenStandardOutput, Console.OutputEncoding)
Else
engine.Runtime.IO.SetOutput(New DataGridViewTextStream(fsheet), UTF8Encoding.UTF8)
End If
scope = engine.CreateScope()
scope.SetVariable("Plugins", My.Application.UtilityPlugins)
scope.SetVariable("Flowsheet", fsheet)
scope.SetVariable("Spreadsheet", fsheet.FormSpreadsheet.Spreadsheet)
Dim Solver As New FlowsheetSolver.FlowsheetSolver
scope.SetVariable("Solver", Solver)
For Each obj As SharedClasses.UnitOperations.BaseClass In fsheet.Collections.FlowsheetObjectCollection.Values
scope.SetVariable(obj.GraphicObject.Tag.Replace("-", "_"), obj)
Next
Dim txtcode As String = scripttext
Dim source As Microsoft.Scripting.Hosting.ScriptSource = engine.CreateScriptSourceFromString(txtcode, Microsoft.Scripting.SourceCodeKind.Statements)
If debuggingstep IsNot Nothing Then
'enable debugging
Dim vars As New List(Of Object)
Dim names As New List(Of String)
For Each variable In scope.GetVariableNames
vars.Add(scope.GetVariable(variable))
names.Add(variable)
Next
Dim var As IronPython.Runtime.Exceptions.TracebackDelegate = Nothing
var = Function(frame As IronPython.Runtime.Exceptions.TraceBackFrame, result As String, payload As Object)
debuggingstep.Invoke(frame)
Return var
End Function
engine.SetTrace(var)
End If
Try
source.Execute(scope)
Catch ex As Exception
Dim ops As ExceptionOperations = engine.GetService(Of ExceptionOperations)()
If My.Application.CommandLineMode Then
Console.WriteLine()
Console.WriteLine("Error running script: " & ops.FormatException(ex).ToString)
Console.WriteLine()
Else
fsheet.ShowMessage(String.Format("Error running script '{0}': {1}", scripttitle, ops.FormatException(ex).ToString), Interfaces.IFlowsheet.MessageType.GeneralError)
End If
Finally
engine.Runtime.Shutdown()
engine = Nothing
scope = Nothing
source = Nothing
End Try
End Sub
Public Shared Sub RunScript_PythonNET(scripttitle As String, scripttext As String, fsheet As FormFlowsheet)
fsheet.PythonPreprocessor?.Invoke(scripttext)
GlobalSettings.Settings.InitializePythonEnvironment()
Using Py.GIL
Try
Dim sys As Object = Py.Import("sys")
If Not GlobalSettings.Settings.IsRunningOnMono() Then
Dim codeToRedirectOutput As String = "import sys" & vbCrLf + "from io import BytesIO as StringIO" & vbCrLf + "sys.stdout = mystdout = StringIO()" & vbCrLf + "sys.stdout.flush()" & vbCrLf + "sys.stderr = mystderr = StringIO()" & vbCrLf + "sys.stderr.flush()"
PythonEngine.RunSimpleString(codeToRedirectOutput)
End If
Dim locals As New PyDict()
locals.SetItem("Plugins", My.Application.UtilityPlugins.ToPython)
locals.SetItem("Flowsheet", fsheet.ToPython)
locals.SetItem("Spreadsheet", fsheet.FormSpreadsheet.Spreadsheet.ToPython)
Dim Solver As New FlowsheetSolver.FlowsheetSolver
locals.SetItem("Solver", Solver.ToPython)
PythonEngine.Exec(scripttext, Nothing, locals)
If Not GlobalSettings.Settings.IsRunningOnMono() Then
fsheet.WriteToLog(sys.stdout.getvalue().ToString, Color.Blue, MessageType.Information)
End If
Catch ex As Exception
If My.Application.CommandLineMode Then
Console.WriteLine()
Console.WriteLine("Error running script: " & ex.ToString)
Console.WriteLine()
Else
fsheet.ShowMessage(String.Format("Error running script '{0}': {1}", scripttitle, ex.ToString), Interfaces.IFlowsheet.MessageType.GeneralError)
End If
Finally
End Try
End Using
End Sub
Private Sub CutToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CutToolStripButton.Click
If Not DWSIM.App.IsRunningOnMono Then
Dim scontrol As ScriptEditorControl = DirectCast(TabStripScripts.SelectedItem.Controls(0).Controls(0), ScriptEditorControl)
scontrol.txtScript.Cut()
Else
Dim scontrol As ScriptEditorControlMono = DirectCast(TabStripScripts.SelectedItem.Controls(0).Controls(0), ScriptEditorControlMono)
If scontrol.txtScript.SelectedText <> "" Then
scontrol.txtScript.Cut()
End If
End If
End Sub
Private Sub CopyToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CopyToolStripButton.Click
If Not DWSIM.App.IsRunningOnMono Then
Dim scontrol As ScriptEditorControl = DirectCast(TabStripScripts.SelectedItem.Controls(0).Controls(0), ScriptEditorControl)
scontrol.txtScript.Copy()
Else
Dim scontrol As ScriptEditorControlMono = DirectCast(TabStripScripts.SelectedItem.Controls(0).Controls(0), ScriptEditorControlMono)
If scontrol.txtScript.SelectedText <> "" Then Clipboard.SetText(scontrol.txtScript.SelectedText)
End If
End Sub
Private Sub PasteToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PasteToolStripButton.Click
If Not DWSIM.App.IsRunningOnMono Then
Dim scontrol As ScriptEditorControl = DirectCast(TabStripScripts.SelectedItem.Controls(0).Controls(0), ScriptEditorControl)
scontrol.txtScript.Paste()
Else
Dim scontrol As ScriptEditorControlMono = DirectCast(TabStripScripts.SelectedItem.Controls(0).Controls(0), ScriptEditorControlMono)
If scontrol.txtScript.SelectionLength <> 0 Then
scontrol.txtScript.SelectedText = Clipboard.GetText()
Else
scontrol.txtScript.Paste()
End If
End If
End Sub
Public Sub UpdateScripts()
fc.UIThread(Sub()
fc.ScriptCollection.Clear()
For Each tab As FATabStripItem In TabStripScripts.Items
If Not DWSIM.App.IsRunningOnMono Then
Dim seditor As ScriptEditorControl = DirectCast(tab.Controls(0).Controls(0), ScriptEditorControl)
Dim scr As New Script() With
{.ID = Guid.NewGuid().ToString,
.Title = tab.Title,
.Linked = seditor.chkLink.Checked,
.ScriptText = seditor.txtScript.Text,
.PythonInterpreter = seditor.cbPythonEngine.SelectedIndex}
Select Case seditor.cbLinkedObject.SelectedIndex
Case 0
scr.LinkedObjectType = Scripts.ObjectType.Simulation
scr.LinkedObjectName = ""
If seditor.cbLinkedEvent.SelectedIndex = 0 Then
scr.LinkedEventType = Scripts.EventType.SimulationOpened
ElseIf seditor.cbLinkedEvent.SelectedIndex = 1 Then
scr.LinkedEventType = Scripts.EventType.SimulationSaved
ElseIf seditor.cbLinkedEvent.SelectedIndex = 2 Then
scr.LinkedEventType = Scripts.EventType.SimulationClosed
ElseIf seditor.cbLinkedEvent.SelectedIndex = 3 Then
scr.LinkedEventType = Scripts.EventType.SimulationTimer1
ElseIf seditor.cbLinkedEvent.SelectedIndex = 4 Then
scr.LinkedEventType = Scripts.EventType.SimulationTimer5
ElseIf seditor.cbLinkedEvent.SelectedIndex = 5 Then
scr.LinkedEventType = Scripts.EventType.SimulationTimer15
ElseIf seditor.cbLinkedEvent.SelectedIndex = 6 Then
scr.LinkedEventType = Scripts.EventType.SimulationTimer30
ElseIf seditor.cbLinkedEvent.SelectedIndex = 7 Then
scr.LinkedEventType = Scripts.EventType.SimulationTimer60
End If
Case 1
scr.LinkedObjectType = Scripts.ObjectType.Solver
scr.LinkedObjectName = ""
If seditor.cbLinkedEvent.SelectedIndex = 0 Then
scr.LinkedEventType = Scripts.EventType.SolverStarted
ElseIf seditor.cbLinkedEvent.SelectedIndex = 1 Then
scr.LinkedEventType = Scripts.EventType.SolverFinished
Else
scr.LinkedEventType = Scripts.EventType.SolverRecycleLoop
End If
Case 2
scr.LinkedObjectType = Scripts.ObjectType.Integrator
scr.LinkedObjectName = ""
If seditor.cbLinkedEvent.SelectedIndex = 0 Then
scr.LinkedEventType = Scripts.EventType.IntegratorStarted
ElseIf seditor.cbLinkedEvent.SelectedIndex = 1 Then
scr.LinkedEventType = Scripts.EventType.IntegratorFinished
ElseIf seditor.cbLinkedEvent.SelectedIndex = 2 Then
scr.LinkedEventType = Scripts.EventType.IntegratorError
ElseIf seditor.cbLinkedEvent.SelectedIndex = 3 Then
scr.LinkedEventType = Scripts.EventType.IntegratorStep
Else
scr.LinkedEventType = Scripts.EventType.IntegratorPreStep
End If
Case Else
If seditor.chkLink.Checked Then
scr.LinkedObjectType = Scripts.ObjectType.FlowsheetObject
Try
scr.LinkedObjectName = fc.GetFlowsheetGraphicObject(seditor.cbLinkedObject.SelectedItem.ToString).Name
Catch ex As Exception
End Try
End If
If seditor.cbLinkedEvent.SelectedIndex = 0 Then
scr.LinkedEventType = Scripts.EventType.ObjectCalculationStarted
ElseIf seditor.cbLinkedEvent.SelectedIndex = 1 Then
scr.LinkedEventType = Scripts.EventType.ObjectCalculationFinished
Else
scr.LinkedEventType = Scripts.EventType.ObjectCalculationError
End If
End Select
fc.ScriptCollection.Add(scr.ID, scr)
Else
Dim seditor As ScriptEditorControlMono = DirectCast(tab.Controls(0).Controls(0), ScriptEditorControlMono)
Dim scr As New Script() With
{.ID = Guid.NewGuid().ToString,
.Title = tab.Title,
.Linked = seditor.chkLink.Checked,
.ScriptText = seditor.txtScript.Text,
.PythonInterpreter = seditor.cbPythonEngine.SelectedIndex}
Select Case seditor.cbLinkedObject.SelectedIndex
Case 0
scr.LinkedObjectType = Scripts.ObjectType.Simulation
scr.LinkedObjectName = ""
If seditor.cbLinkedEvent.SelectedIndex = 0 Then
scr.LinkedEventType = Scripts.EventType.SimulationOpened
ElseIf seditor.cbLinkedEvent.SelectedIndex = 1 Then
scr.LinkedEventType = Scripts.EventType.SimulationSaved
ElseIf seditor.cbLinkedEvent.SelectedIndex = 2 Then
scr.LinkedEventType = Scripts.EventType.SimulationClosed
ElseIf seditor.cbLinkedEvent.SelectedIndex = 3 Then
scr.LinkedEventType = Scripts.EventType.SimulationTimer1
ElseIf seditor.cbLinkedEvent.SelectedIndex = 4 Then
scr.LinkedEventType = Scripts.EventType.SimulationTimer5
ElseIf seditor.cbLinkedEvent.SelectedIndex = 5 Then
scr.LinkedEventType = Scripts.EventType.SimulationTimer15
ElseIf seditor.cbLinkedEvent.SelectedIndex = 6 Then
scr.LinkedEventType = Scripts.EventType.SimulationTimer30
ElseIf seditor.cbLinkedEvent.SelectedIndex = 7 Then
scr.LinkedEventType = Scripts.EventType.SimulationTimer60
End If
Case 1
scr.LinkedObjectType = Scripts.ObjectType.Solver
scr.LinkedObjectName = ""
If seditor.cbLinkedEvent.SelectedIndex = 0 Then
scr.LinkedEventType = Scripts.EventType.SolverStarted
ElseIf seditor.cbLinkedEvent.SelectedIndex = 1 Then
scr.LinkedEventType = Scripts.EventType.SolverFinished
Else
scr.LinkedEventType = Scripts.EventType.SolverRecycleLoop
End If
Case 2
scr.LinkedObjectType = Scripts.ObjectType.Integrator
scr.LinkedObjectName = ""
If seditor.cbLinkedEvent.SelectedIndex = 0 Then
scr.LinkedEventType = Scripts.EventType.IntegratorStarted
ElseIf seditor.cbLinkedEvent.SelectedIndex = 1 Then
scr.LinkedEventType = Scripts.EventType.IntegratorFinished
ElseIf seditor.cbLinkedEvent.SelectedIndex = 2 Then
scr.LinkedEventType = Scripts.EventType.IntegratorError
ElseIf seditor.cbLinkedEvent.SelectedIndex = 3 Then
scr.LinkedEventType = Scripts.EventType.IntegratorStep
Else
scr.LinkedEventType = Scripts.EventType.IntegratorPreStep
End If
Case Else
If seditor.chkLink.Checked Then
scr.LinkedObjectType = Scripts.ObjectType.FlowsheetObject
scr.LinkedObjectName = fc.GetFlowsheetGraphicObject(seditor.cbLinkedObject.SelectedItem.ToString).Name
End If
If seditor.cbLinkedEvent.SelectedIndex = 0 Then
scr.LinkedEventType = Scripts.EventType.ObjectCalculationStarted
ElseIf seditor.cbLinkedEvent.SelectedIndex = 1 Then
scr.LinkedEventType = Scripts.EventType.ObjectCalculationFinished
Else
scr.LinkedEventType = Scripts.EventType.ObjectCalculationError
End If
End Select
fc.ScriptCollection.Add(scr.ID, scr)
End If
Next
fc.WriteToLog("Script Data updated sucessfully.", Color.Blue, MessageType.Information)
End Sub)
End Sub
Private Sub tscb1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tscb1.SelectedIndexChanged
For Each ft As FATabStripItem In TabStripScripts.Items
If Not DWSIM.App.IsRunningOnMono Then
DirectCast(ft.Controls(0).Controls(0), ScriptEditorControl).txtScript.SetEditorStyle(tscb1.SelectedItem.ToString, tscb2.SelectedItem.ToString, False)
Else
DirectCast(ft.Controls(0).Controls(0), ScriptEditorControlMono).txtScript.Font = New Font(tscb1.SelectedItem.ToString, 10)
End If
Next
End Sub
Private Sub tscb2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tscb2.SelectedIndexChanged
For Each ft As FATabStripItem In TabStripScripts.Items
If Not DWSIM.App.IsRunningOnMono Then
DirectCast(ft.Controls(0).Controls(0), ScriptEditorControl).txtScript.SetEditorStyle(tscb1.SelectedItem.ToString, tscb2.SelectedItem.ToString, False)
Else
DirectCast(ft.Controls(0).Controls(0), ScriptEditorControlMono).txtScript.Font = New Font(DirectCast(ft.Controls(0).Controls(0), ScriptEditorControlMono).txtScript.Font.Name, tscb2.SelectedItem)
End If
Next
End Sub
Private Sub NewToolStripButton_Click(sender As Object, e As EventArgs) Handles NewToolStripButton.Click
Dim newscript As New Script With {.ID = Guid.NewGuid().ToString()}
fc.ScriptCollection.Add(newscript.ID, newscript)
InsertScriptTab(newscript)
End Sub
Private Sub InsertScriptTab(scriptdata As Script)
If Not DWSIM.App.IsRunningOnMono Then
Dim p As New Panel With {.Dock = DockStyle.Fill}
Dim scontrol As New ScriptEditorControl With {.Dock = DockStyle.Fill}
With scontrol
AddHandler scontrol.txtScript.KeyDown, AddressOf scriptcontrol_KeyDown
.txtScript.Text = scriptdata.ScriptText
.txtScript.Tag = 1
.txtScript.SetEditorStyle(tscb1.SelectedItem.ToString, tscb2.SelectedItem.ToString, False)
.form = fc
.chkLink.Checked = scriptdata.Linked
p.Controls.Add(scontrol)
Dim stab As New FATabStripItem()
stab.Controls.Add(p)
stab.Tag = scriptdata.ID
If scriptdata.Title = "" Then
stab.Title = "Script" & TabStripScripts.Items.Count + 1
scriptdata.Title = stab.Title
Else
stab.Title = scriptdata.Title
End If
AddHandler scontrol.txtScript.TextChanged,
Sub()
scriptdata.ScriptText = scontrol.txtScript.Text
End Sub
AddHandler scontrol.tbName.TextChanged,
Sub()
scriptdata.Title = scontrol.tbName.Text
stab.Title = scriptdata.Title
End Sub
AddHandler scontrol.btnDelete.Click,
Sub()
If MessageBox.Show(DWSIM.App.GetLocalString("RemoveScriptQuestion"), "DWSIM", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
TabStripScripts.RemoveTab(stab)
fc.ScriptCollection.Remove(scriptdata.ID)
End If
End Sub
TabStripScripts.AddTab(stab, True)
TabStripScripts.SelectedItem = stab
.tbName.Text = scriptdata.Title
Me.Invalidate()
If scriptdata.LinkedObjectName <> "" And fc.SimulationObjects.ContainsKey(scriptdata.LinkedObjectName) Then
.cbLinkedObject.SelectedItem = fc.Collections.FlowsheetObjectCollection(scriptdata.LinkedObjectName).GraphicObject.Tag
Else
Select Case scriptdata.LinkedObjectType
Case Scripts.ObjectType.Simulation
.cbLinkedObject.SelectedIndex = 0
Case Scripts.ObjectType.Solver
.cbLinkedObject.SelectedIndex = 1
Case Scripts.ObjectType.Integrator
.cbLinkedObject.SelectedIndex = 2
End Select
End If
Select Case scriptdata.LinkedEventType
Case Scripts.EventType.ObjectCalculationStarted
.cbLinkedEvent.SelectedIndex = 0
Case Scripts.EventType.ObjectCalculationFinished
.cbLinkedEvent.SelectedIndex = 1
Case Scripts.EventType.ObjectCalculationError
.cbLinkedEvent.SelectedIndex = 2
Case Scripts.EventType.SimulationOpened
.cbLinkedEvent.SelectedIndex = 0
Case Scripts.EventType.SimulationSaved
.cbLinkedEvent.SelectedIndex = 1
Case Scripts.EventType.SimulationClosed
.cbLinkedEvent.SelectedIndex = 2
Case Scripts.EventType.SolverStarted
.cbLinkedEvent.SelectedIndex = 0
Case Scripts.EventType.SolverFinished
.cbLinkedEvent.SelectedIndex = 1
Case Scripts.EventType.SolverRecycleLoop
.cbLinkedEvent.SelectedIndex = 2
Case Scripts.EventType.SimulationTimer1
.cbLinkedEvent.SelectedIndex = 3
Case Scripts.EventType.SimulationTimer5
.cbLinkedEvent.SelectedIndex = 4
Case Scripts.EventType.SimulationTimer15
.cbLinkedEvent.SelectedIndex = 5
Case Scripts.EventType.SimulationTimer30
.cbLinkedEvent.SelectedIndex = 6
Case Scripts.EventType.SimulationTimer60
.cbLinkedEvent.SelectedIndex = 7
Case Scripts.EventType.IntegratorStarted
.cbLinkedEvent.SelectedIndex = 0
Case Scripts.EventType.IntegratorFinished
.cbLinkedEvent.SelectedIndex = 1
Case Scripts.EventType.IntegratorError
.cbLinkedEvent.SelectedIndex = 2
Case Scripts.EventType.IntegratorStep
.cbLinkedEvent.SelectedIndex = 3
Case Scripts.EventType.IntegratorPreStep
.cbLinkedEvent.SelectedIndex = 4
End Select
.cbPythonEngine.SelectedIndex = scriptdata.PythonInterpreter
AddHandler scontrol.cbPythonEngine.SelectedIndexChanged,
Sub()
scriptdata.PythonInterpreter = scontrol.cbPythonEngine.SelectedIndex
End Sub
Dim cbhandler = Sub()
Dim scr = scriptdata
Select Case scontrol.cbLinkedObject.SelectedIndex
Case 0
scr.LinkedObjectType = Scripts.ObjectType.Simulation
scr.LinkedObjectName = ""
If scontrol.cbLinkedEvent.SelectedIndex = 0 Then
scr.LinkedEventType = Scripts.EventType.SimulationOpened
ElseIf scontrol.cbLinkedEvent.SelectedIndex = 1 Then
scr.LinkedEventType = Scripts.EventType.SimulationSaved
ElseIf scontrol.cbLinkedEvent.SelectedIndex = 2 Then
scr.LinkedEventType = Scripts.EventType.SimulationClosed
ElseIf scontrol.cbLinkedEvent.SelectedIndex = 3 Then
scr.LinkedEventType = Scripts.EventType.SimulationTimer1
ElseIf scontrol.cbLinkedEvent.SelectedIndex = 4 Then
scr.LinkedEventType = Scripts.EventType.SimulationTimer5
ElseIf scontrol.cbLinkedEvent.SelectedIndex = 5 Then
scr.LinkedEventType = Scripts.EventType.SimulationTimer15
ElseIf scontrol.cbLinkedEvent.SelectedIndex = 6 Then
scr.LinkedEventType = Scripts.EventType.SimulationTimer30
ElseIf scontrol.cbLinkedEvent.SelectedIndex = 7 Then
scr.LinkedEventType = Scripts.EventType.SimulationTimer60
End If
Case 1
scr.LinkedObjectType = Scripts.ObjectType.Solver
scr.LinkedObjectName = ""
If scontrol.cbLinkedEvent.SelectedIndex = 0 Then
scr.LinkedEventType = Scripts.EventType.SolverStarted
ElseIf scontrol.cbLinkedEvent.SelectedIndex = 1 Then
scr.LinkedEventType = Scripts.EventType.SolverFinished
Else
scr.LinkedEventType = Scripts.EventType.SolverRecycleLoop
End If
Case 2
scr.LinkedObjectType = Scripts.ObjectType.Integrator
scr.LinkedObjectName = ""
If scontrol.cbLinkedEvent.SelectedIndex = 0 Then
scr.LinkedEventType = Scripts.EventType.IntegratorStarted
ElseIf scontrol.cbLinkedEvent.SelectedIndex = 1 Then
scr.LinkedEventType = Scripts.EventType.IntegratorFinished
ElseIf scontrol.cbLinkedEvent.SelectedIndex = 2 Then
scr.LinkedEventType = Scripts.EventType.IntegratorError
ElseIf scontrol.cbLinkedEvent.SelectedIndex = 3 Then
scr.LinkedEventType = Scripts.EventType.IntegratorStep
ElseIf scontrol.cbLinkedEvent.SelectedIndex = 4 Then
scr.LinkedEventType = Scripts.EventType.IntegratorPreStep
End If
Case Else
If scontrol.chkLink.Checked Then
scr.LinkedObjectType = Scripts.ObjectType.FlowsheetObject
Try
scr.LinkedObjectName = fc.GetFlowsheetGraphicObject(scontrol.cbLinkedObject.SelectedItem.ToString).Name
Catch ex As Exception
End Try
End If
If scontrol.cbLinkedEvent.SelectedIndex = 0 Then
scr.LinkedEventType = Scripts.EventType.ObjectCalculationStarted
ElseIf scontrol.cbLinkedEvent.SelectedIndex = 1 Then
scr.LinkedEventType = Scripts.EventType.ObjectCalculationFinished
Else
scr.LinkedEventType = Scripts.EventType.ObjectCalculationError
End If
End Select
End Sub
AddHandler scontrol.cbLinkedObject.SelectedIndexChanged, cbhandler
AddHandler scontrol.cbLinkedEvent.SelectedIndexChanged, cbhandler
AddHandler scontrol.chkLink.CheckStateChanged,
Sub()
scriptdata.Linked = scontrol.chkLink.Checked
End Sub
End With
Else
Dim p As New Panel With {.Dock = DockStyle.Fill}
Dim scontrol As New ScriptEditorControlMono With {.Dock = DockStyle.Fill}
With scontrol
AddHandler scontrol.txtScript.KeyDown, AddressOf scriptcontrol_KeyDown
.txtScript.Font = New Font(tscb1.SelectedItem.ToString, tscb2.SelectedItem)
.txtScript.Text = scriptdata.ScriptText
AddHandler scontrol.txtScript.TextChanged, Sub()
scriptdata.ScriptText = scontrol.txtScript.Text
End Sub
.form = fc
.chkLink.Checked = scriptdata.Linked
p.Controls.Add(scontrol)
Dim stab As New FATabStripItem()
stab.Controls.Add(p)
stab.Tag = scriptdata.ID
If scriptdata.Title = "" Then stab.Title = "Script" & TabStripScripts.Items.Count + 1 Else stab.Title = scriptdata.Title
TabStripScripts.AddTab(stab, True)
TabStripScripts.SelectedItem = stab
Me.Invalidate()
If scriptdata.LinkedObjectName <> "" Then
.cbLinkedObject.SelectedItem = fc.Collections.FlowsheetObjectCollection(scriptdata.LinkedObjectName).GraphicObject.Tag
Else
Select Case scriptdata.LinkedObjectType
Case Scripts.ObjectType.Simulation
.cbLinkedObject.SelectedIndex = 0
Case Scripts.ObjectType.Solver
.cbLinkedObject.SelectedIndex = 1
Case Scripts.ObjectType.Integrator
.cbLinkedObject.SelectedIndex = 2
End Select
End If
Select Case scriptdata.LinkedEventType
Case Scripts.EventType.ObjectCalculationStarted
.cbLinkedEvent.SelectedIndex = 0
Case Scripts.EventType.ObjectCalculationFinished
.cbLinkedEvent.SelectedIndex = 1
Case Scripts.EventType.ObjectCalculationError
.cbLinkedEvent.SelectedIndex = 2
Case Scripts.EventType.SimulationOpened
.cbLinkedEvent.SelectedIndex = 0
Case Scripts.EventType.SimulationSaved
.cbLinkedEvent.SelectedIndex = 1
Case Scripts.EventType.SimulationClosed
.cbLinkedEvent.SelectedIndex = 2
Case Scripts.EventType.SolverStarted
.cbLinkedEvent.SelectedIndex = 0
Case Scripts.EventType.SolverFinished
.cbLinkedEvent.SelectedIndex = 1
Case Scripts.EventType.SolverRecycleLoop
.cbLinkedEvent.SelectedIndex = 2
Case Scripts.EventType.SimulationTimer1
.cbLinkedEvent.SelectedIndex = 3
Case Scripts.EventType.SimulationTimer5
.cbLinkedEvent.SelectedIndex = 4
Case Scripts.EventType.SimulationTimer15
.cbLinkedEvent.SelectedIndex = 5
Case Scripts.EventType.SimulationTimer30
.cbLinkedEvent.SelectedIndex = 6
Case Scripts.EventType.SimulationTimer60
.cbLinkedEvent.SelectedIndex = 7
Case Scripts.EventType.IntegratorStarted
.cbLinkedEvent.SelectedIndex = 0
Case Scripts.EventType.IntegratorFinished
.cbLinkedEvent.SelectedIndex = 1
Case Scripts.EventType.IntegratorError
.cbLinkedEvent.SelectedIndex = 2
Case Scripts.EventType.IntegratorStep
.cbLinkedEvent.SelectedIndex = 3
Case Scripts.EventType.IntegratorPreStep
.cbLinkedEvent.SelectedIndex = 4
End Select
.cbPythonEngine.SelectedIndex = scriptdata.PythonInterpreter
End With
End If
End Sub
Private Sub TabStripScripts_TabStripItemClosing(e As TabStripItemClosingEventArgs) Handles TabStripScripts.TabStripItemClosing
If MessageBox.Show(DWSIM.App.GetLocalString("RemoveScriptQuestion"), "DWSIM", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.No Then
e.Cancel = True
Else
fc.ScriptCollection.Remove(e.Item.Tag)
End If
End Sub
Private Sub scriptcontrol_KeyDown(sender As Object, e As KeyEventArgs)
If e.KeyCode = Keys.F5 Then btnRunAsync.PerformClick()
If e.KeyCode = Keys.F5 And e.Modifiers = Keys.Shift Then btnRun.PerformClick()
End Sub
Private Sub APIHelptsbutton_Click(sender As Object, e As EventArgs) Handles APIHelptsbutton.Click
If FormMain.IsPro Then
fc.DisplayBrowserWindow("https://dwsim.org/api_help/html/G_DWSIM.htm")
Else
Process.Start("https://dwsim.org/api_help/html/G_DWSIM.htm")
End If
End Sub
Private Sub btnUndo_Click(sender As Object, e As EventArgs) Handles btnUndo.Click
If Not DWSIM.App.IsRunningOnMono Then
Dim scontrol As ScriptEditorControl = DirectCast(TabStripScripts.SelectedItem.Controls(0).Controls(0), ScriptEditorControl)
scontrol.txtScript.Undo()
Else
Dim scontrol As ScriptEditorControlMono = DirectCast(TabStripScripts.SelectedItem.Controls(0).Controls(0), ScriptEditorControlMono)
scontrol.txtScript.Undo()
End If
End Sub
Private Sub btnRedo_Click(sender As Object, e As EventArgs) Handles btnRedo.Click
If Not DWSIM.App.IsRunningOnMono Then
Dim scontrol As ScriptEditorControl = DirectCast(TabStripScripts.SelectedItem.Controls(0).Controls(0), ScriptEditorControl)
scontrol.txtScript.Redo()
End If
End Sub
Private Sub ToolStripButton2_Click_1(sender As Object, e As EventArgs) Handles btnComment.Click
If Not DWSIM.App.IsRunningOnMono Then
Dim scontrol As ScriptEditorControl = DirectCast(TabStripScripts.SelectedItem.Controls(0).Controls(0), ScriptEditorControl)
Dim lines = scontrol.txtScript.SelectedText.Split(Environment.NewLine, vbCr, vbLf, vbCrLf)
Dim newlines As String = ""
For Each l In lines
If l <> "" Then newlines += l.Insert(0, "#") & Environment.NewLine
Next
scontrol.txtScript.ReplaceSelection(newlines.TrimEnd(Environment.NewLine, vbCr, vbLf, vbCrLf))
Else
Dim scontrol As ScriptEditorControlMono = DirectCast(TabStripScripts.SelectedItem.Controls(0).Controls(0), ScriptEditorControlMono)
Dim lines = scontrol.txtScript.SelectedText.Split(Environment.NewLine, vbCr, vbLf, vbCrLf)
Dim newlines As String = ""
For Each l In lines
If l <> "" Then newlines += l.Insert(0, "#") & Environment.NewLine
Next
scontrol.txtScript.SelectedText = newlines.TrimEnd(Environment.NewLine, vbCr, vbLf, vbCrLf)
End If
End Sub
Private Sub btnUncomment_Click(sender As Object, e As EventArgs) Handles btnUncomment.Click
If Not DWSIM.App.IsRunningOnMono Then
Dim scontrol As ScriptEditorControl = DirectCast(TabStripScripts.SelectedItem.Controls(0).Controls(0), ScriptEditorControl)
Dim lines = scontrol.txtScript.SelectedText.Split(Environment.NewLine, vbCr, vbLf, vbCrLf)
Dim newlines As String = ""
For Each l In lines
If l <> "" Then newlines += l.TrimStart("#") & Environment.NewLine
Next
scontrol.txtScript.ReplaceSelection(newlines.TrimEnd(Environment.NewLine, vbCr, vbLf, vbCrLf))
Else
Dim scontrol As ScriptEditorControlMono = DirectCast(TabStripScripts.SelectedItem.Controls(0).Controls(0), ScriptEditorControlMono)
Dim lines = scontrol.txtScript.SelectedText.Split(Environment.NewLine, vbCr, vbLf, vbCrLf)
Dim newlines As String = ""
For Each l In lines
If l <> "" Then newlines += l.TrimStart("#") & Environment.NewLine
Next
scontrol.txtScript.SelectedText = newlines.TrimEnd(Environment.NewLine, vbCr, vbLf, vbCrLf)
End If
End Sub
Private Sub btnIdent_Click(sender As Object, e As EventArgs) Handles btnIdent.Click
If Not DWSIM.App.IsRunningOnMono Then
Dim scontrol As ScriptEditorControl = DirectCast(TabStripScripts.SelectedItem.Controls(0).Controls(0), ScriptEditorControl)
Dim lines = scontrol.txtScript.SelectedText.Split(Environment.NewLine, vbCr, vbLf, vbCrLf)
Dim newlines As String = ""
For Each l In lines
If l <> "" Then newlines += l.Insert(0, vbTab) & Environment.NewLine
Next
scontrol.txtScript.ReplaceSelection(newlines.TrimEnd(Environment.NewLine, vbCr, vbLf, vbCrLf))
Else
Dim scontrol As ScriptEditorControlMono = DirectCast(TabStripScripts.SelectedItem.Controls(0).Controls(0), ScriptEditorControlMono)
Dim lines = scontrol.txtScript.SelectedText.Split(Environment.NewLine, vbCr, vbLf, vbCrLf)
Dim newlines As String = ""
For Each l In lines
If l <> "" Then newlines += l.Insert(0, vbTab) & Environment.NewLine
Next
scontrol.txtScript.SelectedText = newlines.TrimEnd(Environment.NewLine, vbCr, vbLf, vbCrLf)
End If
End Sub
Private Sub btnIdentRemove_Click(sender As Object, e As EventArgs) Handles btnIdentRemove.Click
If Not DWSIM.App.IsRunningOnMono Then
Dim scontrol As ScriptEditorControl = DirectCast(TabStripScripts.SelectedItem.Controls(0).Controls(0), ScriptEditorControl)
Dim lines = scontrol.txtScript.SelectedText.Split(Environment.NewLine, vbCr, vbLf, vbCrLf)
Dim newlines As String = ""
For Each l In lines
If l <> "" Then newlines += l.TrimStart(vbTab) & Environment.NewLine
Next
scontrol.txtScript.ReplaceSelection(newlines.TrimEnd(Environment.NewLine, vbCr, vbLf, vbCrLf))
Else
Dim scontrol As ScriptEditorControlMono = DirectCast(TabStripScripts.SelectedItem.Controls(0).Controls(0), ScriptEditorControlMono)
Dim lines = scontrol.txtScript.SelectedText.Split(Environment.NewLine, vbCr, vbLf, vbCrLf)
Dim newlines As String = ""
For Each l In lines
If l <> "" Then newlines += l.TrimStart(vbTab) & Environment.NewLine
Next
scontrol.txtScript.SelectedText = newlines.TrimEnd(Environment.NewLine, vbCr, vbLf, vbCrLf)
End If
End Sub
Private Sub btnRunAsync_Click(sender As Object, e As EventArgs) Handles btnRunAsync.Click
If Not Me.TabStripScripts.SelectedItem Is Nothing Then
If DWSIM.App.IsRunningOnMono Then
Dim script = DirectCast(Me.TabStripScripts.SelectedItem.Controls(0).Controls(0), ScriptEditorControlMono).txtScript.Text
Dim interp = DirectCast(Me.TabStripScripts.SelectedItem.Controls(0).Controls(0), ScriptEditorControlMono).cbPythonEngine.SelectedIndex
If interp = 0 Then
TaskHelper.Run(Sub() RunScript_IronPython("", script, fc, Nothing))
Else
TaskHelper.Run(Sub() RunScript_PythonNET("", script, fc))
End If
Else
Dim script = DirectCast(Me.TabStripScripts.SelectedItem.Controls(0).Controls(0), ScriptEditorControl).txtScript.Text
Dim interp = DirectCast(Me.TabStripScripts.SelectedItem.Controls(0).Controls(0), ScriptEditorControl).cbPythonEngine.SelectedIndex
If interp = 0 Then
TaskHelper.Run(Sub() RunScript_IronPython("", script, fc, Nothing))
Else
TaskHelper.Run(Sub() RunScript_PythonNET("", script, fc))
End If
End If
End If
End Sub
Private Sub btnRunDebug_Click(sender As Object, e As EventArgs) Handles btnRunDebug.Click
If CurrentlyDebugging Then
DebuggingPaused = False
Else
Dim scripteditor = DirectCast(Me.TabStripScripts.SelectedItem.Controls(0).Controls(0), ScriptEditorControl)
Dim script = scripteditor.txtScript.Text