1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
import sys
import os
import os.path
import wx
import ConfigParser

class App(wx.App):
  """Application Class"""
  def __init__(self, redirect=True, filename=None,useBestVisual=False, clearSigInt=True):
    wx.App.__init__(self, redirect, filename, useBestVisual,
      clearSigInt)
    
  def OnInit (self):
    frame = Frame26("Skydive the Ranch",(50,60),(500,500))
    frameid = frame.GetId()
    frame.Show()
    self.SetTopWindow(frame)
    return True
  
  def OnQuit(self, event):
    print >> sys.stderr, "Quitting"
    self.Close()
    
  def OnCloseMe(self, event):
    print >> sys.stderr, "Closing"
    self.Close(True)

  def OnCloseWindow(self, event):
    print >> sys.stderr, "On Close window destroying"
    self.Destroy()
      
class GoProFrame(wx.Frame): 
  """Frame class that displays an image."""
  def __init__(self, image, parent=None, id=-1,
      pos=wx.DefaultPosition, title='GoProFrametest'):
    """Create a Frame insrance and display image."""
    temp = image.ConvertToBitmap()
    size = temp.GetWidth(), temp.GetHeight()
    wx.Frame.__init__(self, parent, id, title, pos, size)
    self.bmp = wx.StaticBitmap(parent=self, bitmap=temp)
  
class Frame26(wx.Frame):
  """ Page 26"""
  def __init__(self, title, pos, size):
    
    wx.Frame.__init__(self,None, -1, title, pos, size)
    
    menuFile = wx.Menu()
    menuFile.Append(1, "&Open...")
    menuFile.Append(2, "&Debug...")
    menuFile.AppendSeparator()
    menuFile.Append(3, "E&xit")
    
    menuHelp = wx.Menu()
    menuHelp.Append(4, "&About...")
    
    menuEdit = wx.Menu()
    menuEdit.Append(5, "&Preferences...")
    
    menuBar = wx.MenuBar()
    menuBar.Append(menuFile, "&File")
    menuBar.Append(menuEdit, "&Edit")
    menuBar.Append(menuHelp, "&Help")
        
    self.SetMenuBar(menuBar)
    self.CreateStatusBar()
    self.SetStatusText("Get it before it snags!")
    
    self.Bind(wx.EVT_MENU, self.OnOpen, id=1)
    self.Bind(wx.EVT_MENU, self.OnAbout, id=4)
    self.Bind(wx.EVT_MENU, self.OnDebug, id=2)
    self.Bind(wx.EVT_MENU, self.OnQuit, id=3)
    self.Bind(wx.EVT_MENU, self.OnPreferences, id=5)
    
    panel = wx.Panel(self)

    image = wx.Image('goproblack.jpg', wx.BITMAP_TYPE_JPEG)
    temp = image.ConvertToBitmap()
    size = temp.GetWidth(), temp.GetHeight()
    bmp = wx.StaticBitmap(panel,bitmap=temp)


    openbutton = wx.Button(panel, label="Play!", pos=(250,425),size=(60,60))
    self.Bind (wx.EVT_BUTTON, self.OnOpen, openbutton)
    configbutton = wx.Button(panel, label="Configme", pos=(320,425),size=(100,100))
    self.Bind (wx.EVT_BUTTON, self.OnConfigMe, configbutton)  
                closebutton = wx.Button(panel, label="Quit", pos=(425, 425),size=(55, 55))
                self.Bind (wx.EVT_BUTTON, self.OnQuit, closebutton)  
  
    #http://docs.python.org/library/configparser.html
    configfile = "gopro.conf"
    config = ConfigParser.RawConfigParser()
    if os.path.isfile(configfile):
      print >> sys.stderr, "Config File Exists"
      config.read(configfile)
    else:
      #Config the app
      self.configFrame = configFrame(parent=self, id=-1, title='GoPro Configuration')
      self.configFrame.Show()
      self.SetTopWindow(self.configFrame)
    
  def OnPreferences(self, event):
    # ==========
    # = Need a config Window =
    # ==========
    dlg = wx.MessageDialog(None, 'Are you sure you want to change Preferences', 'Setting Preferences', wx.YES_NO | wx.ICON_QUESTION)
    result = dlg.ShowModal()
    if result == wx.ID_YES:
      print >> sys.stderr, "Changing Configuration per user request"
      self.configFrame = configFrame(parent=self, id=-1, title='GoPro Configuration')
      self.configFrame.Show()
      SetTopWindow(self.configFrame)
    else:
      pass      
    dlg.Destroy()
      
  def OnQuit(self, event):
    print >> sys.stderr, "Quitting"
    self.Close()
    
  def OnAbout (self, event):
    wx.MessageBox("Where dreams will come",
      "The Ranch!", wx.OK | wx.ICON_INFORMATION, self)
  
  def OnDebug (self, event):
    self.logframe = logFrame(parent=self, id=-1, title='Debug Window')
    self.logframe.Show()
    self.SetTopWindow(self.logframe)
    print >> sys.stderr, "Debug Works"
    
  def OnOpen (self, event):
    """Open a userlist please"""
    # =============================
    # = TODO Insert filesystem ls =
    #  All videos are stored in /mnt/vstorage/all
    # =============================
    
    userlist = ['1.5.2', '2.0', '2.1.3', '2.2', '2.3.1']
    dlg = wx.SingleChoiceDialog(None,'Which GoPro?', 'Open GoPro Archive', userlist)
    if dlg.ShowModal() == wx.ID_OK:
      whichgopro = dlg.GetStringSelection()
      #response = dlg.GetSelection()
    
    filelist = ['blah1','blah2']
    dlg = wx.SingleChoiceDialog(None,'Which Video File?','Open Specific Video',filelist)
    if dlg.ShowModal() == wx.ID_OK:
      whichvideo = dlg.GetStringSelection()
  
  def OnConfigMe (self, event):
    self.configFrame = configFrame(parent=self, id=-1, title='GoPro Configuration')
                self.configFrame.Show()
                SetTopWindow(self.configFrame)

