Skip to content

Commit

Permalink
skeleton for multi URL support
Browse files Browse the repository at this point in the history
  • Loading branch information
marguerite committed Nov 14, 2014
1 parent 6b8c421 commit 68ff31d
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 147 deletions.
148 changes: 1 addition & 147 deletions BiliGui.rb
Original file line number Diff line number Diff line change
@@ -1,151 +1,5 @@
#!/usr/bin/ruby

require 'Qt'
require 'qtwebkit'
require_relative 'BiliConfig'

#Qt.debug_level = Qt::DebugLevel::High

class BiliGuiConfig

include BiliConfig
@@config = Biliconf.new

def put(key,value)
confKey = key
confValue = value
@@config.writeNewConfig(confKey,confValue)
end

def load
@@config.loadConfigs()
end

end

class QtApp < Qt::Widget

slots 'bilidan()'
slots 'clear()'
slots 'bilidanChoose()'
slots 'biliGoWeb()'

Width = 600
Height = 100
@@configw = BiliGuiConfig.new
@@config = @@configw.load

def initialize
super

setWindowTitle "BiliGui"

setToolTip "BiliDan GUI"

init_ui

resize Width, Height
center

show
end

def center
qdw = Qt::DesktopWidget.new

screenWidth = qdw.width
screenHeight = qdw.height

x = (screenWidth - Width) / 2
y = (screenHeight - Height) / 2

move x, y
end

def init_ui
grid = Qt::GridLayout.new self

bilidanPathLabel = Qt::Label.new "Please enter your bilidan's path:", self
@bilidanPath = Qt::LineEdit.new @@config["BilidanPath"], self
bilidanButton = Qt::PushButton.new 'Choose', self
biliUrlLabel = Qt::Label.new "Please paste Bilibili URL below", self
#biliWebButton = Qt::PushButton.new 'Visit bilibili.tv (experimental)', self
@urlArea = Qt::TextEdit.new self
@messageLabel = Qt::Label.new "", self
@messageLabel.setStyleSheet("color: #ff0000;")
okButton = Qt::PushButton.new 'Watch', self
clearButton = Qt::PushButton.new 'Clear', self

grid.addWidget bilidanPathLabel, 0, 0, 1, 1
grid.addWidget @bilidanPath, 0, 1, 1, 2
grid.addWidget bilidanButton, 0, 3, 1, 1
grid.addWidget biliUrlLabel, 1, 0, 1, 3
#grid.addWidget biliWebButton, 1, 3, 1, 1
grid.addWidget @urlArea, 2, 0, 1, 4
grid.addWidget @messageLabel, 3, 0, 1, 1
grid.addWidget okButton, 3, 2, 1, 1
grid.addWidget clearButton, 3, 3, 1, 1
grid.setColumnStretch 1, 2

connect bilidanButton, SIGNAL('clicked()'), self, SLOT('bilidanChoose()')
#connect biliWebButton, SIGNAL('clicked()'), self, SLOT('biliGoWeb()')
connect okButton, SIGNAL('clicked()'), self, SLOT('bilidan()')
connect clearButton, SIGNAL('clicked()'), self, SLOT('clear()')
end

def bilidan

require 'open3'

urlText = @urlArea.toPlainText()
pathText = @bilidanPath.text()

if urlText != "" then
# more tests ?
if pathText != "" && File.exists?(pathText) then
command = "#{pathText} #{urlText}"
Open3.popen2e(command) do |stdin, stdout_and_error, wait_thr|
stdout_and_error.each_line do |line|
puts line
end
end
elsif File.exists?('./bilidan.py') then
command = "./bilidan.py #{urlText}"
Open3.popen2e(command) do |stdin, stdout_and_error, wait_thr|
stdout_and_error.each_line do |line|
puts line
end
end
else
error = "[ERR] you need to choose bilidan.py!"
@messageLabel.setText(error)
end
else
error = "[ERR] you have to paste an URL!"
@messageLabel.setText(error)
end
end

def clear
@urlArea.clear()
end

def bilidanChoose
userHome = `echo $HOME`.gsub(/\n/,"")
bilidanBin = Qt::FileDialog.getOpenFileName(self, "Please choose your bilidan.py", "#{userHome}", "Python files (*.py)")
@bilidanPath.setText(bilidanBin)
@@configw.put("BilidanPath", bilidanBin)
end

def biliGoWeb
biliweb = Qt::WebView.new
biliweb.load Qt::Url.new('http://www.bilibili.tv/')
biliweb.resize 1024, 640
biliweb.show
end

end

