Stringscan

Check-in [3d2ce95654]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:More tweaks for version 1.1
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:3d2ce956541fb18f6be5560b1c47ad59afe049799105e5b8bb8272adcd32ce69
User & Date: kevin 2017-09-18 02:17:49
Context
2017-09-18
02:25
Code cleanup check-in: c7f9249bd0 user: kevin tags: trunk
02:17
More tweaks for version 1.1 check-in: 3d2ce95654 user: kevin tags: trunk
2017-09-17
23:05
Tweak UI layout check-in: ed3a0787fb user: kevin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to stringscan.rb.

    74     74   	end        
    75     75   	drawgui
    76     76   	Tk.tk_call('regproc::readLic', $appname, $appversion)
    77     77   end  
    78     78   
    79     79   #core method; here we search for a string in text files within a directory and  display a list of matching files in the listbox 
    80     80   def stringgrep
           81  +        $root.update
    81     82   	$file_list = []
    82     83   	$grep_list = []
           84  +        $p.start
           85  +        $bottomlabel.configure('text' => "Searching for \"#{$searchterm}\" in #{$dirname}")
    83     86   	$lbox.delete(0, 'end')
           87  +        $root.update
    84     88   	Find.find("#{$dirname}") do |path|
    85     89   		$file_list << path unless FileTest.directory?(path)
    86     90   	end
    87     91   	for i in $file_list
    88     92   	begin
    89     93   		#we are only reading text files here, not binary. 
    90     94   		text =  MIME::Types.type_for(i).first.to_s
................................................................................
    96    100   				$lbox.insert('end', "#{i}")
    97    101   				f.close
    98    102   			end
    99    103   		end
   100    104   	rescue
   101    105   		#puts "Search term not found.\n"
   102    106   	end
          107  +        $p.stop
          108  +        $grep_list = $lbox.get(0, 'end')
          109  +        num = $grep_list.count.to_s
          110  +        $bottomlabel.configure('text' => "Found #{num} matches for \"#{$searchterm}\" in #{$dirname}")
   103    111   end
   104    112   rescue
   105    113   puts "Directory not found.\n"
   106    114   puts "Search complete.\n"
   107    115   end
   108    116   
   109    117   def drawgui 
................................................................................
   228    236   		activestyle "none"
   229    237   		exportselection 0
   230    238   		selectbackground "RoyalBlue1"
   231    239   		selectforeground "white"
   232    240   		dnd_bindtarget('text/uri-list', '<Drop>', '%D') {|d|
   233    241   			filename=d.join(' ')
   234    242   			begin
   235         -				if File.directory?(filename)
          243  +			  if File.directory?(filename)
          244  +                            $tbox.configure('state'=>'normal')
          245  +	                    $tbox.delete('1.0', 'end')
          246  +                            $tbox.configure('state'=>'disabled')
          247  +                            $lbox.delete(0, 'end')
   236    248   					$dirname = filename
   237    249   					$direntry.value = filename
   238    250   				end
   239    251   			rescue
   240    252   				raise
   241    253   			end
   242    254   		}
................................................................................
   267    279   	$tscrollframe = Tk::Frame.new($bottomrightframe).pack('side'=>'right','fill' => 'y', 'expand' => 'no')
   268    280   	$tscroll = Tk::Tile::Scrollbar.new($tscrollframe).pack('side'=>'right','fill' => 'y', 'expand' => 'no')
   269    281   	$tbox.yscrollbar($tscroll)
   270    282   	
   271    283   	
   272    284   	$labelframe = Tk::Tile::Frame.new($root).pack('side'=>'bottom', 'fill'=>'both', 'expand' => 'no')
   273    285   	$bottomlabel = Tk::Tile::Label.new($labelframe) {text "No data displayed"}.pack('side' => 'left','fill' => 'both','expand' => 'no')
          286  +        $p = Tk::Tile::Progressbar.new($labelframe) {orient 'horizontal'; length 200; mode 'indeterminate'}.pack('side' => 'left','fill' => 'both','expand' => 'no')
   274    287   	$bottomsep = Tk::Tile::Separator.new($root) { orient 'horizontal' }.pack('side'=> 'bottom', 'fill'=>'both')
   275    288   	
   276         -#p = Tk::Tile::Progressbar.new(parent) {orient 'horizontal'; length 200; mode 'determinate'}
   277         -
   278         -#Searching for $searchterm in $dirname
   279         -	
   280         -	$root.bind("#{$accelkey}-Q", proc{exit})
          289  +  	$root.bind("#{$accelkey}-Q", proc{exit})
   281    290   	$root.bind("#{$accelkey}-q", proc{exit})
   282    291   	$root.bind("#{$accelkey}-O", proc{choosedir})
   283    292   	$root.bind("#{$accelkey}-o", proc{choosedir})
   284    293   	$root.bind("#{$accelkey}-R", proc{stringgrep})
   285    294   	$root.bind("#{$accelkey}-r", proc{stringgrep})
          295  +
          296  +        $lbox.focus
          297  +
   286    298   end
   287    299   
   288    300   
   289    301   #select search directory
   290    302   def choosedir
   291    303     	$tbox.configure('state'=>'normal')
   292    304   	$tbox.delete('1.0', 'end')
................................................................................
   320    332   		cur, len = $tbox.search_with_length("#{$searchterm}", cur, 'end')
   321    333   		break if cur == ""
   322    334   		$tbox.tag_add('search', cur, "#{cur} + #{len} char")
   323    335   		cur = $tbox.index("#{cur} + #{len} char")
   324    336   	}
   325    337   	$tbox.configure('state'=>'disabled')
   326    338   end
          339  +
   327    340   #about window for app
   328    341   def aboutWindow
   329    342   	Tk::messageBox :type => 'ok',
   330    343   	:message => 'Stringscan: Text Search Tool',
   331    344   	:icon => 'info', :title => 'About Stringscan',
   332    345   	:detail  => "Version 1.1\n(c) 2017 WordTech Communications LLC",
   333    346   	:parent => $root