예제 #1
0
 def submask(self):
     self.bmp = QBitmap(self.size())
     self.bmp.fill()
     self.p = QPainter(self.bmp)
     self.p.setPen(Qt.black)
     self.p.setBrush(Qt.black)
     self.p.drawRoundedRect(self.bmp.rect(), 10, 10)
     self.setMask(self.bmp)
예제 #2
0
    def __init__(self):
        super().__init__()
        self.setWindowTitle('pointout canvas')
        self.setWindowFlags(self.windowFlags()
                            | Qt.Window
                            | Qt.WindowTransparentForInput
                            | Qt.WindowDoesNotAcceptFocus
                            | Qt.FramelessWindowHint
                            | Qt.WindowStaysOnTopHint)
        self.setAttribute(Qt.WA_TransparentForMouseEvents)
        self.setAttribute(Qt.WA_NoSystemBackground)
        self.setAttribute(Qt.WA_TranslucentBackground)
        self.setAttribute(Qt.WA_TabletTracking)

        self.scribbles = []
        self.current_wet = Overlay()
        self.undo_stack = []

        cursor_bitmap = QBitmap.fromData(
            QSize(5, 5), bytes((
                0b00000,
                0b00000,
                0b00100,
                0b00000,
                0b00000,
            )))
        mask_bitmap = QBitmap.fromData(
            QSize(5, 5), bytes((
                0b00100,
                0b00000,
                0b10101,
                0b00000,
                0b00100,
            )))
        self.setCursor(QCursor(cursor_bitmap, mask_bitmap))

        self.anim_timer = QTimer()
        self.anim_timer.timeout.connect(self.anim_update)
        self.anim_timer.start(1000 // 30)
        self.anim_timer.setTimerType(Qt.CoarseTimer)
        self.wet_end = time.monotonic()

        self.tools = {
            'marker': Marker(),
            'highlighter': Highlighter(),
            'eraser': Eraser(),
            'red': ColorMarker(1, 0, 0),
            'green': ColorMarker(0, 1, 0),
            'blue': ColorMarker(0, 0, 1),
            'yellow': ColorMarker(1, 1, 0),
            'purple': ColorMarker(1, 0, 1),
            'cyan': ColorMarker(0, 1, 1),
        }
        self.tool = self.tools['marker']
예제 #3
0
 def blankCanvas(self) -> None:
     margin = self.parentWidget().layout().margin()
     width = self.topLevelWidget().width()
     height = self.topLevelWidget().height()
     for index in range(self.parentWidget().layout().count()):
         if index != self.parentWidget().layout().indexOf(self): 
             height -= (self.parentWidget().layout().itemAt(index).widget().height() + margin * 2)
     canvas = QBitmap(width - margin * 2, height)
     canvas.clear()
     self.setPixmap(canvas)
     self.update()
예제 #4
0
    def __init__(self, glyph: Glyph):
        """Construct a cache entry from a glyph."""

        # Glyph origin.
        self.x = glyph.x
        self.y = glyph.y
        self.w = glyph.w
        self.h = glyph.h

        self.bitmap = QBitmap.fromData(QSize(self.w, self.h), glyph.data, QImage.Format_Mono)
예제 #5
0
파일: view.py 프로젝트: nitrotm/2dtagger
def makeCursor(filename, color=Qt.black):
    pixmap = QPixmap(filename)
    mask = QBitmap(pixmap)
    pixmap.fill(color)
    pixmap.setMask(mask)
    return QCursor(pixmap)
 def testQCursorConstructor(self):
     bmp = QBitmap(16, 16)
     cursor = QCursor(bmp, bmp, 16, 16)
예제 #7
0
 def testFromDataMethod(self):
     dataBits = py3k.b('\x38\x28\x38\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\xfe\xfe\x7c\x7c\x38\x38\x10\x10')
     bim = QBitmap.fromData(QSize(8, 48), dataBits, QImage.Format_Mono) # missing function
예제 #8
0
 def testFromDataMethod(self):
     dataBits = py3k.b('\x38\x28\x38\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\x10\xfe\xfe\x7c\x7c\x38\x38\x10\x10')
     bim = QBitmap.fromData(QSize(8, 48), dataBits, QImage.Format_Mono) # missing function
예제 #9
0
파일: Login.py 프로젝트: alexsb1962/d_py
    def __init__(self):
        QWidget.__init__(self)

        self.theme = 2

        screen = QDesktopWidget()
        logging.info("screen size:" + str(screen.width()) + "," +
                     str(screen.height()))

        self.m_width = screen.height() / 2
        self.m_height = screen.height() / 2
        self.resize(self.m_width, self.m_height)
        # self.setFixedSize(self.m_width, self.m_height)
        size = self.geometry()
        self.move((screen.width() - size.width()) / 2,
                  (screen.height() - size.height()) / 2)

        # delete title box
        self.setWindowFlags(Qt.FramelessWindowHint)
        # self.setAttribute(Qt.WA_TranslucentBackground)

        logging.info("login widget size:" + str(self.size()))
        self.bitmap = QBitmap(self.size())
        painter = QPainter(self.bitmap)

        painter.fillRect(self.rect(), Qt.white)

        painter.setBrush(QColor(0, 0, 0))
        painter.setRenderHint(QPainter.Antialiasing, True)
        painter.drawRoundedRect(self.rect(), 10, 10)
        self.setMask(self.bitmap)

        self.layout = QVBoxLayout(self)
        self.layout.setContentsMargins(0, 0, 0, self.m_height / 15)
        self.layout.setSpacing(self.m_height / 15)
        self.topframe = QFrame(self)
        self.topframe.setObjectName("topframe")
        if self.theme == 1:
            self.topframe.setStyleSheet(
                "#topframe{background-color:qlineargradient("
                "spread:pad,"
                "x1:0,y1:0,x2:1,y2:1,"
                "stop:0 #5efce8,"
                "stop:1 #736efe);}")
        elif self.theme == 2:
            self.topframe.setStyleSheet(
                "#topframe{background-color:qlineargradient("
                "spread:pad,"
                "x1:0,y1:0,x2:1,y2:0,"
                "stop:0 #3a6186,"
                "stop:1 #89253e);}")
        elif self.theme == 3:
            self.topframe.setStyleSheet(
                "#topframe{background-color:qlineargradient("
                "spread:pad,"
                "x1:0,y1:0,x2:0,y2:1,"
                "stop:0 #19547b,"
                "stop:1 #ffd89b);}")
        else:
            self.topframe.setStyleSheet(
                "#topframe{background-color:qlineargradient("
                "spread:pad,"
                "x1:0,y1:0,x2:1,y2:1,"
                "stop:0 #ff8177,"
                "stop:1 #b12a5b);}")
        self.layout.addWidget(self.topframe)

        # setup checkbox
        self.combobox = QComboBox(self)
        self.combobox.setObjectName("combobox")
        self.combobox.setFixedSize(self.m_width / 1.5, self.m_height / 10)
        self.combobox.setStyleSheet(
            "QComboBox{border: 2px solid gray;"
            "border-radius:5px;"
            "background-color:rgb(255, 255, 255);"
            "color:rgb(0, 0, 0);"
            "padding: 1px 20px;}"
            "QComboBox:drop-down{subcontrol-origin: padding;"
            "subcontrol-position: top right;"
            "width: 50px;border-left-style:solid;"
            "border-top-right-radius: 3px;"
            "border-bottom-right-radius: 3px;"
            "border-left: 2px solid gray;"
            "background-color: rgba(100, 25, 100, 0);}"
            "QComboBox:down-arrow{border-image:url(icon/arrow-1.png);}"
            "QComboBox:item:selected{background: rgb(232, 241, 250);color: rgb(2, 65, 132);}"
            "QStyledItemDelegate{border: 100px solid rgb(161,161,161);}")

        # self.combobox.move(200, 200)
        self.layout.addWidget(self.combobox, 0, Qt.AlignHCenter)

        # setup login button
        self.loginbtn = QPushButton("ENTER", self)
        self.loginbtn.setObjectName("loginbtn")
        self.loginbtn.setFixedSize(self.m_width / 1.5, self.m_height / 10)
        self.loginbtn.setContentsMargins(200, 20, 20, 20)
        self.loginbtn.clicked.connect(self.login_event)
        self.loginbtn.setStyleSheet(
            "QPushButton{border-radius:%dpx;"
            "background-color:#89253e;"
            "color:rgb(0, 0, 0);}"
            "QPushButton:hover{color:rgb(0, 255, 0);}" % (self.m_height / 20))
        self.layout.addWidget(self.loginbtn, 0, Qt.AlignHCenter)

        # setup exit button
        self.exitbtn = QPushButton(self)
        # self.exitbtn.setText("Close")
        self.exitbtn.setToolTip("Close the widget")
        self.exitbtn.setFixedSize(40, 40)
        self.exitbtn.setIcon(QIcon("icon/close.png"))
        self.exitbtn.setIconSize(QSize(40, 40))
        self.exitbtn.clicked.connect(self.exit_event)
        logging.info("topframesize:" + str(self.topframe.size()))
        self.exitbtn.move(self.width() - 40, 0)
        # self.exitbtn.setGeometry(self.topframe.width()-40, 0, 100, 40)
        self.exitbtn.setStyleSheet("background-color: #600")
        self.exitbtn.setStyleSheet("background-color: transparent")
        self.exitbtn.isEnabled()

        self.logoImage = QPixmap("icon/silabslogo.png")
        self.logo = self.logoImage.scaled(self.m_width / 5, self.m_height / 5,
                                          Qt.KeepAspectRatio,
                                          Qt.SmoothTransformation)

        self.logoLable = QLabel(self)
        self.logoLable.setObjectName("logoLable")
        self.logoLable.setAlignment(Qt.AlignCenter)
        self.logoLable.setPixmap(self.logo)
        self.logoLable.setFixedSize(self.m_width / 4, self.m_height / 4)
        # self.logo.setScaledContents(True)
        self.logoLable.setStyleSheet("#logoLable{border: 2px solid gray;"
                                     "border-radius:75px;"
                                     "background-color:rgb(100, 100, 100);"
                                     "color:rgb(0, 0, 0);}")
        self.logoLable.move(self.m_width / 2 - self.m_width / 8,
                            self.m_height / 6)

        self.m_drag = False
        self.m_DragPosition = 0
        self.MainWindow = 0
예제 #10
0
class SignInWidget(QWidget, Ui_SignIn):
    def __init__(self):
        super(SignInWidget, self).__init__()
        self.setupUi(self)
        self.setWindowTitle("ctpbee客户端")
        # self.setWindowFlag(Qt.FramelessWindowHint)  # 去边框
        self.setWindowFlags(Qt.WindowCloseButtonHint)
        self.setStyleSheet(qss)
        # tab
        self.setTabOrder(self.userid_sim, self.password_sim)
        self.setTabOrder(self.password_sim, self.interface_sim)
        self.setTabOrder(self.interface_sim, self.other)
        self.setTabOrder(self.other, self.remember_me)
        #
        self.setTabOrder(self.userid, self.password)
        self.setTabOrder(self.password, self.brokerid)
        self.setTabOrder(self.brokerid, self.auth_code)
        self.setTabOrder(self.auth_code, self.appid)
        self.setTabOrder(self.appid, self.td_address)
        self.setTabOrder(self.td_address, self.md_address)
        self.setTabOrder(self.md_address, self.interface_)
        self.setTabOrder(self.interface_, self.remember_me)
        self.setTabOrder(self.remember_me, self.sign_in_btn)
        self.icon.installEventFilter(self)
        self.icon.setText('快速登录')
        self.icon.setStyleSheet("""
        QLabel{
        image: url(:/menu/images/bee_temp_grey.png);
        }
        QLabel:hover{
        color:#1B89CA;
        border:1px solid #2B2B2B;
        border-radius: 5px;
        }
        """)
        #
        self.sign_in_btn.clicked.connect(self.sign_in_slot)
        self.sign_in_btn.setDisabled(True)
        #
        for i in self.__dict__.values():
            if isinstance(i, QLineEdit):
                i.setContextMenuPolicy(Qt.NoContextMenu)  ######不允许右键产生子菜单
        self.login_tab.currentChanged.connect(self.check_disable)
        # 普通
        self.userid_sim.currentTextChanged.connect(self.check_disable)
        self.password_sim.textChanged.connect(self.check_disable)
        #
        self.userid.currentTextChanged.connect(self.check_disable)
        self.password.textChanged.connect(self.check_disable)
        self.brokerid.currentTextChanged.connect(self.check_disable)
        self.auth_code.currentTextChanged.connect(self.check_disable)
        self.appid.currentTextChanged.connect(self.check_disable)
        self.td_address.currentTextChanged.connect(self.check_disable)
        self.td_address.editTextChanged.connect(self.editTextChanged_slot)
        self.md_address.editTextChanged.connect(self.editTextChanged_slot)
        self.md_address.currentTextChanged.connect(self.check_disable)
        # timer
        self.timer = QTimer(self)
        self.timer.timeout.connect(self.close_load)
        self.load_remember()

    def submask(self):
        self.bmp = QBitmap(self.size())
        self.bmp.fill()
        self.p = QPainter(self.bmp)
        self.p.setPen(Qt.black)
        self.p.setBrush(Qt.black)
        self.p.drawRoundedRect(self.bmp.rect(), 10, 10)
        self.setMask(self.bmp)

    @Slot()
    def check_disable(self):
        if self.login_tab.currentIndex() == 0:
            if self.userid_sim.currentText() and self.password_sim.text():
                self.sign_in_btn.setEnabled(True)
            else:
                self.sign_in_btn.setDisabled(True)
        if self.login_tab.currentIndex() == 1:
            if self.userid.currentText() and \
                    self.password.text() and \
                    self.brokerid.currentText() and \
                    self.auth_code.currentText() and \
                    self.appid.currentText() and \
                    self.td_address.currentText() and \
                    self.md_address.currentText():
                self.sign_in_btn.setEnabled(True)
            else:
                self.sign_in_btn.setDisabled(True)

    def editTextChanged_slot(self):
        td = self.td_address.currentText()
        md = self.md_address.currentText()
        k = 'tcp://'
        if not md.startswith(k):
            self.md_address.setCurrentText(k + md)
        if not td.startswith(k):
            self.td_address.setCurrentText(k + td)

    def load_remember(self):
        def get_account(path):
            data = {}
            with open(path, 'r') as f:
                info = f.read()
            if info:
                try:
                    data = json.loads(info)
                    if not isinstance(info, dict):
                        raise Exception
                except Exception:
                    pass
            return data

        path_list = os.listdir(desktop_path)
        for i in path_list:
            path = join_path(desktop_path, i, '.account.json')
            if os.path.exists(path):
                info = get_account(path)
                self.userid.addItem(info.get('userid'))
                self.brokerid.addItem(info.get('brokerid'))
                self.auth_code.addItem(info.get('auth_code'))
                self.appid.addItem(info.get('appid'))
                self.td_address.addItem(info.get('td_address'))
                self.md_address.addItem(info.get('md_address'))
                self.interface_.addItem(info.get('interface'))
            path = join_path(desktop_path, i, '.sim.json')
            if os.path.exists(path):
                info = get_account(path)
                self.userid_sim.addItem(info.get('userid'))
                self.password_sim.setText(info.get('password'))
                self.remember_me_sim.setChecked(True)

    def load_config(self):
        for k, v in G.config.to_dict().items():
            if v:
                current_app.config.update({k: v})

    def close_load(self):
        self.loading.close()
        self.timer.stop()

    def sign_in(self, info):
        bee_app = CtpBee(name=info.get("username"),
                         import_name=__name__,
                         refresh=True)
        login_info = {
            "CONNECT_INFO": info,
            "INTERFACE": info.get('interface'),
            "TD_FUNC": True,
            "MD_FUNC": True,
        }
        bee_app.config.from_mapping(login_info)
        bee_app.start()
        # loading
        self.loading = LoadingDialog()
        G.loading = self.loading
        self.timer.start(2000)  # ms
        self.loading.msg.setText("正在连接服务器...")
        self.loading.exec_()
        if bee_app and \
                bee_app.trader and \
                bee_app.td_login_status:
            ##
            G.signin_success(info['userid'])
            ##
            self.load_config()
            ###
            mainwindow = MainWindow()
            mainwindow.sign_in_success()
            mainwindow.show()
            self.close()
            return True
        else:
            return False

    def sign_in_slot(self):
        if self.login_tab.currentIndex() == 0:
            self.common_sign_in()
        elif self.login_tab.currentIndex() == 1:
            self.detailed_sign_in()

    def common_sign_in(self):
        info = dict(
            userid=self.userid_sim.currentText(),
            password=self.password_sim.text(),
            interface=self.interface_sim.currentText(),
        )
        which_ = self.other.currentText()
        if which_ == 'simnow24小时':
            info.update(simnow_24)
        elif which_ == 'simnow移动':
            info.update(simnow_yd)
        if self.sign_in(info):
            if self.remember_me_sim.isChecked():
                account_path = os.path.join(G.user_path, ".sim.json")
                with open(account_path, 'w') as f:
                    json.dump(info, f)
        else:
            if which_ == 'simnow24小时':
                msg = 'simnow移动'
                info.update(simnow_yd)
            else:
                msg = 'simnow24小时'
                info.update(simnow_24)
            reply = QMessageBox.question(self, '登录出现错误', "是否尝试" + msg,
                                         QMessageBox.Yes | QMessageBox.No,
                                         QMessageBox.Yes)
            if reply == QMessageBox.Yes:
                self.interface_sim.setCurrentText(msg)
                if not self.sign_in(info):
                    QMessageBox.information(self, "提示", "登录失败")

    def detailed_sign_in(self):
        info = dict(
            userid=self.userid.currentText(),
            password=self.password.text(),
            brokerid=self.brokerid.currentText(),
            md_address=self.md_address.currentText(),
            td_address=self.td_address.currentText(),
            product_info="",
            appid=self.appid.currentText(),
            auth_code=self.auth_code.currentText(),
            interface=self.interface_.currentText(),
        )
        if self.sign_in(info):
            if self.remember_me.isChecked():
                account_path = os.path.join(G.user_path, ".account.json")
                with open(account_path, 'w') as f:
                    account = deepcopy(info)
                    account.pop('password')
                    json.dump(account, f)
        else:
            QMessageBox.information(self, '提示', "登录出现错误", QMessageBox.Ok,
                                    QMessageBox.Ok)

    def closeEvent(self, event: QCloseEvent):
        G.loading = None
        if G.mainwindow is None:
            try:
                current_app.release()
            except Exception:
                pass
        event.accept()

    def eventFilter(self, watched: QObject, event: QEvent) -> bool:
        if watched == self.icon:
            if event.type() == QEvent.MouseButtonPress:
                if self.login_tab.currentIndex() == 0:
                    self.login_tab.setCurrentIndex(1)
                    self.icon.setText('详细登录')
                else:
                    self.login_tab.setCurrentIndex(0)
                    self.icon.setText('快速登录')

        return super().eventFilter(watched, event)