“My Mini Pokédex” is an application built in Python made to mimic a Pokédex.

Upon launch, the user can scroll through each of the entries with the arrows at the bottom, or use the list widget on the right.

You can search the list of entries by name with the search bar, or filter them by type with the drop-down menu.

To get its data, the application accesses an online database I made that contains the first original 151 Pokémon. The UI was created with Qt Designer, and imported into the main Python file. The sprites are official Pokémon sprites, but the rest of the artwork I did myself in Aseprite. The font is “Alterebro” by Jorge Moreno.

Below is all the code I wrote for the main application.

from PyQt5 import QtWidgets, uic, QtGui
import resources
from PyQt5.QtWidgets import QApplication, QMainWindow
import sys, os
import pymysql


class MyWindow(QMainWindow):
    def __init__(self):
        super(MyWindow, self).__init__()
        uic.loadUi(os.path.join(os.path.dirname(os.path.abspath(__file__)), "pokedexUI.ui"), self)

        # UI Connections
        self.leftBtn.clicked.connect(self.leftBtnClicked)
        self.rightBtn.clicked.connect(self.rightBtnClicked)
        self.comboBox.activated[str].connect(self.comboBoxChanged)
        self.listWidget.itemSelectionChanged.connect(self.listWidgetSelectionChanged)
        self.searchBar.textChanged.connect(self.searchBarChanged)

        # App displays all entries at first
        global allEntries
        allEntries = self.databaseData("All", "All")
        for row in allEntries:
            self.listWidget.addItem(row[0])
        self.loadEntries("All", "All")
        self.show()
        
    # Load appropriate entries
    def loadEntries(self, row, value):
        validEntries = self.databaseData(row, value)
        validEntriesNames = []
        for entry in validEntries:
            validEntriesNames.append(entry[0])
    
        # Entries that meet filter criteria are shown, otherwise they are hidden
        setFirst = False
        for i in range(0,self.listWidget.count()):
            row = self.listWidget.item(i)
            if row.text() in validEntriesNames:
                row.setHidden(False)
                # Select the first visible entry
                if setFirst == False:
                    self.listWidget.setCurrentItem(row)
                    setFirst = True
            else:
                row.setHidden(True)
        
    # Fetch data from database
    def databaseData(self, row, value):
        db = pymysql.connect(
        host="sql9.freesqldatabase.com",
        user="sql9591398",
        password="VWvBl4fp5U",
        database="sql9591398"
        )
        cursor = db.cursor()

        # Search for all pokemon
        if value == "All":
            sql = "SELECT * FROM Pokemon"
        # Search for both primary and secondary typings
        elif row == "Type":
            sql = "SELECT * FROM Pokemon WHERE Type1 = '{type}' OR Type2='{type}'".format(type=value)
        # Search for a name starting with the value
        elif row == "StartsName":
            sql = "SELECT * FROM Pokemon WHERE Name like '{name}%'".format(name=value)
        else:
            # General search with provided row and value
            sql = "SELECT * FROM Pokemon WHERE {row} = '{type}'".format(row=row,type=value)
            
        # Attempt to fetch data
        try:
            cursor.execute(sql)
            return cursor.fetchall()
        except:
            print("Error: Unable to fetch data")

        db.close()

    # Filter by type with the combo box
    def comboBoxChanged(self):
        self.loadEntries("Type", self.comboBox.currentText())
        self.searchBar.clear()

    def listWidgetSelectionChanged(self):
        pokemon = self.databaseData("Name", self.listWidget.selectedItems()[0].text())[0]
        self.nameLabel.setText(pokemon[0])
        self.categoryLabel.setText("The " + pokemon[1] + " Pokémon")
        self.numberLabel.setText("#" + pokemon[2])
        self.type1Label.setText(pokemon[3])
        self.type2Label.setText(pokemon[4])
        self.notesLabel.setText(pokemon[5])
        imagePath = ":/images/images/pokemon/" + pokemon[0] + ".png"
        self.pictureLabel.setPixmap(QtGui.QPixmap(imagePath))

    def searchBarChanged(self):
        print(self.searchBar.toPlainText())
        if self.searchBar.toPlainText() == "":
            return
        self.loadEntries("StartsName", self.searchBar.toPlainText())

    # Scroll back on visible entries
    def leftBtnClicked(self):
        if self.listWidget.currentItem() == self.currentVisibleEntries()[0]:
            return

        newRow = self.listWidget.currentRow() - 1
        while self.listWidget.item(newRow).isHidden() == True:
            newRow -= 1
        self.listWidget.setCurrentRow(newRow)

    # Scroll forward on visible entries
    def rightBtnClicked(self):
        if self.listWidget.currentItem() == self.currentVisibleEntries()[-1]:
            return

        newRow = self.listWidget.currentRow() + 1
        while self.listWidget.item(newRow).isHidden() == True:
            newRow += 1
        self.listWidget.setCurrentRow(newRow)
    
    def currentVisibleEntries(self):
        visible = []
        for i in range(0,self.listWidget.count()):
            row = self.listWidget.item(i)
            if row.isHidden() == False:
                visible.append(row)
        return visible

def window():
    app = QApplication(sys.argv)
    win = MyWindow()
    sys.exit(app.exec_())

window()
Previous
Previous

Max Cat

Next
Next

Pokémon-Style Battle System