Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5938

Convert to a flat transparent form

$
0
0

I’m trying to flatten the transparent form of the class.
But I can’t figure out what argument “control” is passing, and the editor is giving me an error about “control”

@michaelvollrath Perhaps Sir There is something you should know, asking for your help

import Rhino
import Eto
import Eto.Forms as ef
import Eto.Drawing as ed
Eto_w = 300
Eto_h = 300
class SampleTransparentEtoForm(Eto.Forms.Form):
    def __init__(self):
        super().__init__()
        self.WindowStyle = Eto.Forms.WindowStyle.NONE
        self.Styles.Add[Eto.Forms.Panel]("transparent", self.TransparentFormStyler)
        self.Style = "transparent"
        self.AutoSize = False
        self.Resizable = True
        self.TopMost = True
        self.ShowActivated = False
        self.Size = Eto.Drawing.Size(Eto_w, Eto_w)
        self.Padding = Eto.Drawing.Padding(0)
        self.MovableByWindowBackground = True
        self.Location = ed.PointF(300,300)

        self.bu = ef.Button()

        self.layout_bi = ef.DynamicLayout()
        self.layout_bi.AddRow(self.bu)

        self.layout = Eto.Forms.PixelLayout()
        self.layout.BackgroundColor = ed.Color(0,0,0,0.009)
        self.layout.Add(self.layout_bi,12,12)
        self.Content = self.layout

    def TransparentFormStyler(self, control):
        self.BackgroundColor = Eto.Drawing.Colors.Transparent
        window = control.ControlObject
        if hasattr(window, "AllowsTransparency"):
            window.AllowsTransparency = True
        if hasattr(window, "Background"):
            brush = window.Background.Clone()
            brush.Opacity = 0.5  # win
            window.Background = brush
        else:
            color = window.BackgroundColor
            window.BackgroundColor = color.FromRgba(0, 0, 0, 25)  # mac

def EstablishForm():
    form = SampleTransparentEtoForm()
    form.Owner = Rhino.UI.RhinoEtoApp.MainWindow
    form.Show()

if __name__ == "__main__":
    EstablishForm()

    def TransparentFormStyler(form,control):
        form.BackgroundColor = Eto.Drawing.Colors.Transparent
        window = control.ControlObject
        if hasattr(window, "AllowsTransparency"):
            window.AllowsTransparency = True
        if hasattr(window, "Background"):
            brush = window.Background.Clone()
            brush.Opacity = 0.6
            window.Background = brush
        else:
            color = window.BackgroundColor
            window.BackgroundColor = color.FromRgba(0, 0, 0, 25)

    form = ef.Form()

    form.Width = Eto_w
    form.Height = Eto_h
    form.Topmost = True
    form.Style(TransparentFormStyler(form,control))
    form.Style = "transparent"

    form.Show()

Report an error:

Traceback (most recent call last):
  File "file:///D:/py/Rhino/Eto/%E7%B1%BB%E7%9A%84%E9%80%8F%E6%98%8E%EF%BC%8C%E7%BB%98%E5%88%B6%E6%88%90%E9%9D%9E%E7%B1%BB%E7%9A%84%E9%80%8F%E6%98%8E.py", line 71, in <module>
NameError: name 'control' is not defined

9 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 5938

Trending Articles