Skip to content
This repository has been archived by the owner on Mar 14, 2020. It is now read-only.

Commit

Permalink
Added option to hide sidebarwidget on startup in settings;
Browse files Browse the repository at this point in the history
Minor changes;
  • Loading branch information
twiddli committed Jan 16, 2016
2 parents 4af1313 + 2bf933d commit 0029db4
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 46 deletions.
16 changes: 8 additions & 8 deletions version/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,9 +604,7 @@ def init_toolbar(self):
# debug specfic code
if app_constants.DEBUG:
def debug_func():
from pyqtgraph import examples
print("yes!")
examples.run()
pass

debug_btn = QToolButton()
debug_btn.setText("DEBUG BUTTON")
Expand Down Expand Up @@ -817,7 +815,6 @@ def add_gallery(gallery_list):
def append_to_model(x):
self.manga_list_view.sort_model.insertRows(x, None, len(x))
self.manga_list_view.sort_model.init_search(self.manga_list_view.sort_model.current_term)

class A(QObject):
done = pyqtSignal()
prog = pyqtSignal(int)
Expand Down Expand Up @@ -1151,10 +1148,13 @@ def cleanup_exit(self):
log.exception('Flush temp on exit: FAIL')

# DB
log_i("Analyzing database...")
gallerydb.GalleryDB.analyze()
log_i("Closing database...")
gallerydb.GalleryDB.close()
try:
log_i("Analyzing database...")
gallerydb.GalleryDB.analyze()
log_i("Closing database...")
gallerydb.GalleryDB.close()
except:
pass
self.download_window.close()

# check if there is db activity
Expand Down
3 changes: 2 additions & 1 deletion version/app_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
EXTRACT_CHAPTER_BEFORE_OPENING = get(True, 'Application', 'extract chapter before opening', bool)
OPEN_GALLERIES_SEQUENTIALLY = get(False, 'Application', 'open galleries sequentially', bool)
SEND_FILES_TO_TRASH = get(True, 'Application', 'send files to trash', bool)
SHOW_SIDEBAR_WIDGET = get(False, 'Application', 'show sidebar widget', bool)

# ADVANCED
GALLERY_DATA_FIX_REGEX = get("", 'Advanced', 'gallery data fix regex', str)
Expand Down Expand Up @@ -237,7 +238,7 @@ class WrongLogin(Exception): pass
"""Filters are basically predefined gallery search terms.
Every time a gallery matches the specific filter it gets automatically added to the list!
Filter works the same way a gallery search do so make sure to read the guide in
Filter works the same way a gallery search does so make sure to read the guide in
Settings -> About -> Search Guide.
You can write any valid gallery search term.
Regex works only if enabled in settings.
Expand Down
6 changes: 3 additions & 3 deletions version/database/db.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#"""
#"""
#This file is part of Happypanda.
#Happypanda is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -360,7 +360,7 @@ def begin(cls):
"Useful when modifying for a large amount of data"
cls._AUTO_COMMIT = False
cls.execute(cls, "BEGIN TRANSACTION")
print("STARTED DB OPTIMIZE")
#print("STARTED DB OPTIMIZE")

@classmethod
def end(cls):
Expand All @@ -370,7 +370,7 @@ def end(cls):
except sqlite3.OperationalError:
pass
cls._AUTO_COMMIT = True
print("ENDED DB OPTIMIZE")
#print("ENDED DB OPTIMIZE")

def execute(self, *args):
"Same as cursor.execute"
Expand Down
24 changes: 14 additions & 10 deletions version/gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,9 @@ def img_too_big(start_x):
painter.drawPath(ribbon_path)
#painter.setPen(QColor("#d35400"))
#painter.drawPolyline(rib_top_1, rib_star_p1_1, rib_star_p1_2, rib_star_mid_1, rib_star_p1_4, rib_star_p1_3, rib_side_1)
#painter.drawLine(rib_top_1, rib_top_2)
#painter.drawLine(rib_top_2, rib_side_2)
#painter.drawLine(rib_side_1, rib_side_2)
painter.restore()

