def text(self, value): if self.autohotkey and (value != None): from code.g import hotkey parsed_hotkey = hotkey(value) self.hotkey = parsed_hotkey['key'] text.Text.text.fset(self, parsed_hotkey['text']) else: text.Text.text.fset(self, value)
def test_hotkeys(input_text, hotkey_chars, cleaned_text): hotkey_data = g.hotkey(input_text) actual_hotkey_chars = ''.join(x[0] for x in hotkey_data['keys']) actual_cleaned_text = hotkey_data['text'] actual_hotkey_char = hotkey_data['key'][0] if hotkey_data['key'] else '' expected_hotkey = hotkey_chars[0] if hotkey_chars else '' print(("input: %s - %s" % (input_text, str(hotkey_data['keys'])))) assert actual_hotkey_chars == hotkey_chars assert actual_cleaned_text == cleaned_text assert actual_hotkey_char == expected_hotkey
def rebuild(self): labels = { 'fullscreen': g.hotkey(_("&Fullscreen:")), 'sound': g.hotkey(_("&Sound:")), 'mousegrab': g.hotkey(_("&Mouse grab:")), 'daynight': g.hotkey(_("Da&y/night display:")), } self.fullscreen_label.text = labels['fullscreen']['text'] self.fullscreen_label.underline = labels['fullscreen']['pos'] self.fullscreen_toggle.hotkey = labels['fullscreen']['key'] self.sound_label.text = labels['sound']['text'] self.sound_label.underline = labels['sound']['pos'] self.sound_toggle.hotkey = labels['sound']['key'] self.grab_label.text = labels['mousegrab']['text'] self.grab_label.underline = labels['mousegrab']['pos'] self.grab_toggle.hotkey = labels['mousegrab']['key'] self.daynight_label.text = labels['daynight']['text'] self.daynight_label.underline = labels['daynight']['pos'] self.daynight_toggle.hotkey = labels['daynight']['key'] self.language_label.text = _("Language:") self.resolution_label.text = _("Resolution:") self.resolution_custom.text = _("&CUSTOM:") if gg.fullscreen: self.fullscreen_toggle.text = _("YES") else: self.fullscreen_toggle.text = _("NO") if not g.nosound: self.sound_toggle.text = _("YES") else: self.sound_toggle.text = _("NO") if pygame.event.get_grab(): self.grab_toggle.text = _("YES") else: self.grab_toggle.text = _("NO") super(OptionsScreen, self).rebuild()
def text(self, value): # Updates language-dependent data try: hotkey = g.hotkey(value) except AttributeError: # g.hotkey() wasn't declared yet, mimic its defaults hotkey = dict( text=value, key=value[0:1], pos=0, ) self._text = value self.label = hotkey['text'] # "Friendly" name for screens and buttons self.hotkey = hotkey['key'] # Hotkey char self.pos = hotkey['pos'] # Hotkey index in Label
def load_buttons_defs(lang=None): buttons = { "yes" : g.hotkey(_("&YES")), "no" : g.hotkey(_("&NO")), "ok" : g.hotkey(_("&OK")), "cancel" : g.hotkey(_("&CANCEL")), "destroy" : g.hotkey(_("&DESTROY")), "build" : g.hotkey(_("&BUILD")), "back" : g.hotkey(_("&BACK")), "pause" : g.hotkey(_("&PAUSE")), "load" : g.hotkey(_("&LOAD")), "continue" : g.hotkey(_("&CONTINUE")), "skip" : g.hotkey(_("&SKIP")), "quit" : g.hotkey(_("&QUIT")), } gg.buttons.update(buttons)
def __init__(self, *args, **kwargs): kwargs.setdefault("yes_type", "ok") kwargs.setdefault("no_type", "cancel") super(OptionsScreen, self).__init__(*args, **kwargs) self.yes_button.function = self.check_restart self.size = (.79, .63) self.pos = (.5, .5) self.anchor = constants.MID_CENTER self.background_color = (0,0,50) self.borders = () labels = { 'fullscreen': g.hotkey(_("&Fullscreen:")), 'sound' : g.hotkey(_("&Sound:")), 'mousegrab' : g.hotkey(_("&Mouse grab:")), 'daynight' : g.hotkey(_("Da&y/night display:")), } # First row self.fullscreen_label = text.Text(self, (.01, .01), (.14, .05), text=labels['fullscreen']['text'], underline=labels['fullscreen']['pos'], align=constants.LEFT, background_color=gg.colors["clear"]) self.fullscreen_toggle = OptionButton(self, (.16, .01), (.07, .05), text=_("NO"), text_shrink_factor=.75, hotkey=labels['fullscreen']['key'], force_underline=-1, function=self.set_fullscreen, args=(button.TOGGLE_VALUE,)) self.sound_label = text.Text(self, (.28, .01), (.15, .05), text=labels['sound']['text'], underline=labels['sound']['pos'], background_color=gg.colors["clear"]) self.sound_toggle = OptionButton(self, (.44, .01), (.07, .05), text=_("YES"), text_shrink_factor=.75, hotkey=labels['sound']['key'], force_underline=-1, function=self.set_sound, args=(button.TOGGLE_VALUE,)) self.grab_label = text.Text(self, (.55, .01), (.15, .05), text=labels['mousegrab']['text'], underline=labels['mousegrab']['pos'], background_color=gg.colors["clear"]) self.grab_toggle = OptionButton(self, (.71, .01), (.07, .05), text=_("NO"), text_shrink_factor=.75, hotkey=labels['mousegrab']['key'], force_underline=-1, function=self.set_grab, args=(button.TOGGLE_VALUE,)) # Second and third row self.resolution_label = text.Text(self, (.01, .08), (.14, .05), text=_("Resolution:"), align=constants.LEFT, background_color=gg.colors["clear"]) self.resolution_group = button.ButtonGroup() rows = 2 cols = 4 def xpos(i): return .16 + .16 * (i%cols) def ypos(i): return .08 + .07 * int(i/cols) for index, (xres,yres) in enumerate(sorted(gg.resolutions[0:rows*cols])): self.resolution_group.add(OptionButton(self, (xpos(index), ypos(index)), (.14, .05), text="%sx%s" % (xres, yres), function=self.set_resolution, args=((xres,yres),))) # Adjust index to full row index += cols - (index % cols) - 1 # Forth row self.resolution_custom = OptionButton(self, (xpos(0),ypos(index+1)), (.14, .05), text=_("&CUSTOM:"), autohotkey=True, function=self.set_resolution_custom) self.resolution_group.add(self.resolution_custom) self.resolution_custom_horiz = \ text.EditableText(self, (xpos(1), ypos(index+1)), (.14, .05), text=str(gg.default_screen_size[0]), borders=constants.ALL, border_color=gg.colors["white"], background_color=(0,0,50,255)) self.resolution_custom_X = text.Text(self, (xpos(2)-.02, ypos(index+1)), (.02, .05), text="X", base_font=gg.font[1], background_color=gg.colors["clear"]) self.resolution_custom_vert = \ text.EditableText(self, (xpos(2), ypos(index+1)), (.14, .05), text=str(gg.default_screen_size[1]), borders=constants.ALL, border_color=gg.colors["white"], background_color=(0,0,50,255)) # Fifth row self.language_label = text.Text(self, (.01, .30), (.14, .05), text=_("Language:"), align=constants.LEFT, background_color=gg.colors["clear"]) self.languages = get_languages_list() self.language_choice = \ listbox.UpdateListbox(self, (.16, .30), (.21, .25), list=[lang[1] for lang in self.languages], update_func=self.set_language) self.daynight_label = text.Text(self, (.50, .30), (.20, .05), text=labels['daynight']['text'], underline=labels['daynight']['pos'], background_color=gg.colors["clear"]) self.daynight_toggle = OptionButton(self, (.71, .30), (.07, .05), text=_("NO"), text_shrink_factor=.75, hotkey=labels['daynight']['key'], force_underline=-1, function=self.set_daynight, args=(button.TOGGLE_VALUE,))
def __init__(self, *args, **kwargs): kwargs.setdefault("yes_type", "ok") kwargs.setdefault("no_type", "cancel") super(OptionsScreen, self).__init__(*args, **kwargs) self.yes_button.function = self.check_restart self.size = (.79, .63) self.pos = (.5, .5) self.anchor = constants.MID_CENTER self.background_color = (0, 0, 50) self.borders = () labels = { 'fullscreen': g.hotkey(_("&Fullscreen:")), 'sound': g.hotkey(_("&Sound:")), 'mousegrab': g.hotkey(_("&Mouse grab:")), 'daynight': g.hotkey(_("Da&y/night display:")), } # First row self.fullscreen_label = text.Text( self, (.01, .01), (.14, .05), text=labels['fullscreen']['text'], underline=labels['fullscreen']['pos'], align=constants.LEFT, background_color=gg.colors["clear"]) self.fullscreen_toggle = OptionButton( self, (.16, .01), (.07, .05), text=_("NO"), text_shrink_factor=.75, hotkey=labels['fullscreen']['key'], force_underline=-1, function=self.set_fullscreen, args=(button.TOGGLE_VALUE, )) self.sound_label = text.Text(self, (.28, .01), (.15, .05), text=labels['sound']['text'], underline=labels['sound']['pos'], background_color=gg.colors["clear"]) self.sound_toggle = OptionButton(self, (.44, .01), (.07, .05), text=_("YES"), text_shrink_factor=.75, hotkey=labels['sound']['key'], force_underline=-1, function=self.set_sound, args=(button.TOGGLE_VALUE, )) self.grab_label = text.Text(self, (.55, .01), (.15, .05), text=labels['mousegrab']['text'], underline=labels['mousegrab']['pos'], background_color=gg.colors["clear"]) self.grab_toggle = OptionButton(self, (.71, .01), (.07, .05), text=_("NO"), text_shrink_factor=.75, hotkey=labels['mousegrab']['key'], force_underline=-1, function=self.set_grab, args=(button.TOGGLE_VALUE, )) # Second and third row self.resolution_label = text.Text(self, (.01, .08), (.14, .05), text=_("Resolution:"), align=constants.LEFT, background_color=gg.colors["clear"]) self.resolution_group = button.ButtonGroup() rows = 2 cols = 4 def xpos(i): return .16 + .16 * (i % cols) def ypos(i): return .08 + .07 * int(i / cols) for index, (xres, yres) in enumerate(sorted(gg.resolutions[0:rows * cols])): self.resolution_group.add( OptionButton(self, (xpos(index), ypos(index)), (.14, .05), text="%sx%s" % (xres, yres), function=self.set_resolution, args=((xres, yres), ))) # Adjust index to full row index += cols - (index % cols) - 1 # Forth row self.resolution_custom = OptionButton( self, (xpos(0), ypos(index + 1)), (.14, .05), text=_("&CUSTOM:"), autohotkey=True, function=self.set_resolution_custom) self.resolution_group.add(self.resolution_custom) self.resolution_custom_horiz = \ text.EditableText(self, (xpos(1), ypos(index+1)), (.14, .05), text=str(gg.default_screen_size[0]), borders=constants.ALL, border_color=gg.colors["white"], background_color=(0,0,50,255)) self.resolution_custom_X = text.Text( self, (xpos(2) - .02, ypos(index + 1)), (.02, .05), text="X", base_font=gg.font[1], background_color=gg.colors["clear"]) self.resolution_custom_vert = \ text.EditableText(self, (xpos(2), ypos(index+1)), (.14, .05), text=str(gg.default_screen_size[1]), borders=constants.ALL, border_color=gg.colors["white"], background_color=(0,0,50,255)) # Fifth row self.language_label = text.Text(self, (.01, .30), (.14, .05), text=_("Language:"), align=constants.LEFT, background_color=gg.colors["clear"]) self.languages = get_languages_list() self.language_choice = \ listbox.UpdateListbox(self, (.16, .30), (.21, .25), list=[lang[1] for lang in self.languages], update_func=self.set_language) self.daynight_label = text.Text(self, (.50, .30), (.20, .05), text=labels['daynight']['text'], underline=labels['daynight']['pos'], background_color=gg.colors["clear"]) self.daynight_toggle = OptionButton(self, (.71, .30), (.07, .05), text=_("NO"), text_shrink_factor=.75, hotkey=labels['daynight']['key'], force_underline=-1, function=self.set_daynight, args=(button.TOGGLE_VALUE, ))
def __init__(self, *args, **kwargs): dialog.FocusDialog.__init__(self, *args, **kwargs) # heavily modified __init__ of MessageDialog self.parent = args[0] self.ok_type = kwargs.pop("ok_type", "ok") super(dialog.MessageDialog, self).__init__(self.parent, **kwargs) self.add_key_handler(pygame.K_RETURN, self.on_return) self.add_key_handler(pygame.K_KP_ENTER, self.on_return) self.size = (.79, .63) self.pos = (.5, .5) self.anchor = constants.MID_CENTER self.background_color = (0,0,50) self.borders = () labels = { 'fullscreen': g.hotkey(_("&Fullscreen:")), 'sound' : g.hotkey(_("&Sound:")), 'mousegrab' : g.hotkey(_("&Mouse grab:")), 'daynight' : g.hotkey(_("Da&y/night display:")), } # First row self.fullscreen_label = text.Text(self, (.01, .01), (.14, .05), text=labels['fullscreen']['text'], underline=labels['fullscreen']['pos'], align=constants.LEFT, background_color=gg.colors["clear"]) self.fullscreen_toggle = OptionButton(self, (.16, .01), (.07, .05), text=_("NO"), text_shrink_factor=.75, hotkey=labels['fullscreen']['key'], force_underline=-1, function=self.set_fullscreen, args=(button.TOGGLE_VALUE,)) self.sound_label = text.Text(self, (.28, .01), (.15, .05), text=labels['sound']['text'], underline=labels['sound']['pos'], background_color=gg.colors["clear"]) self.sound_toggle = OptionButton(self, (.44, .01), (.07, .05), text=_("YES"), text_shrink_factor=.75, hotkey=labels['sound']['key'], force_underline=-1, function=self.set_sound, args=(button.TOGGLE_VALUE,)) self.grab_label = text.Text(self, (.55, .01), (.15, .05), text=labels['mousegrab']['text'], underline=labels['mousegrab']['pos'], background_color=gg.colors["clear"]) self.grab_toggle = OptionButton(self, (.71, .01), (.07, .05), text=_("NO"), text_shrink_factor=.75, hotkey=labels['mousegrab']['key'], force_underline=-1, function=self.set_grab, args=(button.TOGGLE_VALUE,)) # Second and third row self.resolution_label = text.Text(self, (.01, .08), (.14, .05), text=_("Resolution:"), align=constants.LEFT, background_color=gg.colors["clear"]) self.resolution_group = button.ButtonGroup() def xpos(i): return .16 + .16 * (i%4) def ypos(i): return .08 + .07 * int(i/4) for i, (xres,yres) in enumerate(resolutions): self.resolution_group.add(OptionButton(self, (xpos(i), ypos(i)), (.14, .05), text="%sx%s" % (xres, yres), function=self.set_resolution, args=((xres,yres),))) # Forth row self.resolution_custom = OptionButton(self, (xpos(0),ypos(i+1)), (.14, .05), text=_("&CUSTOM:"), autohotkey=True, function=self.set_resolution_custom) self.resolution_group.add(self.resolution_custom) self.resolution_custom_horiz = \ text.EditableText(self, (xpos(1), ypos(i+1)), (.14, .05), text=str(default_screen_size[0]), borders=constants.ALL, border_color=gg.colors["white"], background_color=(0,0,50,255)) self.resolution_custom_X = text.Text(self, (xpos(2)-.02, ypos(i+1)), (.02, .05), text="X", base_font=gg.font[1], background_color=gg.colors["clear"]) self.resolution_custom_vert = \ text.EditableText(self, (xpos(2), ypos(i+1)), (.14, .05), text=str(default_screen_size[1]), borders=constants.ALL, border_color=gg.colors["white"], background_color=(0,0,50,255)) # Fifth row self.language_label = text.Text(self, (.01, .30), (.14, .05), text=_("Language:"), align=constants.LEFT, background_color=gg.colors["clear"]) self.languages = get_languages_list() self.language_choice = \ listbox.UpdateListbox(self, (.16, .30), (.21, .25), list=[lang[1] for lang in self.languages], update_func=self.set_language) self.daynight_label = text.Text(self, (.55, .30), (.15, .05), text=labels['daynight']['text'], underline=labels['daynight']['pos'], background_color=gg.colors["clear"]) self.daynight_toggle = OptionButton(self, (.71, .30), (.07, .05), text=_("NO"), text_shrink_factor=.75, hotkey=labels['daynight']['key'], force_underline=-1, function=self.set_daynight, args=(button.TOGGLE_VALUE,)) self.ok_button = ExitOptionButton(self, (-.5,-.99), (-.3,-.1), anchor=constants.BOTTOM_CENTER)