Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python中绘制GdkPixbuf?_Python_Gtk_Pygtk_Gdk_Gdkpixbuf - Fatal编程技术网

如何在python中绘制GdkPixbuf?

如何在python中绘制GdkPixbuf?,python,gtk,pygtk,gdk,gdkpixbuf,Python,Gtk,Pygtk,Gdk,Gdkpixbuf,好的,我试着在一张图片(平面布置图的蓝图)的上面覆盖一张打印机的图片。我最初是在看pixmaps,但在GTK3.0中很难找到关于它们的任何东西(找到了如何在pygtk中使用它们,但不是同一件事)。不管怎么说,这里是我现在拥有的(我省略了我认为代码中不重要的部分。此外,程序构建良好,但我没有看到任何图像覆盖): 导入cairo 导入gi gi.require_版本('Gtk','3.0') 从gi.repository导入Gtk、Gdk、GdkPixbuf 类客户端GUI: def构建_接口(自)

好的,我试着在一张图片(平面布置图的蓝图)的上面覆盖一张打印机的图片。我最初是在看pixmaps,但在GTK3.0中很难找到关于它们的任何东西(找到了如何在pygtk中使用它们,但不是同一件事)。不管怎么说,这里是我现在拥有的(我省略了我认为代码中不重要的部分。此外,程序构建良好,但我没有看到任何图像覆盖):

