示例#1
0
文件: widgets.py 项目: ice-zzz/gi
def textcb(recv, send, sig, data):
    sa = gi.TextField(handle=send)
    tsig = gi.TextFieldSignals(sig)
    if tsig == gi.TextFieldSignals.TextFieldDone:
        print("Received text signal:", tsig.name, "from field:", sa.Name(), "val:", data)
    else:
        print("Received text signal:", tsig.name, "from field:", sa.Name())
示例#2
0
文件: pygiv.py 项目: ice-zzz/gi
def PyObjUpdtView(val, vw, nm):
    """
    updates the given view widget for given value
    """
    if isinstance(val, Enum):
        if isinstance(vw, gi.ComboBox):
            svw = gi.ComboBox(vw)
            svw.SetCurVal(val.name)
        else:
            print("epygiv; Enum value: %s doesn't have ComboBox widget" % nm)
    elif isinstance(val, go.GoClass):
        pass
    elif isinstance(val, ClassViewObj):
        val.UpdateClassViewInline()
        val.UpdateClassView()
    elif isinstance(val, bool):
        if isinstance(vw, gi.CheckBox):
            svw = gi.CheckBox(vw)
            svw.SetChecked(val)
        else:
            print("epygiv; bool value: %s doesn't have CheckBox widget" % nm)
    elif isinstance(val, (int, float)):
        if isinstance(vw, gi.SpinBox):
            svw = gi.SpinBox(vw)
            svw.SetValue(val)
        else:
            print("epygiv; numerical value: %s doesn't have SpinBox widget" % nm)
    else:
        if isinstance(vw, gi.TextField):
            tvw = gi.TextField(vw)
            tvw.SetText(str(val))
        else:
            print("epygiv; object %s = %s doesn't have expected TextField widget" % (nm, val))
示例#3
0
def SetStrValCB(recv, send, sig, data):
    if sig != gi.TextFieldDone:
        return
    vw = gi.TextField(handle=send)
    nm = vw.Name()
    nms = nm.split(':')
    cv = classviews[nms[0]]
    setattr(cv.Class, nms[1], vw.Text())
示例#4
0
文件: widgets.py 项目: studiovc/gi
def textcb(recv, send, sig, data):
    sa = gi.TextField(handle=send)
    print("Received text signal:", sig, "from field:", sa.Name(), "val:", data)
