This repository has been archived on 2023-09-06. You can view files and clone it, but cannot push or open issues/pull-requests.
yutent
/
py-gtk-notes
Archived
1
0
Fork 0
py-gtk-notes/notes/utils.py

46 lines
1.3 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @author yutent<yutent.io@gmail.com>
# @date 2023/07/28 14:39:33
def get_monitor_info(monitor):
return {
"model": monitor.props.model,
"scale_factor": monitor.props.scale_factor,
"manufacturer": monitor.props.manufacturer,
"refresh_rate": monitor.props.refresh_rate,
"is_primary": monitor.is_primary(),
"geometry": {
"width": monitor.props.geometry.width,
"height": monitor.props.geometry.height,
"x": monitor.props.geometry.x,
"y": monitor.props.geometry.y,
}
}
def pixbuf_to_dict(pixbuf, filename = ''):
has_alpha = pixbuf.get_has_alpha()
# 没有apha通道时, get_pixels() 得到像素矩阵会出现极个别像素出现alpha通道
# 所以, 这里强制设置alpha通道为false, 补全像素矩阵的数据
if has_alpha is False:
pixbuf = pixbuf.add_alpha(False, 0, 0, 0)
if pixbuf:
image = {
"width": pixbuf.get_width(),
"height": pixbuf.get_height(),
"colorspace": pixbuf.get_colorspace(),
"has_alpha": has_alpha,
"bits_per_sample": pixbuf.get_bits_per_sample(),
"rowstride": pixbuf.get_rowstride(),
"filepath": filename,
"length": pixbuf.get_byte_length(),
"bytes": list(pixbuf.get_pixels())
}
else:
image = None
return image
python + gtk3 + webkit2 学习笔记
Python 60.1%
JavaScript 37.6%
HTML 2.3%