def __init__(self, parent): QPushButton.__init__(self, parent) self.p_account_id = 0 self.Menu = QMenu(self) self.Menu.addAction(self.tr("Choose account"), self.ChooseAccount) self.Menu.addAction(self.tr("Any account"), self.ClearAccount) self.setMenu(self.Menu) self.dialog = AccountListDialog() self.setText(self.dialog.SelectedName)
def onDataDialog(self, dlg_type): if dlg_type == "account_types": AccountTypeListDialog().exec() elif dlg_type == "accounts": AccountListDialog().exec() elif dlg_type == "assets": AssetListDialog().exec() elif dlg_type == "agents": PeerListDialog().exec() elif dlg_type == "categories": CategoryListDialog().exec() elif dlg_type == "tags": TagsListDialog().exec() elif dlg_type == "countries": CountryListDialog().exec() elif dlg_type == "quotes": QuotesListDialog().exec() else: assert False
class AccountButton(QPushButton): changed = Signal(int) def __init__(self, parent): QPushButton.__init__(self, parent) self.p_account_id = 0 self.Menu = QMenu(self) self.Menu.addAction(self.tr("Choose account"), self.ChooseAccount) self.Menu.addAction(self.tr("Any account"), self.ClearAccount) self.setMenu(self.Menu) self.dialog = AccountListDialog() self.setText(self.dialog.SelectedName) def getId(self): return self.p_account_id def setId(self, account_id): self.p_account_id = account_id if self.p_account_id: self.setText(JalDB().get_account_name(account_id)) else: self.setText(self.tr("ANY")) self.changed.emit(self.p_account_id) account_id = Property(int, getId, setId, notify=changed) def ChooseAccount(self): ref_point = self.mapToGlobal(self.geometry().bottomLeft()) self.dialog.setGeometry(ref_point.x(), ref_point.y(), self.dialog.width(), self.dialog.height()) self.dialog.setFilter() res = self.dialog.exec(enable_selection=True) if res: self.account_id = self.dialog.selected_id def ClearAccount(self): self.account_id = 0