hetch 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (8) hide show
  1. data/README.md +55 -0
  2. data/hetch.gemspec +28 -0
  3. data/hetch_tk.rb +23 -0
  4. data/lib/gui.rb +107 -0
  5. data/lib/guide.rb +41 -0
  6. data/lib/hetch.rb +14 -0
  7. data/test.txt +17 -0
  8. metadata +56 -0
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ Hetch is Graphical User interface to fetch a Regex pattern from a text file and display the result in a text window in the same GUI.
2
+
3
+ The Gui is called by a simpified call to the Tcl/Tk Syntax built in a gui class in a separate "gui.rb"file.
4
+
5
+ The "gui.rb"demonstrates the way to call various widgets including a Help menu on the Menubar which includes the instruction on use of "gui.rb". The Help text is included in a separate "guide.rb" file.
6
+
7
+ Classes:
8
+ class Gui
9
+ class H # Hetch file to fetch string matching a pattern
10
+ class Guide # to "view" the help instructions
11
+
12
+ Files:
13
+ gui.rb
14
+ hetch.rb
15
+ guide.rb
16
+ hetch_tk # file containing the main script to call GUI
17
+
18
+ USAGE:
19
+ simply run 'hetch_tk' file from the command prompt
20
+
21
+ Using the 'gui.rb' file:
22
+ the Gui class may be used for building other Gui's by calling the class name followed by the method with its parameters.
23
+ x, y are the row number (x) and column number (y) in grid geometry
24
+
25
+ 1. Gui.root: no parameters
26
+ 2. Gui.entry($var1, x, y) : $var1 is the variable that contains entry text.
27
+ Gui.entry($var2, x, y) : $var2 is the variable that contains entry
28
+ 3. Gui.textfield(h, w, c1, c2, x, y) : The parameters are
29
+ h=height, w=width, c1=background color, c2=foreground color
30
+ 4. Gui.button(tx1, m, x, y) : tx1= text on button, m= method triggered by button.
31
+ The method should be written in the active script before the end Gui.show command. e.g.
32
+ This simple method just add the two variables and get result into the text window.
33
+ def m
34
+ z = $var1+ $var2
35
+ $textfield.delete(1.0, 'end')
36
+ $textfield.insert(1.0, '#{z}')
37
+ end
38
+ 5. Gui.label(tx2, x, y): tx2 = text on label
39
+ 6. Gui.show :Tk.mainloop
40
+ #______________SAMPLE SCRIPT___________________
41
+ require_relative 'gui'
42
+ Gui.root
43
+ Gui.menu
44
+ Gui.label("Enter Number", 0, 0)
45
+ Gui.entry($var1, 0, 1)
46
+ Gui.label("Enter Number", 1, 0)
47
+ Gui.entry($var2, 1, 1)
48
+ Gui.textfield(15, 1, "black", "white", 2, 1)
49
+ Gui.button("OK", "m" , 2, 0)
50
+ def m
51
+ $z = $var1 + $var2
52
+ $textfield.insert('end', "#$z")
53
+ end
54
+ Gui.show
55
+ #________________________________________________
data/hetch.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "hetch"
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Sabry A F"]
9
+ s.date = "2015-02-11"
10
+ s.description = "hetch is a GUI application to search a comma-separated text file and fetch data based on Regex search pattern. The Gui is based on simplified Tcl/Tk command statements"
11
+ s.email = "sabryabdelfattah@gmail.com"
12
+ s.extra_rdoc_files = ["README.md"]
13
+ s.files = ["hetch.gemspec", "hetch_tk.rb", "README.md", "test.txt", "lib/gui.rb", "lib/guide.rb", "lib/hetch.rb"]
14
+ s.homepage = "http://sabryfattah.com"
15
+ s.rdoc_options = ["--main", "README.md"]
16
+ s.require_paths = ["lib"]
17
+ s.rubygems_version = "1.8.29"
18
+ s.summary = "tk-based Gui App. to search for Regex match in text file"
19
+
20
+ if s.respond_to? :specification_version then
21
+ s.specification_version = 3
22
+
23
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
24
+ else
25
+ end
26
+ else
27
+ end
28
+ end
data/hetch_tk.rb ADDED
@@ -0,0 +1,23 @@
1
+ require 'lib/gui'
2
+ require 'lib/hetch'
3
+ #_________________________________________________________________
4
+ #Main Script to build a GUI for "hetch.rb"
5
+ # user enter the name of the file without extension and Regex matching pattern to fetch
6
+ # The statements here are based on "gui.rb" which simplify "tcl/tk" commands
7
+ #The script require both "gui.rb" and "hetch.rb"
8
+ # For instruction on usage of "gui.rb" click on help on the menubar
9
+ Gui.root
10
+ Gui.menu
11
+ Gui.label("File Name", 0, 0)
12
+ Gui.entry($var1, 0, 1)
13
+ Gui.label("Regex pattern", 1, 0)
14
+ Gui.entry($var2, 1, 1)
15
+ #Gui.label("Result", 3, 0)
16
+ Gui.textfield(35, 8, "black", "white", 2, 2)
17
+ Gui.button("Search", "m" , 6, 0)
18
+ def m
19
+ z = H.fetch("#{$var1}.txt", $var2)
20
+ $textfield.delete('1.0','end')
21
+ $textfield.insert('end', "#{z}")
22
+ end
23
+ Gui.show
data/lib/gui.rb ADDED
@@ -0,0 +1,107 @@
1
+ require 'tk'
2
+ require_relative 'guide'
3
+ #A class which uses tcl/tk to build a GUI for user interaction
4
+ #_______________________________________________
5
+ class Gui
6
+ #we start by building a Toplevel Help window which is used by a menu as a Help guide
7
+ def self.help_win
8
+ $win = TkToplevel.new{title "Help Window"}
9
+ $scrollbar = TkScrollbar.new($win){command proc{|*args| $textwin.yview(*args)}
10
+ }.pack('side' => 'right', 'fill' => 'y')
11
+ $textwin =TkText.new($win){
12
+ borderwidth 5
13
+ wrap 'word'
14
+ font TkFont.new('times 16 bold')
15
+ background "yellow"
16
+ pack('side' => 'right')
17
+ }
18
+ $guide = Guide.view
19
+ $textwin.insert(1.0, "#{$guide}")
20
+ $textwin.yscrollcommand(proc{|first, last| $scrollbar.set(first, last)})
21
+ end
22
+ #_______________________________________________________
23
+ #method to build the root main window
24
+ def self.root
25
+ TkRoot.new{
26
+ title "GUI"
27
+ }
28
+ end
29
+ #_______________________________________________________
30
+ #method to draw a label with text (tx1) and coordinates x,y in a grid
31
+ def self.label(tx1, x, y)
32
+ TkLabel.new(root){
33
+ text tx1
34
+ grid('row' => x, 'column' => y, 'padx' => 10, 'pady' => 15)}
35
+ end
36
+ #________________________________________________________
37
+ #method to draw a button with text (tx2), triggering method (m) and coordinates x,y
38
+ def self.button(tx2, m, x, y)
39
+ TkButton.new(root){
40
+ text tx2
41
+ command(m)
42
+ grid('row' => x, 'column' => y, 'padx' => 10, 'pady' => 15)}
43
+ end
44
+ #__________________________________________________________
45
+ #global variables declared for use in the class method
46
+ $var1 = TkVariable.new
47
+ $var2 = TkVariable.new
48
+ $var3 = TkVariable.new
49
+ #________________________________________________________
50
+ #method to draw an entry field sending value to variable (var)[ use $var1 to $var3]
51
+ def self.entry(var, x, y)
52
+ TkEntry.new(root){
53
+ textvariable var
54
+ grid('row' => x, 'column' => y, 'padx' => 10, 'pady' => 15)}
55
+ end
56
+ #_____________________________________________________________
57
+ #method to draw a textfield with specific width (w), height (h), background color (bg)
58
+ #and foreground color (fg), and coordinates x, y, with vertical scrollbar
59
+ def self.textfield(w, h, bg, fg, x, y)
60
+ $textfield = TkText.new(root){
61
+ width w
62
+ height h
63
+ background bg
64
+ foreground fg
65
+ font TkFont.new('times 16 bold')
66
+ grid('rowspan' => x, 'columnspan' => y, 'padx' => 10, 'pady' => 15)
67
+ }
68
+ end
69
+ #___________________________________________________________
70
+ #method to insert result of the method into the textfield widget
71
+ def self.insert_text(content)
72
+ $textfield.delete(1.0, 'end')
73
+ $textfield.insert('end', content)
74
+ end
75
+
76
+ #____________________________________________________________
77
+ #The Scrollbar to use with textfield widget
78
+ def scroll
79
+ $scroll = TkScrollbar.new{command proc{|*args|
80
+ $textfield.yview(*args)
81
+ $textfield.yscrollcommand(proc {|first, last| $scroll.set(first, last)})
82
+ pack('side' => 'right', 'fill' => 'y')}
83
+ }
84
+ end
85
+ #______________________________________________________________
86
+ # menu to display at the root window menubar
87
+ def self.menu
88
+ TkOption.add '*tearOff', 0
89
+ menu = TkMenu.new(root)
90
+ menu.add('command',
91
+ 'label' => "Help",
92
+ 'command' => proc{help_win},
93
+ 'underline' => 3)
94
+ menu_bar = TkMenu.new
95
+ menu_bar.add('cascade',
96
+ 'menu' => menu,
97
+ 'label' => "Help")
98
+ root.menu(menu_bar)
99
+ end
100
+ #____________________________________________________________
101
+ #The final and essential step, to run the mainloop for GUI to display
102
+ def self.show
103
+ Tk.mainloop
104
+ end
105
+
106
+ end
107
+ #__________________________________________________________
data/lib/guide.rb ADDED
@@ -0,0 +1,41 @@
1
+ #here document to use in Help Window accessed through the menu
2
+ class Guide
3
+ #__________________________________________________________
4
+ def self.view
5
+ return $guide
6
+ end
7
+ #__________________________________________________________
8
+ $guide = %q{
9
+ USAGE:
10
+ x, y are the row number (x) and column number (y) in grid geometry
11
+ 1. Gui.root: no options
12
+ 2. Gui.entry($var1, x, y) : variable that contains entry
13
+ Gui.entry($var1, x, y) : variable that contains entry
14
+ 3. Gui.textfield(h, w, c1, c2, x, y) : h=height, w=width, c1=background, c2=foreground
15
+ 4. Gui.button(tx1, m, x, y) : tx1= text on button, m= method triggered by button.
16
+ Method should be written in the active script. e.g.
17
+ def m
18
+ z = $var1+ $var2
19
+ $textfield.delete(1.0, 'end')
20
+ $textfield.insert(1.0, '#{z}')
21
+ end
22
+ 5. Gui.label(tx2, x, y): tx2 = text on label
23
+ 6. Gui.show :Tk.mainloop
24
+ #______________EXAMPLE___________________
25
+ require_relative 'gui'
26
+ Gui.root
27
+ Gui.menu
28
+ Gui.label("Enter Number", 0, 0)
29
+ Gui.entry($var1, 0, 1)
30
+ Gui.label("Enter Number", 1, 0)
31
+ Gui.entry($var2, 1, 1)
32
+ Gui.textfield(15, 1, "black", "white", 2, 1)
33
+ Gui.button("OK", "m" , 2, 0)
34
+ def m
35
+ $z = $var1 + $var2
36
+ $textfield.insert('end', "#$z")
37
+ end
38
+ Gui.show
39
+ }
40
+ #________________________________________________________
41
+ end
data/lib/hetch.rb ADDED
@@ -0,0 +1,14 @@
1
+ #A class to search a text file and fetch a string matching a Regex pattern
2
+ # user provides the name of the file without extension and the Regex matching pattern
3
+ class H
4
+
5
+ def self.fetch(file, match)
6
+ h = Hash[File.read("#{file}").split("\n").map{|i| i.split(', ')}]
7
+ m = h.keys
8
+ key = m.grep(/#{match}/)
9
+ arr = []
10
+ key.each{|a| arr.push(a," \n ", h.fetch(a), " \n")}
11
+ return arr.join("")
12
+ end
13
+
14
+ end
data/test.txt ADDED
@@ -0,0 +1,17 @@
1
+ James Benton,70116/504-621-8927/504-845 1427
2
+ Josephine Jeffrey, 48116/810-292-9388/810-374-9840
3
+ Art James, 8014/856-636-8749/856-264
4
+ Lenna Johnston, 907-385-4412/907-921-2010
5
+ Donette Foller, 513-570-1893/513-549-4561
6
+ Simona Morasca, 44805/419-503-2484/419-800-6759
7
+ Mitsue Tollner, 60632/773-573-6914/773-924-8565
8
+ Leota Dilliard, 408-752-3500/408-813-
9
+ Sage Wieser, 57105/605-414-2147/605-794-
10
+ Kris Marrier, 21224/410-655-8723/410-804-4694
11
+ Minna Amigon, 19443/215-874-1229/215-422-8694
12
+ Abel Maclead, 11953/631-335-3414/631-677-3675
13
+ Kiley Caldarera, 310-498-5651/310-254-3084
14
+ Graciela Ruta, 44023/440-780-8425/440-579-
15
+ Cammy Albares, 78045/956-537-6195/956-841-7216
16
+ Mattie Poquette, 85013/602-277-4385/602-953-6360
17
+ Meaghan Garufi, 37110/931-313-9635/931-235-7959
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hetch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sabry A F
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-02-11 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: hetch is a GUI application to search a comma-separated text file and
15
+ fetch data based on Regex search pattern. The Gui is based on simplified Tcl/Tk
16
+ command statements
17
+ email: sabryabdelfattah@gmail.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files:
21
+ - README.md
22
+ files:
23
+ - hetch.gemspec
24
+ - hetch_tk.rb
25
+ - README.md
26
+ - test.txt
27
+ - lib/gui.rb
28
+ - lib/guide.rb
29
+ - lib/hetch.rb
30
+ homepage: http://sabryfattah.com
31
+ licenses: []
32
+ post_install_message:
33
+ rdoc_options:
34
+ - --main
35
+ - README.md
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubyforge_project:
52
+ rubygems_version: 1.8.29
53
+ signing_key:
54
+ specification_version: 3
55
+ summary: tk-based Gui App. to search for Regex match in text file
56
+ test_files: []