| 1 |
import sys |
| 2 |
import wx |
| 3 |
from .constants import * |
| 4 |
|
| 5 |
base_width=480 |
| 6 |
option_height=24 |
| 7 |
help_height=32+16*4 |
| 8 |
button_height=32 |
| 9 |
hpadding=16 |
| 10 |
vpadding=8 |
| 11 |
|
| 12 |
class UIOptions(wx.Dialog): |
| 13 |
def __init__(self,parent,options): |
| 14 |
pre=wx.PreDialog() |
| 15 |
pre.Create(parent,wx.ID_ANY,title=kdj_name+' options') |
| 16 |
self.PostCreate(pre) |
| 17 |
|
| 18 |
self.options=options |
| 19 |
|
| 20 |
self.y=vpadding |
| 21 |
self.opt_save_as_copy=self.AddCheckBox( |
| 22 |
'Save remuxed file as a copy of the original Ogg file', |
| 23 |
options.save_as_copy, |
| 24 |
'If enabled, remuxed files will be saved on a different file, so the source '+ |
| 25 |
'file is left untouched. The new file will be named similarly to the old file, '+ |
| 26 |
'but with \'.remuxed\' inserted before the extension.' |
| 27 |
) |
| 28 |
self.y+=vpadding |
| 29 |
self.opt_remove=self.AddCheckBox( |
| 30 |
'Remove all temporary files on exit', |
| 31 |
options.remove_temporary_files, |
| 32 |
'If enabled, any temporary files extracted from an Ogg stream will be, '+ |
| 33 |
'removed, even if the file was not remuxed. Any changes that may have '+ |
| 34 |
'been made to the Kate streams in these temporary files will be lost.' |
| 35 |
) |
| 36 |
self.y+=vpadding |
| 37 |
self.opt_format=self.AddList( |
| 38 |
'Decode Kate streams as', |
| 39 |
['Kate', 'SRT', 'LRC'], |
| 40 |
options.format, |
| 41 |
'Selects the text format to use when decoding Kate streams.\n'+ |
| 42 |
'Typically, text based movie subtitles are best decoded as SRT, and other '+ |
| 43 |
'streams as Kate.' |
| 44 |
) |
| 45 |
self.y+=vpadding |
| 46 |
|
| 47 |
help_pos=(hpadding,self.y) |
| 48 |
help_size=(base_width,help_height) |
| 49 |
help_inset=(16,24) |
| 50 |
wx.StaticBox(self,label='More info',pos=help_pos,size=help_size) |
| 51 |
help_pos=(help_pos[0]+help_inset[0],help_pos[1]+help_inset[1]) |
| 52 |
self.help_size=(help_size[0]-2*help_inset[0],help_size[1]-2*help_inset[1]) |
| 53 |
self.help_text=wx.StaticText(self,wx.ID_ANY,'',pos=help_pos,size=help_size) |
| 54 |
self.y+=help_height |
| 55 |
self.y+=vpadding |
| 56 |
|
| 57 |
self.accept_button=wx.Button(self,wx.ID_OK,'OK',(hpadding,self.y),((base_width-hpadding)/2,button_height)) |
| 58 |
self.cancel_button=wx.Button(self,wx.ID_CANCEL,'Cancel',(hpadding*2+base_width/2,self.y),((base_width-hpadding)/2,button_height)) |
| 59 |
self.accept_button.Bind(wx.EVT_BUTTON,self.OnOK) |
| 60 |
self.y+=button_height |
| 61 |
|
| 62 |
self.y+=vpadding |
| 63 |
self.SetSize((base_width+hpadding*2,self.y)) |
| 64 |
self.Show(True) |
| 65 |
|
| 66 |
def SetHelpText(self,text): |
| 67 |
self.help_text.SetLabel(text) |
| 68 |
|
| 69 |
def SetHelpTextAndSkip(self,text,ev): |
| 70 |
self.help_text.SetLabel(text) |
| 71 |
self.help_text.Wrap(self.help_size[0]) |
| 72 |
ev.Skip() |
| 73 |
|
| 74 |
def AddButton(self,id,label): |
| 75 |
button=wx.Button(self,id=id) #,label=label) |
| 76 |
return button |
| 77 |
|
| 78 |
def AddCheckBox(self,label,on,help_text): |
| 79 |
checkbox=wx.CheckBox(self,label=label,pos=(hpadding,self.y),size=(base_width,option_height)) |
| 80 |
checkbox.Bind(wx.EVT_ENTER_WINDOW,lambda ev: self.SetHelpTextAndSkip(help_text,ev)) |
| 81 |
checkbox.Bind(wx.EVT_LEAVE_WINDOW,lambda ev: self.SetHelpTextAndSkip('',ev)) |
| 82 |
checkbox.SetValue(on) |
| 83 |
self.y+=option_height |
| 84 |
return checkbox |
| 85 |
|
| 86 |
def AddList(self,text,choices,default,help_text): |
| 87 |
box=wx.BoxSizer(wx.HORIZONTAL) |
| 88 |
box.SetDimension(hpadding,self.y,base_width,option_height) |
| 89 |
|
| 90 |
label=wx.StaticText(self,wx.ID_ANY,text) |
| 91 |
box.Add(label,flag=wx.ALIGN_CENTER_VERTICAL) |
| 92 |
label.Bind(wx.EVT_ENTER_WINDOW,lambda ev: self.SetHelpTextAndSkip(help_text,ev)) |
| 93 |
label.Bind(wx.EVT_LEAVE_WINDOW,lambda ev: self.SetHelpTextAndSkip('',ev)) |
| 94 |
|
| 95 |
box.AddSpacer((8,0)) |
| 96 |
|
| 97 |
list=wx.Choice(self, -1, (80,-1),choices=choices) |
| 98 |
list.SetStringSelection(default) |
| 99 |
box.Add(list,flag=wx.ALIGN_CENTER_VERTICAL) |
| 100 |
list.Bind(wx.EVT_ENTER_WINDOW,lambda ev: self.SetHelpTextAndSkip(help_text,ev)) |
| 101 |
list.Bind(wx.EVT_LEAVE_WINDOW,lambda ev: self.SetHelpTextAndSkip('',ev)) |
| 102 |
|
| 103 |
box.Layout() |
| 104 |
self.y+=option_height |
| 105 |
return list |
| 106 |
|
| 107 |
def OnOK(self,event): |
| 108 |
self.options.save_as_copy=self.opt_save_as_copy.IsChecked() |
| 109 |
self.options.remove_temporary_files=self.opt_remove.IsChecked() |
| 110 |
self.options.format=self.opt_format.GetStringSelection().lower() |
| 111 |
self.options.Save() |
| 112 |
event.Skip() |
| 113 |
|