Ren'Py Translator ToolKit  Check-in [c9760c952b]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:GUI: add progress and error report
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | 1.2
Files: files | file ages | folders
SHA3-256:c9760c952b3ac11e01e4e67f297c0006ebb411a43ec8af77f1f00e65da15cbc4
User & Date: Beuc 2019-06-30 19:04:24
Context
2019-10-12
13:44
Clarification on .rpyc check-in: 67d7157d21 user: Beuc tags: trunk
2019-06-30
19:04
GUI: add progress and error report check-in: c9760c952b user: Beuc tags: trunk, 1.2
19:03
Always recompile translations as I always have a doubt check-in: 7fe90bf200 user: Beuc tags: trunk
Changes

Changes to game/choose_file.rpy.

58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
                import traceback
                traceback.print_exc()

                code = 0
                choice = ""
                path = None

                #interface.error(_("Ren'Py was unable to run python with tkinter to choose the directory. Please install the python-tk or tkinter package."), label=None)

            if code:
                #interface.error(_("Ren'Py was unable to run python with tkinter to choose the directory. Please install the python-tk or tkinter package."), label=None)
                pass

            elif choice:
                path = choice.decode("utf-8")

        is_default = False








|


|







58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
                import traceback
                traceback.print_exc()

                code = 0
                choice = ""
                path = None

                interface.error(_("Ren'Py was unable to run python with tkinter to choose the directory. Please install the python-tk or tkinter package."), label=None)

            if code:
                interface.error(_("Ren'Py was unable to run python with tkinter to choose the directory. Please install the python-tk or tkinter package."), label=None)
                pass

            elif choice:
                path = choice.decode("utf-8")

        is_default = False

Changes to game/options.rpy.

1
2
3
4
5
6
define config.name = _("Ren'Py Translator ToolKit")
define gui.show_name = True
define config.version = "1.1"
define build.name = "renpy-ttk"
define config.save_directory = "renpy-ttk-1558194666"
define config.window_icon = None


|



1
2
3
4
5
6
define config.name = _("Ren'Py Translator ToolKit")
define gui.show_name = True
define config.version = "1.2"
define build.name = "renpy-ttk"
define config.save_directory = "renpy-ttk-1558194666"
define config.window_icon = None

Changes to game/screens.rpy.

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
..
66
67
68
69
70
71
72

73
74
75
76
77
78
79
..
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
...
140
141
142
143
144
145
146

147
148
149
150
151
152
153
...
172
173
174
175
176
177
178























































































































            elif renpy.macintosh:
                subprocess.Popen([ "open", directory ])
            else:
                subprocess.Popen([ "xdg-open", directory ])
        except Exception, e:
            print(e)

    class TL2POT(Action):
        def __call__(self):
            if store.projectpath:
                import tl2pot
                tl2pot.tl2pot(store.projectpath,
                    os.path.join(outdir, os.path.basename(store.projectpath) + '.pot'))
                open_directory(outdir)

    class TL2PO(Action):
        def __call__(self):
            if store.projectpath and store.language:
                import tl2po
                tl2po.tl2po(store.projectpath,
                    store.language,
                    os.path.join(outdir, os.path.basename(store.projectpath) + '-' + store.language + '.po'))
                open_directory(outdir)

    class MO2TL(Action):
        def __call__(self):
            if store.projectpath and store.language:
                mofile = choose_file(outdir)
                if mofile:
                    import mo2tl
                    mo2tl.mo2tl(store.projectpath,
                                mofile,
                                store.language)
                    open_directory(os.path.join(store.projectpath,'game','tl',store.language))

    def projects_directory():
        f = os.path.join(renpy.config.savedir,'..','launcher-4/persistent')
        p = renpy.persistent.load(f)
        return p.projects_directory

    def projects_list():
        import glob
................................................................................
        return [d for d in dirs if os.path.isdir(os.path.join(d,'game'))]

    def languages_list():
        if store.projectpath is None:
            return []
        dirs = glob.glob(os.path.join(projectpath,'game','tl','*'))
        return [os.path.basename(d) for d in sorted(dirs) if os.path.isdir(d)]


    # The color of non-interactive text.
    TEXT = "#545454"

    # Colors for buttons in various states.
    IDLE = "#42637b"
    HOVER = "#d86b45"
