Class: Gui
- Inherits:
-
Object
- Object
- Gui
- Defined in:
- lib/gui.rb
Class Method Summary collapse
-
.button(btntxt, m, x, y) ⇒ Object
method to draw a button with text (btntxt), triggering method (m) and coordinates x,y.
-
.entry(var, x, y) ⇒ Object
__ method to draw an entry field sending value to variable (var)[ use $var1 to $var3].
-
.header(hdtxt, x, y) ⇒ Object
_ HEADER _.
-
.help_win ⇒ Object
we start by building a Toplevel Help window which is used by a menu as a Help guide.
-
.label(lbltxt, x, y) ⇒ Object
method to draw a label with text (lbltxt) and coordinates x,y in a grid.
-
.menu ⇒ Object
__ MENU _.
-
.root ⇒ Object
method to build the root main window.
-
.show ⇒ Object
The final and essential step, to run the mainloop for GUI to display.
-
.textfield(w, h, x, y) ⇒ Object
and foreground color (fg), and coordinates x, y, with vertical scrollbar.
Instance Method Summary collapse
-
#scroll ⇒ Object
The Scrollbar to use with textfield widget.
Class Method Details
.button(btntxt, m, x, y) ⇒ Object
method to draw a button with text (btntxt), triggering method (m) and coordinates x,y
53 54 55 56 57 58 |
# File 'lib/gui.rb', line 53 def self.(btntxt, m, x,y) TkButton.new(root){ text "#{btntxt}" command(m) grid('row' => x, 'column' => y, 'padx' => 10, 'pady' => 15)} end |
.entry(var, x, y) ⇒ Object
__ method to draw an entry field sending value to variable (var)[ use $var1 to $var3]
62 63 64 65 66 |
# File 'lib/gui.rb', line 62 def self.entry(var, x, y) TkEntry.new(root){ textvariable var grid('row' => x, 'column' => y, 'padx' => 10, 'pady' => 15)} end |
.header(hdtxt, x, y) ⇒ Object
_ HEADER _
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/gui.rb', line 38 def self.header(hdtxt, x, y) TkLabel.new(root){ text "#{hdtxt}" background "green" borderwidth 4 font TkFont.new('Proxima 16 bold') foreground "black" 'padx' '10' 'pady' '15' justify "center" relief 'raised' grid('rowspan' => x, 'columnspan' => y, 'padx' => 10, 'pady' => 15)} end |
.help_win ⇒ Object
we start by building a Toplevel Help window which is used by a menu as a Help guide
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/gui.rb', line 8 def self.help_win $win = TkToplevel.new{title "Help Window"} $scrollbar = TkScrollbar.new($win){command proc{|*args| $textwin.yview(*args)} }.pack('side' => 'right', 'fill' => 'y') $textwin =TkText.new($win){ borderwidth 1 wrap 'word' font TkFont.new('times 14 bold') background "yellow" pack('side' => 'left') } $guide = Guide.view $textwin.insert(1.0, "#{$guide}") $textwin.yscrollcommand(proc{|first, last| $scrollbar.set(first, last)}) end |
.label(lbltxt, x, y) ⇒ Object
method to draw a label with text (lbltxt) and coordinates x,y in a grid
32 33 34 35 36 |
# File 'lib/gui.rb', line 32 def self.label(lbltxt, x,y) TkLabel.new(root){ text "#{lbltxt}" grid('row' => x, 'column' => y, 'padx' => 10, 'pady' => 15)} end |
.menu ⇒ Object
__ MENU _
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 |
# File 'lib/gui.rb', line 90 def self. #No tearoff marker TkOption.add '*tearOff', 0 #____________________ METHODS _____________________________ #________________CLEAR TEXTFIELD ___________________________ newfile = Proc.new{$textfield.delete(1.0, 'end')} #______________ OPEN DIRECTORY _____________________________ opendir = Proc.new{ $dir = Tk::chooseDirectory $file_list = [] $file_list = Dir.entries($dir).select {|f| !File.directory? f} $files = $file_list.join("\n") $textfield.delete(1.0, 'end') $textfield.insert('end', "#$files") } #___________________________________ exitapp = Proc.new{exit} ###################### Menu ################### ## Menu attached to root, file and help menu = TkMenu.new root.() = TkMenu.new(root) helpMenu = TkMenu.new(root) #_______________FILE MENU_______________ .add('command', 'label' => "New...", 'command' => newfile, 'underline' => 0) .add('command', 'label' => "OpenDir", 'command' => opendir, 'underline' => 0) .add('command', 'label' => "Exit", 'command' => exitapp, 'underline' => 3) #______________HELP MENU _________________________________ helpMenu.add('command', 'label' => "Help", 'command' => proc{help_win}, 'underline' => 3) #_________________________________________ .add('cascade', 'menu' => , 'label' => "Dir") .add('cascade', 'menu' => helpMenu, 'label' => "Help") end |
.root ⇒ Object
method to build the root main window
25 26 27 28 29 |
# File 'lib/gui.rb', line 25 def self.root TkRoot.new{ title "#$title" } end |
.show ⇒ Object
The final and essential step, to run the mainloop for GUI to display
143 144 145 |
# File 'lib/gui.rb', line 143 def self.show Tk.mainloop end |
.textfield(w, h, x, y) ⇒ Object
and foreground color (fg), and coordinates x, y, with vertical scrollbar
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/gui.rb', line 70 def self.textfield(w, h, x, y) $textfield = TkText.new(root){ width w height h background "black" foreground "white" font TkFont.new('times 14 bold') grid('rowspan' => x, 'columnspan' => y, 'padx' => 10, 'pady' => 15) } end |
Instance Method Details
#scroll ⇒ Object
The Scrollbar to use with textfield widget
82 83 84 85 86 87 88 |
# File 'lib/gui.rb', line 82 def scroll $scroll = TkScrollbar.new{command proc{|*args| $textfield.yview(*args) $textfield.yscrollcommand(proc {|first, last| $scroll.set(first, last)}) pack('side' => 'right', 'fill' => 'y')} } end |