예제 #1
0
 def OnTorrentPathButton(self, event):
     defaultPath = normalisePath(self.torrentPath.GetValue(), expand=True)
     if not defaultPath == '':
         #already selected a torrent before
         defaultDir = os.path.dirname(defaultPath)
         defaultFile = os.path.basename(defaultPath)
     else:
         #nothing selected yet, try to guess something useable from the data path
         defaultPath = normalisePath(self.dataPath.GetValue(), expand=True)
         if defaultPath == '':
             defaultPath = self.progPath
             
         if os.path.isdir(defaultPath):
             #directory
             defaultFile = os.path.basename(defaultPath)
             if not defaultFile == '':
                 defaultDir = os.path.dirname(defaultPath)
             else:
                 defaultDir = os.path.dirname(defaultPath[:-1])
                 defaultFile = os.path.basename(defaultPath[:-1])
             if not defaultFile == '':
                 defaultFile += '.torrent'
         else:
             #file
             defaultDir = os.path.dirname(defaultPath)
             defaultFile = os.path.basename(defaultPath)+'.torrent'
     
     fileSelectDialog = wx.FileDialog(self, message='Save Torrent',\
                                      defaultDir=defaultDir, defaultFile=defaultFile,\
                                      wildcard='Torrent files (*.torrent)|*.torrent|All files (*.*)|*.*',\
                                      style=wx.SAVE | wx.OVERWRITE_PROMPT)
                                 
     if fileSelectDialog.ShowModal() == wx.ID_OK:
         #user selected something
         self.torrentPath.SetValue(fileSelectDialog.GetPath())
예제 #2
0
 def OnFilePathDirButton(self, event):
     defaultPath = normalisePath(self.dataPath.GetValue(), expand=True)
     
     if defaultPath == '' or (not os.path.exists(defaultPath)):
         #nothing valid, default
         defaultPath = self.progPath
     elif os.path.isfile(defaultPath):
         #file
         defaultPath = os.path.dirname(defaultPath)
         
     dirSelectDialog = wx.DirDialog(self, message='Select a directory',\
                                    defaultPath=defaultPath,style=wx.DD_DEFAULT_STYLE)
                                 
     if dirSelectDialog.ShowModal() == wx.ID_OK:
         #user selected something
         self.dataPath.SetValue(dirSelectDialog.GetPath())
예제 #3
0
 def OnFilePathFileButton(self, event):
     defaultPath = normalisePath(self.dataPath.GetValue(), expand=True)
     
     if defaultPath == '' or (not os.path.exists(defaultPath)):
         #nothing valid, default
         defaultDir = self.progPath
         defaultFile = ''
     elif os.path.isdir(defaultPath):
         #directory
         defaultDir = defaultPath
         defaultFile = ''
     else:
         #file
         defaultDir = os.path.dirname(defaultPath)
         defaultFile = os.path.basename(defaultPath)
         
     fileSelectDialog = wx.FileDialog(self, message='Select a file',\
                                      defaultDir=defaultDir, defaultFile=defaultFile, wildcard='All files (*.*)|*.*',\
                                      style=wx.OPEN)
                                 
     if fileSelectDialog.ShowModal() == wx.ID_OK:
         #user selected something
         self.dataPath.SetValue(fileSelectDialog.GetPath())