Message Boards Message Boards

0
|
2198 Views
|
10 Replies
|
7 Total Likes
View groups...
Share
Share this post:

Is it possible to add a combobox/dropdown list/popup menu with two columns

Posted 1 year ago

I would like my document to have a control looking something like this
enter image description here

I don't think it is possible but I would love to be told otherwise

POSTED BY: Paul Newton
10 Replies
Posted 1 year ago

That's exactly what I wanted - many thanks Rohit

POSTED BY: Paul Newton
Posted 1 year ago

Thank you Rohit and Eric. I much prefer the look of PopupMenu (just a personal thing) so I wonder whether we could adapt Rohit's code to populate PopupMenu?

POSTED BY: Paul Newton

Hi Paul,

Because there are so many items in menuData they are automatically rendered as a PopupMenu by Manipulate. If you want just a PopupMenu then use the pattern in Eric's code

PopupMenu[Dynamic@molecule, menuData]
POSTED BY: Rohit Namjoshi
Posted 1 year ago

I am not sure how the UI would differ using Row instead of Grid but am attaching sample data and perhaps you could advise. I will also need to investigate how I can respond to changing the selection in the PopupMenu but that can come later.

POSTED BY: Paul Newton

Here is one way

data = Import[
     "~/Downloads/Dissociation constants.xlsx", {"Dataset", 1}] // Normal // 
       DeleteCases[{"", ""}];

menuData = Grid[{#}, ItemSize -> {{35, 5}, Automatic}, Alignment -> Left, Dividers -> Center] & /@ data;
Manipulate[molecule[[1, 1]], {molecule, menuData}]

The menu entries are wide because some molecule names are very long, so a larger ItemSize width is needed to prevent wrapping.

POSTED BY: Rohit Namjoshi
Posted 1 year ago

Looks like Rohit got to it first. You can see the basic idea: create a function that creates the display form for a single "row" of data and map it over your data. You can experiment with Grid, Row, formatted strings, or anything else that strikes your fancy.

POSTED BY: Eric Rimbey
Posted 1 year ago

I have a database of acids and their dissociation constants which I could presumably import (either from DBF or XLS/XLSX) but how I would then programmatically generate the the data required for PopupMenu might be a problem. Do you have any ideas on that? Could we iterate through the data and add entities to PopupMenu one at a time?

POSTED BY: Paul Newton
Posted 1 year ago

If you have the data in a structured form, then that part of the problem would be easy. If you add some sample data, I can show you how. But you might want to first experiment with the UI side of things. You might decide you want Row instead of Grid (or whatever) and so your function to transform from raw data to a UI-friendly representation will depend on where you land on the UI side of things.

POSTED BY: Eric Rimbey
Posted 1 year ago

Thanks - I'll experiment with that and see how I get on.

POSTED BY: Paul Newton
Posted 1 year ago

It might depend on how faithful to that specific image you want to be. You can use pretty much anything you want for the labels in the popup menu, but you might not be able to get the "feel" of a single grid with its own drop-shadow and other details. So, here is a very loose approximation--maybe you can tweak it to get something close enough:

PopupMenu[
 Dynamic[molecule],
 {Entity["Chemical", "AceticAcid"] -> 
   Grid[{{"Acetic acid", 4.74}}, ItemSize -> {{12, 4}, Automatic}, Alignment -> Left],
  Entity["Chemical", "BromoaceticAcid"] -> 
   Grid[{{"Bromoacetic acid", 2.69}}, ItemSize -> {{12, 4}, Automatic}, Alignment -> Left],
  Entity["Chemical", "AdipicAcid"] -> 
   Grid[{{"Adipic acid", 5.41}}, ItemSize -> {{12, 4}, Automatic}, Alignment -> Left]}]

Of course, you probably want to come up with a way to programmatically generate this data.

POSTED BY: Eric Rimbey
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract