def setupSeries(self, mode="all"): """ Chart gets updated displaying the new data. Modes: - all : distribution between all accounts - accs : distribution between portfolio accounts - cryptoaccs : distribution between crypto accounts - strategies : distribution between strategies """ # Series self.chart.removeAllSeries() # Remove any previous series self.series = QPieSeries() # Get data if mode == "all": data = balances.get_all_accounts( ) + cbalances.get_all_accounts_with_amount_fiat() elif mode == "accounts": data = balances.get_all_accounts() elif mode == "crypto": data = cbalances.get_all_accounts_with_amount_fiat() elif mode == "currency": data = [(confighandler.get_fiat_currency().upper(), balances.get_total_balance_all_accounts( )), ("BTC", cbalances.get_total_balance_all_accounts_fiat())] data.sort(key=lambda x: x[1]) # Sort # Set Chart Title self.total = sum([i[1] for i in data]) self.setDefaultTitle() # Add to series for d in data: self.series.append(d[0], d[1]) # Hide little slices' labels self.series.setLabelsVisible(True) for slc in self.series.slices(): if slc.angleSpan() < 5: slc.setLabelVisible(False) slc.setLabelArmLengthFactor(0.05) self.chart.addSeries(self.series) # Signals and functionality self.series.hovered.connect(self.selectSlice)
def insertTransaction(self): # Current data self.current_date = datetime(self.date_edit.date().year(), self.date_edit.date().month(), self.date_edit.date().day()).timestamp() self.current_senderaccount = self.senderaccount_select.currentText() self.current_receiveraccount = self.receiveraccount_select.currentText( ) self.current_amount = int(float(self.amount_select.text()[:-2])) # Deposit/Withdrawal/Transfer if self.deposit_checkbox.isChecked(): self.currenttype = 1 elif self.withdrawal_checkbox.isChecked(): self.currenttype = -1 else: # No checked defaults to transfer self.currenttype = 0 # If there is a new account involved, it should be created first all_accounts = [i[0] for i in balances.get_all_accounts()] if self.current_senderaccount not in all_accounts: balances.add_account(self.current_senderaccount, 0) if self.current_receiveraccount not in all_accounts: balances.add_account(self.current_receiveraccount, 0) # Adding the transaction on db transactions.add_transaction(self.current_date, self.current_senderaccount, self.current_amount, self.current_receiveraccount, self.currenttype, description=self.description_edit.text())
def insertResult(self): """ Insert current form state as a result on the database """ current_date = datetime(self.date_edit.date().year(), self.date_edit.date().month(), self.date_edit.date().day()).timestamp() current_account = self.account_select.currentText() current_strategy = self.strategy_select.currentText() current_amount = self.amount_select.text()[:-2] current_description = self.description_select.text() results.add_result(current_date, current_account, current_strategy, current_amount, description=current_description) # Resetting Account and Strategy QComboBoxes self.account_select.clear() self.strategy_select.clear() currentaccounts = [a[0] for a in balances.get_all_accounts()] self.account_select.addItems(currentaccounts) currentstrategies = [i[0] for i in strategies.get_all_strategies()] self.strategy_select.addItems(currentstrategies) self.resultAdded.emit()
def __init__(self, *agrs, **kwargs): super().__init__(*agrs, **kwargs) self.setWindowTitle(self.tr("Edit Account")) self.layout = QVBoxLayout() # Account selection self.account_selection_combobox = QComboBox() for acc in balances.get_all_accounts(): self.account_selection_combobox.addItem(acc[0]) # Edit account form self.layout_form = QFormLayout() self.name_change_label = QLabel(self.tr("New Name")) self.name_change_field = QLineEdit() self.layout_form.setWidget(0, self.layout_form.LabelRole, self.name_change_label) self.layout_form.setWidget(0, self.layout_form.FieldRole, self.name_change_field) self.balance_change_label = QLabel(self.tr("Balance")) self.balance_change_field = QLineEdit() self.balance_change_field.setReadOnly(True) self.layout_form.setWidget(1, self.layout_form.LabelRole, self.balance_change_label) self.layout_form.setWidget( 1, self.layout_form.FieldRole, self.balance_change_field ) # We'll tell the user that any account balance change should be done differently # Save changes button self.save_changes_bttn = QPushButton(self.tr("Save Changes")) self.save_changes_bttn.clicked.connect(self.saveChanges) self.layout.addWidget(self.account_selection_combobox) self.layout.addSpacing(30) self.layout.addLayout(self.layout_form) self.layout.addWidget(self.save_changes_bttn) self.setLayout(self.layout) # Functionality self.account_selection_combobox.currentTextChanged.connect( self.fillFields) # Initialization self.fillFields(self.account_selection_combobox.currentText()) # Custom Signal self.customSignal = SignalEditAccount()
def add_todays_balances(): """ Reads balances from balances table, and updates the balancehistory table accordingly """ conn = create_connection() with create_connection() as conn: cursor = conn.cursor() todays_balances = get_balances_from_last_day() current_accounts = balances.get_all_accounts() # Delete previous balances from today # (that way we'll avoid dealing with new accounts) for balance_history in todays_balances: _id = balance_history[0] delete_balance_from_id(_id) # Write today's balances query = "INSERT INTO 'balancehistory' (account, date, balance) VALUES (?,?,?);" for acc in current_accounts: account, balance, *_ = acc cursor.execute( query, (account, int(datetime.today().timestamp()), balance)) conn.commit()
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # Title self.title = QLabel(self.tr("Add Transaction")) self.title.setFont(TitleFont()) self.title.setAlignment(Qt.AlignCenter) # First line: Date self.label1 = QLabel(self.tr("Date")) # self.label1.setMinimumWidth(120) self.label1.setMaximumWidth(120) self.date_edit = QDateEdit(datetime.now()) self.date_edit.setDisplayFormat("dd/MM/yyyy") self.date_edit.setCalendarPopup(True) self.label1_checkbox = QPushButton(self.tr("Today")) self.label1_checkbox.setMaximumWidth(50) self.label1_checkbox.clicked.connect(self.setToday) self.line1 = QHBoxLayout() self.line1.addWidget(self.label1) self.line1.addWidget(self.date_edit) self.line1.addWidget(self.label1_checkbox) # Second Line: Account self.label2 = QLabel(self.tr("Sender Account")) self.label2.setMinimumWidth(120) self.label2.setMaximumWidth(120) self.senderaccount_select = QComboBox() self.senderaccount_select.setEditable(True) self.senderaccount_select.setDuplicatesEnabled(False) currentaccounts = [a[0] for a in balances.get_all_accounts()] self.senderaccount_select.addItems(currentaccounts) self.line2 = QHBoxLayout() self.line2.addWidget(self.label2) self.line2.addWidget(self.senderaccount_select, Qt.AlignLeft) # Third Line: Receiver Account self.label3 = QLabel(self.tr("Receiver Account")) self.label3.setMinimumWidth(120) self.label3.setMaximumWidth(120) self.receiveraccount_select = QComboBox() self.receiveraccount_select.setEditable(True) self.receiveraccount_select.setDuplicatesEnabled(False) currentaccounts = [a[0] for a in balances.get_all_accounts()] self.receiveraccount_select.addItems(currentaccounts) self.receiveraccount_select.setCurrentIndex(1) self.line3 = QHBoxLayout() self.line3.addWidget(self.label3) self.line3.addWidget(self.receiveraccount_select, Qt.AlignLeft) # Fourth Line: Amount self.label4 = QLabel(self.tr("Amount")) self.label4.setMinimumWidth(120) self.label4.setMaximumWidth(120) self.amount_select = QSpinBox() self.amount_select.setSuffix(" €") self.amount_select.setMinimum(0) self.amount_select.setMaximum(999999999) self.amount_select.setAccelerated(True) self.line4 = QHBoxLayout() self.line4.addWidget(self.label4) self.line4.addWidget(self.amount_select, Qt.AlignLeft) # Fifth Line: Deposit or Withdrawal self.group = QButtonGroup(self) self.deposit_checkbox = QCheckBox('Deposit') self.deposit_checkbox.stateChanged.connect(self.handlechecks) self.withdrawal_checkbox = QCheckBox('Withdrawal') self.withdrawal_checkbox.stateChanged.connect(self.handlechecks) self.transfer_checkbox = QCheckBox('Transfer') self.transfer_checkbox.stateChanged.connect(self.handlechecks) self.line5 = QHBoxLayout() self.line5.addWidget(self.deposit_checkbox) self.line5.addWidget(self.withdrawal_checkbox) self.line5.addWidget(self.transfer_checkbox) # Sixth Line: Description self.label6 = QLabel(self.tr("Description")) self.label6.setFixedWidth(120) self.description_edit = QLineEdit() self.line6 = QHBoxLayout() self.line6.addWidget(self.label6) self.line6.addWidget(self.description_edit) # Buttons self.button_layout = QHBoxLayout() self.insert_button = QPushButton(self.tr("Insert")) self.insert_button.setMaximumWidth(50) self.button_layout.setAlignment(Qt.AlignHCenter | Qt.AlignTop) # Centering it self.button_layout.setContentsMargins(QMargins( 10, 10, 10, 10)) # A little bit of margin self.insert_button.clicked.connect(self.insertTransaction) self.button_layout.addWidget(self.insert_button, Qt.AlignVCenter) self.addWidget(self.title) self.addLayout(self.line1) self.addLayout(self.line2) self.addLayout(self.line3) self.addLayout(self.line4) self.addLayout(self.line5) self.addLayout(self.line6) self.addLayout(self.button_layout) # Signal handle self.receiveraccount_select.currentTextChanged.connect( self.handleselections) self.senderaccount_select.currentTextChanged.connect( self.handleselections)
def set_combobox(self): self.name_select.clear() for acc in balances.get_all_accounts(): self.name_select.addItem(acc[0])
def changeCellOnDatabase(self, row, column): """ When a Table Item is edited by the user, we want to check if it fits the type and edit it on the database too """ if self.updatingdata_flag is True: return # The data is being modified internally (not by the user) # so no errors assumed new_item = self.item(row, column) new_item_data = new_item.text() database_entry_id = self.item(row, 0).text() previous_amount = results.getResultAmountById( database_entry_id) # Useful for balance adjustments later columnselected_name = self.horizontalHeaderItem(column).text() # Depending on from which column the item is, we check the data # proposed differently # Check which part of the transaction has been edited, and accting accordingly # -------------- id -------------------- if columnselected_name == self.tr("Id"): # Ids can't be edited error_mssg = QMessageBox() error_mssg.setIcon(QMessageBox.Warning) error_mssg.setText(self.tr("Ids can't be edited")) error_mssg.exec_() # -------------- Date -------------------- elif columnselected_name == self.tr("Date"): # The new text has to be a date try: new_date = datetime.strptime(new_item_data, "%d-%m-%Y") results.update_result(database_entry_id, new_date=new_date.timestamp()) except ValueError: error_mssg = QMessageBox() error_mssg.setIcon(QMessageBox.Warning) error_mssg.setText( self.tr("Has to be a date in format dd-mm-yyyy")) error_mssg.exec_() # Reset date to previous one previous_date_timestamp = results.get_result_date_by_id( database_entry_id) previous_date_text = datetime.fromtimestamp( previous_date_timestamp).strftime("%d-%m-%Y") self.updatingdata_flag = True new_item.setData(0, previous_date_text) self.updatingdata_flag = False # -------------- Account -------------------- elif columnselected_name == self.tr("Account"): # The account has to be an existing one all_accounts = [a[0] for a in balances.get_all_accounts()] previous_account = results.get_result_account_by_id( database_entry_id) if new_item_data not in all_accounts: error_mssg = QMessageBox() error_mssg.setIcon(QMessageBox.Warning) error_mssg.setText( self. tr("The account has to be an existing one. \nAdd it first manually" )) error_mssg.exec_() # Reset strategy to previous one self.updatingdata_flag = True new_item.setData(0, previous_account) self.updatingdata_flag = False else: # The data is good # Change the result on the results table on the db results.update_result(database_entry_id, new_account=new_item_data) # Update the balance of the two accounts involved, # according to the result amount balances.update_balances_with_new_result( previous_account, -previous_amount) balances.update_balances_with_new_result( new_item_data, previous_amount) # -------------- Strategy -------------------- elif columnselected_name == self.tr("Strategy"): # The strategy has to be an existing one previous_strategy = results.get_result_strategy_by_id( database_entry_id) all_strategies = [s[0] for s in strategies.get_all_strategies()] if new_item_data not in all_strategies: error_mssg = QMessageBox() error_mssg.setIcon(QMessageBox.Warning) error_mssg.setText( self. tr("The strategy has to be an existing one. \nAdd it first manually" )) error_mssg.exec_() # Reset strategy to previous one self.updatingdata_flag = True new_item.setData(0, previous_strategy) self.updatingdata_flag = False else: # The data is good # Change the result on the results table of the db results.updateResult(database_entry_id, newstrategy=new_item_data) # Update the pnl of the two strategies involved, # according to the result amount strategies.update_strategies_with_new_result( previous_strategy, -previous_amount) strategies.update_strategies_with_new_result( new_item_data, previous_amount) # -------------- Amount -------------------- elif columnselected_name == self.tr("Amount"): # The amount has to be an integer try: new_item_data = int(new_item_data) # Change the result on the results table of the db results.update_result(database_entry_id, new_amount=new_item_data) # Update the balances and strategies with the difference # between the old and the new result diff_betweeen_results = new_item_data - previous_amount account_involved = results.get_result_account_by_id( database_entry_id) strategy_involved = results.get_result_strategy_by_id( database_entry_id) balances.update_balances_with_new_result( account_involved, diff_betweeen_results) strategies.update_strategies_with_new_result( strategy_involved, diff_betweeen_results) except Exception: error_mssg = QMessageBox() error_mssg.setIcon(QMessageBox.Warning) error_mssg.setText(self.tr("Has to be an integer")) error_mssg.exec_() # Reset to previous amount previous_amount = results.get_result_amount_by_id( database_entry_id) self.updatingdata_flag = True new_item.setData(0, previous_amount) self.updatingdata_flag = False # -------------- Description -------------------- elif columnselected_name == self.tr("Description"): # A description can be any data. So no checks results.update_result(database_entry_id, new_description=new_item_data)
def changeCellOnDatabase(self, row, column): """ When a Table Item is edited by the user, we want to check if it fits the type and edit it on the database too """ if self.updatingdata_flag is True: return # The data is being modified internally (not by the user) # so no errors is assumed # Getting edited item data new_item = self.item(row, column) new_item_data = new_item.text() database_entry_id = self.item(row, 0).text() previous_amount = transactions.get_transaction_amount_by_id( database_entry_id ) # Useful for balance and costbasis adjustments later columnselected_name = self.horizontalHeaderItem(column).text() # Depending on from which column the item is, we check the data # proposed differently # Check which part of the transaction has been edited, and accting accordingly # -------------- id -------------------- if columnselected_name == self.tr("id"): # Ids can't be edited error_mssg = QMessageBox() error_mssg.setIcon(QMessageBox.Warning) error_mssg.setText(self.tr("Ids can't be edited")) error_mssg.exec_() # -------------- Date -------------------- elif columnselected_name == self.tr("Date"): # The new text has to be a date try: new_date = datetime.strptime(new_item_data, "%d-%m-%Y") transactions.update_transaction(database_entry_id, newdate=new_date.timestamp()) except ValueError: error_mssg = QMessageBox() error_mssg.setIcon(QMessageBox.Warning) error_mssg.setText( self.tr("Has to be a date in format dd-mm-yyyy")) error_mssg.exec_() # Reset date to previous one previous_date_timestamp = transactions.get_transaction_date_by_id( database_entry_id) previous_date_text = datetime.fromtimestamp( previous_date_timestamp).strftime("%d-%m-%Y") self.updatingdata_flag = True new_item.setData(0, previous_date_text) self.updatingdata_flag = False # -------------- Sender Account -------------------- elif columnselected_name == self.tr("Sender Account"): # The account has to be an existing one all_sender_accounts = [a[0] for a in balances.get_all_accounts()] previous_sender_account = transactions.get_transaction_sender_account_by_id( database_entry_id) if new_item_data not in all_sender_accounts: error_mssg = QMessageBox() error_mssg.setIcon(QMessageBox.Warning) error_mssg.setText( self. tr("The account has to be an existing one. \nAdd it first manually" )) error_mssg.exec_() # Reset strategy to previous one self.updatingdata_flag = True new_item.setData(0, previous_sender_account) self.updatingdata_flag = False else: # The data is good # Change the transaction on the transactions table on the db transactions.update_transaction(database_entry_id, new_sender == new_item_data) # Update the balance of the two accounts involved, # according to the transactions amount balances.update_balances_with_new_result( previous_sender_account, previous_amount) balances.update_balances_with_new_result( new_item_data, -previous_amount) # Same with costbasis costbasis.update_cost_basis_with_new_transaction( previous_sender_account, previous_amount) costbasis.update_cost_basis_with_new_transaction( new_item_data, -previous_amount) # If the sender account is now Cash, the transaction turns into a deposit if new_item_data == "Cash": transactions.update_transaction(database_entry_id, new_d_or_w=1) type_item = self.item( row, self.horizontalheaders.index(self.tr("Type"))) type_item.setData(0, self.tr("Deposit")) # If the sender account was Cash, the transaction turns into a transfer elif previous_sender_account == "Cash": transactions.update_transaction(database_entry_id, new_d_or_w=0) type_item = self.item( row, self.horizontalheaders.index(self.tr("Type"))) type_item.setData(0, self.tr("Transfer")) # -------------- Amount -------------------- elif columnselected_name == self.tr("Amount"): # The amount has to be an integer try: new_item_data = int(new_item_data) # Change the transaction on the transactions table on the db transactions.update_transaction(database_entry_id, new_amount=new_item_data) # Update the balances and strategies with the difference # between the old and the new transaction diff_betweeen_transactions = new_item_data - previous_amount senderaccount_involved = transactions.get_transaction_sender_account_by_id( database_entry_id) receiveraccount_involved = transactions.get_transaction_receiver_account_by_id( database_entry_id) # Update the balance of the accounts involved, # according to the new amount balances.update_balances_with_new_result( senderaccount_involved, -diff_betweeen_transactions) balances.update_balances_with_new_result( receiveraccount_involved, diff_betweeen_transactions) # Same with costbasis costbasis.update_cost_basis_with_new_transaction( senderaccount_involved, -diff_betweeen_transactions) costbasis.update_cost_basis_with_new_transaction( receiveraccount_involved, diff_betweeen_transactions) except Exception: error_mssg = QMessageBox() error_mssg.setIcon(QMessageBox.Warning) error_mssg.setText(self.tr("Has to be an integer")) error_mssg.exec_() # Reset to previous amount previous_amount = transactions.get_transaction_amount_by_id( database_entry_id) self.updatingdata_flag = True new_item.setData(0, previous_amount) self.updatingdata_flag = False # -------------- Receiver Account -------------------- elif columnselected_name == self.tr("Receiver Account"): # The account has to be an existing one all_receiver_accounts = [a[0] for a in balances.getAllAccounts()] previous_receiver_account = transactions.getTransactionReceiverAccountById( database_entry_id) if new_item_data not in all_receiver_accounts: error_mssg = QMessageBox() error_mssg.setIcon(QMessageBox.Warning) error_mssg.setText( self. tr("The account has to be an existing one. \nAdd it first manually" )) error_mssg.exec_() # Reset strategy to previous one self.updatingdata_flag = True new_item.setData(0, previous_receiver_account) self.updatingdata_flag = False else: # The data is good # Change the transaction on the transactions table on the db transactions.update_transaction(database_entry_id, new_receiver=new_item_data) # Update the balance of the two accounts involved, # according to the transactions amount balances.update_balances_with_new_result( previous_receiver_account, -previous_amount) balances.update_balances_with_new_result( new_item_data, previous_amount) # Same with costbasis costbasis.update_cost_basis_with_new_transaction( previous_receiver_account, -previous_amount) costbasis.update_cost_basis_with_new_transaction( new_item_data, previous_amount) # If the receiver account is now Cash, the transaction turns into a withdrawal if new_item_data == "Cash": transactions.update_transaction(database_entry_id, new_d_or_w=-1) type_item = self.item( row, self.horizontalheaders.index(self.tr("Type"))) type_item.setData(0, self.tr("Withdrawal")) # If the receiver account was Cash, the transaction turns into a transfer elif previous_receiver_account == "Cash": transactions.update_transaction(database_entry_id, new_d_or_w=0) type_item = self.item( row, self.horizontalheaders.index(self.tr("Type"))) type_item.setData(0, self.tr("Transfer")) # -------------- Description -------------------- elif columnselected_name == self.tr("Description"): # A description can be any data. So no checks transactions.update_transaction(database_entry_id, new_description=new_item_data)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # Title self.title = QLabel(self.tr("Add Results")) self.title.setFont(TitleFont()) self.title.setAlignment(Qt.AlignCenter) # First line: Date self.label1 = QLabel(self.tr("Date")) self.label1.setFixedWidth(80) self.date_edit = QDateEdit(datetime.now()) self.date_edit.setDisplayFormat("dd/MM/yyyy") self.date_edit.setCalendarPopup(True) self.label1_checkbox = QPushButton(self.tr("Today")) self.label1_checkbox.setMaximumWidth(50) self.label1_checkbox.clicked.connect(self.setToday) self.line1 = QHBoxLayout() self.line1.addWidget(self.label1) self.line1.addWidget(self.date_edit) self.line1.addWidget(self.label1_checkbox) # Second Line: Account self.label2 = QLabel(self.tr("Account")) self.label2.setFixedWidth(80) self.account_select = QComboBox() currentaccounts = [a[0] for a in balances.get_all_accounts()] self.account_select.addItems(currentaccounts) self.line2 = QHBoxLayout() self.line2.addWidget(self.label2) self.line2.addWidget(self.account_select, Qt.AlignLeft) # Third Line: Strategy self.label3 = QLabel(self.tr("Strategy")) self.label3.setFixedWidth(80) self.strategy_select = QComboBox() self.strategy_select.setEditable(True) self.strategy_select.setDuplicatesEnabled(False) currentstrategies = [i[0] for i in strategies.get_all_strategies()] self.strategy_select.addItems(currentstrategies) self.line3 = QHBoxLayout() self.line3.addWidget(self.label3) self.line3.addWidget(self.strategy_select, Qt.AlignLeft) # Fourth Line: Amount self.label4 = QLabel(self.tr("Amount")) self.label4.setFixedWidth(80) self.amount_select = QSpinBox() self.amount_select.setSuffix(" €") self.amount_select.setMinimum(-2147483647) self.amount_select.setMaximum(2147483647) self.amount_select.setAccelerated(True) self.adjust_by_new_balance = QPushButton(self.tr("Adjust")) self.adjust_by_new_balance.clicked.connect(self.showAdjustDialog) self.line4 = QHBoxLayout() self.line4.addWidget(self.label4) self.line4.addWidget(self.amount_select, Qt.AlignLeft) self.line4.addWidget(self.adjust_by_new_balance) # Fifth Line: Description self.label5 = QLabel(self.tr("Description")) self.label5.setFixedWidth(80) self.description_select = QLineEdit() self.line5 = QHBoxLayout() self.line5.addWidget(self.label5) self.line5.addWidget(self.description_select, Qt.AlignLeft) # Buttons self.button_layout = QHBoxLayout() self.insert_button = QPushButton(self.tr("Insert")) self.insert_button.setMaximumWidth(50) self.button_layout.setAlignment(Qt.AlignHCenter | Qt.AlignTop) # Centering it self.button_layout.setContentsMargins(QMargins( 10, 10, 10, 10)) # A little bit of margin self.insert_button.clicked.connect(self.insertResult) self.button_layout.addWidget(self.insert_button, Qt.AlignVCenter) self.addWidget(self.title) self.addLayout(self.line1) self.addLayout(self.line2) self.addLayout(self.line3) self.addLayout(self.line4) self.addLayout(self.line5) self.addLayout(self.button_layout) self.addWidget(self.insert_button)
def __init__(self, date, account, *args, **kwargs): super().__init__(*args, **kwargs) print("Opening Adjust Balance Dialog from account {}".format(account)) # Data previous_balance = balances.get_account_balance(account) # UI self.setFixedSize(250, 250) self.layout = QVBoxLayout() self.layout.setAlignment(Qt.AlignCenter) # First Line: Date self.label1 = QLabel(self.tr("Date")) self.label1.setMinimumWidth(60) self.label1.setMaximumWidth(60) self.date = QLabel(date) # Separator line line = QFrame() line.setFrameShape(QFrame.VLine) line.setFrameShadow(QFrame.Sunken) self.line1 = QHBoxLayout() self.line1.addWidget(self.label1) self.line1.addWidget(line) self.line1.addWidget(self.date) self.layout.addLayout(self.line1) # Second Line: Account self.label2 = QLabel(self.tr("Account")) self.label2.setMinimumWidth(60) self.label2.setMaximumWidth(60) self.account_select = QComboBox() self.account_select.addItems( [i[0] for i in balances.get_all_accounts()]) self.account_select.setCurrentText(account) # Whenever an account is changed, we change the previousbalance self.account_select.currentTextChanged.connect(self.updateWithAccount) # Separator line line = QFrame() line.setFrameShape(QFrame.VLine) line.setFrameShadow(QFrame.Sunken) self.line2 = QHBoxLayout() self.line2.addWidget(self.label2) self.line2.addWidget(line) self.line2.addWidget(self.account_select, Qt.AlignLeft) self.layout.addLayout(self.line2) # Third Line: Previous Balance self.label3 = QLabel(self.tr("Previous")) self.label3.setMinimumWidth(60) self.label3.setMaximumWidth(60) self.previous_balance = QLineEdit() self.previous_balance.setText( str(previous_balance) + " " + confighandler.get_fiat_currency().upper()) self.previous_balance.setReadOnly(True) # Separator line line = QFrame() line.setFrameShape(QFrame.VLine) line.setFrameShadow(QFrame.Sunken) self.line3 = QHBoxLayout() self.line3.addWidget(self.label3) self.line3.addWidget(line) self.line3.addWidget(self.previous_balance) self.layout.addLayout(self.line3) # Fourth Line: New Balance self.label4 = QLabel(self.tr("New")) self.label4.setMinimumWidth(60) self.label4.setMaximumWidth(60) self.new_balance = QSpinBox() self.new_balance.setMinimum(0) self.new_balance.setMaximum(999999) self.new_balance.setSuffix(" " + confighandler.get_fiat_currency().upper()) self.new_balance.setValue(previous_balance) # Whenever a new balance is written, we recalculate the # resulting result self.new_balance.valueChanged.connect(self.updateResult) # Separator line line = QFrame() line.setFrameShape(QFrame.VLine) line.setFrameShadow(QFrame.Sunken) self.line4 = QHBoxLayout() self.line4.addWidget(self.label4) self.line4.addWidget(line) self.line4.addWidget(self.new_balance) self.layout.addLayout(self.line4) # Fifth Line: Result self.label5 = QLabel(self.tr("Result")) self.label5.setMinimumWidth(60) self.label5.setMaximumWidth(60) self.result = QLabel("") font = QFont() font.setBold(True) self.result.setFont(font) # Separator line line = QFrame() line.setFrameShape(QFrame.VLine) line.setFrameShadow(QFrame.Sunken) self.line5 = QHBoxLayout() self.line5.addWidget(self.label5) self.line5.addWidget(line) self.line5.addWidget(self.result) self.layout.addLayout(self.line5) # Sixth Line: Strategy self.label6 = QLabel(self.tr("Strategy")) self.label6.setFixedWidth(60) self.strategy_select = QComboBox() self.strategy_select.setEditable(True) self.strategy_select.setDuplicatesEnabled(False) currentstrategies = [i[0] for i in strategies.get_all_strategies()] self.strategy_select.addItems(currentstrategies) self.line6 = QHBoxLayout() self.line6.addWidget(self.label6) self.line6.addWidget(self.strategy_select) self.layout.addLayout(self.line6) # Seventh Line: Description self.label7 = QLabel(self.tr("Description")) self.label7.setFixedWidth(60) self.description_select = QLineEdit() self.line7 = QHBoxLayout() self.line7.addWidget(self.label7) self.line7.addWidget(self.description_select) self.layout.addLayout(self.line7) # Add result button self.add_result_bttn = QPushButton("Add Result") self.add_result_bttn.clicked.connect(self.addResult) self.layout.addWidget(self.add_result_bttn) self.setLayout(self.layout)