Project

Profile

Help

Revision f2eac2d3

IDf2eac2d39fe9610914734906df62b15a2a09edcf
Parent 54ccc827
Child a4636677

Added by Vincent Le Goff about 3 years ago

Add #82: Add a setting to disable rich text control
(This setting requires AccessPanel 0.14)

View differences:

src/client.py
59 59
        self.engine = engine
60 60
        self.world = world
61 61
        self.running = False
62
        self.strip_ansi = False
62 63
        self.commands = []
63 64
        self.sharp_engine = None
64 65

  
......
132 133
                            mark = len(before) + 1
133 134

  
134 135
            if display:
135
                lines.append(line)
136
                if self.strip_ansi:
137
                    lines.append(no_ansi_line)
138
                else:
139
                    lines.append(line)
140

  
136 141
                if no_ansi_line.strip():
137 142
                    no_ansi_lines.append(no_ansi_line)
138 143

  
139 144
        # Handle the remaining text
140 145
        try:
146
            liens = [l for l in lines if l]
141 147
            self.handle_message("\r\n".join(lines), mark=mark)
142 148
        except Exception:
143 149
            log = logger("client")
src/config.py
231 231
            self.engine.worlds[world.name] = world
232 232
            world.load_characters()
233 233

  
234
        self.load_YAML_file("macros")
235

  
236 234
    def load_options(self):
237 235
        """Load the file containing the options."""
238 236
        lang = locale.getdefaultlocale()[0].split("_")[0]
......
244 242
            [input]
245 243
                command_stacking = string(default=";")
246 244

  
245
            [output]
246
                richtext = boolean(default=True)
247

  
247 248
            [TTS]
248 249
                on = boolean(default=True)
249 250
                outside = boolean(default=True)
src/translations/en/ui/dialog/preferences.yml
8 8
    "on": Enable TTS (Text-To Speech)
9 9
    outside: Enable TTS when on a different window
10 10
    interrupt: Interrupt TTS when a new message is received
11
richtext: Use rich-text control with colors
11 12
update_language: >
12 13
    You have changed the CocoMUD anguage.  You have to restart the
13 14
    application to see these changes.
15
update_richtext: >
16
    You have changed the way the application is to display.  You have
17
    to restart CocoMUD in order to see these modifications.
src/translations/fr/ui/dialog/preferences.yml
8 8
    "on": Activer le TTS (Text-To-Speech)
9 9
    outside: Activer le TTS hors de la fenêtre
10 10
    interrupt: Interrompt le TTS quand un nouveau message est reçu
11
richtext: Active le RichText avec ses couleurs
11 12
update_language: >
12 13
    Vous avez modifié la langue du client CocoMUD. Vous devez
13 14
    redémarrer le programme pour voir ces modifications.
15
update_richtext: >
16
    Vous avez modifié la façon dont CocoMUD affiche son client. Pour
17
    voir ces modifications, il vous faut redémarrer CocoMUD.
src/ui/dialogs/console.py
156 156

  
157 157
class ConsolePanel(AccessPanel):
158 158

  
159
    def __init__(self, parent, engine, world=None):
159
    def __init__(self, parent, engine, world=None, panel=None):
160 160
        AccessPanel.__init__(self, parent, history=True, lock_input=True)
161 161
        self.output.SetDefaultStyle(wx.TextAttr(wx.WHITE, wx.BLACK))
162 162
        self.engine = engine
163 163
        self.world = world
164
        self.panel = panel
164 165
        self.thread = GUIThread(self)
165 166
        self.locals = {
166 167
            "engine": self.engine,
167 168
            "world": self.world,
169
            "panel": self.panel,
168 170
        }
169 171

  
170 172
        # Event binding
......
204 206

  
205 207
class ConsoleDialog(wx.Dialog):
206 208

  
207
    def __init__(self, engine, world=None):
209
    def __init__(self, engine, world=None, panel=None):
208 210
        wx.Dialog.__init__(self, None, title=t("ui.dialog.console.title"))
209 211
        self.engine = engine
210 212
        self.world = world
......
215 217

  
216 218
        # Add in the panel
217 219
        logger.debug("Creating the Python console")
218
        self.panel = ConsolePanel(self, engine, world)
220
        self.panel = ConsolePanel(self, engine, world, panel)
219 221

  
220 222
        # Finish designing the window
221 223
        sizer.Add(self.panel)
src/ui/dialogs/preferences.py
276 276

  
277 277
    def InitUI(self):
278 278
        settings = self.engine.settings
279
        sizer = wx.GridBagSizer(15, 15)
279
        sizer = wx.BoxSizer(wx.VERTICAL)
