Example #1
0
	def onShortcutHandler(self, argsList):
		"""Handles onKbdEvent by firing the keystroke's handler if it has one registered."""
		eventType, key, mx, my, px, py = argsList
		if eventType == 6: # Key down
			if not InputUtil.isModifier(key):
				stroke = InputUtil.Keystroke(key, self.bAlt, self.bCtrl, self.bShift)
				if stroke in self.shortcuts:
					if DebugUtils.bDebugMode:
						print "BugEventManager - calling handler for shortcut %s"
					self.shortcuts[stroke](argsList)
		return 0
Example #2
0
 def onKbdEvent(self, argsList):
     """
     Handles onKbdEvent by firing the keystroke's handler if it has one registered.
     """
     eventType, key, mx, my, px, py = argsList
     if eventType == self.EventKeyDown:
         if not InputUtil.isModifier(key):
             stroke = InputUtil.Keystroke(key, self.bAlt, self.bCtrl, self.bShift)
             if stroke in self.shortcuts:
                 BugUtil.debug("BugEventManager - calling handler for shortcut %s", stroke)
                 self.shortcuts[stroke](argsList)
                 return 1
     return 0
Example #3
0
	def onKbdEvent(self, argsList):
		"""Handles onKbdEvent by firing the keystroke's handler if it has one registered.
		"""
		eventType, key, mx, my, px, py = argsList
		if eventType == self.EventKeyDown:
			if not InputUtil.isModifier(key):
				stroke = InputUtil.Keystroke(key, self.bAlt, self.bCtrl, self.bShift)
				if stroke in self.shortcuts:
					BugUtil.debug("BugEventManager - calling handler for shortcut %s", stroke)
					self.shortcuts[stroke](argsList)
					return 1
		return 0
Example #4
0
	def addShortcutHandler(self, keys, handler):
		"""Adds the given handler to be called when any of the keyboard shortcut(s) is hit.

		The keys argument may be a single Keystroke, a collection of one or more Keystrokes, or
		a string which will be converted to such.
		If any keystrokes have existing handlers, new ones are ignored and a warning is displayed.
		"""
		if isinstance(keys, InputUtil.Keystroke):
			keys = (keys,)
		elif isinstance(keys, basestring):
			keys = InputUtil.stringToKeystrokes(keys)
		for key in keys:
			if key in self.shortcuts:
				BugUtil.error("shortcut %s already assigned", key)
			else:
				BugUtil.debug("BugEventManager - setting shortcut handler for %s", key)
				self.shortcuts[key] = handler
	def addShortcutHandler(self, keys, handler):
		"""Adds the given handler to be called when any of the keyboard shortcut(s) is hit.
		
		The keys argument may be a single Keystroke, a collection of one or more Keystrokes, or
		a string which will be converted to such.
		If any keystrokes have existing handlers, new ones are ignored and a warning is displayed.
		
		"""
		if isinstance(keys, InputUtil.Keystroke):
			keys = (keys,)
		elif isinstance(keys, types.StringTypes):
			keys = InputUtil.stringToKeystrokes(keys)
		for key in keys:
			if key in self.shortcuts:
				BugUtil.error("shortcut %s already assigned", key)
			else:
				BugUtil.debug("BugEventManager - setting shortcut handler for %s", key)
				self.shortcuts[key] = handler
