def nextCurrImgBox(self, evt):

    if len(self.wordDict) > 0:
        self.currWord = randChoice(self.wordDict.keys())
        self.definition = self.wordDict[self.currWord]
        self.wordDict.pop(self.currWord)

        self.currWordLabel.SetLabel(self.definition)

        fileList = self.fileListForWord(self.currWord)

        [img.Destroy() for img in self.currImgHolder]
        self.currImgHolder = []

        self.drawWord(fileList,
                      self.currImgSizer,
                      self.currImgHolder,
                      hidden=True)

    else:
        [img.Hide() for img in self.prevImgHolder]
        [img.Hide() for img in self.currImgHolder]

        self.currWordLabel.SetLabel("")
        self.prevWordLabel.SetLabel("No words remaining")
        self.LAST = True
        self.Layout()
Example #2
0
 async def _listDownload(self, client: AsyncClient,
                         url: str) -> APIResult_T:
     urlParsed = URL(url)
     logger.info("Start downloading list " +
                 f"{urlParsed.full_path!r} from {urlParsed.host!r}.")
     try:
         response = await client.get(
             url,
             headers={
                 "User-Agent":
                 randChoice(ListSpiderConfig["user-agents"].get(list)
                            or [f"DanbooruSpider/{VERSION}"])
             },
         )
         response.raise_for_status()
         data: APIResult_T = response.json()
         logger.trace("Finished downloading list " +
                      f"{urlParsed.full_path!r} from {urlParsed.host!r}.")
     except HTTPError as e:
         raise NetworkException(
             "There was an error in the network when processing the list " +
             f"{url!r}, the reason is: {e}")
     except Exception as e:
         raise SpiderException(
             "There was a unknown error when processing the list " +
             f"{url!r}, the reason is: {e}")
     return data
def nextCurrImgBox(panel):
	"""
	updates the current image container with the next word taken from the dictionary

	argument:
		panel -- reference to MainPanel
	"""

	if len(panel.wordDict) > 0:
		panel.currWord = randChoice(panel.wordDict.keys())
		panel.definition = panel.wordDict[panel.currWord]
		panel.wordDict.pop(panel.currWord)

		panel.currWordLabel.SetLabel(panel.definition)

		fileList = panel.fileListForWord(panel.currWord)

		[img.Destroy() for img in panel.currImgHolder]
		panel.currImgHolder = []

		panel.drawWord(fileList, panel.currImgSizer, panel.currImgHolder)

	else:
		[img.Hide() for img in panel.prevImgHolder]
		[img.Hide() for img in panel.currImgHolder]

		panel.currWordLabel.SetLabel("")
		panel.prevWordLabel.SetLabel("No words remaining")
		panel.LAST = True
		panel.Layout()
Example #4
0
    def enemy_choose_spell(self, player):
        """Return random spell object.

        Parameters
        ---------
        player : Person
            Person object that will choose a spell from their list of spells
        """
        aSpells = list(filter(lambda s: s.cost <= player.get_mp(),
                              player.spell))
        return randChoice(aSpells)
Example #5
0
    async def _imageDownload(
        self,
        client: AsyncClient,
        data: models.DanbooruImage,
    ) -> models.ImageDownload:
        while self._running >= self._workers:
            await asyncio.sleep(1)
        self._running += 1

        urlParsed = URL(data.imageURL)
        logger.trace("Start downloading picture " +
                     f"{urlParsed.full_path!r} from {urlParsed.host!r}.")
        tempfile, hashData, totalWrite = TempFile().create(), HashCreator(), 0
        try:
            response = await client.get(
                urlParsed,
                headers={
                    "User-Agent":
                    randChoice(ImageSpiderConfig["user-agents"].get(list)
                               or [f"DanbooruSpider/{VERSION}"]),
                },
            )
            response.raise_for_status()
            async with AsyncOpen(str(tempfile), "wb") as f:
                async for chunk in response.aiter_bytes():
                    await hashData.update(chunk)
                    totalWrite += await f.write(chunk)
            logger.trace("Finished downloading picture " +
                         f"{urlParsed.full_path!r} from {urlParsed.host!r}, " +
                         f"total write {totalWrite} bytes.")
        except HTTPError as e:
            raise NetworkException(
                "There was an error in the network when processing the picture "
                + f"'{urlParsed}', the reason is: {e}")
        except Exception as e:
            raise SpiderException(
                "There was a unknown error when processing the picture " +
                f"'{urlParsed}', the reason is: {e}")
        finally:
            self._running -= 1
        return models.ImageDownload(
            **{
                "source": str(urlParsed),
                "path": tempfile,
                "size": totalWrite,
                "md5": await hashData.hexdigest(),
                "data": data,
            })
	def addCurrImgBox(self):

		self.currWord=randChoice(self.wordDict.keys())
		self.definition=self.wordDict[self.currWord]
		self.wordDict.pop(self.currWord)

		self.currWordLabel=wx.StaticText(self)
		font=wx.Font(14, wx.FONTFAMILY_DEFAULT, wx.FONTWEIGHT_NORMAL, wx.FONTWEIGHT_NORMAL)
		self.currWordLabel.SetFont(font)

		fileList=self.fileListForWord(self.currWord)

		self.drawWord(fileList, self.currImgSizer, self.currImgHolder)
		self.currImgNLabelSizer.Add(self.currImgSizer, flag=wx.ALIGN_CENTRE)

		self.currWordLabel.SetLabel(self.definition)
		self.currImgNLabelSizer.Add(self.currWordLabel, flag=wx.ALIGN_CENTRE)
