Beispiel #1
0
    def __init__(self, parent=None):
        super(MsgInput, self).__init__(parent)
        self.setContentsMargins(3, 3, 3, 3)

        self.textEdit = TextEdit()
        self.textEdit.setMaximumHeight(self.teditHeight)
        self.setMaximumHeight(self.teditHeight + self.btnSize)
        self.textEdit.setFont(QFont("Times", 15, QFont.Normal))
        self.textEdit.entered.connect(self.sendText)

        sendTxt = QPushButton(u'发送')
        sendTxt.setFont(QFont("Microsoft YaHei", 15, QFont.Bold))
        sendTxt.setFixedHeight(self.btnSize)
        sendTxt.clicked.connect(self.sendText)

        sendSound = QPushButton(u'录音')
        sendSound.setFont(QFont("Microsoft YaHei", 15, QFont.Bold))
        sendSound.setFixedHeight(self.btnSize)
        sendSound.clicked.connect(self.sendSound)

        hl = FlowLayout()
        hl.addWidget(sendTxt)
        hl.addWidget(sendSound)
        # hl.setMargin(0)

        vl = QVBoxLayout()
        vl.addWidget(self.textEdit)
        vl.addLayout(hl)
        # vl.setMargin(0)
        self.setLayout(vl)
Beispiel #2
0
class ActionDelayUI(BasicActionUI):

    actcls = ActionDelay

    def __init__(self, container, act=None):
        super().__init__(container, act)
        self.value = QSpinBox()
        self.value.setMinimum(0)
        self.value.setMaximum(64000)  # up to 64s
        self.value.setValue(self.act.delay)
        self.value.valueChanged.connect(self.on_change)

        self.layout = FlowLayout()
        self.layout_container = QWidget()
        self.layout_container.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Maximum)
        self.layout_container.setLayout(self.layout)

        self.layout.addWidget(self.value)

    def insert(self, row):
        self.container.addWidget(self.layout_container, row, 2)

    def remove(self):
        self.container.removeWidget(self.layout_container)

    def delete(self):
        self.value.deleteLater()
        self.layout_container.deleteLater()

    def on_change(self):
        self.act.delay = self.value.value()
        self.changed.emit()
Beispiel #3
0
    def __init__(self, parent=None):
        super(MsgInput, self).__init__(parent)
        self.setContentsMargins(3, 3, 3, 3)

        self.textEdit = TextEdit()
        self.textEdit.setMaximumHeight(self.teditHeight)
        self.setMaximumHeight(self.teditHeight + self.btnSize)
        self.textEdit.setFont(QFont("Times", 20, QFont.Normal))
        self.textEdit.entered.connect(self.sendText)

        sendImg = QPushButton()
        sendImg.setStyleSheet(
            "QPushButton{border-image:url(icons/img.png);}"  #这个参数可以让图片随大小缩放
            "QPushButton:hover{border: 2px groove blue;}"
            "QPushButton:pressed{border-style: inset;}")
        sendImg.setFixedSize(self.btnSize, self.btnSize)
        sendImg.clicked.connect(self.sendImage)

        sendTxt = QPushButton(u'发送')
        sendTxt.setFont(QFont("Microsoft YaHei", 15, QFont.Bold))
        sendTxt.setFixedHeight(self.btnSize)
        sendTxt.clicked.connect(self.sendText)

        hl = FlowLayout()
        hl.addWidget(sendImg)
        hl.addWidget(sendTxt)
        hl.setMargin(0)

        vl = QVBoxLayout()
        vl.addLayout(hl)
        vl.addWidget(self.textEdit)
        vl.setMargin(0)
        self.setLayout(vl)
