Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include more options in Book window. #6

Merged
merged 1 commit into from
Apr 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
# Filename: .travis.yml

sudo: required
dist: xenial

language: python
cache: pip
# https://github.com/travis-ci/travis-ci/issues/9815
# Enable 3.7 without globally enabling sudo and dist: xenial for other build jobs
matrix:
include:
- python: 3.7
dist: xenial
sudo: true

python:
- '3.7'

install:
- pip install --upgrade -r requirements.txt
- pip install --upgrade -r requirements-dev.txt

# Add xvfb service since we have tests that requires GUI
# https://docs.travis-ci.com/user/gui-and-headless-browsers/#using-services-xvfb
services:
- xvfb

script:
#- pylint booklib
- pip install -e . && python -m pytest tests
- qmake -v
- pip install -e . && pytest --ignore=tests/ui/window tests

notifications:
slack: curious-minds-101:Wkf5gPKQyJalUZ99Oyql0Zav
slack:
rooms:
secure: Su/kx2T4NUiX3p5HdirVhsseYH3sBDiESXo36fCoySqHir+DMEadIFSwGneL9Pxg1OX6QpNnPrawWerc4Bo3uWIH5rqmZdX4hexVDTyG8Y3S2k7bODgRbrPzFIXdT3DequD17qr9veAj8wbfeEJOqvWwvMAMkPtyEvhsRI2RfOvC417lBKlqX/RH72LW1NgbvaM/hcQYDtHqhMdurPJXI7WXGirC1nmt4bPKYfDwewIK+2rH/VUHiXgLpLqZPD0crl3tv0JKvuKv45O2elD4f7j4oEpKp0+DBZLzPlcGHnDdObF2jv3r+vZLqD/SRoMeBwM6tl6qcay6Te2ZLuqGtdj1KmXw2fvo98yDEyUq0sSbBUlOyUBhtLn0qgbBvwpe2YslAuQPdKZABzCiiSv7uU5+TgSvSEq5Rrh5oTBYsfJzb0X9gZWhlZkDb0RhwvEKtQDWmK8j3shxPSSpYAznjvCnNzLywEycGgdU1bk8U9vsWoM/S13BOu+C26cHpTVK7Go4wL3DYrvy/Qx4J26wp1fBnWSbgE1PahkWvNKAj6Sup7hliJc4GukwumEUOuAdu2G0/mk5rKgIFUjswEufSRPzmJLv3xG6xMusJ93+lrddt+wS2d6b7nlnx6MtFV+qkWrtOm9uN8Rot8jW6XcBQdGvrjRluCBdJxA2xAFWnCU=
on_success: always
on_failure: change
4 changes: 4 additions & 0 deletions booklib/ui/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
'category_txt': 'Categories',
'level_txt': 'Level',
'title_txt': 'Title',
'authors_txt': 'Authors',
'publisher_txt': 'Publisher',
'ok_btn': 'OK',
'cancel_btn': 'Cancel',
},
Expand Down Expand Up @@ -58,6 +60,8 @@
'category_txt': 'Categories',
'level_txt': 'Level',
'title_txt': 'Title',
'authors_txt': 'Authors',
'publisher_txt': 'Publisher',
'ok_btn': 'OK',
'cancel_btn': 'Cancel',
},
Expand Down
18 changes: 11 additions & 7 deletions booklib/ui/window/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
"""

# Standard libraries
import typing

# PyQt5
import PyQt5.QtWidgets as qtw

# BookLib
from booklib import config
from booklib.ui.config import LABELS
from booklib.ui.window.account import AccountWindow
from booklib.ui.window.book import BookWindow
Expand All @@ -20,15 +22,17 @@ class AdminWindow(qtw.QMainWindow):
Main admin window.
"""

def __init__(self, cfg, *args, **kwargs):
def __init__(self, cfg: config.MenuConfig, *args, **kwargs):
super().__init__(*args, **kwargs)
self.cfg = cfg
self.label_root = __class__.__name__

# Account window
self.account_btn = None
self.account_window = None

# Book window
self.book_btn = None
self.book_window = None

