PyQt: Global copy/paste actions for custom widgets - menu

I'm writing a tool which has a big custom text area widget and a lot of other text input widgets, etc. I'm currently working with adding copy/paste to my tool and got stuck on how to do this on a global level - i.e. I don't want to implement copy/paste locally in every widget that needs it. For Qt standard widgets it just works to use copy/paste with Ctrl+C/Ctrl+V, but of course I have to implement it manually for my custom widgets.
But what about copy/paste actions in the menu bar? Do I have to connect them to every widget that exists in my program, or is there some better built in way to do this? I would prefer if I could just connect the menu actions to some global copy/paste handler that notifies the widget in focus automatically.

There is no generic copy/paste functionality - for custom widgets, you will have to implement everything yourself. The QClipboard class provides access to the system clipboard. Every application has a single clipboard object, which can be accessed via QApplication.clipboard() or qApp.clipboard().
The standard Qt input widgets all define their own copy() and paste() slots that can be connected to menu actions, toolbar buttons, keyboard shortcuts, etc. So your custom widgets should probably define the same interface.
There are classes such as QActionGroup, QButtonGroup, and QSignalMapper that provide support for centralised signal handling, but it is often much simpler to stick with explicit, one-to-one connections.

Related

Combox nested within another Combobox

Using wxPython, is it possible to nest a combobox inside other combobox in a similar way to how submenus are nested within menus? I need something similar for a wx.Combobox or a wx.Choice.
Or is there any widget with which this can be done?
Well, there are some possibilities:
wx.lib.combotreebox.ComboTreeBox
wx.combo.OwnerDrawnComboBox
# possibly also:
wx.lib.popupctl
You might also use a button (or some control) to invoke a PopupMenu. It may be confusing for the user though, and you might get into trouble when trying to position the Popup menu correctly. Generally speaking, I advice not to be too creative when making UI.
Have you seen wxpython demo? It is a nice showcase of all possible widgets. You can obtain it from here: https://extras.wxpython.org/wxPython4/extras/

Windows Explorer Navigation Bar in PyQt

What's the best approach to mimic the Windows Explorer navigation bar in PyQt?. Perhaps a list of QComboBoxes as part of a parent class that concatenates the current item of each combo box to resolve the final path?
Is it possible to get a similar look by using stylesheets?
This is the object I need to mimic. I just want a theoretical approach about the best way to mimic it.
Thanks in advance
This is technically known as a breadcrumb widget.
There are multiple approaches to this. The closest emulation to Windows Explorer's behavior--leaving out the normally hidden line editor--involves a chain of widgets like so:
A top level parent QWidget-derived class with your implementation, which would have:
A QHBoxLayout
An arbitrary number of QComboBoxes
A QFileSystemModel from which to populate the combo boxes.
Alternatives
You could use a single QLabels with a series of hyperlinks divided by path separators if you don't care about drop-down behavior. Qt Creator does this.
If your data source is static and not as gigantic as the filesystem, you could use QToolButtons backed by a tree of QAction/QMenus. This is possibly a masochistic approach, given that you have to populate all of the actions and menus. Since that's what they are there for, though, it might be handy as part of a context-sensitive menubar or tab bar.
I was looking for such a widget too without any luck. So I've tried to implement this by myself. It's not finished yet and needs some more work, but here's the first result: breadcrumbsaddressbar.
It's based on QToolButton widgets with menu. Parts of address which don't fit are hidden like in Windows Explorer. Also the widget has auto-completion feature.
Update: there's also a C++ widget QtAddressBar which I have't tried.

PyQt inside Scene 3D of Blender

I import the PyQt5 library under blender and I created a command interface.
My problem is that I found myself with two windows (one of blender of course and one of PyQt)
Is there any way to automatically embed (in the script) the PyQt window inside the Blender 3D scene?
Thanks
I don't believe you will get that to work unless you alter blender's source code and build your own version of blender. While you have access to using a range of widgets that blender uses for it's UI, there aren't any ways to incorporate other GUI toolkits into blender's UI.
Blender uses python to define it's user interface and provide access to it's internal data. You can define your own panels, which are collapsible groups of UI widgets, that will be incorporated into blender's UI with the existing panels. You can define operators to perform custom actions, which are then attached to buttons displayed in your custom panels. You can also create addons so that your additions can be enabled every time blender is run.
To get more control over customising the UI appearance you could use the bgl module, I'm not certain if this can be used outside of a 3DView but you could turn a 3DView into your custom drawing area.

Menu Button that does not dismiss options onclick in JavaFX 2

I am quite new in JavaFX and I have a question about the design. I am creating my main menu in FXML using Scene Builder. I have various menu buttons and each of these have a sub-menu. These sub-menu options will open new windows. Is it possible to declare these submenu choices so they do not dissapear after I click on them? If so, can I declare it in my fxml or I have to do it programatically?
Also, is it possible to detach it from the menu button? I would like to have my menu choices around 1 cm away from the menu button itself.
Thank you
Suggested Alternate Solution
If you want more flexibility in positioning a popup menu after a button click as well as fine control over when the menu shows and hides, try using a Button + a ContextMenu rather than a MenuButton.
The relevant methods are:
contextMenu.show(anchorNode, side, dx, dy)
contextMenu.hide()
There is sample code for triggering a context menu on a button press button in the ContextMenu javadoc.
You might also need to monitor the context menu's showingProperty and in a listener show the menu again if the JavaFX system has decided to try and hide it after some user action and you still want the menu visible.
Answers to additional unrelated comments
OK It sounds logical, yet since Im not really good in JavaFX yet, your Idea is quite challenging.
It's not that hard to implement, but from your subsequent comments it sounds like it's probably not the user interface you want for your users anyway (which makes sense to me because the interface you describe in your question seems a little strange).
I thought If it would be easier to have a static xml that have various menu choices, lets say aligned to the right and then whenever I click one of the choices, a new FXML would be loaded in the middle of the screen holding buttons for a submenu?
That seems logical. Sounds like a JavaFX version of a traditional web page layout with a navigation menu on the side controlling a content pane in the center.
A Java only version of that is: How to have menus in java desktop application. You could adapt that to a FXML based version without too much difficulty.
You might also be interested in Managing Multiple Screens in JavaFX.
Also, any tutorial for beginners would be greatly appreciated. These Oracle ones dont make too much sense for me
If you are beginning JavaFX, I recommend using just the Java API portions of JavaFX until you become familiar with them, and then use FXML only after you are comfortable with the Java API.
Personally, I think the Oracle JavaFX Tutorials are excellent. The difficulty for beginners is that the tutorials are also part reference material, which complicates portions of them (especially the deployment related pieces).
If you prefer a different tutorial style see:
Makery JavaFX tutorial (good for beginners)
zenjava tutorials (more advanced)

How to disable or apply custom menu to GTK (PyGTK) Notebook pages?

I am trying to apply custom menu to tab pages on my notebook control. I need to be able to select certain specific action for the entire page and i figured the tab label would be the best place to start.
So, i created a EventBox, applied Label as its child, and bound event callbacks to button-pressed-event and it... works.. kindof.
What i get is two menus: one is the one I create, and on top of it - the one created by GTK Notebook. to select something from my custom menu i need to escape the notebook menu first, and i certainly don't like it.
so the question is: how do I disable gtk notebook menus? or how can i set my own, custom menu, with my own, custom callbacks? I don't want to list all the available tab pages in the menu - it's introducing too much noise, so adding menu labels to the existing menu is not really the way to go.
thanks bunches
GtkNotebook should only show the tab selector if enable-popup is true. It defaults to false, so you've probably enabled it by mistake.

Resources