- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
<分区>
请运行下面的代码得到这样的东西:
基本上,我已经设置了一个 Gtk.DrawingArea,它位于 Gtk.Viewport 中,它也在 Gtk.Scrolledwindow 中。在所述 DrawingArea 中,我绘制了一个图像,并使用 2 个按钮可以缩放该图像。
# -*- encoding: utf-8 -*-
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GdkPixbuf
class MyWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="DrawingTool")
self.set_default_size(800, 600)
# The ratio
self.ratio = 1.
# Image
filename = "image.jpg"
self.original_image = GdkPixbuf.Pixbuf.new_from_file(filename)
self.displayed_image = GdkPixbuf.Pixbuf.new_from_file(filename)
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
# Zoom buttons
self.button_zoom_in = Gtk.Button(label="Zoom-In")
self.button_zoom_out = Gtk.Button(label="Zoom-Out")
# |ScrolledWindow
# |-> Viewport
# |--> DrawingArea
scrolledwindow = Gtk.ScrolledWindow()
viewport = Gtk.Viewport()
self.drawing_area = Gtk.DrawingArea()
self.drawing_area.set_size_request(
self.displayed_image.get_width(), self.displayed_image.get_height())
self.drawing_area.set_events(Gdk.EventMask.ALL_EVENTS_MASK)
# Pack
viewport.add(self.drawing_area)
scrolledwindow.add(viewport)
box.pack_start(self.button_zoom_in, False, True, 0)
box.pack_start(self.button_zoom_out, False, True, 0)
box.pack_start(scrolledwindow, True, True, 0)
self.add(box)
# Connect
self.connect("destroy", Gtk.main_quit)
self.button_zoom_in.connect("clicked", self.on_button_zoom_in_clicked)
self.button_zoom_out.connect("clicked", self.on_button_zoom_out_clicked)
self.drawing_area.connect("enter-notify-event", self.on_drawing_area_mouse_enter)
self.drawing_area.connect("leave-notify-event", self.on_drawing_area_mouse_leave)
self.drawing_area.connect("motion-notify-event", self.on_drawing_area_mouse_motion)
self.drawing_area.connect("draw", self.on_drawing_area_draw)
self.show_all()
def on_button_zoom_in_clicked(self, widget):
self.ratio += 0.1
self.scale_image()
self.drawing_area.queue_draw()
def on_button_zoom_out_clicked(self, widget):
self.ratio -= 0.1
self.scale_image()
self.drawing_area.queue_draw()
def scale_image(self):
self.displayed_image = self.original_image.scale_simple(self.original_image.get_width() * self.ratio,
self.original_image.get_height() * self.ratio, 2)
def on_drawing_area_draw(self, drawable, cairo_context):
pixbuf = self.displayed_image
self.drawing_area.set_size_request(pixbuf.get_width(), pixbuf.get_height())
Gdk.cairo_set_source_pixbuf(cairo_context, pixbuf, 0, 0)
cairo_context.paint()
def on_drawing_area_mouse_enter(self, widget, event):
print("In - DrawingArea")
def on_drawing_area_mouse_leave(self, widget, event):
print("Out - DrawingArea")
def on_drawing_area_mouse_motion(self, widget, event):
(x, y) = int(event.x), int(event.y)
offset = ( (y*self.displayed_image.get_rowstride()) +
(x*self.displayed_image.get_n_channels()) )
pixel_intensity = self.displayed_image.get_pixels()[offset]
print("(" + str(x) + ", " + str(y) + ") = " + str(pixel_intensity))
MyWindow()
Gtk.main()
运行应用程序。我还设置了一些回调,因此当您将鼠标指针悬停在图像上时,您会知道:
i) 当你进入绘图区时
ii) 当你离开绘图区时
iii) DrawingArea 处的(x, y) 和图像像素强度
我面临的问题是,当您缩小足够多的次数时,图像将如下所示:
但是,“鼠标进入”和“鼠标离开”信号以及“鼠标移动”信号被发送,就像 DrawingArea 仍然具有与创建时相同的大小。请将鼠标悬停在图像上和图像外但在 DrawingArea 内以查看终端中的输出。
我希望信号在图像外悬停时不会自行发送。即,如果可能,将 DrawingArea 大小调整为显示的图像大小。
我有一个 GTK+ DrawingArea,它应该在左上角显示一个矩形。当我使用 Cairo 绘制矩形时,整个绘图区域都填充了矩形的颜色。我怎样才能防止这种情况发生?开罗为何这么做?我做错了什么? #
我目前在框架内加载一个 DrawingArea 小部件 - 它总是扩展以填充框架。然后我可以在 DrawingArea 上设置 configure 事件来分配一个与窗口大小相同的像素图,在它上面绘制,
我想通过继承 DrawingArea Widget 来实现自定义小部件,为此我需要使用 cairo 进行绘制。似乎在 gtk3 中引入了一个名为“draw”的新信号。如何在小部件内部绘制? map 和
我想更新 DrawingArea 中的 cairo 绘图。我试图通过使用新函数作为参数调用 DrawingArea::connect_draw(...) 来实现这一点。我的问题是它没有替换原来的绘图函
我正在尝试使用 GTK、Cairo 和 Glade 在 Rust 中构建一个 GUI。我想使用 gtk::DrawingArea 绘制一个运动场,但我不知道如何使用它。我有这个: extern cra
我正在根据找到的基本教程编写一个 PyGtk 绘图程序 here . 有什么方法可以将图像添加到绘图区域,这样您仍然可以在图像上绘图吗?例如邮票或导入的照片。我试过添加 gtk.Image() 但 g
我有以下 Python 2.7/PyGObject 3.0/PyGST 0.10 模块: from gi.repository import Gtk, Gdk, GdkPixbuf import pa
我正在尝试制作简单的正方形,您可以在其中使用鼠标进行绘画。问题是,每当绘制信号发生时,cairo 表面似乎已完全清除。我理解这一点,因为在第一个 queue_draw() 之后,白色背景消失了,我看到
我有一个绘图区,我在里面画了一些图形或图像,所以我有这个回调来截屏: void CanvasToolBox::actionCanvasCamera() { auto root = Gdk::W
我正在使用 gtkmm 和 cairo 开发一款平台游戏,但我找不到将图像设置为背景的方法,因此我不必在每次绘制事件时都重新绘制它。我正在将图像作为 pixbufs 进行管理。这真的可能吗,还是我想错
我想画一些相框,一张一张的Gtk::DrawingArea .在应用开始时,我需要获取DrawingArea的大小, 分配一个 RGB 缓冲区, 但是, DrawingArea::get_width(
我创建了一个 Gtk.grid,其中包含一堆可调整大小并可在网格周围拖动的按钮。 我还创建了一个 Gtk.drawingarea 来绘制网格线。我希望让我的按钮像这样透明: Gtk.Button.se
我想使用 PIL 将 gtk.DrawingArea() 对象内容保存到 jpeg 文件。我特别想添加到 this script制作照片的可能性。我找到了如何save image to jpeg 。我
我有一个使用 Glade 创建的界面。它包含一个 DrawingArea 和按钮。 我尝试创建一个线程,每隔 X 次刷新我的 Canva。几秒钟后,我收到如下错误消息: “X 窗口服务器 0.0”、“
我正在创建一个用于数据可视化的小工具。GUI 是用 Pygtk 创建的,非常简单。用户输入文件名后,可以按“calc”按钮查看输出。输出由 pycairo 渲染并呈现在 gtk.DrawingArea
先上GTKmm documentation example在 more complex clock example 上,他们正在继承 public Gtk::DrawingArea 来构建他们的应用程
我在 CEF Python 3 ( link ) 上得到这段代码 ... self.container = gtk.DrawingArea() self.container.s
我在 Ubuntu 12.04 LTS 32 位上使用带有 GNU 工具链和 gtkmm3 的 C++11。我一直在玩 Programming with gtkmm 3 中 gtkmm3 的一些示例。
我有一个使用 Cairo image surface 的小型 PyGI 项目,然后我用 surface pattern 缩放它并在 Gtk.DrawingArea 上渲染。 我想将缩放 版本写入 PN
我正在使用“gtkmm”制作一个 GUI 程序。我想在“Gtk::DrawingArea”小部件上绘制一些图形,但我希望该小部件“可调整大小”,所以当我绘制时,让我们说一条从“(0, 0)”到“(50
我是一名优秀的程序员,十分优秀!