redix 0.0.2 → 0.0.3

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.
@@ -13,6 +13,8 @@ This should work on KDE/OSX. For other linux WM:
13
13
 
14
14
  gem install qtbindings
15
15
 
16
+ http://github.com/ryanmelt/qtbindings
17
+
16
18
 
17
19
  == Use
18
20
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -1,9 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__)))
3
3
  begin
4
- require 'Qt4'
4
+ begin
5
+ require 'Qt4'
6
+ rescue LoadError
7
+ require 'korundum4'
8
+ end
5
9
  rescue LoadError
6
10
  puts "QT Bindings not found, try `gem install qtbindings`."
11
+ exit
7
12
  end
8
13
  require 'redis'
9
14
  # APP
@@ -17,10 +22,10 @@ module Redix
17
22
 
18
23
  def self.boot!
19
24
  u = Ui_MainWindow.new
20
- w = Qt::MainWindow.new
21
- u.setupUi(w)
25
+ # w = Qt::MainWindow.new
26
+ u.setupUi #(w)
22
27
  Logic.for(u)
23
- w.show
28
+ u.show
24
29
  App.exec
25
30
  end
26
31
 
@@ -1,7 +1,8 @@
1
1
 
2
2
  module Redix
3
3
 
4
- class Logic
4
+ class Logic #< Qt::Widget =/
5
+ #slots :reload, :help, :connect
5
6
 
6
7
  class << self
7
8
 
@@ -37,9 +38,12 @@ module Redix
37
38
  def build_keys
38
39
  @u.listWidget.clear
39
40
  @u.listWidget.addItems(r.keys.sort)
41
+ rescue
42
+ failure "Could not conect to redis"
43
+
40
44
  end
41
45
 
42
- def connect_dialog
46
+ def connect
43
47
  c = ConnectDialog.new
44
48
  c.setupUi
45
49
  redis = "#{r.client.host}:#{r.client.port}/#{r.client.db}"
@@ -49,7 +53,7 @@ module Redix
49
53
  c.show
50
54
  end
51
55
 
52
- def about_dialog
56
+ def help
53
57
  a = AboutDialog.new
54
58
  a.setupUi
55
59
  # a.title.setText("RediX")
@@ -57,13 +61,20 @@ module Redix
57
61
  a.show
58
62
  end
59
63
 
64
+ def new_key
65
+ k = NewKeyDialog.new
66
+ k.setupUi
67
+ k.show
68
+ end
69
+
60
70
  def for(u)
61
71
  @u = u
62
72
  build_keys
63
73
  build_dbs
64
- u.actionConnect.connect(SIGNAL('triggered()')) { connect_dialog }
74
+ u.actionNew.connect(SIGNAL('triggered()')) { new_key }
75
+ u.actionConnect.connect(SIGNAL('triggered()')) { connect }
65
76
  u.actionReconnect.connect(SIGNAL('triggered()')) { reconnect }
66
- u.actionAbout.connect(SIGNAL('triggered()')) { about_dialog }
77
+ u.actionAbout.connect(SIGNAL('triggered()')) { help }
67
78
  u.actionQuit.connect(SIGNAL('triggered()'), App, SLOT('quit()'))
68
79
 
69
80
  # Qt::ListWidgetItem.new(u.listWidget)
@@ -79,13 +90,18 @@ module Redix
79
90
  comm = @u.lineEdit.text
80
91
  @u.lineEdit.clear
81
92
  puts "Exec #{comm}"
82
- res = eval("r.#{comm}")
83
- @u.textBrowser.setHtml(res)# += res
93
+ res = eval("r.#{comm}") rescue "FAIL"
94
+ @u.textBrowser.setHtml("=> #{res}")# += res
95
+
96
+ rescue Exception => e
97
+ @u.textBrowser.setHtml e.to_s
84
98
  end
85
99
 
86
100
  def zoom(i)
87
101
  key = i.text
88
- @u.tableView.model = DataModel.new.for(key)
102
+ model = DataModel.new.for(key)
103
+ @u.tableView.model = model
104
+ @u.tableView.setColumnWidth(0, 400)
89
105
  end
90
106
  end
91
107
 
@@ -95,10 +111,11 @@ module Redix
95
111
 
96
112
  end
97
113
 
98
- class DataModel < Qt::AbstractListModel
114
+ class DataModel < Qt::AbstractTableModel
99
115
 
100
116
  def for(key)
101
117
  r = Logic.r
118
+ @key = key
102
119
  @type = r.type(key)
103
120
  @data = case @type
104
121
  when "string" then r.get(key)
@@ -106,27 +123,56 @@ module Redix
106
123
  when "set" then r.smembers(key)
107
124
  else r.sort(key)
108
125
  end
109
- if @data.respond_to?(:values)
126
+ if @data.kind_of?(Hash)
110
127
  @rows = @data.values
111
128
  @header = @data.keys
112
129
  else
113
- @rows = [@data]
114
- @header = [@type]
130
+ @rows = @data.kind_of?(Array) ? @data : [@data]
131
+ @header = (0..@rows.size).to_a
115
132
  end
116
133
 
117
134
  self
118
135
  end
119
136
 
120
- def rowCount idx
137
+ def flags(arg=nil)
138
+ Qt::ItemIsEditable|Qt::ItemIsEnabled
139
+ end
140
+
141
+ def rowCount idx=nil
121
142
  @rows.size
122
143
  end
123
144
 
145
+ def columnCount idx=nil
146
+ 1
147
+ end
148
+
124
149
  def data idx, role = Qt::DisplayRole
125
150
  if role == Qt::DisplayRole then Qt::Variant.new @rows[idx.row]
126
151
  else Qt::Variant.new
127
152
  end
128
153
  end
129
154
 
155
+ def setData(mid, var, *args)
156
+ p "SETDATA #{mid} | #{var}"
157
+ p mid
158
+ r = Logic.r
159
+ t = var.toString
160
+ case @type
161
+ when 'string' then r.set(@key, t)
162
+ when 'hash' then r.hset(@key, @header[mid.row], t)
163
+ when 'list' then r.lset(@key, mid.row, t)
164
+ when 'set'
165
+ r.srem(@key, @rows[mid.row])
166
+ r.sadd(@key, t)
167
+ end
168
+ p args
169
+ self.for(@key)
170
+ end
171
+
172
+ def setHeaderData(*args)
173
+ p args
174
+ end
175
+
130
176
  def headerData sec, orient, role = Qt::DisplayRole
131
177
  if role == Qt::DisplayRole
132
178
  Qt::Variant.new(orient == 2 ? @header[sec] : @type)
@@ -4,51 +4,41 @@
4
4
  #
5
5
  #
6
6
  #
7
- class Ui_MainWindow
8
- attr_reader :actionNew
9
- attr_reader :actionOpen
10
- attr_reader :actionQuit
11
- attr_reader :actionReconnect
12
- attr_reader :actionConnect
13
- attr_reader :actionHomepage
14
- attr_reader :actionAbout
15
- attr_reader :centralwidget
16
- attr_reader :listWidget
17
- attr_reader :tableView
18
- attr_reader :lineEdit
19
- attr_reader :textBrowser
20
- attr_reader :menubar
21
- attr_reader :menuFile
22
- attr_reader :menuDB
23
- attr_reader :menuChange
24
- attr_reader :menuHelp
25
- attr_reader :statusbar
26
- attr_reader :mainWindow
27
-
28
- def setupUi(mainWindow)
29
- if mainWindow.objectName.nil?
30
- mainWindow.objectName = "mainWindow"
7
+ class Ui_MainWindow < Qt::MainWindow
8
+ attr_reader :actionNew, :actionOpen, :actionQuit, :actionReconnect, :actionConnect
9
+ attr_reader :actionHomepage, :actionAbout, :centralwidget, :listWidget
10
+ attr_reader :tableView, :lineEdit, :textBrowser
11
+ attr_reader :menubar, :menuKey, :menuDB, :menuChange, :menuHelp
12
+ attr_reader :statusbar, :mainWindow
13
+
14
+ slots :reload, :help, :connect, :new_key
15
+
16
+ def setupUi #(self)
17
+ if self.objectName.nil?
18
+ self.objectName = "mainWindow"
31
19
  end
