本文整理汇总了Python中subconvert.utils.Locale._函数的典型用法代码示例。如果您正苦于以下问题:Python _函数的具体用法?Python _怎么用?Python _使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _tokenize_time
def _tokenize_time(timestr):
timestr = re.sub(r'\s+', '', timestr)
SubAssert(timestr, _('Sync: time spec cannot be empty'))
time_args = dict(sign=None, h=0, m=0, s=0, ms=0)
if timestr[0] in '+-':
time_args['sign'] = int('%s1' % timestr[0])
timestr = timestr[1:]
found_units = set()
expr = re.compile(r'''(?P<value>\d+)(?P<unit>[a-zA-Z]+)''')
parsed_len = 0
for elem in expr.finditer(timestr):
val = elem.group('value')
unit = elem.group('unit')
SubAssert(unit not in found_units,
_('Sync: non-unique time units in time spec'))
found_units.add(unit)
time_args[unit] = int(val)
parsed_len += (len(unit) + len(val))
SubAssert(parsed_len == len(timestr),
_('Sync: some characters not parsed'))
try:
return _Time(**time_args)
except TypeError:
raise SubException(_('Sync: incorrect time spec units'))
开发者ID:mgoral,项目名称:subconvert,代码行数:30,代码来源:syncparse.py
示例2: __initWidgets
def __initWidgets(self):
minimalSizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
# List of subtitles
subListDelegate = SubListItemDelegate()
self._model = QStandardItemModel(0, 3, self)
self._model.setHorizontalHeaderLabels([_("Begin"), _("End"), _("Subtitle")])
self._subList = QTableView(self)
self._subList.setModel(self._model)
self._subList.setItemDelegateForColumn(0, subListDelegate)
self._subList.setItemDelegateForColumn(1, subListDelegate)
self._subList.horizontalHeader().setSectionResizeMode(2, QHeaderView.Stretch)
self._searchBar = SearchBar(self)
self._searchBar.hide()
# Top toolbar
toolbar = QHBoxLayout()
toolbar.setAlignment(Qt.AlignLeft)
#toolbar.addWidget(someWidget....)
toolbar.addStretch(1)
# Main layout
grid = QGridLayout()
grid.setSpacing(10)
grid.setContentsMargins(0, 3, 0, 0)
grid.addLayout(toolbar, 0, 0, 1, 1) # stretch to the right
grid.addWidget(self._subList, 1, 0)
grid.addWidget(self._searchBar, 2, 0)
self.setLayout(grid)
开发者ID:mgoral,项目名称:subconvert,代码行数:30,代码来源:SubtitleTabs.py
示例3: saveProperties
def saveProperties(self):
subProperties = None
try:
subProperties = self._createSubtitleProperties()
except Exception as e:
dialog = QMessageBox(self)
dialog.setIcon(QMessageBox.Critical)
dialog.setWindowTitle(_("Incorrect value"))
dialog.setText(_("Could not save SPF file because of incorrect parameters."));
dialog.setDetailedText(str(e));
dialog.exec()
return
fileDialog = FileDialog(
parent = self,
caption = _('Save Subtitle Properties'),
directory = self._settings.getPropertyFilesPath()
)
fileDialog.setAcceptMode(QFileDialog.AcceptSave)
fileDialog.setFileMode(QFileDialog.AnyFile)
if fileDialog.exec():
filename = fileDialog.selectedFiles()[0]
if not filename.endswith(".spf"):
filename = "%s%s" % (filename, ".spf")
self._settings.setPropertyFilesPath(os.path.dirname(filename))
subProperties.save(filename)
self._settings.addPropertyFile(filename)
self.close()
开发者ID:mgoral,项目名称:subconvert,代码行数:30,代码来源:PropertyFileEditor.py
示例4: _createEncodingBox
def _createEncodingBox(self):
groupbox = QGroupBox(_("File Encoding"))
layout = QGridLayout()
self._autoEncoding = QCheckBox(_("Auto input encoding"), self)
self._inputEncoding = QComboBox(self)
self._inputEncoding.addItems(ALL_ENCODINGS)
self._inputEncoding.setDisabled(self._autoEncoding.isChecked())
inputLabel = QLabel(_("Input encoding"))
self._changeEncoding = QCheckBox(_("Change encoding on save"), self)
self._outputEncoding = QComboBox(self)
self._outputEncoding.addItems(ALL_ENCODINGS)
self._outputEncoding.setEnabled(self._changeEncoding.isChecked())
outputLabel = QLabel(_("Output encoding"))
layout.addWidget(self._autoEncoding, 0, 0)
layout.addWidget(self._inputEncoding, 1, 0)
layout.addWidget(inputLabel, 1, 1)
layout.addWidget(self._changeEncoding, 2, 0)
layout.addWidget(self._outputEncoding, 3, 0)
layout.addWidget(outputLabel, 3, 1)
groupbox.setLayout(layout)
return groupbox
开发者ID:mgoral,项目名称:subconvert,代码行数:25,代码来源:PropertyFileEditor.py
示例5: addPoint
def addPoint(self):
rows = self._current.editor.selectedRows()
newStart = self._videoWidget.position
if len(rows) == 0 or newStart is None:
self._err.showMessage(_("Select a subtitle and position in current video first."))
return
# row and sub reflect the same subtitle, but we need both for different things
row = rows[0]
sub = self._current.data.subtitles[row]
# Don't add the same subtitle or the same sync time twice
if any(row == point.subNo or newStart == point.start
for point in _syncPoints(self._current.model)):
self._err.showMessage(_("Can't repeat synchronization points"))
return
if sub.fps != newStart.fps:
self._err.showMessage(_("Subtitle and video have different framerates (%(sub)s vs"
"%(vid)s") % dict(sub=sub.fps, vid=newStart.fps))
return
delta = sub.end - sub.start
newEnd = newStart + delta
startItem, endItem, textItem = createRow(sub, newStart, newEnd)
subNoItem = QStandardItem(str(row))
subNoItem.setEditable(False)
textItem.setEditable(False)
rmItem = QStandardItem("")
self._current.model.appendRow([subNoItem, startItem, endItem, textItem, rmItem])
self._rmButton(self._table, rmItem)
开发者ID:mgoral,项目名称:subconvert,代码行数:34,代码来源:Synchronizer.py
示例6: detectFpsFromMovie
def detectFpsFromMovie(cls, movieFile, default = 23.976):
"""Fetch movie FPS from MPlayer output or return given default."""
# initialize with a default FPS value, but not with a movieFile
videoInfo = VideoInfo(float(default))
command = ['mplayer',
'-really-quiet', '-vo', 'null', '-ao', 'null', '-frames', '0', '-identify', movieFile]
try:
mpOut, mpErr = Popen(command, stdout=PIPE, stderr=PIPE).communicate()
log.debug(mpOut)
log.debug(mpErr)
# Overwrite default (not fetched from video) values.
# If there's any error on changing videoInfo.fps, whole videoInfo won't be changed at
# all.
videoInfo.fps = float(re.search(r'ID_VIDEO_FPS=([\w/.]+)\s?', str(mpOut)).group(1))
videoInfo.videoPath = movieFile
except OSError:
log.warning(_("Couldn't run mplayer. It has to be installed and placed in your $PATH "
"to detect FPS."))
except AttributeError:
log.warning(_("Couldn't get FPS from %(movie)s. Using default value: %(fps)s.") %
{"movie": movieFile, "fps": videoInfo.fps})
else:
pass
log.debug(P_(
"Got %(fps)s FPS from '%(movie)s'.",
"Got %(fps)s FPS from '%(movie)s'.",
int(videoInfo.fps)) % {"fps": videoInfo.fps, "movie": videoInfo.videoPath})
return videoInfo
开发者ID:mgoral,项目名称:subconvert,代码行数:33,代码来源:SubFile.py
示例7: openHelp
def openHelp(self):
url = "https://github.com/mgoral/subconvert/wiki"
if QDesktopServices.openUrl(QUrl(url)) is False:
dialog = QMessageBox(self)
dialog.setIcon(QMessageBox.Critical)
dialog.setWindowTitle(_("Couldn't open URL"))
dialog.setText(_("""Failed to open URL: <a href="%(url)s">%(url)s</a>.""") %
{"url": url})
dialog.exec()
开发者ID:mgoral,项目名称:subconvert,代码行数:9,代码来源:MainWindow.py
示例8: linkVideo
def linkVideo(self):
movieExtensions = "%s%s" % ("*.", ' *.'.join(File.MOVIE_EXTENSIONS))
fileDialog = FileDialog(
parent = self,
caption = _("Select a video"),
directory = self._settings.getLatestDirectory(),
filter = _("Video files (%s);;All files (*)") % movieExtensions)
fileDialog.setFileMode(QFileDialog.ExistingFile)
if fileDialog.exec():
movieFilePath = fileDialog.selectedFiles()[0]
self._setVideoLink(movieFilePath)
开发者ID:mgoral,项目名称:subconvert,代码行数:11,代码来源:MainWindow.py
示例9: offset
def offset(self, seconds):
data = self.data
fps = data.subtitles.fps
if fps is None:
log.error(_("No FPS for '%s' (empty subtitles)." % self.filePath))
return
ft = FrameTime(data.subtitles.fps, seconds=seconds)
data.subtitles.offset(ft)
command = ChangeData(self.filePath, data,
_("Offset by: %s") % ft.toStr())
self._subtitleData.execute(command)
开发者ID:mgoral,项目名称:subconvert,代码行数:11,代码来源:SubtitleTabs.py
示例10: _chooseSubProperties
def _chooseSubProperties(self):
fileDialog = FileDialog(
parent = self,
caption = _("Open Subtitle Properties"),
directory = self._settings.getPropertyFilesPath(),
filter = _("Subtitle Properties (*.spf);;All files (*)")
)
fileDialog.setFileMode(QFileDialog.ExistingFile)
if fileDialog.exec():
filename = fileDialog.selectedFiles()[0]
self._useSubProperties(filename)
开发者ID:mgoral,项目名称:subconvert,代码行数:12,代码来源:SubtitleTabs.py
示例11: openProperties
def openProperties(self):
fileDialog = FileDialog(
parent = self,
caption = _("Open Subtitle Properties"),
directory = self._settings.getPropertyFilesPath(),
filter = _("Subtitle Properties (*.spf);;All files (*)")
)
fileDialog.setFileMode(QFileDialog.ExistingFile)
if fileDialog.exec():
filename = fileDialog.selectedFiles()[0]
self._settings.setPropertyFilesPath(os.path.dirname(filename))
subProperties = SubtitleProperties(list(self._formats.values()), filename)
self.changeProperties(subProperties)
开发者ID:mgoral,项目名称:subconvert,代码行数:14,代码来源:PropertyFileEditor.py
示例12: _createFormatBox
def _createFormatBox(self):
groupbox = QGroupBox(_("Subtitle format"))
layout = QGridLayout()
displayedFormats = list(self._formats.keys())
displayedFormats.sort()
self._outputFormat = QComboBox(self)
self._outputFormat.addItems(displayedFormats)
formatLabel = QLabel(_("Output format"))
layout.addWidget(self._outputFormat, 0, 0)
layout.addWidget(formatLabel, 0, 1)
groupbox.setLayout(layout)
return groupbox
开发者ID:mgoral,项目名称:subconvert,代码行数:14,代码来源:PropertyFileEditor.py
示例13: _createFpsBox
def _createFpsBox(self):
groupbox = QGroupBox(_("FPS"))
layout = QHBoxLayout()
self._autoFps = QCheckBox(_("Auto FPS"), self)
self._fps = QComboBox(self)
self._fps.addItems(["23.976", "24", "25", "29.97", "30"])
self._fps.setEditable(True)
layout.addWidget(self._autoFps)
layout.addWidget(self._fps)
groupbox.setLayout(layout)
return groupbox
开发者ID:mgoral,项目名称:subconvert,代码行数:14,代码来源:PropertyFileEditor.py
示例14: read
def read(self, encoding = None):
if encoding is None:
encoding = self.detectEncoding()
fileInput = []
try:
with open(self._filePath, mode='r', encoding=encoding) as file_:
fileInput = file_.readlines()
except LookupError as msg:
raise SubFileError(_("Unknown encoding name: '%s'.") % encoding)
except UnicodeDecodeError:
vals = {"file": self._filePath, "enc": encoding}
raise SubFileError(_("Cannot handle '%(file)s' with '%(enc)s' encoding.") % vals)
return fileInput
开发者ID:mgoral,项目名称:subconvert,代码行数:14,代码来源:SubFile.py
示例15: _addEncodingsBox
def _addEncodingsBox(self, row, addAuto):
mainLayout = self.layout()
encodingLabel = QLabel(_("File encoding:"), self)
self._encodingBox = QComboBox(self)
if addAuto is True:
self._encodingBox.addItem(AUTO_ENCODING_STR)
self._encodingBox.addItems(ALL_ENCODINGS)
self._encodingBox.setToolTip(_("Change file encoding"))
self._encodingBox.setEditable(True)
mainLayout.addWidget(encodingLabel, row, 0)
mainLayout.addWidget(self._encodingBox, row, 1)
开发者ID:mgoral,项目名称:subconvert,代码行数:14,代码来源:FileDialogs.py
示例16: changeSelectedFilesInputEncoding
def changeSelectedFilesInputEncoding(self, inputEncoding):
items = self.__fileList.selectedItems()
for item in items:
filePath = item.text(0)
data = self._subtitleData.data(filePath)
if data.inputEncoding != inputEncoding:
try:
data.encode(inputEncoding)
except UnicodeDecodeError:
# TODO: indicate with something more than log entry
log.error(_("Cannot decode subtitles to '%s' encoding.") % inputEncoding)
else:
command = ChangeData(filePath, data, _("Input encoding: %s") % inputEncoding)
self._subtitleData.execute(command)
开发者ID:mgoral,项目名称:subconvert,代码行数:14,代码来源:SubtitleTabs.py
示例17: _createButtons
def _createButtons(self):
widget = QWidget(self)
layout = QHBoxLayout()
self._openButton = QPushButton(_("Open"))
self._saveButton = QPushButton(_("Save"))
self._closeButton = QPushButton(_("Close"))
layout.addWidget(self._openButton)
layout.addWidget(self._saveButton)
layout.addWidget(self._closeButton)
widget.setLayout(layout)
return widget
开发者ID:mgoral,项目名称:subconvert,代码行数:14,代码来源:PropertyFileEditor.py
示例18: loadSpf
def loadSpf(formats, filePath):
try:
spf = SubtitleProperties(formats, filePath)
except FileNotFoundError:
log.critical(_("No such file: '%s'") % filePath)
sys.exit(2)
return spf
开发者ID:mgoral,项目名称:subconvert,代码行数:7,代码来源:apprunner.py
示例19: __init__
def __init__(self, filePath, oldSubtitle, newSubtitle, index, parent = None):
super(ChangeSubtitle, self).__init__(filePath, parent)
self.setText(_("Subtitle change (%d: %s)") % (int(index + 1), subExcerpt(newSubtitle)))
self._oldSubtitle = oldSubtitle
self._newSubtitle = newSubtitle
self._subNo = index
开发者ID:mgoral,项目名称:subconvert,代码行数:7,代码来源:SubtitleCommands.py
示例20: __initContextMenu
def __initContextMenu(self):
self._contextMenu = QMenu(self)
self.setContextMenuPolicy(Qt.CustomContextMenu)
af = ActionFactory(self)
insertSub = af.create(title = _("&Insert subtitle"), icon = "list-add",
connection = self.insertNewSubtitle)
self._contextMenu.addAction(insertSub)
insertSub = af.create(title = _("&Add subtitle"), icon = "list-add",
connection = self.addNewSubtitle)
self._contextMenu.addAction(insertSub)
removeSub = af.create(title = _("&Remove subtitles"), icon = "list-remove",
connection = self.removeSelectedSubtitles)
self._contextMenu.addAction(removeSub)
开发者ID:mgoral,项目名称:subconvert,代码行数:16,代码来源:SubtitleTabs.py
注:本文中的subconvert.utils.Locale._函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论