Example #7
0
    def addCurrImgBox(self):

        self.currWord = randChoice(self.wordDict.keys())
        self.definition = self.wordDict[self.currWord]
        self.wordDict.pop(self.currWord)

        self.currWordLabel = wx.StaticText(self)
        font = wx.Font(14, wx.FONTFAMILY_DEFAULT, wx.FONTWEIGHT_NORMAL,
                       wx.FONTWEIGHT_NORMAL)
        self.currWordLabel.SetFont(font)

        fileList = self.fileListForWord(self.currWord)

        self.drawWord(fileList, self.currImgSizer, self.currImgHolder)
        self.currImgNLabelSizer.Add(self.currImgSizer, flag=wx.ALIGN_CENTRE)

        self.currWordLabel.SetLabel(self.definition)
        self.currImgNLabelSizer.Add(self.currWordLabel, flag=wx.ALIGN_CENTRE)
	def addCurrImgBox(self):
		"""
		create the container that will hold the current word/image of syllables
		the chosen starting word is initalized by random selection from self.wordDict
		create sylabble images for the word and add them to the self.currImgSizer which will display the images
		"""

		self.currWord = randChoice(self.wordDict.keys())
		self.definition = self.wordDict[self.currWord]
		self.wordDict.pop(self.currWord)

		self.currWordLabel = wx.StaticText(self)
		self.currWordLabel.SetFont(self.img_box_font)

		fileList = self.fileListForWord(self.currWord)

		self.drawWord(fileList, self.currImgSizer, self.currImgHolder)
		self.currImgNLabelSizer.Add(self.currImgSizer, flag=wx.ALIGN_CENTRE)

		self.currWordLabel.SetLabel(self.definition)
		self.currImgNLabelSizer.Add(self.currWordLabel, flag=wx.ALIGN_CENTRE)
def nextCurrImgBox(self, evt):

	if len(self.wordDict)>0:
		self.currWord=randChoice(self.wordDict.keys())
		self.definition=self.wordDict[self.currWord]
		self.wordDict.pop(self.currWord)

		self.currWordLabel.SetLabel(self.definition)

		fileList=self.fileListForWord(self.currWord)

		[img.Destroy() for img in self.currImgHolder]
		self.currImgHolder=[]

		self.drawWord(fileList, self.currImgSizer, self.currImgHolder, hidden=True)

	else:
		[img.Hide() for img in self.prevImgHolder]
		[img.Hide() for img in self.currImgHolder]

		self.currWordLabel.SetLabel("")
		self.prevWordLabel.SetLabel("No words remaining")
		self.LAST=True
		self.Layout()
Example #10
0
 def randomPlayerWithoutPres(self):
     if len(self.playersWithoutPresents) > 0:
         player = randChoice(list(self.playersWithoutPresents))
         return player
     return None
Example #11
0
#!/usr/bin/env python3

import sys
import string
from random import choice as randChoice, randint
from searchAlgo import node, aStarSearch, greedyBestFirstSearch, backTrace

if len(sys.argv) != 3:
    print("{}: Missing required arguments".format(sys.argv[0]))
    print("Usage: {} numBlocks numStacks".format(sys.argv[0]))
    print("Eg: {} 5 3 for initial state with 5 blocks and 3 stacks".format(
        sys.argv[0]))
    sys.exit()

numBlocks = int(sys.argv[1])
numStacks = int(sys.argv[2])
goalState = list(string.ascii_lowercase[0:numBlocks])
initState = [[] for _ in range(numStacks)]
# For sequences(lists, tuples, strings), empty sequences are False
while goalState:
    stackNo = randint(0, numStacks - 1)
    block = randChoice(goalState)
    initState[stackNo].append(block)
    goalState.remove(block)

initNode = node(initState, 0, None)
goal = aStarSearch(initNode)
print("Solution Path:")
backTrace(goal)
print("Total steps taken : {}".format(goal.pathcost))