32
- @mainWindow = mainWindow
33
- mainWindow.resize(799, 606)
34
- @actionNew = Qt::Action.new(mainWindow)
20
+ @mainWindow = self
21
+ self.resize(799, 606)
22
+ @actionNew = Qt::Action.new(self)
35
23
  @actionNew.objectName = "actionNew"
36
- @actionOpen = Qt::Action.new(mainWindow)
24
+ @actionInfo = Qt::Action.new(self)
25
+ @actionInfo.objectName = "actionInfo"
26
+ @actionOpen = Qt::Action.new(self)
37
27
  @actionOpen.objectName = "actionOpen"
38
- @actionQuit = Qt::Action.new(mainWindow)
28
+ @actionQuit = Qt::Action.new(self)
39
29
  @actionQuit.objectName = "actionQuit"
40
30
 
41
- @actionConnect = Qt::Action.new(mainWindow)
31
+ @actionConnect = Qt::Action.new(self)
42
32
  @actionConnect.objectName = "actionConnect"
43
- @actionReconnect = Qt::Action.new(mainWindow)
33
+ @actionReconnect = Qt::Action.new(self)
44
34
  @actionReconnect.objectName = "actionReconnect"
45
35
 
46
- @actionHomepage = Qt::Action.new(mainWindow)
36
+ @actionHomepage = Qt::Action.new(self)
47
37
  @actionHomepage.objectName = "actionHomepage"
48
- @actionAbout = Qt::Action.new(mainWindow)
38
+ @actionAbout = Qt::Action.new(self)
49
39
  @actionAbout.objectName = "actionAbout"
50
40
 
51
- @centralwidget = Qt::Widget.new(mainWindow)
41
+ @centralwidget = Qt::Widget.new(self)
52
42
  @centralwidget.objectName = "centralwidget"
53
43
  @listWidget = Qt::ListWidget.new(@centralwidget)
54
44
  @listWidget.objectName = "listWidget"
@@ -57,56 +47,82 @@ class Ui_MainWindow
57
47
  @tableView.objectName = "tableView"
58
48
  @tableView.geometry = Qt::Rect.new(260, 10, 531, 441)
59
49
  @tableView.gridStyle = Qt::DotLine
50
+
60
51
  @lineEdit = Qt::LineEdit.new(@centralwidget)
61
52
  @lineEdit.objectName = "lineEdit"
62
53
  @lineEdit.geometry = Qt::Rect.new(260, 510, 531, 31)
63
54
  @textBrowser = Qt::TextBrowser.new(@centralwidget)
64
55
  @textBrowser.objectName = "textBrowser"
65
56
  @textBrowser.geometry = Qt::Rect.new(260, 460, 531, 41)
66
- mainWindow.centralWidget = @centralwidget
67
- @menubar = Qt::MenuBar.new(mainWindow)
57
+ self.centralWidget = @centralwidget
58
+
59
+ @menubar = Qt::MenuBar.new(self)
68
60
  @menubar.objectName = "menubar"
69
61
  @menubar.geometry = Qt::Rect.new(0, 0, 799, 26)
70
- @menuFile = Qt::Menu.new(@menubar)
71
- @menuFile.objectName = "menuFile"
62
+ @menuKey = Qt::Menu.new(@menubar)
63
+ @menuKey.objectName = "menuKey"
72
64
  @menuDB = Qt::Menu.new(@menubar)
73
65
  @menuDB.objectName = "menuDB"
74
66
  @menuChange = Qt::Menu.new(@menuDB)
75
67
  @menuChange.objectName = "menuChange"
76
68
  @menuHelp = Qt::Menu.new(@menubar)
77
69
  @menuHelp.objectName = "menuHelp"
78
- mainWindow.setMenuBar(@menubar)
79
- @statusbar = Qt::StatusBar.new(mainWindow)
70
+ self.setMenuBar(@menubar)
71
+ @statusbar = Qt::StatusBar.new(self)
80
72
  @statusbar.objectName = "statusbar"
81
- mainWindow.statusBar = @statusbar
73
+ self.statusBar = @statusbar
82
74
 
