def ui(self, layout): layout.addSpacing(30) title = Builder().text('Import a keystore file')\ .name('title')\ .build() desc = Builder().text('CPC Wallet uses a keystore format to store encrypted' ' private key information, please drop the file below.')\ .name('desc')\ .wrap(True)\ .height(100)\ .build() self.add(title) self.add(desc, 15) self.file = FileUploadQml(width=247, height=74, background="#f8f8f8", text="Drop keystore file here or", browse_text="browse…") self.add(self.file, 5) password = Input.Builder().placeholder('Password')\ .name('pwd')\ .mode(Input.Password)\ .model(self.password)\ .build() self.add(password, 20) self.import_ = Button.Builder().text('Import')\ .style('primary')\ .click(lambda _: self._import())\ .build() self.add(self.import_, 5) self.loading = Loading() self.loading.hide() self.add(self.loading)
def ui(self, widget): layout = QVBoxLayout(widget) layout.setSpacing(20) self.loading = Loading() layout.addLayout(self.gen_row('Payment password:'******'', self.loading, left_width=120)) self.loading.hide() hbox = QHBoxLayout() hbox.addStretch(1) self.ok = Button.Builder(width=100, height=28).style( 'primary').click(self.beforeSend).text('OK').build() hbox.addWidget(self.ok) hbox.addSpacing(5) layout.addLayout(hbox) return layout
def ui(self): miniWidth = self.width self.setMinimumWidth(miniWidth) layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setAlignment(Qt.AlignTop) status = QLabel(self.name) status.setObjectName('status') if self.mode == 'active': status.setCursor(Qt.PointingHandCursor) status.setAlignment(Qt.AlignCenter) status.setMinimumWidth(miniWidth) status.setMinimumHeight(self.h1) layout.addWidget(status) self.status_elem = status if self.timestamp: timestamp = QLabel(self.timestamp) timestamp.setObjectName('timestamp') timestamp.setAlignment(Qt.AlignCenter) timestamp.setMinimumWidth(miniWidth) timestamp.setMinimumHeight(self.h2) layout.addWidget(timestamp) self.loading = Loading(width=11, height=11, font_size=11) self.loading.setObjectName('loading') self.loading.setMaximumHeight(self.h2) self.loading.setMinimumHeight(self.h2) self.loading.setMaximumWidth(miniWidth) self.loading.hide() layout.addWidget(self.loading) layout.addStretch(1) self.setLayout(layout) self.setStyleSheet(""" #status {{ padding: 6px 2px; font-size: 12px; color: {}; border: 1px solid #d0d0d0; border-radius: 15px; text-align: center; }} #timestamp {{ font-size: 10px; }} """.format(self.getColor()))
def ui(self): scroll = QScrollArea() scroll.setStyleSheet("background: #fafafa;") layout = QVBoxLayout(self) layout.setAlignment(Qt.AlignHCenter | Qt.AlignTop) width = 720 path = abs_path('icons/banner 2.png') banner = Banner( path, width=width, height=155, title="PDASH", subtitle= "Parallel Distributed Architecture for Data Storage and Sharing") banner.setObjectName('banner') layout.addWidget(banner) # add market title layout.addSpacing(15) layout.addWidget(Builder().text("Market Products").style( "font-size:24px;color:#333333;").build()) layout.addSpacing(15) self.loading = Loading(text='Loading') layout.addWidget(self.loading) # Product List pdsWidget = ProductList(self.products, scroll=False) pdsWidget.setObjectName('products_list') pdsWidget.setMinimumWidth(width) pdsWidget.setMaximumWidth(width) layout.addWidget(pdsWidget) layout.addStretch(1) scroll.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) scroll.setWidgetResizable(True) wid = QWidget() wid.setLayout(layout) wid.setContentsMargins(0, 0, 0, 0) scroll.setWidget(wid) _layout = QVBoxLayout() _layout.setAlignment(Qt.AlignTop) _layout.addWidget(scroll) # add spacing with bottom _layout.addSpacing(30) wid.setStyleSheet(""" """) return _layout
def ui(self): layout = QVBoxLayout(self) layout.setAlignment(Qt.AlignHCenter | Qt.AlignTop) width = 750 path = abs_path('icons/banner 2.png') banner = Banner( path, width=720, height=155, title="PDASH", subtitle= "Parallel Distributed Architecture for Data Storage and Sharing") banner.setObjectName('banner') wrapper_banner = QWidget() wrapper_banner.setContentsMargins(0, 0, 0, 0) wrapper_layout = QHBoxLayout() wrapper_layout.addWidget(banner) wrapper_layout.setContentsMargins(0, 0, 0, 0) wrapper_banner.setLayout(wrapper_layout) wrapper_banner.setMinimumWidth(width) wrapper_banner.setMaximumWidth(width) layout.addWidget(wrapper_banner) layout.addSpacing(15) self.loading = Loading(text='Loading') layout.addWidget(self.loading) # Product List pdsWidget = ProductList(self.products) pdsWidget.setObjectName('products_list') pdsWidget.setMinimumWidth(width) pdsWidget.setMaximumWidth(width) layout.addWidget(pdsWidget) self.setStyleSheet(""" QWidget#banner { } QScrollArea#market_page { } QWidget#products_list { width: 720; } """) return layout
class PasswordDialog(Dialog): error = QtCore.pyqtSignal(str, name='error') def __init__(self, parent=None, oklistener=None, value=None, payer_account=None, payee_account=None): width = 420 height = 210 title = "Password" self.value = value self.payer_account = payer_account self.payee_account = payee_account self.oklistener = oklistener self.data() super().__init__(wallet.main_wnd, title=title, width=width, height=height) self.error.connect(self.errorSlot) @component.data def data(self): return {"password": ""} @QtCore.pyqtSlot(str) def errorSlot(self, err): QMessageBox.information(self, "Error", err) def send(self): passwd = self.password.value if web3.personal.unlockAccount(self.payer_account, passwd): web3.personal.lockAccount(self.payer_account) else: self.error.emit('wrong passphrase') return True value = account.to_wei(self.value) transaction = { 'from': self.payer_account, 'to': self.payee_account, 'value': value } web3.personal.sendTransaction(transaction, passwd) return False def beforeSend(self, _): def cb(err): self.setLoading(False) if not err: app.event.emit(UPDATE) self.close() self.setLoading(True) deferToThread(self.send).addCallback(cb) def setLoading(self, is_show): if is_show: self.loading.show() self.ok.setEnabled(False) else: self.loading.hide() self.ok.setEnabled(True) def gen_row(self, left_text, *widgets, **kw): row = QHBoxLayout() row.setContentsMargins(0, 0, 0, 0) row.setSpacing(0) row.addSpacing(16) left_widget = Builder().text(left_text).name('left').build() width = kw.get('left_width', 130) left_widget.setMinimumWidth(width) left_widget.setMaximumWidth(width) row.addWidget(left_widget) for widget in widgets: if isinstance(widget, QWidget): row.addWidget(widget) row.addSpacing(5) row.addStretch(1) return row def ui(self, widget): layout = QVBoxLayout(widget) layout.setSpacing(20) self.loading = Loading() layout.addLayout( self.gen_row('Payment password:'******'', self.loading, left_width=120)) self.loading.hide() hbox = QHBoxLayout() hbox.addStretch(1) self.ok = Button.Builder(width=100, height=28).style('primary').click( self.beforeSend).text('OK').build() hbox.addWidget(self.ok) hbox.addSpacing(5) layout.addLayout(hbox) return layout def style(self): return super().style() + """
class ProductDetail(Page): def __init__(self, parent=None, product_id=None, name="", image=abs_path('icons/test.png'), icon=abs_path('icons/[email protected]'), category="Category", created=None, sales=0, cpc=0, description="", remain=0, market_hash=None, owner_address=None, ptype=None): self.parent = parent self.product_id = product_id self.name_ = name self.image_ = image self.icon = icon self.category = category self.created = created self.sales = sales self.cpc_ = cpc self.description_ = description self.remain = remain self.ptype = ptype self.market_hash = market_hash self.owner_address = owner_address self.is_owner = False self.paying = False super().__init__(parent) self.setObjectName("product_detail") self.signals.payed.connect(self.payedSlot) def payedSlot(self): app.router.redirectTo('purchased_page') @page.create def create(self): @app.event.register(app.events.DETAIL_UPDATE) def detail_update(event): self.signals.refresh.emit() @app.event.register(app.events.NEW_ORDER) def listenNewOrder(event): # redirect to purchased data self.signals.payed.emit() @app.event.register(app.events.CANCEL_PURCHASE) def cancel_purchase(event): self.signals.refresh.emit() def buying(self, is_buying): if is_buying: self.buy.setEnabled(False) self.buy_loading.show() else: self.buy.setEnabled(True) self.buy_loading.hide() @page.data def data(self): return { "id": self.product_id, "image": self.image_, "icon": self.icon, "name": self.name_, "category": self.category, "created": self.created, "sales": self.sales, "cpc": self.cpc_, "remain": self.remain, "description": self.description_, "gas": 1, "account": 15, "password": "", "storagePath": "", "status_text": "Delivered on May 2, 08:09:08" } def setProduct(self, product): self.product = product def add_orders_ui(self, widget): height = widget.height() layout = widget.layout() order = None status = 0 start = 1 is_seller = self.owner_address == wallet.market_client.public_key # Sales if app.products_order.get(self.market_hash): self.sales_header = DetailHeader("{} Sales".format( len(app.products_order.get(self.market_hash)))) layout.insertWidget(start, self.sales_header) start += 1 # enum State { # Created, # SellerConfirmed, # ProxyFetched, # ProxyDelivered, # BuyerConfirmed, # Finished, # SellerRated, # BuyerRated, # Disputed, # Withdrawn # } myaddress = get_address_from_public_key_object( wallet.market_client.public_key) self.salesElem = [] need_show = False for order in app.products_order[self.market_hash]: # not buyer and not seller buyer_addr = eth_addr_to_string(order['buyer_addr']) is_buyer = buyer_addr == myaddress if not is_buyer and not is_seller: continue need_show = True self.buy.setEnabled(False) status = order['status'] if status == 0: current = 1 elif status == 1: current = 1 elif status == 2: current = 2 elif status == 3: current = 3 else: current = 4 sale1 = Sale( image=abs_path('icons/avatar.jpeg'), name=order['public_key'], current=current, timestamps=[ "May 2, 08:09:08", "May 2, 08:09:08", "May 2, 08:09:08", "May 2, 08:09:08" ], order_id=order["order_id"], mhash=self.market_hash, is_buyer=is_buyer, is_seller=is_seller, order_type='stream' if self.ptype == 'stream' else 'file') layout.insertWidget(start, sale1) self.salesElem.append(sale1) start += 1 height += 200 if not need_show: self.sales_header.hide() # Order Detail if status < 1: self.status_text.value = "Created on May 2, 08:09:08" elif status == 1: self.status_text.value = "Delivered on May 2, 08:09:08" elif status <= 3: self.status_text.value = "Received on May 2, 08:09:08" elif status > 3: self.status_text.value = "Confirmed on May 2, 08:09:08" if order and self.owner_address != wallet.market_client.public_key: if status > 2: order_header = DetailHeader('Order Detail') layout.insertWidget(start, order_header) start += 1 height += 100 has_comfirmed = status > 3 if self.ptype == 'file': self.data_type = 'batch' self.order_detail = OrderDetail( order_time=Model("2018/6/15 08:40:39"), status=self.status_text, order_id=order["order_id"], name=self.name.value, data_type=self.data_type, has_comfirmed=has_comfirmed) layout.insertWidget(start, self.order_detail) start += 1 height += 100 if self.ptype == 'stream': self.data_type = 'stream' order_detail = OrderDetail( order_time=Model("2018/6/15 08:40:39"), status=self.status_text, order_id=order["order_id"], market_hash=self.market_hash, name=self.name.value, data_type=self.data_type, has_comfirmed=has_comfirmed) layout.insertWidget(start, order_detail) start += 1 height += 100 widget.setFixedHeight(height) def render_widget(self): height = 200 layout = QVBoxLayout(self) layout.setObjectName('body') layout.setAlignment(Qt.AlignTop) header = QHBoxLayout() # Image imageWid = Picture(self.image.value, 240, 160) Binder.click(imageWid, lambda _: app.event.emit(app.events.DETAIL_UPDATE)) header.addWidget(imageWid) right = QVBoxLayout() right.setAlignment(Qt.AlignTop) right.setSpacing(15) # Title title = Label(self.name) title.setObjectName('name') right.addWidget(title) # category catbox = QHBoxLayout() icon = self.icon.value if icon: iconL = QLabel() iconL.setMaximumWidth(20) iconL.setMaximumHeight(20) iconL.setObjectName('icon') iconL.setPixmap(QPixmap(icon)) catbox.addWidget(iconL) category = Label(self.category) category.setObjectName('category') category.setAlignment(Qt.AlignCenter) category.setMaximumWidth(80) catbox.addWidget(category) catbox.addStretch(1) right.addLayout(catbox) # Timestamp and Remain Days tbox = QHBoxLayout() timestamp = QLabel(self.created.value) timestamp.setObjectName('timestamp') tbox.addWidget(timestamp) sales = QLabel(str(self.sales.value) + ' sales') sales.setObjectName('sales') tbox.addWidget(sales) tbox.addStretch(1) right.addLayout(tbox) # CPC and Sales hbox = QHBoxLayout() hbox.setObjectName('hbox1') cpc = QLabel(str(self.cpc.value)) cpc.setObjectName('cpc') cpc_unit = QLabel('CPC') cpc_unit.setObjectName('cpc_unit') hbox.addWidget(cpc) hbox.addWidget(cpc_unit) # Buy button def openPurchaseDialog(_): self.buying(True) if not self.paying: market_hash = self.market_hash owner_address = self.owner_address purchaseDlg = PurchaseDialog(self, price=self.cpc, gas=self.gas, account=self.account, storagePath=self.storagePath, password=self.password, market_hash=market_hash, name=self.name.value, owner_address=owner_address) purchaseDlg.show() self.buy = Button.Builder(width=100, height=30).text('Buy')\ .style('primary')\ .click(openPurchaseDialog)\ .build() hbox.addWidget(self.buy) if self.owner_address == wallet.market_client.public_key: self.buy.setEnabled(False) # Buy Loading self.buy_loading = Loading() hbox.addWidget(self.buy_loading) self.buy_loading.hide() hbox.addStretch(1) right.addLayout(hbox) header.addLayout(right) layout.addLayout(header) # Description desc = DetailHeader('Description') layout.addWidget(desc) desc = Label(self.description) desc.setWordWrap(True) layout.addWidget(desc) height += 300 layout.addStretch(1) widget_ = QWidget() widget_.setObjectName('parent_widget') widget_.setLayout(layout) widget_.setFixedWidth(720) widget_.setFixedHeight(height) widget_.setStyleSheet(self.style()) self.add_orders_ui(widget_) return widget_ def ui(self): self.widget_ = self.render_widget() # Scroll Area Properties self.scroll = QScrollArea() self.scroll.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.scroll.setWidgetResizable(True) # scroll.setFixedHeight(800) self.scroll.setWidget(self.widget_) self.setWidget(self.scroll) self.setWidgetResizable(True) def style(self): return """
def render_widget(self): height = 200 layout = QVBoxLayout(self) layout.setObjectName('body') layout.setAlignment(Qt.AlignTop) header = QHBoxLayout() # Image imageWid = Picture(self.image.value, 240, 160) Binder.click(imageWid, lambda _: app.event.emit(app.events.DETAIL_UPDATE)) header.addWidget(imageWid) right = QVBoxLayout() right.setAlignment(Qt.AlignTop) right.setSpacing(15) # Title title = Label(self.name) title.setObjectName('name') right.addWidget(title) # category catbox = QHBoxLayout() icon = self.icon.value if icon: iconL = QLabel() iconL.setMaximumWidth(20) iconL.setMaximumHeight(20) iconL.setObjectName('icon') iconL.setPixmap(QPixmap(icon)) catbox.addWidget(iconL) category = Label(self.category) category.setObjectName('category') category.setAlignment(Qt.AlignCenter) category.setMaximumWidth(80) catbox.addWidget(category) catbox.addStretch(1) right.addLayout(catbox) # Timestamp and Remain Days tbox = QHBoxLayout() timestamp = QLabel(self.created.value) timestamp.setObjectName('timestamp') tbox.addWidget(timestamp) sales = QLabel(str(self.sales.value) + ' sales') sales.setObjectName('sales') tbox.addWidget(sales) tbox.addStretch(1) right.addLayout(tbox) # CPC and Sales hbox = QHBoxLayout() hbox.setObjectName('hbox1') cpc = QLabel(str(self.cpc.value)) cpc.setObjectName('cpc') cpc_unit = QLabel('CPC') cpc_unit.setObjectName('cpc_unit') hbox.addWidget(cpc) hbox.addWidget(cpc_unit) # Buy button def openPurchaseDialog(_): self.buying(True) if not self.paying: market_hash = self.market_hash owner_address = self.owner_address purchaseDlg = PurchaseDialog(self, price=self.cpc, gas=self.gas, account=self.account, storagePath=self.storagePath, password=self.password, market_hash=market_hash, name=self.name.value, owner_address=owner_address) purchaseDlg.show() self.buy = Button.Builder(width=100, height=30).text('Buy')\ .style('primary')\ .click(openPurchaseDialog)\ .build() hbox.addWidget(self.buy) if self.owner_address == wallet.market_client.public_key: self.buy.setEnabled(False) # Buy Loading self.buy_loading = Loading() hbox.addWidget(self.buy_loading) self.buy_loading.hide() hbox.addStretch(1) right.addLayout(hbox) header.addLayout(right) layout.addLayout(header) # Description desc = DetailHeader('Description') layout.addWidget(desc) desc = Label(self.description) desc.setWordWrap(True) layout.addWidget(desc) height += 300 layout.addStretch(1) widget_ = QWidget() widget_.setObjectName('parent_widget') widget_.setLayout(layout) widget_.setFixedWidth(720) widget_.setFixedHeight(height) widget_.setStyleSheet(self.style()) self.add_orders_ui(widget_) return widget_
class Status(QWidget): def __init__(self, name, mode=None, timestamp=None, line=True, h1=100, h2=20, width=100, status=False, order_id=None): """ @param mode: finish, active, todo """ self.signals = Signals() self.name = name self.order_id = order_id self.mode = mode self.timestamp = timestamp self.line = line self.h1 = h1 self.h2 = h2 self.status = status self.width = width self.status_elem = None super().__init__() self.handler_map = { 'Deliver': ('delivering', 'delivery'), 'Receive': ('receiving', 'receive'), 'Confirm': ('confirming', 'confirm') } self.init() self.ui() # is loading if self.order_id in app.is_order_handling.get(self.name, set()): self.signals.loading.emit() def init(self): @app.event.register(app.events.UPDATE_ORDER_STATUS) def callback(event): order_id = event.data['order_id'] if order_id != self.order_id: return status = event.data['status'] for k, v in self.handler_map.items(): _set = app.is_order_handling.get(k, set()) if self.name == k: if status == v[0]: self.signals.loading.emit() _set.add(order_id) elif status == v[1]: self.signals.loading_over.emit() _set.remove(order_id) app.is_order_handling[k] = _set self.signals.loading.connect(self.setLoading) self.signals.loading_over.connect(self.hideLoading) @pyqtSlot() def setLoading(self): self.setEnabled(False) self.loading.show() @pyqtSlot() def hideLoading(self): self.setEnabled(True) self.loading.hide() def getColor(self): color = {'finish': '#333333', 'active': '#0073df', 'todo': '#9b9b9b'} if self.mode is None: return color['todo'] return color[self.mode] def ui(self): miniWidth = self.width self.setMinimumWidth(miniWidth) layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setAlignment(Qt.AlignTop) status = QLabel(self.name) status.setObjectName('status') if self.mode == 'active': status.setCursor(Qt.PointingHandCursor) status.setAlignment(Qt.AlignCenter) status.setMinimumWidth(miniWidth) status.setMinimumHeight(self.h1) layout.addWidget(status) self.status_elem = status if self.timestamp: timestamp = QLabel(self.timestamp) timestamp.setObjectName('timestamp') timestamp.setAlignment(Qt.AlignCenter) timestamp.setMinimumWidth(miniWidth) timestamp.setMinimumHeight(self.h2) layout.addWidget(timestamp) self.loading = Loading(width=11, height=11, font_size=11) self.loading.setObjectName('loading') self.loading.setMaximumHeight(self.h2) self.loading.setMinimumHeight(self.h2) self.loading.setMaximumWidth(miniWidth) self.loading.hide() layout.addWidget(self.loading) layout.addStretch(1) self.setLayout(layout) self.setStyleSheet(""" #status {{ padding: 6px 2px; font-size: 12px; color: {}; border: 1px solid #d0d0d0; border-radius: 15px; text-align: center; }} #timestamp {{ font-size: 10px; }} """.format(self.getColor()))
class ImportWindow(MyWindow): error_signal = pyqtSignal() imported = pyqtSignal(str) def __init__(self, reactor=None, parent=None): self.password = Model("") self.file = None super().__init__(reactor, parent) self.username = UserNameWindow(reactor, self) # self.error_signal.connect(lambda: app.msgbox.error("Password mismatch")) self.imported.connect(self.onImported) @app.event.register(app.events.PASSWORD_ERROR) def password_error(_): self.loading_over() self.error_signal.emit() def onImported(self, status): self.username.username_ = status self.username.is_registered = True self.loading_over() self.to(self.username) def _import(self): self.loading_start() if not validate(self, lambda x: x, "Please input the password", self.password.value): self.loading_over() return if not validate(self, lambda x: x, "Please select a file", self.file.file): self.loading_over() return try: def exec_(): account = import_account(self.file.file, self.password.value) self.username.account = account def cb(status): self.imported.emit(status) if account: public_key = ECCipher.serialize_public_key( account.public_key) wallet.market_client.isRegistered(public_key).addCallbacks( cb) deferToThread(exec_) except Exception as e: logger.error(e) QMessageBox.information(self, "error", "Failed!") self.loading_over() def loading_start(self): self.import_.setEnabled(False) self.loading.show() def loading_over(self): self.import_.setEnabled(True) self.loading.hide() def ui(self, layout): layout.addSpacing(30) title = Builder().text('Import a keystore file')\ .name('title')\ .build() desc = Builder().text('CPC Wallet uses a keystore format to store encrypted' ' private key information, please drop the file below.')\ .name('desc')\ .wrap(True)\ .height(100)\ .build() self.add(title) self.add(desc, 15) self.file = FileUploadQml(width=247, height=74, background="#f8f8f8", text="Drop keystore file here or", browse_text="browse…") self.add(self.file, 5) password = Input.Builder().placeholder('Password')\ .name('pwd')\ .mode(Input.Password)\ .model(self.password)\ .build() self.add(password, 20) self.import_ = Button.Builder().text('Import')\ .style('primary')\ .click(lambda _: self._import())\ .build() self.add(self.import_, 5) self.loading = Loading() self.loading.hide() self.add(self.loading) def style(self): return """ """