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 Unified Diffs Ignore Whitespace Patch

Changes to stringscan.rb.

74
75
76
77
78
79
80

81
82


83

84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102




103
104
105
106
107
108
109
	end        
	drawgui
	Tk.tk_call('regproc::readLic', $appname, $appversion)
end  

#core method; here we search for a string in text files within a directory and  display a list of matching files in the listbox 
def stringgrep

	$file_list = []
	$grep_list = []


	$lbox.delete(0, 'end')

	Find.find("#{$dirname}") do |path|
		$file_list << path unless FileTest.directory?(path)
	end
	for i in $file_list
	begin
		#we are only reading text files here, not binary. 
		text =  MIME::Types.type_for(i).first.to_s
		type =  text.split('/')[0]
		if type  =~ /text/
			f = File.open(i, "r:iso-8859-1:utf-8")
			result = f.read
			if result =~ /#{$searchterm}/ then
				$lbox.insert('end', "#{i}")
				f.close
			end
		end
	rescue
		#puts "Search term not found.\n"
	end




end
rescue
puts "Directory not found.\n"
puts "Search complete.\n"
end

def drawgui 







>


>
>

>



















>
>
>
>







74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
	end        
	drawgui
	Tk.tk_call('regproc::readLic', $appname, $appversion)
end  

#core method; here we search for a string in text files within a directory and  display a list of matching files in the listbox 
def stringgrep
        $root.update
	$file_list = []
	$grep_list = []
        $p.start
        $bottomlabel.configure('text' => "Searching for \"#{$searchterm}\" in #{$dirname}")
	$lbox.delete(0, 'end')
        $root.update
	Find.find("#{$dirname}") do |path|
		$file_list << path unless FileTest.directory?(path)
	end
	for i in $file_list
	begin
		#we are only reading text files here, not binary. 
		text =  MIME::Types.type_for(i).first.to_s
		type =  text.split('/')[0]
		if type  =~ /text/
			f = File.open(i, "r:iso-8859-1:utf-8")
			result = f.read
			if result =~ /#{$searchterm}/ then
				$lbox.insert('end', "#{i}")
				f.close
			end
		end
	rescue
		#puts "Search term not found.\n"
	end
        $p.stop
        $grep_list = $lbox.get(0, 'end')
        num = $grep_list.count.to_s
        $bottomlabel.configure('text' => "Found #{num} matches for \"#{$searchterm}\" in #{$dirname}")
end
rescue
puts "Directory not found.\n"
puts "Search complete.\n"
end

def drawgui 
228
229
230
231
232
233
234
235




236
237
238
239
240
241
242
		activestyle "none"
		exportselection 0
		selectbackground "RoyalBlue1"
		selectforeground "white"
		dnd_bindtarget('text/uri-list', '<Drop>', '%D') {|d|
			filename=d.join(' ')
			begin
				if File.directory?(filename)




					$dirname = filename
					$direntry.value = filename
				end
			rescue
				raise
			end
		}







|
>
>
>
>







236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
		activestyle "none"
		exportselection 0
		selectbackground "RoyalBlue1"
		selectforeground "white"
		dnd_bindtarget('text/uri-list', '<Drop>', '%D') {|d|
			filename=d.join(' ')
			begin
			  if File.directory?(filename)
                            $tbox.configure('state'=>'normal')
	                    $tbox.delete('1.0', 'end')
                            $tbox.configure('state'=>'disabled')
                            $lbox.delete(0, 'end')
					$dirname = filename
					$direntry.value = filename
				end
			rescue
				raise
			end
		}
267
268
269
270
271
272
273

274
275
276
277
278
279
280
281
282
283
284
285



286
287
288
289
290
291
292
	$tscrollframe = Tk::Frame.new($bottomrightframe).pack('side'=>'right','fill' => 'y', 'expand' => 'no')
	$tscroll = Tk::Tile::Scrollbar.new($tscrollframe).pack('side'=>'right','fill' => 'y', 'expand' => 'no')
	$tbox.yscrollbar($tscroll)
	
	
	$labelframe = Tk::Tile::Frame.new($root).pack('side'=>'bottom', 'fill'=>'both', 'expand' => 'no')
	$bottomlabel = Tk::Tile::Label.new($labelframe) {text "No data displayed"}.pack('side' => 'left','fill' => 'both','expand' => 'no')

	$bottomsep = Tk::Tile::Separator.new($root) { orient 'horizontal' }.pack('side'=> 'bottom', 'fill'=>'both')
	
