cf_conv 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.
- checksums.yaml +15 -0
- data/README.md +17 -0
- data/lib/cf_conv.rb +26 -0
- data/lib/gui.rb +137 -0
- metadata +51 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
---
|
|
2
|
+
!binary "U0hBMQ==":
|
|
3
|
+
metadata.gz: !binary |-
|
|
4
|
+
NGE3ZTAyYjllZGUyZmQ4NThkYmU1N2FlNDc0NWQ3Y2I4MTNjMWNiNg==
|
|
5
|
+
data.tar.gz: !binary |-
|
|
6
|
+
NzM5YjViNDI3MDQzYTk1MGQyMGNmMDZhZDBlNzVhNzM0MzQ1Y2M4Ng==
|
|
7
|
+
SHA512:
|
|
8
|
+
metadata.gz: !binary |-
|
|
9
|
+
ZjRlNTRiM2ZjYzBkNmU4MjhkYTlhMGE3MDhmZjJiYzhmM2Q3N2Q2NTc4OGE4
|
|
10
|
+
ZTY2NWNhYTg5NTNhNDA1YTczZjNlNzkzOWU4ODQzMWQyMTFlOTI1Njg2MTFk
|
|
11
|
+
ZThkYmNlZTE2OGUxNmU3MmU2MmYzYjIzNTcxZGM1YTkxMWFlYzA=
|
|
12
|
+
data.tar.gz: !binary |-
|
|
13
|
+
MjkwODExMmYzNzcxYjgyNTA2MDQ2YWQyMzdlOGExM2U0YTlmZTRiNTE3NDky
|
|
14
|
+
N2M0OWQzZmQ1NWM0ZTM3Mjk1YTZiNWFlODkwOTkzNmE5MjkxNzI1NzQzMjM4
|
|
15
|
+
ZGRkY2M0NmVmZGI5NmZjOTY1MjI5ODA4OTY2MzVlOWVjMmYxYzU=
|
data/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Cf_Conv
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
install cf_conv yourself as:
|
|
5
|
+
|
|
6
|
+
$ gem install cf_conv
|
|
7
|
+
|
|
8
|
+
## Usage
|
|
9
|
+
|
|
10
|
+
This is a graphical user interface app. Create a ruby file with the following code (notice the backticks):
|
|
11
|
+
```
|
|
12
|
+
require 'cf_conv'
|
|
13
|
+
`cf-conv`
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
and save it as "cf.rb"
|
|
17
|
+
Create a desktop shortcut link to this file. When the shortcut link is clicked the app will be launched.
|
data/lib/cf_conv.rb
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require_relative 'gui'
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
Gui.menu
|
|
5
|
+
Gui.label("Temp in Centigrade", 0, 0)
|
|
6
|
+
Gui.entry($var1, 0, 1)
|
|
7
|
+
Gui.label("Temp in Fahrenheit", 1, 0)
|
|
8
|
+
Gui.entry($var2, 1, 1)
|
|
9
|
+
Gui.textfield(30, 1, "black", "white", 2, 0, 2)
|
|
10
|
+
Gui.button("Centigrade to Fahrenheit", "c" , 3, 0)
|
|
11
|
+
Gui.button("Fahrenheit to Centigrade", "f" , 3, 1)
|
|
12
|
+
|
|
13
|
+
def c
|
|
14
|
+
y = $var1
|
|
15
|
+
$textfield.delete('1.0', 'end')
|
|
16
|
+
$textfield.insert('end', "#{(y * 9/5) + 32} Fahrenheit")
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def f
|
|
21
|
+
x = $var2
|
|
22
|
+
$textfield.delete('1.0', 'end')
|
|
23
|
+
$textfield.insert('end', "#{(x - 32) * 5/9} Centigrade")
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
Gui.show
|
data/lib/gui.rb
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
require 'tk'
|
|
2
|
+
#A class which uses tcl/tk to draw a GUI for user interaction
|
|
3
|
+
#_______________________________________________
|
|
4
|
+
class Gui
|
|
5
|
+
#Start by building a Toplevel Help window which is used by a menu for a Help guide
|
|
6
|
+
def self.help_win
|
|
7
|
+
$win = TkToplevel.new{title "Help Window"}
|
|
8
|
+
$scrollbar = TkScrollbar.new($win){command proc{|*args| $textwin.yview(*args)}
|
|
9
|
+
}.pack('side' => 'right', 'fill' => 'y')
|
|
10
|
+
$textwin =TkText.new($win){
|
|
11
|
+
borderwidth 5
|
|
12
|
+
wrap 'word'
|
|
13
|
+
font TkFont.new('times 16 bold')
|
|
14
|
+
background "yellow"
|
|
15
|
+
pack('side' => 'right')
|
|
16
|
+
}
|
|
17
|
+
$textwin.insert(1.0, "#{$guide}")
|
|
18
|
+
$textwin.yscrollcommand(proc{|first, last| $scrollbar.set(first, last)})
|
|
19
|
+
end
|
|
20
|
+
#_______________________________________________________
|
|
21
|
+
#method to build the root main window
|
|
22
|
+
def self.root
|
|
23
|
+
TkRoot.new{
|
|
24
|
+
title "Title"}
|
|
25
|
+
end
|
|
26
|
+
#_______________________________________________________
|
|
27
|
+
#method to draw a label with text (tx1) and coordinates x,y in a grid
|
|
28
|
+
def self.label(tx1, x, y)
|
|
29
|
+
TkLabel.new(root){
|
|
30
|
+
text tx1
|
|
31
|
+
grid('row' => x, 'column' => y, 'padx' => 10, 'pady' => 15)}
|
|
32
|
+
end
|
|
33
|
+
#________________________________________________________
|
|
34
|
+
#method to draw a button with text (tx2), triggering method (m) and coordinates x,y
|
|
35
|
+
def self.button(tx2, m, x, y)
|
|
36
|
+
TkButton.new(root){
|
|
37
|
+
text tx2
|
|
38
|
+
command(m)
|
|
39
|
+
grid('row' => x, 'column' => y, 'padx' => 10, 'pady' => 15)}
|
|
40
|
+
end
|
|
41
|
+
#__________________________________________________________
|
|
42
|
+
#global variables declared for use in the class methods
|
|
43
|
+
$var1 = TkVariable.new
|
|
44
|
+
$var2 = TkVariable.new
|
|
45
|
+
$var3 = TkVariable.new
|
|
46
|
+
#________________________________________________________
|
|
47
|
+
#method to draw an entry field sending value to variable (var)[ use $var1 to $var3]
|
|
48
|
+
def self.entry(var, x, y)
|
|
49
|
+
TkEntry.new(root){
|
|
50
|
+
textvariable var
|
|
51
|
+
grid('row' => x, 'column' => y, 'padx' => 10, 'pady' => 15)}
|
|
52
|
+
end
|
|
53
|
+
#_____________________________________________________________
|
|
54
|
+
#method to draw a textfield with specific width (w), height (h), background color (bg)
|
|
55
|
+
#and foreground color (fg), (content) and coordinates x, y, with vertical scrollbar
|
|
56
|
+
def self.textfield(w, h, bg, fg, x, y, z)
|
|
57
|
+
$textfield = TkText.new(root){
|
|
58
|
+
width w
|
|
59
|
+
height h
|
|
60
|
+
background bg
|
|
61
|
+
foreground fg
|
|
62
|
+
font TkFont.new('times 16 bold')
|
|
63
|
+
grid('row' => x, 'column' => y,'columnspan' => z, 'padx' => 10, 'pady' => 15)
|
|
64
|
+
}
|
|
65
|
+
end
|
|
66
|
+
#___________________________________________________________
|
|
67
|
+
#method to insert result of the method into the textfield widget
|
|
68
|
+
def self.insert_text(content)
|
|
69
|
+
$textfield.delete(1.0, 'end')
|
|
70
|
+
$textfield.insert('end', content)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
#____________________________________________________________
|
|
74
|
+
#The Scrollbar to use with textfield widget
|
|
75
|
+
def scroll
|
|
76
|
+
$scroll = TkScrollbar.new{command proc{|*args|
|
|
77
|
+
$textfield.yview(*args)
|
|
78
|
+
$textfield.yscrollcommand(proc {|first, last| $scroll.set(first, last)})
|
|
79
|
+
pack('side' => 'right', 'fill' => 'y')}
|
|
80
|
+
}
|
|
81
|
+
end
|
|
82
|
+
#______________________________________________________________
|
|
83
|
+
# menu to display and the root window menubar
|
|
84
|
+
def self.menu
|
|
85
|
+
TkOption.add '*tearOff', 0
|
|
86
|
+
menu = TkMenu.new(root)
|
|
87
|
+
menu.add('command',
|
|
88
|
+
'label' => "Help",
|
|
89
|
+
'command' => proc{help_win},
|
|
90
|
+
'underline' => 3)
|
|
91
|
+
menu_bar = TkMenu.new
|
|
92
|
+
menu_bar.add('cascade',
|
|
93
|
+
'menu' => menu,
|
|
94
|
+
'label' => "Help")
|
|
95
|
+
root.menu(menu_bar)
|
|
96
|
+
end
|
|
97
|
+
#____________________________________________________________
|
|
98
|
+
#The final and essential step, to run the mainloop for GUI to display
|
|
99
|
+
def self.show
|
|
100
|
+
Tk.mainloop
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
end
|
|
104
|
+
#______________________________________________________________
|
|
105
|
+
#here document to use in Help Window accessed through the menu
|
|
106
|
+
$guide = %q{
|
|
107
|
+
USAGE:
|
|
108
|
+
x, y are the row number (x) and column number (y) in grid geometry
|
|
109
|
+
1. Gui.root: no options
|
|
110
|
+
2. Gui.entry($var1, x, y) : variable that contains entry
|
|
111
|
+
Gui.entry($var1, x, y) : variable that contains entry
|
|
112
|
+
3. Gui.textfield(h, w, c1, c2, x, y) : h=height, w=width, c1=background, c2=foreground
|
|
113
|
+
4. Gui.button(tx1, m, x, y) : tx1= text on button, m= method triggered by button.
|
|
114
|
+
Method should be written in the active script. e.g.
|
|
115
|
+
def m
|
|
116
|
+
z = $var1+ $var2
|
|
117
|
+
$textfield.delete(1.0, 'end')
|
|
118
|
+
$textfield.insert(1.0, '#{z}')
|
|
119
|
+
end
|
|
120
|
+
5. Gui.label(tx2, x, y): tx2 = text on label
|
|
121
|
+
6. Gui.show :Tk.mainloop
|
|
122
|
+
#______________EXAMPLE___________________
|
|
123
|
+
require_relative 'gui'
|
|
124
|
+
Gui.root
|
|
125
|
+
Gui.menu
|
|
126
|
+
Gui.label("Enter Number", 0, 0)
|
|
127
|
+
Gui.entry($var1, 0, 1)
|
|
128
|
+
Gui.label("Enter Number", 1, 0)
|
|
129
|
+
Gui.entry($var2, 1, 1)
|
|
130
|
+
Gui.textfield(15, 1, "black", "white", 2, 1)
|
|
131
|
+
Gui.button("OK", "m" , 2, 0)
|
|
132
|
+
def m
|
|
133
|
+
$z = $var1 + $var2
|
|
134
|
+
$textfield.insert('end', "#$z")
|
|
135
|
+
end
|
|
136
|
+
Gui.show
|
|
137
|
+
}
|
metadata
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: cf_conv
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Sabry Fattah
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-02-24 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: A simple gui widget app to convert temperature between centigrade and
|
|
14
|
+
fahrenheit
|
|
15
|
+
email: sabryabdelfattah@gmail.com
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files:
|
|
19
|
+
- README.md
|
|
20
|
+
files:
|
|
21
|
+
- README.md
|
|
22
|
+
- lib/cf_conv.rb
|
|
23
|
+
- lib/gui.rb
|
|
24
|
+
homepage: http://sabryfattah.com
|
|
25
|
+
licenses:
|
|
26
|
+
- MIT
|
|
27
|
+
metadata: {}
|
|
28
|
+
post_install_message:
|
|
29
|
+
rdoc_options:
|
|
30
|
+
- --main
|
|
31
|
+
- README.md
|
|
32
|
+
require_paths:
|
|
33
|
+
- lib
|
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - ! '>='
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '0'
|
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
40
|
+
requirements:
|
|
41
|
+
- - ! '>'
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: '0'
|
|
44
|
+
requirements: []
|
|
45
|
+
rubyforge_project:
|
|
46
|
+
rubygems_version: 2.4.5
|
|
47
|
+
signing_key:
|
|
48
|
+
specification_version: 3
|
|
49
|
+
summary: graphical user interface widget app to convert temperature between centigrade
|
|
50
|
+
and fahrenheit
|
|
51
|
+
test_files: []
|