سلام دوستان
این برنامه پوسته ی گرافیکی برای تعمیر زیرنویس هستش!!
با wxpython
همه جاش درسته جز قسمت درگ فایل :|
در گوگل هم نتونسم راهی براش بیابم !
مشکلش کجاست که درگ کار نمیکنه ؟
لطفا اگه میتونین به فارسی درگ در wxpython رو یاد بدین !!
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on Sat May 31 10:12:45 2014
@author: Amir Bakhtiary
"""
##########################################################################
###iconv -f WINDOWS-1256 -t UTF-8 subtitle.srt --output newsubtitle.srt###
###This program fix your subtitles for movies ###
#current version just support persian language ###
#this is free and open source ###
#----- ###
#i putted some comments in source ###
#Enjoy! ###
#contact me : encoder301 ###
##########################################################################
"""here i imported some modules wich i need
like wx
frame
and more"""
import wx
import os,sys,shutil
"""Make a app object for wx module"""
app=wx.App()
os.chdir("/home/empty/Icons")
icon=wx.Icon("fileico.ico",wx.BITMAP_TYPE_ICO)
os.chdir("/home/")
wildcard="SRT Subtitle Files|*.srt;"
class FileDrop(wx.FileDropTarget):
def __init__(self, window):
wx.FileDropTarget.__init__(self)
self.window = window
def OnDropFiles(self, x, y, filenames):
self.window.WriteText(filenames[0])
class Main(wx.Frame):
def __init__(self):
"""call wx.Frame __init__ special method"""
super(Main,self,).__init__(None,size=(320,260),style=wx.DEFAULT_FRAME_STYLE^wx.RESIZE_BORDER^wx.MAXIMIZE_BOX)
self.SetTitle("GNU\\Linux Subtitle Fixer")
self.list=[]
self.Center()
self.Show()
self.panel=wx.Panel(self)
self.SetIcon(icon)
menubar=wx.MenuBar()
menu1=wx.Menu()
menu2=wx.Menu()
me1=menu1.Append(wx.ID_SAVE,"Start","Start Converting")
me3=menu1.Append(wx.ID_EXIT,"Exit","Close The Program")
me2=menu2.Append(wx.ID_HELP,"About","A Little Passage About Programmer ")
self.CreateStatusBar()
menubar.Append(menu1,"&Tools")
menubar.Append(menu2,"&Help")
self.SetMenuBar(menubar)
self.Bind(wx.EVT_MENU,sys.exit,me3)
self.Bind(wx.EVT_MENU,self.About,me2)
self.Bind(wx.EVT_MENU,self.Start,me1)
self.Bind(wx.EVT_CLOSE , sys.exit)
self.txt1=wx.StaticBox(self.panel,pos=(5,5),label="Input File",size=(310,70))
self.txt2=wx.StaticBox(self.panel,pos=(5,130),label="Output File",size=(310,70))
self.IN=wx.TextCtrl(self.panel,size=(250,25),pos=(15,40),style=wx.TE_READONLY)
self.OUT=wx.TextCtrl(self.panel,size=(250,25),pos=(15,160),style=wx.TE_READONLY)
self.pbtn=wx.Button(self.panel,size=(30,25),pos=(270,40),label="...")
self.pbtn2=wx.Button(self.panel,size=(30,25),pos=(270,160),label="...")
self.btn1=wx.RadioButton(self.panel,pos=(15,80),label="Use The Same Folder For Output")
self.btn2=wx.RadioButton(self.panel,pos=(15,100),label="Use The Different Folder For Output")
self.btn1.SetValue(True)
self.OUT.Disable()
self.pbtn2.Disable()
self.btn1.Bind(wx.EVT_RADIOBUTTON,self.Same)
self.btn2.Bind(wx.EVT_RADIOBUTTON,self.dif)
self.pbtn.Bind(wx.EVT_BUTTON,self.opendialog1)
self.pbtn2.Bind(wx.EVT_BUTTON,self.opendialog2)
drag=FileDrop(self.IN)
self.IN.SetDropTarget(drag)
self.IN.SetFocus()
def About(self,event):
wx.MessageBox("Copyright (c) 2014 By Amir Bakhtiary bz\nThis Program Has Been Developed By Amir Bakhtiary\nContact:\n Encoder301@Yahoo.Com\n","About",parent=self)
def Start(self,event):
if len(self.list)==0:
wx.MessageBox("Choose Option First\t\t","Warning",parent=self)
elif self.list[0]=="same":
if self.IN.GetValue()=="":
wx.MessageBox("No Input File\t\t","Alert",parent=self)
else:
os.system("iconv -f WINDOWS-1256 -t UTF-8 '"+str(self.IN.GetValue())+"' --output '"+str(self.IN.GetValue())[0:-4]+"-fixed.srt'")
elif self.list[0]=="dif":
if self.IN.GetValue()=="":
wx.MessageBox("No Input File\t\t","Alert",parent=self)
else:
if self.OUT.GetValue()=="":
wx.MessageBox("No Output File\t\t","Alert",parent=self)
else:
my_path=str(self.IN.GetValue())[0:-4]+"-fixed.srt"
os.system("iconv -f WINDOWS-1256 -t UTF-8 '"+str(self.IN.GetValue())+"' --output '"+my_path+"'")
shutil.move(my_path,str(self.OUT.GetValue()))
wx.MessageBox("Completed\nFixed subtitle saved in : \n\t"+my_path,"Completed",parent=self)
def dif(self,event):
self.OUT.Enable()
self.pbtn2.Enable()
self.txt2.SetLabel("Output File")
del self.list[:]
self.list.append("dif")
def Same(self,event):
self.OUT.Disable()
self.pbtn2.Disable()
self.txt2.SetLabel("Output File")
del self.list[:]
self.list.append("same")
def opendialog1(self,event):
dialog=wx.FileDialog(self,message="Select Your File",wildcard=wildcard,defaultDir=os.getcwd(),style=wx.FD_OPEN)
ans=dialog.ShowModal()
if ans==wx.ID_OK:
path=dialog.GetPath()
self.IN.SetValue(path)
def opendialog2(self,event):
dialog=wx.FileDialog(self,message="Select Your File",wildcard=wildcard,defaultDir=os.getcwd(),style=wx.FD_SAVE)
ans=dialog.ShowModal()
if ans==wx.ID_OK:
path=dialog.GetPath()
self.OUT.SetValue(path)
main=Main()
app.MainLoop()