Compare commits

..

No commits in common. "b2368b9053dd954bb473206aa2a44786753a0c2b" and "31e91d16bfab4f90980e1a77da6671a44312e631" have entirely different histories.

7 changed files with 54 additions and 110 deletions

View file

@ -35,8 +35,6 @@ def selectFolder(data):
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()
@ -55,8 +53,6 @@ def selectFile(data):
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()

View file

@ -129,11 +129,9 @@ def get_icons_db_path():
import settings
import shutil
library = os.path.expanduser(settings.preferences['libraryPath'])
metadata = os.path.join(library, 'Metadata')
icons_db_path = os.path.join(metadata, 'icons.db')
if os.path.exists(os.path.dirname(library)):
metadata = os.path.join(os.path.expanduser(settings.preferences['libraryPath']), 'Metadata')
ox.makedirs(metadata)
icons_db_path = os.path.join(metadata, 'icons.db')
old_icons_db_path = os.path.join(settings.data_path, 'icons.db')
if not os.path.exists(icons_db_path) and os.path.exists(old_icons_db_path):
shutil.move(old_icons_db_path, icons_db_path)

View file

@ -1,32 +1,24 @@
# encoding: utf-8
# vi:si:et:sw=4:sts=4:ts=4
import sys
import os
try:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GObject
GObject.threads_init()
use_Gtk = True
except:
from tkinter import Tk, PhotoImage
from tkinter import Tk
import tkinter.filedialog
use_Gtk = False
DEBUG = False
def short_home(path):
home = os.path.expanduser('~')
if path and path.startswith(home):
path = path.replace(home, '~')
return path
class GtkUI:
def selectFolder(self, data):
dialog = Gtk.FileChooserDialog(title=data.get("title", "Select Folder"),
action=Gtk.FileChooserAction.SELECT_FOLDER)
dialog.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OPEN, Gtk.ResponseType.OK)
dialog = Gtk.FileChooserDialog(data.get("title", "Select Folder"),
None,
Gtk.FileChooserAction.SELECT_FOLDER,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
dialog.set_default_response(Gtk.ResponseType.OK)
response = dialog.run()
@ -43,13 +35,14 @@ class GtkUI:
Gtk.main_iteration()
if DEBUG:
print("done")
return short_home(filename)
return filename
def selectFile(self, data):
dialog = Gtk.FileChooserDialog(title=data.get("title", "Select File"),
action=Gtk.FileChooserAction.OPEN)
dialog.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OPEN, Gtk.ResponseType.OK)
dialog = Gtk.FileChooserDialog(data.get("title", "Select File"),
None,
Gtk.FileChooserAction.OPEN,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
dialog.set_default_response(Gtk.ResponseType.OK)
response = dialog.run()
@ -66,30 +59,23 @@ class GtkUI:
Gtk.main_iteration()
if DEBUG:
print("done")
return short_home(filename)
return filename
class TkUI:
def __init__(self):
self.root = Tk(className="Open Media Library")
png = os.path.join(os.path.dirname(os.path.abspath('__file__')), 'static', 'png', 'oml.png')
icon = PhotoImage(file=png)
self.root.tk.call('wm', 'iconphoto', self.root._w, icon)
self.root.withdraw() # hiding tkinter window
self.root = Tk()
if sys.platform == 'darwin':
self.root.lift()
self.root.call('wm', 'attributes', '.', '-topmost', True)
self.root.update()
self.root.after_idle(self.root.call, 'wm', 'attributes', '.', '-topmost', False)
self.root.withdraw() # hiding tkinter window
def selectFolder(self, data):
folder = tkinter.filedialog.askdirectory(parent=self.root, title=data.get("title", "Select Folder"))
return short_home(folder)
return tkinter.filedialog.askdirectory(title=data.get("title", "Select Folder"))
def selectFile(self, data):
filename = tkinter.filedialog.askopenfilename(parent=self.root, title=data.get("title", "Select File"))
return short_home(filename)
return tkinter.filedialog.askopenfilename(title=data.get("title", "Select File"))
if use_Gtk:
ui = GtkUI()
@ -97,12 +83,8 @@ else:
ui = TkUI()
if __name__ == '__main__':
base = '~'
if len(sys.argv) >= 3:
base = sys.argv[2]
base = os.path.expanduser(base)
os.chdir(base)
if len(sys.argv) >= 2 and sys.argv[1] == 'folder':
import sys
if len(sys.argv) == 2 and sys.argv[1] == 'folder':
print(ui.selectFolder({}))
else:
print(ui.selectFile({}))

View file

@ -217,7 +217,14 @@ oml.ui.importExportDialog = function() {
var $element = Ox.Element(),
$form = Ox.Form({
items: selected == 'import' ? [
oml.ui.selectFolder({
Ox.Input({
autocomplete: function(value, callback) {
oml.api.autocompleteFolder({path: value}, function(result) {
callback(result.data.items);
});
},
autocompleteSelect: true,
changeOnKeypress: true,
id: 'path',
label: 'Source Path',
labelWidth: 128,
@ -249,7 +256,14 @@ oml.ui.importExportDialog = function() {
width: 480
})
] : [
oml.ui.selectFolder({
Ox.Input({
autocomplete: function(value, callback) {
oml.api.autocompleteFolder({path: value}, function(result) {
callback(result.data.items);
});
},
autocompleteSelect: true,
changeOnKeypress: true,
id: 'path',
label: 'Destination Path',
labelWidth: 128,
@ -282,7 +296,6 @@ oml.ui.importExportDialog = function() {
.bindEvent({
change: function(data) {
var values = $form.values();
console.log(values)
$activityButton[selected].options({
disabled: !values.path
});

View file

@ -25,14 +25,24 @@ oml.ui.preferencesPanel = function() {
{
id: 'libraryPath',
title: 'Library Path',
type: 'selectfolder',
autocomplete: function(value, callback) {
oml.api.autocompleteFolder({path: value}, function(result) {
callback(result.data.items);
});
},
autocompleteSelect: true,
value: preferences.libraryPath,
help: 'The directory in which your "Books" folder is located. This is where your media files are stored. It can be on your local machine, but just as well on an external drive or networked volume.'
},
{
id: 'importPath',
title: 'Import Path',
type: 'selectfolder',
autocomplete: function(value, callback) {
oml.api.autocompleteFolder({path: value}, function(result) {
callback(result.data.items);
});
},
autocompleteSelect: true,
value: preferences.importPath,
help: 'Any media files that you put in this folder will be added to your library. Once added, they will be removed from this folder.'
}
@ -337,15 +347,6 @@ oml.ui.preferencesPanel = function() {
value: item.value,
width: 384
})
: item.type == 'selectfolder'
? oml.ui.selectFolder({
label: Ox._(item.title),
labelWidth: 128,
placeholder: item.placeholder || '',
style: 'squared',
title: oml.user.preferences[item.id] || item.value || '',
width: 384 - !!item.unit * 48
})
: Ox.Input({
autocomplete: item.autocomplete || null,
autocompleteSelect: item.autocompleteSelect || false,
@ -356,6 +357,7 @@ oml.ui.preferencesPanel = function() {
value: oml.user.preferences[item.id] || item.value || '',
width: 384 - !!item.unit * 48
})
].concat(item.unit ? [
Ox.Label({
overlap: 'left',

View file

@ -1,46 +0,0 @@
'use strict';
oml.ui.selectFolder = function(options, self) {
options.width = options.width - options.labelWidth
options = Ox.extend({
title: '...',
textAlign: 'left'
}, options);
var $button = Ox.Button(options, self).bindEvent({
click: function(event) {
oml.api.selectFolder({
base: $button.value()
}, function(result) {
if (result.data.path) {
$button.value(result.data.path);
$button.options({
title: result.data.path
});
$button.triggerEvent('change', result.data.path);
}
})
}
}),
that = Ox.FormElementGroup({
id: options.id,
elements: [
Ox.Label({
style: options.style,
textAlign: 'right',
overlap: 'right',
title: options.label,
width: options.labelWidth
}),
$button
],
}, self);
that.value = function() {
return $button.value()
}
if (options.title && options.title != '...') {
$button.value(options.title)
}
return that;
}

View file

@ -58,7 +58,6 @@
"rightPanel.js",
"sectionButtons.js",
"sectionbar.js",
"selectFolder.js",
"sortElement.js",
"statusIcon.js",
"statusbar.js",