class configFrame(wx.Frame):
  """Configuration Frame"""
  def __init__(self, parent, id, title):
    wx.Frame.__init__(self, parent, id, 'Configure GoPro App',size = (500,500))
    panel = wx.Panel(self)
    closebutton = wx.Button(panel, label="Close", pos=(125, 200),size=(55, 55))
    applybutton = wx.Button(panel, label="Apply", pos=(200, 200),size=(55, 55))
    self.Bind (wx.EVT_BUTTON, self.OnCloseMe, closebutton)
    self.Bind (wx.EVT_BUTTON, self.OnApplyMe, applybutton)
    self.Bind (wx.EVT_CLOSE, self.OnCloseWindow)

    """Configure the GoPro App"""
    #http://docs.python.org/library/configparser.html
    configfile = "gopro.conf"
    if os.path.isfile(configfile):
      print >> sys.stderr, "Config File Exists"
      config = ConfigParser.RawConfigParser()
      config.read(configfile)
      self.status = "Current GoPro Configuration"
      working_directory = config.get ('GoPro','working_directory')
      ffmpeg_location = config.get ('Encoding','ffmpeg_location')
      ffmpeg_quality = config.getint ('Encoding','ffmpeg_quality')
      vlc_location = config.get ('Playback','vlc_location')
      tmppath = config.get ('Encoding','temppath')
    else:
      self.status = "Default GoPro Configuration"
      config = ConfigParser.RawConfigParser()
      config.read(configfile)
      #Config the app
      working = os.getcwd()
      config.add_section('GoPro')
      config.set('GoPro', 'working_directory', '/Volumes/movies/skydiving/GoPro/tmp')
      config.add_section('Encoding')
      config.set('Encoding', 'ffmpeg', 'true')
      config.set('Encoding','ffmpeg_location','/usr/local/bin/ffmpeg')
      config.set('Encoding','ffmpeg_quality','69')
      config.set('Encoding','temppath','/tmp')
      config.add_section('Playback')
                        config.set('Playback', 'vlc', 'true')
      config.set('Playback', 'vlc_location','/Applications/VLC.app/Contents/MacOS/VLC')
      with open(configfile, 'wb') as configfile:
          config.write(configfile)

    # Display The Current Config in the Panel
    wx.StaticText(panel, -1, self.status ,(100, 10))
    wx.StaticText(panel, -1, "working_directory : "+ working_directory, (10,30))
    wx.StaticText(panel, -1, "ffmpeg path : "+ ffmpeg_location, (10,50))
    wx.StaticText(panel, -1, "vlc path : "+ vlc_location, (10,70))
    wx.StaticText(panel, -1, "tmp path : "+ tmppath, (10,90))
    wx.StaticText(panel, -1, "ffmpeg quality : ", (10,110))
    self.count = 0
                slider = wx.Slider(panel, 100, ffmpeg_quality, 1, 100, pos=(10, 130),size=(250, -1),
                style=wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | wx.SL_LABELS )
                slider.SetTickFreq(5, 1)
    
    # Buttons
    workdir_button = wx.Button(panel, label="...", pos=(450,30),size=(30,30))
    ffmpegdir_button = wx.Button(panel, label="...", pos=(450,50),size=(30,30))
    vlcdir_button = wx.Button(panel, label="...", pos=(450,70),size=(30,30))  
    tmpdir_button = wx.Button(panel, label="...", pos=(450,90),size=(30,30))  

  def OnApplyMe(self, event):
    self.Close(True)  
  
  def OnCloseMe(self, event):
    self.Close(True)
  
  def OnCloseWindow(self, event):
    self.Destroy()
  
class logFrame(wx.Frame):
  """Log Frame"""
  def __init__(self, parent, id, title):
    print "Frame __init__"
    wx.Frame.__init__(self, parent, id, title)
    panel = wx.Panel(self, -1)
    button = wx.Button(panel, -1, label="Close", pos=(300, 300),size=(55, 55))
    
    self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
    self.Bind(wx.EVT_BUTTON, self.OnCloseMe, button)
  
  def OnCloseMe(self, event):
    print >> sys.stderr, "Closing"
    self.Close(True)
  
  def OnCloseWindow(self, event):
    print >> sys.stderr, "On Close window destroying"
    self.Destroy()

def main():
  #clean debug file
  if os.path.isfile("debug.txt"):
    os.remove ("debug.txt")
  
  #app = App(redirect=True, filename="debug.txt")
  app = App(False)
  app.MainLoop()
  app=()

if __name__ == '__main__':
  main()