knjrbfw 0.0.48 → 0.0.49

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.48
1
+ 0.0.49
data/knjrbfw.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{knjrbfw}
8
- s.version = "0.0.48"
8
+ s.version = "0.0.49"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kasper Johansen"]
@@ -1,12 +1,23 @@
1
+ #Containing various helper methods for Gtk2-windows.
1
2
  class Knj::Gtk2::Window
2
3
  require "wref"
3
4
  @@uniques = Wref_map.new
4
5
 
6
+ #Used to make a window-instance unique. If it already exists when unique! is called, then it will pass focus to the existing window instead of yielding the block, which should contain code to create the window.
7
+ #===Examples
8
+ #This should only create a single window.
9
+ # Knj::Gtk2::Window.unique!("my_window") do
10
+ # Gtk::Window.new
11
+ # end
12
+ #
13
+ # Knj::Gtk2::Window.unique!("my_window") do
14
+ # Gtk::Window.new
15
+ # end
5
16
  def self.unique!(id)
6
17
  instance = @@uniques.get!(id)
7
18
 
8
19
  if instance and !instance.gui["window"].destroyed?
9
- instance.gui["window"].activate_focus
20
+ instance.gui["window"].present
10
21
  else
11
22
  obj = yield
12
23
  @@uniques[id] = obj
data/lib/knj/unix_proc.rb CHANGED
@@ -1,3 +1,4 @@
1
+ #Requires the 'wref'-gem.
1
2
  require "wref"
2
3
 
3
4
  #This class handels various stuff regarding Unix-processes.
@@ -7,6 +8,7 @@ class Knj::Unix_proc
7
8
  PROCS = Wref_map.new
8
9
  MUTEX = Mutex.new
9
10
 
11
+ #Spawns a process if it doesnt already exist in the wrap-map.
10
12
  def self.spawn(data)
11
13
  pid = data["pid"].to_i
12
14
 
@@ -21,6 +23,7 @@ class Knj::Unix_proc
21
23
  return proc_ele
22
24
  end
23
25
 
26
+ #Returns an array with (or yields if block given) Unix_proc. Hash-arguments as 'grep'.
24
27
  def self.list(args = {})
25
28
  cmdstr = "ps aux"
26
29
  grepstr = ""
@@ -80,13 +83,14 @@ class Knj::Unix_proc
80
83
  end
81
84
  end
82
85
 
86
+ #Returns the "Knj::Unix_proc" for the current process.
83
87
  def self.find_self
84
88
  procs = Knj::Unix_proc.list("ignore_self" => false)
85
89
  pid_find = Process.pid
86
90
 
87
91
  proc_find = false
88
92
  procs.each do |proc_ele|
89
- if proc_ele["pid"].to_s == pid_find.to_s
93
+ if proc_ele["pid"].to_i == pid_find.to_i
90
94
  proc_find = proc_ele
91
95
  break
92
96
  end
@@ -95,20 +99,39 @@ class Knj::Unix_proc
95
99
  return proc_find
96
100
  end
97
101
 
102
+ #Return true if the given PID is running.
103
+ def self.pid_running?(pid)
104
+ begin
105
+ Process.getpgid(pid)
106
+ return true
107
+ rescue Errno::ESRCH
108
+ return false
109
+ end
110
+ end
111
+
112
+ #Initializes various data for a Unix_proc-object. This should not be called manually but through "Unix_proc.list".
98
113
  def initialize(data)
99
114
  @data = data
100
115
  end
101
116
 
117
+ #Updates the data. This should not be called manually, but is exposed because of various code in "Unix_proc.list".
102
118
  def update_data(data)
103
119
  @data = data
104
120
  end
105
121
 
122
+ #Returns a key from the data or raises an error.
106
123
  def [](key)
107
124
  raise "No such data: #{key}" if !@data.key?(key)
108
125
  return @data[key]
109
126
  end
110
127
 
128
+ #Kills the process.
111
129
  def kill
130
+ Process.kill("TERM", @data["pid"].to_i)
131
+ end
132
+
133
+ #Kills the process with 9.
134
+ def kill!
112
135
  Process.kill(9, @data["pid"].to_i)
113
136
  end
114
137
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: knjrbfw
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.48
5
+ version: 0.0.49
6
6
  platform: ruby
7
7
  authors:
8
8
  - Kasper Johansen
@@ -379,7 +379,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
379
379
  requirements:
380
380
  - - ">="
381
381
  - !ruby/object:Gem::Version
382
- hash: -3872337561569078087
382
+ hash: 4237675880439105833
383
383
  segments:
384
384
  - 0
385
385
  version: "0"