Skip to content

Commit

Permalink
Add Combobox.ComboboxSelected() and Text_Modified()
Browse files Browse the repository at this point in the history
  • Loading branch information
cdhigh committed Feb 20, 2024
1 parent 6a65da4 commit 11d9dad
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 50 deletions.
21 changes: 13 additions & 8 deletions Base64.bas
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,29 @@ Option Explicit
'外部直接调用此函数即可
Public Sub Base64Encode(ByRef pbAInput() As Byte, ByRef sOut As String, Optional ByRef sPrexSpace As String = "", Optional ByRef charsPerLine As Integer = 68)

Dim abOut() As Byte, i As Long, s As String
Dim abOut() As Byte, idx As Long, sBase64 As String
Dim lengthMod As Integer
Dim paddingCount As Integer

Encode pbAInput, abOut

ByteArrayToString abOut, s

ByteArrayToString abOut, sBase64
sOut = ""
If Len(sBase64) = 0 Then Exit Sub

If Len(s) = 0 Then Exit Sub
'Base64要求长度为4的倍数,如果不够,则添加"="
lengthMod = Len(sBase64) Mod 4
paddingCount = 4 - lengthMod
sBase64 = sBase64 & String(paddingCount, "=")

'转换为合适的换行模式
If charsPerLine > 0 Then
For i = 1 To Len(s) Step charsPerLine
sOut = sOut & sPrexSpace & Mid(s, i, charsPerLine) & vbCrLf
For idx = 1 To Len(sBase64) Step charsPerLine
sOut = sOut & sPrexSpace & Mid(sBase64, idx, charsPerLine) & vbCrLf
Next
sOut = Mid(sOut, 1, Len(sOut) - 3)
sOut = Mid(sOut, 1, Len(sOut) - 3) '去掉上面语句添加的最后的回车换行
Else
sOut = s
sOut = sBase64
End If

