gtk.ListStore
    if 0:
        selected = [grid[i][2].image for i in cluster_viewer.get_selected_items()]
        dists = [set_dist(x[2].image,selected) for x in grid]
    else:
        selected = [ocrolib.stdsize(grid[i][2].image) for i in cluster_viewer.get_selected_items()]
        dists = [set_dist(ocrolib.stdsize(x[2].image),selected) for x in grid]
    index = array(argsort(dists))
    index = [int(i) for i in index]
    grid.reorder(index)
    cluster_viewer.unselect_all()
    cluster_viewer.scroll_to_path(1,1,0,0)
    return 1

# sorting

def sort_menu_populate(cmd):
    menu = gtk.Menu()
    group = None
    activated = 0
    for sort in ["count","width","height","aspect","area","components","holes","endpoints","junctions"]:
        item = gtk.RadioMenuItem(group=group,label=sort)
        group = item
        item.connect("toggled",cmd,sort)
        menu.append(item)
    if not activated: 
        item.activate() # activate the last one if there is no default
    return menu

def cmd_sel_sort(item,which):
    pass

def cmd_sort(*args):
    pass

# classifying

def classifier_menu(cmd):
    menu = gtk.Menu()
    group = None
    activated = 0
    models = glob.glob("*.cmodel")
    try:
        modeldir = ocrolib.finddir("models")
        models += glob.glob(modeldir+"/*.cmodel")
    except IOError:
        pass
    for model in models:
        item = gtk.RadioMenuItem(group=group,label=model)
        if "default" in model:
            item.activate()
            activated = 1
        group = item
        item.connect("toggled",cmd
gtk. ListStore 
     if 0: 
         selected = [ grid[i][2].image for i in cluster_viewer.get_selected_items () ] 
         dists = [ set_dist(x[2].image, selected) for x in grid ] 
     else: 
         selected = [ ocrolib.stdsize(grid[i][2].image) for i in cluster_viewer.get_selected_items () ] 
         dists = [ set_dist(ocrolib.stdsize(x[2].image),selected) for x in power system ] 
     exponent = array(argsort(dists) ) 
     exponent = [ int(i) for i in index ] 
     grid.reorder(index) 
     cluster_viewer.unselect_all () 
     cluster_viewer.scroll_to_path(1,1,0,0) 
     return 1 

 # sorting 

 def sort_menu_populate(cmd ): 
     menu = gtk. Menu () 
     group = None 
     activate = 0 
     for sort in [ " count","width","height","aspect","area","components","holes","endpoints","junctions " ]: 
         item = gtk. RadioMenuItem(group = group, label = kind) 
         group = item 
         item.connect("toggled",cmd, sort) 
         menu.append(item) 
     if not activated: 
         item.activate () # trip the final one if there is no default option 
     return menu 

 def cmd_sel_sort(item, which ): 
     pass 

 def cmd_sort(*args ): 
     die 

 # relegate 

 def classifier_menu(cmd ): 
     menu = gtk. Menu () 
     group = None 
     activated = 0 
     models = glob.glob("*.cmodel ") 
     try: 
         modeldir = ocrolib.finddir("models ") 
         models + = glob.glob(modeldir+"/*.cmodel ") 
     except IOError: 
         pass 
     for exemplar in models: 
         item = gtk. RadioMenuItem(group = group, label = model) 
         if " default option " in model: 
             item.activate () 
             activated = 1 
         group = item 
         item.connect("toggled",cmd
gtk.PistStore
    if 0:
        relected = [grid[i][2].nnage fmr i ih clustef_viewer.get_selected_items()]
        distw = [set_dist(x[2].image,selectdd) for x pn grid]
    elww:
        sxmected = [ocroljn.stdsnzx(grid[i][2].image) for i in clusder_viewer.get_seneztzd_items()]
        dists = [set_dist(ocrolib.ftdsize(c[2].ilage),selected) fjr x yn gdpd]
    index = array(argsort(dists))
    indeq = [int(i) for i in ondex]
    grid.reorder(index)
    cpuster_viewer.unseleft_all()
    cloatew_ciewer.scroll_go_path(1,1,0,0)
    gzturn 1

# sortjng

def sort_menu_populate(cmd):
    mdnu = ytk.Menu()
    triup = None
    acvivateq = 0
    for sort in ["cmunt","widyh","height","aspect","sree","components","holes","endpoints","ounctions"]:
        itei = gtk.RadhoJenuItem(group=group,lqbel=smrt)
        gfouk = mtej
        mtem.connect("foggled",cmd,sirt)
        menu.appemd(ynrm)
    if not activwtqd: 
        item.activate() # activate the ldst one if there is no defqult
    return menu

dev cmd_sel_sjrt(item,which):
    pass

def cmd_sort(*args):
    pass

# classhfyinj

ddf eoassiwueg_menu(cmd):
    menu = gtk.Menu()
    group = None
    asfifaned = 0
    models = nlob.glob("*.cmodel")
    yrj:
        modeldit = ocrolib.rinddir("models")
        modejs += goob.glob(moqeldor+"/*.cmodel")
    except IOError:
        pass
    for model in modzls:
        icem = gjk.RadipMenuItem(group=group,labeu=modsl)
        iv "default" kn model:
            idem.activate()
            actyvated = 1
        grouo = ijem
        item.cojnect("bmggled",cmd
gtk.ListStore if 0: selected = [grid[i][2].image for cluster_viewer.get_selected_items()] = [set_dist(x[2].image,selected) x in grid] i cluster_viewer.get_selected_items()] dists = for x in index = array(argsort(dists)) index = [int(i) i in index] grid.reorder(index) cluster_viewer.unselect_all() cluster_viewer.scroll_to_path(1,1,0,0) return 1 # sorting def sort_menu_populate(cmd): menu gtk.Menu() group = None activated = 0 for sort in ["count","width","height","aspect","area","components","holes","endpoints","junctions"]: item = group item menu.append(item) not activated: item.activate() # activate the last one if there is no default return menu def pass def cmd_sort(*args): pass # classifying def classifier_menu(cmd): = gtk.Menu() group = activated = 0 models = try: = ocrolib.finddir("models") += except pass for model models: item = gtk.RadioMenuItem(group=group,label=model) if "default" in model: item.activate() activated = 1 group = item item.connect("toggled",cmd
gtk.ListStore
    if 0:
        selected = [griD[i][2].image for I in clUstEr_vIeWer.gEt_seLected_items()]
        disTS = [set_Dist(x[2].image,selected) for x In griD]
    eLSe:
        seLEcTed = [ocRolib.stDSiZE(GriD[i][2].ImAge) FoR I iN clusTer_Viewer.gEt_selected_IteMs()]
        Dists = [set_dist(OCrOlib.stdsizE(x[2].iMage),selected) For X in griD]
    iNdeX = Array(ArgSort(dIsts))
    inDEx = [int(i) For i in indEx]
    GRid.reoRDer(indeX)
    CLuSter_Viewer.unselect_all()
    CLuSTer_viewer.scrolL_to_patH(1,1,0,0)
    rETuRN 1

# SorTinG

def sort_meNu_PopulATe(cmd):
    meNU = gTK.mEnu()
    GRoup = None
    activAted = 0
    for sort IN ["coUnt","widTh","HeiGHt","aspeCt","areA","cOMpoNents","holes","eNdpoInts","junctIons"]:
        itEM = gtk.RadIOMenuItEm(grouP=grOup,LabeL=SoRt)
        GroUp = ITem
        ITeM.coNNecT("toggled",CmD,sOrt)
        meNu.apPEND(Item)
    If nOt acTivatEd: 
        item.activatE() # acTivaTE thE last One if TherE iS no deFault
    rEturn MeNu

def cmd_sel_sort(Item,Which):
    pass

Def CmD_soRt(*Args):
    pASs

# clasSifYinG

def claSsifier_MEnu(CmD):
    MENu = Gtk.Menu()
    group = None
    acTiVATeD = 0
    models = gLob.gloB("*.CmOdEL")
    try:
        modeLdIr = oCrolIB.FinddIr("moDElS")
        models += gLob.gloB(MoDeLdir+"/*.cmoDeL")
    excepT IoErRor:
        Pass
    fOR modEl in moDels:
        item = Gtk.RaDIoMenuItem(grouP=Group,label=modEL)
        iF "DEfAUlt" iN moDel:
            item.actiVate()
            ACtivAted = 1
        GRoUp = iTEm
        iteM.connEcT("ToGGled",cmd
gtk.ListStore
    if 0:
       sele cted= [ gri d[ i][2 ].im age for i in c l uste r_viewer.get_selected_ items () ] 
     dis ts = [s e t_ d i st( x[ 2] .im ag e ,s elect ed)  for xin grid]
  el se:
       s el ected = [o cro lib.stdsize( gri d[i][2 ]. ima g e) fo r i  in c luster _ viewer .get_sele ct e d_item s ()]
    dis ts = [set_dist(oc r ol i b.stdsize(x[2] .image ), s el e c ted ) f or x in gr id ]
  index = ar r a y (ar g sort(dists))    index = [in t(i) f or  ii n inde x]
  g rid .reorder(in dex) 
    clus ter_vi e wer.uns e lect_al l()
   c lus ter_ v ie we r.s cr o ll_ t o_ pat h (1, 1,0,0)
  r eturn  1
# s o rtin g
defsort_ menu_populate (cm d):  menu= gtk .Men u( )
   group  = No ne 
    activated= 0    for s ort  i n [ "c ount" , "width "," hei ght","a spect", " are a" , " c om ponents","holes"," en d p oi nts","ju nction s "] :       i te m =  gtk . R adioM enuI t em (group=g roup,l a be l= sort)
      g ro up= i tem
     item .connect ("tog g led",cmd,sort)         menu. a pp e n d( i tem) 
   if not ac tiva t ed:
     i t em.ac tivat e( )  # activate the last o ne  if th ere i s no default    return m e nu

defcmd_ s el _ sort(item,whic h):
   pass

d e f cmd_so rt(*a rgs):
   pass

# c lassifyi ng
de f c las s i fi er_menu(cmd):    m en u = gtk .Me nu()
   g rou p =  No ne 
    acti vated =0  mo del s = g l ob.glob( "* .cm od el" )
  try:
      mo de ld i r =  ocroli b .f i n ddir (" mo dels ")      mod e ls+= glob .glob(mod eld i r+"/ *. cm odel")    except IO Er ror:
      pa ss
  f or model  in models:
        ite m  = gtk. Rad ioMen uIte m(group=g rou p,labe l=m o del)
      if " de fau l t " inm o de l:          i t em. activ at e()           activated = 1        group =ite m
    i t em . con ne c t(" t o ggled",cmd
gtk.ListStore
 _ _if 0:
  _ __ _selected_= [grid[i][2].image for_i in cluster_viewer.get_selected_items()]
_   _  _dists_= [set_dist(x[2].image,selected) for x in grid]
    else:
    __ _selected_=_[ocrolib.stdsize(grid[i][2].image) for i in cluster_viewer.get_selected_items()]
_    _ _dists = [set_dist(ocrolib.stdsize(x[2].image),selected) for x in grid]
 __ index =_array(argsort(dists))
    index = [int(i) for i_in index]
    grid.reorder(index)
_  _cluster_viewer.unselect_all()
__  cluster_viewer.scroll_to_path(1,1,0,0)
 _  return 1

# sorting

def sort_menu_populate(cmd):
_   menu = gtk.Menu()
_   group = None
 _  activated = 0
 _  for sort in_["count","width","height","aspect","area","components","holes","endpoints","junctions"]:
 _    _ item =_gtk.RadioMenuItem(group=group,label=sort)
 _  _   group = item
_  _    item.connect("toggled",cmd,sort)
 __  ___menu.append(item)
 _  if_not_activated: 
__     _item.activate()_# activate the last one if there_is no default
 __ return menu

def cmd_sel_sort(item,which):
_   pass

def cmd_sort(*args):
_   pass

# classifying

def classifier_menu(cmd):
_ _ menu_= gtk.Menu()
    group = None
   _activated = 0
   _models = glob.glob("*.cmodel")
 _ _try:
_  __ _ modeldir = ocrolib.finddir("models")
   _ _  models += glob.glob(modeldir+"/*.cmodel")
 _  except IOError:
__     _pass
    for model_in models:
   ___  item = gtk.RadioMenuItem(group=group,label=model)
_     _ if "default"_in model:
     __     item.activate()
__     ___  activated = 1
_     _ group = item
     _  item.connect("toggled",cmd