Skip to content

Commit

Permalink
added UI_FONT config.py variable
Browse files Browse the repository at this point in the history
fixed foreground open command issue
  • Loading branch information
GChristensen committed Jun 17, 2024
1 parent 3d69305 commit 6d54b2f
Show file tree
Hide file tree
Showing 23 changed files with 123 additions and 20 deletions.
16 changes: 11 additions & 5 deletions enso/commands/open.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@

shortcuts_map = Shortcuts.get().get_shortcuts()

def displayMessage(msg):

def displayMessage(msg, foreground = False):
import enso.messages
enso.messages.displayMessage("<p>%s</p>" % msg)
enso.messages.displayMessage("<p>%s</p>" % msg, foreground)


def expand_path_variables(file_path):
re_env = re.compile(r'%\w+%')
Expand All @@ -27,14 +29,14 @@ def expander(mo):
def cmd_open(ensoapi, target):
""" Continue typing to open an application or document """

displayMessage("Opening <command>%s</command>..." % target)

try:
global shortcuts_map
shortcut_type, shortuct_id, file_path = shortcuts_map[target]
file_path = os.path.normpath(expand_path_variables(file_path))
logging.info("Executing '%s'" % file_path)

displayMessage("Opening <command>%s</command>..." % target, foreground=True)

if shortcut_type == SHORTCUT_TYPE_CONTROL_PANEL:
if " " in file_path:
executable = file_path[0:file_path.index(' ')]
Expand Down Expand Up @@ -87,7 +89,7 @@ def cmd_open_with(ensoapi, application):
ensoapi.display_message("No file or folder is selected")
return

displayMessage("Opening <command>%s</command>..." % application)
displayMessage("Opening <command>%s</command>..." % application, foreground=True)

#print file, application
global shortcuts_map
Expand All @@ -108,6 +110,7 @@ def cmd_open_with(ensoapi, application):
except Exception as e:
logging.error(e)


cmd_open_with.valid_args = [s[1] for s in list(shortcuts_map.values()) if s[0] == SHORTCUT_TYPE_EXECUTABLE]


Expand Down Expand Up @@ -222,8 +225,11 @@ def cmd_undo_unlearn(ensoapi):
else:
ensoapi.display_message("There is nothing to undo")


if __name__ == "__main__":
import doctest
doctest.testmod()



# vim:set ff=unix tabstop=4 shiftwidth=4 expandtab:
3 changes: 0 additions & 3 deletions enso/enso/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
# Only changes in commands entered through WebUI are tracked by default
TRACK_COMMAND_CHANGES = False

# Enable commands for common Windows utilities, such as regedit, services, etc.4
ENABLE_WINUTILS = False

# Web UI can be disabled as a security option
ENABLE_WEB_UI = True
# Enable CSRF protection
Expand Down
3 changes: 3 additions & 0 deletions enso/enso/graphics/transparentwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,6 @@ def getMaxWidth( self ):
def getMaxHeight( self ):
return pixelsToPoints( self._impl.getMaxHeight() )

def setForeground(self):
if hasattr(self._impl, 'setForeground'):
return self._impl.setForeground()
11 changes: 9 additions & 2 deletions enso/enso/messages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ def __init__( self,
primaryXml = None,
miniXml = None,
isPrimary = False,
isMini = False ):
isMini = False,
isForeground = False):
"""
Initializes the message object. Subclasses should be careful
to call this if they override the constructor.
Expand All @@ -199,10 +200,12 @@ def __init__( self,

self.__isPrimary = isPrimary
self.__isMini = isMini
self.__isForeground = isForeground

self.__fullXml = fullXml
self.__primaryXml = primaryXml
self.__miniXml = miniXml



def isPrimary( self ):
Expand All @@ -222,6 +225,9 @@ def isMini( self ):

return self.__isMini

def isForeground(self):
return self.__isForeground

def getFullXml( self ):
"""
Retrieves the full XML of the entire contents of this
Expand Down Expand Up @@ -418,7 +424,7 @@ def finishMessages( self ):
# Convenience functions
# ----------------------------------------------------------------------------

def displayMessage( msgXml ):
def displayMessage( msgXml, foreground = False ):
"""
Displays a simple primary message that has no mini message.
"""
Expand All @@ -427,6 +433,7 @@ def displayMessage( msgXml ):
isPrimary = True,
isMini = False,
fullXml = msgXml,
isForeground=foreground
)

