我想让窗口管理器管理好这些情节。当我在python中以交互方式创建绘图时:
import zbar
import Image
import ImageDraw
import kanban
class Scanner(object):
def __init__(self, imagepath):
self.image = Image.open(imagepath).convert('L')
self.width, self.height = self.image.size
self.informations = []
# create a reader
self.scanner = zbar.ImageScanner()
# configure the scanner
self.scanner.set_config(0, zbar.Config.ENABLE, 0)
self.scanner.set_config(zbar.Symbol.QRCODE, zbar.Config.ENABLE, 1)
def image_optimize(self):
doubled_size = (self.image.size[0] * 2, self.image.size[1] * 2)
self.image = self.image.resize(doubled_size, Image.ANTIALIAS)
self.width, self.height = self.image.size
def scan(self):
self.image_optimize()
pieces_size = int(self.get_qr_code_size() * 2)
step_size = int(pieces_size / 4)
self.scan_image(self.image,0,0)
y_start = 0
iy = 0
while y_start < self.height:
y_start = iy * step_size
y_end = y_start + pieces_size
iy += 1
ix = 0
x_start = 0
while x_start < self.width:
x_start = ix * step_size
x_end = x_start + pieces_size
crop_to = (x_start, y_start, x_end, y_end)
img_crop = self.image.crop(crop_to)
self.scan_image(img_crop, x_start, y_start)
ix += 1
return self.informations
def get_qr_code_size(self):
zbar_img = zbar.Image(self.width, self.height, 'Y800', self.image.tostring())php
qr_sizes = []
print(qr_sizes)
# scan the image for barcodes
self.scanner.scan(zbar_img)
for symbol in zbar_img:
qr_width = symbol.location[3][0] - symbol.location[0][0]
qr_height = symbol.location[1][1] - symbol.location[0][1]
qr_sizes.append(qr_width)
qr_sizes.append(qr_height)
if len(qr_sizes) == 0:
raise IOError('Klopfer says: no qr code scanned')
return sum(qr_sizes, 0.0) / len(qr_sizes)
def scan_image(self, img_scan, x_start, y_start):
crop_width, crop_height = img_scan.size
zbar_img = zbar.Image(crop_width, crop_height, 'Y800', img_scan.tostring())
# scan the image for barcodes
self.scanner.scan(zbar_img)
# Create a draw object
draw = ImageDraw.Draw(self.image)
draw_crop = ImageDraw.Draw(img_scan)
for symbol in zbar_img:
top_left = (symbol.location[0][0] + x_start, symbol.location[0][1] + y_start)
bottom_left = (symbol.location[1][0] + x_start, symbol.location[1][1] + y_start)
bottom_right = (symbol.location[2][0] + x_start, symbol.location[2][1] + y_start)
top_right = (symbol.location[3][0] + x_start, symbol.location[3][1] + y_start)
self.informations.append(kanban.Information(symbol.data, (top_left, bottom_left, bottom_right, top_right)))
draw.rectangle([(top_left), (bottom_right)], fill="black")
draw_crop.rectangle([symbol.location[0], symbol.location[2]], fill="black")
if len(zbar_img.symbols) > 0:
self.scan_image(img_scan, x_start, y_start)
检查窗口属性,我什么都没得到。
from numpy import arange
import matplotlib
matplotlib.use('Qt5Agg')
import matplotlib.pyplot as pt
pt.ion()
x = arange(-10,10,step=.1)
pt.plot(x, x**3)
如何告诉matplotlib / Python将X-window属性添加到其图中?
答案 0 :(得分:0)
看起来,这不是matplotlib的问题,也不是matplotlib的解决方案:相反,后端似乎负责创建窗口客户端并执行X.org属性的注册和设置。
从Qt5Agg切换到TkAgg后,我突然拥有了我想要的所有属性:
% xprop | grep CLASS
WM_CLASS(STRING) = "tk", "Tk"
% xprop | grep WM_NAME
_NET_WM_NAME(UTF8_STRING) = "Figure 1"
WM_NAME(STRING) = "Figure 1"
我的窗口管理员(herbstluftwm)现在正在很好地处理所有新创建的数字。