Skip to content

Commit 7067be1

Browse files
committed
v1.9
add i18n
1 parent 3b3f5cd commit 7067be1

30 files changed

+390
-312
lines changed

MainForm.frm

Lines changed: 47 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,9 @@ Begin VB.Form FrmMain
300300
Caption = "Use Relative Position(&R)"
301301
Checked = -1 'True
302302
End
303+
Begin VB.Menu mnuI18n
304+
Caption = "Support i18n(&I)"
305+
End
303306
Begin VB.Menu mnuUnicodePrefixU
304307
Caption = "Add A Prefix 'u' to Unicode String(&U)"
305308
End
@@ -398,6 +401,7 @@ Private Sub Form_Load()
398401
mnuV2andV3Code.Checked = GetSetting(App.Title, "Settings", "V2andV3Code", "0") = "1"
399402
mnuUseTtk.Checked = GetSetting(App.Title, "Settings", "UseTtk", "1") = "1"
400403
mnuRelPos.Checked = GetSetting(App.Title, "Settings", "RelPos", "1") = "1"
404+
mnuI18n.Checked = GetSetting(App.Title, "Settings", "i18n", "1") = "1"
401405
mnuUnicodePrefixU.Checked = GetSetting(App.Title, "Settings", "UnicodePrefix", "0") = "1"
402406
g_bUnicodePrefixU = mnuUnicodePrefixU.Checked
403407

@@ -937,11 +941,12 @@ Private Sub TryAssignScrollbar2Widgets()
937941

938942
End Sub
939943

944+
'创建代码
940945
Private Sub CmdGenCode_Click()
941-
942-
Dim I As Long, cnt As Long, o As Object
943-
Dim strHead As New cStrBuilder, strOut As New cStrBuilder, strCmd As New cStrBuilder, s As String, finalCode As String, sF As String
944-
Dim OutOnlyV3 As Boolean, OutRelPos As Boolean, usettk As Boolean
946+
Dim I As Long, cnt As Long, o As Object, sysImport As String
947+
Dim strHead As New cStrBuilder, strOut As New cStrBuilder, strCmd As New cStrBuilder, strI18n As New cStrBuilder, strTmp As New cStrBuilder
948+
Dim s As String, finalCode As String, sF As String
949+
Dim OutOnlyV3 As Boolean, OutRelPos As Boolean, i18n As Boolean, usettk As Boolean
945950
Dim bUnicodePrefix As Boolean '临时保存UNICODE前缀方式
946951
Dim aCompsSorted() As Object '用于排序的代码输出
947952

@@ -962,9 +967,10 @@ Private Sub CmdGenCode_Click()
962967

963968
OutOnlyV3 = Not mnuV2andV3Code.Checked
964969
OutRelPos = mnuRelPos.Checked
970+
i18n = mnuI18n.Checked
965971
usettk = mnuUseTtk.Checked
966972

967-
'绝对坐标
973+
'绝对坐标BUG提示
968974
' If Not OutRelPos And m_curFrm.Properties("ScaleMode") <> vbTwips Then
969975
' '如果使用绝对坐标,则Frame控件仅支持vbTwips模式
970976
' For Each o In m_curFrm.Designer.VBControls
@@ -983,10 +989,11 @@ Private Sub CmdGenCode_Click()
983989
'在输出代码前先更新一下当前显示的数据
984990
UpdateCfgtoCls LstComps.ListIndex
985991

992+
sysImport = IIf(i18n, "import os, sys, gettext", "import os, sys")
986993
If OutOnlyV3 Then '输出仅针对PYTHON 3.X的代码
987994
strHead.Append "#!/usr/bin/env python3"
988995
strHead.Append "#-*- coding:utf-8 -*-" & vbCrLf
989-
strHead.Append "import os, sys"
996+
strHead.Append sysImport
990997
strHead.Append "from tkinter import *"
991998
strHead.Append "from tkinter.font import Font"
992999
If usettk Then strHead.Append "from tkinter.ttk import *"
@@ -1001,7 +1008,7 @@ Private Sub CmdGenCode_Click()
10011008
Else
10021009
strHead.Append "#!/usr/bin/env python"
10031010
strHead.Append "#-*- coding:utf-8 -*-" & vbCrLf
1004-
strHead.Append "import os, sys"
1011+
strHead.Append sysImport
10051012
strHead.Append "if sys.version_info[0] == 2:"
10061013
strHead.Append " from Tkinter import *"
10071014
strHead.Append " from tkFont import Font"
@@ -1047,26 +1054,39 @@ Private Sub CmdGenCode_Click()
10471054
End If
10481055
Next
10491056

