I'm new at GTK. I'm using Glade to make an interface and just want to insert objects (like buttons and others) into a container.
I've choosen GtkFixed so that all elements can be freely located and sized.
The problem is that when i drag a button for example, the button apparently gets it size from the parent (in this case the container) and takes a square shape.
Here's an image
I want the button to take the standard size, just like a rectangule or something. What i'm i doing wrong? I've checked some options in the container but can't figure out the way.
Thanks.
You have to remove the tick from Height request and Width request (I don't know the equivalent names in your language).
Besides, you should be aware that GtkFixed is difficult to use when the window can be resized. GtkBox is often easier.
Related
I am currently working on a project using Python and tkinter.
The problem is that I don't know what's the proper way to display multiple windows, or screens, I don't know how to call them. Let me explain better.
When the application starts the login screen appears. After that, if I click register, I want to go to the register screen, but I don't want it to be a separate window (I don't want to have 2 windows displayed at the same time), but rather another window with different content ?!
How should I handle properly this situation? Create a second window using Toplevel and hiding the first (can I do that?) or changing the widgets of the first?
Code I've written so far
You can do that- just call window.withdraw() on the Toplevel you need to hide after creating a new Toplevel. Changing the widgets in the first is also an option- if you like, you could always try a Notebook widget and disable manual flipping or just put each "screen" in a frame and grid_ or pack_forget them to remove them from the window.
I'm working on a X-plotter like widget that plots incomming data live.
I already searched for an solution to realize a scrolling along the x-axis if the widget has to much values and so they don't fit.
I had the folling approaches to realize it:
derive from a widget that supports scrolling and child widgets and add my own widget while making it bigger and bigger during the live updates: -> Which parent do I need to use and how do I avoid to draw all the stuff that is currently not visible?
modify my widget in a way that it supports the scrollbars itself -> but how?
draw/handle my own scrollbars -> worstcase :(
I really searched the web for suggestions or examples, but there is nothing about how to "construct" custom controls in a good way (beyond drawing something) esp. in the case of interaction...
Sorry but I'm a newbie at GTK in general :/
Most widgets in Gtk do not have scrollbars.
If you want to scroll the entire widget, you have to implement the GtkScrollable interface. Then, you add the widget to a GtkScrolledWindow. The scrolled window has the scrollbars, those GtkScrollbars are linked with GtkAdjustments which are passed to your custom widget through the GtkScrollable interface set_vadjustment and set_hadjustment.
If you just want to add a scrollbar and control its behaviour yourself, then you need to somehow add a GtkScrollbar in your widget, which means you will need to make it a container too.
The GtkScrollable approach is the following, first you implement vadjustment and hadjustment setters and getters, then when the GtkAdjustments are set, you set its lower and upper limits and the page size(how much of the widget is visible at once). After that, you connect their value-changed signal so you can refresh your widget when the scrollbars are dragged. A GtkScrollable doesn't get to check the scrollbars, only the adjustments that will be bound to the scrollbars. When drawing the widget you get the adjustments' value property in order to determine how much the scrollbars have shifted in the horizontal and vertical axes.
I am trying to write a text viewer widget with PyGTK that displays line numbers alongside the main viewing window. Of course I want the line numbers and main window to scroll in sync with each other. I can't figure out how to get this to work, though. Right now I am doing this. TextViewer is a subclass of HBox that creates the two TextViews and packs them into itself under the attribute names linenums and mainview.
self.textviewer = TextViewer.TextViewer(self.toplevel)
sw = gtk.ScrolledWindow()
sw.set_vadjustment(self.textviewer.mainview.get_vadjustment())
sw.set_hadjustment(self.textviewer.mainview.get_hadjustment())
sw.add_with_viewport(self.textviewer)
sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
If I take out the two set_Xadjustment lines, then the embedded TextViews' scroll_to_mark function doesn't work, which isn't acceptable for my application. With them in, the main text window scrolls twice as quickly as the line number window, and vice versa if I set the ScrolledWindow's adjustments to those of self.textviewer.linenums. I strongly suspect that this is a bug. I also tried setting up the viewport myself and setting its adjustments to those of one of the TextViews, but again the scroll_to_mark functions stop working. How can I synchronize both TextViews to scroll as one, so that any scrolling changes to one of them equally affect the other?
EDIT: Here is the code in my main application where I set up the widget.
self.textviewer = TextViewer.TextViewer(self.toplevel)
sw = gtk.ScrolledWindow()
#These are the lines that toggle between the two problems when (un)commented
sw.set_vadjustment(self.textviewer.mainview.get_vadjustment())
sw.set_hadjustment(self.textviewer.mainview.get_hadjustment())
sw.add_with_viewport(self.textviewer)
sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
I'm having difficulty understanding exactly how you've got the two gtk.TextViews packed in the HBox. Are they both packed in separate gtk.ScrolledWindow that are then packed inside of the HBox which is then packed into another gtk.ScrolledWindow(The one mentioned in your post)? From what it sounds like to me, both of these gtk.TextViews are packed in their own gtk.ScrolledWindow within your TextViewer wrapper widget.
If this is the case, a simple solution to your issue, granted that the two gtk.TextViews are the same height(so the line numbers line up with the main view), I suggest simply packing them inside your Hbox without ScrolledWindows. Then you can use your code above, adding them that ScrolledWindow and the viewport will move the two collectively as if they are one widget.
If this isn't your issue, could you please supply some more information about your TextViewer wrapper, and maybe some more sample code?
Also: You may be interested in gtksourceview. With the gtksourceview2 package, you get an instance of the View widget:
import gtksourceview2
view = gtksourceview2.View()
You might want to check how it is implemented in Meld. In particular, the filediff code (search search for sync there).
Do you know if there is an easy way to drag-and-drop elements (icons or buttons) into a canvas and create different drawings on it as a result?
The idea is to have a set of objects and let the user drag them into a drawing space.
In the worst case the user could just click on the icon/button, and then click on the canvas and draw the element in the position, but I think the dragging is more intuitive.
There is an example of something more or less like this here: http://wiki.wxpython.org/wxOGL Although it is about wxOGL, they recommend you to use either SimpleCanvas or FloatCanvas and adapt their examples.
I assume you are building a browser app? If so, the jQuery UI Droppable plugin provides most of the standard functionality, and is pretty easy to modify to fit custom needs. Here's the link: http://jqueryui.com/demos/droppable/
I would like to create an application that has 3-4 frames (or windows) where each frame is attached/positioned to a side of the screen (like a task bar). When a frame is inactive I would like it to auto hide (just like the Windows task bar does; or the dock in OSX). When I move my mouse pointer to the position on the edge of the screen where the frame is hidden, I would like it to come back into focus.
The application is written in Python (using wxPython for the basic GUI aspects). Does anyone know how to do this in Python? I'm guessing it's probably OS dependent? If so, I'd like to focus on Windows first.
I don't do GUI programming very often so my apologies if this makes no sense at all.
As far as I know, there's nothing built in for this.
When the window is hidden, do you want it completely invisible or can a border of a few pixels be showing? That would be an easy way to get a mouse hover event. Otherwise you might have to use something like pyHook to get system-wide mouse events to know when to expand your window.
The events EVT_ENTER_WINDOW and EVT_LEAVE_WINDOW might also be useful here to know when the user has entered/left the window so you can expand/collapse it.
Expanding/collapsing can just be done by showing/hiding windows or resizing them. Standard window functions, nothing fancy.
By the way, you might want to use wx.ClientDisplayRect to figure out where to position your window. That will give you a rectangle of the desktop that does NOT include the task bar or any other toolbars the user has, assuming you want to avoid overlapping with those things.
Personally, I would combine the EVT_ENTER_WINDOW and EVT_LEAVE_WINDOW that FogleBird mentioned with a wx.Timer. Then whenever it the frame or dialog is inactive for x seconds, you would just call its Hide() method.
I think you could easily just make a window that is the same size as the desktop then do some while looping for an inactivity variable based on mouse position, then thread off a timer for loop for the 4 inactivity variables. I'd personally design it so that when they reach 0 from 15, they change size and position to become tabular and create a button on them to reactivate. lots of technical work on this one, but easily done if you figure it out