83
- @menubar.addAction(@menuFile.menuAction())
84
75
  @menubar.addAction(@menuDB.menuAction())
76
+ @menubar.addAction(@menuKey.menuAction())
85
77
  @menubar.addAction(@menuHelp.menuAction())
86
- @menuFile.addAction(@actionNew)
87
- @menuFile.addAction(@actionOpen)
88
- @menuFile.addSeparator()
89
- @menuFile.addAction(@actionQuit)
78
+ @menuDB.addAction(@actionOpen)
90
79
  @menuDB.addAction(@menuChange.menuAction())
91
80
  @menuDB.addAction(@actionConnect)
92
81
  @menuDB.addAction(@actionReconnect)
93
82
  @menuDB.addSeparator()
83
+ @menuDB.addAction(@actionQuit)
84
+ @menuKey.addAction(@actionNew)
85
+ @menuKey.addAction(@actionInfo)
86
+ @menuKey.addSeparator()
94
87
  @menuHelp.addAction(@actionHomepage)
95
88
  @menuHelp.addSeparator()
96
89
  @menuHelp.addAction(@actionAbout)
97
90
 
98
- retranslateUi(mainWindow)
99
91
 
100
- Qt::MetaObject.connectSlotsByName(mainWindow)
92
+ retranslateUi
93
+
94
+ Qt::Shortcut.new(Qt::KeySequence.new(Qt::Key_C.to_i), self, SLOT('connect()'))
95
+ Qt::Shortcut.new(Qt::KeySequence.new(Qt::Key_F1.to_i), self, SLOT('help()'))
96
+ Qt::Shortcut.new(Qt::KeySequence.new(Qt::Key_F2.to_i), self, SLOT('new_key()'))
97
+ Qt::Shortcut.new(Qt::KeySequence.new(Qt::Key_F5.to_i), self, SLOT('reload()'))
98
+
99
+ Qt::MetaObject.connectSlotsByName(self)
101
100
  end # setupUi
102
101
 
103
- def setup_ui(mainWindow)
104
- setupUi(mainWindow)
102
+ def connect
103
+ Redix::Logic.connect_dialog
104
+ end
105
+
106
+ def new_key
107
+ Redix::Logic.new_key
108
+ end
109
+
110
+ def reload
111
+ Redix::Logic.reconnect
112
+ end
113
+
114
+ def help
115
+ Redix::Logic.about_dialog
116
+ end
117
+
118
+ def setup_ui
119
+ setupUi
105
120
  end
106
121
 
107
- def retranslateUi(mainWindow)
108
- mainWindow.windowTitle = Qt::Application.translate("MainWindow", "Redix", nil, Qt::Application::UnicodeUTF8)
122
+ def retranslateUi
123
+ self.windowTitle = Qt::Application.translate("MainWindow", "Redix", nil, Qt::Application::UnicodeUTF8)
109
124
  @actionNew.text = Qt::Application.translate("MainWindow", "New", nil, Qt::Application::UnicodeUTF8)
125
+ @actionInfo.text = Qt::Application.translate("MainWindow", "Info", nil, Qt::Application::UnicodeUTF8)
110
126
  @actionOpen.text = Qt::Application.translate("MainWindow", "Open", nil, Qt::Application::UnicodeUTF8)
111
127
  @actionQuit.text = Qt::Application.translate("MainWindow", "Quit", nil, Qt::Application::UnicodeUTF8)
112
128
  @actionConnect.text = Qt::Application.translate("MainWindow", "Connect", nil, Qt::Application::UnicodeUTF8)
@@ -114,14 +130,69 @@ class Ui_MainWindow
114
130
  @actionHomepage.text = Qt::Application.translate("MainWindow", "Homepage", nil, Qt::Application::UnicodeUTF8)
115
131
  @actionAbout.text = Qt::Application.translate("MainWindow", "About", nil, Qt::Application::UnicodeUTF8)
116
132
  @lineEdit.toolTip = Qt::Application.translate("MainWindow", "Run commands", nil, Qt::Application::UnicodeUTF8)