Beispiel #4
0
    def __init__(self, parent=None):
        super().__init__(parent)

        self.keymap_override = None

        self.tab_basic = QScrollArea()
        self.tab_iso = QScrollArea()
        self.tab_layers = QScrollArea()
        self.tab_quantum = QScrollArea()
        self.tab_backlight = QScrollArea()
        self.tab_media = QScrollArea()
        self.tab_user = QScrollArea()
        self.tab_macro = QScrollArea()

        self.widgets = []

        for (tab, label, keycodes) in [
            (self.tab_basic, "Basic",
             KEYCODES_SPECIAL + KEYCODES_BASIC + KEYCODES_SHIFTED),
            (self.tab_iso, "ISO/JIS", KEYCODES_ISO),
            (self.tab_layers, "Layers", KEYCODES_LAYERS),
            (self.tab_quantum, "Quantum", KEYCODES_QUANTUM),
            (self.tab_backlight, "Backlight", KEYCODES_BACKLIGHT),
            (self.tab_media, "App, Media and Mouse", KEYCODES_MEDIA),
            (self.tab_user, "User", KEYCODES_USER),
            (self.tab_macro, "Macro", KEYCODES_MACRO),
        ]:
            layout = FlowLayout()
            if tab == self.tab_layers:
                self.layout_layers = layout
            elif tab == self.tab_macro:
                self.layout_macro = layout
            elif tab == self.tab_user:
                self.layout_user = layout
            elif tab == self.tab_basic:
                # create the "Any" keycode button
                btn = SquareButton()
                btn.setText("Any")
                btn.setRelSize(KEYCODE_BTN_RATIO)
                btn.clicked.connect(lambda: self.anykey.emit())
                layout.addWidget(btn)

            self.widgets += self.create_buttons(layout, keycodes)

            tab.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
            tab.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
            tab.setWidgetResizable(True)

            w = QWidget()
            w.setLayout(layout)
            tab.setWidget(w)
            self.addTab(tab, tr("TabbedKeycodes", label))

        self.layer_keycode_buttons = []
        self.macro_keycode_buttons = []
        self.user_keycode_buttons = []
        self.set_keymap_override(KEYMAPS[0][1])
Beispiel #5
0
def updateUI(l):
    global pages,firstApp
    pages[1] = QWidget()
    layout = FlowLayout(spacing=30)
    if len(l)>0:
        firstApp = l[0]
    else: 
        firstApp = None
    for item in l:
        layout.addWidget(item)
    pages[1].setLayout(layout)
    stackedLayout.addWidget(pages[1])
    stackedLayout.setCurrentWidget(pages[1])
Beispiel #6
0
def updateUI(l):
    global pages, firstApp
    pages[1] = QWidget()
    layout = FlowLayout(spacing=30)
    # layout = QVBoxLayout()
    if len(l) > 0:
        firstApp = l[0]
    else:
        firstApp = None
    for item in l:
        layout.addWidget(item)
        pages[1].setLayout(layout)

    stackedLayout.addWidget(pages[1])
    # stackedLayout.setSize(pages[1].baseSize())
    # pages[1].setMinimumSize(800,1200)
    stackedLayout.setCurrentWidget(pages[1])
Beispiel #7
0
    def create_controls(self, score):
        inner_widget = QWidget(self)
        set_background(inner_widget, QColor('white'))
        self.inner_widget = inner_widget

        bar_layout = FlowLayout(inner_widget)
        self.bar_layout = bar_layout

        for i, bar in enumerate(score):
            b = self.create_bar(i)
            bar_layout.addWidget(b)

        scroller = DumbScrollArea()
        scroller.setWidget(inner_widget)
        scroller.setWidgetResizable(True)
        scroller.setFocusPolicy(Qt.NoFocus)
        self.scroller = scroller

        layout = QVBoxLayout(self)
        layout.addWidget(scroller)
