<commit_before>#!/usr/bin/env python

'''
AutoTrace.py
Written by <NAME> on Aug 16 2010

purpose:
    This is the main script for the AutoTrace tools.

usage:
    python AutoTrace.py
    
--------------------------------------------------
Modified by <NAME> on Feb 21 2011
reason:
    added support for ROI_config.txt, network selection.
--------------------------------------------------
Modified by <NAME> on Feb 25 2011
reason:
    added support for unique tracer codes on .traced.txt files
'''

import sys, os, time
import subprocess
import PGLite as pg
import fixImages
import format4R as f4r
import LinguaView as lv
import TrackDots as hc
import pygtk
pygtk.require("2.0")
import gtk
import gtk.glade
import Queue
import threading

CopyQueue = Queue.Queue()

class CopyThread(threading.Thread):        
    def run(self):
        flag = 'ok'
        while (flag != 'stop'):
            cmd = CopyQueue.get()
            if cmd == None:
                flag = 'stop'
            else:
                print ' '.join(cmd)
                p = subprocess.Popen(cmd)
                p.wait()
        print "CopyThread stopped"


class Controller:
    def __init__(self):
        self.app_dir = os.getcwd() 
        self.gladefile = self.app_dir + "/LinguaViewer.glade"
        self.wTree = gtk.glade.XML(self.gladefile, "PGController")
        self.win = self.wTree.get_widget("PGController")
        self.win.set_title("AutoTrace")
        
        dic = { "on_PGController_destroy" : gtk.main_quit,
                "on_quit5_activate" : gtk.main_quit,
                "on_open2_activate" : self.onOpen,
                "on_tbOpe_clicked" : self.onOpen,
                "on_tbView1_clicked" : self.onView,
                "on_tbTrace_clicked" : self.onAutoTrace,
                "on_tbExport_clicked" : self.onExport,
                "on_tbNetwork_clicked" : self.onNetwork,
                "on_tbHeadCorr_clicked" : self.onHeadCorr}
                
        self.wTree.signal_autoconnect(dic)
        
        self.TreeView = self.wTree.get_widget("treeview2")
        column = gtk.TreeViewColumn("Image Files", gtk.CellRendererText(), text=0)
        column.set_resizable(True)
        column.set_sort_column_id(0)
        self.TreeView.append_column(column)
        self.DataList = gtk.ListStore(str)
        self.TreeView.set_model(self.DataList)
        self.tmpdirs = []
        self.network = ''
        
    def onHeadCorr(self, event):
        hc.TrackWindow(self.datafiles)

    def onNetwork(self, event):
        nc = gtk.FileChooserDialog(title='Open Network File', parent=None, 
            action=gtk.FILE_CHOOSER_ACTION_OPEN, 
            buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, 
            gtk.STOCK_OPEN, gtk.RESPONSE_OK))
        g_directory = nc.get_current_folder()
        nc.set_current_folder(g_directory)
        nc.set_default_response(gtk.RESPONSE_OK)
        nc.set_select_multiple(False)
        ffilter = gtk.FileFilter()
        ffilter.set_name('.mat Files')
        ffilter.add_pattern('*.mat')
        nc.add_filter(ffilter)
        response = nc.run()
        if response == gtk.RESPONSE_OK:
            self.network = nc.get_filename()
            g_directory = nc.get_current_folder()
        nc.destroy()        
        
    def onOpen(self, event):
        fc = gtk.FileChooserDialog(title='Open Image Files', parent=None, 
            action=gtk.FILE_CHOOSER_ACTION_OPEN, 
            buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, 
            gtk.STOCK_OPEN, gtk.RESPONSE_OK))
        g_directory = fc.get_current_folder()
        fc.set_current_folder(g_directory)
        fc.set_default_response(gtk.RESPONSE_OK)
        fc.set_select_multiple(True)
        ffilter = gtk.FileFilter()
        ffilter.set_name('.jpg Files')
        ffilter.add_pattern('*.jpg')
        ffilter.add_pattern('*.png')
        fc.add_filter(ffilter)
        response = fc.run()
        if response == gtk.RESPONSE_OK:
            self.datafiles = fc.get_filenames()
            g_directory = fc.get_current_folder()
            for i in self.datafiles:
                self.DataList.append([i])
            fixImages.ImageFixer(self.datafiles)
        fc.destroy()
                
    def onView(self, event):
        # first we need to check whether autotracer.m updated anything<commit_msg>fixed potential bug for cases where get_current_folder() == None<commit_after>#!/usr/bin/env python

