Skip to content

Commit

Permalink
Changes fo python3 for FavouritesMenu.
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmXinu committed Dec 19, 2019
1 parent 874c9eb commit e501eff
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion FavouritesMenu/__init__.py
Expand Up @@ -14,7 +14,7 @@ class ActionFavouritesMenu(InterfaceActionBase):
description = 'Create a customised toolbar menu button for features from other plugins or calibre menus to save screen space'
supported_platforms = ['windows', 'osx', 'linux']
author = 'Grant Drake'
version = (1, 0, 4)
version = (1, 0, 5)
minimum_calibre_version = (0, 8, 18)

actual_plugin = 'calibre_plugins.favourites_menu.action:FavouritesMenuAction'
Expand Down
2 changes: 2 additions & 0 deletions FavouritesMenu/action.py
Expand Up @@ -8,6 +8,8 @@
__docformat__ = 'restructuredtext en'

import weakref
from six import text_type as unicode

try:
from PyQt5.Qt import (QToolButton, QMenu, QAction)
except ImportError as e:
Expand Down
10 changes: 6 additions & 4 deletions FavouritesMenu/common_utils.py
Expand Up @@ -8,6 +8,8 @@
__docformat__ = 'restructuredtext en'

import os
import six
from six import text_type as unicode

try:
from PyQt5 import QtWidgets as QtGui
Expand Down Expand Up @@ -429,15 +431,15 @@ def __init__(self, parent, values, selected_key):
def populate_combo(self, selected_key):
self.clear()
selected_idx = idx = -1
for key, value in self.values.iteritems():
for key, value in six.iteritems(self.values):
idx = idx + 1
self.addItem(value)
if key == selected_key:
selected_idx = idx
self.setCurrentIndex(selected_idx)

def selected_key(self):
for key, value in self.values.iteritems():
for key, value in six.iteritems(self.values):
if value == unicode(self.currentText()).strip():
return key

Expand Down Expand Up @@ -665,7 +667,7 @@ def _init_controls(self):
def _populate_settings(self):
self.keys_list.clear()
ns_prefix = self._get_ns_prefix()
keys = sorted([k[len(ns_prefix):] for k in self.db.prefs.iterkeys()
keys = sorted([k[len(ns_prefix):] for k in six.iterkeys(self.db.prefs)
if k.startswith(ns_prefix)])
for key in keys:
self.keys_list.addItem(key)
Expand Down Expand Up @@ -713,7 +715,7 @@ def _clear_settings(self):
return

ns_prefix = self._get_ns_prefix()
keys = [k for k in self.db.prefs.iterkeys() if k.startswith(ns_prefix)]
keys = [k for k in six.iterkeys(self.db.prefs) if k.startswith(ns_prefix)]
for k in keys:
del self.db.prefs[k]
self._populate_settings()
Expand Down
16 changes: 10 additions & 6 deletions FavouritesMenu/config.py
Expand Up @@ -7,6 +7,10 @@
__copyright__ = '2011, Grant Drake <grant.drake@gmail.com>'
__docformat__ = 'restructuredtext en'

import six
from six import text_type as unicode
from six.moves import range

try:
from PyQt5.Qt import (QWidget, QHBoxLayout, QMenu, QTreeWidget, Qt, QIcon,
QTreeWidgetItem, QListWidget, QListWidgetItem, QSize,
Expand Down Expand Up @@ -107,7 +111,7 @@ def populate_list_item(self, fav_menu, idx= -1):

def remove_matching_item(self, remove_fav_menu):
paths_text = '/'.join(remove_fav_menu['path'])
for row in xrange(self.count()):
for row in range(self.count()):
lw = self.item(row)
data = convert_qvariant(lw.data(Qt.UserRole))
if data is not None:
Expand All @@ -118,7 +122,7 @@ def remove_matching_item(self, remove_fav_menu):

def get_fav_menus(self):
fav_menus = []
for row in xrange(self.count()):
for row in range(self.count()):
lw = self.item(row)
data = convert_qvariant(lw.data(Qt.UserRole))
if data is None:
Expand Down Expand Up @@ -233,7 +237,7 @@ def _add_separator(self):
def _remove_item(self):

def find_child(twi, paths):
for i in xrange(0, twi.childCount()):
for i in range(0, twi.childCount()):
c = twi.child(i)
text = unicode(c.text(0))
if text == paths[0]:
Expand Down Expand Up @@ -319,11 +323,11 @@ def _populate_actions_tree(self, lookup_menu_map):
# Lets re-sort the keys so that items will appear on screen sorted
# by their display name (not by their key)
skeys_map = {}
for plugin_name, iaction in self.gui.iactions.iteritems():
for plugin_name, iaction in six.iteritems(self.gui.iactions):
if plugin_name == self.plugin_action.name:
continue
if 'toolbar' in iaction.dont_add_to and 'toolbar-device' in iaction.dont_add_to:
print('Not adding:', plugin_name)
print(('Not adding:', plugin_name))
continue
display_name = unicode(iaction.qaction.text())
if plugin_name == 'Choose Library':
Expand Down Expand Up @@ -402,7 +406,7 @@ def _populate_action_children(self, children, parent, possible_menus, paths,

def _is_in_menu(self, possible_menus, paths=[]):
path_text = '|'.join(paths)
for x in xrange(0, len(possible_menus)):
for x in range(0, len(possible_menus)):
fav_menu = possible_menus[x]
if fav_menu['paths_text'] == path_text:
del possible_menus[x]
Expand Down

0 comments on commit e501eff

Please sign in to comment.