Skip to content

Commit

Permalink
Added the rest of the description
Browse files Browse the repository at this point in the history
  • Loading branch information
Lioheart committed May 28, 2020
1 parent 6bd7489 commit 38f3537
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 39 deletions.
47 changes: 30 additions & 17 deletions notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@


class NotificationIcon:
"""
Odpowiada za ikony notyfikacji
"""
Info, Success, Warning, Error, Close = range(5)
Types = {
Info: None,
Expand All @@ -37,6 +40,9 @@ class NotificationIcon:

@classmethod
def init(cls):
"""
Inicjalizuje proces
"""
cls.Types[cls.Info] = QPixmap(QImage.fromData(base64.b64decode(
'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAC5ElEQVRYR8VX0VHbQBB9e/bkN3QQU0FMBSEVYFcQ8xPBJLJ1FWAqOMcaxogfTAWQCiAVRKkgTgfmM4zRZu6QhGzL0p0nDPr17e7bt7tv14RX/uiV48MJgAon+8TiAMRtMFogaqUJxADPwRRzg67kl8+xbWJWANR40iPQSSFgtX/mGQkaDr56V3VAKgGos4s2JXwJoF3naMPvMS+SrpTHs032GwGkdF+DsFMVnJm/oyGGeHico0EjIjpYes+YMyVd6R/flfkpBWCCQ9zaZM2LZDfLMGXsZ5kdI/lYBmINgHHyyLd1mWdBbAFAM/GY7K2WYx1AeB4T6L1N9umbGxZ0qktATaEAdCps48D39oq/LwEw3U5CN92LfczJoewfT7MAywDCaEbAuxeLrh0zz4L+0e4aAJfGy+sP3IMxlH1vpMJoSMCJDXgWtJeJVc6ACs9HBBrYODCJAFdYvAmkPJxnNqMwYht7Bn+T/lGg3z4DGEd3RPhQ54DBvwAOVkeqagRXfTLjh+x7+8sALOtfHLuiYzWOAiLoKbD58mnIGbCmLxUepS6NQmYlUGE0JeCTTXT9JvA9E9sZgO5iIpoyc6/YzcqSwQzgGgBXB7oXpH9klpRSkxY1xW/b7Iu2zk34PILPnazCqEPAtTWA8iZ0HsOu9L0bw4DzCJeNocMGNDpQ3IKO+6NUiJ4ysZNiBv5I3zPnmJmG5oM+wbS+9+qkvGi7NAXGmeUy0ioofa+XA0jH0UaMKpdRWs/adcwMqfV/tenqpqHY/Znt+j2gJi00RUzA201dXaxh9iZdZloJS+9H1otrkbRrD5InFqpPskxEshJQ468CkSmJC+i1HigaaxCAuCljgoDhwPdOjf7rFVxxuJrMkXScjtKc1rOLNpJk6nii5XmYzbngzlZn+RIb40kPJPTBYXUt6VEDJ8Pi6bWpNFb/jFYY6YGpDeKdjBmTKdMcxDGEmP73v2a2Gr/NOycGtglQZ/MPzEqCMLGckJEAAAAASUVORK5CYII=')))
cls.Types[cls.Success] = QPixmap(QImage.fromData(base64.b64decode(
Expand All @@ -50,27 +56,35 @@ def init(cls):

@classmethod
def icon(cls, ntype):
"""
Metoda odpowiedzialna za wybranie odpowiedniej ikony
:param ntype:
:return: ikona
"""
return cls.Types.get(ntype)


class NotificationItem(QWidget):
"""
Klasa reprezentująca pojedynczy dymek
"""
closed = Signal(QListWidgetItem)

def __init__(self, title, message, item, *args, ntype=0, callback=None, **kwargs):
super(NotificationItem, self).__init__(*args, **kwargs)
self.item = item
self.callback = callback
layout = QHBoxLayout(self, spacing=0)
layout.setContentsMargins(0, 0, 0, 0)
lhbox = QHBoxLayout(self, spacing=0)
lhbox.setContentsMargins(0, 0, 0, 0)
self.bgWidget = QWidget(self) # 背景控件, 用于支持动画效果
layout.addWidget(self.bgWidget)
lhbox.addWidget(self.bgWidget)

layout = QGridLayout(self.bgWidget)
layout.setHorizontalSpacing(15)
layout.setVerticalSpacing(10)
lgbox = QGridLayout(self.bgWidget)
lgbox.setHorizontalSpacing(15)
lgbox.setVerticalSpacing(10)

# 标题左边图标
layout.addWidget(
lgbox.addWidget(
QLabel(self, pixmap=NotificationIcon.icon(ntype)), 0, 0)

# 标题
Expand All @@ -93,11 +107,11 @@ def __init__(self, title, message, item, *args, ntype=0, callback=None, **kwargs
self.labelMessage.adjustSize()

# 添加到布局
layout.addWidget(self.labelTitle, 0, 1)
layout.addItem(QSpacerItem(
lgbox.addWidget(self.labelTitle, 0, 1)
lgbox.addItem(QSpacerItem(
40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum), 0, 2)
layout.addWidget(self.labelClose, 0, 3)
layout.addWidget(self.labelMessage, 1, 1, 1, 2)
lgbox.addWidget(self.labelClose, 0, 3)
lgbox.addWidget(self.labelMessage, 1, 1, 1, 2)

# 边框阴影
effect = QGraphicsDropShadowEffect(self)
Expand All @@ -111,17 +125,15 @@ def __init__(self, title, message, item, *args, ntype=0, callback=None, **kwargs
# 5秒自动关闭
self._timer = QTimer(self, timeout=self.doClose)
self._timer.setSingleShot(True) # 只触发一次
self._timer.start(6000)
self._timer.start(12000)

def doClose(self):
self.closed.emit(self.item)

def showAnimation(self, width):
# 显示动画
pass

def closeAnimation(self):
# 关闭动画
pass

def mousePressEvent(self, event):
Expand Down Expand Up @@ -149,6 +161,9 @@ def paintEvent(self, event):


class NotificationWindow(QListWidget):
"""
Klasa odpowiedznialna za wyswietlanie listy powiadomień
"""
_instance = None

def __init__(self, *args, **kwargs):
Expand All @@ -157,9 +172,7 @@ def __init__(self, *args, **kwargs):
self.setMinimumWidth(412)
self.setMaximumWidth(412)
# QApplication.instance().setQuitOnLastWindowClosed(True)
# 隐藏任务栏,无边框,置顶等
self.setWindowFlags(self.windowFlags() | Qt.Tool |
Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint)
self.setWindowFlags(self.windowFlags() | Qt.Tool | Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint)
# 去掉窗口边框
self.setFrameShape(self.NoFrame)
# 背景透明
Expand Down
Binary file added resources/descriptions/desc_magic.txt.gz
Binary file not shown.
Binary file modified resources/descriptions/magic.txt.gz
Binary file not shown.
51 changes: 29 additions & 22 deletions src/spells.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def initUI(self):
self.btn_subback.setIcon(icon)
icon.addFile('./resources/icons/arrow-left-solid.svg', QSize(), QIcon.Normal, QIcon.Off)
btn_back.setIcon(icon)
# TODO usuń to po wprowadzeniu odpowiednich wartości w bazie danych
# TODO usuń to po wprowadzeniu odpowiednich wartości czarów w bazie danych
self.btn_list.setEnabled(False)
self.text_desc.setViewportMargins(10, 10, 10, 10)

Expand Down Expand Up @@ -172,6 +172,7 @@ def magic(self):
"""
Odpowiada za wyświetlenie menu funkcjonowania czarów
"""
path = './resources/descriptions/magic.txt.gz'
self.clear_layout()

btn_mag1 = QPushButton('Funkcjonowanie czarowania')
Expand All @@ -184,14 +185,16 @@ def magic(self):
btn_mag8 = QPushButton('Specjalne efekty czarów')
btn_mag9 = QPushButton('Łączenie efektów magicznych')

self.submenu_create(btn_mag1, btn_mag2, btn_mag3, btn_mag4, btn_mag5, btn_mag6, btn_mag7, btn_mag8, btn_mag9)
self.create_btn_connect(path, btn_mag1, btn_mag2, btn_mag3, btn_mag4, btn_mag5, btn_mag6, btn_mag7, btn_mag8,
btn_mag9)

self.description_thread('./resources/descriptions/magic.txt.gz')
self.description_thread(path, 'description')

def description(self):
"""
Odpowiada za wyświetlenie menu opisu zaklęć
"""
path = './resources/descriptions/desc_magic.txt.gz'
self.clear_layout()

btn_desc1 = QPushButton('Nazwa')
Expand All @@ -207,8 +210,8 @@ def description(self):
btn_desc11 = QPushButton('Odporność na czary')
btn_desc12 = QPushButton('Opis działania')

self.submenu_create(btn_desc1, btn_desc2, btn_desc3, btn_desc4, btn_desc5, btn_desc6, btn_desc7, btn_desc8,
btn_desc9, btn_desc10, btn_desc11, btn_desc12)
self.create_btn_connect(path, btn_desc1, btn_desc2, btn_desc3, btn_desc4, btn_desc5, btn_desc6, btn_desc7,
btn_desc8, btn_desc9, btn_desc10, btn_desc11, btn_desc12)

self.text_desc.setText(
'''
Expand All @@ -221,54 +224,58 @@ def arcane(self):
"""
Odpowiada za wyświetlenie menu opisu zaklęć wtajemniczeń
"""
path = './resources/descriptions/arcane.txt.gz'
self.clear_layout()

btn_arc1 = QPushButton('Jak czarodziej przygotowuje zaklęcia')
btn_arc2 = QPushButton('Magiczne zapiski wtajemniczeń')
btn_arc3 = QPushButton('Zaklinacze i bardowie')

self.submenu_create(btn_arc1, btn_arc2, btn_arc3)
self.create_btn_connect(path, btn_arc1, btn_arc2, btn_arc3)

btn_arc1.clicked.connect(lambda: self.description_thread('./resources/descriptions/arcane.txt.gz', 'btn1'))
btn_arc2.clicked.connect(lambda: self.description_thread('./resources/descriptions/arcane.txt.gz', 'btn2'))
btn_arc3.clicked.connect(lambda: self.description_thread('./resources/descriptions/arcane.txt.gz', 'btn3'))

self.description_thread('./resources/descriptions/arcane.txt.gz', 'description')
self.description_thread(path, 'description')

def divine(self):
"""
Odpowiada za wyświetlenie menu opisu zakleć objawień
"""
path = './resources/descriptions/divine.txt.gz'
self.clear_layout()

btn_div1 = QPushButton('Jak przygotowuje się zaklęcia objawień')
btn_div2 = QPushButton('Magiczne zapiski objawień')
btn_div3 = QPushButton('Nowe czary objawień')

self.submenu_create(btn_div1, btn_div2, btn_div3)

btn_div1.clicked.connect(
lambda: self.description_thread('./resources/descriptions/divine.txt.gz', 'btn1'))
btn_div2.clicked.connect(
lambda: self.description_thread('./resources/descriptions/divine.txt.gz', 'btn2'))
btn_div3.clicked.connect(
lambda: self.description_thread('./resources/descriptions/divine.txt.gz', 'btn3'))

self.description_thread('./resources/descriptions/divine.txt.gz', 'description')
self.create_btn_connect(path, btn_div1, btn_div2, btn_div3)
self.description_thread(path, 'description')

def power(self):
"""
Odpowiada za wyświetlenie menu zdolności specjalnych
"""
path = './resources/descriptions/power.txt.gz'
self.clear_layout()

self.submenu_create()

self.description_thread('./resources/descriptions/power.txt.gz')
self.description_thread(path)

def create_btn_connect(self, path, *args):
"""
Służy do utworzenia odpowiednich powiązań z przyciskami podmenu. Wymaga ścieżki do pliku z danym opisem
oraz argumentów w postaci przycisków QPushButton
:param path: ścieżka do pliku z opisem
:param args: przyciski QPushButton
"""
self.submenu_create(*args)
for i, val in enumerate(args):
y = 'btn' + str(i + 1)
val.pressed.connect(lambda x=y: self.description_thread(path, x))

def description_thread(self, path, bs_id=None):
"""
Wykonuje odczyt opisu danego podrozdziału z pliku, w osobnym wątku
:param bs_id: id div
:param path: ścieżka do pliku z opisem
"""
que = queue.Queue()
Expand Down

0 comments on commit 38f3537

Please sign in to comment.