Example #6
0
    def onKbdEvent(self, argsList):
        """
		Handles onKbdEvent by firing the keystroke's handler if it has one registered.
		"""
        eventType, key, mx, my, px, py = argsList
        if eventType == self.EventKeyDown and not InputUtil.isModifier(key):
            # <f1rpo> (advc.007b)
            # Added not bCtrl/bAlt/bShift checks so that each cheat is triggered by only one combination of modifier keys
            theKey = int(key)
            if not self.bShift and self.bCtrl and self.bAlt and theKey == int(
                    InputTypes.KB_R):
                BugUtil.warn(
                    "Note (K-Mod): Reloading of Art Defines (Ctrl+Alt+R) is disabled"
                )
                return 1  # Don't use this key combination for anything else
            # </f1rpo>
            stroke = InputUtil.Keystroke(key, self.bAlt, self.bCtrl,
                                         self.bShift)
            if stroke in self.shortcuts:
                BugUtil.debug(
                    "BugEventManager - calling handler for shortcut %s",
                    stroke)
                self.shortcuts[stroke](argsList)
                return 1
            # <f1rpo> (advc.007b) Cheats copied from CvEventManager
            if gc.getGame().isDebugMode():
                # Shift - T Debug - techs
                if self.bShift and not self.bCtrl and not self.bAlt and theKey == int(
                        InputTypes.KB_T):
                    self.beginEvent(CvUtil.EventAwardTechsAndGold)
                    return 1
                elif self.bShift and self.bCtrl and not self.bAlt and theKey == int(
                        InputTypes.KB_W):
                    self.beginEvent(CvUtil.EventShowWonder)
                    return 1
                # Shift - ] Debug - currently mouse-over'd unit: health+=10
                elif theKey == int(
                        InputTypes.KB_LBRACKET
                ) and self.bShift and not self.bCtrl and not self.bAlt:
                    unit = CyMap().plot(px, py).getUnit(0)
                    if not unit.isNone():
                        d = min(unit.maxHitPoints() - 1, unit.getDamage() + 10)
                        unit.setDamage(d, PlayerTypes.NO_PLAYER)
                # Shift - [ Debug - currently mouse-over'd unit: health-= 10
                elif theKey == int(
                        InputTypes.KB_RBRACKET
                ) and self.bShift and not self.bCtrl and not self.bAlt:
                    unit = CyMap().plot(px, py).getUnit(0)
                    if not unit.isNone():
                        d = max(0, unit.getDamage() - 10)
                        unit.setDamage(d, PlayerTypes.NO_PLAYER)
                # <advc.gfd> Keep Nightinggale's key combination
                elif theKey == int(
                        InputTypes.KB_F1
                ) and self.bShift and self.bCtrl and not self.bAlt:
                    GameFontDisplay.GameFontDisplay().interfaceScreen()
                    return 1  # </advc.gfd>
                elif theKey == int(InputTypes.KB_F1):
                    if self.bShift and not self.bCtrl and not self.bAlt:
                        CvScreensInterface.replayScreen.showScreen(False)
                        return 1
                elif theKey == int(InputTypes.KB_F2):
                    if self.bShift and not self.bCtrl and not self.bAlt:
                        import CvDebugInfoScreen
                        CvScreensInterface.showDebugInfoScreen()
                        return 1
                elif theKey == int(InputTypes.KB_F3):
                    if self.bShift and not self.bCtrl and not self.bAlt:
                        CvScreensInterface.showDanQuayleScreen(())
                        return 1
                elif theKey == int(InputTypes.KB_F4):
                    if self.bShift and not self.bCtrl and not self.bAlt:
                        CvScreensInterface.showUnVictoryScreen(())
                        return 1
                # </f1rpo>
        return 0
Example #7
0
from Hopfield import Hopfield
import InputUtil
import PatternUtil

hf = Hopfield()
labels, training_patterns = InputUtil.load_training_data()
hf.train(training_patterns)

test_patterns = InputUtil.load_test_data()
for test in test_patterns:
    print("Initial pattern:")
    PatternUtil.display_pattern(test)
    updated_pattern = hf.async_recall(test)
    print("Updated pattern:")
    PatternUtil.display_pattern(updated_pattern)
    hf.predict_from_pattern(labels, training_patterns, updated_pattern)
    def onKbdEvent(self, argsList):
        'keypress handler - return 1 if the event was consumed'
        """
        Handles onKbdEvent by firing the keystroke's handler if it has one registered.
        """

        eventType, key, mx, my, px, py = argsList
        game = gc.getGame()

        # if self.bAllowCheats:
        if gc.getGame().isDebugMode():
            # notify debug tools of input to allow it to override the control
            argsList = (eventType, key, self.bCtrl, self.bShift, self.bAlt, mx,
                        my, px, py, game.isNetworkMultiPlayer())
            if CvDebugTools.g_CvDebugTools.notifyInput(argsList):
                return 0

        if eventType == self.EventKeyDown and not InputUtil.isModifier(key):
            theKey = int(key)
            # <f1rpo> (advc.007b)
            # Added not bCtrl/bAlt/bShift checks so that each cheat is triggered by only one combination of modifier keys
            if not self.bShift and self.bCtrl and self.bAlt and theKey == int(
                    InputTypes.KB_R):
                BugUtil.warn(
                    "Note (K-Mod): Reloading of Art Defines (Ctrl+Alt+R) is disabled"
                )
                return 1  # Don't use this key combination for anything else
            # </f1rpo>

            stroke = InputUtil.Keystroke(key, self.bAlt, self.bCtrl,
                                         self.bShift)
            if stroke in self.shortcuts:
                BugUtil.debug(
                    "BugEventManager - calling handler for shortcut %s",
                    stroke)
                self.shortcuts[stroke](argsList)
                return 1

            # From FfH-Mod: by Kael 07/05/2008
            if theKey == int(InputTypes.KB_LEFT):
                if self.bCtrl:
                    CyCamera().SetBaseTurn(CyCamera().GetBaseTurn() - 45.0)
                    return 1
                elif self.bShift:
                    CyCamera().SetBaseTurn(CyCamera().GetBaseTurn() - 10.0)
                    return 1

            if theKey == int(InputTypes.KB_RIGHT):
                if self.bCtrl:
                    CyCamera().SetBaseTurn(CyCamera().GetBaseTurn() + 45.0)
                    return 1
                elif self.bShift:
                    CyCamera().SetBaseTurn(CyCamera().GetBaseTurn() + 10.0)
                    return 1
            # From FfH: End

            # PAE Spieler am Zug Message aktivieren/deaktvieren: STRG+P / CTRL+P --
            if theKey == int(InputTypes.KB_P):
                if self.bCtrl:
                    if self.bPAE_ShowMessagePlayerTurn:
                        self.bPAE_ShowMessagePlayerTurn = False
                        CyInterface().addMessage(
                            gc.getGame().getActivePlayer(), True, 5,
                            CyTranslator().getText(
                                "TXT_KEY_MESSAGE_PAE_CIV_TURN_DEACTIVATED",
                                ("", )), None, 2, None, ColorTypes(14), 0, 0,
                            False, False)
                    else:
                        self.bPAE_ShowMessagePlayerTurn = True
                        self.iPAE_ShowMessagePlayerHumanID = gc.getGame(
                        ).getActivePlayer()
                        CyInterface().addMessage(
                            gc.getGame().getActivePlayer(), True, 5,
                            CyTranslator().getText(
                                "TXT_KEY_MESSAGE_PAE_CIV_TURN_ACTIVATED",
                                ("", )), None, 2, None, ColorTypes(14), 0, 0,
                            False, False)
                    return 1

            CvCameraControls.g_CameraControls.handleInput(theKey)

            ## AI AutoPlay ##
            if CyGame().getAIAutoPlay():
                if theKey == int(InputTypes.KB_SPACE) or theKey == int(
                        InputTypes.KB_ESCAPE):
                    CyGame().setAIAutoPlay(0)
                    return 1
            ## AI AutoPlay ##

            # <f1rpo> (advc.007b) Cheats copied from CvEventManager
            # if self.bAllowCheats:
            if gc.getGame().isDebugMode():
                # Shift - T (Debug - No MP)
                if self.bShift and not self.bCtrl and not self.bAlt and theKey == int(
                        InputTypes.KB_T):
                    self.beginEvent(CvUtil.EventAwardTechsAndGold)
                    return 1
                if self.bShift and self.bCtrl and not self.bAlt and theKey == int(
                        InputTypes.KB_W):
                    self.beginEvent(CvUtil.EventShowWonder)
                    return 1
                # Shift - ] Debug - currently mouse-over'd unit, health += 10
                elif theKey == int(
                        InputTypes.KB_LBRACKET
                ) and self.bShift and not self.bCtrl and not self.bAlt:
                    unit = CyMap().plot(px, py).getUnit(0)
                    if not unit.isNone():
                        d = min(unit.maxHitPoints() - 1, unit.getDamage() + 10)
                        unit.setDamage(d, PlayerTypes.NO_PLAYER)
                # Shift - [ Debug - currently mouse-over'd unit, health -= 10
                elif theKey == int(
                        InputTypes.KB_RBRACKET
                ) and self.bShift and not self.bCtrl and not self.bAlt:
                    unit = CyMap().plot(px, py).getUnit(0)
                    if not unit.isNone():
                        d = max(0, unit.getDamage() - 10)
                        unit.setDamage(d, PlayerTypes.NO_PLAYER)
                # <advc.gfd> Keep Nightinggale's key combination
                elif theKey == int(
                        InputTypes.KB_F1
                ) and self.bShift and self.bCtrl and not self.bAlt:
                    GameFontDisplay.GameFontDisplay().interfaceScreen()
                    return 1  # </advc.gfd>
                elif theKey == int(InputTypes.KB_F1):
                    if self.bShift and self.bAlt:
                        CyInterface().addImmediateMessage(
                            "BEGIN Python file optimization", "")
                        import ResolveConstantFunctions
                        ResolveConstantFunctions.main(True)
                        CyInterface().addImmediateMessage(
                            "END Python file optimization", "")
                        return 1
                    elif self.bShift and not self.bCtrl and not self.bAlt:
                        CvScreensInterface.replayScreen.showScreen(False)
                        return 1
                    # don't return 1 unless you want the input consumed

                elif theKey == int(InputTypes.KB_F2):
                    if self.bShift and not self.bCtrl and self.bAlt:
                        import remote_pdb
                        remote_pdb.RemotePdb("127.0.0.1", 4444).set_trace()
                        return 1
                    elif self.bShift and not self.bCtrl and not self.bAlt:
                        import CvDebugInfoScreen
                        CvScreensInterface.showDebugInfoScreen()
                        return 1
                elif theKey == int(InputTypes.KB_F3):
                    if self.bShift and not self.bCtrl and not self.bAlt:
                        CvScreensInterface.showDanQuayleScreen(())
                        return 1
                elif theKey == int(InputTypes.KB_F4):
                    if self.bShift and not self.bCtrl and not self.bAlt:
                        CvScreensInterface.showUnVictoryScreen(())
                        return 1
                # </f1rpo>
        return 0
Example #9
0
				 "int": 0,
				 "float": 0.0,
				 "key": "",
				 "tuple": () }
TYPE_DEFAULT_FUNC = { "list": list,
					  "set": set,
					  "dict": dict }
TYPE_EVAL = { "boolean": lambda x: x.lower() in TRUE_STRINGS,
			  "string": lambda x: x,
			  "int": lambda x: int(x),
			  "float": lambda x: float(x),
			  "tuple": lambda x: eval("(%s,)" % x),
			  "list": lambda x: eval("[%s]" % x),
			  "set": lambda x: eval("set([%s])" % x),
			  "dict": lambda x: eval("{%s}" % x),
			  "key": lambda x: InputUtil.stringToKeystrokes(x) }

g_builder = None

def makeOptionId(modId, optionId):
	"""Concatenates the mod and option ID with a separator of the option ID
	doesn't already have one.
	
	Returns a fully qualified option ID.
	"""
	if optionId is not None and modId is not None:
		if optionId.find(MOD_OPTION_SEP) == -1:
			return modId + MOD_OPTION_SEP + optionId
	return optionId

class GameBuilder: