<s> """<STR_LIT>""" <EOL> import logging <EOL> logger = logging . getLogger ( '<STR_LIT>' ) <EOL> import threading , Queue <EOL> import wx <EOL> from wx . xrc import XmlResource , XRCCTRL , XRCID <EOL> from wx . lib . pubsub import Publisher as pub <EOL> from wx . gizmos import TreeListCtrl as tlc <EOL> from dicompyler import guiutil , util <EOL> import dicom <EOL> def pluginProperties ( ) : <EOL> """<STR_LIT>""" <EOL> props = { } <EOL> props [ '<STR_LIT:name>' ] = '<STR_LIT>' <EOL> props [ '<STR_LIT:description>' ] = "<STR_LIT>" <EOL> props [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> props [ '<STR_LIT:version>' ] = "<STR_LIT>" <EOL> props [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> props [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> props [ '<STR_LIT>' ] = [ ] <EOL> props [ '<STR_LIT>' ] = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> return props <EOL> def pluginLoader ( parent ) : <EOL> """<STR_LIT>""" <EOL> res = XmlResource ( util . GetBasePluginsPath ( '<STR_LIT>' ) ) <EOL> panelTreeView = res . LoadPanel ( parent , '<STR_LIT>' ) <EOL> panelTreeView . Init ( res ) <EOL> return panelTreeView <EOL> class pluginTreeView ( wx . Panel ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> pre = wx . PrePanel ( ) <EOL> self . PostCreate ( pre ) <EOL> def Init ( self , res ) : <EOL> """<STR_LIT>""" <EOL> self . choiceDICOM = XRCCTRL ( self , '<STR_LIT>' ) <EOL> self . tlcTreeView = DICOMTree ( self ) <EOL> res . AttachUnknownControl ( '<STR_LIT>' , self . tlcTreeView , self ) <EOL> wx . EVT_CHOICE ( self , XRCID ( '<STR_LIT>' ) , self . OnLoadTree ) <EOL> self . Bind ( wx . EVT_WINDOW_DESTROY , self . OnDestroy ) <EOL> font = wx . SystemSettings . GetFont ( wx . SYS_DEFAULT_GUI_FONT ) <EOL> if guiutil . IsMac ( ) : <EOL> font . SetPointSize ( <NUM_LIT:10> ) <EOL> self . tlcTreeView . SetFont ( font ) <EOL> pub . subscribe ( self . OnUpdatePatient , '<STR_LIT>' ) <EOL> def OnUpdatePatient ( self , msg ) : <EOL> """<STR_LIT>""" <EOL> self . choiceDICOM . Enable ( ) <EOL> self . choiceDICOM . Clear ( ) <EOL> self . choiceDICOM . Append ( "<STR_LIT>" ) <EOL> self . choiceDICOM . Select ( <NUM_LIT:0> ) <EOL> self . tlcTreeView . DeleteAllItems ( ) <EOL> for k , v in msg . data . iteritems ( ) : <EOL> if isinstance ( v , dicom . dataset . FileDataset ) : <EOL> i = self . choiceDICOM . Append ( v . SOPClassUID . name . split ( '<STR_LIT>' ) [ <NUM_LIT:0> ] ) <EOL> self . choiceDICOM . SetClientData ( i , v ) <EOL> if ( k == '<STR_LIT>' ) : <EOL> for imgnum , image in enumerate ( v ) : <EOL> i = self . choiceDICOM . Append ( <EOL> image . SOPClassUID . name . split ( '<STR_LIT>' ) [ <NUM_LIT:0> ] + '<STR_LIT>' + str ( imgnum + <NUM_LIT:1> ) ) <EOL> self . choiceDICOM . SetClientData ( i , image ) <EOL> def OnDestroy ( self , evt ) : <EOL> """<STR_LIT>""" <EOL> pub . unsubscribe ( self . OnUpdatePatient ) <EOL> def OnLoadTree ( self , event ) : <EOL> """<STR_LIT>""" <EOL> choiceItem = event . GetInt ( ) <EOL> if not ( choiceItem == <NUM_LIT:0> ) : <EOL> dataset = self . choiceDICOM . GetClientData ( choiceItem ) <EOL> else : <EOL> return <EOL> self . tlcTreeView . DeleteAllItems ( ) <EOL> self . root = self . tlcTreeView . AddRoot ( text = dataset . SOPClassUID . name ) <EOL> self . tlcTreeView . Collapse ( self . root ) <EOL> dlgProgress = guiutil . get_progress_dialog ( <EOL> wx . GetApp ( ) . GetTopWindow ( ) , <EOL> "<STR_LIT>" ) <EOL> self . queue = Queue . Queue ( ) <EOL> self . t = threading . Thread ( target = self . RecurseTreeThread , <EOL> args = ( dataset , self . root , self . AddItemTree , <EOL> dlgProgress . OnUpdateProgress , len ( dataset ) ) ) <EOL> self . t . start ( ) <EOL> dlgProgress . ShowModal ( ) <EOL> dlgProgress . Destroy ( ) <EOL> self . tlcTreeView . SetFocus ( ) <EOL> self . tlcTreeView . Expand ( self . root ) <EOL> def RecurseTreeThread ( self , ds , parent , addItemFunc , progressFunc , length ) : <EOL> """<STR_LIT>""" <EOL> for i , data_element in enumerate ( ds ) : <EOL> if ( length > <NUM_LIT:0> ) : <EOL> wx . CallAfter ( progressFunc , i , length , '<STR_LIT>' ) <EOL> if ( i == length - <NUM_LIT:1> ) : <EOL> wx . CallAfter ( progressFunc , i , len ( ds ) , '<STR_LIT>' ) <EOL> if not ( data_element . VR == '<STR_LIT>' ) : <EOL> cs = ds . get ( '<STR_LIT>' , "<STR_LIT>" ) <EOL> wx . CallAfter ( addItemFunc , data_element , parent , cs = cs ) <EOL> else : <EOL> wx . CallAfter ( addItemFunc , data_element , parent , needQueue = True ) <EOL> item = self . queue . get ( ) <EOL> for i , ds in enumerate ( data_element . value ) : <EOL> sq_item_description = data_element . name . replace ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> sq_element_text = "<STR_LIT>" % ( sq_item_description , i + <NUM_LIT:1> ) <EOL> wx . CallAfter ( addItemFunc , data_element , item , sq_element_text , needQueue = True ) <EOL> sq = self . queue . get ( ) <EOL> self . RecurseTreeThread ( ds , sq , addItemFunc , progressFunc , <NUM_LIT:0> ) <EOL> def AddItemTree ( self , data_element , parent , sq_element_text = "<STR_LIT>" , needQueue = False , cs = None ) : <EOL> """<STR_LIT>""" <EOL> if not ( sq_element_text == "<STR_LIT>" ) : <EOL> item = self . tlcTreeView . AppendItem ( parent , text = sq_element_text ) <EOL> else : <EOL> item = self . tlcTreeView . AppendItem ( parent , text = data_element . name ) <EOL> if not ( data_element . VR == '<STR_LIT>' ) : <EOL> value = data_element . value <EOL> if ( data_element . name == '<STR_LIT>' ) : <EOL> value = '<STR_LIT>' + str ( len ( data_element . value ) ) + '<STR_LIT>' <EOL> elif ( ( data_element . VR == '<STR_LIT>' ) and not ( type ( data_element . value ) == str ) ) : <EOL> value = data_element . repval <EOL> else : <EOL> if not isinstance ( data_element . value , unicode ) : <EOL> try : <EOL> dicom . charset . decode ( <EOL> dicom . charset . decode ( data_element , cs ) ) <EOL> except : <EOL> try : <EOL> value = unicode ( data_element . value ) <EOL> except : <EOL> logger . info ( <EOL> "<STR_LIT>" , <EOL> data_element . name ) <EOL> value = unicode ( <EOL> data_element . value , errors = '<STR_LIT:replace>' ) <EOL> else : <EOL> value = data_element . value <EOL> self . tlcTreeView . SetItemText ( item , value , <NUM_LIT:1> ) <EOL> self . tlcTreeView . SetItemText ( item , unicode ( data_element . tag ) , <NUM_LIT:2> ) <EOL> self . tlcTreeView . SetItemText ( item , unicode ( data_element . VM ) , <NUM_LIT:3> ) <EOL> self . tlcTreeView . SetItemText ( item , unicode ( data_element . VR ) , <NUM_LIT:4> ) <EOL> if ( needQueue ) : <EOL> self . queue . put ( item ) <EOL> class DICOMTree ( tlc ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( DICOMTree , self ) . __init__ ( * args , ** kwargs ) <EOL> self . AddColumn ( '<STR_LIT:Name>' ) <EOL> self . AddColumn ( '<STR_LIT>' ) <EOL> self . AddColumn ( '<STR_LIT>' ) <EOL> self . AddColumn ( '<STR_LIT>' ) <EOL> self . AddColumn ( '<STR_LIT>' ) <EOL> self . SetMainColumn ( <NUM_LIT:0> ) <EOL> self . SetColumnWidth ( <NUM_LIT:0> , <NUM_LIT:200> ) <EOL> self . SetColumnWidth ( <NUM_LIT:1> , <NUM_LIT:200> ) <EOL> self . SetColumnWidth ( <NUM_LIT:3> , <NUM_LIT:50> ) <EOL> self . SetColumnWidth ( <NUM_LIT:4> , <NUM_LIT:50> ) </s>
