def __init__(self, user: User, parent): super().__init__( parent, Qt.WindowCloseButtonHint | Qt.WindowMinimizeButtonHint) self.setupUi(self) self.user: User = user self.refreshButton.clicked.connect(self.refresh_tables) self._client = Client()
def __init__(self, parent, user: User, currency: UserCurrency): super().__init__(parent, Qt.WindowCloseButtonHint | Qt.WindowMinimizeButtonHint) self.setupUi(self) self.parent = parent self.buyButton.clicked.connect(self.buy) self.sellButton.clicked.connect(self.sell) self.refreshButton.clicked.connect(self.refresh) self._user: User = user self._currency: UserCurrency = currency self._client = Client() self.setWindowTitle(currency.name)
class CurrencyWindow(Ui_CurrencyWindow, QMainWindow): def __init__(self, parent, user: User, currency: UserCurrency): super().__init__( parent, Qt.WindowCloseButtonHint | Qt.WindowMinimizeButtonHint) self.setupUi(self) self.parent = parent self.buyButton.clicked.connect(self.buy) self.sellButton.clicked.connect(self.sell) self.refreshButton.clicked.connect(self.refresh) self._user: User = user self._currency: UserCurrency = currency self._client = Client() self.setWindowTitle(currency.name) def set_text_info(self, selling_price, buying_price, account, currency_amount, currency_name): self.buyingPrice.setText('Cтоимость покупки: ' + str(buying_price) + ' у.е.') self.sellingPrice.setText('Стоимость продажи: ' + str(selling_price) + ' у.е.') self.account.setText('На счёте: ' + str(account) + ' у.е. | ' + str(currency_amount) + ' ' + currency_name) def draw_graphs(self): self.graphicsView.plotItem.clear() self._user = self._client.get_user(self._user.id) self._currency = self._client.get_user_currency( self._user.id, self._currency.id) pg.setConfigOptions(antialias=True) history_items: List[ CurrencyHistory] = self._client.get_currency_history( self._currency.id) selling_prices = list( map(lambda item: float(item.selling_price), history_items)) purchasing_prices = list( map(lambda item: float(item.purchasing_price), history_items)) time = {} for i in range(len(history_items)): if i == 0 or i == len(history_items) - 1: time[i] = datetime.strftime(history_items[i].time, '%Y-%m-%d %H:%M:%S') else: time[i] = '' self.set_text_info( selling_prices[-1], purchasing_prices[-1], str(self._user.money), str(self._currency.amount), self._currency.name, ) self.graphicsView.setBackground('w') self.graphicsView.addLegend() time_axis = pg.AxisItem(orientation='bottom') time_axis.setTicks([time.items()]) self.graphicsView.setAxisItems(axisItems={'bottom': time_axis}) self.graphicsView.setLabel('left', 'Цена') self.graphicsView.setLabel('bottom', 'Время') self.graphicsView.showGrid(x=True, y=True) self.plot( list(time.keys()), purchasing_prices, 'Цена покупки', (0, 220, 0), 1.5, 'o', 5, ) self.plot( list(time.keys()), selling_prices, 'Цена продажи', (255, 0, 0), 1.5, 'o', 5, ) def plot(self, x, y, plot_name, color, width, symbol, symbol_size): pen = pg.mkPen(color=color, width=width) self.graphicsView.plot( x, y, name=plot_name, pen=pen, symbol=symbol, symbolSize=symbol_size, symbolBrush=color, ) def buy(self): self.buy_window = BuyWindow(self, self._client, self._user, self._currency) self.buy_window.init() def sell(self): self.sell_window = SellWindow(self, self._client, self._user, self._currency) self.sell_window.init() def refresh(self): try: self.init() except ConnectionError: QMessageBox().warning(self, 'Ошибка', str(Message.CONNECTION_ERROR.value)) def init(self): self.draw_graphs() self.show()
def __init__(self): super().__init__(None, Qt.WindowCloseButtonHint) self.setupUi(self) self._authorize: Client = Client() self.confirmButton.clicked.connect(self.auth) self.cancelButton.clicked.connect(lambda: self.close())
class MainWindow(Ui_MainWindow, QMainWindow): def __init__(self, user: User, parent): super().__init__( parent, Qt.WindowCloseButtonHint | Qt.WindowMinimizeButtonHint) self.setupUi(self) self.user: User = user self.refreshButton.clicked.connect(self.refresh_tables) self._client = Client() '''Логика кнопки обновления''' def refresh_tables(self): self.init() def fill_all_currencies(self): self.allCurrenciesTable.clear() currencies = self._client.get_all_currencies() labels = ['Название', 'Цена продажи', 'Цена покупки', ''] create_headers(self.allCurrenciesTable, labels) for i in currencies: detail_button = QPushButton('Подробнее') detail_button.clicked.connect(lambda a, i=i: self.show_details( self.user, UserCurrency(**i.dict()))) row = self.allCurrenciesTable.rowCount() self.allCurrenciesTable.setRowCount(row + 1) self.allCurrenciesTable.setItem(row, 0, QTableWidgetItem(i.name)) self.allCurrenciesTable.setItem( row, 1, QTableWidgetItem(str(i.selling_price))) self.allCurrenciesTable.setItem( row, 2, QTableWidgetItem(str(i.purchasing_price))) self.allCurrenciesTable.setCellWidget(row, 3, detail_button) def fill_my_currencies(self): self.myCurrenciesTable.clear() labels = [ 'Название', 'Колличество', 'Цена продажи', 'Цена покупки', '' ] create_headers(self.myCurrenciesTable, labels) currencies = self._client.get_user_currencies(self.user.id) for i in currencies: detail_button = QPushButton('Подробнее') detail_button.clicked.connect( lambda f, i=i: self.show_details(self.user, i)) row = self.myCurrenciesTable.rowCount() self.myCurrenciesTable.setRowCount(row + 1) self.myCurrenciesTable.setItem(row, 0, QTableWidgetItem(i.name)) self.myCurrenciesTable.setItem(row, 1, QTableWidgetItem(str(i.amount))) self.myCurrenciesTable.setItem( row, 2, QTableWidgetItem(str(i.selling_price))) self.myCurrenciesTable.setItem( row, 3, QTableWidgetItem(str(i.purchasing_price))) self.myCurrenciesTable.setCellWidget(row, 4, detail_button) def fill_operations(self): self.operationsTable.clear() labels = ['Операция', 'Название', 'Количество'] create_headers(self.operationsTable, labels) operations = self._client.get_operations(self.user.id) operations.reverse() for i in operations: row = self.operationsTable.rowCount() self.operationsTable.setRowCount(row + 1) self.operationsTable.setItem( row, 0, QTableWidgetItem('Покупка' if i.operation_type == OperationType.BUY else 'Продажа'), ) self.operationsTable.setItem(row, 1, QTableWidgetItem(i.currency_name)) self.operationsTable.setItem(row, 2, QTableWidgetItem((str(i.amount)))) '''Логика кнопки "Подробнее"''' def show_details(self, user: User, currency: UserCurrency): CurrencyWindow(self, user, currency).init() def init(self): self.operationsTable.setRowCount(0) self.allCurrenciesTable.setRowCount(0) self.myCurrenciesTable.setRowCount(0) self.user = self._client.sign_in(self.user.login) try: self.fill_all_currencies() self.fill_my_currencies() self.fill_operations() except ConnectionError: QMessageBox().warning(self, 'Ошибка', Message.CONNECTION_ERROR.value) return self.show()