if app_constants._REFRESH_EXTERNAL_VIEWER:
Expand Down Expand Up @@ -888,8 +890,10 @@ def draw_text_label(lbl_h):
lbl_rect = draw_text_label(app_constants.GRIDBOX_LBL_H)

clipping = QRectF(x, y+app_constants.THUMB_H_SIZE, w, app_constants.GRIDBOX_LBL_H - 10)
painter.setPen(QColor(title_color))
title_layout.draw(painter, QPointF(x, y+app_constants.THUMB_H_SIZE),
clip=clipping)
painter.setPen(QColor(artist_color))
artist_layout.draw(painter, QPointF(x, y+app_constants.THUMB_H_SIZE+t_h),
clip=clipping)
#painter.fillRect(option.rect, QColor)
Expand Down Expand Up @@ -950,16 +954,16 @@ def draw_text_label(lbl_h):
txt_layout.draw(painter, QPointF(x, y+h*0.3))
painter.restore()

#if app_constants.DEBUG:
# painter.save()
# painter.setBrush(QBrush(QColor("red")))
# painter.setPen(QColor("white"))
# txt_l = self.title_font_m.width(str(gallery.id))
# painter.drawRect(x, y, txt_l*2, self.title_font_m.height())
# painter.drawText(x+1, y+11, str(gallery.id))
# painter.restore()
#if option.state & QStyle.State_Selected:
# painter.setPen(QPen(option.palette.highlightedText().color()))
if app_constants.DEBUG:
painter.save()
painter.setBrush(QBrush(QColor("red")))
painter.setPen(QColor("white"))
txt_l = self.title_font_m.width(str(gallery.id))
painter.drawRect(x, y+40, txt_l*2, self.title_font_m.height())
painter.drawText(x+1, y+51, str(gallery.id))
painter.restore()
if option.state & QStyle.State_Selected:
painter.setPen(QPen(option.palette.highlightedText().color()))
else:
super().paint(painter, option, index)

Expand Down
2 changes: 2 additions & 0 deletions version/gallerydb.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ def clear_thumb(path):
try:
if not os.path.samefile(path, app_constants.NO_IMAGE_PATH):
os.unlink(path)
except FileNotFoundError:
pass
except:
log.exception('Failed to delete thumb {}'.format(os.path.split(path)[1].encode(errors='ignore')))

Expand Down
3 changes: 1 addition & 2 deletions version/gallerydialog.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import queue, os, threading, random, logging, time, scandir
import queue, os, threading, random, logging, time, scandir
from datetime import datetime

from PyQt5.QtWidgets import (QWidget, QVBoxLayout, QDesktopWidget, QGroupBox,
Expand Down Expand Up @@ -202,7 +202,6 @@ def resizeEvent(self, event):

def _find_combobox_match(self, combobox, key, default):
f_index = combobox.findText(key, Qt.MatchFixedString)
print(key)
if f_index != -1:
combobox.setCurrentIndex(f_index)
else:
Expand Down
3 changes: 2 additions & 1 deletion version/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,7 @@ def __init__(self, parent, mode=PROGRESS):
main_layout.addWidget(self.info_lbl)
if mode == self.PROGRESS:
self.info_lbl.setText("Updating your galleries to newest version...")
self.info_lbl.setWordWrap(True)
class progress(QProgressBar):
reached_maximum = pyqtSignal()
def __init__(self, parent=None):
Expand All @@ -1419,7 +1420,7 @@ def setValue(self, v):
main_layout.addWidget(self.restart_info)
elif mode == self.MESSAGE:
self.info_lbl.setText("<font color='red'>An exception has ben encountered.\nContact the developer to get this fixed."+
"\nStability from this point on won't be guaranteed.</font>")
"\nStability from this point onward cannot be guaranteed.</font>")
self.setWindowTitle("It was too big!")

self.main_widget.setLayout(main_layout)
Expand Down
17 changes: 10 additions & 7 deletions version/misc_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,18 +325,18 @@ def __init__(self, parent):
super().__init__(parent)
self.parent_widget = parent
self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Expanding)
widget_layout = QHBoxLayout(self)
self._widget_layout = QHBoxLayout(self)

