import ezPyJFxLib as ez
def onAbout(event):
v = ez.YesNoDialog("Global", "Dialog")
if v: ez.AlertDialog("Result", "Yes")
else: ez.AlertDialog("Result", "No")
def onBrowse(event):
f = ez.FileOpenDialog(None)
ctrl = ez.GetControl('text')
if ctrl and f: ctrl.SetText(f.getPath())
def onExit(event):
from javafx.application import Platform
Platform.exit()
#from java.lang import System
#System.exit(0)
#self.Close()
def onClose(event):
global appWin
v = ez.YesNoDialog("Alert", "Do you want to quit ?", appWin.GetStage())
if not v: event.consume()
def onChoice(event):
c = ez.GetControl('choice')
t = ez.GetControl('texttool')
if c and t: t.SetText( c.GetSelectedItem() )
def onCombo(event):
c = ez.GetControl('combo')
t = ez.GetControl('texttool')
if c and t: t.SetText( c.GetSelectedItem() )
def onListBox(event):
c = ez.GetControl('listbox')
t = ez.GetControl('texttool')
if c and t: t.SetText( c.GetSelectedItem() )
def onTreeView(event):
c = ez.GetControl('tree')
t = ez.GetControl('texttool')
print(c.GetSelectedItem())
if c and t: t.SetText( c.GetSelectedItemPath("-") )
def onTableView(event):
print('onTableView')
c = ez.GetControl('table')
for item in c.GetSelectedItems():
print(item)
def onToggle(newvalue):
print("toggle")
def onCheck(newvalue):
print("toggle")
def threadHandler():
import time
p = ez.GetControl('progress')
for i in range(100):
ez.RunLater(None,lambda : p.SetValue(i))
time.sleep(0.1)
def onCreated():
table = ez.GetControl('table')
table.EnableMultiSelection()
table.AddRow(["Tom", "and", "Doe"])
table.AddRow(["Jane", "and", "Deer"])
tree = ez.GetControl('tree')
item = tree.AddRootItem("Item1")
tree.AddItem("Item1-1",item)
tree.AddItem("Item1-2",item)
item = tree.AddRootItem("Item2")
tree.AddItem("Item2-1",item)
tree.AddItem("Item2-2",item)
ez.StartThread(threadHandler,None)
#ControlTable()
def onRun(event):
text = ez.GetControl('text')
print(text.GetText())
if text:
rv, out = ez.Execute(text.GetText())
textarea = ez.GetControl('textarea')
textarea.SetText(str(rv) + '\n' + out)
app_mainmenu = [
{ 'name' : "File",
'item' : [
{ 'name' : "Exit" , 'item' : onExit, 'image' : 'exit' },
{ 'name' : "-" },
{ 'name' : "About", 'item' : onAbout, 'image' : 'help' } ]
}, { 'name' : "Help",
'item' : [
{ 'name' : "About", 'item' : onAbout, 'image' : 'help' } ]
}]
app_tool = [[
{ "name" : "Label", "label" : "Address:", "menu" : app_mainmenu },
{ "name" : "ChoiceBox", "key" : "choice", 'handler' : onChoice, 'items' : ["apple","orange"] },
{ "name" : "ComboBox", "key" : "combo", 'handler' : onCombo, 'items' : ["apple","orange"] },
{ "name" : "TextField", "key" : "texttool", "width" : 100 },
{ "name" : "ToggleButton", "label" : "Toggle", "handler" : onToggle, "tooltip" : "Toggle", 'image' : 'icon/folder512.png', 'size' : 16 },
{ "name" : "CheckBox", "label" : "Check", "handler" : onCheck, "tooltip" : "Check", 'image' : 'icon/folder512.png', 'size' : 16 },
],[
{ "name" : "Button", "label" : "Exit", "handler" : onExit, "tooltip" : "Quit", 'image' : 'icon/folder512.png', 'size' : 16, 'icon_top' : True },
]]
app_status = [
{ "name" : "ProgressBar", 'key' : 'progress' },
{ "name" : "<>"},
]
tab1 = [[ { "name" : "TreeView", "key" : "tree", 'handler' : onTreeView,"expand" : True },
{ "expand" : True }, ]]
tab2 = [[ { "name" : "ListBox", "key" : "listbox", 'handler' : onListBox, 'items' : ["apple","orange"], 'expand' : True },
{ "expand" : True }, ]]
tab3 = [[ { "name" : "ScrollImageView", 'file' : "./Lenna.png", 'bindwidth' : True, 'bindheight' : True, 'expand' : True },
{ "expand" : True }, ]]
tab4 = [[ { "name" : "TableView", 'key':'table', 'columns' : ['First','Mid','Last'], 'rwidths' : [100,50,100], 'aligns':[1,0,-1], 'handler':onTableView, 'expand' : True },
{ "expand" : True }, ]]
split1 = [[
{ "name" : "TabPane", "labels" : [ "Tree", "List", "Image", "Table" ], "items" : [ tab1, tab2, tab3, tab4 ], "expand" : True },
{ "expand" : True }, ]]
split2 = [[ { "name" : "TextArea", 'key' : 'textarea', "expand" : True },
{ "expand" : True }, ]]
app_content = [ # vbox
[ # hbox
{ "name" : "Label", "label" : "Address:", "menu" : app_mainmenu },
{ "name" : "TextField", "key" : "text", "expand" : True, "menu" : app_mainmenu },
{ "name" : "Button", "label" : "Browse", "tooltip" : "Open File", "handler" : onBrowse },
{ "name" : "Button", "label" : "Run", "handler" : onRun, "menu" : app_mainmenu },
],
[ # hbox
{ "name" : "HSplit", "items" : [ split1, split2 ] , "first" : 0.5, "expand" : True},
{ "expand" : True },
],
]
if __name__ == "__main__":
global appWin
appWin = ez.Window()
appWin.SetTitle("ezPyJFX")
appWin.SetSize(640,400)
appWin.SetIcon("./Lenna.png")
appWin.SetMenuBar(app_mainmenu)
appWin.SetToolBar(app_tool)
appWin.SetStatusBar(app_status)
appWin.SetContent(app_content)
appWin.SetCreatedHandler(onCreated)
appWin.SetCloseHandler(onClose)
appWin.Run()
댓글 없음:
댓글 쓰기