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): main_layout = QVBoxLayout() main_layout.setAlignment(Qt.AlignHCenter | Qt.AlignTop) main_layout.setContentsMargins(0, 0, 0, 0) close_btn = Builder( widget=QPushButton).text('x').name('close_btn').click( self.close).build() header = QHBoxLayout() header.addStretch(1) header.addWidget(close_btn) main_layout.addLayout(header) wid = QWidget(self) wid.setObjectName('main') wid.setLayout(main_layout) self.setCentralWidget(wid) return main_layout
def gen_row(self, left_text, *widgets, **kw): row = QHBoxLayout() left_widget = Builder().text(left_text).name('left').build() width = kw.get('left_width', 140) left_widget.setMinimumWidth(width) left_widget.setMaximumWidth(width) row.addWidget(left_widget) for widget in widgets: if isinstance(widget, QWidget): row.addWidget(widget) row.addStretch(1) return row
def gen_row(self, left_text, *widgets, **kw): row = QHBoxLayout() row.setSpacing(0) left_widget = Builder().text(left_text).name('left').build() width = kw.get('left_width', 110) left_widget.setMinimumWidth(width) left_widget.setMaximumWidth(width) left_widget.setMaximumHeight(30) left = QVBoxLayout() left.setAlignment(Qt.AlignTop) left.addWidget(left_widget) row.addLayout(left) row.addSpacing(10) for widget in widgets: if isinstance(widget, QWidget): row.addWidget(widget) elif isinstance(widget, int): row.addSpacing(widget) row.addStretch(1) return row
def __init__(self, parent, title="Title", width=500, height=180): self.parent = parent super().__init__(parent) self.setWindowFlags(Qt.FramelessWindowHint) # Dialog Shadow if not self.NO_SHADOW: self.setAttribute(Qt.WA_TranslucentBackground) effect = QGraphicsDropShadowEffect() effect.setBlurRadius(15) effect.setXOffset(0) effect.setYOffset(0) self.setGraphicsEffect(effect) self.center(width, height) self.setContentsMargins(0, 0, 0, 0) self.setAcceptDrops(True) layout = QVBoxLayout() layout.setSpacing(0) layout.setAlignment(Qt.AlignTop) layout.setContentsMargins(0, 0, 0, 0) # Title title = QLabel(title) title.setObjectName('title') def trigger_close(_): self.close() close_btn = Builder().text('x').name('close_btn').click(trigger_close).build() header = QHBoxLayout() header.addWidget(title) header.addStretch(1) header.addWidget(close_btn) dlgHeader = QFrame() dlgHeader.setObjectName('header') dlgHeader.setLayout(header) layout.addWidget(dlgHeader) widget = QWidget(self) self.main = self.ui(widget) widget.setObjectName('main') widget.setLayout(self.main) layout.addWidget(widget) self.setLayout(layout) self.setStyleSheet(self.style())
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 gen_row(self, left_text, *widgets, **kw): row = QHBoxLayout() row.setContentsMargins(0, 0, 0, 0) row.setSpacing(0) row.addSpacing(32) left_widget = Builder().text(left_text).name('left').style( "font-size: 14px;").build() width = kw.get('left_width', 66) left_widget.setMinimumWidth(width) left_widget.setMaximumWidth(width) left_widget.setMinimumHeight(34) left = QVBoxLayout() left.setContentsMargins(0, 0, 0, 0) left.addWidget(left_widget) left.addStretch(1) row.addLayout(left) row.addSpacing(8) for widget in widgets: if isinstance(widget, QWidget): row.addWidget(widget) row.addSpacing(5) row.addStretch(1) return row
def ui(self, layout): layout.setAlignment(Qt.AlignTop) self.add(Builder().text('Balance').name('title').build()) self.addH(Builder(Label).model(self.balance).name('amount').build(), 0, align=Qt.AlignBottom | Qt.AlignLeft) self.addH(Builder().text('CPC').name('unit').build()) self.add() width = 90 height = 30 self.addH( Button.Builder(width=width, height=height).text('Receive').click( self.receive).name('receive').style('primary').build()) self.addH( Button.Builder(width=width, height=height).text('Send').click( self.send).name('send').build()) self.add(space=20) self.add(Line(wid=1, color='#e1e1e1')) self.add(space=18) self.add(Builder().text('Account').name('title').build()) def buildTable(): header = { 'headers': ['Category', 'Payer', 'Amount(CPC)', 'Time'], 'width': [202, 190, 170, 108] } data = [] self.table_data.value = data def itemHandler(data): items = [] items.append(data.category) items.append(data.payer) try: amount = str(account.to_ether(abs(data.amount))) if data.amount > 0: amount = '+' + amount elif data.amount < 0: amount = '-' + amount except ValueError as e: logger.error(e) wid = QLabel(amount) wid.setStyleSheet("QLabel{{color: {};}}".format( '#00a20e' if data.amount >= 0 else '#d0021b')) items.append(wid) items.append(data.time) return items table = Table(self, header, self.table_data, itemHandler, sort=None) table.setObjectName('my_table') table.setFixedWidth(802) return table table = buildTable() self.table = table self.buildTable = buildTable self.add(table) # No Data nodata = QLabel('No Data!') nodata.setObjectName('no_data') self.nodata = nodata self.add(nodata) self.nodata.hide() if len(self.table_data.value) == 0: self.nodata.show() layout.addStretch(1) return layout
def __init__(self, parent, title="Title", width=500, height=180): self.parent = parent self.dragPosition = None self.width = width self.height = height super().__init__(parent) self.setWindowFlags(Qt.FramelessWindowHint) self.setAttribute(Qt.WA_TranslucentBackground) self.gap = 10 self.center(self.width + self.gap, self.height + self.gap) self.setAcceptDrops(True) layout = QVBoxLayout() layout.setSpacing(0) layout.setAlignment(Qt.AlignTop) layout.setContentsMargins(0, 0, 0, 0) # Title title = QLabel(title) title.setObjectName('title') def trigger_close(_): self.close() close_btn = Builder().text('x').name('close_btn').click( trigger_close).build() header = QHBoxLayout() header.addWidget(title) header.addStretch(1) header.addWidget(close_btn) self.close_btn = close_btn dlgHeader = QFrame() dlgHeader.setObjectName('header') dlgHeader.setMaximumWidth(width) dlgHeader.setLayout(header) layout.addWidget(dlgHeader) widget = QWidget(self) self.main = self.ui(widget) widget.setObjectName('main') widget.setLayout(self.main) widget.setMaximumWidth(width) layout.addWidget(widget) _main = QWidget() _main.setContentsMargins(0, 0, 0, 10) _main.setLayout(layout) _main.setStyleSheet(self.style()) _main.setWindowOpacity(0.5) _main_layout = QStackedLayout() _main_layout.setContentsMargins(20, 20, 20, 20) _main_layout.setAlignment(Qt.AlignCenter) _main_layout.setStackingMode(QStackedLayout.StackAll) _backgound = QFrame() _backgound.setMinimumWidth(width) _backgound.setMinimumHeight(height) _backgound.setMaximumWidth(width) _backgound.setMaximumHeight(height) _backgound.setStyleSheet("background: #fafafa; border-radius:5px;") if not app.is_windows(): _main_layout.addWidget(_backgound) _main_layout.addWidget(_main) self.setLayout(_main_layout) self.effect = QGraphicsDropShadowEffect(_backgound) self.effect.setOffset(0, 0) self.effect.setBlurRadius(30) # self.effect.setEnabled(False) _backgound.setGraphicsEffect(self.effect)
def ui(self, vLayout): def buildTable(): header = { 'headers': ['Name', 'Location', 'Size', 'Status'], 'width': [282, 170, 170, 54] } data = fs.get_file_by_data_type() self.table_data.value = data def buildProductClickListener(product_id): def listener(event): app.router.redirectTo('publish_product', product_id=product_id) return listener def itemHandler(data): items = [] items.append(data.name) items.append(data.remote_type) items.append(str(sizeof_fmt(data.size))) status = data.is_published wid = QLabel('Published') if not status: wid.setText('Publish as product') wid.setStyleSheet("QLabel{color: #006bcf;}") Binder.click(wid, buildProductClickListener(data.id)) items.append(wid) return items table = Table(self, header, self.table_data, itemHandler, sort=None) table.setObjectName('my_table') table.setFixedWidth(800) return table table = buildTable() self.table = table self.buildTable = buildTable def buildStreamTable(): def right_menu(row): self.menu = QMenu(self.stream_table) show_id = QAction('Stream ID', self) def open(): uri = self.stream_data.value[row].remote_uri name = self.stream_data.value[row].name if uri: try: uri = json.loads(uri) ws_url = uri.get('ws_url') dlg = StreamUploadedDialog(data_name=name, stream_id=ws_url) dlg.show() except Exception as e: logger.debug(uri) logger.error(e) show_id.triggered.connect(lambda: open()) self.menu.addAction(show_id) self.menu.popup(QCursor.pos()) self.menu.setStyleSheet(""" QMenu::item::selected { color: #666; } """) header = { 'headers': ['Name', 'Location', 'Status'], 'width': [327, 295, 54] } data = fs.get_file_by_data_type('stream') self.stream_data.value = data def buildProductClickListener(product_id): def listener(event): app.router.redirectTo('publish_product', product_id=product_id, type_='stream') return listener def itemHandler(data): items = [] items.append(data.name) items.append(data.remote_type) status = data.is_published wid = QLabel('Published') if not status: wid.setText('Publish as product') wid.setStyleSheet("QLabel{color: #006bcf;}") Binder.click(wid, buildProductClickListener(data.id)) items.append(wid) return items table = Table(self, header, self.stream_data, itemHandler, sort=None) table.setObjectName('my_table') table.setFixedWidth(800) def record_check(item): right_menu(item.row()) table.itemClicked.connect(record_check) return table stream_table = buildStreamTable() self.stream_table = stream_table self.buildStreamTable = buildStreamTable self.addH( Button.Builder(width=150, height=30).style('primary').name( 'btn').text('Upload Batch Data').click( self.onClickUpload).build(), 6) self.addH( Button.Builder( width=180, height=30).name('btn').text('Upload Streaming Data').click( self.onClickStreamUpload).build()) self.add(space=10) # Line self.add(Line(wid=1, color="#dadada"), 20) # My Product self.add(Builder().text('My Product').name('label_hint').build()) # Product List pdsWidget = ProductList(self.products, scroll=False) width = 750 height = 200 pdsWidget.setMinimumWidth(width) pdsWidget.setMaximumWidth(width) self.addH(pdsWidget, align=Qt.AlignTop | Qt.AlignHCenter) # Batch Data self.add(Builder().text('Batch Data').name('label_hint').build()) self.add(table) if len(self.table_data.value) == 0: # No Data self.add(Builder().text('0 Batch Data!').name('no_data').build()) # Stream Data self.add(Builder().text('Streaming Data').name('label_hint').build()) self.add(stream_table) if len(self.stream_data.value) == 0: # No Data self.add( Builder().text('0 Streaming Data!').name('no_data').build()) vLayout.addSpacing(100) vLayout.addStretch(1) return vLayout
def ui(self): layout = QVBoxLayout() layout.setAlignment(Qt.AlignTop) first = QHBoxLayout() image = QLabel() image.setObjectName('image') pix = QPixmap(self.image) pix = pix.scaled(96, 96) image.setPixmap(pix) first.addWidget(image) name = Builder().model(self.name).build() first.addWidget(name) first.addStretch(1) layout.addLayout(first) status = ['Order', 'Deliver', 'Receive', 'Confirm', 'Comment'] callbacks = { 'Deliver': self.deliver, 'Receive': self.receive, 'Confirm': self.confirm, 'Comment': self.comment } second = QHBoxLayout() second.setAlignment(Qt.AlignLeft) second.addSpacing(50) second.setSpacing(5) i = 0 h1 = 35 h2 = 15 width = 95 for item in status: mode = 'active' if i == self.current else ( 'todo' if i > self.current else 'finish') if item == 'Deliver' and self.current == 1 and self.is_buyer: mode = 'todo' if item == 'Receive' and self.current == 2 and self.is_seller: mode = 'todo' if item == 'Confirm' and self.current == 3 and self.is_seller: mode = 'todo' if item == 'Comment' and self.current == 4 and self.is_seller: mode = 'todo' timestamp = self.timestamps[i] if i < self.current else None tmp = Status(name=item, mode=mode, timestamp=timestamp, h1=h1, h2=h2, width=width, order_id=self.order_id) cb = callbacks.get(item) if cb and mode == 'active': Binder.click(tmp, cb) second.addWidget(tmp) if item != status[-1]: line = StatusLine(h1, h2) second.addWidget(line) i += 1 second.addStretch(1) layout.addLayout(second) layout.addStretch(1) self.setLayout(layout) self.setStyleSheet(""" """)
class ReceiveDialog(Dialog): def __init__(self, parent=None, oklistener=None, address=None): width = 540 height = 230 title = "Receive Token" self.oklistener = oklistener self.address = address self.data() super().__init__(wallet.main_wnd, title=title, width=width, height=height) @component.data def data(self): return { "address": self.address } def close(self): app.event.emit(UPDATE) super().close() def show_copyed(self): self.copyed.show() def hide(): time.sleep(2) self.copyed.hide() deferToThread(hide) def copy_address(self): clipboard = QApplication.clipboard() clipboard.setText(self.address.value) self.show_copyed() def openUrl(self, url): try: webbrowser.get('chrome').open_new_tab(url) except: webbrowser.open_new_tab(url) def ui(self, widget): layout = QVBoxLayout(widget) row = QHBoxLayout() row.addWidget(Builder().text('Address:').name('address_hint').build()) row.addWidget(Builder().text( self.address.value).name('address').build()) row.addStretch(1) layout.addLayout(row) row2 = QHBoxLayout() row2.setAlignment(Qt.AlignBottom) row2.addWidget(Button.Builder(width=50, height=25).click( self.copy_address).text('copy').name('copy').build()) self.copyed = Builder().text('copyed!').name('copyed').build() row2.addWidget(self.copyed) self.copyed.hide() row2.addStretch(1) layout.addLayout(row2) layout.addWidget(Builder().text('Get CPC for free').name('get_cpc').click( lambda _: self.openUrl(config.account.charge_server)).build()) return layout def style(self): return super().style() + """
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) image_path = config.market.market_url + '/product/v1/allproducts/images/?path=' + self.image.value imageWid = ProductQML(self, image=image_path, img_width=240, img_height=160) imageWid.obj.signals.click.connect( 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() catbox.setSpacing(5) type_text = 'Batch' if self.ptype == 'file' else 'Streaming' icon = self.icon.value if icon: iconL = QLabel() iconL.setObjectName('icon') iconL.setPixmap(QPixmap(icon)) catbox.addWidget(iconL) type_wid = Builder().text(type_text).name('type_text').style( "color: #444;font-size:14").build() catbox.addWidget(type_wid) catbox.addSpacing(10) 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_