Jump to content

Simple dialog with wxPython in AutoCAD


Recommended Posts

Posted
import traceback
import wx
from pyrx import Ap


class TestUIDialog(wx.Dialog):

  def __init__(self, parent=None):
    style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER
    super().__init__(
        parent,
        title="PyRx wxPython Control Check",
        size=(340, 240),
        style=style,
        name="PyRxTestUIDialog",
    )

    # Create a panel, a sizer and some controls
    panel = wx.Panel(self)
    sizer = wx.BoxSizer(wx.VERTICAL)

    self.cb = wx.CheckBox(panel, label="Modern Visual Styles Active")
    self.cb.SetValue(True)

    self.combo = wx.ComboBox(
        panel,
        choices=["Option A", "Option B"],
        value="Option A",
        style=wx.CB_READONLY,
    )
    
    # Bind to an event 
    self.combo.Bind(wx.EVT_COMBOBOX, self.on_combo_select)

    self.gauge = wx.Gauge(panel, range=100)
    self.gauge.SetValue(70)

    self.txt = wx.TextCtrl(panel, value="Text input test")
    self.btn = wx.Button(panel, wx.ID_OK, label="Close Test")

    # add the controls to the sizer
    for ctrl in (self.cb, self.combo, self.gauge, self.txt, self.btn):
      sizer.Add(ctrl, 0, wx.ALL | wx.EXPAND, 8)

    # add the sizer to the panel
    panel.SetSizer(sizer)

  def on_combo_select(self, event):
    print("Selected:", self.combo.GetValue())
    event.Skip()


@Ap.Command()
def testui():
  try:
    with TestUIDialog() as dlg:
      res = Ap.Application.showModalDialog(dlg)
      print(res)
  except Exception as err:
    traceback.print_exception(err)

 

gui.png.a886c0ca4e5d04e9565e754c31a64f7f.png

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...