Beispiel #8
0
    def generate(self):
        self.glyphs = {}
        self.metrics = QtGui.QFontMetrics(self.font)

        chrs = [chr(i) for i in range(self.first, self.first + self.count)]
        rects = [
            self.metrics.boundingRect(i) for i in chrs
            if not self.ignore.get(i, False)
        ]
        bounds = [
            min([R.left() for R in rects]),
            min([R.top() for R in rects]),
            max([R.right() for R in rects]),
            max([R.bottom() for R in rects])
        ]
        self.sz = [bounds[2] - bounds[0], bounds[3] - bounds[1]]
        self.baseline = -bounds[1] - 1
        if self.minimize:
            self.sz[1] -= self.metrics.descent() - 1
            self.baseline -= self.metrics.descent() - 1
        print self.sz, self.baseline, self.metrics.descent()

        frame = QtGui.QFrame(self)
        self.scroller.setWidget(frame)
        flow = FlowLayout(frame)
        flow.setSpacing(5)

        for i in chrs:
            flow.addWidget(GlyphWidget(self.makePixmap(i), i, self.sz[0],
                                       self))

        # compute the memory required for all the glyphs
        mem = sum([
            g.width()
            for i, g in self.glyphs.items() if not self.ignore.get(i, False)
        ]) * self.sz[1] / 8
        self.lbsz.setText("Required memory: %d bytes" % mem)
        # generate a test string to see how it looks
        self.testString()
Beispiel #9
0
class IconList(QLabel):
    def __init__(self, main, *args):
        super(IconList, self).__init__(*args)
        self.setMinimumSize(400, 400)
        self.main = main

        self.threadpool = QThreadPool()

        self.layout = FlowLayout()
        self.setLayout(self.layout)
        for i, dir in enumerate(os.listdir(QUAVERPATH)):
            print("asd", dir)
            w = LoadWorker(os.path.join(QUAVERPATH, dir), self)
            w.signals.result.connect(self.load_complete)
            self.threadpool.start(w)
            #if i == 5: break

    def load_complete(self, ret):
        s, p, f = ret
        # TODO why is this so god damn slow
        c = Card(folder=f, songname=s, pixmap=p, main=self.main)
        self.layout.addWidget(c)
Beispiel #10
0
    def __init__(self, parent=None):
        super(MsgInput, self).__init__(parent)
        self.setContentsMargins(3, 3, 3, 3)

        self.textEdit = TextEdit()
        self.textEdit.setMaximumHeight(self.teditHeight)
        self.setMaximumHeight(self.teditHeight + self.btnSize)
        self.textEdit.setFont(QFont("Times", 15, QFont.Normal))
        self.textEdit.entered.connect(self.sendText)

        sendImg = QPushButton()
        sendImg.setStyleSheet(
            "margin:0px;padding:1px;border:0px;background-image:url(img/file.png);"
        )
        sendImg.setFixedSize(22, 22)
        sendImg.clicked.connect(self.sendImage)

        sendEmoji = QPushButton()
        sendEmoji.setFixedSize(22, 22)
        sendEmoji.setStyleSheet(
            "margin:0px;padding:1px;border:0px;background-image:url(img/emoji.png);"
        )
        sendEmoji.clicked.connect(self.toInsertEmoji)

        sendTxt = QPushButton(u'发送')
        sendTxt.setStyleSheet(
            "QPushButton{border:1px solid #cccccc;color:cccccc}"
            "QPushButton:hover{background-color:#129611;color:while}"
            "QPushButton:pressed{background-color:#129611;;color:while}")
        sendTxt.setFixedHeight(self.btnSize)
        sendTxt.clicked.connect(self.sendText)

        hl = FlowLayout()
        hl.addWidget(sendTxt)

        hl.setMargin(2)

        h2 = FlowLayout()
        h2.addWidget(sendImg)
        h2.addWidget(sendEmoji)
        h2.setMargin(2)

        vl = QVBoxLayout()
        vl.addLayout(h2)
        vl.addWidget(self.textEdit)
        vl.addLayout(hl)

        vl.setMargin(0)
        self.setLayout(vl)
Beispiel #11
0
layout = FlowLayout(spacing=30)
appPanel = QScrollArea()
appPanel.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
stackedLayout = QStackedLayout()
pages = [QWidget(),None]
i = 0
firstApp = None
for app in launchers:
    try:
        if not app == {}:
            btn = AppButton(app['Name'], app['Exec'], app['Icon'], panel)
            if not firstApp:
                firstApp = btn
            btns.append(btn)
            i += 1
            layout.addWidget(btn)
          
    except Exception, e:
        print app, e