................................................................................

define projectpath = None
define language = None

# Recover from Python exception on "Ignore"
label start:
    call screen main_menu




































































screen main_menu():
    style_prefix "main_menu"

    add gui.main_menu_background

    ## This empty frame darkens the main menu.
    hbox:
        null width 10
        vbox:
            text _("PROJECTS:") style "l_label_text" size 36 yoffset 10
            null height 20
            for p in projects_list():
                textbutton os.path.basename(p) action SetVariable('projectpath',p),SetVariable('language',None)
        null width 20
        vbox:
            null height 10
            textbutton "tl2pot: generate POT template for your game" action TL2POT()
            textbutton "tl2po: extract existing Ren'Py translations to PO catalog" action TL2PO()
            textbutton "mo2tl: inject MO catalog into Ren'Py translations" action MO2TL()

            null height 20
            if projectpath:
                text "Set language:"
            else:
                text "< Select project"

            for l in languages_list():
................................................................................

        hbox:
            xalign 1.0
            text "v[config.version]":
                style "main_menu_version"
            text " {a=https://www.beuc.net/donate/}by Beuc{/a}":
                style "main_menu_version"


style main_menu_frame is empty
style main_menu_vbox is vbox
style main_menu_text is gui_text
style main_menu_title is main_menu_text
style main_menu_version is main_menu_text

................................................................................
    idle_color IDLE
    hover_color HOVER
    size 18
style l_label_text is l_default:
    size 24
    xpos INDENT
    yoffset 6






























































































































<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>










|



|


|
|
|
>







 







>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
20
21
22
23
24
25
26




























27
28
29
30
31
32
33
..
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
..
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
...
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
...
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
            elif renpy.macintosh:
                subprocess.Popen([ "open", directory ])
            else:
                subprocess.Popen([ "xdg-open", directory ])
        except Exception, e:
            print(e)





























    def projects_directory():
        f = os.path.join(renpy.config.savedir,'..','launcher-4/persistent')
        p = renpy.persistent.load(f)
        return p.projects_directory

    def projects_list():
        import glob
................................................................................
        return [d for d in dirs if os.path.isdir(os.path.join(d,'game'))]

    def languages_list():
        if store.projectpath is None:
            return []
        dirs = glob.glob(os.path.join(projectpath,'game','tl','*'))
        return [os.path.basename(d) for d in sorted(dirs) if os.path.isdir(d)]
        

    # The color of non-interactive text.
    TEXT = "#545454"

    # Colors for buttons in various states.
    IDLE = "#42637b"
    HOVER = "#d86b45"
................................................................................

define projectpath = None
define language = None

# Recover from Python exception on "Ignore"
label start:
    call screen main_menu
    return

# label to create new context so Ren'Py doesn't complain
label ltest_error:
    $ interface.error("blah")

# Doesn't create a new context:
#    init python:
#    class test_error(Action):
#        def __call__(self):
#            interface.error("blah")
#            #call ltest_error
#            #jump start

# Action labels
# - labels rather than Action classes to create new contexts and have a chance to update the interface
# - Jump() rather than Call() because Call() doesn't Return to the calling screen (Ren'Py launcher does the same)

label TL2POT:
    if store.projectpath:
        show screen progress
        pause 0
        python hide:
            renpy.not_infinite_loop(30)
            import tl2pot
            tl2pot.tl2pot(store.projectpath,
                os.path.join(outdir, os.path.basename(store.projectpath) + '.pot'))
            open_directory(outdir)
    hide screen progress
    call screen main_menu

label TL2PO:
    if store.projectpath and store.language:
        show screen progress
        pause 0
        python hide:
            renpy.not_infinite_loop(30)
            import tl2po
            tl2po.tl2po(store.projectpath,
                store.language,
                os.path.join(outdir, os.path.basename(store.projectpath) + '-' + store.language + '.po'))
            open_directory(outdir)
    hide screen progress
    call screen main_menu