require_relative 'BiliGuiWidget'
app = Qt::Application.new ARGV
QtApp.new
app.exec
156 changes: 156 additions & 0 deletions BiliGuiWidget.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
require 'Qt'
require 'qtwebkit'
require_relative 'BiliConfig'

class BiliGuiConfig

include BiliConfig
@@config = Biliconf.new

def put(key,value)
confKey = key
confValue = value
@@config.writeNewConfig(confKey,confValue)
end

def load
@@config.loadConfigs()
end

end

class QtApp < Qt::Widget

slots 'bilidan()'
slots 'clear()'
slots 'bilidanChoose()'
slots 'biliGoWeb()'

Width = 600
Height = 100
@@configw = BiliGuiConfig.new
@@config = @@configw.load

def initialize
super

setWindowTitle "BiliGui"

setToolTip "BiliDan GUI"

init_ui

resize Width, Height
center

show
end

def center
qdw = Qt::DesktopWidget.new

screenWidth = qdw.width
screenHeight = qdw.height

x = (screenWidth - Width) / 2
y = (screenHeight - Height) / 2

move x, y
end

def init_ui
grid = Qt::GridLayout.new self

bilidanPathLabel = Qt::Label.new "Please enter your bilidan's path:", self
@bilidanPath = Qt::LineEdit.new @@config["BilidanPath"], self
bilidanButton = Qt::PushButton.new 'Choose', self
biliUrlLabel = Qt::Label.new "Please paste Bilibili URL below", self
#biliWebButton = Qt::PushButton.new 'Visit bilibili.tv (experimental)', self
@urlArea = Qt::TextEdit.new self
@messageLabel = Qt::Label.new "", self
@messageLabel.setStyleSheet("color: #ff0000;")
okButton = Qt::PushButton.new 'Watch', self
clearButton = Qt::PushButton.new 'Clear', self
@consoleArea = Qt::TextEdit.new self
@consoleArea.setVisible false
@consoleArea.setStyleSheet("color: #fff; background-color: #333;")

grid.addWidget bilidanPathLabel, 0, 0, 1, 1
grid.addWidget @bilidanPath, 0, 1, 1, 2
grid.addWidget bilidanButton, 0, 3, 1, 1
grid.addWidget biliUrlLabel, 1, 0, 1, 3
#grid.addWidget biliWebButton, 1, 3, 1, 1
grid.addWidget @urlArea, 2, 0, 1, 4
grid.addWidget @messageLabel, 3, 0, 1, 1
grid.addWidget okButton, 3, 2, 1, 1
grid.addWidget clearButton, 3, 3, 1, 1
grid.addWidget @consoleArea, 4, 0, 1, 4
grid.setColumnStretch 1, 2

connect bilidanButton, SIGNAL('clicked()'), self, SLOT('bilidanChoose()')
#connect biliWebButton, SIGNAL('clicked()'), self, SLOT('biliGoWeb()')
connect okButton, SIGNAL('clicked()'), self, SLOT('bilidan()')
connect clearButton, SIGNAL('clicked()'), self, SLOT('clear()')
end

def bilidan

require 'open3'

urlText = @urlArea.toPlainText()
pathText = @bilidanPath.text()

if urlText != "" then
# more tests ?
if pathText != "" && File.exists?(pathText) then
command = "#{pathText} #{urlText}"
Open3.popen2e(command) do |stdin, stdout_and_error, wait_thr|
stdout_and_error.each_line do |line|
#@consoleArea.setVisible true
#@consoleArea.append(line)
puts line
end

if wait_thr.value.success?() then
bilidanNext()
end
end
elsif File.exists?('./bilidan.py') then
command = "./bilidan.py #{urlText}"
Open3.popen2e(command) do |stdin, stdout_and_error, wait_thr|
stdout_and_error.each_line do |line|
puts line
end
end
else
error = "[ERR] you need to choose bilidan.py!"
@messageLabel.setText(error)
end
else
error = "[ERR] you have to paste an URL!"
@messageLabel.setText(error)
end
end

def bilidanNext
end

def clear
@urlArea.clear()
end

def bilidanChoose
userHome = `echo $HOME`.gsub(/\n/,"")
bilidanBin = Qt::FileDialog.getOpenFileName(self, "Please choose your bilidan.py", "#{userHome}", "Python files (*.py)")
@bilidanPath.setText(bilidanBin)
@@configw.put("BilidanPath", bilidanBin)
end

def biliGoWeb
biliweb = Qt::WebView.new
biliweb.load Qt::Url.new('http://www.bilibili.tv/')
biliweb.resize 1024, 640
biliweb.show
end

end

0 comments on commit 68ff31d

Please sign in to comment.