pages[0].setLayout(layout)
stackedLayout.addWidget(pages[0])
appPanel.setLayout(stackedLayout)

vbox = QVBoxLayout()
search = QLineEdit()


class WorkThread(QThread):

    def __init__(self):
Beispiel #12
0
class MainWindow(QtWidgets.QMainWindow):
    def __init__(self, args=None):
        super(MainWindow, self).__init__()
        uic.loadUi(utils.get_file('mainwindow.ui'), self)
        self.show()
        self.args = args
        self.scan_button = self.findChild(QtWidgets.QPushButton, "scanButton")
        self.combo_cast = self.findChild(QtWidgets.QComboBox, "comboCast")
        self.channels_layout = FlowLayout()
        self.scroll_contents = self.findChild(QtWidgets.QWidget,
                                              "scroll_contents")
        self.scroll_contents.setLayout(self.channels_layout)
        self.get_channels()
        self.get_chromecasts()

    def get_channels(self):
        self.channels = {}
        self.cp = ChannelParser(self.args)
        self.cp.newChannel.connect(self.onNewChannel)
        self.cp.cannotRetrieveChannels.connect(self.onCannotRetrieveChannels)
        self.cp.start()

    def get_chromecasts(self):
        self.combo_cast.clear()
        self.cs = ChromecastScanner()
        self.cs.newChromecast.connect(self.onNewChromecast)
        self.cs.start()

    def get_selected_chromecast(self):
        sci = self.combo_cast.currentIndex()
        cast = self.combo_cast.itemData(sci)
        return cast

    # Slots

    def onScan(self):
        self.get_chromecasts()

    def onPlay(self):
        button = self.sender()
        channel = self.channels[button]
        cast = self.get_selected_chromecast()
        if (cast):
            cast.wait()
            cast.media_controller.play_media(channel['stream'], 'video/mp4')

    @QtCore.pyqtSlot()
    def onCannotRetrieveChannels(self):
        QtWidgets.QMessageBox.warning(self, "Error",
                                      "Cannot retrieve channels")

    @QtCore.pyqtSlot(object)
    def onNewChannel(self, channel):
        button = QtWidgets.QPushButton()
        button.setMaximumWidth(60)
        button.setMinimumHeight(60)
        button.clicked.connect(self.onPlay)
        button.setToolTip(channel['name'])
        self.channels[button] = channel
        tf = channel.get('icon-tempfile')
        if (tf):
            button.setIcon(QtGui.QIcon(tf.fileName()))
            tf.remove()
        self.channels_layout.addWidget(button)

    @QtCore.pyqtSlot(object)
    def onNewChromecast(self, cast):
        self.combo_cast.addItem(cast.device.friendly_name, userData=cast)
Beispiel #13
0
class MainWindow(QMainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)

        self.load_wordlists()

        self.setWindowTitle('JWordInfo')
        self.setWindowIcon(QIcon('./icon.ico'))

        try:
            stylesheet = open('stylesheet.css', 'r').read()
            self.setStyleSheet(stylesheet)
        except:
            pass

        self.central_widget = QWidget()
        self.setCentralWidget(self.central_widget)

        self.lyt = QVBoxLayout(self.central_widget)

        self.line_edit = QLineEdit()
        self.line_edit.textChanged.connect(self.on_line_change)
        self.lyt.addWidget(self.line_edit)

        self.scroll_area = QScrollArea()
        self.scroll_area.setWidgetResizable(True)
        self.lyt.addWidget(self.scroll_area)

        self.scroll_area_widget = QWidget()
        self.scroll_area.setWidget(self.scroll_area_widget)
        self.scroll_area_lyt = FlowLayout(self.scroll_area_widget, grid=True)

        self.wordinfowidges = []

        for wordinfolist in self.wordinfolists:
            self.wordinfowidges.append(
                WordInfoWidget(wordinfolist, with_title=True))
            self.scroll_area_lyt.addWidget(self.wordinfowidges[-1])

        if len(self.wordinfowidges) < 1:
            self.scroll_area_lyt.addWidget(QLabel('No list loaded'))

        self.line_edit.setText('ようこそ')

    def load_wordlists(self):
        self.wordinfolists = []

        try:
            f = open('lists.txt', 'r', encoding='utf-8-sig')
        except:
            QMessageBox.warning(self, 'Error',
                                'Word list configuration was not found!')
            return

        for l in f:
            if l.startswith('#'):
                continue
            l = l.rstrip()
            if l != '':
                try:
                    l = WordInfoList(l)
                    self.wordinfolists.append(l)
                except ValueError as e:
                    QMessageBox.warning(
                        self, 'Error',
                        F'Loading a word list failed:\n\n{l}\n\n{str(e)}')

        f.close()

    def on_line_change(self, text):
        text = text.strip()

        for wordinfowidget in self.wordinfowidges:
            wordinfowidget.set_word(text)