导入cairo
导入gi
gi.require_版本('Gtk','3.0')
从gi.repository导入Gtk、Gdk、GdkPixbuf
类客户端GUI:
def构建_接口(自):
#窗口
self.window=Gtk.window(Gtk.WindowType.TOPLEVEL,title=“SG打印辅助”)
self.window.add(self.topbox)
self.window.set_名称('window')
self.window.show()
self.hbox=Gtk.Box(方向=Gtk.orientation.卧式,间距=6)
#部门组合框;从另一个py文件调用函数,该文件检索要使用的模型。在我的程序中,还有两个其他组合框依赖于这个组合框。
self.department\u combo=Gtk.ComboBox.new\u,带有\u model\u和\u条目(self.logic.get\u department\u store())
self.department\u combo.connect(“已更改”,self.on\u department\u combo\u已更改)
self.department\u组合。set\u entry\u text\u列(0)
self.hbox.pack\u开始(self.department\u组合,False,False,0)
self.department\u combo.show()
self.hbox.show()
#形象;将根据用户在组合框中的输入更改为不同的图像(楼层平面图)
self.image=Gtk.image()
self.image.set_来自_文件(“pics/City Logo.jpg”)
self.image.show()
#XPM;这不是一台打印机,但出于测试目的,它真的不重要。
打印机\u xpm=[
"48 48 64 1",
“无”,
“.c#DF7DCF3CC71B”,
“X c#965875D669A6”,
“o c#71C671C671C6”,
“O c#A699A289A699”,
“+c#965892489658”,
“@c#8E38410330C2”,
“#c#D75C7DF769A6”,
“$c#F7DECF371B”,
“%c#96588A288E38”,
“&c#A69992489E79”,
“*c#8E3886178E38”,
“=c#104008200820”,
“-c#596510401040”,
“c#C71B30C230C2”,
“:c#C71B9A699658”,
“>c#618561856185”,
“,c#20811C712081”,
“,                 459@>+&&                    ",
“$2u+>”,
“Oh$;ya*3d.a8j,Xe.d3g8+”,
“Oh$;ka*3d$a8lz,,xxc:.e3g54”,
“Oh$;kO*pd$%svbzz,sxxxfx..&wn>”,
“哦$@mO*3dthlsszjzxxxxxx3:td8M4”,
“Oh$@g&*3d$XNLVVLLLM,MNWXXXXXXXXFA.:,B*”,
“哦,$@,Od。czlllllzlmmqV@V#V@fxxxxxxxf:%j5&“,
“Oh$1hd5lllslllCCZrV#r#:#2XXXXXXXXXXXXCDWM*”,
“OXq6c.%8vvvllZZiqqApA:mq:XXCPCXXXFDC9*”,
“2r”,

“OA1您没有任何GUI元素。您想要什么类型的GUI?我已经设置好GUI(使用gtk窗口和gtk小部件),我只是没有包括它,因为它有很多小部件,我不想占用大量与问题无关的空间。我将在代码中添加一些。是的,请设置一个最小的示例来显示您想要做的事情。创建新的cairo上下文以在屏幕上显示内容是不寻常的,这就是为什么我需要sk.对于文档,你看了吗?@SANIN404查看
GdkDrawingArea
并使用
draw
信号。这将为你提供可绘制的开罗上下文。你没有任何GUI元素。你想要什么样的GUI?我已经设置好GUI(使用gtk窗口和gtk小部件),我只是没有
import cairo
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk, GdkPixbuf

class ClientGUI:
    def build_interface(self):

        # Window
        self.window = Gtk.Window(Gtk.WindowType.TOPLEVEL, title="SG Print Assist")
        self.window.add(self.topbox)
        self.window.set_name('window')
        self.window.show()

        self.hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=6)
        # Department combobox; calls a function from another py file that retrieves the model to use.  In my program there are two other combo boxes that are dependent on this one.
        self.department_combo = Gtk.ComboBox.new_with_model_and_entry(self.logic.get_department_store())
        self.department_combo.connect("changed", self.on_department_combo_changed)
        self.department_combo.set_entry_text_column(0)
        self.hbox.pack_start(self.department_combo, False, False, 0)
        self.department_combo.show()
        self.hbox.show()

        # Image; will change to different images (floor plans) based on user input into combobox
        self.image = Gtk.Image()
        self.image.set_from_file("pics/City Logo.jpg")
        self.image.show()


        # XPM;  This isn't a printer, but for testing purposes it really doesn't matter.
        printer_xpm = [
            "48 48 64 1",
            "       c None",
            ".      c #DF7DCF3CC71B",
            "X      c #965875D669A6",
            "o      c #71C671C671C6",
            "O      c #A699A289A699",
            "+      c #965892489658",
            "@      c #8E38410330C2",
            "#      c #D75C7DF769A6",
            "$      c #F7DECF3CC71B",
            "%      c #96588A288E38",
            "&      c #A69992489E79",
            "*      c #8E3886178E38",
            "=      c #104008200820",
            "-      c #596510401040",
            ";      c #C71B30C230C2",
            ":      c #C71B9A699658",
            ">      c #618561856185",
            ",      c #20811C712081",
            "<      c #104000000000",
            "1      c #861720812081",
            "2      c #DF7D4D344103",
            "3      c #79E769A671C6",
            "4      c #861782078617",
            "5      c #41033CF34103",
            "6      c #000000000000",
            "7      c #49241C711040",
            "8      c #492445144924",
            "9      c #082008200820",
            "0      c #69A618611861",
            "q      c #B6DA71C65144",
            "w      c #410330C238E3",
            "e      c #CF3CBAEAB6DA",
            "r      c #71C6451430C2",
            "t      c #EFBEDB6CD75C",
            "y      c #28A208200820",
            "u      c #186110401040",
            "i      c #596528A21861",
            "p      c #71C661855965",
            "a      c #A69996589658",
            "s      c #30C228A230C2",
            "d      c #BEFBA289AEBA",
            "f      c #596545145144",
            "g      c #30C230C230C2",
            "h      c #8E3882078617",
            "j      c #208118612081",
            "k      c #38E30C300820",
            "l      c #30C2208128A2",
            "z      c #38E328A238E3",
            "x      c #514438E34924",
            "c      c #618555555965",
            "v      c #30C2208130C2",
            "b      c #38E328A230C2",
            "n      c #28A228A228A2",
            "m      c #41032CB228A2",
            "M      c #104010401040",
            "N      c #492438E34103",
            "B      c #28A2208128A2",
            "V      c #A699596538E3",
            "C      c #30C21C711040",
            "Z      c #30C218611040",
            "A      c #965865955965",
            "S      c #618534D32081",
            "D      c #38E31C711040",
            "F      c #082000000820",
            "                                                ",
            "          .XoO                                  ",
            "         +@#$%o&                                ",
            "         *=-;#::o+                              ",
            "           >,<12#:34                            ",
            "             45671#:X3                          ",
            "               +89<02qwo                        ",
            "e*                >,67;ro                       ",
            "ty>                 459@>+&&                    ",
            "$2u+                  ><ipas8*                  ",
            "%$;=*                *3:.Xa.dfg>                ",
            "Oh$;ya             *3d.a8j,Xe.d3g8+             ",
            " Oh$;ka          *3d$a8lz,,xxc:.e3g54           ",
            "  Oh$;kO       *pd$%svbzz,sxxxxfX..&wn>         ",
            "   Oh$@mO    *3dthwlsslszjzxxxxxxx3:td8M4       ",
            "    Oh$@g& *3d$XNlvvvlllm,mNwxxxxxxxfa.:,B*     ",
            "     Oh$@,Od.czlllllzlmmqV@V#V@fxxxxxxxf:%j5&   ",
            "      Oh$1hd5lllslllCCZrV#r#:#2AxxxxxxxxxcdwM*  ",
            "       OXq6c.%8vvvllZZiqqApA:mq:Xxcpcxxxxxfdc9* ",
            "        2r<6gde3bllZZrVi7S@SV77A::qApxxxxxxfdcM ",
            "        :,q-6MN.dfmZZrrSS:#riirDSAX@Af5xxxxxfevo",
            "         +A26jguXtAZZZC7iDiCCrVVii7Cmmmxxxxxx%3g",
            "          *#16jszN..3DZZZZrCVSA2rZrV7Dmmwxxxx&en",
            "           p2yFvzssXe:fCZZCiiD7iiZDiDSSZwwxx8e*>",
            "           OA1<jzxwwc:$d%NDZZZZCCCZCCZZCmxxfd.B ",
            "            3206Bwxxszx%et.eaAp77m77mmmf3&eeeg* ",
            "             @26MvzxNzvlbwfpdettttttttttt.c,n&  ",
            "             *;16=lsNwwNwgsvslbwwvccc3pcfu<o    ",
            "              p;<69BvwwsszslllbBlllllllu<5+     ",
            "              OS0y6FBlvvvzvzss,u=Blllj=54       ",
            "               c1-699Blvlllllu7k96MMMg4         ",
            "               *10y8n6FjvllllB<166668           ",
            "                S-kg+>666<M<996-y6n<8*          ",
            "                p71=4 m69996kD8Z-66698&&        ",
            "                &i0ycm6n4 ogk17,0<6666g         ",
            "                 N-k-<>     >=01-kuu666>        ",
            "                 ,6ky&      &46-10ul,66,        ",
            "                 Ou0<>       o66y<ulw<66&       ",
            "                  *kk5       >66By7=xu664       ",
            "                   <<M4      466lj<Mxu66o       ",
            "                   *>>       +66uv,zN666*       ",
            "                              566,xxj669        ",
            "                              4666FF666>        ",
            "                               >966666M         ",
            "                                oM6668+         ",
            "                                  *4            ",
            "                                                ",
            "                                                "
        ]

        # Pixbuf; the printer image I'm trying to overlay on the image.  Will probably create a class to represent the printer objects overlaying which contains position member variables.  Will then make a list of these to overlay all of them over the image at different positions.
        pixbuf = GdkPixbuf.Pixbuf.new_from_xpm_data(printer_xpm)
        w, h = pixbuf.get_width(), pixbuf.get_height()

        surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h)
        context = cairo.Context(surface)

        Gdk.cairo_set_source_pixbuf(context, pixbuf, 100, 100)
        context.paint()