fix windows select folder

This commit is contained in:
j 2019-01-31 19:11:13 +05:30
parent 0062191db4
commit ca35c413fe
4 changed files with 43 additions and 31 deletions

View file

@ -3,11 +3,12 @@
import os
import sys
from os.path import normpath, dirname, abspath, join
import site
base = normpath(dirname(dirname(dirname(abspath(__file__)))))
if sys.platform == 'win32':
from os.path import normpath, dirname, abspath, join
import site
base = normpath(dirname(dirname(dirname(abspath(__file__)))))
for site_packages in (
join(base, 'openmedialibrary'),
join(base, 'platform', 'Shared', 'lib', 'python3.4', 'site-packages'),
@ -20,6 +21,7 @@ if sys.platform == 'win32':
unrar_dll = join(base, 'platform_win32', 'unrar.dll')
if os.path.exists(unrar_dll):
os.environ['UNRAR_LIB_PATH'] = unrar_dll
os.environ['TCL_LIBRARY'] = join(base, 'platform_win32', 'tcl', 'tcl8.6')
import api
import commands
@ -27,6 +29,9 @@ import server
if len(sys.argv) > 1 and sys.argv[1] == 'server':
server.run()
if len(sys.argv) > 1 and sys.argv[1] == 'ui':
import ui
ui.main(sys.argv[2:])
else:
commands.main()
if sys.platform == 'win32':

View file

@ -13,6 +13,7 @@ from oxtornado import actions
import item.api
import user.api
import update
import utils
import logging
logger = logging.getLogger(__name__)
@ -20,8 +21,8 @@ logger = logging.getLogger(__name__)
def win32_ui(type):
base = normpath(dirname(dirname(dirname(abspath(__file__)))))
cmd = [
join(base, 'platform_win32', 'python.exe'),
join(base, 'openmediablirary', 'oml', 'ui.py'), type
join('..', 'platform_win32', 'pythonw.exe'),
join('oml', 'ui.py'), type
]
return cmd
@ -31,14 +32,7 @@ def selectFolder(data):
path
}
'''
cmd = ['./ctl', 'ui', 'folder']
if sys.platform == 'win32':
cmd = win32_ui('folder')
if 'base' in data:
cmd += [data['base']]
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, close_fds=True)
stdout, stderr = p.communicate()
path = stdout.decode('utf-8').strip()
path = utils.ctl_output('ui', 'folder')
if path == 'None':
path = None
return {
@ -53,14 +47,7 @@ def selectFile(data):
path
}
'''
cmd = ['./ctl', 'ui', 'file']
if sys.platform == 'win32':
cmd = win32_ui('file')
if 'base' in data:
cmd += [data['base']]
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
stdout, stderr = p.communicate()
path = stdout.decode('utf-8').strip()
path = utils.ctl_output('ui', 'file')
if path == 'None':
path = None
return {

View file

@ -93,6 +93,17 @@ class TkUI:
filename = tkinter.filedialog.askopenfilename(parent=self.root, title=data.get("title", "Select File"))
return short_home(filename)
def main(args):
base = '~'
if len(args) >= 2:
base = args[1]
base = os.path.expanduser(base)
if os.path.exists(base):
os.chdir(base)
if args and args[0] == 'folder':
print(ui.selectFolder({}))
else:
print(ui.selectFile({}))
if use_Gtk:
ui = GtkUI()
@ -100,13 +111,4 @@ else:
ui = TkUI()
if __name__ == '__main__':
base = '~'
if len(sys.argv) >= 3:
base = sys.argv[2]
base = os.path.expanduser(base)
if os.path.exists(base):
os.chdir(base)
if len(sys.argv) >= 2 and sys.argv[1] == 'folder':
print(ui.selectFolder({}))
else:
print(ui.selectFile({}))
main(sys.argv[1:])

View file

@ -409,6 +409,24 @@ def ctl(*args):
subprocess.Popen([os.path.join(settings.base_dir, 'ctl')] + list(args),
close_fds=True, start_new_session=True)
def ctl_output(*args):
import settings
if sys.platform == 'win32':
platform_win32 = os.path.join('..', 'platform_win32')
python = os.path.join(platform_win32, 'python.exe')
cmd = [python, 'oml'] + list(args)
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = subprocess.SW_HIDE
p = subprocess.Popen(cmd, cwd=settings.base_dir, startupinfo=startupinfo,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
else:
p = subprocess.Popen([os.path.join(settings.base_dir, 'ctl')] + list(args),
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
logger.debug('ctl_output%s -> %s [%s]', args, stdout, stderr)
return stdout.decode('utf-8').strip()
def user_sort_key(u):
return ox.sort_string(str(u.get('index', '')) + 'Z' + (u.get('name') or ''))