Example #1
0
def handleKeyEvent(event):
    isDown, key, mods, isRepeat = convertKeyEvent(event)
    if WebBrowser.g_mgr.handleKeyEvent(event):
        return True
    else:
        if isRepeat:
            if onRepeatKeyEvent(event):
                return True
        if g_replayCtrl.isPlaying:
            if g_replayCtrl.handleKeyEvent(isDown, key, mods, isRepeat, event):
                return True
        if constants.IS_CAT_LOADED:
            import Cat
            if Cat.handleKeyEventBeforeGUI(isDown, key, mods, event):
                return True
        if not isRepeat:
            InputHandler.g_instance.handleKeyEvent(event)
            if GUI.handleKeyEvent(event):
                return True
        if constants.IS_CAT_LOADED:
            import Cat
            if Cat.handleKeyEventAfterGUI(isDown, key, mods, event):
                return True
        if not isRepeat:
            if MessengerEntry.g_instance.gui.isEditing(event):
                return True
        inputHandler = getattr(BigWorld.player(), 'inputHandler', None)
        if inputHandler is not None:
            if inputHandler.handleKeyEvent(event):
                return True
        return False
Example #2
0
def fini():
    global g_scenario
    LOG_DEBUG('fini')
    if OfflineMode.enabled():
        return
    else:
        BigWorld.wg_setScreenshotNotifyCallback(None)
        if g_postProcessing is None:
            return
        g_critMemHandler.restore()
        g_critMemHandler.destroy()
        if constants.IS_CAT_LOADED:
            import Cat
            Cat.fini()
        MusicControllerWWISE.destroy()
        if RSSDownloader.g_downloader is not None:
            RSSDownloader.g_downloader.destroy()
        connectionManager.onConnected -= onConnected
        connectionManager.onDisconnected -= onDisconnected
        MessengerEntry.g_instance.fini()
        g_postProcessing.fini()
        from helpers import EdgeDetectColorController
        if EdgeDetectColorController.g_instance is not None:
            EdgeDetectColorController.g_instance.destroy()
            EdgeDetectColorController.g_instance = None
        BigWorld.resetEntityManager(False, False)
        BigWorld.clearAllSpaces()
        if TriggersManager.g_manager is not None:
            TriggersManager.g_manager.destroy()
            TriggersManager.g_manager = None
        gui_personality.fini()
        tutorialLoaderFini()
        import LcdKeyboard
        LcdKeyboard.finalize()
        import Vibroeffects
        if Vibroeffects.VibroManager.g_instance is not None:
            Vibroeffects.VibroManager.g_instance.destroy()
            Vibroeffects.VibroManager.g_instance = None
        if g_replayCtrl is not None:
            g_replayCtrl.destroy()
        from LightFx import LightManager
        if LightManager.g_instance is not None:
            LightManager.g_instance.destroy()
            LightManager.g_instance = None
        import AuxiliaryFx
        if AuxiliaryFx.g_instance is not None:
            AuxiliaryFx.g_instance.destroy()
            AuxiliaryFx.g_instance = None
        from predefined_hosts import g_preDefinedHosts
        if g_preDefinedHosts is not None:
            g_preDefinedHosts.fini()
        voipRespHandler = VOIP.getVOIPManager()
        if voipRespHandler is not None:
            VOIP.getVOIPManager().destroy()
        import SoundGroups
        SoundGroups.g_instance.destroy()
        Settings.g_instance.save()
        if g_scenario is not None:
            g_scenario.fini()
        return
Example #3
0
def fini():
    global g_scenario
    LOG_DEBUG('fini')
    if OfflineMode.enabled():
        return
    else:
        BigWorld.wg_setScreenshotNotifyCallback(None)
        if g_postProcessing is None:
            return
        g_critMemHandler.restore()
        g_critMemHandler.destroy()
        if constants.IS_CAT_LOADED:
            import Cat
            Cat.fini()
        MusicControllerWWISE.destroy()
        if RSSDownloader.g_downloader is not None:
            RSSDownloader.g_downloader.destroy()
        connectionManager.onConnected -= onConnected
        connectionManager.onDisconnected -= onDisconnected
        MessengerEntry.g_instance.fini()
        g_postProcessing.fini()
        from helpers import EdgeDetectColorController
        if EdgeDetectColorController.g_instance is not None:
            EdgeDetectColorController.g_instance.destroy()
            EdgeDetectColorController.g_instance = None
        BigWorld.resetEntityManager(False, False)
        BigWorld.clearAllSpaces()
        if TriggersManager.g_manager is not None:
            TriggersManager.g_manager.destroy()
            TriggersManager.g_manager = None
        gui_personality.fini()
        tutorialLoaderFini()
        import LcdKeyboard
        LcdKeyboard.finalize()
        import Vibroeffects
        if Vibroeffects.VibroManager.g_instance is not None:
            Vibroeffects.VibroManager.g_instance.destroy()
            Vibroeffects.VibroManager.g_instance = None
        if g_replayCtrl is not None:
            g_replayCtrl.destroy()
        from LightFx import LightManager
        if LightManager.g_instance is not None:
            LightManager.g_instance.destroy()
            LightManager.g_instance = None
        import AuxiliaryFx
        if AuxiliaryFx.g_instance is not None:
            AuxiliaryFx.g_instance.destroy()
            AuxiliaryFx.g_instance = None
        from predefined_hosts import g_preDefinedHosts
        if g_preDefinedHosts is not None:
            g_preDefinedHosts.fini()
        voipRespHandler = VOIP.getVOIPManager()
        if voipRespHandler is not None:
            VOIP.getVOIPManager().destroy()
        import SoundGroups
        SoundGroups.g_instance.destroy()
        Settings.g_instance.save()
        if g_scenario is not None:
            g_scenario.fini()
        return
