示例#1
0
文件: loading.py 项目: jkulesza/pdash
 def initUI(self):
     self.setObjectName('Loading')
     layout = QHBoxLayout()
     layout.setContentsMargins(0, 0, 0, 0)
     layout.setSpacing(0)
     layout.setAlignment(Qt.AlignCenter)
     loading = LoadingGif(self,
                          path=abs_path('icons/new_loading.gif'),
                          width=self.width_,
                          height=self.height_)
     loading.setObjectName('loading')
     layout.addWidget(loading)
     text = QLabel(self.text_)
     text.setObjectName('Text')
     text.setContentsMargins(0, 0, 0, 0)
     layout.addWidget(text)
     self.setStyleSheet("""
     QLabel#Text {{
         font-size: {}px;
         color: #9B9B9B;
         padding-bottom: 3px;
         padding-left: 3px;
     }}
     """.format(self.font_size))
     self.setLayout(layout)
     self.setContentsMargins(0, 0, 0, 0)
示例#2
0
    def ui(self, widget):
        layout = QVBoxLayout(widget)
        width = 340
        layout.addWidget(Builder().name('field').text('Data name:').build())
        layout.addWidget(Input.Builder(width=width).model(self.data_name).name('data-name').placeholder('Please input data name').build())
        layout.addSpacing(10)
        layout.addWidget(Builder().name('field').text('Select a Proxy:').build())

        combox = ComboBox(self.proxy)
        combox.setMaximumWidth(width + 24)
        combox.setMinimumWidth(width + 24)
        layout.addWidget(combox)

        hbox = QHBoxLayout()
        hbox.setAlignment(Qt.AlignRight)
        hbox.addWidget(Button.Builder(width=100, height=30).text('Cancel').click(lambda _: self.close()).build())
        hbox.addSpacing(10)
        self.next_btn = Button.Builder(width=100, height=30).text('Next').click(self.toNext).style('primary').build()
        hbox.addWidget(self.next_btn)

        self.loading = LoadingGif()
        hbox.addWidget(self.loading)
        self.loading.hide()

        layout.addStretch(1)
        layout.addLayout(hbox)
        return layout
示例#3
0
    def ui(self, widget):
        layout = QVBoxLayout(widget)
        layout.setSpacing(1)
        self.input_name = Input(self.data_name)
        layout.addWidget(self.gen_row('Data Name:', self.input_name))

        # Storage
        storage = QComboBox()
        for item in self.storage:
            if item:
                storage.addItem(item['name'])
        storage.currentIndexChanged.connect(self.onChangeStorage)
        layout.addWidget(self.gen_row('Storage Location:', storage))

        self.now_wid = self.build_option_widget(
            self.storage[self.storage_index])
        height = self.storage[self.storage_index].get('height', self.height_)
        self.setHeight(height)
        layout.addWidget(self.now_wid)

        print(self.input_name.width())
        # # File Drop or Open
        fileSlt = FileUploadQml(width=330, height=121, gap=1)
        layout.addWidget(self.gen_row("File:", fileSlt))
        self.fileSlt = fileSlt

        layout.addStretch(1)

        # Ok and Cancel
        bottom = QHBoxLayout()
        bottom.setAlignment(Qt.AlignRight)
        bottom.setSpacing(20)
        bottom.addStretch(1)

        self.cancel = QPushButton('Cancel')
        self.cancel.setObjectName('pinfo_cancel_btn')
        self.cancel.clicked.connect(lambda _: self.close())
        bottom.addWidget(self.cancel)

        ok = QPushButton('OK')
        ok.setObjectName('pinfo_publish_btn')
        ok.clicked.connect(self.okListener)
        bottom.addWidget(ok)

        self.loading = LoadingGif()
        self.ok = ok
        self.loading.hide()
        bottom.addWidget(self.loading)
        layout.addLayout(bottom)
        return layout
示例#4
0
 def ui(self, layout):
     self.spacing(40)
     title = Builder().text('Generating keystore file…')\
                      .name('title')\
                      .build()
     self.add(title)
     self.spacing(60)
     loading = LoadingGif(path=abs_path('icons/GIF_3dot.gif'),
                          width=228,
                          height=228)
     self.add(loading)
