I want remember the position of the panel,Who can help me

I want the position of the panel can remember the position of the last move. The next time it appears in the last position
The position can also be memorized when the panel exits directly

# -*- coding: utf-8 -*-  
import Eto as e
import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc
class aa(e.Forms.Dialog):
    def __init__(self):
        self.Title = '【纵 横】'
#        第1个框
        layout1 = e.Forms.DynamicLayout()
#        按钮1
        def OnLine1(sender,e):
#            self.Visible = False
            self.cl1('A1')
            rs.Command('_Lock')
#            self.Visible = True
        layout1.AddRow(e.Forms.Button(Text='锁 定',Height=25,ID='A1',BackgroundColor=e.Drawing.Color(123,123,1) ,click = OnLine1))
#        按钮2
        def OnLine2(sender,e):
#            self.Visible = False
            self.cl1('A2')
            rs.Command('_UnlockSelected')
#            self.Visible = True
        layout1.AddRow(e.Forms.Button(Text='解锁选取',Height=25,ID='A2',click = OnLine2))
        
#        按钮3
        def OnLine3(sender,e):
#            self.Visible = False
            self.cl1('A3')
            rs.Command('_Unlock')
#            self.Visible = True
        layout1.AddRow(e.Forms.Button(Text='解 锁',Height=25,ID='A3',click = OnLine3))
#         第2个框
        layout2 = e.Forms.DynamicLayout()
#        按钮1
        def OnLine1(sender,e):
#            self.Visible = False
            self.cl1('B1')
            rs.Command('_InterpcrvOnSrf')
#            self.Visible = True
        layout2.AddRow(e.Forms.Button(Text='曲面上曲线',Height=25,ID='B1',BackgroundColor=e.Drawing.Color(255,1,0) ,click = OnLine1))
#        按钮2
        def OnLine2(sender,e):
#            self.Visible = False
            self.cl1('B2')
            rs.Command('_Sweep1')
#            self.Visible = True
        layout2.AddRow(e.Forms.Button(Text='单 轨',Height=25,ID='B2',click = OnLine2))
        
#        按钮3
        def OnLine3(sender,e):
#            self.Visible = False
            self.cl1('B3')
            rs.Command('_Sweep2')
#            self.Visible = True
        layout2.AddRow(e.Forms.Button(Text='双 轨',Height=25,ID='B3',click = OnLine3))
        
        
        layout = e.Forms.DynamicLayout()
        layout.AddRow(layout1,layout2)
        self.AbortButton = e.Forms.Button(Text = 'Esc',Height=25,click = self.cl2,BackgroundColor=e.Drawing.Color(1,1,0))
#        self.AbortButton.Click += self.OnCloseButtonClick

        layout2.AddRow(self.AbortButton)
        try:
            layout.FindChild(sc.doc.Notes).Focus()
        except:
            pass
        self.Content = layout
        
        
        
    def cl1(self,bid):
        sc.doc.Notes=bid
        self.Close()
    def cl2(self,sender,e):
        self.Close()
    def jj(self,sender,e):
        self.Close()
a = aa()
rc = a.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)

thank you very much

but There’s another question
How to set the button focus? The second time you open the panel, you will focus on the button you clicked last time, and there will be ants on the button

http://pages.picoe.ca/docs/api/search.html?SearchText=focus

image
you have to add something like:

sc.sticky[‘prev_button’] = sender

in each of your def OnLine

after that you can have “sc.sticky[‘prev_button’].focus()” in the begining.

Thank you very much. Is it possible to repeat the last button command by hitting the space bar

If it’s hard to achieve, you can’t do it

# -*- coding: utf-8 -*-
import Eto as e
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

command_name = ''

# button color
default_color = e.Drawing.Color(0, 0, 0, 0)
color_a = e.Drawing.Color(0.682353, 0.772549, 0.901961)
color_b = e.Drawing.Color(0.54902, 0.870588, 0.760784)
color_exit = e.Drawing.Color(0.921569, 0.882353, 0.486275)
prev_color = e.Drawing.Color(0.921569, 0.513725, 0.513725)

