Skip to content

Commit

Permalink
v1.2-alpha-PUSH14 (#13)
Browse files Browse the repository at this point in the history
* v1.2-alpha-part1:
    基础变更,启动界面增加临时读取更改

* v1.2-alpha-part2:
    一些bug补丁

* v1.2-alpha-part3.1:
    音量调节相关变动第一部分

* v1.2-alpha-part3.1:
    音量调节相关变动第一部分

* v1.2-alpha-part3.2:
    音量调节相关变动第二部分

* v1.2-alpha-part3.3:
    音量调节相关变动第三部分

* v1.2-alpha-part4:
    窗口变动部分

* v1.2-alpha-part4:
    最后一小部分变动
  • Loading branch information
MeowDWing authored Jan 11, 2024
1 parent 7720ec3 commit a520398
Show file tree
Hide file tree
Showing 14 changed files with 686 additions and 225 deletions.
5 changes: 4 additions & 1 deletion DanmakuReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import global_setting
import initial
from funcs.file_func import redirect_print
from dr_window import DanmakuReaderMainWindow


Expand All @@ -17,7 +18,9 @@ def sys_init():
initial.initial()
settings.geetest_auto_open = True
global_setting.load_setting()
global_setting.other_init()
tof = global_setting.other_init()
print(tof)
redirect_print()


if __name__ == '__main__':
Expand Down
183 changes: 119 additions & 64 deletions dr_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,20 @@
from collections import deque

import bilibili_api
from PyQt5 import QtWidgets, QtCore
from PyQt5 import QtWidgets, QtGui
from PyQt5.QtWidgets import QMainWindow, QWidget, QMessageBox

from bilibili_api import login, settings, exceptions, credential, sync
from bilibili_api import credential, sync

import initial
import global_setting
import iosetting as ios
from ui import danmakureaderwindow, updatecontent, login_qrcode, loginwindow, launchwindow, settingswindow
from funcs import launch_func, file_func, login_func


class DanmakuReaderMainWindow(QMainWindow):
"""
主窗口
"""
def __init__(self):
super().__init__()
Expand All @@ -46,15 +43,23 @@ def __init__(self):
self.launch_window = None
self.settings_window = None

# 更新内容弹出
self.update_auto_show = False
if os.path.exists('./files/temp'):
self.update_auto_show = True
os.remove('./files/temp')

def display(self) -> None:
self.show()
if self.update_auto_show:
self.update_window = UpdateContentWindow()
self.update_window.show()


def login_update(self, state=0) -> None:
"""
更新登录状态
:param state: 0-初始化登录 1-登录成功后更新
"""
online = sync(credential.check_cookies(global_setting.credential))

Expand All @@ -74,27 +79,22 @@ def login_update(self, state=0) -> None:

def launch(self) -> None:
"""
启动(名词)窗口
"""
self.launch_window = LaunchWindow()
self.launch_window.display()
self.close()

def settings(self) -> None:
"""
设置窗口
"""
self.settings_window = SettingsWindow()
self.settings_window.display()

def check(self, action: QtWidgets.QAction) -> None:
"""
查看操作
:param action: 选择的选项
"""
act_name = action.text()
Expand All @@ -104,19 +104,15 @@ def check(self, action: QtWidgets.QAction) -> None:

def login(self) -> None:
"""
登录窗口
"""
self.login_window = LoginWindow(self)
self.login_window.display()

@staticmethod
def reset() -> None:
"""
重置选项
"""

# 确认框
Expand All @@ -143,87 +139,150 @@ def reset() -> None:

class LaunchWindow(QWidget):
"""
启动窗口
"""
def __init__(self) -> None:
super().__init__()
self.ui = launchwindow.Ui_Launch()
self.ui.setupUi(self)

self.__global_queue = None
self.process_receiver: QtCore.QThread | None = None
self.process_reader: QtCore.QThread | None = None

# 窗口样式设置(黑底色, 默认字体, 白色字体)
self.ui.readtext.setStyleSheet('''
QTextBrowser
{
color: white;
background: black;
font-family:system-ui,-apple-system,BlinkMacSystemFont,segoe ui,Roboto,Helvetica,Arial,sans-serif,apple color emoji,segoe ui emoji,segoe ui symbol;
}
''')
self.ui.recivetext.setStyleSheet('''
QTextBrowser
{
color: white;
background: black;
font-family:system-ui,-apple-system,BlinkMacSystemFont,segoe ui,Roboto,Helvetica,Arial,sans-serif,apple color emoji,segoe ui emoji,segoe ui symbol;
}
''')

self.ui.volume_bar.setValue(90)
self.process_receiver: launch_func.RecThread | None = None
self.process_reader: launch_func.RecThread | None = None

self.ui.lvl_combox.setCurrentText(str(global_setting.settings.min_lvl))

# 音量调节部分初始化
'''
音量滑块文档:
按下 - 记录位置,按下标记
移动 - 如果已按下,则操作
释放 - 清除按下标记
简写:
n -> normalize
p -> pos -> position
x, y, w, h -> x, y, width, height
'''
# - 初始值设置
self.volume_bar = self.ui.volume_bar
self.volume_bar.setValue(int(global_setting.settings.vol))
# - 事件捕获
self.volume_bar.mousePressEvent = self.slider_mouse_press_event
self.volume_bar.mouseReleaseEvent = self.slider_mouse_realise_event
self.volume_bar.mouseMoveEvent = self.slider_mouse_move_event
# - 事件变量整理
self.volume_bar_pressed = False


''' ------ 音量调节函数部分 起始 -------- '''
def slider_mouse_press_event(self, a0: QtGui.QMouseEvent) -> None:

self.volume_bar_pressed = True

def slider_mouse_realise_event(self, a0: QtGui.QMouseEvent) -> None:

self.volume_bar_pressed = False
w = self.volume_bar.width()
p = a0.pos()
px = p.x()

now_x = int((self.volume_bar.value()/100)*w)

if (now_x - 40) < px < (now_x + 40):
pass
else:
px = int((px / w) * 100)
self.volume_bar.setValue(px)
global_setting.volume_ctrl.set_volume(px)


def slider_mouse_move_event(self, a0: QtGui.QMouseEvent) -> None:
if self.volume_bar_pressed is True:
w = self.volume_bar.width()
p = a0.pos()
px = p.x()
npx = int((px/w)*100)
self.volume_bar.setValue(npx)
global_setting.volume_ctrl.set_volume(npx)
else:
pass

''' ------ 音量调节函数部分 结束 -------- '''

def display(self) -> None:
"""
显示界面,并初始化接受机制和读取机制
"""
self.show()
self.init_reader_and_receiver()

def closeEvent(self, a0: QtGui.QCloseEvent) -> None:
s_vol = global_setting.settings.vol
now_vol = self.volume_bar.value()
if s_vol != now_vol:
run_dict = global_setting.settings.run_dict_constructor(vol=now_vol)
global_setting.settings.update_conform_and_dump(run_dict=run_dict)

super().closeEvent(a0)

def init_reader_and_receiver(self) -> None:
self.__global_queue = deque()
print('正在读取房间号...')

print('正在初始化弹幕获取器...')
self.process_receiver = launch_func.RecThread(_g_queue=self.__global_queue, _ui=self.ui)
self.process_receiver = launch_func.RecThread(_g_queue=self.__global_queue)

print("正在初始化阅读器...")
self.process_reader = launch_func.RdThread(_g_queue=self.__global_queue, _ui=self.ui)
print(1)

self.process_reader.start()
self.process_receiver.start()

def volume_adjust(self):
def temp_lvl_limit(self):
if isinstance(self.process_receiver, launch_func.RecThread):
temp_lvl_str = self.ui.lvl_combox.currentText()
if len(temp_lvl_str)<5:
temp_lvl = int(temp_lvl_str)
else:
temp_lvl = -1

if temp_lvl>0:
self.process_receiver.x.min_lvl = temp_lvl
self.process_receiver.x.read_any_lvl = False
elif temp_lvl==0:
self.process_receiver.x.min_lvl = 0
self.process_receiver.x.read_any_lvl = True

vol = self.ui.volume_bar.value()
norm_vol = vol/100.0
global_setting.narrator.say_engin.setProperty('volume', norm_vol)

def pause_read(self):
pause = global_setting.read_pause

if pause:
self.ui.pause_btn.setText('暂停')
pause = not pause
else:
self.ui.pause_btn.setText('继续')
pause = not pause

global_setting.read_pause = pause

def join2txt_browser(self, which, txt) -> None:
pass

def test(self) -> None:
"""
定时器测试用例,无实际用处
:return:
"""
self.startTimer(100)

def timerEvent(self, a0) -> None:
self.ui.readtext.append("<font color=\"#00FFFF\"> WOW <\\font>")
pass


class LoginWindow(QWidget):
"""
登录窗口类
"""

def __init__(self, main_window: DanmakuReaderMainWindow):
Expand All @@ -246,19 +305,20 @@ def __init__(self, main_window: DanmakuReaderMainWindow):


def display(self) -> None:
self.main_window.close()
self.show()
self.main_window.hide()

def close(self) -> bool:
def closeEvent(self, a0: QtGui.QCloseEvent) -> None:
self.main_window.display()
super().closeEvent(a0)

def close(self) -> bool:
ret = super().close()
return ret

def loginwindow_login(self) -> None:
"""
”登录“按钮槽
"""

sign: login_func.LoginState | None = None
Expand Down Expand Up @@ -312,7 +372,6 @@ def loginwindow_loginfunc_combox(self, idx) -> None:
def __self_login_func_choice(self, idx) -> None:
"""
方式选择导致的界面变更
:param idx: 0-账号密码 1-验证码 2-二维码
"""
self.login_func_index = idx
Expand Down Expand Up @@ -349,10 +408,9 @@ def display(self) -> None:
self.qrcode_timer_id = self.startTimer(1000)
self.show()

def close(self) -> bool:
def closeEvent(self, a0: QtGui.QCloseEvent) -> None:
self.killTimer(self.qrcode_timer_id)
ret = super().close()
return ret
super().closeEvent(a0)


class UpdateContentWindow(QWidget):
Expand Down Expand Up @@ -449,16 +507,13 @@ def save_and_close(self) -> None:
for line in lines:
line = line.strip()
if line[0] == '-':
regex_match.append(line)
regex_match.append(line[1:])
elif line[0] == '$':
pass
else:
all_match.append(line)
global_setting.ban_word.word_conform_update_and_dump(all_match_add=all_match, regex_match_add=regex_match)




self.close()

def cookie_change(self) -> None:
Expand Down
Loading

0 comments on commit a520398

Please sign in to comment.