def elided_text(text, font=None, width=300, pos='middle'):
 from PyQt5.Qt import QFontMetrics, QApplication
 fm = (QApplication.fontMetrics() if (font is None) else (font if isinstance(font, QFontMetrics) else QFontMetrics(font)))
 delta = 4
 ellipsis = u'\u2026'
 def remove_middle(x):
  mid = (len(x) // 2)
  return ((x[:max(0, (mid - (delta // 2)))] + ellipsis) + x[(mid + (delta // 2)):])
 chomp = {'middle': remove_middle, 'left': (lambda x: (ellipsis + x[delta:])), 'right': (lambda x: (x[:(- delta)] + ellipsis))}[pos]
 while ((len(text) > delta) and (fm.width(text) > width)):
  text = chomp(text)
 return unicode(text)

def elided_text ( text , font = None , width = 300 , pos = 'middle' ) : from PyQt5 . Qt import QFontMetrics , QApplication fm = ( QApplication . fontMetrics ( ) if ( font is None ) else ( font if isinstance ( font , QFontMetrics ) else QFontMetrics ( font ) ) ) delta = 4 ellipsis = u'\u2026' def remove_middle ( x ) : mid = ( len ( x ) // 2 ) return ( ( x [ : max ( 0 , ( mid - ( delta // 2 ) ) ) ] + ellipsis ) + x [ ( mid + ( delta // 2 ) ) : ] ) chomp = { 'middle' : remove_middle , 'left' : ( lambda x : ( ellipsis + x [ delta : ] ) ) , 'right' : ( lambda x : ( x [ : ( - delta ) ] + ellipsis ) ) } [ pos ] while ( ( len ( text ) > delta ) and ( fm . width ( text ) > width ) ) : text = chomp ( text ) return unicode ( text )
return a version of text that is no wider than width pixels when rendered .