'''
AutoTrace.py
Written by <NAME> on Aug 16 2010

purpose:
    This is the main script for the AutoTrace tools.

usage:
    python AutoTrace.py
    
--------------------------------------------------
Modified by <NAME> on Feb 21 2011
reason:
    added support for ROI_config.txt, network selection.
--------------------------------------------------
Modified by <NAME> on Feb 25 2011
reason:
    added support for unique tracer codes on .traced.txt files
'''

import sys, os, time
import subprocess
import PGLite as pg
import fixImages
import format4R as f4r
import LinguaView as lv
import TrackDots as hc
import pygtk
pygtk.require("2.0")
import gtk
import gtk.glade
import Queue
import threading

CopyQueue = Queue.Queue()

class CopyThread(threading.Thread):        
    def run(self):
        flag = 'ok'
        while (flag != 'stop'):
            cmd = CopyQueue.get()
            if cmd == None:
                flag = 'stop'
            else:
                print ' '.join(cmd)
                p = subprocess.Popen(cmd)
                p.wait()
        print "CopyThread stopped"


class Controller:
    def __init__(self):
        self.app_dir = os.getcwd() 
        self.gladefile = self.app_dir + "/LinguaViewer.glade"
        self.wTree = gtk.glade.XML(self.gladefile, "PGController")
        self.win = self.wTree.get_widget("PGController")
        self.win.set_title("AutoTrace")
        
        dic = { "on_PGController_destroy" : gtk.main_quit,
                "on_quit5_activate" : gtk.main_quit,
                "on_open2_activate" : self.onOpen,
                "on_tbOpe_clicked" : self.onOpen,
                "on_tbView1_clicked" : self.onView,
                "on_tbTrace_clicked" : self.onAutoTrace,
                "on_tbExport_clicked" : self.onExport,
                "on_tbNetwork_clicked" : self.onNetwork,
                "on_tbHeadCorr_clicked" : self.onHeadCorr}
                
        self.wTree.signal_autoconnect(dic)
        
        self.TreeView = self.wTree.get_widget("treeview2")
        column = gtk.TreeViewColumn("Image Files", gtk.CellRendererText(), text=0)
        column.set_resizable(True)
        column.set_sort_column_id(0)
        self.TreeView.append_column(column)
        self.DataList = gtk.ListStore(str)
        self.TreeView.set_model(self.DataList)
        self.tmpdirs = []
        self.network = ''
        
    def onHeadCorr(self, event):
        hc.TrackWindow(self.datafiles)

    def onNetwork(self, event):
        nc = gtk.FileChooserDialog(title='Open Network File', parent=None, 
            action=gtk.FILE_CHOOSER_ACTION_OPEN, 
            buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, 
            gtk.STOCK_OPEN, gtk.RESPONSE_OK))
        g_directory = nc.get_current_folder()
        nc.set_current_folder(g_directory)
        nc.set_default_response(gtk.RESPONSE_OK)
        nc.set_select_multiple(False)
        ffilter = gtk.FileFilter()
        ffilter.set_name('.mat Files')
        ffilter.add_pattern('*.mat')
        nc.add_filter(ffilter)
        response = nc.run()
        if response == gtk.RESPONSE_OK:
            self.network = nc.get_filename()
            g_directory = nc.get_current_folder()
        nc.destroy()        
        
    def onOpen(self, event):
        fc = gtk.FileChooserDialog(title='Open Image Files', parent=None, 
            action=gtk.FILE_CHOOSER_ACTION_OPEN, 
            buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, 
            gtk.STOCK_OPEN, gtk.RESPONSE_OK))
        g_directory = fc.get_current_folder()
        if not g_directory:
            g_directory = os.path.expanduser('~')
        fc.set_current_folder(g_directory)
        fc.set_default_response(gtk.RESPONSE_OK)
        fc.set_select_multiple(True)
        ffilter = gtk.FileFilter()
        ffilter.set_name('.jpg Files')
        ffilter.add_pattern('*.jpg')
        ffilter.add_pattern('*.png')
        fc.add_filter(ffilter)
        response = fc.run()
        if response == gtk.RESPONSE_OK:
            self.datafiles = fc.get_filenames()
            g_directory = fc.get_current_folder()
            for i in self.datafiles:
                self.DataList.append([i])
            fixImages.ImageFixer(self.datafiles)
        fc.destroy()
                
    def onView(self, event):
        # first we need to check whether autotracer.m updated anything
{'fraction_non_alphanumeric': 0.12029133947877546, 'fraction_numerical': 0.006373051098213269, 'mean_word_length': 2.041883004499827, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3660695', 'n_tokens_mistral': 2907, 'n_tokens_neox': 2772, 'n_words': 525}