End Sub
Expand Down
4 changes: 4 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ Readme of english version refers to [Readme_EN.md](https://github.com/cdhigh/tki


# 版本历史
* v1.7.1
1. Combobox的Change事件映射到Tkinter的ComboboxSelected
2. 多行Text的Change事件映射到Tkinter的Modified
3. 修正base64编码的一个小bug,之前的版本将末尾填充的=去掉了,导致有些解码库报错
* v1.7
1. 插件名从 TkinterDesigner 更名为 Vb6Tkinter
2. 增加在线检查版本更新功能
Expand Down
6 changes: 3 additions & 3 deletions Vb6Tkinter.vbp
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,17 @@ Startup="(None)"
HelpFile=""
Title="Vb6Tkinter"
ExeName32="Vb6Tkinter.dll"
Path32="Bin"
Path32="Release"
Command32=""
Name="Vb6Tkinter"
HelpContextID="0"
Description="VB6 Tkinter Designer"
CompatibleMode="2"
CompatibleEXE32="Bin\Vb6Tkinter.dll"
CompatibleEXE32="Release\Vb6Tkinter.dll"
VersionCompatible32="1"
MajorVer=1
MinorVer=7
RevisionVer=0
RevisionVer=1
AutoIncrementVer=0
ServerSupportFiles=0
DllBaseAddress=&H1f390000
Expand Down
14 changes: 7 additions & 7 deletions Vb6Tkinter.vbw
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GridOcx = 125, 125, 851, 574, C, 175, 175, 1048, 606, C
Common = 125, 125, 998, 556, C
FileDlg = 150, 150, 981, 581, C
clsBaseControl = 100, 100, 931, 531, C
clsBaseControl = 100, 100, 931, 531, Z
clsButton = 75, 75, 906, 506, C
clsCanvas = 0, 0, 0, 0, C
clsCheckbutton = 0, 0, 0, 0, C
Expand All @@ -17,16 +17,16 @@ clsSerialization = 0, 0, 0, 0, C
clsText = 0, 0, 879, 406, C
cStrBuilder = 0, 0, 0, 0, C
Dictionary = 0, 0, 0, 0, C
FrmMain = 25, 25, 898, 456, C, 50, 50, 923, 481, C
FrmMain = 25, 25, 898, 456, , 50, 50, 923, 481, C
clsMenu = 0, 0, 0, 0, C
clsMenuItem = 0, 0, 0, 0, C
clsProgressBar = 0, 0, 0, 0, C
clsCombobox = 175, 175, 1054, 581, C
clsComboboxAdapter = 0, 0, 0, 0, C
clsCombobox = 175, 175, 1054, 581,
clsComboboxAdapter = 25, 25, 799, 474,
clsTreeview = 200, 200, 1079, 606, C
clsNotebook = 50, 50, 929, 456, C
MultiLanguage = 175, 175, 1054, 608, Z
Base64 = 0, 0, 0, 0, C
MultiLanguage = 175, 175, 1054, 608,
Base64 = 100, 100, 874, 549,
clsForm = 125, 125, 956, 556, C
clsStatusbar = 75, 75, 801, 497, C
Resizer = 100, 100, 826, 549, C
Expand All @@ -35,7 +35,7 @@ xpcmdbutton = 0, 0, 0, 0, C, 0, 0, 873, 431, C
clsNotebookTab = 0, 0, 0, 0, C
clsSeparator = 0, 0, 0, 0, C
Connect = 25, 25, 904, 458,
frmEncodeAFile = 100, 100, 973, 531, C, 25, 25, 898, 456, C
frmEncodeAFile = 100, 100, 973, 531, , 25, 25, 898, 456, C
http = 125, 125, 1004, 558, C
modJson = 25, 25, 904, 458, C
frmNewVer = 100, 100, 979, 533, C, 75, 75, 954, 508, C
Expand Down
84 changes: 52 additions & 32 deletions clsBaseControl.cls
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ End Sub
'输出结构化代码
Public Sub toStringStructure(ByRef sOut As cStrBuilder, ByRef sCmdFunc As cStrBuilder, rel As Boolean, usettk As Boolean, Optional sOtherParams As String = "")

Dim s() As String, i As Long, extra As String, sStyle As String
Dim s() As String, I As Long, extra As String, sStyle As String
Dim sTmp As String, dTmp As Double, sCmdName As String, sUnderlineCmd As String

'如果需要变量绑定,则先创建对应的变量
Expand Down Expand Up @@ -186,32 +186,32 @@ Public Sub toStringStructure(ByRef sOut As cStrBuilder, ByRef sCmdFunc As cStrBu
sTmp = Replace(sTmp, " ", "")

s = Split(sTmp, ",")
For i = 0 To UBound(s)
s(i) = Trim(s(i))
If s(i) = "<Change>" Then '专门处理自定义的这个事件,用控件变量监视器模拟
For I = 0 To UBound(s)
s(I) = Trim(s(I))
If s(I) = "<Change>" Then '专门处理自定义的这个事件,用控件变量监视器模拟
If (m_Type = "Combobox" Or m_Type = "Entry" Or m_Type = "Label") And (Len(Dic("textvariable")) > 0) Then
sCmdName = m_Name & "_Change"
sOut.Append Space(4) & Dic("textvariable") & ".trace('w', " & sCmdName & ")"
sCmdFunc.Append CreateFuncDef(sCmdName, "*args")
End If
ElseIf Left(s(i), 1) = "<" And Right(s(i), 1) = ">" Then
ElseIf Left(s(I), 1) = "<" And Right(s(I), 1) = ">" Then

sCmdName = m_Name & "_" & Replace(Replace(Replace(s(i), "<", ""), ">", ""), "-", "_")
sCmdName = m_Name & "_" & Replace(Replace(Replace(s(I), "<", ""), ">", ""), "-", "_")

sOut.Append Space(4) & m_Name & ".bind('" & s(i) & "', " & sCmdName & ")"
sOut.Append Space(4) & m_Name & ".bind('" & s(I) & "', " & sCmdName & ")"

sCmdFunc.Append CreateFuncDef(sCmdName, "event")

'Python是大小写敏感的,对应快捷键也一样,如果设置的快捷键包含字母键,则将对应的大写/小写也一起绑定
If Right(s(i), 3) >= "-a>" And Right(s(i), 3) <= "-z>" Then
If Right(s(I), 3) >= "-a>" And Right(s(I), 3) <= "-z>" Then

s(i) = Left(s(i), Len(s(i)) - 2) & UCase(Mid(s(i), Len(s(i)) - 1, 1)) & ">" '对应字母变大写
sOut.Append Space(4) & m_Name & ".bind('" & s(i) & "', " & sCmdName & ")"
s(I) = Left(s(I), Len(s(I)) - 2) & UCase(Mid(s(I), Len(s(I)) - 1, 1)) & ">" '对应字母变大写
sOut.Append Space(4) & m_Name & ".bind('" & s(I) & "', " & sCmdName & ")"

ElseIf Right(s(i), 3) >= "-A>" And Right(s(i), 3) <= "-Z>" Then
ElseIf Right(s(I), 3) >= "-A>" And Right(s(I), 3) <= "-Z>" Then

s(i) = Left(s(i), Len(s(i)) - 2) & LCase(Mid(s(i), Len(s(i)) - 1, 1)) & ">" '对应字母变小写
sOut.Append Space(4) & m_Name & ".bind('" & s(i) & "', " & sCmdName & ")"
s(I) = Left(s(I), Len(s(I)) - 2) & LCase(Mid(s(I), Len(s(I)) - 1, 1)) & ">" '对应字母变小写
sOut.Append Space(4) & m_Name & ".bind('" & s(I) & "', " & sCmdName & ")"

End If
End If
Expand All @@ -223,7 +223,7 @@ End Sub
'输出面向对象代码
Public Sub toStringOOP(ByRef sOut As cStrBuilder, ByRef sCmdFunc As cStrBuilder, rel As Boolean, usettk As Boolean, Optional sOtherParams As String = "")

Dim s() As String, i As Long, extra As String
Dim s() As String, I As Long, extra As String
Dim sTmp As String, sStyle As String, sCmdName As String, sUnderlineCmd As String

'如果需要变量绑定,则先创建对应的变量
Expand Down Expand Up @@ -353,31 +353,31 @@ Public Sub toStringOOP(ByRef sOut As cStrBuilder, ByRef sCmdFunc As cStrBuilder,
sTmp = Replace(sTmp, " ", "")

s = Split(sTmp, ",")
For i = 0 To UBound(s)
s(i) = Trim(s(i))
If s(i) = "<Change>" Then '专门处理自定义的这个事件,用控件变量监视器模拟
For I = 0 To UBound(s)
s(I) = Trim(s(I))
If s(I) = "<Change>" Then '专门处理自定义的这个事件,用控件变量监视器模拟
If (m_Type = "Combobox" Or m_Type = "Entry" Or m_Type = "Label") And (Len(Dic("textvariable")) > 0) Then
sCmdName = m_Name & "_Change"
sOut.Append Space(8) & "self." & Dic("textvariable") & ".trace('w', self." & sCmdName & ")"
sCmdFunc.Append CreateFuncDefOOP(sCmdName, "*args")
End If
ElseIf Left(s(i), 1) = "<" And Right(s(i), 1) = ">" Then
ElseIf Left(s(I), 1) = "<" And Right(s(I), 1) = ">" Then

sCmdName = m_Name & "_" & Replace(Replace(Replace(s(i), "<", ""), ">", ""), "-", "_")
sCmdName = m_Name & "_" & Replace(Replace(Replace(s(I), "<", ""), ">", ""), "-", "_")

sOut.Append Space(8) & "self." & m_Name & ".bind('" & s(i) & "', self." & sCmdName & ")"
sOut.Append Space(8) & "self." & m_Name & ".bind('" & s(I) & "', self." & sCmdName & ")"
sCmdFunc.Append CreateFuncDefOOP(sCmdName, "event")

'Python是大小写敏感的,对应快捷键也一样,如果设置的快捷键包含字母键,则将对应的大写/小写也一起绑定
If Right(s(i), 3) >= "-a>" And Right(s(i), 3) <= "-z>" Then
If Right(s(I), 3) >= "-a>" And Right(s(I), 3) <= "-z>" Then

s(i) = Left(s(i), Len(s(i)) - 2) & UCase(Mid(s(i), Len(s(i)) - 1, 1)) & ">" '变大写
sOut.Append Space(8) & "self." & m_Name & ".bind('" & s(i) & "', self." & sCmdName & ")"
s(I) = Left(s(I), Len(s(I)) - 2) & UCase(Mid(s(I), Len(s(I)) - 1, 1)) & ">" '变大写
sOut.Append Space(8) & "self." & m_Name & ".bind('" & s(I) & "', self." & sCmdName & ")"

ElseIf Right(s(i), 3) >= "-A>" And Right(s(i), 3) <= "-Z>" Then
ElseIf Right(s(I), 3) >= "-A>" And Right(s(I), 3) <= "-Z>" Then

s(i) = Left(s(i), Len(s(i)) - 2) & LCase(Mid(s(i), Len(s(i)) - 1, 1)) & ">" '变小写
sOut.Append Space(8) & "self." & m_Name & ".bind('" & s(i) & "', self." & sCmdName & ")"
s(I) = Left(s(I), Len(s(I)) - 2) & LCase(Mid(s(I), Len(s(I)) - 1, 1)) & ">" '变小写
sOut.Append Space(8) & "self." & m_Name & ".bind('" & s(I) & "', self." & sCmdName & ")"

End If
End If
Expand Down Expand Up @@ -534,6 +534,10 @@ Public Function GetBindCommandStr(dMethods As Dictionary) As String
If InStr(1, s, "," & m_Name & "_MouseDown,") > 0 Then sOut.Append "<Button-1>"
ElseIf m_Type = "Listbox" Then
If InStr(1, s, "," & m_Name & "_Click,") > 0 Then sOut.Append "<<ListboxSelect>>"
ElseIf m_Type = "Combobox" Then
If InStr(1, s, "," & m_Name & "_Change,") > 0 Then sOut.Append "<<ComboboxSelected>>"
ElseIf m_Type = "Text" Then
If InStr(1, s, "," & m_Name & "_Change,") > 0 Then sOut.Append "<<Modified>>"
ElseIf m_Type <> "Notebook" Then
If InStr(1, s, "," & m_Name & "_Click,") > 0 Or InStr(1, s, "," & m_Name & "_MouseDown,") > 0 Then sOut.Append "<Button-1>"
End If
Expand All @@ -548,7 +552,9 @@ Public Function GetBindCommandStr(dMethods As Dictionary) As String
If InStr(1, s, "," & m_Name & "_Enter,") > 0 Or InStr(1, s, "," & m_Name & "_MouseMove,") > 0 Then sOut.Append "<Motion>"
If InStr(1, s, "," & m_Name & "_Leave,") > 0 Then sOut.Append "<Leave>"

If InStr(1, s, "," & m_Name & "_Change,") > 0 Then sOut.Append "<Change>" '这个事件由内部处理,不是标准tk事件
If m_Type <> "Combobox" And m_Type <> "Text" And InStr(1, s, "," & m_Name & "_Change,") > 0 Then
sOut.Append "<Change>" '这个事件由内部处理,不是标准tk事件
End If

If m_Type = "Treeview" Then
If InStr(1, s, "," & m_Name & "_NodeClick,") > 0 Then sOut.Append "<<TreeviewSelect>>"
Expand Down Expand Up @@ -599,15 +605,15 @@ End Function

'将用户选择的配置更新到对象中,参数为使用"|"分割的很多对属性/值对
Public Sub SetConfig(sAttrs As String)
Dim sa() As String, i As Long
Dim sa() As String, I As Long

sa = Split(sAttrs, "|")
Debug.Assert (UBound(sa) Mod 1 = 0)

m_dic.RemoveAll

For i = 0 To UBound(sa) - 1 Step 2
m_dic(sa(i)) = sa(i + 1)
For I = 0 To UBound(sa) - 1 Step 2
m_dic(sa(I)) = sa(I + 1)
Next

End Sub
Expand Down Expand Up @@ -803,6 +809,7 @@ End Sub

'构建一个函数空骨架; FuncName: 函数名,Params: 参数,sbody: 函数体
Public Function CreateFuncDef(funcName As String, Optional sparams As String = "", Optional sbody As String = "") As String
Dim txtMod As String, widgetName As String
If Len(funcName) = 0 Then Exit Function
CreateFuncDef = "def " & funcName & "(" & sparams & "):" & vbCrLf
If Len(sbody) Then
Expand All @@ -812,13 +819,20 @@ Public Function CreateFuncDef(funcName As String, Optional sparams As String = "
CreateFuncDef = CreateFuncDef & Space(4) & "print('" & funcName & "')" & vbCrLf
#Else
CreateFuncDef = CreateFuncDef & Space(4) & "#TODO, Please finish the function here!" & vbCrLf
CreateFuncDef = CreateFuncDef & Space(4) & "pass" & vbCrLf
txtMod = "_Modified"
If m_Type = "Text" And Right(funcName, Len(txtMod)) = txtMod Then
widgetName = Left(funcName, Len(funcName) - Len(txtMod))
CreateFuncDef = CreateFuncDef & Space(4) & widgetName & ".edit_modified(False)" & vbCrLf
Else
CreateFuncDef = CreateFuncDef & Space(4) & "pass" & vbCrLf
End If
#End If
End If
End Function

'构建一个函数空骨架(面向对象代码); FuncName: 函数名,Params: 参数,sbody: 函数体
Public Function CreateFuncDefOOP(funcName As String, Optional sparams As String = "", Optional sbody As String = "") As String
Dim txtMod As String, widgetName As String
If Len(funcName) = 0 Then Exit Function
CreateFuncDefOOP = " def " & funcName & "(self" & IIf(Len(sparams), ", ", "") & sparams & "):" & vbCrLf
If Len(sbody) Then
Expand All @@ -828,7 +842,13 @@ Public Function CreateFuncDefOOP(funcName As String, Optional sparams As String
CreateFuncDefOOP = CreateFuncDefOOP & Space(8) & "print('" & funcName & "')" & vbCrLf
#Else
CreateFuncDefOOP = CreateFuncDefOOP & Space(8) & "#TODO, Please finish the function here!" & vbCrLf
CreateFuncDefOOP = CreateFuncDefOOP & Space(8) & "pass" & vbCrLf
txtMod = "_Modified"
If m_Type = "Text" And Right(funcName, Len(txtMod)) = txtMod Then
widgetName = Left(funcName, Len(funcName) - Len(txtMod))
CreateFuncDefOOP = CreateFuncDefOOP & Space(8) & "self." & widgetName & ".edit_modified(False)" & vbCrLf
Else
CreateFuncDefOOP = CreateFuncDefOOP & Space(8) & "pass" & vbCrLf
End If
#End If
End If
End Function
Expand Down

0 comments on commit 11d9dad

Please sign in to comment.