# widget stuff
self._d_widget = QWidget(self)
widget_layout.addWidget(self._d_widget)
self._widget_layout.addWidget(self._d_widget)
self.main_layout = QVBoxLayout(self._d_widget)
self.main_layout.setSpacing(0)
self.main_layout.setContentsMargins(0,0,0,0)
self.arrow_handle = misc.ArrowHandle(self)
self.arrow_handle.CLICKED.connect(self.slide)

widget_layout.addWidget(self.arrow_handle)
self._widget_layout.addWidget(self.arrow_handle)
self.setContentsMargins(0,0,-self.arrow_handle.width(),0)

self.show_all_galleries_btn = QPushButton("Show all galleries")
Expand Down Expand Up @@ -405,20 +405,20 @@ def __init__(self, parent):
parent.manga_list_view.gallery_model.db_emitter.DONE.connect(self.tags_tree.setup_tags)
parent.manga_list_view.gallery_model.db_emitter.DONE.connect(self.lists.setup_lists)

self.adjustSize()
self.slide_animation = misc.create_animation(self, "maximumSize")
self.slide_animation.stateChanged.connect(self._slide_hide)
self.slide_animation.setEasingCurve(QEasingCurve.InOutQuad)
self._max_width = 300

def _slide_hide(self, state):
size = self.sizeHint()
if state == self.slide_animation.Stopped:
if self.arrow_handle.current_arrow == self.arrow_handle.OUT:
self._d_widget.hide()
elif self.slide_animation.Running:
if self.arrow_handle.current_arrow == self.arrow_handle.IN:
self._d_widget.show()


def slide(self, state):
self.slide_animation.setEndValue(QSize(self.arrow_handle.width()*2, self.height()))

Expand All @@ -430,11 +430,14 @@ def slide(self, state):
self.slide_animation.start()

def showEvent(self, event):
return super().showEvent(event)
super().showEvent(event)
if not app_constants.SHOW_SIDEBAR_WIDGET:
self.arrow_handle.click()

def _init_size(self, event=None):
h = event.size().height() if event else self.parent_widget.height()
h = self.parent_widget.height()
self._max_width = self.parent_widget.width()*0.2
self.updateGeometry()
self.setMaximumWidth(self._max_width)
self.slide_animation.setStartValue(QSize(self._max_width, h))

Expand Down
19 changes: 11 additions & 8 deletions version/pewnet.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#"""
#"""
#This file is part of Happypanda.
#Happypanda is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -129,7 +129,10 @@ def _downloading(self):
r = self._browser_session.get(download_url, stream=True)
else:
r = requests.get(download_url, stream=True)
item.total_size = int(r.headers['content-length'])
try:
item.total_size = int(r.headers['content-length'])
except KeyError:
item.total_size = 0

with open(file_name_part, 'wb') as f:
for data in r.iter_content(chunk_size=1024):
Expand Down Expand Up @@ -426,9 +429,8 @@ def from_gallery_url(self, g_url):
"""
Finds gallery download url and puts it in download queue
"""
if 'ipb_member_id' in self._browser.session.cookies and \
'ipb_pass_hash' in self._browser.session.cookies:
hen = ExHen(self._browser.session.cookies)
if 'exhentai' in g_url:
hen = ExHen(settings.ExProperties().cookies)
else:
hen = EHen()
log_d("Using {}".format(hen.__repr__()))
Expand Down Expand Up @@ -689,7 +691,8 @@ def search(self, search_string, cookies = None):

class EHen(CommenHen):
"Fetches galleries from ehen"
def __init__(self):
def __init__(self, cookies = None):
self.cookies = cookies
self.e_url = "http://g.e-hentai.org/api.php"

@classmethod
Expand Down Expand Up @@ -1003,8 +1006,8 @@ def no_hits_found_check(html):

class ExHen(EHen):
"Fetches gallery metadata from exhen"
def __init__(self, cookies):
self.cookies = cookies
def __init__(self, cookies=None):
super().__init__(cookies)
self.e_url = "http://exhentai.org/api.php"