Beispiel #14
0
class ActionSequenceUI(BasicActionUI):

    actcls = ActionSequence

    def __init__(self, container, act=None):
        super().__init__(container, act)

        self.btn_plus = QToolButton()
        self.btn_plus.setText("+")
        self.btn_plus.setToolButtonStyle(Qt.ToolButtonTextOnly)
        self.btn_plus.clicked.connect(self.on_add)

        self.layout = FlowLayout()
        self.layout_container = QWidget()
        self.layout_container.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Maximum)
        self.layout_container.setLayout(self.layout)
        self.widgets = []
        self.recreate_sequence()

    def recreate_sequence(self):
        self.layout.removeWidget(self.btn_plus)
        for w in self.widgets:
            self.layout.removeWidget(w)
            w.deleteLater()
        self.widgets.clear()

        for item in self.act.sequence:
            w = QComboBox()
            w.view().setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
            w.setStyleSheet("QComboBox { combobox-popup: 0; }")
            w.addItem(tr("MacroEditor", "Remove"))
            w.insertSeparator(1)
            for k in MACRO_SEQUENCE_KEYCODES:
                w.addItem(k.label.replace("\n", ""))
            w.setCurrentIndex(2 + MACRO_SEQUENCE_KEYCODES.index(item))
            w.currentIndexChanged.connect(self.on_change)
            self.layout.addWidget(w)
            self.widgets.append(w)
        self.layout.addWidget(self.btn_plus)

    def insert(self, row):
        self.container.addWidget(self.layout_container, row, 2)

    def remove(self):
        self.container.removeWidget(self.layout_container)

    def delete(self):
        for w in self.widgets:
            w.deleteLater()
        self.btn_plus.deleteLater()
        self.layout_container.deleteLater()

    def on_add(self):
        self.act.sequence.append(KC_A)
        self.recreate_sequence()
        self.changed.emit()

    def on_change(self):
        for x in range(len(self.act.sequence)):
            index = self.widgets[x].currentIndex()
            if index == 0:
                # asked to remove this item
                del self.act.sequence[x]
                self.recreate_sequence()
                break
            else:
                self.act.sequence[x] = MACRO_SEQUENCE_KEYCODES[self.widgets[x].currentIndex() - 2]
        self.changed.emit()
class GridWidget(QWidget):

    Page = 0
    loadStarted = pyqtSignal(bool)

    def __init__(self, *args, **kwargs):
        super(GridWidget, self).__init__(*args, **kwargs)
        self._layout = FlowLayout(self)  # 使用自定义流式布局
        # 异步网络下载管理器
        self._manager = QNetworkAccessManager(self)
        self._manager.finished.connect(self.onFinished)

    def load(self):
        if self.Page == -1:
            return
        self.loadStarted.emit(True)
        # 延迟一秒后调用目的在于显示进度条
        QTimer.singleShot(1000, self._load)

    def _load(self):
        print("load url:", Url.format(self.Page * 30))
        url = QUrl(Url.format(self.Page * 30))
        self._manager.get(QNetworkRequest(url))

    def onFinished(self, reply):
        # 请求完成后会调用该函数
        req = reply.request()  # 获取请求
        iwidget = req.attribute(QNetworkRequest.User + 1, None)
        path = req.attribute(QNetworkRequest.User + 2, None)
        html = reply.readAll().data()
        reply.deleteLater()
        del reply
        if iwidget and path and html:
            # 这里是图片下载完毕
            open(path, "wb").write(html)
            iwidget.setCover(path)
            return
        # 解析网页
        self._parseHtml(html)
        self.loadStarted.emit(False)

    def _parseHtml(self, html):
        #         encoding = chardet.detect(html) or {}
        #         html = html.decode(encoding.get("encoding","utf-8"))
        html = HTML(html)
        # 查找所有的li list_item
        lis = html.xpath("//li[@class='list_item']")
        if not lis:
            self.Page = -1  # 后面没有页面了
            return
        self.Page += 1
        self._makeItem(lis)

    def _makeItem(self, lis):
        for li in lis:
            a = li.find("a")
            video_url = a.get("href")  # 视频播放地址
            img = a.find("img")
            cover_url = "http:" + img.get("r-lazyload")  # 封面图片
            figure_title = img.get("alt")  # 电影名
            figure_info = a.find("div/span")
            figure_info = "" if figure_info is None else figure_info.text  # 影片信息
            figure_score = "".join(li.xpath(".//em/text()"))  # 评分
            # 主演
            figure_desc = "<span style=\"font-size: 12px;\">主演:</span>" + \
                "".join([Actor.format(**dict(fd.items()))
                         for fd in li.xpath(".//div[@class='figure_desc']/a")])
            # 播放数
            figure_count = (
                li.xpath(".//div[@class='figure_count']/span/text()") or [""])[0]
            path = "cache/{0}.jpg".format(
                os.path.splitext(os.path.basename(video_url))[0])
            cover_path = "pic_v.png"
            if os.path.isfile(path):
                cover_path = path
            iwidget = ItemWidget(cover_path, figure_info, figure_title,
                                 figure_score, figure_desc, figure_count, video_url, cover_url, path, self)
            self._layout.addWidget(iwidget)
Beispiel #16
0
class Tab(QObject):

    keycode_changed = pyqtSignal(int)

    def __init__(self,
                 parent,
                 label,
                 keycodes,
                 word_wrap=False,
                 prefix_buttons=None):
        super().__init__()

        self.label = label
        self.keycodes = keycodes
        self.word_wrap = word_wrap

        self.container = QScrollArea(parent)
        self.layout = FlowLayout()
        if prefix_buttons:
            for btn in prefix_buttons:
                self.layout.addWidget(btn)

        self.container.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
        self.container.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.container.setWidgetResizable(True)

        w = QWidget()
        w.setLayout(self.layout)
        self.container.setWidget(w)

        self.buttons = []

    def recreate_buttons(self):
        for btn in self.buttons:
            btn.hide()
            btn.deleteLater()
        self.buttons = []

        for keycode in self.keycodes:
            btn = SquareButton()
            btn.setWordWrap(self.word_wrap)
            btn.setRelSize(KEYCODE_BTN_RATIO)
            btn.setToolTip(Keycode.tooltip(keycode.code))
            btn.clicked.connect(
                lambda st, k=keycode: self.keycode_changed.emit(k.code))
            btn.keycode = keycode
            self.layout.addWidget(btn)
            self.buttons.append(btn)

        self.relabel_buttons()
        self.container.setVisible(len(self.buttons) > 0)

    def relabel_buttons(self):
        for widget in self.buttons:
            qmk_id = widget.keycode.qmk_id
            if qmk_id in KeycodeDisplay.keymap_override:
                label = KeycodeDisplay.keymap_override[qmk_id]
                highlight_color = QApplication.palette().color(
                    QPalette.Link).getRgb()
                widget.setStyleSheet("QPushButton {color: rgb%s;}" %
                                     str(highlight_color))
            else:
                label = widget.keycode.label
                widget.setStyleSheet("QPushButton {}")
            widget.setText(label.replace("&", "&&"))