# button dict list
column_dict_list = [[{'text': '锁 定', 'cmd': '_Lock', 'color': color_a},
                     {'text': '解锁选取', 'cmd': '_UnlockSelected', 'color': default_color},
                     {'text': '解 锁', 'cmd': '_Unlock', 'color': default_color}],
                    [{'text': '曲面上曲线', 'cmd': '_InterpcrvOnSrf', 'color': color_b},
                     {'text': '单 轨', 'cmd': '_Sweep1', 'color': default_color},
                     {'text': '双 轨', 'cmd': '_Sweep2', 'color': default_color},
                     {'text': '退 出', 'cmd': 'exit', 'color': color_exit}]]


class CustomDialog(e.Forms.Dialog):

    def __init__(self):

        def define_button(_i, _j):
            item = column_dict_list[_i][_j]
            btn = e.Forms.Button(Text=item['text'], Height=25, ID=item['cmd'], BackgroundColor=item['color'],
                                 click=OnButtonPress)
            return btn

        def OnButtonPress(sender, e):
            global command_name  # global variable
            command_name = sender.ID  # ID = command name
            sc.sticky['prev'] = command_name  # record command name to rhino sticky
            self.Close()  # close ETO dialog

        # ETO layout
        layout = e.Forms.DynamicLayout()
        layout.BeginHorizontal()
        for i in range(len(column_dict_list)):
            layout.BeginVertical()
            for j in range(len(column_dict_list[i])):
                layout.Add(define_button(i, j))
            layout.EndVertical()
        self.Content = layout

        # load previous button
        if 'prev' in sc.sticky:
            prev_command = sc.sticky['prev']  # load recorded command name
            last_button = layout.FindChild(prev_command)  # find the button
            last_button.BackgroundColor = prev_color  # change background color
            last_button.Focus()  # set focus to button


dialog = CustomDialog()

# load previous dialog position
if 'pos' in sc.sticky:
    dialog.Location = sc.sticky['pos']

dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)

if command_name != 'exit':
    rs.Command(command_name)

# record current dialog position
sc.sticky['pos'] = dialog.Location

1 Like

焦点其实在的,你空格就能用上次按过的按钮,但是虚线不行,可能是BUG
虚线只有首次运行ETO或者上次的ETO窗体先关闭一次,第二次才能正确显示虚线
我研究了好久觉得这多半就是ETO自己的问题。回头我再去发帖问问。

不影响使用,现在用红色显示上次用过的,比虚线清楚多了。

至于右键重复命令,暂时没搞,也是回头等我有时间了再去发帖问问。
现在不管虚线是不是显示,焦点其实都是正确的。你要重复也就是从一下空格变成两下空格,暂时凑合这么用吧。
正如我说的,一开始方法选错了,选择python本来就不合适

代码全部给你重写了。本来那代码根本没眼看。200块钱你不能指望太多,只能搞到这种稀烂的质量。
这个世界是守恒的,你花多少钱就能有多少回报,没啥捷径可选。

1 Like

The program experience you gave was very good

Thanks again for your patience and selfless help like God

和原版相比少了一个效果, 过程中 按ESC 键可以 直接 中断退出结束面板,其他方面感觉都很好
Compared with the original version, it has one less effect. Pressing ESC during the process can directly interrupt and exit the end panel

1 Like

very nice , very beautiful
Be worthy of being the moderator不愧为版主,暂时完美流畅运行
我以后有需求就找你编写任何程序。可以支付一定报酬。因为你很热情,耐心
I will ask you for any program I need to write in the future. I can pay you a certain amount.
Because you are very enthusiastic and patient

问一个低级的问题,有什么方法可视化观察和控制或者转换颜色 e.Drawing.Color(0.682353, 0.772549, 0.901961)这个颜色值怎么来的
Ask a low-level question, what are the methods to visually observe and control or change colors
e.Drawing.Color(0.682353, 0.772549, 0.901961)

你可以查阅API文档
下面给你详细介绍方法,下次如果还有这类问题,那就不是low而是懒了,你应该明白这个道理。

此页面你应该已经知道,第一句话就是明确ETO是开源的,并给了github链接

点进去该链接


找到api文档,再点进去
代码是e.Drawing.Color,不管是谁写的,至少别人帮你明确了位置
根据这个位置查找左侧

看参数的样子,找到这一条
image

image

点进后里面明确说了他是0-1之间,并且告诉了你RGB
也就是说只需要将本来0-255的转化为0-1即可
数量不多你就手工转,数量多可以借助GH


右键panel后copy data即可直接黏贴到代码内