Skip to content

Commit

Permalink
1.5.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
noembryo committed Aug 1, 2022
1 parent efeb823 commit b9b1cf7
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 27 deletions.
1 change: 1 addition & 0 deletions images.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<file alias='db_open.png'>stuff/db_open.png</file>
<file alias='db_add.png'>stuff/db_add.png</file>
<file alias='books.png'>stuff/books.png</file>
<file alias='calendar.png'>stuff/calendar.png</file>
<file alias='view_books.png'>stuff/view_books.png</file>
<file alias='view-highlights.png'>stuff/view-highlights.png</file>
<file alias='label_green.png'>stuff/label_green.png</file>
Expand Down
51 changes: 36 additions & 15 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@


__author__ = "noEmbryo"
__version__ = "1.4.4.0"
__version__ = "1.5.0.0"


def _(text): # for future gettext support
Expand Down Expand Up @@ -113,7 +113,7 @@ def get_csv_row(data):
# def hide_console():
# """ Hides the console window in GUI mode. Necessary for frozen application,
# because this application support both, command line processing AND GUI mode
# and therefor cannot be run via pythonw.exe.
# and therefore cannot be run via pythonw.exe.
# """
#
# win_handles = ctypes.windll.kernel32.GetConsoleWindow()
Expand Down Expand Up @@ -159,6 +159,7 @@ def __init__(self, parent=None):
self.exit_msg = True
self.db_path = join(SETTINGS_DIR, "data.db")
self.date_vacuumed = datetime.now().strftime(DATE_FORMAT)
self.date_format = DATE_FORMAT
# ___ ___________________________________

self.file_selection = None
Expand Down Expand Up @@ -959,9 +960,10 @@ def create_row(self, filename, data=None, date=None):
stats = self.get_item_db_stats(data)
icon, title, authors, percent, rating, status, high_count = stats

# noinspection PyArgumentList
color = ("#660000" if status == "abandoned" else
# "#005500" if status == "complete" else
None)
QApplication.palette().text().color())

self.file_table.setSortingEnabled(False)
self.file_table.insertRow(0)
Expand Down Expand Up @@ -1359,11 +1361,13 @@ def populate_high_list(self, data, path=""):
self.status.act_date.isChecked() else "")
line_break = (":\n" if self.status.act_page.isChecked() or
self.status.act_date.isChecked() else "")
def_date_format = self.date_format == DATE_FORMAT
highlights = self.parse_highlights(data, path)
for i in sorted(highlights, key=self.sort_high4view):
page_text = (_("Page ") + str(i["page"])
if self.status.act_page.isChecked() else "")
date_text = "[" + i["date"] + "]" if self.status.act_date.isChecked() else ""
date = i["date"] if def_date_format else self.get_date_text(i["date"])
date_text = "[" + date + "]" if self.status.act_date.isChecked() else ""
high_text = i["text"] if self.status.act_text.isChecked() else ""
line_break2 = ("\n" if self.status.act_comment.isChecked() and i["comment"]
else "")
Expand Down Expand Up @@ -1426,14 +1430,14 @@ def get_highlight_info(data, page, page_id):
highlight["date"] = date
highlight["text"] = text
highlight["comment"] = comment
highlight["page"] = page
highlight["page"] = str(page) # 2check for problems elsewhere
highlight["page_id"] = page_id
except KeyError: # blank highlight
return
return highlight

@staticmethod
def get_high_data(data, page, page_id): # 2check: is it better than the prev
def get_high_data(data, page, page_id): # 2check: is it better than the prev def
""" Get the highlight's info (text, comment, date and page)
:type data: dict
Expand Down Expand Up @@ -2202,7 +2206,6 @@ def on_export(self):
idx = MANY_CSV if multi else ONE_CSV
else:
return

self.export(idx)

# noinspection PyCallByClass
Expand Down Expand Up @@ -2414,10 +2417,15 @@ def save_sel_highlights(self):

text = HTML_HEAD if html_out else CSV_HEAD if csv_out else ""
encoding = "utf-8-sig" if csv_out else "utf-8"
def_date_format = self.date_format == DATE_FORMAT
for i in sorted(self.sel_high_view):
row = i.row()
data = self.high_table.item(row, HIGHLIGHT_H).data(Qt.UserRole)
comment = "\n● " + data["comment"] if data["comment"] else ""

if not def_date_format:
data["date"] = self.get_date_text(data["date"])

if text_out:
txt = ("{} [{}]\nPage {} [{}]\n{}{}"
.format(data["title"], data["authors"], data["page"],
Expand Down Expand Up @@ -2458,6 +2466,7 @@ def analyze_high(self, data, page, page_id, format_):
high_text = (highlight["text"].replace("\n", linesep)
if self.status.act_text.isChecked() else "")
date = highlight["date"]
date = date if self.date_format == DATE_FORMAT else self.get_date_text(date)
line_break2 = (os.linesep if self.status.act_text.isChecked() and comment else "")
if format_ in [ONE_CSV, MANY_CSV]:
page_text = str(page) if self.status.act_page.isChecked() else ""
Expand All @@ -2471,6 +2480,11 @@ def analyze_high(self, data, page, page_id, format_):
if self.status.act_comment.isChecked() and comment else "")
return date_text, high_comment, high_text, page_text

def get_date_text(self, date):
dt_obj = datetime.strptime(date, DATE_FORMAT)
date = dt_obj.strftime(self.date_format)
return date

# ___ ___________________ SETTINGS STUFF ________________________

def settings_load(self):
Expand All @@ -2497,6 +2511,7 @@ def settings_load(self):
self.toolbar_size = app_config.get("toolbar_size", 48)
self.skip_version = app_config.get("skip_version", None)
self.date_vacuumed = app_config.get("date_vacuumed", self.date_vacuumed)
self.date_format = app_config.get("date_format", DATE_FORMAT)
self.archive_warning = app_config.get("archive_warning", True)
self.exit_msg = app_config.get("exit_msg", True)
self.high_merge_warning = app_config.get("high_merge_warning", True)
Expand Down Expand Up @@ -2533,7 +2548,7 @@ def settings_save(self):
"archive_warning": self.archive_warning, "exit_msg": self.exit_msg,
"current_view": self.current_view, "db_mode": self.db_mode,
"high_by_page": self.high_by_page, "date_vacuumed": self.date_vacuumed,
"show_info": self.fold_btn.isChecked(),
"show_info": self.fold_btn.isChecked(), "date_format": self.date_format,
"show_items": (self.status.act_page.isChecked(),
self.status.act_date.isChecked(),
self.status.act_text.isChecked(),
Expand Down Expand Up @@ -2605,7 +2620,8 @@ def thread_cleanup(self):
self.threads.remove(thread)

def popup(self, title, text, icon=QMessageBox.Warning, buttons=1,
extra_text="", button_text=(_("OK"), _("Cancel")), check_text=""):
extra_text="", button_text=(_("OK"), _("Cancel")),
check_text=False, input_text=False):
""" Creates and returns a Popup dialog
:type title: str|unicode
Expand All @@ -2619,7 +2635,9 @@ def popup(self, title, text, icon=QMessageBox.Warning, buttons=1,
:type extra_text: str|unicode
:parameter extra_text: The extra button's text (button is omitted if "")
:type check_text: str|unicode
:parameter check_text: The checkbox's text (checkbox is omitted if "")
:parameter check_text: The checkbox's text (checkbox is omitted if False)
:type input_text: str | unicode | bool
:parameter input_text: The input text's text (input text is omitted if False)
"""
popup = XMessageBox(self)
popup.setWindowIcon(self.ico_app)
Expand All @@ -2633,19 +2651,22 @@ def popup(self, title, text, icon=QMessageBox.Warning, buttons=1,
raise TypeError("Wrong icon type!")
popup.setWindowTitle(title)
popup.setText(text + "\n" if check_text else text)

if buttons == 1:
popup.addButton(_("Close"), QMessageBox.RejectRole)
elif buttons == 2:
popup.addButton(button_text[0], QMessageBox.AcceptRole)
popup.addButton(button_text[1], QMessageBox.RejectRole)

if extra_text: # add an extra button
popup.addButton(extra_text, QMessageBox.ApplyRole)
if check_text: # hide check_box if no text for it
popup.check_box.setText(check_text)
else:
popup.check_box.hide()
popup.checked = popup.exec_()[1]

if check_text: # Show check_box
popup.set_check(check_text)
elif input_text: # Show input QLineEdit
popup.set_input(input_text)

popup.exec_()
return popup

def passed_files(self):
Expand Down
87 changes: 75 additions & 12 deletions secondary.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
from PySide.QtCore import Qt, Slot, QObject, Signal, QSize, QPoint, QEvent
from PySide.QtGui import (QApplication, QMessageBox, QIcon, QFileDialog, QTableWidgetItem,
QDialog, QWidget, QMovie, QFont, QMenu, QAction, QTableWidget,
QCheckBox, QToolButton, QActionGroup, QCursor)
QCheckBox, QToolButton, QActionGroup, QCursor, QLineEdit)
else:
from PySide2.QtCore import QObject, Qt, Signal, QPoint, Slot, QSize, QEvent
from PySide2.QtGui import QFont, QMovie, QIcon, QCursor
from PySide2.QtWidgets import (QTableWidgetItem, QTableWidget, QMessageBox,
from PySide2.QtWidgets import (QTableWidgetItem, QTableWidget, QMessageBox, QLineEdit,
QApplication, QWidget, QDialog, QFileDialog,
QActionGroup, QMenu, QAction, QToolButton, QCheckBox)
import requests
Expand Down Expand Up @@ -123,20 +123,57 @@ def __init__(self, parent=None):
super(XMessageBox, self).__init__(parent)

self.check_box = QCheckBox()
self.check_box.stateChanged.connect(self.checkbox_state_changed)
self.checked = False

if QT4:
# Access the Layout of the MessageBox to add a Checkbox
layout = self.layout()
layout.addWidget(self.check_box, 1, 1)
else:
self.setCheckBox(self.check_box)
self.input = QLineEdit()
self.input.textChanged.connect(self.input_text_changed)
self.typed_text = ""

def set_check(self, text):
""" Sets the Popup's CheckBox
:type text: str|unicode
:param text: The CheckBox's text
"""
self.add_to_layout(self.check_box)
self.check_box.setText(text)

def checkbox_state_changed(self, state):
""" Update the checked variable
def exec_(self, *args, **kwargs):
""" Override the exec_ method so
you can return the value of the checkbox
:type state: bool
:param state: The CheckBox's state
"""
return QMessageBox.exec_(self, *args, **kwargs), self.check_box.isChecked()
self.checked = bool(state)

def set_input(self, text):
""" Sets the Popup's text input
:type text: str|unicode|bool
:param text: The QLineEdit's text
"""
self.add_to_layout(self.input)
if not isinstance(text, bool):
self.input.setText(text)

def input_text_changed(self, text):
""" Update the typed_text variable
:type text: str|unicode
:param text: The QLineEdit's text
"""
self.typed_text = text

def add_to_layout(self, widget):
""" Add the given widget to the popup's layout
Only one widget can be added in a popup instance
:type widget: QWidget
:param widget: The widget to be added
"""
# noinspection PyArgumentList
self.layout().addWidget(widget, 1, 1 if PYTHON2 else 2)


class XToolButton(QToolButton):
Expand Down Expand Up @@ -269,6 +306,7 @@ def get_book_highlights(self, data, path):

# ___ _______________________ GUI STUFF _____________________________


from gui_about import Ui_About
from gui_auto_info import Ui_AutoInfo
from gui_toolbar import Ui_ToolBar
Expand Down Expand Up @@ -725,6 +763,11 @@ def __init__(self, parent=None):
i.triggered.connect(self.on_show_items)
i.setChecked(True)

action = QAction(_("Date Format"), self.show_menu)
action.setIcon(QIcon(":/stuff/calendar.png"))
action.triggered.connect(self.set_date_format)
self.show_menu.addAction(action)

sort_menu = QMenu(self)
ico_sort = QIcon(":/stuff/sort.png")
group = QActionGroup(self)
Expand Down Expand Up @@ -761,6 +804,26 @@ def on_show_items(self):
item = self.base.file_table.item(idx.row(), 0)
self.base.on_file_table_itemClicked(item)

def set_date_format(self):
""" Changes the date format
"""
popup = self.base.popup(_("Set custom Date format"),
_("The default format is %Y-%m-%d %H:%M:%S\nUse these "
"symbols in any order, combined with any other "
"character.\nFor more info about the supported symbols "
"press Help."),
icon=QMessageBox.Information, buttons=2,
extra_text=_("Help"), input_text=self.base.date_format,
button_text=(_("OK"), _("Use Default")))
if popup.buttonRole(popup.clickedButton()) == QMessageBox.AcceptRole:
self.base.date_format = popup.typed_text
elif popup.buttonRole(popup.clickedButton()) == QMessageBox.RejectRole:
self.base.date_format = DATE_FORMAT
elif popup.buttonRole(popup.clickedButton()) == QMessageBox.ApplyRole:
webbrowser.open("https://docs.python.org/2.7/library/datetime.html"
"#strftime-strptime-behavior")
self.on_show_items()

def animation(self, run):
""" Creates or deletes temporary files and folders
Expand Down
Binary file added stuff/calendar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b9b1cf7

Please sign in to comment.