Stringscan

Check-in [f0321c7428]
Login

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

Overview
Comment:Update stringscan.rb
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: f0321c74284574e453b66ebfd2f65aecfada529b7d3c9110469823db513511be
User & Date: kevin 2017-06-20 03:10:06
Context
2017-06-20
03:15
More tweaks check-in: c51392b042 user: kevin tags: trunk
03:10
Update stringscan.rb check-in: f0321c7428 user: kevin tags: trunk
2017-06-12
03:39
Refine selection of files in listbox check-in: b5b1f268c0 user: kevin tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to scriptlibs/softwareupdate/softwareupdate.tcl.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#softwareupdate.tcl  routines to manage spoftware updates

#  Copyright (C) 2014  WordTech Communications LLC

#MIT license

package provide softwareupdate 1.5
package require http
package require tls 

::http::register https 443 [list ::tls::socket -servername codebykevin.com -request 0 -require 0 -ssl2 0 -ssl3 0 -tls1 1]

namespace eval softwareupdate {

    if {![info exists library]} {
	variable library [file dirname [info script]]








|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#softwareupdate.tcl  routines to manage spoftware updates

#  Copyright (C) 2014  WordTech Communications LLC

#MIT license

package provide softwareupdate 1.5
package require http
package require tls

::http::register https 443 [list ::tls::socket -servername codebykevin.com -request 0 -require 0 -ssl2 0 -ssl3 0 -tls1 1]

namespace eval softwareupdate {

    if {![info exists library]} {
	variable library [file dirname [info script]]

Changes to stringscan.rb.

1
2
3
4
5
6
7
8
9
10
11
12
13

14
15




16
17
18




19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66



67
68
69
70
71
72
73
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
#Stringscan: grep-like tool, written in Ruby-Tk. (c) 2017 Kevin Walzer/WordTech Communications LLC. License: MIT license.
 
#encoding: UTF-8
 
require 'tk'
require 'tkballoonhelp'
require 'tkextlib/tile'
require 'find'
require 'tkextlib/tcllib/tablelist_tile'
require 'mime/types'
require 'tk/tk_mac'
require 'tkextlib/tkDND'



$platform = Tk.windowingsystem()




if $platform == 'aqua'
  TkPackage.require('windowlist')
end






class StringscanApp

  #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. 
        if MIME::Types.type_for(i).first.media_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
    
    begin
      Tk.ip_eval("console hide")
    rescue
      puts "Could not hide console.\n"
    end

    #image data
    $folderdata = 'R0lGODlhGAAYAIABAAQHB////yH+EUNyZWF0ZWQgd2l0aCBHSU1QACH5BAEKAAEALAAAAAAYABgAAAI1hI8Wy70JgZshJurOtFzmHm0ghJXVZVJkKo7uC8cr28z0g944ojP2/aMFWcNU0SRLxk5KSQEAOw=='

    $glassdata = 'R0lGODlhGAAYAIABAAAAAP///yH+EUNyZWF0ZWQgd2l0aCBHSU1QACH5BAEKAAEALAAAAAAYABgAAAJHjI8Gy+nJYntQWkBVRDLv9zkTNXKleAYhuaBYpr2m7LWVXdOxfvMd67OATpeJcFa89JK/A1O5PMJUySlyZaVis1oel/o9FAAAOw=='

    $folderimage = TkPhotoImage.new(:data => $folderdata)
    $glassimage = TkPhotoImage.new(:data => $glassdata)



 
    #initialize variables for entry
    $dirname = TkVariable.new
    $searchterm = TkVariable.new
    #top window and frame

    Tk::TkDND::DND
    
    $root = TkRoot.new {
      title "Stringscan"
    }
    
    #menu
    $menubar = TkMenu.new($root)
    TkOption.add '*tearOff', 0
    if $platform == 'aqua'
      $appmenu = TkSysMenu_Apple.new($menubar)
      $menubar.add :cascade, :menu => $appmenu
      $appmenu.add :command, :label => 'About Stringscan', :command=> proc{aboutWindow}



      $appmenu.add :separator
    end
    $searchmenu = TkMenu.new($menubar)
    $menubar.add :cascade, :menu => $searchmenu, :label => 'Search'
    $searchmenu.add :command, :label => 'Run Search', :command => proc{stringgrep}
    $searchmenu.add :command, :label => 'Choose Directory...', :command => proc{ $dirname = Tk::chooseDirectory('initialdir'=>Dir.home, 'parent'=>$root)
      $direntry.value = $dirname
    }
    if $platform == 'win32'
      $searchmenu.add :command, :label => "Exit", :command=>exit
    end
    if $platform == 'aqua'
      Tk.tk_call("windowlist::windowMenu",  $menubar)
    end
    $helpmenu = TkSysMenu_Help.new($menubar)
    $menubar.add :cascade, :menu => $helpmenu, :label => 'Help'
    if $platform == 'aqua'










      #       Tk.ip_eval("proc ::tk::mac::ShowHelp {} {#{Tk.install_cmd(proc{...})}}")





    end
    $root['menu'] = $menubar
    $mainframe = Tk::Tile::Frame.new($root).pack('side' => 'top','fill' => 'both','expand' => 'yes')
 
    #button frame and buttons
    $buttonframe = Tk::Tile::Frame.new($mainframe){padding 2}.pack('side' => 'top','fill' => 'both','expand' => 'no')
    $choosebutton = Tk::Tile::Button.new($buttonframe) {
      image $folderimage
      takefocus 0
      padding 5













>

|
>
>
>
>



>
>
>
>














|

|
















|
<

|

|







|
|
>
>
>







<
|
|









>
>
>


|









|



|
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>


|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61

62
63
64
65
66
67
68
69
70
71
72
73
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#Stringscan: grep-like tool, written in Ruby-Tk. (c) 2017 Kevin Walzer/WordTech Communications LLC. License: MIT license.
 
#encoding: UTF-8
 
require 'tk'
require 'tkballoonhelp'
require 'tkextlib/tile'
require 'find'
require 'tkextlib/tcllib/tablelist_tile'
require 'mime/types'
require 'tk/tk_mac'
require 'tkextlib/tkDND'

$platform = Tk.windowingsystem()

if $platform == 'aqua'
  Tk::AUTO_PATH.list <<= File.dirname(__FILE__)
end


if $platform == 'aqua'
  TkPackage.require('windowlist')
end
TkPackage.require('regproc')
TkPackage.require('machelp')
TkPackage.require('softwareupdate')
TkPackage.require('xplat')


class StringscanApp

  #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. 
        if MIME::Types.type_for(i).first.media_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 

    begin
      tk.ip_eval("console hide")
    rescue
      puts "could not hide console.\n"
    end

    #image data
    $folderdata = 'R0lGODlhGAAYAIABAAQHB////yH+EUNyZWF0ZWQgd2l0aCBHSU1QACH5BAEKAAEALAAAAAAYABgAAAI1hI8Wy70JgZshJurOtFzmHm0ghJXVZVJkKo7uC8cr28z0g944ojP2/aMFWcNU0SRLxk5KSQEAOw=='

    $glassdata = 'R0lGODlhGAAYAIABAAAAAP///yH+EUNyZWF0ZWQgd2l0aCBHSU1QACH5BAEKAAEALAAAAAAYABgAAAJHjI8Gy+nJYntQWkBVRDLv9zkTNXKleAYhuaBYpr2m7LWVXdOxfvMd67OATpeJcFa89JK/A1O5PMJUySlyZaVis1oel/o9FAAAOw=='

    $folderimage = tkphotoimage.new(:data => $folderdata)
    $glassimage = tkphotoimage.new(:data => $glassdata)

    $icondata = 'R0lGODlhQABAAOf/AB8jJSktLyUvLyouMCsvMSwwMi0xMy4yNC8zNS80NjI2ODU5Ozc7PT5APjxBQz5CRUJEQUJGSERJS0hKR0ZLTUBPX0tPUk9QTk5SVFBST0dVZlJUUVBVV1RVU0NZaFJXWVVXVVZYVUdab1dZVlVaXFhaV1lbWFpcWVhcX0tedFtdWi1kplxeW09hbF5fXTZlm1xgYzhloUlkeV9hXkhlhWBiX15jZWFjYE9mgT1opWJkYTRsp2NlYmRlY2VmZGZnZWNoaj9to1FsgU9sjGdpZlRsh2VqbGhqZ2lraElvoGpsaVNwkWttamltcF5we1lwjEZzqm1vbFFzmW5wbWxwc1l0iVh0lXByb25ydVR2nHJzcUt5qk14sHB0d2V3gnN1clx4mUh7uFt6lXV3dHN3ell7oWZ5kFh9nVZ9qXd5dnp5cVKAsXl7eFt/slaAuWN/oGx/il+Ap3h9f3t9enx+e2GCqX1/fH+BfmWGrXeGjIKEgWKJtmmJpIOFgoGFiHKImW6Jn4SGg4eGfnaJlWWLuIWHhHyIlWOOs2mNrluPx2yNtXSMqIiKh3eOnomLiHGQq4uMiXyPm3+PlYyOi4+OhnGSuY6QjXmUqpKRiX6VppCSj3eWspKUkXuXun2YrpSWk3Gd0H+bvpGZoXedyoWcrZeZloKdtH6euZqcmXyhwpyem4yjtImlu4ykwaCin4Gn1YyovqSlooqqxpGoxqaopYiu3Jauv6mrqKOstJqtxZWwx6utqp2wyaGww7Cvpoy13a+xrqeywLK0sa63v6i4y7W3tKy4xaG94aK+1bm7uLC8yrS8xJ3C5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Oc2thGNVZDiEpcQgxRCwQ6r8karWtUCYK/Ahk/EAhjNgMY0ArBEBLChD1+YaCns4QwoPEIZmF2GZocxDFHAoRGZAEQRnpAEXqgDGmm4ghZWu9panYZWbGD+Ax0CoYkQNVYLXSuSPtKRg0eYohfGMMYwcCGKPBgiEo2oggyKYIUYZCMeu5iDdKdLXenS4brX1cMkbPuS4ZCAEYXQAzjiQQg8LAIQgPjDHwYRCUlIwgkeSAEOhiAFLsBjHoyYFCUoMYn++ve//63tWwKAAAW4wA52vEYOPMHgTGRiEF5oQQU0IAIaDKG5zsDHND6Apw57+MMfLpvZEDCAMcSDHq1IghiqIIQUiMADIqjwEJaQhSQoAh766MMAAMDjHgMAURKJQCz6AY9KvOAJTyjCEqQghSVn4QxBaAM7+nGLEQC5MnNIhgNnsYItKAIPdYhDHOqwhRWEAh79UIfyOnahgiu/RQ/N6Mc+vNGJHaxgB3bOgSKugY9+pAMcluhDLELg5qcU4hbx6Ic+6JENt16DHvTDhyug0ZNS6MGAhX7KJJKhDn3wox+g1kc8isGEDZTiFqrYBSoEzQQIZNopdrBELHaxi1gwogYdEAgEILGLU7uiEKqgg6tfnSYIpEEYp44FJDgxiWETW0xEKEYpaEGL/pZiAs9O0wmkHYtbaIIRrshAticSD3vYYx7qgEgGgFGKbt8im9get0HmF+p4kAMiE6CFKmKRjmzOQd5ZggAqmkEOcsSDCQDPUgNKgQ98AKMBCRfTBTIA8Yhb/OKICggAOw=='
    $icon = tkphotoimage.new(:data => $icondata)
 
    #initialize variables for entry
    $dirname = TkVariable.new
    $searchterm = TkVariable.new
    #top window and frame

    Tk::TkDND::DND

    $root = tkroot.new {
      title "stringscan"
    }
    
    #menu
    $menubar = TkMenu.new($root)
    TkOption.add '*tearOff', 0
    if $platform == 'aqua'
      $appmenu = TkSysMenu_Apple.new($menubar)
      $menubar.add :cascade, :menu => $appmenu
      $appmenu.add :command, :label => 'About Stringscan', :command=> proc{aboutWindow}
      $appmenu.add :command, :label => 'License', :command=>proc{getReg}
      $appmenu.add :command, :label=>'Check for Updates', :command=>proc{checkUpdate}
      
      $appmenu.add :separator
    end
  $searchmenu = TkMenu.new($menubar)
    $menubar.add :cascade, :menu => $searchmenu, :label => 'Search'
    $searchmenu.add :command, :label => 'Run Search', :command => proc{stringgrep}
    $searchmenu.add :command, :label => 'Choose Directory...', :command => proc{ $dirname = Tk::chooseDirectory('initialdir'=>Dir.home, 'parent'=>$root)
      $direntry.value = $dirname
    }
    if $platform == 'win32'
      $searchmenu.add :command, :label => "Exit", :command=>exit
    end
    if $platform == 'aqua'
      tk.tk_call("windowlist::windowMenu",  $menubar)
    end
    $helpmenu = TkSysMenu_Help.new($menubar)
    $menubar.add :cascade, :menu => $helpmenu, :label => 'Help'
      if $platform != 'aqua'
        $helpmenu.add :command, :label=>'Stringscan Help', :command=>proc{
        tk.tk_call('machelp::userhelp')
        }
      end
         $helpmenu.add :command, :label=>'Contact Code by Kevin', :command=>proc{
        Tk.tk_call('xplat::launch', 'mailto:kw@codebykevin.com?subject=Stringscan')
     }
      $helpmenu.add :command, :label=>'Web Site', :command=>proc{
         Tk.tk_call('xplat::launch', 'https://www.codebykevin.com/stringscan.html')
      }

      if $platform != 'aqua'
      $helpmenu.add :command, :label => 'About Stringscan', :command=> proc{aboutWindow}
      $helpmenu.add :command, :label => 'License', :command=>proc{getReg}
      $helpmenu.add :command, :label=>'Check for Updates', :command=>proc{checkUpdate}
      
    end
    $root['menu'] = $menubar
   $mainframe = Tk::Tile::Frame.new($root).pack('side' => 'top','fill' => 'both','expand' => 'yes')
 
    #button frame and buttons
    $buttonframe = Tk::Tile::Frame.new($mainframe){padding 2}.pack('side' => 'top','fill' => 'both','expand' => 'no')
    $choosebutton = Tk::Tile::Button.new($buttonframe) {
      image $folderimage
      takefocus 0
      padding 5
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231

232
233
234





235











236
237

238
239





240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255

256
257
258
259
260
261
262

      state 'disabled'
    }.pack('side'=>'left','fill' => 'both', 'expand' => 'yes')
    $tscrollframe = Tk::Frame.new($bottomrightframe).pack('side'=>'right','fill' => 'y', 'expand' => 'no')
    $tscroll = Tk::Scrollbar.new($tscrollframe).pack('side'=>'right','fill' => 'y', 'expand' => 'no')
    $tbox.yscrollbar($tscroll)
  end


  #read file for display in text widget
  def highlighttext(file)
   $tbox.configure('state'=>'normal')
   $tbox.delete('1.0', 'end') 
   f = open(file, 'rb')
    while(!f.eof?)
      $tbox.insert('end', f.read(1000))
	end
    f.close
    $tbox.configure('state'=>'disabled')
    $tbox.tag_configure('search', :background=>'yellow')
    sethighlight
  end

  #set highlight color for search term
  def sethighlight
    $tbox.configure('state'=>'normal')
    $tbox.tag_remove('search', '0.0', 'end')
    return if $searchterm == ""
    cur = '1.0'
    loop {
      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',

    :parent => $root
  end






 











  #here we initialize our app class
   def initialize

    $dirname = ""
    $searchterm = ""






        if $platform == 'aqua'
          ##map Ruby proc to "odoc" Apple Event
          setDir = Tk.install_cmd(proc{
                               |*args|
                               filename=(args[0]).delete('{}')
                               begin
                                 if File.directory?(filename)
                                   $dirname = filename
                                   $direntry.value = filename
                                 end
                               rescue
                                 raise
                               end
                          })    
     Tk.ip_eval("proc ::tk::mac::OpenDocument {args} {#{setDir} $args}")

        end        
    drawgui()
  end             
end
 
app = StringscanApp.new()
Tk.mainloop()








<











|



















|
|


>



>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>

|
>


>
>
>
>
>


|












|
>







>
217
218
219
220
221
222
223

224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
      state 'disabled'
    }.pack('side'=>'left','fill' => 'both', 'expand' => 'yes')
    $tscrollframe = Tk::Frame.new($bottomrightframe).pack('side'=>'right','fill' => 'y', 'expand' => 'no')
    $tscroll = Tk::Scrollbar.new($tscrollframe).pack('side'=>'right','fill' => 'y', 'expand' => 'no')
    $tbox.yscrollbar($tscroll)
  end


  #read file for display in text widget
  def highlighttext(file)
   $tbox.configure('state'=>'normal')
   $tbox.delete('1.0', 'end') 
   f = open(file, 'rb')
    while(!f.eof?)
      $tbox.insert('end', f.read(1000))
	end
    f.close
    $tbox.configure('state'=>'disabled')
    $tbox.tag_configure('search', :background=>'yellow')
    sethighlight()
  end

  #set highlight color for search term
  def sethighlight
    $tbox.configure('state'=>'normal')
    $tbox.tag_remove('search', '0.0', 'end')
    return if $searchterm == ""
    cur = '1.0'
    loop {
      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.0\n(c) 2017 Wordtech Communications LLC",
    :parent => $root
  end

#check version of installed software
def checkUpdate 
    Tk.tk_call('softwareupdate::setIcon', $icon)
    Tk.tk_call('softwareupdate::checkVersion', $appname, $appversion)
end

#check version of installed software
def getReg
  tk.tk_call('regproc::getReg')
end

#user help
def showhelp
  tk.tk_call('machelp::showhelp')
end
  
 
  #here we initialize our app class
def initialize

    $dirname = ""
    $searchterm = ""
    $appname = 'stringscan'
    $appnversion = '1.0'
    Tk.tk_call('machelp::setAppName', $appname, $appversion)
    Tk.tk_call('softwareupdate::setAppName', $appname);
    Tk.tk_call('softwareupdate::setVersion', $appname, $appversion);

        if $platform == 'aqua'
          ##map ruby proc to "odoc" Apple Event
          setDir = Tk.install_cmd(proc{
                               |*args|
                               filename=(args[0]).delete('{}')
                               begin
                                 if File.directory?(filename)
                                   $dirname = filename
                                   $direntry.value = filename
                                 end
                               rescue
                                 raise
                               end
                          })    
          Tk.ip_eval("proc ::tk::mac::OpenDocument {args} {#{setdir} $args}")
          Tk.ip_eval("proc ::tk::mac::ShowHelp {} {#{tk.install_cmd(proc{showhelp})}}")
        end        
    drawgui()
  end             
end
 
app = StringscanApp.new()
Tk.mainloop()