label MO2TL:
    if store.projectpath and store.language:
        $ mofile = choose_file(outdir)
        if mofile:
            show screen progress
            pause 0
            python:
                renpy.not_infinite_loop(30)
                import mo2tl
                mo2tl.mo2tl(store.projectpath,
                            mofile,
                            store.language)
                open_directory(os.path.join(store.projectpath,'game','tl',store.language))
    hide screen progress
    call screen main_menu


screen progress:
    add "#ffffff"
    text _("Calling Ren'Py to extract latest translations, please wait..."):
        align 0.5, 0.5
        color "#ff0000"

screen main_menu():
    style_prefix "main_menu"

    add gui.main_menu_background

    ## This empty frame darkens the main menu.
    hbox:
        null width 10
        vbox:
            text _("PROJECTS") style "l_label_text" size 36 yoffset 10
            null height 20
            for p in projects_list():
                textbutton os.path.basename(p) action SetVariable('projectpath',p),SetVariable('language',None)
        null width 40
        vbox:
            null height 10
            textbutton "tl2pot: generate POT template for your game" action Jump("TL2POT")
            textbutton "tl2po: extract existing Ren'Py translations to PO catalog" action Jump("TL2PO")
            textbutton "mo2tl: inject MO catalog into Ren'Py translations" action Jump("MO2TL")
            #textbutton "Test" action Jump("ltest_error")
            null height 20
            if projectpath:
                text "Set language:"
            else:
                text "< Select project"

            for l in languages_list():
................................................................................

        hbox:
            xalign 1.0
            text "v[config.version]":
                style "main_menu_version"
            text " {a=https://www.beuc.net/donate/}by Beuc{/a}":
                style "main_menu_version"


style main_menu_frame is empty
style main_menu_vbox is vbox
style main_menu_text is gui_text
style main_menu_title is main_menu_text
style main_menu_version is main_menu_text

................................................................................
    idle_color IDLE
    hover_color HOVER
    size 18
style l_label_text is l_default:
    size 24
    xpos INDENT
    yoffset 6


style l_root is l_default:
    background "#ffffff"
    xpadding 10
    top_padding 64
    bottom_padding 128

style l_info_frame is l_default:
    ypadding 21
    xfill True
    yminimum 180
    ypos 75

style l_info_label is l_default:
    xalign 0.5
    ypos 75
    yanchor 1.0
    yoffset 12

style l_right_button is l_default:
    xalign 1.0
    ypos 600 - 128 + 12
    left_margin 8 + INDENT
    right_margin 10 + INDENT

style l_right_button_text is l_default:
    size 30


screen common:

    default complete = None
    default total = None
    default yes = None
    default no = None
    default choices = None
    default cancel = None
    default bar_value = None

    frame:
        style "l_root"

        frame:
            style_group "l_info"

            has vbox

            text message:
                text_align 0.5
                xalign 0.5
                color "#000000"

            if complete is not None:
                add SPACER

                frame:
                    style "l_progress_frame"

                    bar:
                        range total
                        value complete
                        style "l_progress_bar"

            if bar_value is not None:
                add SPACER

                frame:
                    style "l_progress_frame"

                    bar:
                        value bar_value
                        style "l_progress_bar"


            if choices:
                add SPACER

                for v, l in choices:
                    textbutton l action SetScreenVariable("selected", v)

                if selected is not None:
                    $ continue_ = Return(selected)
                else:
                    $ continue_ = None

            if submessage:
                add SPACER

                text submessage:
                    text_align 0.5
                    xalign 0.5
                    layout "subtitle"

            if yes:
                add SPACER

                hbox:
                    xalign 0.5
                    textbutton _("Yes") style "l_button" action yes
                    null width 160
                    textbutton _("No") style "l_button" action no


        label title text_color title_color style "l_info_label"

    textbutton _("Continue") action continue_ style "l_right_button"
    key "input_enter" action continue_


init python in interface:
    from store import Return, Jump
    def error(message, submessage=None, label="start", **kwargs):
        if label is None:
            action = Return(False)
        else:
            action = Jump(label)

        return renpy.call_screen("common", title=_("ERROR"), title_color='#FF0000', message=message, submessage=submessage, continue_=action, **kwargs)