"Fossies" - the Fresh Open Source Software Archive

Member "photofilmstrip-3.7.0/photofilmstrip/gui/DlgDuration.py" (12 Nov 2018, 5582 Bytes) of package /linux/privat/photofilmstrip-3.7.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "DlgDuration.py" see the Fossies "Dox" file reference documentation.

    1 # encoding: UTF-8
    2 #
    3 # PhotoFilmStrip - Creates movies out of your pictures.
    4 #
    5 # Copyright (C) 2010 Jens Goepfert
    6 #
    7 
    8 import wx
    9 import wx.lib.masked.timectrl
   10 
   11 from photofilmstrip.gui.ctrls.PnlDlgHeader import PnlDlgHeader
   12 
   13 
   14 class DlgDuration(wx.Dialog):
   15 
   16     def _InitSizers(self):
   17 
   18         szManual = wx.BoxSizer(wx.HORIZONTAL)
   19         szManual.Add(self.rbManual, flag=wx.ALIGN_CENTER_VERTICAL)
   20         szManual.AddSpacer(8)
   21         szManual.Add(self.timeCtrlTotalLength, 1)
   22 
   23         szCtrls = wx.BoxSizer(orient=wx.VERTICAL)
   24         szCtrls.AddSpacer(8)
   25         szCtrls.Add(self.cbTotalLength, border=8, flag=wx.LEFT)
   26         szCtrls.AddSpacer(8)
   27         szCtrls.Add(self.rbAudio, border=32, flag=wx.LEFT | wx.EXPAND)
   28         szCtrls.AddSpacer(8)
   29         szCtrls.Add(szManual, border=32, flag=wx.LEFT | wx.EXPAND)
   30 
   31         szCmds = wx.BoxSizer(orient=wx.HORIZONTAL)
   32         szCmds.Add(self.cmdCancel, 0, border=0, flag=0)
   33         szCmds.AddSpacer(8)
   34         szCmds.Add(self.cmdOk, 0, border=0, flag=0)
   35 
   36         szMain = wx.BoxSizer(orient=wx.VERTICAL)
   37         szMain.Add(self.pnlHdr, 0, border=0, flag=wx.EXPAND)
   38         szMain.Add(szCtrls, 0, border=8, flag=wx.ALL | wx.EXPAND)
   39         szMain.Add(self.staticLine, 0, border=0, flag=wx.EXPAND)
   40         szMain.Add(szCmds, 0, border=8, flag=wx.ALL | wx.ALIGN_RIGHT)
   41 
   42         self.SetSizer(szMain)
   43 
   44     def _InitCtrls(self):
   45         self.pnlHdr = PnlDlgHeader(self)
   46 
   47         self.cbTotalLength = wx.CheckBox(self,
   48               label=_(u'Total length:'), name=u'cbTotalLength')
   49         self.cbTotalLength.SetValue(False)
   50         self.cbTotalLength.SetToolTip(_(u'Overrides the duration of single pictures and gives the project this total length.'))
   51         self.cbTotalLength.Bind(wx.EVT_CHECKBOX, self.OnControlStatusTotalLength)
   52 
   53         self.rbManual = wx.RadioButton(self,
   54               label=_(u'User defined:'), name=u'rbManual')
   55         self.rbManual.Bind(wx.EVT_RADIOBUTTON, self.OnControlStatusTotalLength)
   56 
   57         self.timeCtrlTotalLength = wx.lib.masked.timectrl.TimeCtrl(self,
   58               display_seconds=True, fmt24hr=True,
   59               name=u'timeCtrlTotalLength', oob_color=wx.YELLOW,
   60               style=0, useFixedWidthFont=True, value='12:00:00 AM',
   61               size=wx.Size(300, -1))
   62         self.timeCtrlTotalLength.Enable(False)
   63 
   64         self.rbAudio = wx.RadioButton(self,
   65               label=_(u'Fit to audio files'), name=u'rbAudio')
   66         self.rbAudio.Bind(wx.EVT_RADIOBUTTON, self.OnControlStatusTotalLength)
   67 
   68         self.staticLine = wx.StaticLine(self)
   69 
   70         self.cmdCancel = wx.Button(self, id=wx.ID_CANCEL, label=_(u'&Cancel'),
   71               name=u'cmdCancel')
   72         self.cmdOk = wx.Button(self, id=wx.ID_OK, label=_(u'&Ok'),
   73               name=u'cmdOk')
   74         self.cmdOk.Bind(wx.EVT_BUTTON, self.OnCmdOkButton, id=wx.ID_OK)
   75         self.cmdOk.SetDefault()
   76 
   77     def __init__(self, parent, project=None):
   78         wx.Dialog.__init__(self, parent, name=u'DlgDuration',
   79                            style=wx.DEFAULT_DIALOG_STYLE,
   80                            title=_(u'Slideshow duration'))
   81 
   82         self._InitCtrls()
   83 
   84         self.pnlHdr.SetTitle(_(u'Configure duration of slideshow'))
   85         self.pnlHdr.SetBitmap(wx.ArtProvider.GetBitmap('PFS_ICON_32'))
   86 
   87         defTime = wx.DateTime.Now()
   88         defTime.SetHMS(0, 0, 30)
   89         minTime = wx.DateTime.Now()
   90         minTime.SetHMS(0, 0, 1)
   91         maxTime = wx.DateTime.Now()
   92         maxTime.SetHMS(1, 59, 59)
   93         self.timeCtrlTotalLength.SetValue(defTime)
   94         self.timeCtrlTotalLength.SetMin(minTime)
   95         self.timeCtrlTotalLength.SetMax(maxTime)
   96         self.timeCtrlTotalLength.SetLimited(True)
   97 
   98         self.__project = project
   99 
  100         pfsDur = project.GetDuration(calc=True)
  101         duration = project.GetDuration(calc=False)
  102         if duration is None:
  103             self.cbTotalLength.SetValue(False)
  104         elif duration <= 0:
  105             self.cbTotalLength.SetValue(True)
  106             self.rbAudio.SetValue(True)
  107         else:
  108             self.cbTotalLength.SetValue(True)
  109             self.rbManual.SetValue(True)
  110             pfsDur = duration
  111 
  112         pfsDur = int(round(pfsDur))
  113 
  114         dur = wx.DateTime.Now()
  115         dur.SetHMS(pfsDur // 3600, (pfsDur % 3600) // 60, pfsDur % 60)
  116         try:
  117             self.timeCtrlTotalLength.SetWxDateTime(dur)
  118         except ValueError:
  119             # duration is invalid if there are no photos
  120             pass
  121 
  122         self.__ControlStatusTotalLength()
  123 
  124         self._InitSizers()
  125         self.Fit()
  126         self.CenterOnParent()
  127         self.SetFocus()
  128 
  129     def OnControlStatusTotalLength(self, event):
  130         self.__ControlStatusTotalLength()
  131         event.Skip()
  132 
  133     def OnCmdOkButton(self, event):
  134         self.__project.SetDuration(self.__GetTotalLength())
  135         event.Skip()
  136 
  137     def __ControlStatusTotalLength(self):
  138         active = self.cbTotalLength.GetValue()
  139         manual = self.rbManual.GetValue()
  140 
  141         self.rbAudio.Enable(active)
  142         self.rbManual.Enable(active)
  143         self.timeCtrlTotalLength.Enable(active and manual)
  144 
  145     def __GetTotalLength(self):
  146         totalLength = None
  147 
  148         if self.cbTotalLength.GetValue():
  149             if self.rbManual.GetValue():
  150                 totalLength = 0
  151                 dateTime = self.timeCtrlTotalLength.GetValue(as_wxDateTime=True)
  152                 totalLength += dateTime.GetHour() * 3600
  153                 totalLength += dateTime.GetMinute() * 60
  154                 totalLength += dateTime.GetSecond()
  155             elif self.rbAudio.GetValue():
  156                 totalLength = -1
  157 
  158         return totalLength