self.init_ui()
Expand All @@ -54,16 +58,16 @@ def init_window_ui(self):
grid = qtw.QGridLayout()
vbox_side_menu = qtw.QVBoxLayout()
# Add account button
account_btn = qtw.QPushButton(labels['account_btn'], self)
account_btn.clicked.connect(self.show_account_window)
self.account_btn = qtw.QPushButton(labels['account_btn'], self)
self.account_btn.clicked.connect(self.show_account_window)
# grid.addWidget(account_btn, 1, 0)
vbox_side_menu.addWidget(account_btn)
vbox_side_menu.addWidget(self.account_btn)

# Add book button
book_btn = qtw.QPushButton(labels['book_btn'], self)
book_btn.clicked.connect(self.show_book_window)
self.book_btn = qtw.QPushButton(labels['book_btn'], self)
self.book_btn.clicked.connect(self.show_book_window)
# grid.addWidget(book_btn, 2, 0)
vbox_side_menu.addWidget(book_btn)
vbox_side_menu.addWidget(self.book_btn)

# Add search menu: text bar + button
hbox_search_menu = qtw.QHBoxLayout()
Expand Down
21 changes: 20 additions & 1 deletion booklib/ui/window/book.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from booklib.ui.config import LABELS

# BookLib
from booklib.models import BookCategoryEnum
from booklib.models import BookCategoryEnum, ReadingLevelEnum


class BookInfo:
Expand Down Expand Up @@ -47,6 +47,17 @@ def __init__(self):
categories_layout.addWidget(self.categories_others_qt, 5, 0)
self.categories_box_qt.setLayout(categories_layout)

self.reading_level_qt = qtw.QComboBox()
# Add empty string as default.
self.reading_level_qt.addItem('')
for level in ReadingLevelEnum:
self.reading_level_qt.addItem(level.name)
# self.reading_level_qt.activated[str].connect()

self.title_qt = qtw.QLineEdit()
self.author_qt = qtw.QLineEdit()
self.publisher_qt = qtw.QLineEdit()


class BookWindow(qtw.QDialog):
def __init__(self, admin_window, *args, **kwargs):
Expand All @@ -64,13 +75,21 @@ def init_ui(self):

isbn_no = qtw.QLabel(labels['isbn_no_txt'])
call_no = qtw.QLabel(labels['call_no_txt'])
title = qtw.QLabel(labels['title_txt'])
authors = qtw.QLabel(labels['authors_txt'])
publisher = qtw.QLabel(labels['publisher_txt'])
categories = qtw.QLabel(labels['category_txt'])
reading_level = qtw.QLabel(labels['level_txt'])

# Create forms.
form_layout = qtw.QFormLayout()
form_layout.addRow(isbn_no, self.book.isbn_no_qt)
form_layout.addRow(call_no, self.book.call_no_qt)
form_layout.addRow(title, self.book.title_qt)
form_layout.addRow(authors, self.book.author_qt)
form_layout.addRow(publisher, self.book.publisher_qt)
form_layout.addRow(categories, self.book.categories_box_qt)
form_layout.addRow(reading_level, self.book.reading_level_qt)

# Add confirmation buttons at the bottom.
button_box = qtw.QDialogButtonBox()
Expand Down
2 changes: 2 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ coverage
pylint
pyqt5-stubs
pytest
pytest-qt
pytest-xvfb
pytype
Empty file added tests/ui/window/__init__.py
Empty file.
34 changes: 34 additions & 0 deletions tests/ui/window/test_admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Filename: tests/ui/window/test_admin.py

# Standard library
import os

# PyQt5
from PyQt5 import QtCore as qtc

# PyTest-Qt
from pytestqt import qtbot

# BookLib
from booklib import config
from booklib.ui.window import admin


def test_click_account(qtbot):
cfg = config.MenuConfig()
window = admin.AdminWindow(cfg)
qtbot.addWidget(window)

qtbot.mouseClick(window.account_btn, qtc.Qt.LeftButton)
assert window.account_window.isVisible()
assert not window.isVisible()


def test_click_book(qtbot):
cfg = config.MenuConfig()
window = admin.AdminWindow(cfg)
qtbot.addWidget(window)

qtbot.mouseClick(window.book_btn, qtc.Qt.LeftButton)
assert window.book_window.isVisible()
assert not window.isVisible()