mark items as owned and unowned
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
from .manager import *
|
||||
from .accounts import *
|
||||
from .owning import *
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from gui.gui import Ui_MainWindow
|
||||
from modules.database import Database
|
||||
from gui.modules.core import items_list
|
||||
from modules.config import Config
|
||||
|
||||
|
||||
@@ -17,3 +18,4 @@ def fill_accounts(ui: Ui_MainWindow):
|
||||
def set_current_profile(ui: Ui_MainWindow):
|
||||
if ui.accounts_list.currentItem():
|
||||
Config.update("profile", ui.accounts_list.currentItem().text())
|
||||
items_list.refill_list(ui)
|
||||
|
||||
14
gui/modules/account/owning.py
Normal file
14
gui/modules/account/owning.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from gui.gui import Ui_MainWindow
|
||||
from gui.modules.core import items_list
|
||||
from modules.database import Database
|
||||
|
||||
|
||||
def on_change_owning_clicked(ui: Ui_MainWindow):
|
||||
if items_list.selected_item(ui) not in Database.get_profile().owned_items:
|
||||
Database.set_owned(items_list.selected_item(ui))
|
||||
ui.own_button.setText("Mark this item as unowned")
|
||||
items_list.refill_list(ui)
|
||||
else:
|
||||
Database.set_unowned(items_list.selected_item(ui))
|
||||
ui.own_button.setText("Mark this item as owned")
|
||||
items_list.refill_list(ui)
|
||||
@@ -6,6 +6,12 @@ from PyQt5 import QtWidgets, QtGui
|
||||
from gui.modules.handlers import fill_info
|
||||
|
||||
|
||||
def selected_item(ui: Ui_MainWindow):
|
||||
if ui.items_list.currentItem():
|
||||
return ui.items_list.currentItem().text() \
|
||||
.removesuffix(' - ' + ui.items_list.currentItem().text().split(' - ')[-1]).replace("☑", "")
|
||||
|
||||
|
||||
def refill_list(ui: Ui_MainWindow):
|
||||
ui.items_list.clear()
|
||||
if Database.get().items:
|
||||
@@ -24,14 +30,14 @@ def refill_list(ui: Ui_MainWindow):
|
||||
continue
|
||||
|
||||
if (not ui.filter_show_owned_items_check.isChecked()) and item.item_name in \
|
||||
Database.get().profiles[Config.get().profile].owned_items:
|
||||
Database.get_profile().owned_items:
|
||||
continue
|
||||
|
||||
list_item = QtWidgets.QListWidgetItem()
|
||||
if Config.get().profile:
|
||||
ui.own_button.setEnabled(True)
|
||||
|
||||
if item.item_name in Database.get().profiles[Config.get().profile].owned_items:
|
||||
if item.item_name in Database.get_profile().owned_items:
|
||||
ui.own_button.setText("Mark this item as unowned")
|
||||
else:
|
||||
ui.own_button.setText("Mark this item as owned")
|
||||
@@ -39,9 +45,11 @@ def refill_list(ui: Ui_MainWindow):
|
||||
ui.own_button.setEnabled(False)
|
||||
ui.own_button.setText("Select profile first")
|
||||
|
||||
list_item.setText(f''
|
||||
f'{"☑" if Config.get().profile and item.item_name in Database.get().profiles[Config.get().profile].owned_items else ""}'
|
||||
f'{item.item_name} - ${"{:,}".format(item.price)}')
|
||||
list_item.setText(
|
||||
f''
|
||||
f'{"☑" if Config.get().profile and item.item_name in Database.get_profile().owned_items else ""}'
|
||||
f'{item.item_name} - ${"{:,}".format(item.price)}'
|
||||
)
|
||||
pixmap = QtGui.QPixmap()
|
||||
try:
|
||||
pixmap.loadFromData(requests.get(item.image).content)
|
||||
|
||||
@@ -3,14 +3,12 @@ from PyQt5 import QtWidgets, QtGui, QtCore
|
||||
from gui.gui import Ui_MainWindow
|
||||
from modules.database import Database
|
||||
from modules.config import Config
|
||||
from gui.modules.core import items_list
|
||||
|
||||
|
||||
def on_item_click(ui: Ui_MainWindow, mode: str):
|
||||
if ui.items_list.currentItem():
|
||||
item = Database.get().items[
|
||||
ui.items_list.currentItem().text().removesuffix(' - ' + ui.items_list.currentItem().text().split(' - ')[-1])
|
||||
.replace("☑", "")
|
||||
]
|
||||
item = Database.get().items[items_list.selected_item(ui)]
|
||||
|
||||
pixmap = QtGui.QPixmap()
|
||||
try:
|
||||
@@ -23,7 +21,7 @@ def on_item_click(ui: Ui_MainWindow, mode: str):
|
||||
if Config.get().profile:
|
||||
ui.own_button.setEnabled(True)
|
||||
|
||||
if item.item_name in Database.get().profiles[Config.get().profile].owned_items:
|
||||
if item.item_name in Database.get_profile().owned_items:
|
||||
ui.own_button.setText("Mark this item as unowned")
|
||||
else:
|
||||
ui.own_button.setText("Mark this item as owned")
|
||||
|
||||
@@ -7,10 +7,7 @@ from gui.modules.filters.menu import refill_filters
|
||||
def on_rm_click(ui: Ui_MainWindow):
|
||||
from gui.modules.handlers import fill_info
|
||||
if ui.items_list.currentItem():
|
||||
Database.remove_item(
|
||||
ui.items_list.currentItem().text().removesuffix(' - ' + ui.items_list.currentItem().text().split(' - ')[-1])
|
||||
.replace("☑", "")
|
||||
)
|
||||
Database.remove_item(items_list.selected_item(ui))
|
||||
items_list.refill_list(ui)
|
||||
refill_filters(ui)
|
||||
fill_info.on_item_click(ui, 'close')
|
||||
|
||||
@@ -30,4 +30,6 @@ def register_handlers(ui: Ui_MainWindow):
|
||||
ui.accept_account_name.clicked.connect(lambda: account.manager.create_account(ui))
|
||||
ui.use_this_account_button.clicked.connect(lambda: account.accounts.set_current_profile(ui))
|
||||
|
||||
ui.own_button.clicked.connect(lambda: account.owning.on_change_owning_clicked(ui))
|
||||
|
||||
on_add_click.register_add_handlers(ui)
|
||||
|
||||
@@ -16,6 +16,10 @@ class Database:
|
||||
json.dump(default_database, f, indent=4)
|
||||
return DatabaseModel.from_dict(default_database)
|
||||
|
||||
@staticmethod
|
||||
def get_profile():
|
||||
return Database.get().profiles[Config.get().profile]
|
||||
|
||||
@staticmethod
|
||||
def write(db: DatabaseModel):
|
||||
with open(Config.get().database, 'w') as f:
|
||||
@@ -48,3 +52,18 @@ class Database:
|
||||
db.profiles.pop(profile_name)
|
||||
|
||||
Database.write(db)
|
||||
|
||||
@staticmethod
|
||||
def set_owned(item_name: str):
|
||||
db = Database.get()
|
||||
db.profiles[Config.get().profile].owned_items.append(item_name)
|
||||
|
||||
Database.write(db)
|
||||
|
||||
@staticmethod
|
||||
def set_unowned(item_name: str):
|
||||
db = Database.get()
|
||||
if item_name in db.profiles[Config.get().profile].owned_items:
|
||||
db.profiles[Config.get().profile].owned_items.remove(item_name)
|
||||
|
||||
Database.write(db)
|
||||
|
||||
Reference in New Issue
Block a user