pygtk

Enable GtkFileChooserDialog to select files OR folders

戏子无情 提交于 2019-12-02 00:21:05
问题 Using GTK+'s GtkFileChooserDialog, how can I allow the user to select a file or a folder (both are valid here). The actions available are mutually exclusive. 回答1: Unfortunately I don't think this is possible. I played around with this a bit in the "create a torrent" dialog in Transmission, and wound up using a radibox to enable one of two chooserdialogbuttons, one in file mode and the other in folder mode. 回答2: You could add another button. Here is a small example which illustrates how you

Handling spreadsheet data through the clipboard in GTK

微笑、不失礼 提交于 2019-12-02 00:17:51
问题 I'm using a GtkSheet widget in PyGTK to power my application's spreadsheet, and it gives me an API to pull and push data out of cells. (I looked at using GtkTreeView, but it seemed to be too much work) What I don't understand is how to intercept paste requests (via ie. CTRL+V) so that I can process them rather than passing it through to the widget. Currently, when pasting from a spreadsheet the data shows up as follows: becomes Is there a signal I should intercept? I'm on Ubuntu 9.10, Python

Label does not trigger mouse event

人盡茶涼 提交于 2019-12-02 00:15:56
问题 In the pygtk reference it states that every Gtk.Widget has the event enter-event-notify, but with my test code that event is never fired for the Label widget (with others it has worked). Is there something I should do differently? import pygtk pygtk.require('2.0') import gtk class LabelTest: def delete_event(self, widget, event, data=None): return False def destroy(self, widget, data=None): gtk.main_quit() def __init__(self): self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.connect(

How to correctly covert 3d array into continguous rgb bytes

时光毁灭记忆、已成空白 提交于 2019-12-01 21:40:29
问题 I'm trying to convert the 3d array returned by cv2.imread to the continguous rgb byte array , in order to display in GTK. And below is my conversion code: def ndarr2rgb(img): r_arr = img[:, :, 0].ravel() # read channel g_arr = img[:, :, 1].ravel() # green channel b_arr = img[:, :, 2].ravel() # blue channel numItems = img.shape[0] * img.shape[1] * img.shape[2] # number of entries in byte array z = img.shape[2] # z dimension, always equal to 3 arr = np.zeros((numItems, 1)) # to fill the byte

update a gtk.VBox dynamically

╄→尐↘猪︶ㄣ 提交于 2019-12-01 21:34:56
I have been using this website pretty often in order to solve small issues that I have while programming in Python. This time, somehow I could not find a suitable solution for my situation. So, here is my problem: I want to dynamically add entries to a gtk.VBox widget. The problem is that it doesn't work the way I want it to work. I simply have a button, whose action is to add an additional widget to a VBox. Unfortunately the widget doesn't appear on the window. I guess, I have to add something like a repaint function call, but I didn't find anything like that. Here is a sample code, showing

Label does not trigger mouse event

久未见 提交于 2019-12-01 21:34:12
In the pygtk reference it states that every Gtk.Widget has the event enter-event-notify , but with my test code that event is never fired for the Label widget (with others it has worked). Is there something I should do differently? import pygtk pygtk.require('2.0') import gtk class LabelTest: def delete_event(self, widget, event, data=None): return False def destroy(self, widget, data=None): gtk.main_quit() def __init__(self): self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.connect("delete_event", self.delete_event) self.window.connect("destroy", self.destroy) self.window.set_border

Python如何开发桌面应用程序?Python基础教程,第十三讲,图形界面

梦想与她 提交于 2019-12-01 19:30:23
当使用桌面应用程序的时候,有没有那么一瞬间,想学习一下桌面应用程序开发?行业内专业的桌面应用程序开发一般是C++,C#来做,Java开发的也有,但是比较少。本节课会介绍Python的GUI(图形用户界面)编程,用Python也可以写出漂亮的桌面程序,建议此次课程大家稍作了解不要浪费太多时间,因为没有哪家公司会招聘以为Python程序员开发桌面程序吧? 学完此次课程,我能做什么? 学完本次课程,大家可以完成一个简易的记事本编辑器。 学习此次课程,需要多久? 15-20分钟 课程内容 首先看一下目前有哪些主流的GUI平台。 Tkinter:使用Tk平台,支持大多数的Unix系统,同时可以在Windows和Mac下运行,是Python的标准界面库,但是由于界面丑陋,文档极差而被开发者吐槽。 wxpython:拥有成熟和丰富的包,跨平台,可在Unix,Windows,Mac下运行,入门简单,文档写的很详细,再加上官方的Demo大全,确实给初学者降低难度,可以作为入门学习的首选库。 PythonWin:只能在Windows上使用,调用windows的GUI,如果要做跨平台的应用程序,显然不会选择它。 PyGTK:使用GTK平台,Linux系统上使用较多,跨平台。 PyQt:优点界面美观,多个平台,文档和教程丰富。但是商业化使用有版权的问题,需要授权,体积相对较大。

How do you change alternating background row colors of a gtk.TreeView in pygtk?

醉酒当歌 提交于 2019-12-01 18:33:22
I'm trying to change the alternating background color of a treeview. I know that this should normally be left up to the theme, but I'd like to override to test the gtk Style functionality. According to the treeview documentation here , I learned that the TreeView has several style options that are Read-only, including "even-row-color", "odd-row-color" and "allow-rules"(which according to the documentation, allows drawing of even and odd row colors). And I know that in order to override those Read-only settings I've got to change the style in a gtkrc-style file or string. So my string for a

Python&PyGTK: Stop while on button click

风流意气都作罢 提交于 2019-12-01 18:23:27
I'm working on programming some application and I would like to create while loop when button is clicked and if it's clicked again to stop it. This is the code for button: self.btnThisOne = gtk.Button("This one") self.btnThisOne.connect("clicked", self.startLoop) The code for startLoop def would be: def startLoop(self): while self.btnThisOne?(is_clicked)?: #do something How to do that? Unfortunately, you cannot just have an unconstrained while loop running in the main thread of your application. That would block the main gtk event loop and you won't be able to process any more events. What you

Changing the selected item colour in a GtkTreeview using python

纵饮孤独 提交于 2019-12-01 17:32:36
I have a dialog which contains a pygtk.treeview for listing tasks by priority. Each row has the background colour set based on that priority, so for example the highest priority has a light red background. The row selection color is not so easy to change. I can set it using treeview.modify_base(gtk.STATE_SELECTED, "#C4C4C4") , but no colours work well with the colours used to enhance the concept of priority. I had the idea to change the selection colour to be a slightly darker version of the colour used as the normal row background, so in the example above, that would be a darker red. I tried