示例#5
0
文件: widgets.py 项目: AoAnima/gi
def mainrun():
    width = 1024
    height = 768

    # turn these on to see a traces of various stages of processing..
    # gi.Update2DTrace = True
    # gi.Render2DTrace = True
    # gi.Layout2DTrace = True
    # ki.SignalTrace = True

    gi.SetAppName("widgets")
    gi.SetAppAbout(
        'This is a demo of the main widgets and general functionality of the <b>GoGi</b> graphical interface system, within the <b>GoKi</b> tree framework.  See <a href="https://github.com/goki">GoKi on GitHub</a>. <p>The <a href="https://github.com/goki/gi/blob/master/examples/widgets/README.md">README</a> page for this example app has lots of further info.</p>'
    )

    win = gi.NewWindow2D("gogi-widgets-demo", "GoGi Widgets Demo", width,
                         height, True)  # True = pixel sizes

    icnm = "widget-wedge-down"

    vp = win.WinViewport2D()
    updt = vp.UpdateStart()

    # style sheet
    css = ki.Props()
    bg = ki.Props()
    ki.SetPropStr(bg, "background-color", "#FFF0F0FF")
    ki.SetSubProps(css, "button", bg)
    cmbo = ki.Props()
    ki.SetPropStr(cmbo, "background-color", "#F0FFF0FF")
    ki.SetSubProps(css, "#combo", cmbo)
    hsld = ki.Props()
    ki.SetPropStr(hsld, "background-color", "#F0E0FFFF"),
    ki.SetSubProps(css, ".hslides", hsld)
    kbd = ki.Props()
    ki.SetPropStr(kbd, "color", "blue")
    ki.SetSubProps(css, "kbd", kbd)
    vp.CSS = css

    mfr = win.SetMainFrame()
    mfr.SetPropStr("spacing", "1ex")
    # mfr.SetProp("background-color", "linear-gradient(to top, red, lighter-80)")
    # mfr.SetProp("background-color", "linear-gradient(to right, red, orange, yellow, green, blue, indigo, violet)")
    # mfr.SetProp("background-color", "linear-gradient(to right, rgba(255,0,0,0), rgba(255,0,0,1))")
    # mfr.SetProp("background-color", "radial-gradient(red, lighter-80)")

    trow = gi.Layout(mfr.AddNewChild(gi.KiT_Layout(), "trow"))
    trow.Lay = gi.LayoutHoriz
    trow.SetStretchMaxWidth()

    # giedsc = gi.ActiveKeyMap().ChordForFun(gi.KeyFunGoGiEditor())
    # prsc = gi.ActiveKeyMap().ChordForFun(gi.KeyFunPrefs())

    giedsc = "Ctrl+Alt+I"
    prsc = "Alt+P"

    title = gi.Label(trow.AddNewChild(gi.KiT_Label(), "title"))
    title.Text = 'This is a <b>demonstration</b> of the <span style="color:red">various</span> <a href="https://github.com/goki/gi/gi">GoGi</a> <i>Widgets</i><br> <large>Shortcuts: <kbd>' + prsc + '</kbd> = Preferences, <kbd>' + giedsc + '</kbd> = Editor, <kbd>Ctrl/Cmd +/-</kbd> = zoom</large><br> See <a href="https://github.com/goki/gi/blob/master/examples/widgets/README.md">README</a> for detailed info and things to try.'
    title.SetPropStr("white-space", "normal")  # wrap
    title.SetPropStr(
        "text-align", "center"
    )  # note: this also sets horizontal-align, which controls the "box" that the text is rendered in..
    title.SetPropStr("vertical-align", "center")
    title.SetPropStr("font-family", "Times New Roman, serif")
    title.SetPropStr("font-size", "x-large")
    # # title.SetProp("letter-spacing", 2)
    # title.SetProp("line-height", 1.5)
    title.SetStretchMaxWidth()
    title.SetStretchMaxHeight()

    # Buttons

    mfr.AddNewChild(gi.KiT_Space(), "blspc")
    blrow = gi.Layout(mfr.AddNewChild(gi.KiT_Layout(), "blrow"))
    blab = gi.Label(blrow.AddNewChild(gi.KiT_Label(), "blab"))
    blab.Text = "Buttons:"
    blab.Selectable = True

    brow = gi.Layout(mfr.AddNewChild(gi.KiT_Layout(), "brow"))
    brow.Lay = gi.LayoutHoriz
    brow.SetPropStr("spacing", "2ex")

    brow.SetPropStr("horizontal-align", "left")
    # brow.SetProp("horizontal-align", gi.AlignJustify)
    brow.SetStretchMaxWidth()

    button1 = gi.Button(brow.AddNewChild(gi.KiT_Button(), "button1"))
    # button1.SetProp("#icon", ki.Props{ # note: must come before SetIcon
    # "width":  units.NewValue(1.5, units.Em),
    # "height": units.NewValue(1.5, units.Em),
    # })
    button1.Tooltip = "press this <i>button</i> to pop up a dialog box"

    button1.SetIcon(icnm)
    button1.ButtonSig.Connect(win.This(), button1cb)

    button2 = gi.Button(brow.AddNewChild(gi.KiT_Button(), "button2"))
    button2.SetText("Open GoGiEditor")
    # # button2.SetProp("background-color", "#EDF")
    button2.Tooltip = "This button will open the GoGi GUI editor where you can edit this very GUI and see it update dynamically as you change things"
    button2.ButtonSig.Connect(win.This(), button2cb)

    checkbox = gi.CheckBox(brow.AddNewChild(gi.KiT_CheckBox(), "checkbox"))
    checkbox.Text = "Toggle"

    # # note: receiver for menu items with shortcuts must be a Node2D or Window
    mb1 = gi.MenuButton(brow.AddNewChild(gi.KiT_MenuButton(), "menubutton1"))
    mb1.SetText("Menu Button")
    mb1.Menu.AddAction(
        gi.ActOpts(Label="Menu Item 1", Shortcut="Shift+Control+1", Data=1),
        win.This(), menu1cb)
    mi2 = mb1.Menu.AddAction(gi.ActOpts(Label="Menu Item 2", Data=2), go.nil(),
                             go.nil())

    mi2.Menu.AddAction(gi.ActOpts(Label="Sub Menu Item 2", Data=2.1),
                       win.This(), menu1cb)

    mb1.Menu.AddSeparator("sep1")

    mb1.Menu.AddAction(
        gi.ActOpts(Label="Menu Item 3", Shortcut="Control+3", Data=3),
        win.This(), menu1cb)

    # //////////////////////////////////////////
    #       Sliders

    mfr.AddNewChild(gi.KiT_Space(), "slspc")
    slrow = gi.Layout(mfr.AddNewChild(gi.KiT_Layout(), "slrow"))
    slab = gi.Label(slrow.AddNewChild(gi.KiT_Label(), "slab"))
    slab.Text = "Sliders:"

    srow = gi.Layout(mfr.AddNewChild(gi.KiT_Layout(), "srow"))
    srow.Lay = gi.LayoutHoriz
    srow.SetPropStr("spacing", "2ex")
    srow.SetPropStr("horizontal-align", "left")
    srow.SetStretchMaxWidth()

    slider1 = gi.Slider(srow.AddNewChild(gi.KiT_Slider(), "slider1"))
    slider1.Dim = gi.X
    slider1.Class = "hslides"
    slider1.Defaults()
    slider1.SetMinPrefWidth(units.NewValue(20, units.Em))
    slider1.SetMinPrefHeight(units.NewValue(2, units.Em))
    slider1.SetValue(0.5)
    slider1.Snap = True
    slider1.Tracking = True
    slider1.Icon = "widget-circlebutton-on"

    slider2 = gi.Slider(srow.AddNewChild(gi.KiT_Slider(), "slider2"))
    slider2.Dim = gi.Y
    slider2.Defaults()
    slider2.SetMinPrefHeight(units.NewValue(10, units.Em))
    slider2.SetMinPrefWidth(units.NewValue(1, units.Em))
    slider2.SetStretchMaxHeight()
    slider2.SetValue(0.5)

    slider1.SliderSig.Connect(win.This(), slidercb)
    slider2.SliderSig.Connect(win.This(), slidercb)

    scrollbar1 = gi.ScrollBar(
        srow.AddNewChild(gi.KiT_ScrollBar(), "scrollbar1"))
    scrollbar1.Dim = gi.X
    scrollbar1.Class = "hslides"
    scrollbar1.Defaults()
    scrollbar1.SetMinPrefWidth(units.NewValue(20, units.Em))
    scrollbar1.SetMinPrefHeight(units.NewValue(1, units.Em))
    scrollbar1.SetThumbValue(0.25)
    scrollbar1.SetValue(0.25)
    scrollbar1.Snap = True
    scrollbar1.Tracking = True
    scrollbar1.SliderSig.Connect(win.This(), scrollcb)

    scrollbar2 = gi.ScrollBar(
        srow.AddNewChild(gi.KiT_ScrollBar(), "scrollbar2"))
    scrollbar2.Dim = gi.Y
    scrollbar2.Defaults()
    scrollbar2.SetMinPrefHeight(units.NewValue(10, units.Em))
    scrollbar2.SetMinPrefWidth(units.NewValue(1, units.Em))
    scrollbar2.SetStretchMaxHeight()
    scrollbar2.SetThumbValue(0.1)
    scrollbar2.SetValue(0.5)
    scrollbar2.SliderSig.Connect(win.This(), scrollcb)

    # //////////////////////////////////////////
    # #      Text Widgets

    mfr.AddNewChild(gi.KiT_Space(), "tlspc")
    txlrow = gi.Layout(mfr.AddNewChild(gi.KiT_Layout(), "txlrow"))
    txlab = gi.Label(txlrow.AddNewChild(gi.KiT_Label(), "txlab"))
    txlab.Text = "Text Widgets:"
    txrow = gi.Layout(mfr.AddNewChild(gi.KiT_Layout(), "txrow"))
    txrow.Lay = gi.LayoutHoriz
    txrow.SetPropStr("spacing", "2ex")
    # # txrow.SetProp("horizontal-align", gi.AlignJustify)
    txrow.SetStretchMaxWidth()

    edit1 = gi.TextField(txrow.AddNewChild(gi.KiT_TextField(), "edit1"))
    edit1.Placeholder = "Enter text here..."
    # edit1.SetText("Edit this text")
    edit1.SetPropStr("min-width", "20em")
    # edit1.SetCompleter(edit1, Complete, CompleteEdit) # gets us word demo completion
    edit1.TextFieldSig.Connect(win.This(), textcb)
    # edit1.SetProp("inactive", True)

    sb = gi.SpinBox(txrow.AddNewChild(gi.KiT_SpinBox(), "spin"))
    sb.Defaults()
    sb.HasMin = True
    sb.Min = 0.0
    sb.SpinBoxSig.Connect(win.This(), spinboxcb)

    cb = gi.ComboBox(txrow.AddNewChild(gi.KiT_ComboBox(), "combo"))
    cbitms = go.Slice_string(["Item1", "AnotherItem", "Item3"])
    cb.ItemsFromStringList(cbitms, True, 50)
    cb.ComboSig.Connect(win.This(), combocb)

    # //////////////////////////////////////////
    # #      Main Menu

    appnm = gi.AppName()
    mmen = win.MainMenu
    mmen.ConfigMenus(go.Slice_string([appnm, "File", "Edit", "Window"]))

    amen = gi.Action(mmen.ChildByName(appnm, 0))
    # amen.Menu = make(gi.Menu, 0, 10)
    amen.Menu.AddAppMenu(win)

    # note: use KeyFunMenu* for standard shortcuts
    # Command in shortcuts is automatically translated into Control for
    # Linux, Windows or Meta for MacOS
    fmen = gi.Action(win.MainMenu.ChildByName("File", 0))
    fmen.Menu.AddAction(gi.ActOpts(Label="New", ShortcutKey=gi.KeyFunMenuNew),
                        win.This(), menu1cb)
    fmen.Menu.AddAction(
        gi.ActOpts(Label="Open", ShortcutKey=gi.KeyFunMenuOpen), win.This(),
        menu1cb)
    fmen.Menu.AddAction(
        gi.ActOpts(Label="Save", ShortcutKey=gi.KeyFunMenuSave), win.This(),
        menu1cb)
    fmen.Menu.AddAction(
        gi.ActOpts(Label="Save As..", ShortcutKey=gi.KeyFunMenuSaveAs),
        win.This(), menu1cb)
    fmen.Menu.AddSeparator("csep")
    fmen.Menu.AddAction(
        gi.ActOpts(Label="Close Window", ShortcutKey=gi.KeyFunMenuClose),
        win.This(), winclosecb)

    emen = gi.Action(win.MainMenu.ChildByName("Edit", 1))
    emen.Menu.AddCopyCutPaste(win)

    # inQuitPrompt = False
    # gi.SetQuitReqFunc(func() {
    # if inQuitPrompt {
    # return
    # }
    # inQuitPrompt = True
    # gi.PromptDialog(vp, gi.DlgOpts{Title: "Really Quit?",
    # Prompt: "Are you <i>sure</i> you want to quit?"}, True, True,
    # win.This(), func(recv, send ki.Ki, sig int64, data interface{}) {
    # if sig == int64(gi.DialogAccepted) {
    # gi.Quit()
    # } else {
    # inQuitPrompt = False
    # }
    # })
    # })

    # gi.SetQuitCleanFunc(func() {
    # print("Doing final Quit cleanup here..")
    # })

    # inClosePrompt = False
    # win.SetCloseReqFunc(func(w gi.Window) {
    # if inClosePrompt {
    # return
    # }
    # inClosePrompt = True
    # gi.PromptDialog(vp, gi.DlgOpts{Title: "Really Close Window?",
    # Prompt: "Are you <i>sure</i> you want to close the window?  This will Quit the App as well."}, True, True,
    # win.This(), func(recv, send ki.Ki, sig int64, data interface{}) {
    # if sig == int64(gi.DialogAccepted) {
    # gi.Quit()
    # } else {
    # inClosePrompt = False
    # }
    # })
    # })

    # win.SetCloseCleanFunc(func(w gi.Window) {
    # print("Doing final Close cleanup here..")
    # })

    win.MainMenuUpdated()
    vp.UpdateEndNoSig(updt)
    win.GoStartEventLoop()