<commit_before># MyInventory.setInventory(self.tab_inventory)

from tkinter import *
from tkinter.ttk import *
from hack_classes import Item
import os.path

class SetInventoryItem():
    """
    Store inventory item info, grid position, and character item reference
    """
    
    def __init__(self, name, file, description, effect, uses,
                 value, row, column, item_ref):
        self.name = name
        self.file = file
        self.description = description
        self.effect = effect
        self.uses = uses
        self.value = value
        self.row = row
        self.column = column
        self.item_ref = item_ref
        
    """"
    getter methods
    """
    
    def getName(self):
        return self.name

    def getFile(self):
        return self.file
    
    def getDescription(self):
        return self.description

    def getEffect(self):
        return self.effect

    def getUses(self):
        return self.uses

    def getValue(self):
        return self.value
    
    def getRow(self):
        return self.row

    def getColumn(self):
        return self.column

    def getItemRef(self):
        return self.item_ref

    """
    setter methods
    """
    
    def setUses(self, uses):
        self.uses = uses
        
    def setRow(self, row):
        self.row = row

    def setColumn(self, col):
        self.column = col
    

class MyInventory():
    """
    this class is used for link the Inventory class with the GUI class
    """
    
    api = None # reference to GUI class object
    my_inventory = None # Inventory class object stored here
    
    # called in work_space.py
    def setInventory(inventory_frame):
        MyInventory.my_inventory = Inventory(inventory_frame)

    # called at the end of engine/GUI's constructor function 
    def setApi(api_ref):
        MyInventory.api = api_ref
        MyInventory.my_inventory.initInventory(MyInventory.api.get_character_items())

        
