本文整理汇总了Python中Misc类的典型用法代码示例。如果您正苦于以下问题:Python Misc类的具体用法?Python Misc怎么用?Python Misc使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Misc类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SelectCell
def SelectCell(self, col, row):
""" Handle the selection of an individual cell in the Grid """
# If we're in the "Time" column ...
if col == 0:
# ... determine the time of the selected item
times = self.gridClips.GetCellValue(row, col).split('-')
# ... and move to that time
self.ControlObject.SetVideoStartPoint(Misc.time_in_str_to_ms(times[0]))
# Retain the program focus in the Data Window
self.gridClips.SetFocus()
# If we're in the "ID" or "Keywords" column ...
else:
# ... if we have a Clip ...
if self.gridClips.GetCellValue(row, 4) == 'Clip':
# Load the Clip
# Switched to CallAfter because of crashes on the Mac.
wx.CallAfter(self.ControlObject.LoadClipByNumber, int(self.gridClips.GetCellValue(row, 3)))
# NOTE: LoadClipByNumber eliminates the DataItemsTab, so no further processing can occur!!
# There used to be code here to select the Clip in the Database window, but it stopped
# working when I added multiple transcripts, so I moved it to the ControlObject.LoadClipByNumber()
# method.
# ... if we have a Snapshot ...
elif self.gridClips.GetCellValue(row, 4) == 'Snapshot':
tmpSnapshot = Snapshot.Snapshot(int(self.gridClips.GetCellValue(row, 3)))
# ... load the Snapshot
self.ControlObject.LoadSnapshot(tmpSnapshot)
# ... determine the time of the selected item
times = self.gridClips.GetCellValue(row, 0).split('-')
# ... and move to that time
self.ControlObject.SetVideoStartPoint(Misc.time_in_str_to_ms(times[0]))
# ... and set the program focus on the Snapshot
self.ControlObject.SelectSnapshotWindow(tmpSnapshot.id, tmpSnapshot.number, selectInDataWindow=True)
示例2: predict_round
def predict_round(self, tourney_round, analysis):
"""
:method: Predict winner of a single round of the tournament.
:param int tourney_round: round of the tournament to predict.
:param object analysis: Analysis object
"""
Misc.check_input_data("Kaggle", "tourney_slots")
last_round_id_2digit = "R%02d" % (tourney_round - 1)
current_round_id_1digit = "R%d" % tourney_round
current_round_id_2digit = "R%02d" % tourney_round
df = Constants.INPUT_DATA['Kaggle']['tourney_slots']
tourney_slots = df[df.season == self.season_id] # slice of tourney_slots DataFrame for current season
for _id, row in tourney_slots.iterrows():
if row.slot[:2] == current_round_id_1digit:
if tourney_round == 6:
strongseed = row.strongseed[-2:]
weakseed = row.weakseed[-2:]
else:
strongseed = self.zero_pad_seed(row.strongseed)
weakseed = self.zero_pad_seed(row.weakseed)
team_1 = self.bracket[last_round_id_2digit][strongseed]
team_2 = self.bracket[last_round_id_2digit][weakseed]
if not team_1 or not team_2:
raise Exception("Cannot predict round '%s', do not have results from prior round." % tourney_round)
winner = analysis.predict_winner(team_1, team_2, self.season_id)
if tourney_round == 5:
slot = row.slot[-2:]
else:
slot = self.zero_pad_seed(row.slot[-2:])
self.bracket[current_round_id_2digit][slot] = winner
示例3: populate_1st_round
def populate_1st_round(self, analysis):
"""
:method: Populate 1st round of bracket with teams.
:param object analysis: Analysis object
"""
Misc.check_input_data("Kaggle", "tourney_slots")
Misc.check_input_data("Kaggle", "tourney_seeds")
#variable init
round_1 = "R00"
# predict winners for play-in games
df = Constants.INPUT_DATA['Kaggle']['tourney_slots']
tourney_slots = df[df.season == self.season_id] # slice of tourney_slots DataFrame for current season
for _id, row in tourney_slots.iterrows():
if row.slot[0] != "R":
# play-in game
team_1 = self.get_team_by_seed(row.strongseed)
team_2 = self.get_team_by_seed(row.weakseed)
winner = analysis.predict_winner(team_1, team_2, self.season_id)
slot = self.zero_pad_seed(row.slot)
self.bracket[round_1][slot] = winner
# populate non-play-in teams
df = Constants.INPUT_DATA['Kaggle']['tourney_seeds']
tourney_seeds = df[df.season == self.season_id] # slice of tourney_seeds DataFrame for current season
for _id, row in tourney_seeds.iterrows():
if len(row.seed) == 3:
self.bracket[round_1][row.seed] = self.get_team_by_seed(row.seed)
示例4: data_available
def data_available(self, season_id):
Misc.check_input_data("Kaggle", "tourney_seeds", raise_exception=True)
tournament_year = Constants.SEASON_ID_TO_YEAR.get(season_id)
file_name = 'summary%s' % str(tournament_year)[-2:]
result = Misc.check_input_data("KenPomWithIds", file_name, raise_exception=False)
return result
示例5: OnSSLButton
def OnSSLButton(self, event):
""" Handle the Browse buttons for the SSL Client Certificate and the SSL CLient Key file fields """
# Define the File Type as *.pem files
fileType = '*.pem'
fileTypesString = _("SSL Certificate Files (*.pem)|*.pem|All files (*.*)|*.*")
if event.GetId() == self.sslClientCertBrowse.GetId():
prompt = _("Select the SSL Client Certificate file")
fileName = self.sslClientCert.GetValue()
elif event.GetId() == self.sslClientKeyBrowse.GetId():
prompt = _("Select the SSL Client Key file")
fileName = self.sslClientKey.GetValue()
elif event.GetId() == self.sslMsgSrvCertBrowse.GetId():
prompt = _("Select the SSL Message Server Certificate file")
fileName = self.sslMsgSrvCert.GetValue()
(path, flnm) = os.path.split(fileName)
if path != '':
self.sslDir = path
# Invoke the File Selector with the proper default directory, filename, file type, and style
fs = wx.FileSelector(prompt, self.sslDir, fileName, fileType, fileTypesString, wx.OPEN | wx.FILE_MUST_EXIST)
# If user didn't cancel ..
if fs != "":
# Mac Filenames use a different encoding system. We need to adjust the string returned by the FileSelector.
# Surely there's an easier way, but I can't figure it out.
if 'wxMac' in wx.PlatformInfo:
import Misc
fs = Misc.convertMacFilename(fs)
if event.GetId() == self.sslClientCertBrowse.GetId():
self.sslClientCert.SetValue(fs)
elif event.GetId() == self.sslClientKeyBrowse.GetId():
self.sslClientKey.SetValue(fs)
elif event.GetId() == self.sslMsgSrvCertBrowse.GetId():
self.sslMsgSrvCert.SetValue(fs)
(path, flnm) = os.path.split(fs)
if path != '':
self.sslDir = path
示例6: get_team_by_seed
def get_team_by_seed(self, seed):
"""
:method: Get team object from tournament seed string.
:param string seed: tournament seed string
:returns: Team object
:rtype: object
"""
Misc.check_input_data("Kaggle", "tourney_seeds")
df = Constants.INPUT_DATA['Kaggle']['tourney_seeds']
team_df = df[(df.season == self.season_id) & (df.seed == seed)]
if not team_df.empty:
team_id = team_df.team.iloc[0]
team = self.team_factory.get_team(team_id)
else:
team = None
return team
示例7: add_all_teams
def add_all_teams(self):
""":method: Build objects for all teams from Kaggle data & add them to factory."""
Misc.check_input_data("Kaggle", "tourney_seeds")
Misc.check_input_data("Kaggle", "teams")
df_seeds = Constants.INPUT_DATA['Kaggle']['tourney_seeds']
for _id, row in df_seeds.iterrows():
# variable init
season_id = row.season
team_id = int(row.team)
tourney_seed = row.seed
df_teams = Constants.INPUT_DATA['Kaggle']['teams']
team_name = df_teams[df_teams.id == team_id].name.iloc[0]
# create Team object
team = self.get_team(team_id)
if not team:
team = self.add_team(team_id, team_name)
season = team.add_season(season_id)
season.set_tourney_seed(tourney_seed)
示例8: testDot
def testDot(fpath):
try:
cmd = "%s -V" % (fpath)
(sts,sout,serr) = Misc.safeCommandOutput(cmd)
if sts != -1:
if "version" in sout + serr:
return True
except:
pass
return False
示例9: __repr__
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')
示例10: ScytherIcon
def ScytherIcon(window):
""" Set a nice Scyther icon """
import os,inspect
# Determine base directory (taking symbolic links into account)
cmd_file = os.path.realpath(os.path.abspath(inspect.getfile( inspect.currentframe() )))
basedir = os.path.split(cmd_file)[0]
path = os.path.join(basedir,"Images")
iconfile = Misc.mypath(os.path.join(path,"scyther-gui-32.ico"))
if os.path.isfile(iconfile):
icon = wx.Icon(iconfile,wx.BITMAP_TYPE_ICO)
window.SetIcon(icon)
示例11: findDot
def findDot():
global DOTLOCATION
# Cache the results
if DOTLOCATION != None:
return DOTLOCATION
DOTLOCATION = scanLocations()
if DOTLOCATION == None:
Misc.panic("""
Could not find the required 'dot' program, which is part of the Graphviz suite.
Please install it from http://www.graphviz.org/
Ubuntu users: install the 'graphviz' package.
Windows users: make sure that Graphviz is installed and
that the location of the 'dot' program is in
the PATH environment variable.
Restarting your system may be needed for Scyther to locate any newly installed
programs.
""")
return DOTLOCATION
示例12: get_input
def get_input(self):
"""Custom input routine."""
# Inherit base input routine
gen_input = Dialogs.GenForm.get_input(self)
# If OK ...
if gen_input:
# Get main data values from the form, ID, Comment, and Image Filename
self.obj.id = gen_input[_('Snapshot ID')]
self.obj.image_filename = gen_input[_('Image Filename')]
if gen_input[_('Episode Position')] == '':
self.obj.episode_start = 0.0
else:
self.obj.episode_start = Misc.time_in_str_to_ms(gen_input[_('Episode Position')])
if gen_input[_('Duration')] == '':
self.obj.episode_duration = 0.0
else:
self.obj.episode_duration = Misc.time_in_str_to_ms(gen_input[_('Duration')])
self.obj.comment = gen_input[_('Comment')]
else:
self.obj = None
return self.obj
示例13: _set_keyword
def _set_keyword(self, keyword):
# Make sure parenthesis characters are not allowed in Keywords
if (string.find(keyword, '(') > -1) or (string.find(keyword, ')') > -1):
keyword = string.replace(keyword, '(', '')
keyword = string.replace(keyword, ')', '')
if 'unicode' in wx.PlatformInfo:
# Encode with UTF-8 rather than TransanaGlobal.encoding because this is a prompt, not DB Data.
prompt = unicode(_('Keywords cannot contain parenthesis characters.\nYour Keyword has been renamed to "%s".'), 'utf8') % keyword
else:
prompt = _('Keywords cannot contain parenthesis characters.\nYour Keyword has been renamed to "%s".') % keyword
dlg = Dialogs.ErrorDialog(None, prompt)
dlg.ShowModal()
dlg.Destroy()
self._keyword = Misc.unistrip(keyword)
示例14: _set_keywordGroup
def _set_keywordGroup(self, keywordGroup):
# ALSO SEE Dialogs.add_kw_group_ui(). The same errors are caught there.
# Make sure parenthesis characters are not allowed in Keyword Group. Remove them if necessary.
if (string.find(keywordGroup, '(') > -1) or (string.find(keywordGroup, ')') > -1):
keywordGroup = string.replace(keywordGroup, '(', '')
keywordGroup = string.replace(keywordGroup, ')', '')
if 'unicode' in wx.PlatformInfo:
# Encode with UTF-8 rather than TransanaGlobal.encoding because this is a prompt, not DB Data.
prompt = unicode(_('Keyword Groups cannot contain parenthesis characters.\nYour Keyword Group has been renamed to "%s".'), 'utf8') % keywordGroup
else:
prompt = _('Keyword Groups cannot contain parenthesis characters.\nYour Keyword Group has been renamed to "%s".') % keywordGroup
dlg = Dialogs.ErrorDialog(None, prompt)
dlg.ShowModal()
dlg.Destroy()
# Colons are not allowed in Keyword Groups. Remove them if necessary.
if keywordGroup.find(":") > -1:
keywordGroup = keywordGroup.replace(':', '')
if 'unicode' in wx.PlatformInfo:
msg = unicode(_('You may not use a colon (":") in the Keyword Group name. Your Keyword Group has been changed to\n"%s"'), 'utf8')
else:
msg = _('You may not use a colon (":") in the Keyword Group name. Your Keyword Group has been changed to\n"%s"')
dlg = Dialogs.ErrorDialog(None, msg % keywordGroup)
dlg.ShowModal()
dlg.Destroy()
# Let's make sure we don't exceed the maximum allowed length for a Keyword Group.
# First, let's see what the max length is.
maxLen = TransanaGlobal.maxKWGLength
# Check to see if we've exceeded the max length
if len(keywordGroup) > maxLen:
# If so, truncate the Keyword Group
keywordGroup = keywordGroup[:maxLen]
# Display a message to the user describing the trunctions
if 'unicode' in wx.PlatformInfo:
# Encode with UTF-8 rather than TransanaGlobal.encoding because this is a prompt, not DB Data.
msg = unicode(_('Keyword Group is limited to %d characters. Your Keyword Group has been changed to\n"%s"'), 'utf8')
else:
msg = _('Keyword Group is limited to %d characters. Your Keyword Group has been changed to\n"%s"')
dlg = Dialogs.ErrorDialog(None, msg % (maxLen, keywordGroup))
dlg.ShowModal()
dlg.Destroy()
# Remove white space from the Keyword Group.
self._keywordGroup = Misc.unistrip(keywordGroup)
示例15: __repr__
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')