Create a Popup Dialog with colors on it

I have a color mapping dictionary, whose keys and values are:

  • Key: a number
  • Value: A color mapped to that key

Can I create a dialog (or a popup), that shown the color alongside it’s associated value ? Something along the line of the figure below.

image

Cheers!

Hi,
I’m not sure about a custom dialog, It does sound possible.
One way I’d tackle this problem is by using a form instead.
You can use the System.Windows.Forms.Panel class and the System.Drawing.Color class. Here is an example of how you might do this:

import System.Drawing
import System.Windows.Forms

# Create a dictionary that maps colors to their values
color_values = {
    System.Drawing.Color.Red: 100,
    System.Drawing.Color.Green: 200,
    System.Drawing.Color.Blue: 300
}

# Create a panel
panel = System.Windows.Forms.Panel()

# Set the panel's layout to a vertical flow layout

panel.AutoScroll = True

# Iterate over the colors in the dictionary
for color, value in color_values.items():
    # Create a label for the color
    color_label = System.Windows.Forms.Label()
    color_label.BackColor = color
    color_label.Text = color.Name
    color_label.Width = 100
    color_label.Height = 50

    # Create a label for the value
    value_label = System.Windows.Forms.Label()
    value_label.Text = str(value)
    value_label.Width = 100
    value_label.Height = 50

    # Create a panel for the color and value labels
    color_value_panel = System.Windows.Forms.Panel()
    color_value_panel.Controls.Add(color_label)
    color_value_panel.Controls.Add(value_label)

    # Add the color-value panel to the main panel
    panel.Controls.Add(color_value_panel)

# Display the panel
form = System.Windows.Forms.Form()
form.Controls.Add(panel)
form.Show()
Print "Your nice custom form :)"

Hope that helps

Appreciated, I’m not familiar with the API so your suggestion gave me some pointer.
Currently, I’m using Eto.Drawing.Forms (cause its for C#).
For some reason, the label background color doesn’t show.

Hi,
Post your code here using the appropriate tag and make sure to point out which part of the code doesn’t work, I’ll gladly help you

Hello,

Here is my current code.

Dictionary<double, Color> colorDict = new Dictionary<double, Color>();

# def create_key,value_pairs_for_colorDict()

Panel panel = new Panel();
DynamicLayout panelLayout = new DynamicLayout();
panelLayout.BeginHorizontal();
foreach (var item in colorDict)
{
    var sysColor = item.Value;
    var etoColor = convertSysToEtoColor(sysColor); 

    Label valueLabel = new Label();
    valueLabel.Text = item.Key.ToString();
    valueLabel.Width = 100;
    valueLabel.Height = 50;

    Label colorLabel = new Label();
    colorLabel.BackgroundColor = etoColor;
    colorLabel.Width = 100;
    colorLabel.Height = 50;

    panelLayout.Add(colorLabel);
    panelLayout.Add(valueLabel);
}
panelLayout.EndHorizontal();
panel.Content = panelLayout;
Form form = new Form();
form.Content = panel;
form.Show();

#conversion between System.Drawing.Color to Eto.Drawing.Color
        private Eto.Drawing.Color convertSysToEtoColor(System.Drawing.Color color)
        {
            Eto.Drawing.Color result = new Eto.Drawing.Color();
            result.A = color.A;
            result.R = color.R;
            result.G = color.G;
            result.B = color.B;
            return result;
        }

Nvm, I found the solution, for some reason, Label.backgroundColor() only works when the Color object is initialized using Color.FromArgb().

            Panel panel = new Panel();
            DynamicLayout panelLayout = new DynamicLayout();
            panelLayout.BeginHorizontal();
            foreach (var item in colorDict)
            {
                var sysColor = item.Value;
                //var etoColor = convertSysToEtoColor(sysColor);

                Label valueLabel = new Label();
                valueLabel.Text = item.Key.ToString();
                valueLabel.Width = 100;
                valueLabel.Height = 50;

                Label colorLabel = new Label();
                colorLabel.BackgroundColor = Color.FromArgb(sysColor.R,
                    sysColor.G, sysColor.B, sysColor.A);
                //colorLabel.BackgroundColor = Colors.LightGreen;

                colorLabel.Width = 100;
                colorLabel.Height = 50;

                panelLayout.Add(colorLabel);
                panelLayout.Add(valueLabel);
            }
            panelLayout.EndHorizontal();
            panel.Content = panelLayout;
            Form form = new Form();
            form.Content = panel;
            form.Show();