Example #4
0
def handleKeyEvent(event):
    isDown, key, mods, isRepeat = convertKeyEvent(event)
    if WebBrowser.g_mgr.handleKeyEvent(event):
        return True
    else:
        if isRepeat:
            if onRepeatKeyEvent(event):
                return True
        if g_replayCtrl.isPlaying:
            if g_replayCtrl.handleKeyEvent(isDown, key, mods, isRepeat, event):
                return True
        if constants.IS_CAT_LOADED:
            import Cat
            if Cat.handleKeyEventBeforeGUI(isDown, key, mods, event):
                return True
        if not isRepeat:
            InputHandler.g_instance.handleKeyEvent(event)
            if GUI.handleKeyEvent(event):
                return True
        if constants.IS_CAT_LOADED:
            import Cat
            if Cat.handleKeyEventAfterGUI(isDown, key, mods, event):
                return True
        if not isRepeat:
            if MessengerEntry.g_instance.gui.isEditing(event):
                return True
        inputHandler = getattr(BigWorld.player(), 'inputHandler', None)
        if inputHandler is not None:
            if inputHandler.handleKeyEvent(event):
                return True
        return False
Example #5
0
def handleMouseEvent(event):
    if OfflineMode.handleMouseEvent(event):
        return True
    else:
        dx, dy, dz, cursorPos = convertMouseEvent(event)
        if constants.IS_CAT_LOADED:
            import Cat
            if Cat.handleMouseEvent(dx, dy, dz):
                return True
        if g_replayCtrl.isPlaying:
            if g_replayCtrl.handleMouseEvent(dx, dy, dz):
                return True
        if GUI.handleMouseEvent(event):
            return True
        inputHandler = getattr(BigWorld.player(), 'inputHandler', None)
        if inputHandler is not None:
            if inputHandler.handleMouseEvent(dx, dy, dz):
                return True
        for handler in g_mouseEventHandlers:
            try:
                if handler(event):
                    return True
            except Exception:
                LOG_CURRENT_EXCEPTION()

        return False
Example #6
0
def handleMouseEvent(event):
    if OfflineMode.handleMouseEvent(event):
        return True
    else:
        dx, dy, dz, cursorPos = convertMouseEvent(event)
        if constants.IS_CAT_LOADED:
            import Cat
            if Cat.handleMouseEvent(dx, dy, dz):
                return True
        if g_replayCtrl.isPlaying:
            if g_replayCtrl.handleMouseEvent(dx, dy, dz):
                return True
        if GUI.handleMouseEvent(event):
            return True
        inputHandler = getattr(BigWorld.player(), 'inputHandler', None)
        if inputHandler is not None:
            if inputHandler.handleMouseEvent(dx, dy, dz):
                return True
        for handler in g_mouseEventHandlers:
            try:
                if handler(event):
                    return True
            except Exception:
                LOG_CURRENT_EXCEPTION()

        return False
Example #7
0
def defineCat(name, color, age, gender, extrasound):
    aCat = Cat.Cat()
    aCat.setName(name)
    aCat.setColor(color)
    aCat.setAge(age)
    aCat.setGender(gender)
    if extrasound != "":
        aCat.addSound(extrasound)
    return aCat
Example #8
0
 def defineCat(self, name, color, age, gender, extrasound):
     aCat = Cat.Cat()
     aCat.setName(name)
     aCat.setColor(color)
     aCat.setAge(age)
     aCat.setGender(gender)
     if extrasound != "":
         aCat.addSound(extrasound)
     self.theCats.append(aCat)
Example #9
0
def handleKeyEvent(event):
    if OfflineMode.handleKeyEvent(event):
        return True
    elif LightingGenerationMode.handleKeyEvent(event):
        return True
    else:
        isDown, key, mods, isRepeat = convertKeyEvent(event)
        if g_bootcamp.isRunning():
            g_bootcamp.handleKeyEvent(event)
        if WebBrowser.g_mgr.handleKeyEvent(event):
            return True
        if g_replayCtrl.isPlaying:
            if g_replayCtrl.handleKeyEvent(isDown, key, mods, isRepeat, event):
                return True
        if isRepeat:
            if onRepeatKeyEvent(event):
                return True
        if constants.IS_CAT_LOADED:
            import Cat
            if Cat.handleKeyEventBeforeGUI(isDown, key, mods, event):
                return True
        if not isRepeat:
            InputHandler.g_instance.handleKeyEvent(event)
            if GUI.handleKeyEvent(event):
                return True
        if constants.IS_CAT_LOADED:
            import Cat
            if Cat.handleKeyEventAfterGUI(isDown, key, mods, event):
                return True
        if not isRepeat:
            if MessengerEntry.g_instance.gui.handleKey(event):
                return True
        inputHandler = getattr(BigWorld.player(), 'inputHandler', None)
        if inputHandler is not None:
            if inputHandler.handleKeyEvent(event):
                return True
        for handler in g_keyEventHandlers:
            try:
                if handler(event):
                    return True
            except Exception:
                LOG_CURRENT_EXCEPTION()

        return False
