Categories
C#

C# winform 自定义 UserControl 生命周期

UserControl 类 是C# winform 中自定义控件的基类

所有自定义控件都要继承UserControl

自定义组件结构分为

组件属性 组件事件 和 组件方法

一般来说 在无参构造方法中 调用 InitializeComponent后 就可以执行 自己的初始化(InitializeComponent 后可认为组件已经渲染完毕)

之后一般是执行属性设置和事件绑定

Categories
linux

树莓派5 双触摸屏

第一禁用Wayland 用回x11设置

raspi-config 里设置后 重启

xinput查看当前当前触摸屏与设备 xrandr也可查看当前屏幕

xinput map-to-output 7 HDMI-1

xinput map-to-output 8 HDMI-2

Categories
python

pyqt5 pyside6 切换

pyside6 导入文件

from PySide6.QtCore import *
from PySide6.QtGui import *
from PySide6.QtWidgets import *

pyqt5 导入文件

from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *

切记pyqt5 与 pyside6 不能混用

Categories
python

PyQt5 QStackedWidget 使用方法

initialize sub component

self.Stack = QStackedWidget (self)
self.Stack.addWidget (self.stack1)
self.Stack.addWidget (self.stack2)
self.Stack.addWidget (self.stack3)

事件触发关联

self.leftlist.currentRowChanged.connect(self.display)

切换页面

def display(self,i):
    self.Stack.setCurrentIndex(i)
Categories
python

QT 使用图片作为背景

convertToQtFormat = QtGui.QImage(rgbImage.data, rgbImage.shape[1], rgbImage.shape[0], QImage.Format_RGB888)
									#在这里可以对每帧图像进行处理,
									image = convertToQtFormat.scaled(440, 330, Qt.KeepAspectRatio)
									self.video.setPixmap(QPixmap.fromImage(image))

rgbImage.data 是 python图片数组数据

所有组件都可以通过 setPixmap(QPixmap.fromImage(image)) 设置背景图像

import sysfrom PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QApplication, QMainWindow

class Ui_MainWindow(object):

def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(270, 180, 241, 101))
self.label.setText("")
self.label.setPixmap(QtGui.QPixmap(":/img/logo.png"))
self.label.setObjectName("label")
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)

def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))

if __name__ == '__main__':import resource  
# 导入添加的资源(根据实际情况填写文件名)
app = QApplication(sys.argv)
MainWindow = QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())

设置icon

        self.pushButton_9.setIcon(QtGui.QIcon(QtGui.QPixmap("./resources/setting.png")))
self.pushButton_9.setIconSize(QtCore.QSize(30,30))
Categories
python

QT designer 使用

使用QT designer会生成一系列ui后缀文件

通过pyuic可以将ui文件转化为py文件

python -m PyQt5.uic.pyuic 1.ui -o 1.py
pyuic5 1.ui -o 1.py
pyside6-uic form.ui -o ui_form.py

把1.ui 转换为 1.py

class MainForm(QtWidgets.QMainWindow):
	def __init__(self,parent=None):
		super(MainForm,self).__init__(parent)
		__content = Ui_MainWindow.Ui_MainWindow()
		__content.setupUi(self)
		
	

if  __name__ == "__main__" :
	try: 
		print('start')
		__app = QtWidgets.QApplication(sys.argv) 
		__win = MainForm()
		__win .show()
		sys.exit(__app.exec_())
	except KeyboardInterrupt :
		print('destroy')

__content = Ui_MainWindow.Ui_MainWindow()

这段代码可以换成不同的UI generate的代码 就可以 切换ui文件 看效果

Categories
python

Pyqt 组件说明

Categories
objective-c

object-c UIImageView

UIImageView 是IOS图片控件。点击右上角 加号。可以打开控件窗口

绑定图片到UIImageView

点击UIImageView。右上角image选择图片绑定

Categories
php

laravel 默认 token 校验

调用的是TokenGuard 这个类

数据库user 表有 字段名为 api_token 的校验 用来存放token

用户登录后会获取该token 之后所有请求 都要带上该token

该token没有超时机制 每次获取user个人信息需要根据token查一次数据库 比jwttoken 性能要差

Categories
php

laravel jwt

为api 调用提供身份校验功能

docs https://jwt-auth.readthedocs.io/

install

composer require tymon/jwt-auth

Add the service provider to the providers array in the config/app.php config file as follows:

'providers' => [

    ...

    Tymon\JWTAuth\Providers\LaravelServiceProvider::class,
]

Run the following command to publish the package config file:

php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\LaravelServiceProvider"

Generate secret key

This will update your .env file with something like JWT_SECRET=XXX

php artisan jwt:secret

该包 修改laravel api 路径下默认的 token校验方式 把token改为JWT token

其实生成流程和校验流程和之前没变化

login 通过用户账号密码 作为 credentials 然后去数据库获取用户信息 该用户信息会生成JWT token 放在laravel 默认缓存管理器

后续请求 在请求头带上 Authorazation : bear $token

通过auth:api 中间件校验