Skip to content

Commit

Permalink
v2.3.4
Browse files Browse the repository at this point in the history
Backlog
  • Loading branch information
ccz-2 committed Mar 10, 2020
1 parent a5cb33f commit 0fbe6bc
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 18 deletions.
Binary file modified NDFS.ankiaddon
Binary file not shown.
22 changes: 14 additions & 8 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# No Distractions Full Screen
# v2.3.3 2/10/2020
# v2.3.4 2/10/2020
# Copyright (c) 2020 Quip13 ([email protected])
#
# MIT License
Expand Down Expand Up @@ -28,7 +28,7 @@
from aqt import *
from aqt.reviewer import Reviewer
from anki.hooks import *

from anki.utils import isMac, isWin
#read files
reformat = open(os.path.join(os.path.dirname(__file__), 'NDFullScreen.js')).read()
hide_cursor = open(os.path.join(os.path.dirname(__file__), 'hide_cursor.js')).read()
Expand All @@ -41,6 +41,7 @@ def recheckBoxes():
cursorIdleTimer = config['cursor_idle_timer']
last_toggle = config['last_toggle']
onTop = config['stay_on_top']
shortcut = config['hotkey']

if op == 1:
mouseover_default.setChecked(True)
Expand All @@ -53,10 +54,10 @@ def recheckBoxes():
enable_cursor_hide.setChecked(True)

if last_toggle == 'windowed':
windowed.setShortcut('F11')
windowed.setShortcut(shortcut)
fullscreen.setShortcut('')
else:
fullscreen.setShortcut('F11')
fullscreen.setShortcut(shortcut)
windowed.setShortcut('')

if onTop == True:
Expand Down Expand Up @@ -107,19 +108,22 @@ def toggle():
global config
global fs_window
global og_window_flags
global og_window_state
global window_flags_set
config = mw.addonManager.getConfig(__name__)
window_flags_set = False

if not ndfs_enabled:
ndfs_enabled = True
mw.showNormal()
og_window_state = mw.windowState()
og_reviewer = Reviewer._initWeb #stores initial reviewer before wrap
og_window_flags = mw.windowFlags() #stores initial flags

Reviewer._initWeb = wrap(og_reviewer, reviewer_wrapper) #tried to use triggers instead but is called prematurely upon suspend/bury

if config['last_toggle'] == 'full_screen':
if isMac: #kicks out of OSX maximize
mw.showNormal()
mw.showFullScreen()
if config['stay_on_top'] and not mw.isFullScreen():
mw.setWindowFlags(og_window_flags | Qt.WindowStaysOnTopHint)
Expand Down Expand Up @@ -147,7 +151,7 @@ def toggle():
else:
ndfs_enabled = False
Reviewer._initWeb = og_reviewer #reassigns initial constructor
mw.showNormal()
mw.setWindowState(og_window_state)
mw.mainLayout.removeWidget(fs_window)
mw.mainLayout.addWidget(mw.toolbar.web)
mw.mainLayout.addWidget(mw.reviewer.web)
Expand Down Expand Up @@ -181,16 +185,18 @@ def stateChange(new_state, old_state, *args):
def toggle_full_screen():
config = mw.addonManager.getConfig(__name__)
config['last_toggle'] = 'full_screen'
shortcut = config['hotkey']
mw.addonManager.writeConfig(__name__, config)
fullscreen.setShortcut('F11')
fullscreen.setShortcut(shortcut)
windowed.setShortcut('')
toggle()

def toggle_window():
config = mw.addonManager.getConfig(__name__)
config['last_toggle'] = 'windowed'
shortcut = config['hotkey']
mw.addonManager.writeConfig(__name__, config)
windowed.setShortcut('F11')
windowed.setShortcut(shortcut)
fullscreen.setShortcut('')
toggle()

Expand Down
3 changes: 2 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"cursor_idle_timer": 10000,
"last_toggle": "full_screen",
"stay_on_top": false,
"answer_button_border_color": "rgba(110, 110, 110, 0.8)"
"answer_button_border_color": "rgba(110, 110, 110, 0.8)",
"hotkey": "F11"
}
18 changes: 13 additions & 5 deletions config.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
**Note: Changing settings through menu buttons will override respective values**
Unless otherwise stated, changes are effective immediately
Note: Changing settings through menu buttons will override respective values

- `answer_button_border_color`: Color of border around answer buttons
Accepts HTML color codes. For help, see: [Color Picker](https://www.hexcolortool.com/#6e6e6e,0.8)

- `answer_button_opacity`: Pre-mouse hover opacity
0 = hidden, 1 = solid. Must add leading 0 for decimals (e.g. 0.5)

- `answer_button_border_color`: Color of border around answer buttons
- Accepts HTML color codes. For help, see: [Color Picker](https://www.hexcolortool.com/#6e6e6e,0.8)
- `answer_button_opacity`: Pre-mouse hover opacity
- 0 = hidden, 1 = solid. Must add leading 0 for decimals (e.g. 0.5)
- `cursor_idle_timer`: Milliseconds to wait before hiding mouse

- `hotkey`: Keybinding that toggles fullscreen/windowed mode
Examples: `F11`, `Ctrl+F`, `Shift+D`, `P`
For more details, see: [QKeySequence](https://doc.qt.io/qtforpython/PySide2/QtGui/QKeySequence.html?highlight=qkeysequence#PySide2.QtGui.QKeySequence)
**Must restart to take effect**
29 changes: 25 additions & 4 deletions hide_cursor.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
//No Distractions Full Screen v2.3.2
//var cursorIdleTimer = 5000; //Defined in python
//No Distractions Full Screen v2.3.4
//var cursorIdleTimer = 500; //Defined in python

var cursorHidden = false;
var timer;

function hide_mouse() {
pycmd("cursor_hide");
Expand All @@ -15,25 +16,45 @@ function show_mouse() {
console.log("cursor_show");
//$('*').css({cursor: 'default'});
cursorHidden = false;
clearTimeout(timer);
}

$(function hide_cursor() {
if (cursorIdleTimer >= 0) {
var currentTime = Date.now();
var lastTime = currentTime;
var timer = setTimeout(function(){hide_mouse();}, cursorIdleTimer);
timer = setTimeout(function(){hide_mouse();}, cursorIdleTimer);

$(document).mousemove(function() {
currentTime = Date.now();
if (cursorHidden){
show_mouse();
} else if (currentTime - lastTime > 500) {
show_mouse();
clearTimeout(timer);
timer = setTimeout(function(){hide_mouse();}, cursorIdleTimer);
lastTime = currentTime;
}
//console.log("skip");
});
}
});

//Needed when adding card - not activated by hook
$(function test() {
var focused = false
setInterval(function(){ loseFocus(); }, 200);
function loseFocus() {
if (!document.hasFocus()) {
if (focused) {
show_mouse();
focused = false}
} else {
focused = true;
}
}
});

//removes timers when leaving element
$(document).mouseleave(function () {
show_mouse();
});

0 comments on commit 0fbe6bc

Please sign in to comment.