Skip to content

Commit

Permalink
fix python version issue and windows issue
Browse files Browse the repository at this point in the history
  • Loading branch information
bigeagle committed Nov 8, 2014
1 parent 35d1b2c commit 2f09136
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 17 deletions.
9 changes: 3 additions & 6 deletions danmaQ/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import sys
import json
Expand Down Expand Up @@ -26,6 +26,7 @@ def run(self):
server = self.server[:-1]
else:
server = self.server

url = server + uri

while 1:
Expand Down Expand Up @@ -128,11 +129,8 @@ def on_new_danmaku(self, text, style, position):
dm.exited.connect(self.delete_danmaku)
self.dms[str(id(dm))] = dm

dm.show()

def delete_danmaku(self, _id):
dm = self.dms.pop(_id)
dm.close()
self.dms.pop(_id)

def on_subscription_started(self):
if self._save_server.isChecked():
Expand All @@ -158,7 +156,6 @@ def on_subscription_finished(self):

def apply_new_preference(self):
pref = self.config_dialog.preferences()
# print(pref)
Danmaku.set_options(pref)


Expand Down
2 changes: 1 addition & 1 deletion danmaQ/config_dialog.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
from PyQt5 import QtWidgets, QtCore, QtGui
from PyQt5.QtCore import pyqtSignal
Expand Down
20 changes: 14 additions & 6 deletions danmaQ/danmaq_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
OPTIONS = load_config()


class Danmaku(QtWidgets.QLabel):
class Danmaku(QtWidgets.QWidget):
_lock = Lock()
vertical_slots = None

Expand All @@ -44,7 +44,7 @@ def set_options(cls, opts):
cls._speed_scale = opts['speed_scale']

def __init__(self, text="text", style='white', position='fly', parent=None):
super(Danmaku, self).__init__(text, parent)
super(Danmaku, self).__init__(parent)

self._text = text
self._style = style
Expand Down Expand Up @@ -76,25 +76,33 @@ def __init__(self, text="text", style='white', position='fly', parent=None):
self.init_position()

def init_text(self, text, style):
self.label = QtWidgets.QLabel(text, parent=self)
tcolor, bcolor = color_styles.get(style, color_styles['white'])

effect = QtWidgets.QGraphicsDropShadowEffect(self)
effect.setBlurRadius(7)
effect.setColor(bcolor)
effect.setOffset(0, 0)

self.setStyleSheet(
self.label.setStyleSheet(
self._style_tmpl.format(
font_size=self._font_size,
font_family=self._font_family,
color=tcolor,
)
)

self.setGraphicsEffect(effect)
self.label.setGraphicsEffect(effect)
self.label.setContentsMargins(0, 0, 0, 0)

self.setContentsMargins(0, 0, 0, 0)
layout = QtWidgets.QVBoxLayout()
layout.addWidget(self.label, 0, QtCore.Qt.AlignVCenter)
layout.setContentsMargins(0, 0, 0, 0)
self.setLayout(layout)

_msize = self.minimumSizeHint()
_msize.setHeight(_msize.height())
_msize.setHeight(self.label.height()+16)
self.resize(_msize)

def init_position(self):
Expand Down Expand Up @@ -165,7 +173,7 @@ def clean_close(self):
Danmaku.vertical_slots[self.vslot] = 0

self.exited.emit(str(id(self)))
self.close()
self.destroy()


class DanmakuTestApp(QtWidgets.QDialog):
Expand Down
15 changes: 12 additions & 3 deletions danmaQ/settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import os
import sys
import json

DEFAULT_OPTIONS = {
Expand All @@ -22,8 +23,12 @@ def load_config():

if os.path.exists(_cfg_file):
try:
with open(_cfg_file, 'r') as f:
opts = json.load(f)
with open(_cfg_file, 'rb') as f:
if sys.version_info[0] == 3:
s = bytes(f.read()).decode('utf-8')
opts = json.loads(s)
else:
opts = json.load(f)
options['font_family'] = opts['font_family']
options['font_size'] = opts['font_size']
options['speed_scale'] = opts['speed_scale']
Expand All @@ -41,6 +46,10 @@ def load_config():

def save_config(options):
with open(_cfg_file, 'wb') as f:
json.dump(options, f, indent=4)
if sys.version_info[0] == 3:
s = json.dumps(options, indent=4)
f.write(bytes(s, 'utf-8'))
else:
json.dump(options, f, indent=4)

# vim: ts=4 sw=4 sts=4 expandtab
2 changes: 1 addition & 1 deletion danmaQ/tray_icon.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import os
import sys
Expand Down

0 comments on commit 2f09136

Please sign in to comment.