def get_metadata(self, list_of_urls):
Expand Down
10 changes: 7 additions & 3 deletions version/settingsdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def restore_options(self):
self._find_combobox_match(self.g_type, app_constants.G_DEF_TYPE, 0)
self.g_status.addItems(app_constants.G_STATUS)
self._find_combobox_match(self.g_status, app_constants.G_DEF_STATUS, 0)
self.sidebar_widget_hidden.setChecked(app_constants.SHOW_SIDEBAR_WIDGET)
self.send_2_trash.setChecked(app_constants.SEND_FILES_TO_TRASH)
self.subfolder_as_chapters.setChecked(app_constants.SUBFOLDER_AS_GALLERY)
self.extract_gallery_before_opening.setChecked(app_constants.EXTRACT_CHAPTER_BEFORE_OPENING)
Expand Down Expand Up @@ -251,6 +252,8 @@ def accept(self):
set = settings.set

# App / General
app_constants.SHOW_SIDEBAR_WIDGET = self.sidebar_widget_hidden.isChecked()
set(app_constants.SHOW_SIDEBAR_WIDGET, 'Application', 'show sidebar widget')
app_constants.SEND_FILES_TO_TRASH = self.send_2_trash.isChecked()
set(app_constants.SEND_FILES_TO_TRASH, 'Application', 'send files to trash')

Expand All @@ -262,7 +265,6 @@ def accept(self):
g_custom_lang.append(l)

app_constants.G_CUSTOM_LANGUAGES = g_custom_lang
print(g_custom_lang)
set(app_constants.G_CUSTOM_LANGUAGES, 'General', 'gallery custom languages')
if self.g_languages.currentText():
app_constants.G_DEF_LANGUAGE = self.g_languages.currentText()
Expand Down Expand Up @@ -546,6 +548,8 @@ def new_tab(name, parent, scroll=False):
application_general, app_general_m_l = new_tab('General', application, True)

# App / General
self.sidebar_widget_hidden = QCheckBox("Show sidebar widget on startup")
app_general_m_l.addRow(self.sidebar_widget_hidden)
self.send_2_trash = QCheckBox("Send deleted files to recycle bin", self)
self.send_2_trash.setToolTip("When unchecked, files will get deleted permanently and be unrecoverable!")
app_general_m_l.addRow(self.send_2_trash)
Expand Down Expand Up @@ -615,8 +619,8 @@ def new_tab(name, parent, scroll=False):
self.subfolder_as_chapters = QCheckBox("Subdirectiories should be treated as standalone galleries instead of chapters (applies in archives too)")
self.subfolder_as_chapters.setToolTip("This option will enable creating standalone galleries for each subdirectiories found recursively when importing."+
"\nDefault action is treating each subfolder found as chapters of a gallery.")
extract_gallery_info = QLabel("Note: This option has no effect when turned off if path to viewer is not specified.")
self.extract_gallery_before_opening = QCheckBox("Extract archive before opening (only turn off if your viewer supports it)")
extract_gallery_info = QLabel("Note: This option has no effect when turned off if path to external viewer is not specified.")
self.extract_gallery_before_opening = QCheckBox("Extract archive before opening (Uncheck only if your viewer supports it)")
self.open_galleries_sequentially = QCheckBox("Open chapters sequentially (Note: has no effect if path to viewer is not specified)")
subf_info = QLabel("Behaviour of 'Scan for new galleries on startup' option will be affected.")
subf_info.setWordWrap(True)
Expand Down
6 changes: 3 additions & 3 deletions version/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#"""
#"""
#This file is part of Happypanda.
#Happypanda is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -591,10 +591,10 @@ def find_f_img_archive(extract=True):
else:
zip.extract_all(t_p) # Compatibility reasons.. TODO: REMOVE IN BETA
if app_constants.USE_EXTERNAL_VIEWER:
filepath = os.path.join(t_p, [x for x in sorted([y.name for y in scandir.scandir(t_p)])\
if x.lower().endswith(IMG_FILES)][0]) # Find first page
filepath = t_p
else:
filepath = os.path.join(t_p, [x for x in sorted([y.name for y in scandir.scandir(t_p)])\
if x.lower().endswith(IMG_FILES)][0]) # Find first page
filepath = os.path.abspath(filepath)
else:
if is_archive or chapterpath.endswith(ARCHIVE_FILES):
Expand Down

0 comments on commit 0029db4

Please sign in to comment.