280 280
        self.SetSizer(sizer)
281 281

  
282 282
        # TTS preferendces
283
        s_TTS = wx.BoxSizer(wx.HORIZONTAL)
283 284
        self.TTS_on = wx.CheckBox(self,
284 285
                label=t("ui.dialog.preferences.TTS.on"))
285 286
        self.TTS_on.SetValue(settings["options.TTS.on"])
......
291 292
        self.TTS_interrupt.SetValue(settings["options.TTS.interrupt"])
292 293

  
293 294
        # Append to the sizer
294
        sizer.Add(self.TTS_on, pos=(0, 0))
295
        sizer.Add(self.TTS_outside, pos=(0, 1))
296
        sizer.Add(self.TTS_interrupt, pos=(1, 1))
295
        s_TTS.Add(self.TTS_on)
296
        s_TTS.Add(self.TTS_outside)
297
        s_TTS.Add(self.TTS_interrupt)
298

  
299
        # RichTextControl
300
        s_other = wx.BoxSizer(wx.HORIZONTAL)
301
        self.richtext = wx.CheckBox(self,
302
                label=t("ui.dialog.preferences.richtext"))
303
        self.richtext.SetValue(settings["options.output.richtext"])
304
        s_other.Add(self.richtext)
305

  
306
        # Add to the main sizer
307
        sizer.Add(s_TTS)
308
        sizer.Add(s_other)
297 309

  
298 310

  
299 311
class PreferencesTabs(wx.Notebook):
......
358 370
        command_stacking = input.command_stacking.GetValue()
359 371
        old_language = settings["options.general.language"]
360 372
        interrupt = accessibility.TTS_interrupt.GetValue()
373
        old_richtext = settings["options.output.richtext"]
374
        richtext = accessibility.richtext.GetValue()
361 375
        settings["options.general.language"] = new_language
362 376
        settings["options.general.encoding"] = encoding
363 377
        settings["options.input.command_stacking"] = command_stacking
364 378
        settings["options.TTS.on"] = accessibility.TTS_on.GetValue()
365 379
        settings["options.TTS.outside"] = accessibility.TTS_outside.GetValue()
366 380
        settings["options.TTS.interrupt"] = interrupt
381
        settings["options.output.richtext"] = richtext
367 382
        settings["options"].write()
368 383
        self.engine.TTS_on = accessibility.TTS_on.GetValue()
369 384
        self.engine.TTS_outside  = accessibility.TTS_outside.GetValue()
370 385
        if old_language != new_language:
371 386
            wx.MessageBox(t("ui.dialog.preferences.update_language"),
372 387
                    t("ui.button.restart"), wx.OK | wx.ICON_INFORMATION)
388
        elif old_richtext != richtext:
389
            wx.MessageBox(t("ui.dialog.preferences.update_richtext"),
390
                    t("ui.button.restart"), wx.OK | wx.ICON_INFORMATION)
391

  
373 392
        self.Destroy()
374 393

  
375 394
    def OnCancel(self, e):
src/ui/window.py
325 325

  
326 326
    def OnConsole(self, e):
327 327
        """Open the console dialog box."""
328
        dialog = ConsoleDialog(self.engine, self.world)
328
        dialog = ConsoleDialog(self.engine, self.world, self.panel)
329 329
        dialog.ShowModal()
330 330

  
331 331
    def OnAlias(self, e):
......
463 463
class MUDPanel(AccessPanel):
464 464

  
465 465
    def __init__(self, parent, window, engine, world, session):
466
        self.rich = engine.settings["options.output.richtext"]
467
        print "Create a world with rich", self.rich
466 468
        AccessPanel.__init__(self, parent, history=True, lock_input=True,
467
                ansi=True)
468
        self.output.SetDefaultStyle(wx.TextAttr(wx.WHITE, wx.BLACK))
469
        ansi = self.extensions["ANSI"]
470
        ansi.default_foreground = wx.WHITE
471
        ansi.default_background = wx.BLACK
469
                ansi=self.rich, rich=self.rich)
470
        if self.rich:
471
            self.output.SetDefaultStyle(wx.TextAttr(wx.WHITE, wx.BLACK))
472
            ansi = self.extensions["ANSI"]
473
            ansi.default_foreground = wx.WHITE
474
            ansi.default_background = wx.BLACK
472 475
        self.window = window
473 476
        self.engine = engine
474 477
        self.client = None
......
499 502
        port = world.port
500 503
        client = engine.open(hostname, port, world)
501 504
        client.link_window(self)
505
        client.strip_ansi = not self.rich
502 506
        world.load()
503 507
        client.commands = self.login()
504 508
        client.start()

Also available in: Unified diff