1057+
'国际化支持函数头
1058+
If i18n Then
1059+
strI18n.Append vbCrLf & " def retranslateUi(self):"
1060+
End If
1061+
1062+
'命令回调代码块
1063+
strTmp.Reset
1064+
If i18n Then
1065+
strTmp.Append vbCrLf & " tr = gettext.translation('lang', localedir='i18n', languages=['en'], fallback=True)"
1066+
strTmp.Append " tr.install()"
1067+
strTmp.Append " self.retranslateUi()"
1068+
End If
10501069
strCmd.Append vbCrLf
10511070
strCmd.Append "class Application(Application_ui):"
1052-
strCmd.Append " " & L("l_cmtClsApp", "#The class will implement callback function for events and your logical code.")
1053-
strCmd.Append " def __init__(self, master=None):"
1071+
strCmd.Append " def __init__(self, master):"
10541072
If OutOnlyV3 Then
1055-
strCmd.Append " super().__init__(master)" & vbCrLf
1073+
strCmd.Append " super().__init__(master)" & strTmp.toString(vbCrLf) & vbCrLf
10561074
Else
1057-
strCmd.Append " Application_ui.__init__(self, master)" & vbCrLf
1075+
strCmd.Append " Application_ui.__init__(self, master)" & strTmp.toString(vbCrLf) & vbCrLf
10581076
End If
1077+
strTmp.Reset
10591078

1079+
'主GUI代码块
10601080
strOut.Append "class Application_ui(Frame):"
1061-
strOut.Append " " & L("l_cmtClsUi", "#The class will create all widgets for UI.")
1062-
strOut.Append " def __init__(self, master=None):"
1081+
strOut.Append " def __init__(self, master):"
10631082
If OutOnlyV3 Then
10641083
strOut.Append " super().__init__(master)"
10651084
Else
10661085
strOut.Append " Frame.__init__(self, master)"
10671086
End If
1068-
g_Comps(0).toString strOut, strCmd, OutRelPos, usettk 'g_Comps(0)固定是Form
1087+
g_Comps(0).toString strOut, strCmd, strI18n, OutRelPos, usettk 'g_Comps(0)固定是Form
10691088
strOut.Append " self.createWidgets()" & vbCrLf
1089+
10701090
strOut.Append " def createWidgets(self):"
10711091
strOut.Append " self." & WTOP & " = self.winfo_toplevel()" & vbCrLf
10721092
If usettk Then strOut.Append " self.style = Style()" & vbCrLf
@@ -1086,18 +1106,19 @@ Private Sub CmdGenCode_Click()
10861106

10871107
'遍历各控件,由各控件自己输出自己的界面生成代码
10881108
For I = 0 To cnt - 1
1089-
aCompsSorted(I).toString strOut, strCmd, OutRelPos, usettk
1109+
aCompsSorted(I).toString strOut, strCmd, strI18n, OutRelPos, usettk
10901110
strOut.Append "" '两个控件之间使用一个空行隔开
10911111
Next
10921112

1093-
'输出到文本框
1113+
'拼接各部分代码,输出到文本框
1114+
If Not i18n Then
1115+
strI18n.Reset
1116+
End If
10941117
strCmd.Append "if __name__ == ""__main__"":"
10951118
strCmd.Append " " & WTOP & " = Tk()"
10961119
strCmd.Append " Application(" & WTOP & ").mainloop()"
10971120
strCmd.Append vbCrLf
1098-
'strCmd.Append " try: " & WTOP & ".destroy()"
1099-
'strCmd.Append " except: pass" & vbCrLf
1100-
finalCode = strHead.toString(vbCrLf) & strOut.toString(vbCrLf) & strCmd.toString(vbCrLf)
1121+
finalCode = strHead.toString(vbCrLf) & strOut.toString(vbCrLf) & strI18n.toString(vbCrLf) & strCmd.toString(vbCrLf)
11011122

