本文整理汇总了Python中Misc.time_in_ms_to_str方法的典型用法代码示例。如果您正苦于以下问题:Python Misc.time_in_ms_to_str方法的具体用法?Python Misc.time_in_ms_to_str怎么用?Python Misc.time_in_ms_to_str使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Misc
的用法示例。
在下文中一共展示了Misc.time_in_ms_to_str方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __repr__
# 需要导入模块: import Misc [as 别名]
# 或者: from Misc import time_in_ms_to_str [as 别名]
def __repr__(self):
str = 'Transcript Object:\n'
str = str + "Number = %s\n" % self.number
str = str + "ID = %s\n" % self.id
str = str + "Episode Number = %s\n" % self.episode_num
str = str + "Source Transcript = %s\n" % self.source_transcript
str = str + "Clip Number = %s\n" % self.clip_num
str = str + "Sort Order = %s\n" % self.sort_order
str = str + "Transcriber = %s\n" % self.transcriber
str = str + "Clip Start = %s\n" % Misc.time_in_ms_to_str(self.clip_start)
str = str + "Clip Stop = %s\n" % Misc.time_in_ms_to_str(self.clip_stop)
str = str + "Comment = %s\n" % self.comment
str += "MinTranscriptWidth = %s\n" % self.minTranscriptWidth
str = str + "LastSaveTime = %s\n" % self.lastsavetime
# str += "isLocked = %s\n" % self._isLocked
# str += "recordlock = %s\n" % self.recordlock
# str += "locktime = %s\n" % self.locktime
if len(self.text) > 250:
str = str + "text[:50] = %s\n\n" % self.text[:50]
else:
str = str + "text = %s\n\n" % self.text
return str.encode('utf8')
示例2: __repr__
# 需要导入模块: import Misc [as 别名]
# 或者: from Misc import time_in_ms_to_str [as 别名]
def __repr__(self):
str = 'Episode Object:\n'
str = str + "Number = %s\n" % self.number
str = str + "id = %s\n" % self.id
str = str + "comment = %s\n" % self.comment
str = str + "Media file 1 = %s\n" % self.media_filename
str = str + "Media File 1 Length = %s\n" % self.tape_length
str += "Media File 1 Offset = %s\n" % self.offset
str = str + "Additional media file:\n"
for addFile in self.additional_media_files:
str += ' %s %s %s %s\n' % (addFile['filename'], addFile['offset'], addFile['length'], addFile['audio'])
str += "Total adjusted Episode Length = %d (%s)\n" % (self.episode_length(), Misc.time_in_ms_to_str(self.episode_length()))
str = str + "Date = %s\n" % self.tape_date
str = str + "Series ID = %s\n" % self.series_id
str = str + "Series Num = %s\n" % self.series_num
str += "Keywords:\n"
for kw in self._kwlist:
str += ' ' + kw.keywordPair + '\n'
return str.encode('utf8')
示例3: OnItemSelected
# 需要导入模块: import Misc [as 别名]
# 或者: from Misc import time_in_ms_to_str [as 别名]
def OnItemSelected(self, event):
""" Process the selection of a clip to be merged with the original clip """
# Identify the selected item
self.mergeItemIndex = event.GetIndex()
# Get the Clip Data for the selected item
mergeClip = Clip.Clip(self.mergeList[self.mergeItemIndex][0])
# re-initialize the TRANSCRIPT start and stop times
self.transcript_clip_start = []
self.transcript_clip_stop = []
# Merge the clips.
# First, determine whether the merging clip comes BEFORE or after the original
if mergeClip.clip_start < self.obj.clip_start:
# The start value comes from the merge clip
self.clip_start_edit.SetValue(Misc.time_in_ms_to_str(mergeClip.clip_start))
# Update the merged clip Start Time
self.clip_start = mergeClip.clip_start
# The stop value comes from the original clip
self.clip_stop_edit.SetValue(Misc.time_in_ms_to_str(self.obj.clip_stop))
# Update the Clip Length
self.clip_length_edit.SetValue(Misc.time_in_ms_to_str(self.obj.clip_stop - mergeClip.clip_start))
# Update the merged clip Stop Time
self.clip_stop = self.obj.clip_stop
# For each of the original clip's Transcripts ...
for x in range(len(self.obj.transcripts)):
# We get the TRANSCRIPT start time from the merge clip
self.transcript_clip_start.append(mergeClip.transcripts[x].clip_start)
# We get the TRANSCRIPT end time from the original clip
self.transcript_clip_stop.append(self.obj.transcripts[x].clip_stop)
# If we're using the Rich Text Ctrl ...
if TransanaConstants.USESRTC:
# ... clear the transcript ...
self.text_edit[x].ClearDoc(skipUnlock = True)
# ... turn off read-only ...
self.text_edit[x].SetReadOnly(0)
# Create the Transana XML to RTC Import Parser. This is needed so that we can
# pull XML transcripts into the existing RTC. Pass the RTC to be edited.
handler = PyXML_RTCImportParser.XMLToRTCHandler(self.text_edit[x])
# Parse the merge clip transcript text, adding it to the RTC
xml.sax.parseString(mergeClip.transcripts[x].text, handler)
# Add a blank line
self.text_edit[x].Newline()
# ... trap exceptions here ...
try:
# ... insert a time code at the position of the clip break ...
self.text_edit[x].insert_timecode(self.obj.clip_start)
# If there were exceptions (duplicating time codes, for example), just skip it.
except:
pass
# Parse the original transcript text, adding it to the RTC
xml.sax.parseString(self.obj.transcripts[x].text, handler)
# If we're using the Styled Text Ctrl
else:
# ... clear the transcript ...
self.text_edit[x].ClearDoc()
# ... turn off read-only ...
self.text_edit[x].SetReadOnly(0)
# ... insert the merge clip's text, skipping whitespace at the end ...
self.text_edit[x].InsertRTFText(mergeClip.transcripts[x].text.rstrip())
# ... add a couple of line breaks ...
self.text_edit[x].InsertStyledText('\n\n', len('\n\n'))
# ... trap exceptions here ...
try:
# ... insert a time code at the position of the clip break ...
self.text_edit[x].insert_timecode(self.obj.clip_start)
# If there were exceptions (duplicating time codes, for example), just skip it.
except:
pass
# ... now add the original clip's text ...
self.text_edit[x].InsertRTFText(self.obj.transcripts[x].text)
# ... signal that time codes will be visible, which they always are in the Clip Properties ...
self.text_edit[x].codes_vis = 0
# ... scan transcript for Time Codes ...
self.text_edit[x].load_timecodes()
# ... display the time codes
self.text_edit[x].show_codes()
# If the merging clip comes AFTER the original ...
else:
# The start value comes from the original clip
self.clip_start_edit.SetValue(Misc.time_in_ms_to_str(self.obj.clip_start))
# Update the merged clip Start Time
self.clip_start = self.obj.clip_start
# The stop value comes from the merge clip
self.clip_stop_edit.SetValue(Misc.time_in_ms_to_str(mergeClip.clip_stop))
# Update the Clip Length
self.clip_length_edit.SetValue(Misc.time_in_ms_to_str(mergeClip.clip_stop - self.obj.clip_start))
# Update the merged clip Stop Time
self.clip_stop = mergeClip.clip_stop
# For each of the original clip's Transcripts ...
for x in range(len(self.obj.transcripts)):
# We get the TRANSCRIPT start time from the original clip
self.transcript_clip_start.append(self.obj.transcripts[x].clip_start)
# We get the TRANSCRIPT end time from the merge clip
self.transcript_clip_stop.append(mergeClip.transcripts[x].clip_stop)
# If we're using the Rich Text Ctrl ...
if TransanaConstants.USESRTC:
# ... clear the transcript ...
self.text_edit[x].ClearDoc(skipUnlock = True)
# ... turn off read-only ...
#.........这里部分代码省略.........
示例4: OnSnapshot
# 需要导入模块: import Misc [as 别名]
# 或者: from Misc import time_in_ms_to_str [as 别名]
def OnSnapshot(self, event):
""" Handle the Snapshot button press """
# Just because the media file is showing doesn't mean it's the CURRENT item in the Transana interface.
# Let's bring the Transcript forward, making the media file part of the CURRENT interface
self.parent.ControlObject.BringTranscriptToFront()
# Create the Media Conversion dialog, including Clip Information so we export only the clip segment
convertDlg = MediaConvert.MediaConvert(self, self.parent.ControlObject.currentObj.media_filename,
self.parent.ControlObject.GetVideoPosition(), snapshot=True)
# Show the Media Conversion Dialog
convertDlg.ShowModal()
# If the user took a snapshop and the image was successfully created ...
if convertDlg.snapshotSuccess and os.path.exists(convertDlg.txtDestFileName.GetValue() % 1):
imgFile = convertDlg.txtDestFileName.GetValue() % 1
# Set the field value to the file name selected
self.fname_edit.SetValue(imgFile)
# If the form's ID field is empty ...
if self.id_edit.GetValue() == '':
# ... get the base filename
tempFilename = os.path.basename(imgFile)
# ... separate the filename root and extension
(self.obj.id, tempExt) = os.path.splitext(tempFilename)
# ... and set the ID to match the base file name
self.id_edit.SetValue(self.obj.id)
# If the Snapshot comes from an Episode ...
if isinstance(self.parent.ControlObject.currentObj, Episode.Episode):
self.obj.series_num = self.parent.ControlObject.currentObj.series_num
self.obj.series_id = self.parent.ControlObject.currentObj.series_id
self.obj.episode_num = self.parent.ControlObject.currentObj.number
self.obj.episode_id = self.parent.ControlObject.currentObj.id
self.obj.transcript_num = self.parent.ControlObject.TranscriptWindow.dlg.editor.TranscriptObj.number
self.series_cb.SetStringSelection(self.obj.series_id)
self.PopulateEpisodeChoiceBasedOnSeries(self.obj.series_id)
self.episode_cb.SetStringSelection(self.obj.episode_id)
self.PopulateTranscriptChoiceBasedOnEpisode(self.obj.series_id, self.obj.episode_id)
tmpTranscript = Transcript.Transcript(self.obj.transcript_num)
self.transcript_cb.SetStringSelection(tmpTranscript.id)
self.obj.episode_start = self.parent.ControlObject.GetVideoPosition()
self.episode_start_edit.SetValue(Misc.time_in_ms_to_str(self.obj.episode_start))
self.episode_start_edit.Enable(True)
self.obj.episode_duration = 10000
self.episode_duration_edit.SetValue(Misc.time_in_ms_to_str(self.obj.episode_duration))
self.episode_duration_edit.Enable(True)
# If the Snapshot comes from a Clip ...
elif isinstance(self.parent.ControlObject.currentObj, Clip.Clip):
self.obj.episode_num = self.parent.ControlObject.currentObj.episode_num
tmpEpisode = Episode.Episode(self.obj.episode_num)
self.obj.series_num = tmpEpisode.series_num
self.obj.series_id = tmpEpisode.series_id
self.obj.episode_id = tmpEpisode.id
# We need the Clip's SOURCE TRANSCRIPT for the Active Transcript
self.obj.transcript_num = self.parent.ControlObject.currentObj.transcripts[self.parent.ControlObject.activeTranscript].source_transcript
self.series_cb.SetStringSelection(self.obj.series_id)
self.PopulateEpisodeChoiceBasedOnSeries(self.obj.series_id)
self.episode_cb.SetStringSelection(self.obj.episode_id)
self.PopulateTranscriptChoiceBasedOnEpisode(self.obj.series_id, self.obj.episode_id)
tmpTranscript = Transcript.Transcript(self.obj.transcript_num)
self.transcript_cb.SetStringSelection(tmpTranscript.id)
self.obj.episode_start = self.parent.ControlObject.currentObj.clip_start
self.episode_start_edit.SetValue(Misc.time_in_ms_to_str(self.obj.episode_start))
self.episode_start_edit.Enable(True)
self.obj.episode_duration = self.parent.ControlObject.currentObj.clip_stop - self.parent.ControlObject.currentObj.clip_start - 0.1
self.episode_duration_edit.SetValue(Misc.time_in_ms_to_str(self.obj.episode_duration))
self.episode_duration_edit.Enable(True)
# We need to explicitly Close the conversion dialog here to force cleanup of temp files in some circumstances
convertDlg.Close()
# Destroy the Media Conversion Dialog
convertDlg.Destroy()
示例5: __init__
# 需要导入模块: import Misc [as 别名]
# 或者: from Misc import time_in_ms_to_str [as 别名]
#.........这里部分代码省略.........
self.episode_cb.Bind(wx.EVT_CHOICE, self.OnEpisodeChoice)
self.episodeList = []
if self.obj.series_id != '':
self.PopulateEpisodeChoiceBasedOnSeries(self.obj.series_id)
# Add the row sizer to the main vertical sizer
mainSizer.Add(r4Sizer, 0, wx.EXPAND)
# Add a vertical spacer to the main sizer
mainSizer.Add((0, 10))
# Create a HORIZONTAL sizer for the next row
r5Sizer = wx.BoxSizer(wx.HORIZONTAL)
# Create a VERTICAL sizer for the next element
v6 = wx.BoxSizer(wx.VERTICAL)
# Episode ID
self.transcript_cb = self.new_choice_box(_("Transcript ID"), v6, [''])
# Add the element to the sizer
r5Sizer.Add(v6, 2, wx.EXPAND)
self.transcript_cb.Bind(wx.EVT_CHOICE, self.OnTranscriptChoice)
self.transcriptList = []
if self.obj.episode_id != '':
self.PopulateTranscriptChoiceBasedOnEpisode(self.obj.series_id, self.obj.episode_id)
# Add a horizontal spacer to the row sizer
r5Sizer.Add((10, 0))
# Create a VERTICAL sizer for the next element
v7 = wx.BoxSizer(wx.VERTICAL)
# Episode Time Code. Convert to HH:MM:SS.mm
self.episode_start_edit = self.new_edit_box(_("Episode Position"), v7, Misc.time_in_ms_to_str(self.obj.episode_start))
# Add the element to the sizer
r5Sizer.Add(v7, 1, wx.EXPAND)
if self.episode_cb.GetStringSelection() == '':
self.episode_start_edit.Enable(False)
# Add a horizontal spacer to the row sizer
r5Sizer.Add((10, 0))
# Create a VERTICAL sizer for the next element
v8 = wx.BoxSizer(wx.VERTICAL)
# Episode Duration. Convert to HH:MM:SS.mm
self.episode_duration_edit = self.new_edit_box(_("Duration"), v8, Misc.time_in_ms_to_str(self.obj.episode_duration))
# Add the element to the sizer
r5Sizer.Add(v8, 1, wx.EXPAND)
if self.episode_cb.GetStringSelection() == '':
self.episode_duration_edit.Enable(False)
# Add the row sizer to the main vertical sizer
mainSizer.Add(r5Sizer, 0, wx.EXPAND)
# Add a vertical spacer to the main sizer
mainSizer.Add((0, 10))
# Create a HORIZONTAL sizer for the next row
r6Sizer = wx.BoxSizer(wx.HORIZONTAL)
# Create a VERTICAL sizer for the next element
v9 = wx.BoxSizer(wx.VERTICAL)
# Comment
comment_edit = self.new_edit_box(_("Comment"), v9, self.obj.comment, maxLen=255)
# Add the element to the sizer
r6Sizer.Add(v9, 1, wx.EXPAND)
示例6: Export
# 需要导入模块: import Misc [as 别名]
# 或者: from Misc import time_in_ms_to_str [as 别名]
#.........这里部分代码省略.........
collectionID = collection.GetNodeString()
quoteID = quote.id
try:
document = Document.Document(quote.source_document_num)
documentID = document.id
quoteSourceFilename = document.imported_file
# If we're doing a Library report, we need the Quote's source document and Library for Document Filter comparison.
if self.libraryNum != 0:
library = Library.Library(document.library_num)
libraryID = library.id
# If we have an orphaned Quote ...
except TransanaExceptions.RecordNotFoundError, e:
# ... then we don't know these values!
documentID = ''
quoteSourceFilename = _('Source Document unknown')
libraryID = 0
# Implement Document filtering if needed. If we have a Library Report, we need to confirm that the Source Document
# is "checked" in the filter list. (If we don't have a Library Report, this check isn't needed.)
if (self.libraryNum == 0) or ((documentID == '') and (libraryID == '')) or ((documentID, libraryID, True) in documentList):
# Write the Quote's data values to the output file. We're creating a tab-delimited file,
# so we'll use tabs to separate the items.
f.write('%s\t%s\t%s\t%s\t%s\t%s\t%d' % (collectionID, '1', quoteID, quoteSourceFilename,
quote.start_char, quote.end_char,
(quote.end_char - quote.start_char)))
# Now we iterate through the keyword list ...
for keyword in keywordList:
# ... looking only at those keywords the user left "checked" in the filter dialog ...
if keyword[2]:
# ... and check to see if the Quote HAS the keyword.
if quote.has_keyword(keyword[0], keyword[1]):
# If so, we write a "1", indicating True.
f.write('\t1')
else:
# If not, we write a "0", indicating False.
f.write('\t0')
# Add a line break to signal the end of the Quote record
f.write('\n')
# Now iterate through the Clip List
for clipRec in clipList:
# See if the user has left the clip "checked" in the filter dialog.
# Also, if we are using a collection report, either Nested Data should be requested OR the current
# clip should be from the main collection if it is to be included in the report.
if clipRec[2] and ((self.collectionNum == 0) or (showNested) or (clipRec[1] == self.collectionNum)):
# Load the Clip data. The ClipLookup dictionary allows this easily.
# No need to load the Clip Transcripts, which can be slow to load.
clip = Clip.Clip(clipLookup[clipRec[0], clipRec[1]], skipText=True)
# Get the collection the clip is from.
collection = Collection.Collection(clip.collection_num)
# Encode string values using the Export Encoding
collectionID = collection.GetNodeString()
clipID = clip.id
clipMediaFilename = clip.media_filename
# If we're doing a Library report, we need the clip's source episode and Library for Episode Filter comparison.
if self.libraryNum != 0:
episode = Episode.Episode(clip.episode_num)
library = Library.Library(episode.series_num)
# Implement Episode filtering if needed. If we have a Library Report, we need to confirm that the Source Episode
# is "checked" in the filter list. (If we don't have a Library Report, this check isn't needed.)
if (self.libraryNum == 0) or ((episode.id, library.id, True) in episodeList):
# Write the Clip's data values to the output file. We're creating a tab-delimited file,
# so we'll use tabs to separate the items.
f.write('%s\t%s\t%s\t%s\t%s\t%s\t%10.4f' % (collectionID, '2', clipID, clipMediaFilename,
Misc.time_in_ms_to_str(clip.clip_start), Misc.time_in_ms_to_str(clip.clip_stop),
(clip.clip_stop - clip.clip_start) / 1000.0))
# Now we iterate through the keyword list ...
for keyword in keywordList:
# ... looking only at those keywords the user left "checked" in the filter dialog ...
if keyword[2]:
# ... and check to see if the Clip HAS the keyword.
if clip.has_keyword(keyword[0], keyword[1]):
# If so, we write a "1", indicating True.
f.write('\t1')
else:
# If not, we write a "0", indicating False.
f.write('\t0')
# Add a line break to signal the end of the Clip record
f.write('\n')
# Flush the output file's buffer (probably unnecessary)
f.flush()
# Close the output file.
f.close()
# Restore the cursor when we're done.
TransanaGlobal.menuWindow.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
# If so, create a prompt to inform the user and ask to overwrite the file.
if 'unicode' in wx.PlatformInfo:
# Encode with UTF-8 rather than TransanaGlobal.encoding because this is a prompt, not DB Data.
prompt = unicode(_('Clip Data has been exported to file "%s".'), 'utf8')
else:
prompt = _('Clip Data has been exported to file "%s".')
# Create the dialog to inform the user
dlg2 = Dialogs.InfoDialog(self, prompt % fs)
# Show the Info dialog.
dlg2.ShowModal()
# Destroy the Information dialog
dlg2.Destroy()
示例7: __init__
# 需要导入模块: import Misc [as 别名]
# 或者: from Misc import time_in_ms_to_str [as 别名]
def __init__(self, parent, id, title, clip_object, mergeList=None):
# If no Merge List is passed in ...
if mergeList == None:
# ... use the default Clip Properties Dialog size passed in from the config object. (This does NOT get saved.)
size = TransanaGlobal.configData.clipPropertiesSize
# ... we can enable Clip Change Propagation
propagateEnabled = True
HelpContext='Clip Properties'
# If we DO have a merge list ...
else:
# ... increase the size of the dialog to allow for the list of mergeable clips.
size = (TransanaGlobal.configData.clipPropertiesSize[0], TransanaGlobal.configData.clipPropertiesSize[1] + 130)
# ... and Clip Change Propagation should be disabled
propagateEnabled = False
HelpContext='Clip Merge'
# Make the Keyword Edit List resizable by passing wx.RESIZE_BORDER style. Signal that Propogation is included.
Dialogs.GenForm.__init__(self, parent, id, title, size=size, style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
propagateEnabled=propagateEnabled, useSizers = True, HelpContext=HelpContext)
if mergeList == None:
# Define the minimum size for this dialog as the initial size
minWidth = 750
minHeight = 570
else:
# Define the minimum size for this dialog as the initial size
minWidth = 750
minHeight = 650
# Remember the Parent Window
self.parent = parent
# Remember the original Clip Object passed in
self.obj = clip_object
# Add a placeholder to the clip object for the merge clip number
self.obj.mergeNumber = 0
# Remember the merge list, if one is passed in
self.mergeList = mergeList
# Initialize the merge item as unselected
self.mergeItemIndex = -1
# if Keywords that server as Keyword Examples are removed, we will need to remember them.
# Then, when OK is pressed, the Keyword Example references in the Database Tree can be removed.
# We can't remove them immediately in case the whole Clip Properties Edit process is cancelled.
self.keywordExamplesToDelete = []
# Initialize a variable to hold merged keyword examples.
self.mergedKeywordExamples = []
# Create the form's main VERTICAL sizer
mainSizer = wx.BoxSizer(wx.VERTICAL)
# If we're merging Clips ...
if self.mergeList != None:
# ... display a label for the Merge Clips ...
lblMergeClip = wx.StaticText(self.panel, -1, _("Clip to Merge"))
mainSizer.Add(lblMergeClip, 0)
# Add a vertical spacer to the main sizer
mainSizer.Add((0, 3))
# Create a HORIZONTAL sizer for the merge information
mergeSizer = wx.BoxSizer(wx.HORIZONTAL)
# ... display a ListCtrl for the Merge Clips ...
self.mergeClips = wx.ListCtrl(self.panel, -1, size=(300, 100), style=wx.LC_REPORT | wx.LC_SINGLE_SEL)
# Add the element to the sizer
mergeSizer.Add(self.mergeClips, 1, wx.EXPAND)
# ... bind the Item Selected event for the List Control ...
self.mergeClips.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected)
# ... define the columns for the Merge Clips ...
self.mergeClips.InsertColumn(0, _('Clip Name'))
self.mergeClips.InsertColumn(1, _('Collection'))
self.mergeClips.InsertColumn(2, _('Start Time'))
self.mergeClips.InsertColumn(3, _('Stop Time'))
self.mergeClips.SetColumnWidth(0, 244)
self.mergeClips.SetColumnWidth(1, 244)
# ... and populate the Merge Clips list from the mergeList data
for (ClipNum, ClipID, CollectNum, CollectID, ClipStart, ClipStop, transcriptCount) in self.mergeList:
index = self.mergeClips.InsertStringItem(sys.maxint, ClipID)
self.mergeClips.SetStringItem(index, 1, CollectID)
self.mergeClips.SetStringItem(index, 2, Misc.time_in_ms_to_str(ClipStart))
self.mergeClips.SetStringItem(index, 3, Misc.time_in_ms_to_str(ClipStop))
# Add the row sizer to the main vertical sizer
mainSizer.Add(mergeSizer, 3, wx.EXPAND)
# Add a vertical spacer to the main sizer
mainSizer.Add((0, 10))
# Create a HORIZONTAL sizer for the first row
r1Sizer = wx.BoxSizer(wx.HORIZONTAL)
# Create a VERTICAL sizer for the next element
v1 = wx.BoxSizer(wx.VERTICAL)
# Clip ID
self.id_edit = self.new_edit_box(_("Clip ID"), v1, self.obj.id, maxLen=100)
# Add the element to the sizer
r1Sizer.Add(v1, 1, wx.EXPAND)
# Add a horizontal spacer to the row sizer
r1Sizer.Add((10, 0))
#.........这里部分代码省略.........
示例8: tape_length_str
# 需要导入模块: import Misc [as 别名]
# 或者: from Misc import time_in_ms_to_str [as 别名]
def tape_length_str(self):
"""Return a string representation (HH:MM:SS) of tape length."""
return Misc.time_in_ms_to_str(self.episode_length())
示例9: DisplayCells
# 需要导入模块: import Misc [as 别名]
# 或者: from Misc import time_in_ms_to_str [as 别名]
#.........这里部分代码省略.........
cellData[(snapshot['SnapshotStart'], snapshot['SnapshotStop'], tmpObj.GetNodeString(True).upper())] = tmpObj
# Get the Keys for the cellData
sortedKeys = cellData.keys()
# Sort the keys for the cellData into the right order
sortedKeys.sort()
# Add rows to the Grid to accomodate the amount of data returned, or delete rows if we have too many
if len(cellData) > self.gridClips.GetNumberRows():
self.gridClips.AppendRows(len(cellData) - self.gridClips.GetNumberRows(), False)
elif len(cellData) < self.gridClips.GetNumberRows():
self.gridClips.DeleteRows(numRows = self.gridClips.GetNumberRows() - len(cellData))
# Initialize the Row Counter
loop = 0
# Add the data to the Grid
for keyVals in sortedKeys:
# If we have a Clip ...
if isinstance(cellData[keyVals], Clip.Clip):
# ... get the start, stop times and the object type
startTime = cellData[keyVals].clip_start
stopTime = cellData[keyVals].clip_stop
objType = 'Clip'
# Initialize the string for all the Keywords to blank
kwString = unicode('', 'utf8')
# Initialize the prompt for building the keyword string
kwPrompt = '%s'
# If we have a Snapshot ...
elif isinstance(cellData[keyVals], Snapshot.Snapshot):
# ... get the start, stop times and the object type
startTime = cellData[keyVals].episode_start
stopTime = cellData[keyVals].episode_start + cellData[keyVals].episode_duration
objType = 'Snapshot'
# if there are whole snapshot keywords ...
if len(cellData[keyVals].keyword_list) > 0:
# ... initialize the string for all the Keywords to indicate this
kwString = unicode(_('Whole:'), 'utf8') + '\n'
# If there are NOT whole snapshot keywords ...
else:
# ... initialize the string for all the Keywords to blank
kwString = unicode('', 'utf8')
# Initialize the prompt for building the keyword string
kwPrompt = ' %s'
# For each Keyword in the Keyword List ...
for kws in cellData[keyVals].keyword_list:
# ... add the Keyword to the Keyword List
kwString += kwPrompt % kws.keywordPair
# If we have a Clip ...
if isinstance(cellData[keyVals], Clip.Clip):
# After the first keyword, we need a NewLine in front of the Keywords. This accompishes that!
kwPrompt = '\n%s'
# If we have a Snapshot ...
elif isinstance(cellData[keyVals], Snapshot.Snapshot):
# After the first keyword, we need a NewLine in front of the Keywords. This accompishes that!
kwPrompt = '\n %s'
# If we have a Snapshot, we also want to display CODED Keywords in addition to the WHOLE Snapshot keywords
# we've already included
if isinstance(cellData[keyVals], Snapshot.Snapshot):
# Keep a list of the coded keywords we've already displayed
codedKeywords = []
# Modify the template for additional keywords
kwPrompt = '\n %s : %s'
# For each of the Snapshot's Coding Objects ...
for x in range(len(cellData[keyVals].codingObjects)):
# ... if the Coding Object is visible and if it is not already in the codedKeywords list ...
if (cellData[keyVals].codingObjects[x]['visible']) and \
(not (cellData[keyVals].codingObjects[x]['keywordGroup'], cellData[keyVals].codingObjects[x]['keyword']) in codedKeywords):
# ... if this is the FIRST Coded Keyword ...
if len(codedKeywords) == 0:
# ... and if there WERE Whole Snapshot Keywords ...
if len(kwString) > 0:
# ... then add a line break to the Keywords String ...
kwString += '\n'
# ... add the indicator to the Keywords String that we're starting to show Coded Keywords
kwString += unicode(_('Coded:'), 'utf8')
# ... add the coded keyword to the Keywords String ...
kwString += kwPrompt % (cellData[keyVals].codingObjects[x]['keywordGroup'], cellData[keyVals].codingObjects[x]['keyword'])
# ... add the keyword to the Coded Keywords list
codedKeywords.append((cellData[keyVals].codingObjects[x]['keywordGroup'], cellData[keyVals].codingObjects[x]['keyword']))
# Insert the data values into the Grid Row
# Start and Stop time in column 0
self.gridClips.SetCellValue(loop, 0, "%s -\n %s" % (Misc.time_in_ms_to_str(startTime), Misc.time_in_ms_to_str(stopTime)))
# Node String (including Item name) in column 1
self.gridClips.SetCellValue(loop, 1, cellData[keyVals].GetNodeString(True))
# make the Collection / Item ID line auto-word-wrap
self.gridClips.SetCellRenderer(loop, 1, grid.GridCellAutoWrapStringRenderer())
# Keywords in column 2
self.gridClips.SetCellValue(loop, 2, kwString)
# Item Number (hidden) in column 3. Convert value to a string
self.gridClips.SetCellValue(loop, 3, "%s" % cellData[keyVals].number)
# Item Type (hidden) in column 4
self.gridClips.SetCellValue(loop, 4, "%s" % objType)
# Auto-size THIS row
self.gridClips.AutoSizeRow(loop, True)
# Increment the Row Counter
loop += 1
# Select the first cell
self.gridClips.SetGridCursor(0, 0)
示例10: __init__
# 需要导入模块: import Misc [as 别名]
# 或者: from Misc import time_in_ms_to_str [as 别名]
#.........这里部分代码省略.........
# Initialize and fill the initial data structure that will be turned into the report
self.data = []
# Create a Dictionary Data Structure to accumulate Keyword Counts
keywordCounts = {}
# The majorList and minorList are constructed differently for the Episode version of the report,
# and so the report must be built differently here too!
if episodeName == None:
if 'unicode' in wx.PlatformInfo:
# Encode with UTF-8 rather than TransanaGlobal.encoding because this is a prompt, not DB Data.
majorLabel = unicode(majorLabel, 'utf8')
# Iterate through the major list
for (groupNo, group, parentCollNo) in majorList:
# Use the group name as a Heading
self.data.append((('Subheading', '%s %s' % (majorLabel, group)),))
# Iterate through the list of Keywords for the group
for (keywordGroup, keyword, example) in minorList[group]:
# Use the Keyword name as a Subheading
self.data.append((('Subtext', '%s : %s' % (keywordGroup, keyword)),))
# Add this Keyword to the Keyword Counts
if keywordCounts.has_key('%s : %s' % (keywordGroup, keyword)):
keywordCounts['%s : %s' % (keywordGroup, keyword)] = keywordCounts['%s : %s' % (keywordGroup, keyword)] + 1
else:
keywordCounts['%s : %s' % (keywordGroup, keyword)] = 1
# Add a blank line after each group
self.data.append((('Normal', ''),))
else:
# Iterate through the major list
for clipRecord in majorList:
# Use the group name as a Heading
if 'unicode' in wx.PlatformInfo:
# Encode with UTF-8 rather than TransanaGlobal.encoding because this is a prompt, not DB Data.
prompt = unicode(_('Collection: %s, Clip: %s'), 'utf8')
else:
prompt = _('Collection: %s, Clip: %s')
self.data.append((('Subheading', prompt % (clipRecord['CollectID'], clipRecord['ClipID'])), ('NormalRight', '(%s - %s)' % (Misc.time_in_ms_to_str(clipRecord['ClipStart']), Misc.time_in_ms_to_str(clipRecord['ClipStop'])))))
# Iterate through the list of Keywords for the group
for (keywordGroup, keyword, example) in minorList[(clipRecord['ClipID'], clipRecord['CollectID'], clipRecord['ParentCollectNum'])]:
# Use the Keyword name as a Subheading
self.data.append((('Subtext', '%s : %s' % (keywordGroup, keyword)),))
# Add this Keyword to the Keyword Counts
if keywordCounts.has_key('%s : %s' % (keywordGroup, keyword)):
keywordCounts['%s : %s' % (keywordGroup, keyword)] = keywordCounts['%s : %s' % (keywordGroup, keyword)] + 1
else:
keywordCounts['%s : %s' % (keywordGroup, keyword)] = 1
# Add a blank line after each group
self.data.append((('Normal', ''),))
# If there's data in the majorList ...
if len(majorList) != 0:
# Now add the Report Summary
self.data.append((('Subheading', _('Summary')),))
# Get a list of the Keyword Group : Keyword pairs that have been used
countKeys = keywordCounts.keys()
# Sort the list
countKeys.sort()
# Add the sorted keywords to the summary with their counts
for key in countKeys:
self.data.append((('Subtext', key), ('NormalRight', '%s' % keywordCounts[key])))
# The initial data structure needs to be prepared. What PrepareData() does is to create a graphic
# object that is the correct size and dimensions for the type of paper selected, and to create
# a datastructure that breaks the data sent in into separate pages, again based on the dimensions
# of the paper currently selected.
(self.graphic, self.pageData) = ReportPrintoutClass.PrepareData(TransanaGlobal.printData, self.title, self.data, self.subtitle)
# Send the results of the PrepareData() call to the MyPrintout object, once for the print preview
# version and once for the printer version.
printout = ReportPrintoutClass.MyPrintout(self.title, self.graphic, self.pageData, self.subtitle)
printout2 = ReportPrintoutClass.MyPrintout(self.title, self.graphic, self.pageData, self.subtitle)
# Create the Print Preview Object
self.preview = wx.PrintPreview(printout, printout2, TransanaGlobal.printData)
# Check for errors during Print preview construction
if not self.preview.Ok():
dlg = Dialogs.ErrorDialog(None, _("Print Preview Problem"))
dlg.ShowModal()
dlg.Destroy()
return
# Create the Frame for the Print Preview
theWidth = max(wx.ClientDisplayRect()[2] - 180, 760)
theHeight = max(wx.ClientDisplayRect()[3] - 200, 560)
frame = wx.PreviewFrame(self.preview, None, _("Print Preview"), size=(theWidth, theHeight))
frame.Centre()
# Initialize the Frame for the Print Preview
frame.Initialize()
# Display the Print Preview Frame
frame.Show(True)
# If there's NO data in the majorList ...
else:
# If there are no clips to report, display an error message.
if 'unicode' in wx.PlatformInfo:
# Encode with UTF-8 rather than TransanaGlobal.encoding because this is a prompt, not DB Data.
prompt = unicode(_('%s has no data for the Keyword Usage Report.'), 'utf8')
else:
prompt = _('%s has no data for the Keyword Usage Report.')
dlg = wx.MessageDialog(None, prompt % self.subtitle, style = wx.OK | wx.ICON_EXCLAMATION)
dlg.ShowModal()
dlg.Destroy()
示例11: Export
# 需要导入模块: import Misc [as 别名]
# 或者: from Misc import time_in_ms_to_str [as 别名]
#.........这里部分代码省略.........
# if the specified file has no path specification ...
if fs.find(os.sep) == -1:
# ... then prepend the HOME folder
fs = os.getenv("HOME") + os.sep + fs
# Open the output file for writing.
f = codecs.open(fs, 'w', 'utf8') # file(fs, 'w')
prompt = unicode(_('Collection Name\tClip Name\tMedia File\tClip Start\tClip End\tClip Length (seconds)'), 'utf8')
# If the user does NOT want UTF-8 Encoding, then encode the data using EXPORT_ENCODING
## if not utfEncodingRequested:
## prompt = prompt.encode(EXPORT_ENCODING, 'backslashreplace')
# Write the Header line. We're creating a tab-delimited file, so we'll use tabs to separate the items.
f.write(prompt)
# Add keywords to the Header. Iterate through the Keyword List.
for keyword in keywordList:
# See if the user has left the keyword "checked" in the filter dialog.
if keyword[2]:
## # If the user does NOT want UTF-8 Encoding, then encode the data using EXPORT_ENCODING
## if not utfEncodingRequested:
## # Encode and write all "checked" keywords to the Header.
## kwg = keyword[0].encode(EXPORT_ENCODING, 'backslashreplace')
## kw = keyword[1].encode(EXPORT_ENCODING, 'backslashreplace')
## else:
# Encode and write all "checked" keywords to the Header.
kwg = keyword[0]
kw = keyword[1]
f.write('\t%s : %s' % (kwg, kw))
# Add a line break to signal the end of the Header line.
f.write('\n')
# Now iterate through the Clip List
for clipRec in clipList:
# See if the user has left the clip "checked" in the filter dialog.
# Also, if we are using a collection report, either Nested Data should be requested OR the current
# clip should be from the main collection if it is to be included in the report.
if clipRec[2] and ((self.collectionNum == 0) or (showNested) or (clipRec[1] == self.collectionNum)):
# Load the Clip data. The ClipLookup dictionary allows this easily.
# No need to load the Clip Transcripts, which can be slow to load.
clip = Clip.Clip(clipLookup[clipRec[0], clipRec[1]], skipText=True)
# Get the collection the clip is from.
collection = Collection.Collection(clip.collection_num)
## # If the user does NOT want UTF-8 Encoding, then encode the data using EXPORT_ENCODING
## if not utfEncodingRequested:
## # Encode string values using the Export Encoding
## collectionID = collection.GetNodeString().encode(EXPORT_ENCODING, 'backslashreplace') # clip.collection_id.encode(EXPORT_ENCODING)
## clipID = clip.id.encode(EXPORT_ENCODING, 'backslashreplace')
## clipMediaFilename = clip.media_filename.encode(EXPORT_ENCODING, 'backslashreplace')
## else:
# Encode string values using the Export Encoding
collectionID = collection.GetNodeString()
clipID = clip.id
clipMediaFilename = clip.media_filename
# If we're doing a Series report, we need the clip's source episode and Series for Episode Filter comparison.
if self.seriesNum != 0:
episode = Episode.Episode(clip.episode_num)
series = Series.Series(episode.series_num)
# Implement Episode filtering if needed. If we have a Series Report, we need to confirm that the Source Episode
# is "checked" in the filter list. (If we don't have a Series Report, this check isn't needed.)
if (self.seriesNum == 0) or ((episode.id, series.id, True) in episodeList):
# Write the Clip's data values to the output file. We're creating a tab-delimited file,
# so we'll use tabs to separate the items.
f.write('%s\t%s\t%s\t%s\t%s\t%10.4f' % (collectionID, clipID, clipMediaFilename,
Misc.time_in_ms_to_str(clip.clip_start), Misc.time_in_ms_to_str(clip.clip_stop),
(clip.clip_stop - clip.clip_start) / 1000.0))
# Now we iterate through the keyword list ...
for keyword in keywordList:
# ... looking only at those keywords the user left "checked" in the filter dialog ...
if keyword[2]:
# ... and check to see if the Clip HAS the keyword.
if clip.has_keyword(keyword[0], keyword[1]):
# If so, we write a "1", indicating True.
f.write('\t1')
else:
# If not, we write a "0", indicating False.
f.write('\t0')
# Add a line break to signal the end of the Clip record
f.write('\n')
# Flush the output file's buffer (probably unnecessary)
f.flush()
# Close the output file.
f.close()
# Restore the cursor when we're done.
TransanaGlobal.menuWindow.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
# If so, create a prompt to inform the user and ask to overwrite the file.
if 'unicode' in wx.PlatformInfo:
# Encode with UTF-8 rather than TransanaGlobal.encoding because this is a prompt, not DB Data.
prompt = unicode(_('Clip Data has been exported to file "%s".'), 'utf8')
else:
prompt = _('Clip Data has been exported to file "%s".')
# Create the dialog to inform the user
dlg2 = Dialogs.InfoDialog(self, prompt % fs)
# Show the Info dialog.
dlg2.ShowModal()
# Destroy the Information dialog
dlg2.Destroy()
# Destroy the Filter Dialog. We're done with it.
dlgFilter.Destroy()
示例12: RunTests
# 需要导入模块: import Misc [as 别名]
# 或者: from Misc import time_in_ms_to_str [as 别名]
def RunTests(self):
# Tests defined:
testsNotToSkip = []
startAtTest = 1 # Should start at 1, not 0!
endAtTest = 500 # Should be one more than the last test to be run!
testsToRun = testsNotToSkip + range(startAtTest, endAtTest)
t = datetime.datetime.now()
if 10 in testsToRun:
# dt_to_datestr
testName = 'Misc.dt_to_datestr()'
self.SetStatusText(testName)
prompt = 'Raw Date/Time information: %s\n\n Is the correct M/D/Y formatted date string "%s"?' % (t, Misc.dt_to_datestr(t))
self.ConfirmTest(prompt, testName)
if 20 in testsToRun:
# time_in_ms_to_str
testName = 'Misc.time_in_ms_to_str()'
self.SetStatusText(testName)
prompt = 'Are the following time to string conversions correct?\n\nTime in ms:\ttime_in_ms_to_str():\n'
for x in [100, 200, 1000, 2000, 10000, 20000, 60000, 120000, 600000, 1200000, 3600000, 7200000]:
prompt += " %12d\t %s\n" % (x, Misc.time_in_ms_to_str(x))
self.ConfirmTest(prompt, testName)
if 30 in testsToRun:
# TimeMsToStr
testName = 'Misc.TimeMsToStr()'
self.SetStatusText(testName)
prompt = 'Are the following time to string conversions correct?\n\nTime in ms:\tTimeMsToStr():\n'
for x in [1000, 2000, 10000, 20000, 60000, 120000, 600000, 1200000, 3600000, 7200000]:
prompt += " %12d\t %s\n" % (x, Misc.TimeMsToStr(x))
self.ConfirmTest(prompt, testName)
if 40 in testsToRun:
# time_in_str_to_ms
testName = 'Misc.time_in_str_to_ms()'
self.SetStatusText(testName)
prompt = 'Are the following string to time conversions correct?\n\nTime in string:\ttime_in_str_to_ms():\n'
for x in ['0:00:00.1', '0:00:00.2', '0:00:01.0', '0:00:02.0', '0:00:10.0', '0:00:20.0', '0:01:00.0', '0:02:00.0', '0:10:00.0', '0:20:00.0', '1:00:00.0', '2:00:00.0']:
prompt += " %s\t %12d\n" % (x, Misc.time_in_str_to_ms(x))
self.ConfirmTest(prompt, testName)
if 100 in testsToRun:
# English
testName = 'English translation'
langName = 'en'
lang = wx.LANGUAGE_ENGLISH
self.presLan_en = gettext.translation('Transana', 'locale', languages=['en']) # English
self.presLan_en.install()
self.locale = wx.Locale(lang)
self.locale.AddCatalog("Transana")
prompt = '%s: Series = %s (%s)\n' % (langName, _('Series'), type(_('Series')))
prompt += ' Collection = %s (%s)\n' % ( _('Collection'), type(_('Collection')))
prompt += ' Keyword = %s (%s)\n' % ( _('Keyword'), type(_('Keyword')))
prompt += ' Search = %s (%s)\n' % ( _('Search'), type(_('Search')))
self.ConfirmTest(prompt, testName)
if 110 in testsToRun:
# Arabic
testName = 'Arabic translation'
langName = 'ar'
lang = wx.LANGUAGE_ARABIC
self.presLan_ar = gettext.translation('Transana', 'locale', languages=['ar']) # Arabic
self.presLan_ar.install()
self.locale = wx.Locale(lang)
prompt = '%s: Series = %s (%s)\n' % (langName, _('Series'), type(_('Series')))
prompt += ' Collection = %s (%s)\n' % ( _('Collection'), type(_('Collection')))
prompt += ' Keyword = %s (%s)\n' % ( _('Keyword'), type(_('Keyword')))
prompt += ' Search = %s (%s)\n' % ( _('Search'), type(_('Search')))
self.ConfirmTest(prompt, testName)
if 120 in testsToRun:
# Danish
testName = 'Danish translation'
langName = 'da'
lang = wx.LANGUAGE_DANISH
self.presLan_da = gettext.translation('Transana', 'locale', languages=['da']) # Danish
self.presLan_da.install()
self.locale = wx.Locale(lang)
prompt = '%s: Series = %s (%s)\n' % (langName, _('Series'), type(_('Series')))
prompt += ' Collection = %s (%s)\n' % ( _('Collection'), type(_('Collection')))
prompt += ' Keyword = %s (%s)\n' % ( _('Keyword'), type(_('Keyword')))
prompt += ' Search = %s (%s)\n' % ( _('Search'), type(_('Search')))
self.ConfirmTest(prompt, testName)
if 130 in testsToRun:
# German
testName = 'German translation'
langName = 'de'
lang = wx.LANGUAGE_GERMAN
self.presLan_de = gettext.translation('Transana', 'locale', languages=['de']) # German
self.presLan_de.install()
self.locale = wx.Locale(lang)
prompt = '%s: Series = %s (%s)\n' % (langName, _('Series'), type(_('Series')))
prompt += ' Collection = %s (%s)\n' % ( _('Collection'), type(_('Collection')))
prompt += ' Keyword = %s (%s)\n' % ( _('Keyword'), type(_('Keyword')))
prompt += ' Search = %s (%s)\n' % ( _('Search'), type(_('Search')))
self.ConfirmTest(prompt, testName)
#.........这里部分代码省略.........