How do I convert the .place() method in python to java? - python

I am trying to convert my Python Code to Java. I need a GUI that is similar to python where I can use widgetname.place(x,y) to place objects anywhere I want in the window. I want to be able to specify where the object is placed in the window. I have tried GridLayout, GridBagLayout, BoxLayout and FlowLayout. None of those are allowing me to secify x and y coordinates to place my objects(text fields, labels, buttons) where ever I want. I need to be able to specify where the object goes on the screen using x and y coordinates.
Anyone have any ideas?

This can be done setting your LayoutManager to null, but it's highly discouraged precisely because it annihilates the goal of layouts, which is to be able to have good-looking frames, regardless of the look and feel, screen resolution, etc.
You'd better learn how to use layout managers, because that's the good way to design a GUI.

There's a Swing tutorial that gives a concise example on positioning widgets absolutely.

If you do start using LayoutManagers I recommend using TableLayout because it far easier and more powerful than GridBagLayout.
http://java.sun.com/products/jfc/tsc/articles/tablelayout/
Hopefully your need to do absolute positioning is relatively small because it's not flexible should the user resize the window, and your components need to change their size. If you are trying to build a component that renders to X,Y to draw graphics you can subclass JComponent and override paint().

Related

Best way of creating layout in pyqt5 to be resposive?

So I am curren]tly working on an app for image processing. I am using PyQt5 for this purpose. You can see how it looks like now on the picture below. My question is, what is the best way to make it responsive, meaning, if I resize the window, all the widgets will rescale as well. Right now I am using some groupboxes, Hlayouts, VLayouts.
Only thing that comes to my mind is to create a gridlayout, though I would like to know, if there is by any chance any other possibility how to easily do it, since there is quite a lot of widgets.
Also, I would like to ask about GroubBox widget. Down left I have four buttons which are in one groupbox whose border is set to none by self.tableButtonsGroupBox.setStyleSheet("tableButtonsGroupBox {border: none}"), but there is still visible the upper line. Is there way to get rid of it?
Thank you for suggestions in advance!

tkinter best way to adjust absolute coordinates based on native resolution

Presently I have my code which places a window on a canvas using
create_window((x,y),anchor="nw",....). I see how it displays (on a 1920x1080 monitor)and have adjusted x,y accordingly. But, when I then ran it on a 1360x768 screen it does not look good. So, I adjusted x,y (using the method to get screen width/height) and using different values for (x,y) based on that.
Is this the normal way to do that ? Because I have several places in my code for other calculations where I have to make this explicit adjustment. I am wondering if there is some better way to do this ?
As ProgrammingIsAwsome mentioned in the comments, I think you want your application to be in fullscreen mode. There are two different ways to do this (assuming root is a tk.Tk() instance):
The first way is actually a maximized window:
self.root.state("zoomed")
The second is the real fullscreen mode, hiding the taskbar and title bar:
self.root.attributes("-fullscreen", True)
Furthermore, I wouldn't recommend doing anything with absolute sizes. Use the nice geometry managers grid and place which manage that for you.

Python : UI Image Wipe, compare two images

I wanted to know if anyone knew where to start in terms of recreating this sort of functionality?
http://www.learningnuke.com/wp-content/uploads/nukewipepreview.png
In the picture you can drag the centre line to reveal Image A or Image B or parts of each, interactively.
I want to be able to wipe/reveal across two images, maybe it's possible doing some sort of interactive crop of sorts.
Wanting to add this feature to a window in Maya, so maybe with QT, but not essential.
Just some pointers would be great.
I can tell you that this is possible via Qt/PyQt in maya. You can create a dialog that displays QPixmaps with some form of mouse interaction to control their display. I would forget about trying to extend the actual Render View as this would be a pain in the ass.
Just focus on a Qt solution. Unfortunately beyond this, I'm not sure what more I can offer unless you have a specific question about its implementation.
I would probably stack the QPixmaps on top of each other inside of custom QLabel widgets. The QLabel would have a custom mousepress/move event that would resize maybe the right edge to simulate the wipe effect, and reveal the one stacked underneath.
Also, it does resemble the functionality of a QSplitter so that might also work, with an image on each side of the layout and a custom style to the split bar.

Is it possible to make text translucent in wxPython?

I am adding some wx.StaticText objects on top of my main wx.Frame, which already has a background image applied. However, the StaticText always seems to draw with a solid (opaque) background color, hiding the image. I have tried creating a wx.Color object and changing the alpha value there, but that yields no results. Is there any way I can put text on the frame and have the background shine through? And furthermore, is it possible to make the text itself translucent? Thanks.
You probably need some graphics rendering widget. As far as I know, in wxPython you can use either built-in wxGraphicsContext or pyCairo directly. Cairo is more powerful. However, I don't know the details.
I would try aggdraw into a small canvas.
Any Static Text uses the platform's native label machinery, so you don't get that sort of control over it.

How do I overlap widgets with the Tkinter pack geometry manager?

I want to put a Canvas with an image in my window, and then I want to pack widgets on top of it, so the Canvas acts as a background.
Is it possible to have two states for the pack manager: one for one set of widgets and another for another set?
The answer to your specific question is no. You can't have two states or otherwise use pack two different ways in the same parent.
However, what I think you want to accomplish is simple. Use the built-in features of the canvas to create an image item that is part of the canvas, then pack things into the canvas as if it were a frame.
You can accomplish a similar thing by creating a label widget with an image, then pack your other widgets into the label.
One advantage to using a canvas is you can easily tile an image to fill the whole canvas with a repeating background image so as the window grows the image will continue to fill the window (of course you can just use a sufficiently large original image...)
I believe that Bryan's answer is probably the best general solution. However, you may also want to look at the place geometry manager. The place geometry manager lets you specify the exact size and position of the widget... which can get tedious quickly, but will get the job done.
... turned out to be unworkable because I wanted to add labels and more canvases to it, but I can't find any way to make their backgrounds transparent
If it is acceptable to load an additional extension, take a look at Tkzinc. From the web site,
Tkzinc (historically called Zinc) widget is very similar to the Tk Canvas in that they both support structured graphics. Like the Canvas, Tkzinc implements items used to display graphical entities. Those items can be manipulated and bindings can be associated with them to implement interaction behaviors. But unlike the Canvas, Tkzinc can structure the items in a hierarchy, has support for scaling and rotation, clipping can be set for sub-trees of the item hierarchy, supports muti-contour curves. It also provides advanced rendering with the help of OpenGL, such as color gradient, antialiasing, transparencies and a triangles item.
I'm currently using it on a tcl project and am quite pleased with the results. Extensions for tcl, perl, and python are available.
Not without swapping widget trees in and out, which I don't think can be done cleanly with Tk. Other toolkits can do this a little more elegantly.
COM/VB/MFC can do this with an ActiveX control - you can hide/show multiple ActiveX controls in the same region. Any of the containers will let you do this by changing the child around. If you're doing a windows-specific program you may be able to accomplish it this way.
QT will also let you do this in a similar manner.
GTK is slightly harder.

Categories

Resources