示例#5
0
    def ui(self):
        self.setContentsMargins(0, 0, 0, 0)
        layout = QVBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)

        if os.path.exists(self.path):
            photo = QPixmap(self.path)
            photo = photo.scaled(self.width, self.height)

            label = QLabel()
            label.setPixmap(photo)
            self.photo = photo
            layout.addWidget(label)
        else:
            self.get_picture()
            gif = LoadingGif()
            self.gif = gif
            layout.addWidget(gif)
        self.layout = layout
        return layout
示例#6
0
class StreamUploadDialog(Dialog):

    uploaded = pyqtSignal(object)

    def __init__(self, parent=None, oklistener=None):
        width = 400
        height = 280
        title = "Upload Streaming Data"
        self.now_wid = None
        self.oklistener = oklistener
        self.data()
        self.init_proxy()
        super().__init__(wallet.main_wnd, title=title, width=width, height=height)
        self.uploaded.connect(self.uploadedSlot)

    @component.method
    def init_proxy(self):
        def set_proxy(proxy):
            self.proxy.value = proxy
        pick_proxy().addCallbacks(set_proxy)

    @component.data
    def data(self):
        return {
            "data_name": "",
            "proxy": []
        }

    def ui(self, widget):
        layout = QVBoxLayout(widget)
        width = 340
        layout.addWidget(Builder().name('field').text('Data name:').build())
        layout.addWidget(Input.Builder(width=width).model(self.data_name).name('data-name').placeholder('Please input data name').build())
        layout.addSpacing(10)
        layout.addWidget(Builder().name('field').text('Select a Proxy:').build())

        combox = ComboBox(self.proxy)
        combox.setMaximumWidth(width + 24)
        combox.setMinimumWidth(width + 24)
        layout.addWidget(combox)

        hbox = QHBoxLayout()
        hbox.setAlignment(Qt.AlignRight)
        hbox.addWidget(Button.Builder(width=100, height=30).text('Cancel').click(lambda _: self.close()).build())
        hbox.addSpacing(10)
        self.next_btn = Button.Builder(width=100, height=30).text('Next').click(self.toNext).style('primary').build()
        hbox.addWidget(self.next_btn)

        self.loading = LoadingGif()
        hbox.addWidget(self.loading)
        self.loading.hide()

        layout.addStretch(1)
        layout.addLayout(hbox)
        return layout

    def show_loading(self, flag):
        if flag:
            self.loading.show()
            self.next_btn.hide()
        else:
            self.loading.hide()
            self.next_btn.show()


    def uploadedSlot(self, path):
        self.show_loading(False)
        result = StreamUploadedDialog(oklistener=self.oklistener, data_name=self.data_name.value, stream_id=path['ws_url'])
        result.show()
        self.close()

    def toNext(self, _):
        # Upload to proxy, get streaming id
        def callback(path):
            try:
                # Save
                proxy = self.proxy.current
                self.aes_key = AESCipher.generate_key()
                remote_uri = str(path)
                new_file_info = FileInfo(name=self.data_name.value, data_type='stream', proxy=proxy,
                                         remote_type='stream', remote_uri=remote_uri, public_key=wallet.market_client.public_key,
                                         is_published=False, created=func.current_timestamp(), aes_key=self.aes_key)
                fs.add_file(new_file_info)
                self._id = new_file_info.id
                encrypted_key = RSACipher.encrypt(self.aes_key)
                encrypted_key = Encoder.bytes_to_base64_str(encrypted_key)
                wallet.market_client.upload_file_info(None, None, 0, self._id, 'stream', json.dumps(remote_uri), self.data_name.value, encrypted_key)
                path = json.loads(path)
                self.uploaded.emit(path)
            except Exception as err:
                logger.error(err)
        self.show_loading(True)
        self.upload().addCallbacks(callback)

    @component.method
    def upload(self):
        proxy = self.proxy.current
        storage_type = 'stream'
        storage_plugin = "cpchain.storage_plugin."
        module = importlib.import_module(storage_plugin + storage_type)
        s = module.Storage()
        param = dict()
        param['proxy_id'] = proxy # should be selected by UI from proxy list
        path = s.upload_data(None, param)
        return path

    def style(self):
        return super().style() + """
示例#7
0
class UploadDialog(Dialog):

    okSignal = pyqtSignal(int)

    def __init__(self, parent=None, oklistener=None):
        self.width_ = 550
        self.height_ = 630
        title = "Upload your file"
        self.storage_index = 0
        self.now_wid = None
        self.oklistener = oklistener

        self.storage = [{
            'name': 'Proxy',
            'type': 'proxy',
            'height': self.height_ - 200,
            'options': [{
                'type': 'combo',
                'items': []
            }]
        }, {
            'name':
            'Amazon S3',
            'type':
            's3',
            'options': [{
                'type': 'edit',
                'name': 'Bucket',
                'id': 'bucket'
            }, {
                'type': 'edit',
                'name': 'aws_secret_access_key',
                'id': 'aws_secret_access_key'
            }, {
                'type': 'edit',
                'name': 'aws_access_key_id',
                'id': 'aws_access_key_id'
            }, {
                'type': 'edit',
                'name': 'Key',
                'id': 'key'
            }],
            'listener':
            None
        }, {
            'name':
            'IPFS',
            'type':
            'ipfs',
            'height':
            self.height_ - 100,
            'options': [{
                'type': 'edit',
                'name': 'Host',
                'id': 'host'
            }, {
                'type': 'edit',
                'name': 'Port',
                'id': 'port'
            }],
            'listener':
            None
        }]
        self.proxy = ListModel([])
        self.create()
        self.max_row = 0
        for i in self.storage:
            if i:
                self.max_row = max(self.max_row, len(i['options']))
        self.data()
        super().__init__(wallet.main_wnd,
                         title=title,
                         width=self.width_,
                         height=self.height_)
        self.okSignal.connect(self.handle_upload_resp)

    def onChangeStorage(self, index):
        self.storage_index = index
        new_wid = self.build_option_widget(self.storage[self.storage_index])
        height = self.storage[self.storage_index].get('height', self.height_)
        self.setHeight(height)
        self.main.replaceWidget(self.now_wid, new_wid)
        self.now_wid.deleteLater()
        del self.now_wid
        self.now_wid = new_wid

    def build_option_widget(self, storage):
        if not storage:
            return
        storage_module = importlib.import_module("cpchain.storage_plugin." +
                                                 storage['type'])
        self.dst = app.storage[storage['type']]

        layout = QVBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        row = 0
        options = storage['options']
        for option in options:
            if option['type'] == 'edit':
                wid = QLineEdit()
                wid.setObjectName('{}-{}'.format(storage["type"],
                                                 option["id"]))
                wid.setText(self.dst[option['id']])
                layout.addWidget(self.gen_row(option['name'] + ":", wid))
            if option['type'] == 'combo':
                wid = ComboBox(self.proxy)
                wid.setMinimumWidth(340)
                layout.addWidget(self.gen_row("Proxy:", wid))

            row += 1
        wid = QWidget()
        wid.setLayout(layout)
        wid.setContentsMargins(0, 0, 0, 0)
        wid.setStyleSheet("""
            QWidget {
                
            }
            QComboBox {
                
            }
        """)
        return wid

    def gen_row(self, name, widget, width=None):
        layout = QHBoxLayout()
        layout.setAlignment(Qt.AlignLeft)
        nameWid = QLabel(name)
        nameWid.setMinimumWidth(160)
        nameWid.setObjectName("name")
        layout.addWidget(nameWid)
        layout.addWidget(widget)
        if width:
            widget.setMinimumWidth(width)
        if isinstance(widget, Label):
            unit = Label('CPC')
            unit.setObjectName('unit')
            widget.setObjectName('value')
            layout.addWidget(unit)
        tmp = QWidget()
        tmp.setLayout(layout)
        tmp.setObjectName('item')
        return tmp

    @component.data
    def data(self):
        return {"data_name": ""}

    @component.create
    def create(self):
        def set_proxy(proxy):
            if proxy:
                self.proxy.value = list(set(proxy))

        pick_proxy().addCallbacks(set_proxy)

    def ui(self, widget):
        layout = QVBoxLayout(widget)
        layout.setSpacing(1)
        self.input_name = Input(self.data_name)
        layout.addWidget(self.gen_row('Data Name:', self.input_name))

        # Storage
        storage = QComboBox()
        for item in self.storage:
            if item:
                storage.addItem(item['name'])
        storage.currentIndexChanged.connect(self.onChangeStorage)
        layout.addWidget(self.gen_row('Storage Location:', storage))

        self.now_wid = self.build_option_widget(
            self.storage[self.storage_index])
        height = self.storage[self.storage_index].get('height', self.height_)
        self.setHeight(height)
        layout.addWidget(self.now_wid)

        print(self.input_name.width())
        # # File Drop or Open
        fileSlt = FileUploadQml(width=330, height=121, gap=1)
        layout.addWidget(self.gen_row("File:", fileSlt))
        self.fileSlt = fileSlt

        layout.addStretch(1)

        # Ok and Cancel
        bottom = QHBoxLayout()
        bottom.setAlignment(Qt.AlignRight)
        bottom.setSpacing(20)
        bottom.addStretch(1)

        self.cancel = QPushButton('Cancel')
        self.cancel.setObjectName('pinfo_cancel_btn')
        self.cancel.clicked.connect(lambda _: self.close())
        bottom.addWidget(self.cancel)

        ok = QPushButton('OK')
        ok.setObjectName('pinfo_publish_btn')
        ok.clicked.connect(self.okListener)
        bottom.addWidget(ok)

        self.loading = LoadingGif()
        self.ok = ok
        self.loading.hide()
        bottom.addWidget(self.loading)
        layout.addLayout(bottom)
        return layout

    def show_loading(self, flag):
        if flag:
            self.loading.show()
            self.ok.hide()
        else:
            self.loading.hide()
            self.ok.show()

    def okListener(self, _):
        self.show_loading(True)
        # Find All needed values
        storage = self.storage[self.storage_index]
        dst = dict()
        if storage['type'] == 'proxy':
            dst['proxy_id'] = self.proxy.current
        for option in storage['options']:
            if option['type'] == 'edit':
                objName = storage['type'] + '-' + option['id']
                child = self.findChild((QLineEdit, ), objName)
                dst[option['id']] = child.text()
                if not dst[option['id']]:
                    warning(self)
                    self.show_loading(False)
                    return
        # save storage params
        deferToThread(app.save_params, storage['type'], dst)
        # Data Name
        dataname = self.data_name.value or self.input_name.text()
        if not dataname:
            warning(self, "Please input data name first")
            self.show_loading(False)
            return
        # File
        file = self.fileSlt.file
        if not file:
            warning(self, "Please drag a file or open a file first")
            self.show_loading(False)
            return
        fs.upload_file(file, storage['type'], dst,
                       dataname).addCallbacks(self.handle_ok_callback)

    def handle_upload_resp(self, status):
        self.show_loading(False)
        try:
            if status == 1:
                app.msgbox.info("Uploaded successfuly")
                if self.oklistener:
                    self.oklistener()
                self.close()
            else:
                app.msgbox.error("Uploaded fail")
                self.close()
        except Exception as e:
            logger.error(e)
            app.msgbox.error("Uploaded fail")
            self.close()

    def handle_ok_callback(self, file_id):
        file_info = fs.get_file_by_id(file_id)
        hashcode = file_info.hashcode
        path = file_info.path
        size = file_info.size
        product_id = file_info.id
        remote_type = file_info.remote_type
        remote_uri = file_info.remote_uri
        name = file_info.name
        encrypted_key = RSACipher.encrypt(file_info.aes_key)
        encrypted_key = Encoder.bytes_to_base64_str(encrypted_key)
        d = wallet.market_client.upload_file_info(hashcode, path, size,
                                                  product_id, remote_type,
                                                  remote_uri, name,
                                                  encrypted_key)

        def cb(status):
            self.okSignal.emit(status)

        d.addCallbacks(cb)

    def style(self):
        return super().style() + """