#p = Tk::Tile::Progressbar.new(parent) {orient 'horizontal'; length 200; mode 'determinate'}

#Searching for $searchterm in $dirname
	
	$root.bind("#{$accelkey}-Q", proc{exit})
	$root.bind("#{$accelkey}-q", proc{exit})
	$root.bind("#{$accelkey}-O", proc{choosedir})
	$root.bind("#{$accelkey}-o", proc{choosedir})
	$root.bind("#{$accelkey}-R", proc{stringgrep})
	$root.bind("#{$accelkey}-r", proc{stringgrep})



end


#select search directory
def choosedir
  	$tbox.configure('state'=>'normal')
	$tbox.delete('1.0', 'end')







>


<
<
<
<
|





>
>
>







279
280
281
282
283
284
285
286
287
288




289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
	$tscrollframe = Tk::Frame.new($bottomrightframe).pack('side'=>'right','fill' => 'y', 'expand' => 'no')
	$tscroll = Tk::Tile::Scrollbar.new($tscrollframe).pack('side'=>'right','fill' => 'y', 'expand' => 'no')
	$tbox.yscrollbar($tscroll)
	
	
	$labelframe = Tk::Tile::Frame.new($root).pack('side'=>'bottom', 'fill'=>'both', 'expand' => 'no')
	$bottomlabel = Tk::Tile::Label.new($labelframe) {text "No data displayed"}.pack('side' => 'left','fill' => 'both','expand' => 'no')
        $p = Tk::Tile::Progressbar.new($labelframe) {orient 'horizontal'; length 200; mode 'indeterminate'}.pack('side' => 'left','fill' => 'both','expand' => 'no')
	$bottomsep = Tk::Tile::Separator.new($root) { orient 'horizontal' }.pack('side'=> 'bottom', 'fill'=>'both')
	




  	$root.bind("#{$accelkey}-Q", proc{exit})
	$root.bind("#{$accelkey}-q", proc{exit})
	$root.bind("#{$accelkey}-O", proc{choosedir})
	$root.bind("#{$accelkey}-o", proc{choosedir})
	$root.bind("#{$accelkey}-R", proc{stringgrep})
	$root.bind("#{$accelkey}-r", proc{stringgrep})

        $lbox.focus

end


#select search directory
def choosedir
  	$tbox.configure('state'=>'normal')
	$tbox.delete('1.0', 'end')
320
321
322
323
324
325
326

327
328
329
330
331
332
333
		cur, len = $tbox.search_with_length("#{$searchterm}", cur, 'end')
		break if cur == ""
		$tbox.tag_add('search', cur, "#{cur} + #{len} char")
		cur = $tbox.index("#{cur} + #{len} char")
	}
	$tbox.configure('state'=>'disabled')
end

#about window for app
def aboutWindow
	Tk::messageBox :type => 'ok',
	:message => 'Stringscan: Text Search Tool',
	:icon => 'info', :title => 'About Stringscan',
	:detail  => "Version 1.1\n(c) 2017 WordTech Communications LLC",
	:parent => $root







>







332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
		cur, len = $tbox.search_with_length("#{$searchterm}", cur, 'end')
		break if cur == ""
		$tbox.tag_add('search', cur, "#{cur} + #{len} char")
		cur = $tbox.index("#{cur} + #{len} char")
	}
	$tbox.configure('state'=>'disabled')
end

#about window for app
def aboutWindow
	Tk::messageBox :type => 'ok',
	:message => 'Stringscan: Text Search Tool',
	:icon => 'info', :title => 'About Stringscan',
	:detail  => "Version 1.1\n(c) 2017 WordTech Communications LLC",
	:parent => $root