class Inventory():
    def __init__(self, inventory_plugin_frame):
        self.frame = inventory_plugin_frame
        self.canvas_color = '#EBEDF1'
        
        self.items = [] # store all of the player's Item objects here
        
        self.selceted_item_id = None
        self.selected_item_ref = None
        self.item_set = False

        # used for visually updating the use count under each item object/image
        self.uses_labels = []
        
        
    def initInventory(self, char_items):
        row, col = 0, 0
        for item in char_items:
            self.items.append([SetInventoryItem(item.name, item.image, item.description, item.effect,
                                                item.uses, item.value, row, col, item), None])
            col += 1
            if col == 5: # max of 5 items in a row
                col = 0
                row += 1
   
        self.makeLayout()
        self.createItems()


    def createItems(self):
        # loops through the list of items that need to be created and shown in the shop
        for i in range(len(self.items)):
            self.makeItemFrame(i)


    def addItem(self, item):
        if len(self.items) == 0:
            self.items.append([SetInventoryItem(item.name, item.image, item.description, item.effect,
                                                item.uses, item.value, 0, 0, item), None])
            self.makeItemFrame(0)
        else:
            # this function is called when a new item is purchased
            col = self.items[len(self.items)-1][0].getColumn() + 1
            row = self.items[len(self.items)-1][0].getRow()
        
            if col == 5: # max of 5 items in a row
                col = 0
                row += 1
                
            self.items.append([SetInventoryItem(item.name, item.image, item.description, item.effect,
                                                item.uses, item.value, row, col, item), None])
            self.makeItemFrame(len(self.items)-1)
            self.reposition()

        
    def makeItemFrame(self, i):
        # prep appropriate data for when the user clicks on a item
        t_name = self.items[i][0].getName()
        t_descript = self.items[i][0].getDescription()
        t_cost = self.items[i][0].getValue()


        # create frame border for item
        border_frame = Frame(self.inventoryFrame, padding=2, cursor='hand2', style='c.TFrame')
        border_frame.grid(row=self.items[i][0].getRow(), column=self.items[i][0].getColumn(),
                          padx=7, pady=7, sticky='wn')
        self.style.configure('c.TFrame', background=self.canvas_color)

        # Important step. This refer ence is used to visually delete the item from the inventory
        self.items[i][1] = border_frame
        
        # user clicks on the frame border
        border_frame.bind('<1>', lambda e, item_id=i, item_ref=self.items[i][0].getItemRef():
                          self.selectItem(item_id, item_ref))
        border_frame.bind('<Enter>', lambda e, name=t_name, descript = t_descript, cost=t_cost :
                          self.setItemInfo(name, descript, self.items[i][0].getUses(), cost))


        # create frame for item data
        item_frame = Frame(border_frame, style='itemFrame.TFrame', padding=9, cursor='hand2')
        item_frame.grid(sticky='wn')
        self.style.configure('itemFrame.TFrame', background=self.canvas_color)
        
        # user clicks on the frame containing all of the item's info
        item_frame.bind('<1>', lambda e, item_id=i, item_ref=self.items[i][0].getItemRef():
                        self.selectItem(item_id, item_ref))
        item_frame.bind('<Enter>', lambda e, name=t_name, descript = t_descript, cost=t_cost :
                        self.setItemInfo(name, descript, self.items[i][0].getUses(), cost))
        item_frame.bind('<Enter>', lambda e, _i=i: self.highlight(_i, True))
        item_frame.bind('<Leave>', lambda e, _i=i: self.highlight(_i, False))
        

        # create label to hold the item's image
        img = PhotoImage(file=self.items[i][0].getFile())
        new_item = Label(item_frame, padding=10, image=img, style='item.TLabel', cursor='hand2')
        new_item.grid(row=1, column=0)
        new_item.image = img
        self.style.configure('item.TLabel', background=self.canvas_color)
        
        # user clicks on the image of the item
        new_item.bind('<1>', lambda e, item_id=i, item_ref=self.items[i][0].getItemRef():
                      self.selectItem(item_id, item_ref))
        new_item.bind('<Enter>', lambda e, name=t_name, descript = t_descript, cost=t_cost :
                      self.setItemInfo(name, descript, self.items[i][0].getUses(), cost))

        # create dynamic label for displaying the number of uses remaining for the given item
        str_uses = StringVar()
        str_uses.set("uses: " + str(self.items[i][0].getUses()))
        uses_label = Label(item_frame, textvariable=str_uses, anchor=CENTER, foreground='#646464',
                     background=self.canvas_color, font='arial 10 bold italic')
        uses_label.grid(row=2, column=0, sticky='news')
        self.uses_labels.append([str_uses, uses_label])
        
    def remove_selected_item(self):
        """
        remove the item from the panel on the
        right side of the inventory
        """
        self.selectedItem.image = None
        self.selectedItem.destroy()
        self.selectedItemFrame.destroy()

        
    def remove_item_from_inventory(self, item_id):
        """
        remove the selected item from the inventory
        on both sell and use commands
        """
        self.remove_selected_item()
        self.items[item_id][1].destroy()
        self.items[item_id][1] = None
        self.reposition()
        self.item_set = False

        
    def selectItem(self, item_id, item):
        """<commit_msg>clicking on the uses label also selects the item now<commit_after># MyInventory.setInventory(self.tab_inventory)

from tkinter import *
from tkinter.ttk import *
from hack_classes import Item
import os.path

class SetInventoryItem():
    """
    Store inventory item info, grid position, and character item reference
    """
    
    def __init__(self, name, file, description, effect, uses,
                 value, row, column, item_ref):
        self.name = name
        self.file = file
        self.description = description
        self.effect = effect
        self.uses = uses
        self.value = value
        self.row = row
        self.column = column
        self.item_ref = item_ref
        
    """"
    getter methods
    """
    
    def getName(self):
        return self.name

    def getFile(self):
        return self.file
    
    def getDescription(self):
        return self.description

    def getEffect(self):
        return self.effect

    def getUses(self):
        return self.uses

    def getValue(self):
        return self.value
    
    def getRow(self):
        return self.row

    def getColumn(self):
        return self.column

    def getItemRef(self):
        return self.item_ref

    """
    setter methods
    """
    
    def setUses(self, uses):
        self.uses = uses
        
    def setRow(self, row):
        self.row = row

    def setColumn(self, col):
        self.column = col
    

class MyInventory():
    """
    this class is used for link the Inventory class with the GUI class
    """
    
    api = None # reference to GUI class object
    my_inventory = None # Inventory class object stored here
    
    # called in work_space.py
    def setInventory(inventory_frame):
        MyInventory.my_inventory = Inventory(inventory_frame)

    # called at the end of engine/GUI's constructor function 
    def setApi(api_ref):
        MyInventory.api = api_ref
        MyInventory.my_inventory.initInventory(MyInventory.api.get_character_items())

        
class Inventory():
    def __init__(self, inventory_plugin_frame):
        self.frame = inventory_plugin_frame
        self.canvas_color = '#EBEDF1'
        
        self.items = [] # store all of the player's Item objects here
        
        self.selceted_item_id = None
        self.selected_item_ref = None
        self.item_set = False

        # used for visually updating the use count under each item object/image
        self.uses_labels = []
        
        
    def initInventory(self, char_items):
        row, col = 0, 0
        for item in char_items:
            self.items.append([SetInventoryItem(item.name, item.image, item.description, item.effect,
                                                item.uses, item.value, row, col, item), None])
            col += 1
            if col == 5: # max of 5 items in a row
                col = 0
                row += 1
   
        self.makeLayout()
        self.createItems()


    def createItems(self):
        # loops through the list of items that need to be created and shown in the shop
        for i in range(len(self.items)):
            self.makeItemFrame(i)


    def addItem(self, item):
        if len(self.items) == 0:
            self.items.append([SetInventoryItem(item.name, item.image, item.description, item.effect,
                                                item.uses, item.value, 0, 0, item), None])
            self.makeItemFrame(0)
        else:
            # this function is called when a new item is purchased
            col = self.items[len(self.items)-1][0].getColumn() + 1
            row = self.items[len(self.items)-1][0].getRow()
        
            if col == 5: # max of 5 items in a row
                col = 0
                row += 1
                
            self.items.append([SetInventoryItem(item.name, item.image, item.description, item.effect,
                                                item.uses, item.value, row, col, item), None])
            self.makeItemFrame(len(self.items)-1)
            self.reposition()

        
    def makeItemFrame(self, i):
        # prep appropriate data for when the user clicks on a item
        t_name = self.items[i][0].getName()
        t_descript = self.items[i][0].getDescription()
        t_cost = self.items[i][0].getValue()


        # create frame border for item
        border_frame = Frame(self.inventoryFrame, padding=2, cursor='hand2', style='c.TFrame')
        border_frame.grid(row=self.items[i][0].getRow(), column=self.items[i][0].getColumn(),
                          padx=7, pady=7, sticky='wn')
        self.style.configure('c.TFrame', background=self.canvas_color)

        # Important step. This refer ence is used to visually delete the item from the inventory
        self.items[i][1] = border_frame
        
        # user clicks on the frame border
        border_frame.bind('<1>', lambda e, item_id=i, item_ref=self.items[i][0].getItemRef():
                          self.selectItem(item_id, item_ref))
        border_frame.bind('<Enter>', lambda e, name=t_name, descript = t_descript, cost=t_cost :
                          self.setItemInfo(name, descript, self.items[i][0].getUses(), cost))


        # create frame for item data
        item_frame = Frame(border_frame, style='itemFrame.TFrame', padding=9, cursor='hand2')
        item_frame.grid(sticky='wn')
        self.style.configure('itemFrame.TFrame', background=self.canvas_color)
        
        # user clicks on the frame containing all of the item's info
        item_frame.bind('<1>', lambda e, item_id=i, item_ref=self.items[i][0].getItemRef():
                        self.selectItem(item_id, item_ref))
        item_frame.bind('<Enter>', lambda e, name=t_name, descript = t_descript, cost=t_cost :
                        self.setItemInfo(name, descript, self.items[i][0].getUses(), cost))
        item_frame.bind('<Enter>', lambda e, _i=i: self.highlight(_i, True))
        item_frame.bind('<Leave>', lambda e, _i=i: self.highlight(_i, False))
        

        # create label to hold the item's image
        img = PhotoImage(file=self.items[i][0].getFile())
        new_item = Label(item_frame, padding=10, image=img, style='item.TLabel', cursor='hand2')
        new_item.grid(row=1, column=0)
        new_item.image = img
        self.style.configure('item.TLabel', background=self.canvas_color)
        
        # user clicks on the image of the item
        new_item.bind('<1>', lambda e, item_id=i, item_ref=self.items[i][0].getItemRef():
                      self.selectItem(item_id, item_ref))
        new_item.bind('<Enter>', lambda e, name=t_name, descript = t_descript, cost=t_cost :
                      self.setItemInfo(name, descript, self.items[i][0].getUses(), cost))

        # create dynamic label for displaying the number of uses remaining for the given item
        str_uses = StringVar()
        str_uses.set("uses: " + str(self.items[i][0].getUses()))
        uses_label = Label(item_frame, textvariable=str_uses, anchor=CENTER, foreground='#646464',
                     background=self.canvas_color, font='arial 10 bold italic')
        uses_label.grid(row=2, column=0, sticky='news')
        uses_label.bind('<1>', lambda e, item_id=i, item_ref=self.items[i][0].getItemRef():
                        self.selectItem(item_id, item_ref))
        self.uses_labels.append([str_uses, uses_label])
        
    def remove_selected_item(self):
        """
        remove the item from the panel on the
        right side of the inventory
        """
        self.selectedItem.image = None
        self.selectedItem.destroy()
        self.selectedItemFrame.destroy()

        
    def remove_item_from_inventory(self, item_id):
        """
        remove the selected item from the inventory
        on both sell and use commands
        """
        self.remove_selected_item()
        self.items[item_id][1].destroy()
        self.items[item_id][1] = None
        self.reposition()
        self.item_set = False

        
    def selectItem(self, item_id, item):
        """
{'fraction_non_alphanumeric': 0.10718093446221386, 'fraction_numerical': 0.007902163687676388, 'mean_word_length': 2.101731180704143, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4761878', 'n_tokens_mistral': 4708, 'n_tokens_neox': 4557, 'n_words': 1164}