117
- @menuFile.title = Qt::Application.translate("MainWindow", "File", nil, Qt::Application::UnicodeUTF8)
133
+ @menuKey.title = Qt::Application.translate("MainWindow", "Key", nil, Qt::Application::UnicodeUTF8)
118
134
  @menuDB.title = Qt::Application.translate("MainWindow", "DB", nil, Qt::Application::UnicodeUTF8)
119
135
  @menuChange.title = Qt::Application.translate("MainWindow", "Change", nil, Qt::Application::UnicodeUTF8)
120
136
  @menuHelp.title = Qt::Application.translate("MainWindow", "Help", nil, Qt::Application::UnicodeUTF8)
121
137
  end # retranslateUi
122
138
 
123
- def retranslate_ui(mainWindow)
124
- retranslateUi(mainWindow)
139
+ def retranslate_ui
140
+ retranslateUi
141
+ end
142
+
143
+ end
144
+
145
+
146
+ class NewKeyDialog < Qt::Dialog
147
+ attr_reader :data
148
+ attr_reader :buttonBox
149
+ attr_reader :input_name
150
+ attr_reader :input_type
151
+
152
+
153
+ def updateData(new)
154
+ @data = new
155
+ end
156
+ def setupUi(dialog = self)
157
+
158
+ @buttonBox = Qt::DialogButtonBox.new(dialog)
159
+ @buttonBox.objectName = "buttonBox"
160
+ @buttonBox.geometry = Qt::Rect.new(30, 100, 341, 32)
161
+ @buttonBox.orientation = Qt::Horizontal
162
+ @buttonBox.standardButtons = Qt::DialogButtonBox::Cancel|Qt::DialogButtonBox::Ok
163
+ @input_name = Qt::LineEdit.new(dialog)
164
+ @input_name.objectName = "input_name"
165
+ @input_name.geometry = Qt::Rect.new(70, 20, 311, 22)
166
+ @label = Qt::Label.new(dialog)
167
+ @label.objectName = "label"
168
+ @label.geometry = Qt::Rect.new(20, 23, 61, 21)
169
+
170
+ @input_type = Qt::LineEdit.new(dialog)
171
+ @input_type.objectName = "input_type"
172
+ @input_type.geometry = Qt::Rect.new(70, 50, 311, 22)
173
+ @label_type = Qt::Label.new(dialog)
174
+ @label_type.objectName = "label_type"
175
+ @label_type.geometry = Qt::Rect.new(20, 53, 61, 21)
176
+
177
+ retranslateUi(dialog)
178
+ Qt::Object.connect(@buttonBox, SIGNAL('accepted()'), dialog, SLOT('accept()'))
179
+ Qt::Object.connect(@buttonBox, SIGNAL('rejected()'), dialog, SLOT('reject()'))
180
+
181
+ Qt::MetaObject.connectSlotsByName(dialog)
182
+ end # setupUi
183
+
184
+ def setup_ui(dialog)
185
+ setupUi(dialog)
186
+ end
187
+
188
+ def retranslateUi(dialog)
189
+ dialog.windowTitle = Qt::Application.translate("Dialog", "New Key", nil, Qt::Application::UnicodeUTF8)
190
+ @label.text = Qt::Application.translate("Dialog", "Name", nil, Qt::Application::UnicodeUTF8)
191
+ @label_type.text = Qt::Application.translate("Dialog", "Type", nil, Qt::Application::UnicodeUTF8)
192
+ end # retranslateUi
193
+
194
+ def retranslate_ui(dialog)
195
+ retranslateUi(dialog)
125
196
  end
126
197
 
127
198
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{redix}
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Marcos Piccinini"]
12
- s.date = %q{2010-10-07}
12
+ s.date = %q{2010-10-08}
13
13
  s.default_executable = %q{redix}
14
14
  s.description = %q{QT GUI for Redis Beta}
15
15
  s.email = %q{x@nofxx.com}
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 2
9
- version: 0.0.2
8
+ - 3
9
+ version: 0.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Marcos Piccinini
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-07 00:00:00 -03:00
17
+ date: 2010-10-08 00:00:00 -03:00
18
18
  default_executable: redix
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency