diff --git a/app/camera/buffer.py b/app/camera/buffer.py index 09657b8..f5410b8 100644 --- a/app/camera/buffer.py +++ b/app/camera/buffer.py @@ -46,7 +46,7 @@ class AppBuffer(Buffer): self.buffer_widget.camera.start() def take_photo(self): - self.buffer_widget.take_photo() + self.buffer_widget.take_photo(self.emacs_var_dict["eaf-camera-save-path"]) class CameraWidget(QWidget): @@ -83,11 +83,16 @@ class CameraWidget(QWidget): self.camera.setCaptureMode(QCamera.CaptureStillImage) self.camera.start() - def take_photo(self): - photo_path = os.path.join(str(Path.home()), "EAF_Camera_Photo_" + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(time.time())))) - + def take_photo(self, camera_save_path): image_capture = QCameraImageCapture(self.camera) - image_capture.capture(photo_path) + try: + save_path = str(Path(os.path.expanduser(camera_save_path))) + photo_path = os.path.join(save_path, "EAF_Camera_Photo_" + time.strftime("%Y-%m-%d_%H:%M:%S", time.localtime(int(time.time())))) + image_capture.capture(photo_path) + except: + save_path = str(Path(os.path.expanduser("~/Downloads"))) + photo_path = os.path.join(save_path, "EAF_Camera_Photo_" + time.strftime("%Y-%m-%d_%H:%M:%S", time.localtime(int(time.time())))) + image_capture.capture(photo_path) self.message_to_emacs.emit("Save photo at: " + photo_path) diff --git a/core/buffer.py b/core/buffer.py index 6d90637..5e419b2 100644 --- a/core/buffer.py +++ b/core/buffer.py @@ -152,6 +152,7 @@ class Buffer(QGraphicsScene): self.progressbar_progress = 0 self.progressbar_color = QColor(233, 129, 35, 255) self.progressbar_height = 2 + self.emacs_var_dict = {} def drawForeground(self, painter, rect): if self.draw_progressbar: diff --git a/eaf.el b/eaf.el index 108c964..adf16d8 100644 --- a/eaf.el +++ b/eaf.el @@ -7,7 +7,7 @@ ;; Copyright (C) 2018, Andy Stewart, all rights reserved. ;; Created: 2018-06-15 14:10:12 ;; Version: 0.3 -;; Last-Updated: Sat Nov 23 03:15:08 2019 (-0500) +;; Last-Updated: Tue Nov 26 19:58:38 2019 (-0500) ;; By: Mingde (Matthew) Zeng ;; URL: http://www.emacswiki.org/emacs/download/eaf.el ;; Keywords: @@ -131,6 +131,11 @@ (defvar eaf-http-proxy-port "") +(defvar eaf-var-list '() + "The alist storing user-defined variables that's shared with EAF Python side. + +Use `eaf-setq' to modify this list.") + (defvar eaf-find-alternate-file-in-dired nil "If non-nil, when calling `eaf-file-open-in-dired', EAF unrecognizable files will be opened by `dired-find-alternate-file'. Otherwise they will be opened normally with `dired-find-file'.") @@ -539,6 +544,13 @@ Otherwise call send_key message to Python side." (eaf-call "execute_function" buffer-id (cdr function-name-value)) (eaf-call "send_key" buffer-id key-desc)))) +(defun eaf-setq (sym val) + "Similar to `setq', but store SYM with VAL in the EAF Python side. + +Use it as (eaf-setq 'sym val)" + (when (symbol-name sym) + (map-put eaf-var-list sym val))) + (defun eaf-focus-buffer (msg) (let* ((coordinate-list (split-string msg ",")) (mouse-press-x (string-to-number (nth 0 coordinate-list))) @@ -662,6 +674,16 @@ Otherwise call send_key message to Python side." "com.lazycat.eaf" "input_message" 'eaf-input-message) +(defun eaf-send-var-to-python () + (message "Sending variables to Python side...") + (cl-loop for (sym . val) in eaf-var-list + do (eaf-call "store_emacs_var" (symbol-name sym) val))) + +(dbus-register-signal + :session "com.lazycat.eaf" "/com/lazycat/eaf" + "com.lazycat.eaf" "get_emacs_var" + 'eaf-send-var-to-python) + (add-hook 'window-size-change-functions 'eaf-monitor-window-size-change) (add-hook 'window-configuration-change-hook #'eaf-monitor-configuration-change) (add-hook 'pre-command-hook #'eaf-monitor-key-event) @@ -713,6 +735,7 @@ Otherwise call send_key message to Python side." (defun eaf-open-camera () "Open EAF camera application." (interactive) + (eaf-setq 'eaf-camera-save-path "~/Downloads") (eaf-open "eaf-camera" "camera")) (defun eaf-open-terminal () @@ -764,9 +787,8 @@ When called interactively, URL accepts a file that can be opened by EAF." ;; Split window to show file and previewer. (eaf-split-preview-windows) (setq app-name "org-previewer")))) - - (unless arguments - (setq arguments "")) + (unless arguments (setq arguments "")) + ;; Now that app-name should hopefully be set (if app-name ;; Open url with eaf application if app-name is not empty. (if (process-live-p eaf-process) diff --git a/eaf.py b/eaf.py index de4da67..28291c8 100755 --- a/eaf.py +++ b/eaf.py @@ -142,6 +142,9 @@ class EAF(dbus.service.Object): # Send message to emacs. app_buffer.input_message.connect(self.input_message) + # Get variables defined in emacs + self.get_emacs_var() + # Handle buffer close request. app_buffer.close_buffer.connect(self.request_kill_buffer) @@ -249,7 +252,13 @@ class EAF(dbus.service.Object): if buffer.buffer_id == buffer_id: buffer.handle_input_message(callback_type, callback_result) - @dbus.service.signal("com.lazycat.eaf") + @dbus.service.method(EAF_DBUS_NAME, in_signature="ss", out_signature="") + def store_emacs_var(self, var_name, var_value): + for buffer in list(self.buffer_dict.values()): + buffer.emacs_var_dict[var_name] = var_value + # self.message_to_emacs("EAF Python: Storing " + var_name + " with " + buffer.emacs_var_dict[var_name]) + + @dbus.service.signal(EAF_DBUS_NAME) def focus_emacs_buffer(self, message): pass @@ -285,6 +294,10 @@ class EAF(dbus.service.Object): def message_to_emacs(self, message): pass + @dbus.service.signal(EAF_DBUS_NAME) + def get_emacs_var(self): + pass + def save_buffer_session(self, buf): # Create config file it not exist. if not os.path.exists(self.session_file_path):