Skip to content

Commit

Permalink
implement local config system[1]
Browse files Browse the repository at this point in the history
  • Loading branch information
marguerite committed Nov 14, 2014
1 parent cab0a0f commit 5fb4f15
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 6 deletions.
42 changes: 42 additions & 0 deletions BiliConfig.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module BiliConfig

class Biliconf

@@userHome = `echo $HOME`.gsub(/\n/,"")
@@configPath = File.join(@@userHome,".config")

def initialize(name="biligui.conf", path=@@configPath)

@name = name
@path = path
@configEntries = []

end

# test code
def print
p @name
p @path
p @configEntries
end

end

# test code
def hello
a = Biliconf.new
a.print()
end

end

# Test codes

class AConfig

include BiliConfig

end

a = AConfig.new
a.hello()
27 changes: 21 additions & 6 deletions BiliGui.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
#!/usr/bin/ruby

require 'Qt'
require 'qtwebkit'

Width = 600
Height = 100
Qt.debug_level = Qt::DebugLevel::High

class QtApp < Qt::Widget

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

Width = 600
Height = 100

def initialize
super
Expand Down Expand Up @@ -45,6 +49,7 @@ def init_ui
@bilidanPath = Qt::LineEdit.new 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;")
Expand All @@ -54,14 +59,16 @@ def init_ui
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, 4
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
Expand All @@ -70,14 +77,15 @@ def bilidan
urlText = @urlArea.toPlainText()
pathText = @bilidanPath.text()
if urlText != "" then
if pathText != "" then
command = "#{pathText}/bilidan.py #{urlText}"
# more tests ?
if pathText != "" && File.exists?(pathText) then
command = "#{pathText} #{urlText}"
exec command
elsif File.exists?('./bilidan.py') then
command = "./bilidan.py #{urlText}"
exec command
else
error = "[ERR] you need to choose bilidan!"
error = "[ERR] you need to choose bilidan.py!"
@messageLabel.setText(error)
end
else
Expand All @@ -96,6 +104,13 @@ def bilidanChoose
@bilidanPath.setText(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

app = Qt::Application.new ARGV
Expand Down

0 comments on commit 5fb4f15

Please sign in to comment.