Skip to content

Commit

Permalink
Lint the code
Browse files Browse the repository at this point in the history
  • Loading branch information
nikosavola committed Jan 7, 2022
1 parent 0a20501 commit 91fefee
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 60 deletions.
9 changes: 6 additions & 3 deletions bulletin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from functools import partial
from jinja2 import Environment, FileSystemLoader, Markup

from jinja2 import Environment, FileSystemLoader
from markupsafe import Markup

from utils import grouper, category_sort, categories, categories_en, week, all_entries


Expand Down Expand Up @@ -37,10 +40,10 @@ def nl2br(s):
template_short = env.get_template('cells_short.html')
variables = {
"title": "Fyysikkokillan viikkotiedote",
"header": week+"/2020\n"+"Kilta tiedottaa\nGuild News",
"header": week+"/2022\n"+"Kilta tiedottaa\nGuild News",
"category_events": pairs,
"category_events_en": pairs_en,
"communications_officer": "Niko Savola",
"communications_officer": "Jaakko Johansson",
"telegram_nick": "viestintavastaava",
"email": "viestintavastaava@fyysikkokilta.fi",
"week": week
Expand Down
76 changes: 21 additions & 55 deletions gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
from PyQt5 import QtCore, QtGui
from PyQt5.QtCore import QDateTime
from PyQt5.QtWidgets import (QApplication, QDialog, QGridLayout, QGroupBox,
QRadioButton, QHBoxLayout, QVBoxLayout, QStyleFactory, QLineEdit,
QTextEdit, QLabel, QPushButton, QTabWidget, QWidget, QButtonGroup,
QDateEdit, QCheckBox, QShortcut, QTextBrowser)
QRadioButton, QHBoxLayout, QVBoxLayout, QStyleFactory, QLineEdit,
QTextEdit, QLabel, QPushButton, QButtonGroup,
QDateEdit, QCheckBox)

from utils import save_entry


class MainWindow(QDialog):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
super().__init__(parent)

self.createCategorySelectionGroupBox()
self.createTextEditLayout()
Expand All @@ -28,8 +29,8 @@ def __init__(self, parent=None):
self.setWindowIcon(QtGui.QIcon('templates/fi.png'))

# Always-on-top mode. Currently does not work on Windows.
#alwaysOnTopShortcut = QShortcut(QtGui.QKeySequence("Ctrl+O"), self)
#alwaysOnTopShortcut.activated.connect(lambda:
# alwaysOnTopShortcut = QShortcut(QtGui.QKeySequence("Ctrl+O"), self)
# alwaysOnTopShortcut.activated.connect(lambda:
# super(MainWindow, self).__init__(parent, QtCore.Qt.WindowStaysOnTopHint))

def createCategorySelectionGroupBox(self):
Expand Down Expand Up @@ -73,46 +74,27 @@ def createCategorySelectionGroupBox(self):
self.categorySelectionLayout.addWidget(dateLabel)
self.categorySelectionLayout.addWidget(self.dateEdit)


def otherLanguageText(self, text): # convert to dictionary

if (text == "Guild's events"):
@staticmethod
def otherLanguageText(text): # convert to dictionary
if text == "Guild's events":
return "Killan tapahtumat"
elif (text == "Killan tapahtumat"):
elif text == "Killan tapahtumat":
return "Guild's events"
elif (text == "Other events"):
elif text == "Other events":
return "Muut tapahtumat"
elif (text == "Muut tapahtumat"):
elif text == "Muut tapahtumat":
return "Other events"
elif (text == "General"):
elif text == "General":
return "Yleistä"
elif (text == "Yleistä"):
elif text == "Yleistä":
return "General"
elif (text == "Studies"):
elif text == "Studies":
return "Opinnot"
elif (text == "Opinnot"):
elif text == "Opinnot":
return "Studies"
else:
raise Exception("Wrong value for otherLanguageText")

"""
categoriesDict_en = {
"Guild's events":"Killan tapahtumat",
"Other events":"Muut tapahtumat",
"General":"Yleistä",
"Studies":"Opinnot"
}
categoriesDict_fi = dict(reversed(item) for item in categoriesDict_en.items())
categoriesDict = dict(categoriesDict_en, categoriesDict_fi)
try:
return categoriesDict(text)
except ValueError:
raise Exception("Wrong value for otherLanguageText")
"""


def languageCheckBoxClicked(self, state):
if state == QtCore.Qt.Checked:
self.radioButton1.setText("Guild's events")
Expand All @@ -125,21 +107,11 @@ def languageCheckBoxClicked(self, state):
self.radioButton3.setText("Yleistä")
self.radioButton4.setText("Opinnot")



#def hide(self):
# self.headerLineEdit.hide()
# self.textBrowser = QTextBrowser()
# self.textBrowser.setGeometry(QtCore.QRect(390, 10, 531, 681))
# self.textBrowser.setObjectName("textBrowser")
# self.textBrowser.show()


def createTextEditLayout(self):
self.textEditLayout = QVBoxLayout()

self.additionalWeeksEdit = QLineEdit()
self.additionalWeeksEdit.setText("0") # default
self.additionalWeeksEdit.setText("0") # default
self.headerLineEdit = QLineEdit()
self.imageUrl = QLineEdit()
self.contentTextEdit = QTextEdit()
Expand All @@ -162,8 +134,6 @@ def createTextEditLayout(self):
self.textEditLayout.addWidget(contentLabel)
self.textEditLayout.addWidget(self.contentTextEdit)



def createButtonLayout(self):
self.buttonLayout = QHBoxLayout()

Expand All @@ -177,7 +147,6 @@ def createButtonLayout(self):
self.buttonLayout.addStretch(1)
self.buttonLayout.addWidget(savePushButton)


def save(self):
category = self.categorySelectionButtonGroup.checkedButton().text()
date = [self.dateEdit.date().day(), self.dateEdit.date().month(), self.dateEdit.date().year()]
Expand All @@ -192,20 +161,19 @@ def save(self):
'header': header,
'image': image,
'content': content
}, self.languageCheckBox.isChecked(), weeks)
}, self.languageCheckBox.isChecked(), weeks)

if self.toBothBulletinsCheckBox.isChecked():
save_entry({
'category': self.otherLanguageText(category), # both languages fix here
'category': self.otherLanguageText(category), # both languages fix here
'date': date,
'header': header,
'image': image,
'content': content
}, not self.languageCheckBox.isChecked(), weeks)
}, not self.languageCheckBox.isChecked(), weeks)

self.clear()


def clear(self):
self.headerLineEdit.clear()
self.imageUrl.clear()
Expand All @@ -215,9 +183,7 @@ def clear(self):
self.dateEdit.setDateTime(QDateTime.currentDateTime())



if __name__ == '__main__':

import sys

app = QApplication(sys.argv)
Expand Down
4 changes: 2 additions & 2 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


# Database logic.
def save_entry(dict, isEnglish=False, addWeeks=0):
def save_entry(entry, isEnglish=False, addWeeks=0):
"""Save entry to database."""
for i in range(addWeeks+1):
week_number = str(int(week)+i).zfill(2)
Expand All @@ -28,7 +28,7 @@ def save_entry(dict, isEnglish=False, addWeeks=0):
else:
path = 'data/week'+week_number+'.json'
db = TinyDB(path, ensure_ascii=False, sort_keys=True, indent=4, separators=(',', ': '))
db.insert(dict)
db.insert(entry)

def all_entries(isEnglish=False):
"""Return all events from database for this week."""
Expand Down

0 comments on commit 91fefee

Please sign in to comment.