MessageManager.get().newMessage( msg )
Expand Down
6 changes: 3 additions & 3 deletions enso/enso/messages/primarywindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def setMessage( self, message ):

# Set the current primary message, and draw it.
self.__msg = message
self.__drawMessage()
self.__drawMessage(message.isForeground())

# Now, set a time-responder to wait for a bit, so that the
# user doesn't accidentally clear the message before it registers
Expand Down Expand Up @@ -240,7 +240,7 @@ def __interrupt( self ):
if self.__waiting:
self.__evtManager.removeResponder( self.waitTick )

def __drawMessage( self ):
def __drawMessage( self, foreground = False ):
"""
Draws the current message to the underlying Cario context.
"""
Expand Down Expand Up @@ -272,7 +272,7 @@ def __drawMessage( self ):
# Set the window opacity (which can be left at 0 by the animation)
self._wind.setOpacity( 255 )
# Show and update the window.
self.show()
self.show(foreground)


def __isOneLineMsg( self, msgDoc, capDoc ):
Expand Down
7 changes: 6 additions & 1 deletion enso/enso/messages/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def hide( self ):
self._wind.update()


def show( self ):
def show( self, foreground = False ):
"""
Sets the underlying TransparentWindow's size to the stored
"current size" variable, essentially re-correlating the actual
Expand All @@ -154,6 +154,11 @@ def show( self ):
self.setSize( *self.getSize() )
self._wind.update()

# this to fix the bug in the 'open' command, when for some reason
# the message window is not foreground
if foreground:
self._wind.setForeground()


def clearWindow( self ):
"""
Expand Down
Binary file modified enso/enso/platform/win32/AsyncEventProcessorRegistry.dll
Binary file not shown.
Binary file modified enso/enso/platform/win32/CLogging.dll
Binary file not shown.
Binary file modified enso/enso/platform/win32/Keyhook.dll
Binary file not shown.
Binary file modified enso/enso/platform/win32/cairo/_cairo.pyd
Binary file not shown.
10 changes: 10 additions & 0 deletions enso/enso/platform/win32/graphics/TransparentWindow.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 4.0.2
#
# !!! This file is edited
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.
from .utils import setForegroundWindow

# Import the low-level C/C++ module
if __package__ or "." in __name__:
Expand Down Expand Up @@ -137,6 +140,13 @@ def getMaxHeight(self):
def makeCairoSurface(self):
return _TransparentWindow.TransparentWindow_makeCairoSurface(self)

def getHandle(self):
return _TransparentWindow.TransparentWindow_getHandle(self)

def setForeground(self):
handle = self.getHandle()
setForegroundWindow(handle)

# Register TransparentWindow in _TransparentWindow:
_TransparentWindow.TransparentWindow_swigregister(TransparentWindow)

Expand Down
Binary file modified enso/enso/platform/win32/graphics/_TransparentWindow.pyd
Binary file not shown.
57 changes: 57 additions & 0 deletions enso/enso/platform/win32/graphics/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import time

import win32con
import win32api
import win32gui
import win32process

from test.test_ctypes import ctypes


def setForegroundWindow(hwnd):
try:
dwCurrentThread = win32api.GetCurrentThreadId()
dwFGWindow = win32gui.GetForegroundWindow()
[dwFGThread, _] = win32process.GetWindowThreadProcessId(dwFGWindow)
ctypes.windll.user32.AttachThreadInput(dwCurrentThread, dwFGThread, 1)

try:
if win32gui.IsIconic(hwnd):
win32gui.ShowWindow(hwnd, win32con.SW_RESTORE)

win32gui.SetWindowPos(hwnd, win32con.HWND_NOTOPMOST, 0, 0, 0, 0, win32con.SWP_NOMOVE + win32con.SWP_NOSIZE)
win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, 0, 0, 0, 0, win32con.SWP_NOMOVE + win32con.SWP_NOSIZE)
win32gui.SetWindowPos(hwnd, win32con.HWND_NOTOPMOST, 0, 0, 0, 0, win32con.SWP_SHOWWINDOW + win32con.SWP_NOMOVE + win32con.SWP_NOSIZE)

try:
win32gui.SetForegroundWindow(hwnd)
except Exception as e:
print(e)

try:
win32gui.SetFocus(hwnd)
except Exception as e:
print(e)

try:
win32gui.SetActiveWindow(hwnd)
except Exception as e:
print(e)

finally:
ctypes.windll.user32.AttachThreadInput(dwCurrentThread, dwFGThread, 0)

except Exception as e:
print(e)
if e[0] == 0:
time.sleep(0.2)
try:
win32gui.SetForegroundWindow(hwnd)
except Exception as e:
time.sleep(0.2)
try:
win32gui.BringWindowToTop(hwnd)
except Exception as e:
pass
elif e[0] == 2:
pass
Binary file modified enso/enso/platform/win32/input/_AsyncEventThread.pyd
Binary file not shown.
Binary file modified enso/enso/platform/win32/input/_InputManager.pyd
Binary file not shown.
Binary file modified enso/enso/platform/win32/selection/_ClipboardBackend.pyd
Binary file not shown.
2 changes: 1 addition & 1 deletion enso/enso/strings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Enso version for use in UI
ENSO_VERSION = "1.1.1"
ENSO_VERSION = "1.1.2"

# The message displayed when the user types some text that is not a command.
BAD_COMMAND_MSG = "<p><command>%s</command> is not a command.</p>" \
Expand Down
4 changes: 2 additions & 2 deletions enso/enso/user/mediaprobe.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ def directory_probe(category, directory, player="", additional=None):
"""Sends directory entries found in the 'directory' to 'player',
makes command arguments from the directory entries."""

dictionary = collect_descendants(directory)
dictionary = collect_descendants(directory) or {}

if dictionary and additional:
if additional:
dictionary.update(additional)

return dictionary_probe(category, dictionary, player, directory)
Expand Down
2 changes: 1 addition & 1 deletion enso/enso/webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
def requires_auth(f):
@wraps(f)
def decorated(*args, **kwargs):
if config.ENABLE_WEB_UI_CSRF and not request.authorization or request.authorization["password"] != AUTH_TOKEN:
if config.ENABLE_WEB_UI_CSRF and (not request.authorization or request.authorization["password"] != AUTH_TOKEN):
return abort(401)
return f(*args, **kwargs)
return decorated
Expand Down
15 changes: 14 additions & 1 deletion enso/enso/webui/tutorial.html
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ <h2><a id="user-content-prolonged-execution" class="anchor" aria-hidden="true" h
t <span class="pl-k">=</span> threading.Thread(<span class="pl-v">target</span> <span class="pl-k">=</span> do_something)
t.start()
ensoapi.display_message(<span class="pl-s"><span class="pl-pds">"</span>Please wait...<span class="pl-pds">"</span></span>)
<span class="pl-k">while</span> t.isAlive():
<span class="pl-k">while</span> t.is_alive():
<span class="pl-k">yield</span>
ensoapi.display_message(<span class="pl-s"><span class="pl-pds">"</span>Done!<span class="pl-pds">"</span></span>)</pre></div>
<p>Returning control back to Enso is highly encouraged - without it, your
Expand Down Expand Up @@ -228,6 +228,19 @@ <h2><a id="user-content-command-updating" class="anchor" aria-hidden="true" href
with the command execution call itself, <code>on_quasimode_start()</code> may
use <code>yield</code> to relegate control back to Enso when it knows that some
operation will take a while to finish.</p>

<pre>
from enso.messages import displayMessage

def cmd_test(ensoapi):
ensoapi.display_message("demo")

def my_func():
displayMessage("&lt;p&gt;On quasimode start&lt;/p&gt;")

cmd_test.on_quasimode_start = my_func
</pre>

<h2><a id="user-content-including-other-files" class="anchor" aria-hidden="true" href="#including-other-files"></a>Including Other Files</h2>
<p>It is possible to install or uninstall Python libraries from <a href="https://pypi.org/">PyPi</a>
using 'enso install' and 'enso uninstall' commands respectively.<br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -649,3 +649,6 @@ _getDesktopOffset( int *left,
*top = rectWorkArea.top;
}

int TransparentWindow::getHandle() {
return (int)_window;
}
2 changes: 2 additions & 0 deletions platform/win32/Graphics/TransparentWindow/TransparentWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ class TransparentWindow
int
getMaxHeight( void );

int getHandle();

#ifndef SWIG
private:

Expand Down
2 changes: 1 addition & 1 deletion setup.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Unicode True

!define DIRNAME "Enso Launcher"
!define APPNAME "Enso Open-Source"
!define VERSION "1.1.1"
!define VERSION "1.1.2"

!include LogicLib.nsh

Expand Down

0 comments on commit 6d54b2f

Please sign in to comment.