11021123
'VB的TEXTBOX最多支持65K文本
11031124
If Len(finalCode) > 65000 Then
@@ -1117,9 +1138,9 @@ Private Sub CmdGenCode_Click()
11171138
strOut.Reset
11181139
strHead.Reset
11191140
strCmd.Reset
1141+
strI18n.Reset
11201142

11211143
g_bUnicodePrefixU = bUnicodePrefix '恢复UNICODE前缀模式
1122-
11231144
End Sub
11241145

11251146
'输入自定义的Tooltip类
@@ -1549,8 +1570,13 @@ Private Sub mnuGenCode_Click()
15491570
CmdGenCode_Click
15501571
End Sub
15511572

1573+
Private Sub mnuI18n_Click()
1574+
Dim o As Object
1575+
mnuI18n.Checked = Not mnuI18n.Checked
1576+
SaveSetting App.Title, "Settings", "i18n", IIf(mnuI18n.Checked, "1", "0")
1577+
End Sub
1578+
15521579
Private Sub mnuLng_Click(Index As Integer)
1553-
15541580
Dim I As Long
15551581

15561582
If m_nLngNum = 0 Then Exit Sub
@@ -1563,11 +1589,9 @@ Private Sub mnuLng_Click(Index As Integer)
15631589
SaveSetting App.Title, "Settings", "Language", mnuLng(Index).Caption
15641590

15651591
ChangeLanguage (mnuLng(Index).Caption)
1566-
15671592
End Sub
15681593

15691594
Private Sub mnuSaveAll_Click()
1570-
15711595
Dim sF As String
15721596
sF = FileDialog(Me, True, L("l_fdSave", "Save file to:"), "*.py", m_prevsf)
15731597

@@ -1577,7 +1601,6 @@ Private Sub mnuSaveAll_Click()
15771601
End If
15781602

15791603
m_prevsf = sF
1580-
15811604
End Sub
15821605

15831606
'仅输出界面生成类,用于之前已经建好框架,并且也写了一些代码,现在修改空间布局,不用影响其他代码
@@ -1704,9 +1727,7 @@ Private Sub mnuRefreshForms_Click()
17041727
End Sub
17051728

17061729
Private Sub mnuRelPos_Click()
1707-
17081730
Dim o As Object
1709-
17101731
mnuRelPos.Checked = Not mnuRelPos.Checked
17111732

17121733
'绝对坐标

