def initial_setup(): if 'portfolio' not in os.listdir(user_config_dir()): logger.info(f"Creating {Paths.CONFIG_PATH}") os.makedirs(Paths.CONFIG_PATH) if 'config.ini' not in os.listdir(Paths.CONFIG_PATH): create_config_file() migrate_version()
def main(): try: from PyQt5.QtWinExtras import QtWin myappid = f'timeerr.portfolio.{confighandler.get_version().replace(".","-")}' QtWin.setCurrentProcessExplicitAppUserModelID(myappid) except ImportError: pass app = QApplication(sys.argv) # ----- Internationalization ------ # If a language hasn't been selected yet, we ask the user for one confighandler.initial_setup() if confighandler.get_language( ) == 'None' or confighandler.get_fiat_currency() == 'None': # Select language for the first time preferences_dlg = PreferencesSelection() preferences_dlg.exec_() # Load language selected_language = confighandler.get_language() if selected_language != 'EN': logger.info(f"Loading language {selected_language}") # Search for translation file translation_file = os.path.join( RESOURCES_PATH, f"app_{selected_language.lower()}_{confighandler.get_version()}.qm" ) if not os.path.exists(translation_file): logger.warning( f"Couldn't tanslate app to {selected_language} : Translation file missing" ) else: # Translate translator = QTranslator() translator.load(translation_file) app.installTranslator(translator) # ------- Style --------- # Dark Style Theme app.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5()) # Font defaultfont = QFont() defaultfont.setFamily('Roboto') app.setFont(defaultfont) # Icon app.setWindowIcon(resource_gatherer.get_resource_QIcon('logo.png')) # ---- Execution ---- window = MainWindow() window.show() app.exec_()
def add_cost_basis(new_account: str, starting_costbasis: float): """ Adds new account with an initial costbasis """ with create_connection() as conn: cursor = conn.cursor() query = """INSERT INTO 'costbasis' ('account','amount') VALUES (?,?);""" try: cursor.execute(query, (new_account, starting_costbasis)) logger.info( f"Added new account's '{new_account}' costbasis on database") conn.commit() except sqlite3.IntegrityError: logger.warning(f"Account {new_account} cost basis already exists") return
def add_account(account: str, token: str, amount: float, _type: str, kyc: str, description: str): token = token.lower() with create_connection() as conn: cursor = conn.cursor() query = """INSERT INTO 'cbalances' ('account','token','amount','type','kyc','description') VALUES (?,?,?,?,?,?);""" try: cursor.execute(query, (account, token, amount, _type, kyc, description)) conn.commit() logger.info(f"Added new account {account} ({token}) on database") return cursor.lastrowid except sqlite3.IntegrityError: logger.warning(f"{account=} with {token=} already exists") return
def initialize(): from portfolio import logger from portfolio.utils import confighandler from portfolio.utils.confighandler import Paths from portfolio.utils.appdirs import user_data_dir confighandler.initial_setup() # ---- Move resources to filesystem---- RESOURCES_PATH = Paths.RESOURCES_PATH # Remove previous resources if 'portfolio' in os.listdir(user_data_dir()): logger.info(f"Deleting previous resources: {RESOURCES_PATH}") shutil.rmtree(RESOURCES_PATH) # Translation files for file in os.listdir('translations'): if ".qm" in file: dest = os.path.join(RESOURCES_PATH, file) shutil.copy(os.path.join('translations',file), dest) logger.info(f"- Moved {file} translation to {dest}") # Assets shutil.copytree(os.path.join('resources'), RESOURCES_PATH) logger.info("Created resources folder on {RESOURCES_PATH}")
def closeEvent(self, event): """Making sure that the database is properly updated before closing the app""" if type(self.centralWidget()) == WelcomeWidget: return logger.info("App Closed, updating database ...") dbhandler.handle_close()
def deletePortfolioData(self, path: str): logger.info( f"Deleting portfolio data for {path}") # Delete entry confighandler.delete_portfolio_data(path)
def deletePortfolioLyt(self, name: str): logger.info(f"Deleting portfolio entry for {name}") confighandler.delete_portfolio_entry(name) for w in self.layouts_tracker[name]: w.deleteLater()