6 from . import table, area
7 from . import basic, input, button
8 from . import pguglobals
10 class Dialog(table.Table):
11 """A dialog window with a title bar and an "close" button on the bar.
14 title = gui.Label("My Title")
15 main = gui.Container()
16 #add stuff to the container...
18 d = gui.Dialog(title,main)
22 def __init__(self,title,main,**params):
23 """Dialog constructor.
26 title -- title widget, usually a label
27 main -- main widget, usually a container
30 params.setdefault('cls','dialog')
31 table.Table.__init__(self,**params)
35 self.td(title,align=-1,cls=self.cls+'.bar')
36 clos = button.Icon(self.cls+".bar.close")
37 clos.connect(CLICK,self.close,None)
38 self.td(clos,align=1,cls=self.cls+'.bar')
41 self.td(main,colspan=2,cls=self.cls+".main")
47 # t = table.Table(cls=self.cls+".bar")
50 # clos = button.Icon(self.cls+".bar.close")
52 # clos.connect(CLICK,self.close,None)
55 # main.rect.w,main.rect.h = main.resize()
56 # clos.rect.w,clos.rect.h = clos.resize()
57 # title.container.style.width = main.rect.w - clos.rect.w
60 # self.td(main,cls=self.cls+".main")
64 class FileDialog(Dialog):
65 """A file picker dialog window."""
67 def __init__(self, title_txt="File Browser", button_txt="Okay", cls="dialog", path=None):
68 """FileDialog constructor.
71 title_txt -- title text
72 button_txt -- button text
78 if not path: self.curdir = os.getcwd()
79 else: self.curdir = path
80 self.dir_img = basic.Image(
81 pguglobals.app.theme.get(cls1+".folder", "", 'image'))
82 td_style = {'padding_left': 4,
86 self.title = basic.Label(title_txt, cls=cls+".title.label")
87 self.body = table.Table()
88 self.list = area.List(width=350, height=150)
89 self.input_dir = input.Input()
90 self.input_file = input.Input()
92 self.button_ok = button.Button(button_txt)
94 self.body.td(basic.Label("Folder"), style=td_style, align=-1)
95 self.body.td(self.input_dir, style=td_style)
97 self.body.td(self.list, colspan=3, style=td_style)
98 self.list.connect(CHANGE, self._item_select_changed_, None)
99 self.button_ok.connect(CLICK, self._button_okay_clicked_, None)
101 self.body.td(basic.Label("File"), style=td_style, align=-1)
102 self.body.td(self.input_file, style=td_style)
103 self.body.td(self.button_ok, style=td_style)
105 Dialog.__init__(self, self.title, self.body)
107 def _list_dir_(self):
108 self.input_dir.value = self.curdir
109 self.input_dir.pos = len(self.curdir)
110 self.input_dir.vpos = 0
114 for i in os.listdir(self.curdir):
115 if os.path.isdir(os.path.join(self.curdir, i)): dirs.append(i)
116 else: files.append(i)
118 self.input_file.value = "Opps! no access"
119 #if '..' not in dirs: dirs.append('..')
125 #item = ListItem(image=self.dir_img, text=i, value=i)
126 self.list.add(i,image=self.dir_img,value=i)
128 #item = ListItem(image=None, text=i, value=i)
129 self.list.add(i,value=i)
131 self.list.set_vertical_scroll(0)
132 #self.list.repaintall()
135 def _item_select_changed_(self, arg):
136 self.input_file.value = self.list.value
137 fname = os.path.abspath(os.path.join(self.curdir, self.input_file.value))
138 if os.path.isdir(fname):
139 self.input_file.value = ""
145 def _button_okay_clicked_(self, arg):
146 if self.input_dir.value != self.curdir:
147 if os.path.isdir(self.input_dir.value):
148 self.input_file.value = ""
149 self.curdir = os.path.abspath(self.input_dir.value)
153 self.value = os.path.join(self.curdir, self.input_file.value)