deselect(element) doesn't work, if selection is range
If I select range in score (not by plugin), I can deselcet some of elements. (It also changed range selection to list selection).
It is not possible to do this in plugin. If I deselect element of range selection, it removes all selection.
Is it possible to go around this somehow?
I can imagine, I can loop elements and create new selection, but this way "only a limited number of element types is supported".
Comments
I'm not the world's greatest plugin expert; but from my experience so far I don't believe you can deselect inside a plugin the way you wish to. Unless, perhaps, you could do some trickery using the 'cmd()' commands? Meaning you'd be simulating a user at the keyboard from inside your plugin.
The bigger question might be: what would you then intend to do with the remaining selected items? What are you trying to achieve in the end?
In reply to I'm not the world's greatest… by rocchio
I want to copy content from one staff to other. Almost whole content. Except some elements.
(I know, I can copy all and remove unwanted from second staff).
But this limit surprised me.
In reply to I want to copy content from… by sammik
Gotcha. The plugin API certainly does have it's limitations.
In reply to I want to copy content from… by sammik
I think maybe you're looking at this wrong. You can't copy list selections even from the GUI - well, at least not arbitrary ones. For instance, what would it mean to copy just one note of a chord from beat two of a measure, plus a hairpin on another staff, plus the composer text from the title frame? We only allow copying of very specific list selections - a list of lyrics, or of articulations, etc.
Meaning, even if you successfully created the selection, it would be usefuless for anything else deleting or making invisible. What you want instead is the Selection Filter - this is how you exclude elements from the selection while keeping it a range so you can do range things with it.
As for the specific feature of converting a range to a list by adding or removing individual elements - this was not something the UI could do either until quite recently, I think I added it maybe around 3.4 or 3.5. It's a bit of a hack actually, and I have no idea how one would go extending the plugin framework to produce the same. but you could possibly reproduce it in roughly the same way yourself - create a list of the selected elements, clear the selection, then build a new one by adding the elements back one by one. Again, though, it wouldn't actually be very useful, so probably not worth the bother. Copy and delete would be more straightforward, if you can't access the Selection Filter.
In reply to I think maybe you're looking… by Marc Sabatella
Thank you.
I need to rethink it a bit :)
Where did you find the documentation for 'deselect', I'm having similar issues, I think I can solve but need an explanation of how the
.select()
function worksIn reply to Where did you find the… by Dylan Nicholson1
https://musescore.github.io/MuseScore_PluginAPI_Docs/plugins/html/class…
In reply to https://musescore.github.io… by sammik
Ah, thanks, couldn't find that for some reason. Anyway to solve your problem you need to create a copy of the list of selected elements, clear the selection, then re-add individually (using
select(element, true)
- it was thattrue
parameter I was missing!)In reply to Ah, thanks, couldn't find… by Dylan Nicholson1
Sure. But select() works only for limited types of elements.
In reply to Sure. But select() works… by sammik
I don't think that's true. maybe you were confused by something I wrote above - selecting works for anything, but copying and pasting an arbitrary list of unrelated elements isn't possible. Not due to some arbitrary limitation of the plugin framework, but because it's nonsensical to copy and paste arbitrary lists of unrelated elements.
In reply to I don't think that's true. … by Marc Sabatella
But "select" in the plugin API is limited though, I believe it can't select barlines for example
In reply to I don't think that's true. … by Marc Sabatella
Plugin help says:
"At this point only a limited number of element types is supported, like notes, rests and most of text elements."
I cant remember, if, or how deeply I tested it, but somewhere in my mind is, that it really is limited.
In reply to I don't think that's true. … by Marc Sabatella
OK, thanks, I wasn't aware of this, and thought you might have been referring to my previous comment.