###################################################################### # Copyright (c) 2007, Petteri Aimonen # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # * Redistributions of source code must retain the above copyright # notice and this list of conditions. # * Redistributions in binary form must reproduce the above copyright # notice and this list of conditions in the documentation and/or other # materials provided with the distribution. '''Gui configuration dialog for basic settings''' import wx import wx.lib.filebrowsebutton as filebrowse from pymisc import _ import settings class ConfigDialog(wx.Dialog): def __init__(self, title = _('File paths')): wx.Dialog.__init__(self, None, title = title, style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER) self.afeedsel = filebrowse.DirBrowseButton(self, labelText = _('Per-animal data file directory:')) self.gfeedsel = filebrowse.FileBrowseButton(self, labelText = _('Groupfeed data file location:')) self.okbutton = wx.Button(self, wx.ID_OK) self.sizer = wx.BoxSizer(wx.VERTICAL) self.sizer.Add(self.afeedsel, flag = wx.EXPAND | wx.LEFT, border = 5) self.sizer.Add(self.gfeedsel, flag = wx.EXPAND | wx.LEFT, border = 5) self.sizer.Add(wx.StaticLine(self), flag = wx.EXPAND | wx.ALL, border = 5) self.sizer.Add(self.okbutton, border = 5, flag = wx.ALIGN_RIGHT | wx.RIGHT | wx.BOTTOM) self.SetAutoLayout(True) self.SetSizer(self.sizer) self.Layout() w, h = self.GetBestSize() self.SetSize((600, h)) self.SetMinSize((w, h)) self.SetMaxSize((-1, h)) def do_guiconfig(): dlg = ConfigDialog() dlg.ShowModal() afeeddir = dlg.afeedsel.GetValue() gfeedfile = dlg.gfeedsel.GetValue() settings.parser.set("DEFAULT", "animalfeed_datapath", afeeddir) settings.parser.set("DEFAULT", "groupfeed_datafile", gfeedfile) settings.saveconfig() if __name__ == '__main__': print "Unit testing" class MyApp(wx.App): def OnInit(self): dlg = ConfigDialog() dlg.ShowModal() raise SystemExit return True app = MyApp(0) app.MainLoop()