-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathContainer_Keyword.xojo_window
1217 lines (1067 loc) · 34.6 KB
/
Container_Keyword.xojo_window
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
#tag DesktopWindow
Begin DesktopContainer Container_Keyword
AllowAutoDeactivate= True
AllowFocus = False
AllowFocusRing = False
AllowTabs = True
Backdrop = 0
BackgroundColor = &cFFFFFF
Composited = False
Enabled = True
HasBackgroundColor= False
Height = 486
Index = -2147483648
InitialParent = ""
Left = 0
LockBottom = False
LockLeft = True
LockRight = False
LockTop = True
TabIndex = 0
TabPanelIndex = 0
TabStop = True
Tooltip = ""
Top = 0
Transparent = True
Visible = True
Width = 564
Begin DesktopSearchField SearchField_Filter
Active = False
AllowAutoDeactivate= True
AllowFocusRing = True
AllowRecentItems= False
AllowTabStop = True
ClearMenuItemValue= "Clear"
Enabled = True
Height = 22
Hint = "Prompt Filter"
Index = -2147483648
InitialParent = ""
Left = 0
LockBottom = False
LockedInPosition= False
LockLeft = True
LockRight = True
LockTop = True
MaximumRecentItems= -1
PanelIndex = 0
RecentItemsValue= "Recent Searches"
Scope = 2
TabIndex = 0
TabPanelIndex = 0
Text = ""
Tooltip = ""
Top = 0
Transparent = False
Visible = True
Width = 284
_mIndex = 0
_mInitialParent = ""
_mName = ""
_mPanelIndex = 0
End
Begin PushButtonSized PushButton_Save_Keyword
AllowAutoDeactivate= True
Bold = False
Cancel = False
Caption = "💾"
Default = False
Enabled = True
FontName = "System"
FontSize = 0.0
FontUnit = 0
Height = 20
Index = -2147483648
InitialParent = ""
Italic = False
Left = 296
LockBottom = False
LockedInPosition= False
LockLeft = False
LockRight = True
LockTop = True
MacButtonStyle = 0
Scope = 2
TabIndex = 1
TabPanelIndex = 0
TabStop = True
Tooltip = "Save the text entered in the prompt filter as new keyword, in the selected category."
Top = 0
Transparent = False
Underline = False
Visible = True
Width = 32
End
Begin PushButtonSized PushButton_Delete_Keyword
AllowAutoDeactivate= True
Bold = False
Cancel = False
Caption = "🗑️"
Default = False
Enabled = True
FontName = "System"
FontSize = 0.0
FontUnit = 0
Height = 20
Index = -2147483648
InitialParent = ""
Italic = False
Left = 340
LockBottom = False
LockedInPosition= False
LockLeft = False
LockRight = True
LockTop = True
MacButtonStyle = 0
Scope = 2
TabIndex = 2
TabPanelIndex = 0
TabStop = True
Tooltip = "Delete the keyword marked in the list below from the database."
Top = 0
Transparent = False
Underline = False
Visible = True
Width = 32
End
Begin DesktopPopupMenu PopupMenu_Category
AllowAutoDeactivate= True
Bold = False
Enabled = False
FontName = "System"
FontSize = 0.0
FontUnit = 0
Height = 22
Index = -2147483648
InitialValue = ""
Italic = False
Left = 384
LockBottom = False
LockedInPosition= False
LockLeft = False
LockRight = True
LockTop = True
Scope = 2
SelectedRowIndex= 0
TabIndex = 3
TabPanelIndex = 0
TabStop = True
Tooltip = "Select a Keyword Category.\r\nCategories are for organization only and do not affect the image generation of your prompt."
Top = 0
Transparent = False
Underline = False
Visible = True
Width = 180
End
Begin DesktopListBoxDM ListBox_PromptWords
AllowAutoDeactivate= True
AllowAutoHideScrollbars= True
AllowExpandableRows= False
AllowFocusRing = False
AllowResizableColumns= False
AllowRowDragging= False
AllowRowReordering= True
Bold = False
ColumnCount = 6
ColumnWidths = "22,*,50,65,120,0"
DefaultRowHeight= -1
DropIndicatorVisible= False
Enabled = True
FontName = "System"
FontSize = 0.0
FontUnit = 0
GridLineStyle = 0
HasBorder = True
HasHeader = True
HasHorizontalScrollbar= False
HasVerticalScrollbar= True
HeadingIndex = -1
Height = 215
Index = -2147483648
InitialValue = " Keyword(s) Weight Negative Category Position in Prompt"
Italic = False
Left = 0
LockBottom = True
LockedInPosition= False
LockLeft = True
LockRight = True
LockTop = True
NegativeColumn = 3
RequiresSelection= True
RowSelectionType= 1
Scope = 2
TabIndex = 4
TabPanelIndex = 0
TabStop = True
Tooltip = "List entries can be edited by selecting it twice. Double-click slowly to edit entries, double-click quickly to move an entry to the top of the list. The order can also be changed by dragging and dropping."
Top = 34
Transparent = False
Underline = False
Visible = True
Width = 564
_ScrollOffset = 0
_ScrollWidth = -1
End
Begin DesktopTextArea TextArea_PromptPositive
AllowAutoDeactivate= True
AllowFocusRing = True
AllowSpellChecking= False
AllowStyledText = False
AllowTabs = False
BackgroundColor = &cFFFFFF
Bold = False
Enabled = True
FontName = "System"
FontSize = 0.0
FontUnit = 0
Format = ""
HasBorder = True
HasHorizontalScrollbar= False
HasVerticalScrollbar= True
Height = 152
HideSelection = False
Index = -2147483648
Italic = False
Left = 0
LineHeight = 0.0
LineSpacing = 1.0
LockBottom = True
LockedInPosition= False
LockLeft = True
LockRight = False
LockTop = False
MaximumCharactersAllowed= 0
Multiline = True
ReadOnly = True
Scope = 2
TabIndex = 5
TabPanelIndex = 0
TabStop = True
Text = ""
TextAlignment = 0
TextColor = &c000000
Tooltip = "This prompt is composed of your selection of keywords and the recommended keywords of your selected model."
Top = 261
Transparent = False
Underline = False
UnicodeMode = 1
ValidationMask = ""
Visible = True
Width = 280
End
Begin DesktopLabel Label_PositivePrompt_Length
AllowAutoDeactivate= False
Bold = False
Enabled = True
FontName = "System"
FontSize = 9.0
FontUnit = 0
Height = 12
Index = -2147483648
Italic = False
Left = 0
LockBottom = True
LockedInPosition= False
LockLeft = True
LockRight = False
LockTop = False
Multiline = False
Scope = 2
Selectable = False
TabIndex = 6
TabPanelIndex = 0
TabStop = False
Text = "Token counter (estimated): 0"
TextAlignment = 2
TextColor = &c5C5C5C00
Tooltip = "This counter is only a rough estimate of the token count."
Top = 414
Transparent = False
Underline = False
Visible = True
Width = 278
End
Begin PushButton PushButton_Copy_PromptPositive
AllowAutoDeactivate= True
Bold = False
Cancel = False
Caption = "Copy positive prompt"
Default = False
Enabled = True
FontName = "System"
FontSize = 0.0
FontUnit = 0
Height = 22
Index = -2147483648
InitialParent = ""
Italic = False
Left = 0
LockBottom = True
LockedInPosition= False
LockLeft = True
LockRight = False
LockTop = False
MacButtonStyle = 0
Scope = 2
TabIndex = 7
TabPanelIndex = 0
TabStop = True
Tooltip = "Copy the above prompt to the clipboard and paste it into your Stable Diffusion instance."
Top = 427
Transparent = False
Underline = False
Visible = True
Width = 278
End
Begin DesktopTextArea TextArea_PromptNegative
AllowAutoDeactivate= True
AllowFocusRing = True
AllowSpellChecking= False
AllowStyledText = False
AllowTabs = False
BackgroundColor = &cFFFFFF
Bold = False
Enabled = True
FontName = "System"
FontSize = 0.0
FontUnit = 0
Format = ""
HasBorder = True
HasHorizontalScrollbar= False
HasVerticalScrollbar= True
Height = 152
HideSelection = False
Index = -2147483648
Italic = False
Left = 292
LineHeight = 0.0
LineSpacing = 1.0
LockBottom = True
LockedInPosition= False
LockLeft = False
LockRight = True
LockTop = False
MaximumCharactersAllowed= 0
Multiline = True
ReadOnly = True
Scope = 2
TabIndex = 8
TabPanelIndex = 0
TabStop = True
Text = ""
TextAlignment = 0
TextColor = &c000000
Tooltip = "This prompt is composed of your selection of keywords and the recommended keywords of your selected model."
Top = 261
Transparent = False
Underline = False
UnicodeMode = 1
ValidationMask = ""
Visible = True
Width = 272
End
Begin DesktopLabel Label_NegativePrompt_Length
AllowAutoDeactivate= False
Bold = False
Enabled = True
FontName = "System"
FontSize = 9.0
FontUnit = 0
Height = 12
Index = -2147483648
Italic = False
Left = 292
LockBottom = True
LockedInPosition= False
LockLeft = False
LockRight = True
LockTop = False
Multiline = False
Scope = 2
Selectable = False
TabIndex = 9
TabPanelIndex = 0
TabStop = False
Text = "Token counter (estimated): 0"
TextAlignment = 2
TextColor = &c5C5C5C00
Tooltip = "This counter is only a rough estimate of the token count."
Top = 414
Transparent = False
Underline = False
Visible = True
Width = 272
End
Begin PushButton PushButton_Copy_PromptNegative
AllowAutoDeactivate= True
Bold = False
Cancel = False
Caption = "Copy negative prompt"
Default = False
Enabled = True
FontName = "System"
FontSize = 0.0
FontUnit = 0
Height = 22
Index = -2147483648
InitialParent = ""
Italic = False
Left = 292
LockBottom = True
LockedInPosition= False
LockLeft = False
LockRight = True
LockTop = False
MacButtonStyle = 0
Scope = 2
TabIndex = 10
TabPanelIndex = 0
TabStop = True
Tooltip = "Copy the above prompt to the clipboard and paste it into your Stable Diffusion instance."
Top = 427
Transparent = False
Underline = False
Visible = True
Width = 272
End
Begin DesktopButton Button_SendToSDHost
AllowAutoDeactivate= True
Bold = False
Cancel = False
Caption = "Send to Stable Diffusion Host"
Default = False
Enabled = True
FontName = "System"
FontSize = 0.0
FontUnit = 0
Height = 20
Index = -2147483648
Italic = False
Left = 0
LockBottom = True
LockedInPosition= True
LockLeft = True
LockRight = True
LockTop = False
MacButtonStyle = 0
Scope = 2
TabIndex = 11
TabPanelIndex = 0
TabStop = True
Tooltip = "Send above Prompts to the Stabe Diffusion processor configured in SDP Settings."
Top = 461
Transparent = False
Underline = False
Visible = True
Width = 564
End
End
#tag EndDesktopWindow
#tag WindowCode
#tag Event
Sub Resized()
Var TextAreaWidth As Integer = (Self.Width / 2) - 6
TextArea_PromptPositive.Width = TextAreaWidth
PushButton_Copy_PromptPositive.Width = TextAreaWidth
Label_PositivePrompt_Length.Width = TextAreaWidth
TextArea_PromptNegative.Left = TextAreaWidth + 12
TextArea_PromptNegative.Width = TextAreaWidth
PushButton_Copy_PromptNegative.Left = TextArea_PromptNegative.Left
PushButton_Copy_PromptNegative.Width = TextAreaWidth
Label_NegativePrompt_Length.Left = TextArea_PromptNegative.Left
Label_NegativePrompt_Length.Width = TextAreaWidth
Self.Refresh
End Sub
#tag EndEvent
#tag Method, Flags = &h0
Sub Keywords_DeselectAll()
If ListBox_PromptWords.RowCount=0 Then Return
For X As Integer = 0 To ListBox_PromptWords.LastRowIndex
If ListBox_PromptWords.CellCheckBoxValueAt(X,0) Then
CurrentPreset.Keyword_Remove(ListBox_PromptWords.RowTagAt(X).IntegerValue)
ListBox_PromptWords.CellCheckBoxValueAt(X,0) = False
End If
Next
Prompt_Show
End Sub
#tag EndMethod
#tag Method, Flags = &h0
Sub Keywords_List()
If PopupMenu_Category.SelectedRowIndex=0 Then
ListBox_PromptWords.ColumnSortDirectionAt(5) = DesktopListBox.SortDirections.Ascending
ListBox_PromptWords.AllowRowReordering=True
Else
ListBox_PromptWords.ColumnSortDirectionAt(5) = DesktopListBox.SortDirections.None
ListBox_PromptWords.AllowRowReordering=False
End If
Try
Var RS As RowSet
If SearchField_Filter.Text.Trim.Length=0 Then
If PopupMenu_Category.SelectedRowIndex=0 Then
RS = App.SDP_Database.SelectSQL("SELECT keyword.id,keyword.words,category.label,keyword.negative,keyword.weight " + _
"FROM category " + _
"INNER Join keyword ON category.id = keyword.id_category " + _
"WHERE active=1 " + _
"ORDER BY keyword.negative,keyword.words")
Else
RS = App.SDP_Database.SelectSQL("SELECT keyword.id,keyword.words,category.label,keyword.negative,keyword.weight " + _
"FROM category " + _
"INNER Join keyword ON category.id = keyword.id_category " + _
"WHERE active=1 AND id_category=? " + _
"ORDER BY keyword.negative,keyword.words", PopupMenu_Category.RowTagAt(PopupMenu_Category.SelectedRowIndex).IntegerValue)
End If
Else
Var Filter As String = SearchField_Filter.Text.Trim
Filter = "%" + Filter.ReplaceAll(" ","%") + "%"
If PopupMenu_Category.SelectedRowIndex=0 Then
RS = App.SDP_Database.SelectSQL("SELECT keyword.id,keyword.words,category.label,keyword.negative,keyword.weight " + _
"FROM category " + _
"INNER Join keyword ON category.id = keyword.id_category " + _
"WHERE active=1 AND keyword.words LIKE ? " + _
"ORDER BY keyword.negative,keyword.words", Filter)
Else
RS = App.SDP_Database.SelectSQL("SELECT keyword.id,keyword.words,category.label,keyword.negative,keyword.weight " + _
"FROM category " + _
"INNER Join keyword ON category.id = keyword.id_category " + _
"WHERE active=1 AND keyword.words LIKE ? AND id_category=? " + _
"ORDER BY keyword.negative,keyword.words", Filter, PopupMenu_Category.RowTagAt(PopupMenu_Category.SelectedRowIndex).IntegerValue)
End If
End If
If RS <> Nil Then
ListBox_PromptWords.RemoveAllRows
While Not RS.AfterLastRow
ListBox_PromptWords.AddRow("", RS.Column("words").StringValue, Format(RS.Column("weight").DoubleValue, "0.0"), "", RS.Column("label").StringValue,"999999")
ListBox_PromptWords.CellCheckBoxValueAt(ListBox_PromptWords.LastAddedRowIndex,3) = RS.Column("negative").BooleanValue
If CurrentPreset<>Nil Then
ListBox_PromptWords.CellTextAt(ListBox_PromptWords.LastAddedRowIndex,5) = Format(CurrentPreset.Keyword_Position_Get(RS.Column("id").IntegerValue), "000000")
End If
If ListBox_PromptWords.CellTextAt(ListBox_PromptWords.LastAddedRowIndex,5) <> "999999" Then
ListBox_PromptWords.CellCheckBoxValueAt(ListBox_PromptWords.LastAddedRowIndex,0) = True
End If
ListBox_PromptWords.RowTagAt(ListBox_PromptWords.LastAddedRowIndex) = RS.Column("id").IntegerValue
RS.MoveToNextRow
Wend
If ListBox_PromptWords.RowCount>0 Then ListBox_PromptWords.SelectedRowIndex=0
End If
Catch err As DatabaseException
System.Log(System.LogLevelError, CurrentMethodName + " - Error Code: " + err.ErrorNumber.ToString + EndOfLine + "Error Message: " + err.Message)
End Try
ListBox_PromptWords.Sort
End Sub
#tag EndMethod
#tag Method, Flags = &h0
Sub Keywords_PositionUpdate()
If ListBox_PromptWords.RowCount=0 Then Return
For Y As Integer = 0 To CurrentPreset.Keywords.LastIndex
For X As Integer = 0 To ListBox_PromptWords.LastRowIndex
If ListBox_PromptWords.RowTagAt(X).IntegerValue=CurrentPreset.Keywords(Y).DatabaseID Then
CurrentPreset.Keywords(Y).Position = X
Exit For X
End If
Next
Next
End Sub
#tag EndMethod
#tag Method, Flags = &h0
Sub Keywords_PositionUsualOrder()
If ListBox_PromptWords.RowCount=0 Then Return
Var x,y As Integer
Var rs As RowSet
Try
rs = App.SDP_Database.SelectSQL("SELECT preset_keyword.id_keyword As id, " + _
"AVG( preset_keyword.position ) As position , " + _
"keyword.negative As negative " + _
"FROM preset " + _
"INNER JOIN preset_keyword ON preset.id = preset_keyword.id_preset " + _
"INNER JOIN keyword ON keyword.id = preset_keyword.id_keyword " + _
"GROUP BY position " + _
"ORDER BY negative,position")
If rs=Nil Then Return
While Not rs.AfterLastRow
For Y = 0 To CurrentPreset.Keywords.LastIndex
If rs.Column("id").IntegerValue=CurrentPreset.Keywords(Y).DatabaseID Then
CurrentPreset.Keywords(Y).Position = X
X = X + 1
Exit For Y
End If
Next
rs.MoveToNextRow
Wend
For X = 0 To ListBox_PromptWords.LastRowIndex
ListBox_PromptWords.CellTextAt(X,5)="999999"
For Y = 0 To CurrentPreset.Keywords.LastIndex
If CurrentPreset.Keywords(Y).DatabaseID = ListBox_PromptWords.RowTagAt(X) Then
ListBox_PromptWords.CellTextAt(X,5)=Format(CurrentPreset.Keywords(Y).Position, "000000")
ListBox_PromptWords.CellTextAt(X,2)=Format(CurrentPreset.Keywords(Y).Weight, "0.0")
Exit For Y
End If
Next
Next
ListBox_PromptWords.Sort
Keywords_PositionUpdate
Catch err As DatabaseException
System.Log(System.LogLevelError, CurrentMethodName + " - Error Code: " + err.ErrorNumber.ToString + EndOfLine + "Error Message: " + err.Message)
End Try
End Sub
#tag EndMethod
#tag Method, Flags = &h0
Sub Keywords_Select(Keywords() As String)
If Keywords.Count=0 Then Return
If ListBox_PromptWords.RowCount=0 Then Return
For Y As Integer = 0 To Keywords.LastIndex
For X As Integer = 0 To ListBox_PromptWords.LastRowIndex
If ListBox_PromptWords.CellTextAt(X,1)=Keywords(Y) Then
CurrentPreset.Keyword_Add(ListBox_PromptWords.RowTagAt(X).IntegerValue)
ListBox_PromptWords.CellCheckBoxValueAt(X,0)=True
End If
Next
Next
Prompt_Show
End Sub
#tag EndMethod
#tag Method, Flags = &h0
Sub Keyword_Disable()
If ListBox_PromptWords.SelectedRowIndex = -1 Then Return
If ListBox_PromptWords.SelectedRowCount>1 Then
If Not Show_MessageDialog(MessageDialog.IconTypes.Question, "Delete selected Keywords", "Cancel", "Delete selected Keyword(s)", _
"Are you sure you want to delete the selected " + ListBox_PromptWords.SelectedRowCount.ToString + " Keywords?") Then Return
End If
// If the DesktopListBox is in multiple-row selection mode,
// then the number of the lowest selected row is returned.
// For example, if rows 1 and 4 are selected, it returns a 1.
Var SelectedIndex As Integer = ListBox_PromptWords.SelectedRowIndex
For X As Integer = ListBox_PromptWords.LastRowIndex DownTo 0
If ListBox_PromptWords.RowSelectedAt(X) Then
Var KW As New Class_Keyword(ListBox_PromptWords.RowTagAt(X).IntegerValue)
CurrentPreset.Keyword_Remove(KW)
Call KW.Disable
End If
Next
Keywords_List
If SelectedIndex<ListBox_PromptWords.RowCount Then ListBox_PromptWords.SelectedRowIndex=SelectedIndex
End Sub
#tag EndMethod
#tag Method, Flags = &h0
Sub Keyword_Save()
If PopupMenu_Category.SelectedRowIndex=0 Then PopupMenu_Category.SelectedRowIndex=1
Var KW As New Class_Keyword(0)
KW.Keyword=SearchField_Filter.Text.Trim
KW.CategoryID=PopupMenu_Category.RowTagAt(PopupMenu_Category.SelectedRowIndex).IntegerValue
If KW.Save Then
Keywords_List
End If
End Sub
#tag EndMethod
#tag Method, Flags = &h0
Sub Prompt_Show()
Var s(1) As String = CurrentPreset.Prompt_Generate
TextArea_PromptPositive.Text = s(0)
TextArea_PromptNegative.Text = s(1)
End Sub
#tag EndMethod
#tag Method, Flags = &h21
Private Sub Tooltip_RemoveFromKeywords()
ListBox_PromptWords.Tooltip=""
End Sub
#tag EndMethod
#tag EndWindowCode
#tag Events SearchField_Filter
#tag Event
Sub Pressed()
Keywords_List
End Sub
#tag EndEvent
#tag Event
Sub TextChanged()
Keywords_List
End Sub
#tag EndEvent
#tag EndEvents
#tag Events PushButton_Save_Keyword
#tag Event
Sub Action()
Keyword_Save
End Sub
#tag EndEvent
#tag EndEvents
#tag Events PushButton_Delete_Keyword
#tag Event
Sub Action()
Keyword_Disable
End Sub
#tag EndEvent
#tag EndEvents
#tag Events PopupMenu_Category
#tag Event
Sub SelectionChanged(item As DesktopMenuItem)
#Pragma unused item
Keywords_List
End Sub
#tag EndEvent
#tag Event
Sub Opening()
Me.Load_Categorys
Me.Enabled = True
End Sub
#tag EndEvent
#tag EndEvents
#tag Events ListBox_PromptWords
#tag Event
Sub Opening()
Me.ColumnTypeAt(0) = DesktopListBox.CellTypes.CheckBox
Me.ColumnTypeAt(1) = DesktopListBox.CellTypes.TextField
Me.ColumnTypeAt(2) = DesktopListBox.CellTypes.TextField
Me.ColumnTypeAt(3) = DesktopListBox.CellTypes.CheckBox
Me.ColumnAlignmentAt(2) = DesktopListBox.Alignments.Decimal
Me.ColumnAlignmentAt(3) = DesktopListBox.Alignments.Center
Me.ColumnAlignmentOffsetAt(2) = -Me.ColumnAttributesAt(2).WidthActual/2
Me.ColumnSortDirectionAt(-1) = DesktopListbox.SortDirections.None
Me.SortingColumn=5
Me.ColumnSortDirectionAt(5) = DesktopListbox.SortDirections.Ascending
End Sub
#tag EndEvent
#tag Event
Sub CellAction(row As Integer, column As Integer)
#Pragma unused column
If row>-1 And row<Me.RowCount Then
Me.SelectedRowIndex=row
Var KW As New Class_Keyword(Me.RowTagAt(row).IntegerValue)
KW.Keyword = Me.CellTextAt(row,1).Trim
KW.Weight = Me.CellTextAt(row,2).ToDouble
KW.Negative = Me.CellCheckBoxValueAt(row,3)
KW.Position = row
Call KW.Save
If KW.DatabaseID>0 Then
If Me.CellCheckBoxValueAt(row,0) Then
CurrentPreset.Keyword_Add(KW)
Else
CurrentPreset.Keyword_Remove(KW)
End If
Me.Refresh
Prompt_Show
End If
End If
End Sub
#tag EndEvent
#tag Event
Function ConstructContextualMenu(base As DesktopMenuItem, x As Integer, y As Integer) As Boolean
#Pragma unused y
#Pragma unused x
base.AddMenu(New DesktopMenuItem("Deselect all"))
base.AddMenu(New DesktopMenuItem(DesktopMenuItem.TextSeparator))
base.AddMenu(New DesktopMenuItem("Delete Keyword"))
End Function
#tag EndEvent
#tag Event
Function ContextualMenuItemSelected(selectedItem As DesktopMenuItem) As Boolean
Select Case selectedItem.Text
Case "Deselect all"
Keywords_DeselectAll
Case "Delete Keyword"
Keyword_Disable
End Select
End Function
#tag EndEvent
#tag Event
Sub DoublePressed()
If Not Me.CellCheckBoxValueAt(Me.SelectedRowIndex,0) Then Return
If PopupMenu_Category.SelectedRowIndex>0 Then Return
Me.AddRowAt(0, "")
Me.CellCheckBoxValueAt(0,0)=True
Me.CellTextAt(0,1)=Me.CellTextAt(Me.SelectedRowIndex,1)
Me.CellTextAt(0,2)=Me.CellTextAt(Me.SelectedRowIndex,2)
Me.CellCheckBoxValueAt(0,3)=Me.CellCheckBoxValueAt(Me.SelectedRowIndex,3)
Me.CellTextAt(0,4)=Me.CellTextAt(Me.SelectedRowIndex,4)
Me.CellTagAt(0,4)=Me.CellTagAt(Me.SelectedRowIndex,4).IntegerValue
Me.RowTagAt(0)=Me.RowTagAt(Me.SelectedRowIndex)
Me.RemoveRowAt(Me.SelectedRowIndex)
End Sub
#tag EndEvent
#tag Event
Sub MouseEnter()
Timer.CallLater(30000, AddressOf Tooltip_RemoveFromKeywords)
End Sub
#tag EndEvent
#tag Event
Sub KeyUp(key As String)
If Me.SelectedRowIndex>-1 Then
Var KW As New Class_Keyword(Me.RowTagAt(Me.SelectedRowIndex).IntegerValue)
Select Case key.Asc
Case 32
Me.CellCheckBoxValueAt(Me.SelectedRowIndex,0) = Not Me.CellCheckBoxValueAt(Me.SelectedRowIndex,0)
If KW.DatabaseID>0 Then
KW.Weight = Me.CellTextAt(Me.SelectedRowIndex,2).ToDouble
KW.Negative = Me.CellCheckBoxValueAt(Me.SelectedRowIndex,3)
KW.Position = Me.SelectedRowIndex
If Me.CellCheckBoxValueAt(Me.SelectedRowIndex,0) Then
CurrentPreset.Keyword_Add(KW)
Else
CurrentPreset.Keyword_Remove(KW)
End If
Prompt_Show
End If
End Select
End If
End Sub
#tag EndEvent
#tag EndEvents
#tag Events TextArea_PromptPositive
#tag Event
Sub TextChanged()
Label_PositivePrompt_Length.Text = "Token counter (estimated): " + CalculateTokenCount(Me.Text).ToString
End Sub
#tag EndEvent
#tag EndEvents
#tag Events PushButton_Copy_PromptPositive
#tag Event
Sub Action()
Var c As New Clipboard
c.Text = TextArea_PromptPositive.Text.Trim
End Sub
#tag EndEvent
#tag EndEvents
#tag Events TextArea_PromptNegative
#tag Event
Sub TextChanged()
Label_NegativePrompt_Length.Text = "Token counter (estimated): " + CalculateTokenCount(Me.Text).ToString
End Sub
#tag EndEvent
#tag EndEvents
#tag Events PushButton_Copy_PromptNegative
#tag Event
Sub Action()
Var c As New Clipboard
c.Text = TextArea_PromptNegative.Text.Trim
End Sub
#tag EndEvent
#tag EndEvents
#tag Events Button_SendToSDHost
#tag Event
Sub Pressed()
If App.SD_Host.HostAddress.Trim <> "" And App.SD_Host.HostPort > 0 Then
If App.SD_Host.Use_Model Then
App.SD_Host.Model = Window_Main.Cont_Preset.ComboBox_PresetModel.Text
End If
App.SD_Host.SendPrompt(TextArea_PromptPositive.Text.Trim, TextArea_PromptNegative.Text.Trim)
End If
End Sub
#tag EndEvent
#tag EndEvents
#tag ViewBehavior