Example #10
0
def main():
    #get images
    get_images()
    cat = Cat((-90, random.randint(50, height - 50)), cat_images)
    player = Player((width // 2, height // 2), man_images)

    #exit screen
    while True:
        clock.tick(60)
        for event in pygame.event.get():
            if event.type == QUIT:
                sys.exit()
        keys = pygame.key.get_pressed()
        if keys[K_UP]:
            player.up()
        if keys[K_DOWN]:
            player.down()
        if keys[K_LEFT]:
            player.left()
        if keys[K_RIGHT]:
            player.right()
        player.update()

        #frame rate
        cat.update()
        screen.fill(color)
        cat.draw(screen)
        player.draw(screen)
        pygame.display.flip()

        if cat.rect.colliderect(player.rect):
            print("You lost")
            break
Example #11
0
def handleKeyEvent(event):
    if OfflineMode.handleKeyEvent(event):
        return True
    else:
        isDown, key, mods, isRepeat = convertKeyEvent(event)
        if WebBrowser.g_mgr.handleKeyEvent(event):
            return True
        if g_replayCtrl.isPlaying:
            if g_replayCtrl.handleKeyEvent(isDown, key, mods, isRepeat, event):
                return True
        if isRepeat:
            if onRepeatKeyEvent(event):
                return True
        if constants.IS_CAT_LOADED:
            import Cat
            if Cat.handleKeyEventBeforeGUI(isDown, key, mods, event):
                return True
        if not isRepeat:
            InputHandler.g_instance.handleKeyEvent(event)
            if GUI.handleKeyEvent(event):
                return True
        if constants.IS_CAT_LOADED:
            import Cat
            if Cat.handleKeyEventAfterGUI(isDown, key, mods, event):
                return True
        if not isRepeat:
            if MessengerEntry.g_instance.gui.handleKey(event):
                return True
        inputHandler = getattr(BigWorld.player(), 'inputHandler', None)
        if inputHandler is not None:
            if inputHandler.handleKeyEvent(event):
                return True
        for handler in g_keyEventHandlers:
            try:
                if handler(event):
                    return True
            except Exception:
                LOG_CURRENT_EXCEPTION()

        return False
def ProcessRequest(dataInput):

    sqlParms = jsonToSqlParms.JsonToSqlParms(dataInput)
    if (type(sqlParms) == type(dict())):  # if an error json is returned
        return json.dumps(sqlParms)

    sqlQuery = sqlParmsToQuery.sqlParmsToQuery(sqlParms, dataInput)

    sql_data = sql_utils.get_dict(sqlQuery[0])
    cats = Cat.sql_data_to_cats(sql_data)

    # if statistical operation
    if len(sqlQuery) == 3:
        col = []
        for cat in cats:
            col.append(getattr(cat.base_info, sqlQuery[2]))
        return "{\"" + sqlQuery[2] + "\": " + str(sqlQuery[1](col)) + "}"

    else:
        completedRequest = Cat.cats_to_json(cats)

    return completedRequest
Example #13
0
 def main(self):
     WillieWolf = Wolf(FeedWithFear)
     WhinnyWolf = Wolf(FeedWithFear)
     CarlCat = Cat()
     CindyCat = Cat()
     DougDog = Dog(FeedWithCare)
     DippyDog = Dog(FeedWithCare)
     EllyElephant = Elephant()
     EarlElephant = Elephant()
     HarryHippo = Hippo()
     HenryHippo = Hippo()
     LillyLion = Lion()
     LarryLion = Lion()
     RyanRhino = Rhino()
     RandyRhino = Rhino()
     TonyTiger = Tiger()
     TimmyTiger = Tiger()
     ZaneZooKeeper = ZooKeeper()
     ZaneZooKeeper.Add(WillieWolf)
     ZaneZooKeeper.Add(WhinnyWolf)
     ZaneZooKeeper.Add(CarlCat)
     ZaneZooKeeper.Add(CindyCat)
     ZaneZooKeeper.Add(DougDog)
     ZaneZooKeeper.Add(DippyDog)
     ZaneZooKeeper.Add(EllyElephant)
     ZaneZooKeeper.Add(EarlElephant)
     ZaneZooKeeper.Add(HarryHippo)
     ZaneZooKeeper.Add(HenryHippo)
     ZaneZooKeeper.Add(LillyLion)
     ZaneZooKeeper.Add(LarryLion)
     ZaneZooKeeper.Add(RyanRhino)
     ZaneZooKeeper.Add(RandyRhino)
     ZaneZooKeeper.Add(TonyTiger)
     ZaneZooKeeper.Add(TimmyTiger)
     ZaneZooKeeper.WakeUp()
     ZaneZooKeeper.RollCall()
     ZaneZooKeeper.Roam()
     ZaneZooKeeper.Eat()
     ZaneZooKeeper.Sleep()
Example #14
0
def main():
    user='******'
    key_path='~/.ssh/scat'
    try:    # retrieve list of system hostnames
        addr_ls=Cat.system_list(user, key_path)
    except:
        raise
    # compile list of Cat.Boxen
    boxen=SetBoxen(addr_ls, user, key_path)
    boxen=SortBoxen(boxen)
    print('')
    for b in boxen:
        print('%s %s%6.2f'%(b.address, (25-len(b.address))*' ', b.loadavg))
    return 0
Example #15
0
def handleMouseEvent(event):
    dx, dy, dz, cursorPos = convertMouseEvent(event)
    if constants.IS_CAT_LOADED:
        import Cat
        if Cat.handleMouseEvent(dx, dy, dz):
            return True
    if g_replayCtrl.isPlaying:
        if g_replayCtrl.handleMouseEvent(dx, dy, dz):
            return True
    if GUI.handleMouseEvent(event):
        return True
    else:
        inputHandler = getattr(BigWorld.player(), 'inputHandler', None)
        if inputHandler is None:
            return False
        return inputHandler.handleMouseEvent(dx, dy, dz)
Example #16
0
def handleMouseEvent(event):
    dx, dy, dz, cursorPos = convertMouseEvent(event)
    if constants.IS_CAT_LOADED:
        import Cat
        if Cat.handleMouseEvent(dx, dy, dz):
            return True
    if g_replayCtrl.isPlaying:
        if g_replayCtrl.handleMouseEvent(dx, dy, dz):
            return True
    if GUI.handleMouseEvent(event):
        return True
    else:
        inputHandler = getattr(BigWorld.player(), 'inputHandler', None)
        if inputHandler is None:
            return False
        return inputHandler.handleMouseEvent(dx, dy, dz)
from Cat import *
from Dog import *
from Elephant import *
from Hippo import *
from Lion import *
from Rhino import *
from Tiger import *

if __name__ == "__main__":
    # The client code.

    ## setting with stragey pattern
    WillieWolf = Wolf(FeedWithFear())
    WhinnyWolf = Wolf(FeedWithFear())

    CarlCat = Cat()
    CindyCat = Cat()
    ## setting with stragey pattern
    DougDog = Dog(FeedWithCare())
    DippyDog = Dog(FeedWithCare())

    EllyElephant = Elephant()
    EarlElephant = Elephant()
    HarryHippo = Hippo()
    HenryHippo = Hippo()
    LillyLion = Lion()
    LarryLion = Lion()
    RyanRhino = Rhino()
    RandyRhino = Rhino()
    TonyTiger = Tiger()
    TimmyTiger = Tiger()
Example #18
0
class Zookeeper:

    # list of Animals is kept as an attribute of Zookeeper class
    animalsList = [
        Cat('Carl'),
        Cat('Candy'),
        Dog('Doris'),
        Dog('Dan'),
        Elephant('Eric'),
        Elephant('Earl'),
        Hippo('Harry'),
        Hippo('Humphrey'),
        Lion('Leopold'),
        Lion('Larry'),
        Rhino('Rory'),
        Rhino('Rodger'),
        Tiger('Terrance'),
        Tiger('Time'),
        Wolf('Wallace'),
        Wolf('Wendy')
    ]

    def main(self):

        if not os._exists(
                'out'):  # if out folder doesn't exist, then create one
            os.mkdir('out')

        sys.stdout = open(os.path.join('out', 'dayAtTheZoo.out'),
                          'w')  # write all print statements to a file

        # call wakeAnimals(), rollCallAnimals(), feedAnimals(), letAnimalsRoam(), putAnimalsToBed() in the same order
        print("The Zookeeper is waking up the animals:\n---")
        self.wakeAnimals()
        print("\nThe Zookeeper is doing roll call:\n---")
        self.rollCallAnimals()
        print("\nThe Zookeeper is feeding the animals:\n---")
        self.feedAnimals()
        print("\nThe Zookeeper is letting the animals roam about:\n---")
        self.letAnimalsRoam()
        print("\nThe Zookeeper is putting the animals to bed:\n---")
        self.putAnimalsToBed()

        return

    def wakeAnimals(self):
        '''
        :return: wakeUp() list of Animals one at a time
        '''
        for animal in self.animalsList:
            animal.wakeUp()
        return

    def feedAnimals(self):
        '''
        :return: feedAnimals() list of Animals one at a time
        '''
        for animal in self.animalsList:
            animal.eat()
        return

    def letAnimalsRoam(self):
        '''
        :return: lets list of Animals roam one at a time
        '''
        for animal in self.animalsList:
            animal.roam()
        return

    def rollCallAnimals(self):
        '''
        :return: allows roll call list of Animals one at a time.
        '''
        for animal in self.animalsList:
            animal.makeNoise()
        return

    def putAnimalsToBed(self):
        '''
        :return: allows list of Animals put to bed one at a time.
        '''
        for animal in self.animalsList:
            animal.sleep()
        return
Example #19
0
#!/usr/bin/python
import Cat
import Tiger
import Wolf
import Dog
import ZooKeeper
import ZooAnnouncer

if __name__ == '__main__':

    # Instantiating all the animals in the zoo.
    Chesire = Cat.Cat("Chesire")
    Calum = Cat.Cat("Calum")
    Timon = Tiger.Tiger("Timon")
    Tina = Tiger.Tiger("Tina")
    Walace = Wolf.Wolf("Walace")
    Willy = Wolf.Wolf("Willy")
    Diane = Dog.Dog("Diane")
    Dan = Dog.Dog("Dan")

    # Placing all the animals into a list
    animals = [Chesire, Calum, Timon, Tina, Walace, Willy, Diane, Dan]

    # Instantiating the Zoo Announcer, Zoo Keeper, Attaching the Announcer to get updates from
    # the Zoo Keeper, and having the Zoo Keeper go through their daily duties.
    Announcer = ZooAnnouncer.ZooAnnouncer()
    Keeper = ZooKeeper.ZooKeeper(animals)
    Keeper.attach(Announcer)
    Keeper.wake_animals()
    Keeper.roll_call()
    Keeper.feed_animals()
Example #20
0
def fini():
    global g_replayCtrl
    global g_onBeforeSendEvent
    global g_scenario
    LOG_DEBUG('fini')
    if OfflineMode.enabled():
        dependency.clear()
        return
    elif LightingGenerationMode.enabled():
        return
    else:
        BigWorld.wg_setScreenshotNotifyCallback(None)
        g_critMemHandler.restore()
        g_critMemHandler.destroy()
        if constants.IS_CAT_LOADED:
            import Cat
            Cat.fini()
        MusicControllerWWISE.destroy()
        if RSSDownloader.g_downloader is not None:
            RSSDownloader.g_downloader.destroy()
        ServiceLocator.connectionMgr.onConnected -= onConnected
        ServiceLocator.connectionMgr.onDisconnected -= onDisconnected
        MessengerEntry.g_instance.fini()
        from helpers import EdgeDetectColorController
        if EdgeDetectColorController.g_instance is not None:
            EdgeDetectColorController.g_instance.destroy()
            EdgeDetectColorController.g_instance = None
        BigWorld.resetEntityManager(False, False)
        BigWorld.clearAllSpaces()
        if TriggersManager.g_manager is not None:
            TriggersManager.g_manager.destroy()
            TriggersManager.g_manager = None
        if g_replayCtrl is not None:
            g_replayCtrl.unsubscribe()
        gui_personality.fini()
        tutorialLoaderFini()
        import Vibroeffects
        if Vibroeffects.VibroManager.g_instance is not None:
            Vibroeffects.VibroManager.g_instance.destroy()
            Vibroeffects.VibroManager.g_instance = None
        from LightFx import LightManager
        if LightManager.g_instance is not None:
            LightManager.g_instance.destroy()
            LightManager.g_instance = None
        import AuxiliaryFx
        if AuxiliaryFx.g_instance is not None:
            AuxiliaryFx.g_instance.destroy()
            AuxiliaryFx.g_instance = None
        from predefined_hosts import g_preDefinedHosts
        if g_preDefinedHosts is not None:
            g_preDefinedHosts.fini()
        from bootcamp.BootcampTransition import BootcampTransition
        BootcampTransition.stop()
        SoundGroups.g_instance.stopListeningGUISpaceChanges()
        dependency.clear()
        if g_replayCtrl is not None:
            g_replayCtrl.destroy()
            g_replayCtrl = None
        voipRespHandler = VOIP.getVOIPManager()
        if voipRespHandler is not None:
            voipRespHandler.destroy()
        SoundGroups.g_instance.destroy()
        Settings.g_instance.save()
        if g_scenario is not None:
            g_scenario.destroy()
        g_onBeforeSendEvent = None
        WebBrowser.destroyExternalCache()
        if constants.HAS_DEV_RESOURCES:
            import development
            development.fini()
        return
Example #21
0
Create a class called Cat in a new file. Give the Cat the attributes
`eyeColor` and `name` in the constructor.

Dont forget to import the file.

In the code below initiate a variable named `cat` with a *Cat object*, give
it eye color "blue" and name "Basion".

Answer with the string "My cats name is `name` and has `eyeColor` eyes.".


Write your code below and put the answer into the variable ANSWER.
"""

cat = Cat.Cat("blue", "Basion")

ANSWER = "My cats name is {name} and has {eyeColor} eyes.".format(
    name=cat.str_name, eyeColor=cat.str_eyeColor)

# I will now test your answer - change false to true to get a hint.
print(dbwebb.assertEqual("1.1", ANSWER, False))
"""
Exercise 1.2

Expand your Cat class with the variables `livesLeft`.

Initialize the attribute in the constructor to `-1`. In the code below
change the value to `9`.

Answer with number of lives the cat has left.
Example #22
0
def genCatCsv(catType, markAttType, sem, inputfile, outputfile):
    with open(inputfile, newline='') as csvfile:
        reader = csv.DictReader(csvfile)
        my_obj = list(reader)
        newlist = sorted(my_obj, key=lambda k: k['RRN'])
        #print(newlist)--Debugging Purpose
        size_list = len(newlist)
        myTotalKeys = list(newlist[0].keys())
        #Getting the subject codes from header
        #print(mykeys)--Debugging Purpose
        myTotalKeys.remove('RRN')
        #RRN Key is removed since it is not needed in DB.
        #print(mykeys)
        size_keys = len(myTotalKeys)
        myAttKeys = []
        for i in range(size_keys):
            if '-Att' in myTotalKeys[i]:
                myAttKeys.append(myTotalKeys[i])
        size_att_keys = len(myAttKeys)
        myMarkKeys = list(set(myTotalKeys) - set(myAttKeys))
        size_mark_keys = len(myMarkKeys)
        print('Total', myTotalKeys)
        print('myMarkKeys', myMarkKeys)
        print('AttKeys', myAttKeys)
        cat_list = []
        count = 0
        if markAttType == 'mark':
            for i in range(size_list):
                for j in range(size_mark_keys):
                    cat_list.append(Cat.Cat(newlist[i]['RRN'], myMarkKeys[j]))
                    count = count + 1
                    cat_list[count - 1].setCatMark(newlist[i][str(
                        myMarkKeys[j])])
                    cat_list[count - 1].setSem(sem)
        elif markAttType == 'att':
            for i in range(size_list):
                for j in range(size_att_keys):
                    cat_list.append(
                        Cat.Cat(newlist[i]['RRN'],
                                myAttKeys[j].rstrip('-Att')))
                    count = count + 1
                    cat_list[count - 1].setCatAtt(newlist[i][str(
                        myAttKeys[j])])
                    cat_list[count - 1].setSem(sem)
        elif markAttType == 'markAtt':
            for i in range(size_list):
                for j in range(size_mark_keys):
                    cat_list.append(Cat.Cat(newlist[i]['RRN'], myMarkKeys[j]))
                    count = count + 1
                    cat_list[count - 1].setCatMark(newlist[i][str(
                        myMarkKeys[j])])
                    cat_list[count - 1].setCatAtt(
                        newlist[i][str(myMarkKeys[j]) + '-Att'])
                    cat_list[count - 1].setSem(sem)

    with open(outputfile, 'w') as writefile:
        if catType == 'cat1':
            fieldnames = [
                'RRN', 'SUBJECT_CODE', 'CAT1_MARK', 'CAT1_ATTENDANCE',
                'SEM_TAKEN'
            ]
        elif catType == 'cat2':
            fieldnames = [
                'RRN', 'SUBJECT_CODE', 'CAT2_MARK', 'CAT2_ATTENDANCE',
                'SEM_TAKEN'
            ]
        elif catType == 'cat3':
            fieldnames = [
                'RRN', 'SUBJECT_CODE', 'CAT3_MARK', 'CAT3_ATTENDANCE',
                'SEM_TAKEN'
            ]
        writer = csv.DictWriter(writefile, fieldnames=fieldnames)
        writer.writeheader()
        for k in range(count):
            writer.writerow({
                fieldnames[0]: cat_list[k].rrn,
                fieldnames[1]: cat_list[k].sub_code,
                fieldnames[2]: cat_list[k].cat_mark,
                fieldnames[3]: cat_list[k].cat_att,
                fieldnames[4]: cat_list[k].sem
            })
Example #23
0
    '''
    '''
    # case 5
    mouse_angle = -57.000
    mouse_heading = mouse_angle - 90
    cat_angle = 0.000
    cat_heading = cat_angle - 90
    cat_radius = 4.000
    # stoptime = 30*10**3
    '''

    statue = Statue(Vector(200, 200), 0, radius * 100)
    mouse = Mouse(Vector(200, 200), mouse_heading, radius * 100, 1,
                  mouse_angle, arena)
    cat = Cat(Vector(200, 200), cat_heading, radius * 100, cat_radius * 100,
              1.25, 1, cat_angle, mouse_angle, mouse, arena,
              updatetime.callback())

    arena.add(statue)
    arena.add(mouse)
    arena.add(cat)
    arena.getinitial()
    arena.make_time_widgets()

    def cursor_motion(event):
        if arena.is_running() != 1:
            # print('stopped')
            if round(cat.position.x + arena._canvas_offset.x - 15) <= round(
                    event.x
            ) <= round(cat.position.x + arena._canvas_offset.x + 15) and round(
                    cat.position.y + arena._canvas_offset.y - 15) <= round(
Example #24
0
class Zoo:
    def __init__(self, zoo_name):
        self.zoo_name = zoo_name
        self.animals = {}

    def add_new_animal_by_id(self, animal):
        animal_id = id(animal)
        if animal_id in self.animals:
            raise ValueError(f"Animal {animal.__dict__['name']} already in the zoo!") from BaseException
        self.animals[animal_id] = animal

    def get_all_animals(self):
        for v in self.animals.values():
            print(v.__dict__)

    def has_animal(self, animal_name):
        for v in self.animals.values():
            if v.__dict__['name'] == animal_name:
                print(f'{animal_name} is in the zoo')


if __name__ == '__main__':
    cat1 = Cat.Cat('cat1', 'meat', 'medium', 'dangerous')
    cat2 = Cat.Cat('cat2', 'meat', 'small', 'dangerous')
    dog1 = Dog.Dog('dog1', 'meat', 'medium', 'dangerous')
    zoo1 = Zoo('Zoo1')
    zoo1.add_new_animal_by_id(cat1)
    zoo1.add_new_animal_by_id(cat2)
    zoo1.add_new_animal_by_id(cat1)
    zoo1.has_animal('cat1')
Example #25
0
    def __init__(self, level_size, kitties, dogs):
        pygame.init()
        pygame.font.init()
        pygame.mixer.init()
        pygame.mixer.music.load("data\\sounds\\rain.wav")
        pygame.mixer.music.play(-1)
        self.level_size = level_size
        self.kitties_n = kitties
        self.dogs_n = dogs
        self.fps = 20
        self.size = (640, 480)
        self.screen = pygame.display.set_mode(self.size)
        self.loading_screen = pygame.Surface(self.size)
        self.loading_screen.fill((0, 0, 0))
        self.screen.blit(self.loading_screen, (0, 0))
        self.screen.blit(
            pygame.font.SysFont("comicsansms",
                                20).render("Loading", False, (255, 255, 255)),
            (self.size[0] / 2, self.size[1] / 2))
        pygame.display.flip()
        self.level = Level.Level(self.level_size)
        self.level_size_p = self.level.level_size_p

        self.kitties = []
        self.kitties_del = []
        self.dogs = []

        self.cat = Cat.Cat(self.level.safespace.center, self.level_size_p,
                           self.kitties, self.kitties_del, self.dogs)

        for i in range(self.dogs_n):
            self.dogs.append(Dog.Dog(self.level_size_p, self.kitties,
                                     self.cat))

        for i in range(self.kitties_n):
            self.kitties.append(
                Kitty.Kitty(self.level_size_p, self.level.safespace, self.cat))

        self.pause = False

        self.draws = [self.level.safespace] + self.dogs + self.kitties
        self.updates = [self.cat] + self.kitties + self.dogs

        self.camera = Camera.Camera(
            ((self.level.level_size_p[0] - self.size[0]) / 2 - 1,
             self.level.level_size_p[1] - self.size[1] - 1), self.size,
            self.level, self.cat, self.kitties, self.draws, self.screen,
            self.level_size_p)

        self.keydown_handlers = defaultdict(list)
        self.keyup_handlers = defaultdict(list)

        self.keydown_handlers[pygame.K_UP].append(self.cat.act)
        self.keydown_handlers[pygame.K_RIGHT].append(self.cat.act)
        self.keydown_handlers[pygame.K_DOWN].append(self.cat.act)
        self.keydown_handlers[pygame.K_LEFT].append(self.cat.act)
        self.keydown_handlers[pygame.K_F1].append(self.camera.about_switch)
        self.keydown_handlers[pygame.K_c].append(self.cat.meow)
        self.keydown_handlers[pygame.K_x].append(self.cat.ask_meow)
        self.keydown_handlers[pygame.K_z].append(self.cat.hit)
        self.keydown_handlers[pygame.K_LSHIFT].append(self.cat.speedy)
        self.keyup_handlers[pygame.K_UP].append(self.cat.act)
        self.keyup_handlers[pygame.K_RIGHT].append(self.cat.act)
        self.keyup_handlers[pygame.K_DOWN].append(self.cat.act)
        self.keyup_handlers[pygame.K_LEFT].append(self.cat.act)
        self.keyup_handlers[pygame.K_LSHIFT].append(self.cat.act)
        self.keyup_handlers[pygame.K_F1].append(self.camera.about_switch)
        self.keyup_handlers[pygame.K_LSHIFT].append(self.cat.speedy)

        while len(self.kitties):
            self.start = time.time()
            for event in pygame.event.get():
                if event.type == pygame.QUIT: sys.exit()
                elif event.type == pygame.KEYDOWN:
                    for handler in self.keydown_handlers[event.key]:
                        handler()
                elif event.type == pygame.KEYUP:
                    for handler in self.keyup_handlers[event.key]:
                        handler()
            for i in self.updates:
                i.update()
            if len(self.kitties_del):
                for i in self.kitties_del:
                    if not i.state:
                        self.kitties_del.remove(i)
                        self.kitties.remove(i)
                        self.draws.remove(i)
                        self.updates.remove(i)
            self.camera.draw()
            pygame.display.flip()
            self.end = time.time()
            self.diff = self.end - self.start
            self.delay = 1.0 / self.fps - self.diff
            if self.delay > 0:
                time.sleep(self.delay)
        self.screen.blit(
            pygame.font.SysFont("comicsansms",
                                20).render("You win! Restarting…", False,
                                           (255, 255, 255)),
            (self.size[0] / 3, self.size[1] / 3))
        pygame.display.flip()
        time.sleep(5)
Example #26
0
class Zookeeper:

    zoo_announcers = []

    animalsList = [
        Cat('Carl'),
        Cat('Candy'),
        Dog('Doris'),
        Dog('Dan'),
        Elephant('Eric'),
        Elephant('Earl'),
        Hippo('Harry'),
        Hippo('Humphrey'),
        Lion('Leopold'),
        Lion('Larry'),
        Rhino('Rory'),
        Rhino('Rodger'),
        Tiger('Terrance'),
        Tiger('Time'),
        Wolf('Wallace'),
        Wolf('Wendy')
    ]

    def add_observer(self, zoo_announcer: 'ZooAnnouncer'):
        self.zoo_announcers.append(zoo_announcer)

    def notify_observers(self, task: Task):
        for announcer in self.zoo_announcers:
            announcer.update(task)

    def remove_observer(self, zoo_announcer: 'ZooAnnouncer'):
        self.zoo_announcers.remove(zoo_announcer)

    def wakeAnimals(self):
        self.notify_observers(Task.WAKEUP)
        for animal in self.animalsList:
            animal.wakeUp()
        return

    def feedAnimals(self):
        self.notify_observers(Task.FEED)
        for animal in self.animalsList:
            animal.eat()
        return

    def letAnimalsRoam(self):
        self.notify_observers(Task.LETROAM)
        for animal in self.animalsList:
            animal.roam()
        return

    def rollCallAnimals(self):
        self.notify_observers(Task.ROLLCALL)
        for animal in self.animalsList:
            animal.makeNoise()
        return

    def putAnimalsToBed(self):
        self.notify_observers(Task.PUTTOBED)
        for animal in self.animalsList:
            animal.sleep()
        return
Example #27
0
from Tkinter import *  # Import everything from Tkinter
from Arena import Arena  # Import our Arena
from Turtle import Turtle  # Import our Turtle
from Vector import *  # Import everything from our Vector

Turtle.m = 50.0  # Scaling factor
Turtle.origin = Vector(400, 300)
from Statue import *
from Mouse import *
from Cat import *

statue = Statue(Turtle.origin + Vector(0, 0), 0)
mouse = Mouse(Turtle.origin + Vector(0, -Turtle.m).rotate(40), 0)
cat = Cat(Turtle.origin + Vector(0, -4 * Turtle.m).rotate(200), 0, mouse)

tk = Tk()  # Create a Tk top-level widget
arena = Arena(tk, 800, 600)  # Create an Arena widget, arena
arena.pack()  # Tell arena to pack itself on screen
arena.add(statue)  # Add a very simple, statue
arena.add(mouse)  # Add a green mouse centered at the base of the statue
arena.add(cat)  # Add a red cat
cat_radius = StringVar()
cat_radius.set('CatRadius: %2.f' % cat.radius)
cat_angle = StringVar()
cat_angle.set('CatAngle: %2.f' % cat.angle)
mouse_angle = StringVar()
mouse_angle.set('MouseAngle: %2.f' % mouse.angle)
arena.add_labels(arena.time, cat_radius, cat_angle, mouse_angle)
tk.mainloop()  # Enter the Tkinter event loop
Example #28
0
from Animal import *
from Canine import *
from Pachyderm import *
from Feline import *
from Cat import *
from Dog import *
from Elephant import *
from Hippo import *
from Rhino import *
from Lion import *
from Tiger import *
from Wolf import *
from ZooKeeperInterface import *

if __name__ == "__main__":
    Cody = Cat("Cody")
    Code = Cat("Code")
    Code.setStatus()
    Donald = Dog("Donald")
    Dash = Dog("Dash")
    Dash.setStatus()
    Eric = Elephant("Eric")
    Edward = Elephant("Edward")
    Edward.setStatus()
    Heman = Hippo("Heman")
    Heather = Hippo("Heather")
    Heather.setStatus()
    Luke = Lion("Luke")
    Lisa = Lion("Lisa")
    Lisa.setStatus()
    Rosy = Rhino("Rosy")
Example #29
0
__author__ = 'zhengxiaoyu'
from Tkinter import *  # Import everything from Tkinter
from Arena import Arena  # Import our Arena
from Turtle import Turtle  # Import our Turtle
from Vector import *  # Import everything from our Vector
from Mouse import *
from WalkingTurtle import *
from Status import *
from Cat import *
little_mouse = Mouse(Vector(345, 350), 1, 1)
little_cat = Cat(Vector(800, 350), 1, little_mouse)
little_status = Status(Vector(450, 350), 1)
tk = Tk()  # Create a Tk top-level widget
arena = Arena(tk, little_cat)  # Create an Arena widget, arena
arena.pack()
arena.add(little_mouse)
arena.add(little_cat)
arena.add(little_status)
tk.mainloop()  # Enter the Tkinter event loop
Example #30
0
import Dog, Cat

dog = Dog.Dog()
dog.run()

cat = Cat.Cat()
cat.run()

def run_twice(func):
    func.run()

run_twice(dog)
run_twice(cat)