7 import basic
, input, button
10 class Dialog(table
.Table
):
11 """A dialog window with a title bar and an "close" button on the bar.
13 <pre>Dialog(title,main)</pre>
16 <dt>title<dd>title widget, usually a label
17 <dt>main<dd>main widget, usually a container
20 <strong>Example</strong>
22 title = gui.Label("My Title")
23 main = gui.Container()
24 #add stuff to the container...
26 d = gui.Dialog(title,main)
30 def __init__(self
,title
,main
,**params
):
31 params
.setdefault('cls','dialog')
32 table
.Table
.__init
__(self
,**params
)
36 self
.td(title
,align
=-1,cls
=self
.cls
+'.bar')
37 clos
= button
.Icon(self
.cls
+".bar.close")
38 clos
.connect(CLICK
,self
.close
,None)
39 self
.td(clos
,align
=1,cls
=self
.cls
+'.bar')
42 self
.td(main
,colspan
=2,cls
=self
.cls
+".main")
48 # t = table.Table(cls=self.cls+".bar")
51 # clos = button.Icon(self.cls+".bar.close")
53 # clos.connect(CLICK,self.close,None)
56 # main.rect.w,main.rect.h = main.resize()
57 # clos.rect.w,clos.rect.h = clos.resize()
58 # title.container.style.width = main.rect.w - clos.rect.w
61 # self.td(main,cls=self.cls+".main")
65 class FileDialog(Dialog
):
66 """A file picker dialog window.
68 <pre>FileDialog()</pre>
69 <p>Some optional parameters:</p>
71 <dt>title_txt<dd>title text
72 <dt>button_txt<dd>button text
73 <dt>path<dd>initial path
77 def __init__(self
, title_txt
="File Browser", button_txt
="Okay", cls
="dialog", folderText
= "Folder", fileText
= "File", path
=None, customFont
= None, showCurDir
= True, customWidth
= 350, customHeight
= 150):
79 self
.customFont
= customFont
80 self
.showCurDir
= showCurDir
82 if not path
: self
.curdir
= os
.getcwd()
83 else: self
.curdir
= path
84 self
.dir_img
= basic
.Image(
85 pguglobals
.app
.theme
.get(cls1
+'.folder', '', 'image'))
86 td_style
= {'padding_left': 4,
90 self
.title
= basic
.Label(title_txt
, cls
=cls
+".title.label")
91 self
.body
= table
.Table()
92 self
.list = area
.List(width
=customWidth
, height
=customHeight
)
93 self
.input_dir
= input.Input(customFont
= self
.customFont
)
94 self
.input_file
= input.Input(customFont
= self
.customFont
)
96 self
.button_ok
= button
.Button(button_txt
)
99 self
.body
.td(basic
.Label(folderText
), style
=td_style
, align
=-1)
100 self
.body
.td(self
.input_dir
, style
=td_style
)
102 self
.body
.td(self
.list, colspan
=3, style
=td_style
)
103 self
.list.connect(CHANGE
, self
._item
_select
_changed
_, None)
104 self
.button_ok
.connect(CLICK
, self
._button
_okay
_clicked
_, None)
106 self
.body
.td(basic
.Label(fileText
), style
=td_style
, align
=-1)
107 self
.body
.td(self
.input_file
, style
=td_style
)
108 self
.body
.td(self
.button_ok
, style
=td_style
)
110 Dialog
.__init
__(self
, self
.title
, self
.body
)
112 def _list_dir_(self
):
113 self
.input_dir
.value
= self
.curdir
114 self
.input_dir
.pos
= len(self
.curdir
)
115 self
.input_dir
.vpos
= 0
119 for i
in os
.listdir(self
.curdir
):
120 if os
.path
.isdir(os
.path
.join(self
.curdir
, i
)): dirs
.append(i
)
121 else: files
.append(i
)
123 self
.input_file
.value
= "Opps! no access"
124 #if '..' not in dirs: dirs.append('..')
130 #item = ListItem(image=self.dir_img, text=i, value=i)
131 if self
.customFont
== None :
132 self
.list.add(i
,image
=self
.dir_img
,value
=i
)
134 label
= basic
.Label(i
,font
= self
.customFont
)
135 self
.list.add(label
,image
=self
.dir_img
,value
=i
)
137 #item = ListItem(image=None, text=i, value=i)
138 if self
.customFont
== None :
139 self
.list.add(i
,value
=i
)
141 label
= basic
.Label(i
,font
= self
.customFont
)
142 self
.list.add(label
,value
=i
)
144 self
.list.set_vertical_scroll(0)
145 #self.list.repaintall()
148 def _item_select_changed_(self
, arg
):
149 self
.input_file
.value
= self
.list.value
150 fname
= os
.path
.abspath(os
.path
.join(self
.curdir
, self
.input_file
.value
))
151 if os
.path
.isdir(fname
):
152 self
.input_file
.value
= ""
158 def _button_okay_clicked_(self
, arg
):
159 if self
.input_dir
.value
!= self
.curdir
:
160 if os
.path
.isdir(self
.input_dir
.value
):
161 self
.input_file
.value
= ""
162 self
.curdir
= os
.path
.abspath(self
.input_dir
.value
)
166 self
.value
= os
.path
.join(self
.curdir
, self
.input_file
.value
)