1.1 --- a/main.py Thu Sep 24 22:54:44 2009 +0300
1.2 +++ b/main.py Sun Sep 27 18:00:08 2009 +0200
1.3 @@ -24,6 +24,7 @@
1.4 import EXIF
1.5
1.6 from picture_list import indexed_files
1.7 +from options import Options, deskframe_options
1.8
1.9 class BorderLessWindow(wx.Frame):
1.10 """A window with no title and only a resize border. Moving is done
1.11 @@ -110,65 +111,6 @@
1.12 grid.SetColSize(1,grid.GetColSize(0))
1.13 grid.Show()
1.14
1.15 -class AddDirectory(wx.Dialog):
1.16 - def __init__(self,parent,id,dir_list) :
1.17 - wx.Dialog.__init__(self,parent,id,title='Add directory',
1.18 - style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER)
1.19 -
1.20 - ## get IDs for all controls
1.21 - self.ID_ADD = wx.NewId()
1.22 - self.ID_DEL = wx.NewId()
1.23 -
1.24 - wx.EVT_BUTTON(self, self.ID_DEL, self.OnDel)
1.25 - wx.EVT_BUTTON(self, self.ID_ADD, self.OnAdd)
1.26 -
1.27 - panel = wx.Panel(self,wx.ID_ANY)
1.28 - box = wx.StaticBox(panel,label='Search Path')
1.29 - self.list = wx.ListBox(panel,wx.ID_ANY,choices=dir_list,
1.30 - style=wx.LB_SINGLE | wx.LB_SORT )
1.31 - ok = wx.Button(panel, wx.ID_OK)
1.32 - cancel = wx.Button(panel, wx.ID_CANCEL)
1.33 - add = wx.Button(panel, self.ID_ADD,label='&Add ...')
1.34 - delete = wx.Button(panel, self.ID_DEL,label='&Delete')
1.35 -
1.36 - path_strip = wx.BoxSizer(wx.HORIZONTAL)
1.37 - path_strip.Add(add,0, wx.ALL|wx.EXPAND, 5)
1.38 - path_strip.Add(delete,0, wx.ALL|wx.EXPAND, 5)
1.39 -
1.40 - path = wx.StaticBoxSizer(box,wx.VERTICAL)
1.41 - path.Add(self.list , 1, wx.ALL|wx.EXPAND, 5)
1.42 - path.Add(path_strip , 0, wx.ALL, 5)
1.43 -
1.44 - bottom_strip = wx.BoxSizer(wx.HORIZONTAL)
1.45 - bottom_strip.Add(ok,0, wx.ALL|wx.EXPAND, 5)
1.46 - bottom_strip.Add(cancel,0, wx.ALL|wx.EXPAND, 5)
1.47 -
1.48 - toplevel = wx.BoxSizer(wx.VERTICAL)
1.49 - toplevel.Add(path,1,wx.ALL|wx.EXPAND, 5)
1.50 - toplevel.Add(bottom_strip,0,wx.ALL, 5)
1.51 - panel.SetSizer(toplevel)
1.52 - toplevel.Fit(panel)
1.53 -
1.54 - def OnDel(self,event):
1.55 - sel = self.list.GetSelection()
1.56 - if sel != wx.NOT_FOUND :
1.57 - ans = wx.MessageDialog(self,
1.58 - message='Delete "%s"?'
1.59 - % self.list.GetString(sel),
1.60 - ).ShowModal()
1.61 - if ans == wx.ID_OK :
1.62 - self.list.Delete(sel)
1.63 -
1.64 - def OnAdd(self,event):
1.65 - dir_dial = wx.DirDialog(self,
1.66 - style=wx.DD_DEFAULT_STYLE,
1.67 - message='Select a directory to add')
1.68 - if dir_dial.ShowModal() == wx.ID_OK :
1.69 - self.list.Append(dir_dial.GetPath())
1.70 -
1.71 - def GetStrings(self) :
1.72 - return self.list.GetStrings()
1.73 -
1.74
1.75 class Canvas(BorderLessWindow):
1.76 def __init__(self, parent, id):
1.77 @@ -187,19 +129,19 @@
1.78 wx.EVT_MENU (self, self.ID_OPTIONS, self.OnOptions)
1.79 wx.EVT_MENU (self, self.ID_INFO, self.OnInfo)
1.80
1.81 + self.config = wx.Config('DeskFrame')
1.82 + self.options = deskframe_options(self.config)
1.83 +
1.84 wx.EVT_TIMER (self, self.ID_TIMER, self.OnTimer)
1.85 self.timer = wx.Timer(self, self.ID_TIMER)
1.86 - self.timer.Start(1000)
1.87 + self.timer.Start(self.options.timeout*1000)
1.88
1.89 - self.config = wx.Config('DeskFrame')
1.90 -
1.91 - self.dir_list = self.ReadDirList()
1.92 self.LoadImageList()
1.93 self.image_idx = 0
1.94
1.95 def LoadImageList(self) :
1.96 self.image_list = indexed_files()
1.97 - for dd in self.dir_list :
1.98 + for dd in self.options.dir_list :
1.99 self.image_list.add_root(dd)
1.100
1.101 def image(self,fname) :
1.102 @@ -214,20 +156,11 @@
1.103 ## because we are lazy to define our own
1.104 raise KeyError
1.105
1.106 - def ReadDirList(self) :
1.107 - try :
1.108 - return self.config.Read('dir_list').split(':')
1.109 - except :
1.110 - return []
1.111 -
1.112 - def WriteDirList(self,dir_list) :
1.113 - self.config.Write('dir_list',':'.join(dir_list))
1.114 -
1.115 def OnTimer(self,event):
1.116 self.timer.Stop()
1.117 try :
1.118 self.image(self.image_list.get_file(self.image_idx))
1.119 - self.timer.Start(1000)
1.120 + self.timer.Start(self.options.timeout*1000)
1.121 except :
1.122 ## bad image -- skip right to the next one
1.123 self.timer.Start(10)
1.124 @@ -252,10 +185,10 @@
1.125 EXIFviewer(self,wx.ID_ANY,self.EXIF).Show()
1.126
1.127 def OnOptions(self,event) :
1.128 - add_dir = AddDirectory(self,wx.ID_ANY,self.dir_list)
1.129 - if add_dir.ShowModal() == wx.ID_OK:
1.130 - self.dir_list = add_dir.GetStrings()
1.131 - self.WriteDirList(self.dir_list)
1.132 + opts = Options(self,wx.ID_ANY,self.options)
1.133 + if opts.ShowModal() == wx.ID_OK:
1.134 + self.options = opts.get_options()
1.135 + self.options.Write(self.config)
1.136 self.LoadImageList()
1.137
1.138 def OnExit(self,event) :
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/options.py Sun Sep 27 18:00:08 2009 +0200
2.3 @@ -0,0 +1,130 @@
2.4 +#
2.5 +# DeskFrame
2.6 +#
2.7 +# Copyright (C) 2009 Shai Ayal
2.8 +#
2.9 +# This file is part of DeskFrame.
2.10 +#
2.11 +# DeskFrame is free software: you can redistribute it and/or modify
2.12 +# it under the terms of the GNU General Public License as published by
2.13 +# the Free Software Foundation, either version 3 of the License, or
2.14 +# (at your option) any later version.
2.15 +#
2.16 +# DeskFrame is distributed in the hope that it will be useful,
2.17 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2.18 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2.19 +# GNU General Public License for more details.
2.20 +#
2.21 +# You should have received a copy of the GNU General Public License
2.22 +# along with DeskFrame. If not, see <http://www.gnu.org/licenses/>.
2.23 +#
2.24 +
2.25 +import wx
2.26 +
2.27 +class deskframe_options(object):
2.28 + def __init__(self, config=None) :
2.29 + self.Read(config)
2.30 +
2.31 + def Read(self,config) :
2.32 + try :
2.33 + self.dir_list = config.Read('dir_list').split(':')
2.34 + except :
2.35 + self.dir_list = []
2.36 +
2.37 + try :
2.38 + self.timeout = config.ReadInt('timeout')
2.39 + ## 0 is a very bad value for us!
2.40 + if self.timeout == 0 :
2.41 + self.timeout = 5
2.42 + except :
2.43 + self.timeout = 5
2.44 +
2.45 + def Write(self,config) :
2.46 + config.Write('dir_list',':'.join(self.dir_list))
2.47 + config.WriteInt('timeout',self.timeout)
2.48 +
2.49 +
2.50 +class OptPanel(wx.Panel) :
2.51 + def __init__(self,parent,id,df_opts) :
2.52 + wx.Panel.__init__(self,parent,id)
2.53 +
2.54 + self.timeout = wx.SpinCtrl(self,min = 1, max = 3600,
2.55 + initial = df_opts.timeout)
2.56 +
2.57 +
2.58 +class PathPanel(wx.Panel) :
2.59 + def __init__(self,parent,id,df_opts) :
2.60 + wx.Panel.__init__(self,parent,id)
2.61 +
2.62 + ## get IDs for all controls
2.63 + self.ID_ADD = wx.NewId()
2.64 + self.ID_DEL = wx.NewId()
2.65 +
2.66 + wx.EVT_BUTTON(self, self.ID_DEL, self.OnDel)
2.67 + wx.EVT_BUTTON(self, self.ID_ADD, self.OnAdd)
2.68 +
2.69 + self.list = wx.ListBox(self,wx.ID_ANY,choices=df_opts.dir_list,
2.70 + style=wx.LB_SINGLE | wx.LB_SORT )
2.71 + add = wx.Button(self, self.ID_ADD,label='&Add ...')
2.72 + delete = wx.Button(self, self.ID_DEL,label='&Delete')
2.73 +
2.74 + path_strip = wx.BoxSizer(wx.HORIZONTAL)
2.75 + path_strip.Add(add,0, wx.ALL|wx.EXPAND, 5)
2.76 + path_strip.Add(delete,0, wx.ALL|wx.EXPAND, 5)
2.77 +
2.78 + path = wx.BoxSizer(wx.VERTICAL)
2.79 + path.Add(self.list , 1, wx.ALL|wx.EXPAND, 5)
2.80 + path.Add(path_strip , 0, wx.ALL, 5)
2.81 + self.SetSizer(path)
2.82 +
2.83 + def OnDel(self,event):
2.84 + sel = self.list.GetSelection()
2.85 + if sel != wx.NOT_FOUND :
2.86 + ans = wx.MessageDialog(self,
2.87 + message='Delete "%s"?'
2.88 + % self.list.GetString(sel),
2.89 + ).ShowModal()
2.90 + if ans == wx.ID_OK :
2.91 + self.list.Delete(sel)
2.92 +
2.93 + def OnAdd(self,event):
2.94 + dir_dial = wx.DirDialog(self,
2.95 + style=wx.DD_DEFAULT_STYLE,
2.96 + message='Select a directory to add')
2.97 + if dir_dial.ShowModal() == wx.ID_OK :
2.98 + self.list.Append(dir_dial.GetPath())
2.99 +
2.100 +
2.101 +class Options(wx.Dialog):
2.102 + def __init__(self,parent,id,df_opts) :
2.103 + wx.Dialog.__init__(self,parent,id,title='Options',
2.104 + style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER)
2.105 +
2.106 + top_panel = wx.Panel (self, wx.ID_ANY)
2.107 + ok = wx.Button (top_panel, wx.ID_OK)
2.108 + cancel = wx.Button (top_panel, wx.ID_CANCEL)
2.109 + bottom_strip = wx.BoxSizer(wx.HORIZONTAL)
2.110 + bottom_strip.Add(ok,0, wx.ALL|wx.EXPAND, 5)
2.111 + bottom_strip.Add(cancel,0, wx.ALL|wx.EXPAND, 5)
2.112 +
2.113 + notebook = wx.Notebook(top_panel)
2.114 +
2.115 + ## Search path panel
2.116 + self.panel_dir = PathPanel(notebook,wx.ID_ANY,df_opts)
2.117 + self.panel_opt = OptPanel(notebook,wx.ID_ANY,df_opts)
2.118 +
2.119 + ## put everything together
2.120 + toplevel = wx.BoxSizer(wx.VERTICAL)
2.121 + toplevel.Add(notebook,1,wx.ALL|wx.EXPAND, 5)
2.122 + toplevel.Add(bottom_strip,0,wx.ALL, 5)
2.123 + top_panel.SetSizer(toplevel)
2.124 + toplevel.Fit(top_panel)
2.125 + notebook.AddPage(self.panel_dir,'Search path')
2.126 + notebook.AddPage(self.panel_opt, 'Options')
2.127 +
2.128 + def get_options(self) :
2.129 + ## gather the options from their respective panels
2.130 + opts = deskframe_options()
2.131 + opts.dir_list = self.panel_dir.list.GetStrings()
2.132 + opts.timeout = self.panel_opt.timeout.GetValue()
2.133 + return opts