Readme.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ Readme of english version refers to [Readme_EN.md](https://github.com/cdhigh/tki
7575
Python文本框有两种:Entry和Text,如果VB的TextBox的MultiLine=False,则
7676
生成Entry,否则生成Text。
7777
4. **Frame**
78-
对应Python的LabelFrame控件,做为其他控件的容器,或做为界面元素视觉分类。
78+
对应Python的Frame或LabelFrame控件,做为其他控件的容器,或做为界面元素视觉分类。
79+
有Caption时生成LabelFrame,否则生成Frame。
7980
5. **CommandButton**
8081
对应Python的Button,没有太多区别。
8182
为了代码简洁,窗体的退出按钮可以设置Cancel属性为True,然后程序自动生成
@@ -195,7 +196,11 @@ Readme of english version refers to [Readme_EN.md](https://github.com/cdhigh/tki
195196
2. 插件不支持使用控件数组,界面可以显示,但是后面的同名控件名会覆盖前面定义的,导致在代码中无法再和此控件互动。
196197
3. VB窗体的ScaleMode建议保持默认值(vbTwips),如果要设置为其他值,则Frame控件内就不要再放Frame控件了,否则其内部的控件布局错误。
197198
4. 如果需要简体汉字界面,则需要Vb6Tkinter.lng文件在Vb6Tkinter.dll同一目录。
198-
5. 此插件支持更多的一些便捷特性,分散在版本历史中,这里就不一一列举了,有需要的可以去了解。
199+
5. 界面设计往往需要经历多次修改,如果某些属性不使用Vb6Tkinter生成的默认值,则有可能下次修改界面时忘记同步修改,导致界面错误,此时可以修改对应控件的Tag属性为下面两个格式任何一个:
200+
- `p@属性1@属性2@属性n`
201+
- `p@属性1=值1@属性2=值2@属性n=值n`
202+
每个属性的值可以忽略,忽略值属性则自动选中对应属性,不修改值。
203+
6. 此插件支持更多的一些便捷特性,分散在版本历史中,这里就不一一列举了,有需要的可以去了解。
199204

200205

201206

@@ -205,12 +210,15 @@ Readme of english version refers to [Readme_EN.md](https://github.com/cdhigh/tki
205210
只是要注意以下几个ttk的BUG:
206211
1. TTK的Entry和Combobox控件背景色设置无效(可以设置,不报错,但是界面不变)。
207212
2. LabelFrame和Notebook控件的字体单独设置无效,但是可以设置ttk的全局字体属性来改变,比如:self.style.configure('.', font=('宋体',12))。
208-
3. Python 2.7.3附带的ttk中的Treeview字体设置无效,但3.2.3及之后的的Treeview的字体设置有效。
209213

210214

211215

212216

213217
# 版本历史
218+
* v1.9
219+
1. 支持生成GUI国际化代码(gettext)
220+
* v1.8.1
221+
1. 根据Caption属性自动转换Frame为LabelFrame或Frame
214222
* v1.8
215223
1. 删除结构化代码生成逻辑,仅生成面向对象代码
216224
2. ListBox添加 (MultiSelect -> selectmode) 属性对应转换

Readme_EN.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ There are two methods, choose either:
8080
Python offers two types of text boxes: Entry and Text. If VB's TextBox has property MultiLine=False, it generates an Entry; otherwise, it produces a Text.
8181

8282
4. **Frame**
83-
Corresponding to Python's LabelFrame widget, the Frame acts as a container for other controls or visually classifies interface elements.
83+
Corresponding to Python's LabelFrame widget, the Frame acts as a container for other controls or visually classifies interface elements.
84+
A LabelFrame will be placed if the property "Caption" is not empty, otherwise, will be a Frame.
8485

8586
5. **CommandButton**
8687
Corresponding to Python's Button with minimal differences. For concise code, setting the Cancel property to True for the form's exit button generates the Tkinter destroy callback, eliminating the need for a separate callback function. In VB, prefixing a letter with "&" directly binds a shortcut key 'Alt + corresponding letter'(forexample &A). Vb6Tkinter supports this, automatically generating the associated event binding code. The same approach applies to other controls with a "Caption" property, such as CheckBox.
@@ -168,7 +169,13 @@ There are two methods, choose either:
168169

169170
4. For a Simplified Chinese addin interface, the Vb6Tkinter.lng file should be in the same directory as Vb6Tkinter.dll.
170171

171-
5. The addin offers additional convenient features scattered throughout its version changelog. Here, we won't list them all, but those interested can explore them as needed.
172+
5. GUI design often requires multiple iterations. If certain properties deviate from the default values generated by Vb6Tkinter, there's a risk of forgetting to update them during subsequent modifications, potentially causing GUI errors. To address this, you can update the corresponding control's `Tag` property using one of the following formats:
173+
- `p@property1@property2@propertyN`
174+
- `p@property1=value1@property2=value2@propertyN=valueN`
175+
176+
In this notation, you can omit the value of any property. When a value is omitted, the corresponding property is automatically selected without altering its value.
177+
178+
6. The addin offers additional convenient features scattered throughout its version changelog. Here, we won't list them all, but those interested can explore them as needed.
172179

173180

174181

@@ -177,12 +184,15 @@ The standard built-in ttk themes extension provides native style on different op
177184

178185
1. Setting the background color for TTK's Entry and Combobox controls is ineffective (you can set it without errors, but the interface remains unchanged).
179186
2. Individually setting the font for LabelFrame and Notebook controls has no effect, but you can use ttk's global font attributes to change it, for example: `self.style.configure('.', font=('Arial', 12))`.
180-
3. Font settings for Treeview in ttk accompanying Python 2.7.3 are ineffective, but they work for Treeview in version 3.2.3 and later.
181187

182188

183189

184190

185191
# Changelog
192+
* v1.9
193+
1. Supported I18N feature (gettext)
194+
* v1.8.1
195+
1. Frame of VB will be translated to LabelFrame or Frame of tkinter automatically.
186196
* v1.8
187197
1. Generate oop code only.
188198
2. Add an interpretation of property (MultiSelect -> selectmode) of ListBox.

Vb6Tkinter.lng

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ mnuOptions=ѡ
1414
mnuV2andV3Code=����Python 2.x/3.x���ݴ���(&C)
1515
mnuUseTtk=����TTK�����(&T)
1616
mnuRelPos=ʹ���������(&R)
17+
mnuI18n=֧��I18n(&I)
1718
mnuUnicodePrefixU=Unicode�ַ�������ǰ׺u(&U)
1819
mnuPythonExe=����Python.exe�(&E)...
1920
mnuTools=����(&T)
@@ -84,8 +85,6 @@ l_msgEncodeResultTooLong=ת
8485
l_msgCodeTooBig=���ɵĴ����ģ̫���ı���װ���£���ѡ��һ���ļ�ֱ�����ڱ�������
8586
l_fdOpen=��ѡ���ļ���
8687
l_fdSave=���ļ����浽��
87-
l_cmtClsApp=#�����ʵ�־�����¼������ص��������������ɴ�����Application_ui�С�
88-
l_cmtClsUi=#������ʵ�ֽ������ɹ��ܣ������¼���������������Application�С�
8988
l_cmtgComps=#���пؼ��Ϳؼ��󶨱��������ֵ䣬ʹ������ֵ���Ϊ�˷����������������������пؼ���
9089
l_cmtTodoCols=#TODO���������ӱ����б�����һ�й̶�Ϊ������ʾ
9190
l_cmtTodoDisCols=#TODO������������ʾ�����б�����һ�й̶�Ϊ������ʾ
@@ -222,6 +221,7 @@ mnuOptions=Options(&O)
222221
mnuV2andV3Code=Compatible Code for Python 2.x/3.x(&C)
223222
mnuUseTtk=Use TTK Themed Library(&T)
224223
mnuRelPos=Use Relative Position(&R)
224+
mnuI18n=Support i18n(&I)
225225
mnuUnicodePrefixU=Add A Prefix 'u' to Unicode String(&U)
226226
mnuPythonExe=Set diretory of python.exe(&E)...
227227
mnuTools=Tools(&T)
@@ -292,8 +292,6 @@ l_msgEncodeResultTooLong=Size of encoded string is too big to load into TextBox,
292292
l_msgCodeTooBig=Size of generated code is too big to load into TextBox, please choose a file to save it.
293293
l_fdOpen=Please Choose file:
294294
l_fdSave=Save file to:
295-
l_cmtClsApp=#The class will implement callback function for events and your logical code.
296-
l_cmtClsUi=#The class will create all widgets for UI.
297295
l_cmtgComps=#Global dictionary of widgets for using in others functions.
298296
l_cmtTodoCols=#TODO Add list of titles here, first column fixed for tree view.
299297
l_cmtTodoDisCols=#TODO Add list of titles will be displayed, first column fixed for tree view.

Vb6Tkinter.vbp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ CompatibleMode="2"
6363
CompatibleEXE32="Release\Vb6Tkinter.dll"
6464
VersionCompatible32="1"
6565
MajorVer=1
66-
MinorVer=8
66+
MinorVer=9
6767
RevisionVer=0
6868
AutoIncrementVer=0
6969
ServerSupportFiles=0

Vb6Tkinter.vbw

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
11
GridOcx = 125, 125, 851, 574, C, 175, 175, 1048, 606, C
2-
Common = 125, 125, 998, 556,
2+
Common = 125, 125, 998, 556, C
33
FileDlg = 150, 150, 981, 581, C
4-
clsBaseControl = 100, 100, 931, 531,
5-
clsButton = 75, 75, 906, 506,
6-
clsCanvas = 25, 25, 869, 474,
7-
clsCheckbutton = 50, 50, 894, 499,
8-
clsEntry = 75, 75, 954, 481,
9-
clsLabel = 175, 175, 1019, 624,
10-
clsLabelFrame = 200, 200, 1044, 649,
11-
clsListbox = 150, 150, 994, 599,
12-
clsOptionMenu = 25, 25, 904, 431,
13-
clsRadiobutton = 150, 150, 994, 599,
14-
clsScale = 175, 175, 1019, 624,
15-
clsScrollbar = 200, 200, 1044, 649,
16-
clsSerialization = 25, 25, 869, 474,
17-
clsText = 0, 0, 879, 406,
18-
cStrBuilder = 0, 0, 0, 0, C
4+
clsBaseControl = 100, 100, 931, 531, C
5+
clsButton = 75, 75, 906, 506, C
6+
clsCanvas = 25, 25, 869, 474, C
7+
clsCheckbutton = 50, 50, 894, 499, C
8+
clsEntry = 75, 75, 954, 481, C
9+
clsLabel = 175, 175, 1019, 624, C
10+
clsLabelFrame = 200, 200, 1044, 649, C
11+
clsListbox = 150, 150, 994, 599, C
12+
clsOptionMenu = 25, 25, 904, 431, C
13+
clsRadiobutton = 150, 150, 994, 599, C
14+
clsScale = 175, 175, 1019, 624, C
15+
clsScrollbar = 200, 200, 1044, 649, C
16+
clsSerialization = 25, 25, 869, 474, C
17+
clsText = 0, 0, 879, 406, C
18+
cStrBuilder = 100, 100, 969, 549, C
1919
Dictionary = 0, 0, 0, 0, C
20-
FrmMain = 25, 25, 898, 456, , 50, 50, 923, 481, C
21-
clsMenu = 0, 0, 844, 449, Z
22-
clsMenuItem = 25, 25, 869, 474,
23-
clsProgressBar = 125, 125, 969, 574,
24-
clsCombobox = 175, 175, 1054, 581,
25-
clsComboboxAdapter = 25, 25, 799, 474,
26-
clsTreeview = 200, 200, 1079, 606,
27-
clsNotebook = 50, 50, 929, 456,
20+
FrmMain = 25, 25, 898, 456, Z, 50, 50, 923, 481, C
21+
clsMenu = 0, 0, 844, 449, C
22+
clsMenuItem = 25, 25, 869, 474, C
23+
clsProgressBar = 125, 125, 969, 574, C
24+
clsCombobox = 175, 175, 1054, 581, C
25+
clsComboboxAdapter = 25, 25, 799, 474, C
26+
clsTreeview = 200, 200, 1079, 606, C
27+
clsNotebook = 50, 50, 929, 456, C
2828
MultiLanguage = 175, 175, 1054, 608, C
2929
Base64 = 100, 100, 874, 549, C
30-
clsForm = 125, 125, 956, 556,
31-
clsStatusbar = 75, 75, 801, 497,
30+
clsForm = 125, 125, 956, 556, C
31+
clsStatusbar = 75, 75, 801, 497, C
3232
Resizer = 100, 100, 826, 549, C
3333
frmOption = 0, 0, 0, 0, C, 200, 200, 1073, 631, C
3434
xpcmdbutton = 0, 0, 0, 0, C, 0, 0, 873, 431, C
35-
clsNotebookTab = 75, 75, 919, 524,
36-
clsSeparator = 0, 0, 844, 449,
35+
clsNotebookTab = 75, 75, 919, 524, C
36+
clsSeparator = 0, 0, 844, 449, C
3737
Connect = 25, 25, 904, 458, C
3838
frmEncodeAFile = 100, 100, 973, 531, C, 25, 25, 898, 456, C
3939
http = 125, 125, 1004, 558, C
4040
modJson = 25, 25, 904, 458, C
4141
frmNewVer = 100, 100, 979, 533, C, 75, 75, 954, 508, C
4242
frmAbout = 50, 50, 776, 472, C, 25, 25, 927, 447, C
43-
utf8file = 50, 50, 894, 499,
43+
utf8file = 50, 50, 894, 499, C

0 commit comments

Comments
 (0)