Code refactor, add doc, check eaf-camera-save-path

master
Matthew Mingde Zeng 6 years ago
parent 7d6b7b8b11
commit a856bbbe67
  1. 17
      app/camera/buffer.py
  2. 16
      eaf.el
  3. 6
      eaf.py

@ -45,7 +45,10 @@ class AppBuffer(Buffer):
self.buffer_widget.camera.start()
def take_photo(self):
self.buffer_widget.take_photo(self.emacs_var_dict["eaf-camera-save-path"])
if os.path.exists(os.path.expanduser(self.emacs_var_dict["eaf-camera-save-path"])):
self.buffer_widget.take_photo(self.emacs_var_dict["eaf-camera-save-path"])
else:
self.buffer_widget.take_photo("~/Downloads")
class CameraWidget(QWidget):
@ -84,15 +87,9 @@ class CameraWidget(QWidget):
def take_photo(self, camera_save_path):
image_capture = QCameraImageCapture(self.camera)
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)
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)
self.message_to_emacs.emit("Captured Photo at " + photo_path)
if __name__ == "__main__":

@ -7,7 +7,7 @@
;; Copyright (C) 2018, Andy Stewart, all rights reserved.
;; Created: 2018-06-15 14:10:12
;; Version: 0.5
;; Last-Updated: Thu Dec 26 22:26:34 2019 (-0500)
;; Last-Updated: Sat Dec 28 00:52:53 2019 (-0500)
;; By: Mingde (Matthew) Zeng
;; URL: http://www.emacswiki.org/emacs/download/eaf.el
;; Keywords:
@ -409,6 +409,7 @@ For now only EAF browser app is supported."
(bookmark-set cand)))))
(defun eaf-call (method &rest args)
"Call EAF Python process using `dbus-call-method' with METHOD and ARGS."
(apply #'dbus-call-method
:session ; use the session (not system) bus
"com.lazycat.eaf" ; service name
@ -440,6 +441,7 @@ For now only EAF browser app is supported."
(message "[EAF] Process starting...")))
(defun eaf-stop-process ()
"Stop all EAF process and kill EAF buffers."
(interactive)
;; Kill EAF buffers.
(let ((count 0))
@ -464,12 +466,10 @@ For now only EAF browser app is supported."
(setq eaf-org-killed-file-list nil)
;; Kill process after kill buffer, make application can save session data.
(eaf-kill-python-process))
(eaf--kill-python-process))
(defun eaf-kill-python-process ()
"Kill EAF background python process for debug.
NOTE: this function just use for developer debug.
Don't call this function if you not EAF developer."
(defun eaf--kill-python-process ()
"Kill EAF background python process."
(interactive)
(if (process-live-p eaf-process)
;; Delete EAF server process.
@ -479,6 +479,7 @@ Don't call this function if you not EAF developer."
(message "[EAF] Process already terminated.")))
(defun eaf-restart-process ()
"Stop and restart EAF process."
(interactive)
(eaf-stop-process)
(eaf-start-process))
@ -502,6 +503,7 @@ We need calcuate render allocation to make sure no black border around render co
(list x y w h)))
(defun eaf--generate-id ()
"Randomly generate a seven digit id used for EAF buffers."
(format "%04x-%04x-%04x-%04x-%04x-%04x-%04x"
(random (expt 16 4))
(random (expt 16 4))
@ -861,7 +863,7 @@ of `eaf--buffer-app-name' inside the EAF buffer."
"Send variables defined in `eaf-var-list' to the Python side."
(eaf-call "store_emacs_var"
(string-join (cl-loop for (key . value) in eaf-var-list
collect (format "%s,%s" key value)) ":")))
collect (format "%s:%s" key value)) ",")))
(defun eaf--open-internal (url app-name arguments)
(let* ((buffer (eaf--create-buffer url app-name))

@ -289,8 +289,8 @@ class EAF(dbus.service.Object):
@dbus.service.method(EAF_DBUS_NAME, in_signature="s", out_signature="")
def store_emacs_var(self, var_dict_string):
for var_pair in var_dict_string.split(":"):
(var_name, var_value) = var_pair.split(",")
for var_pair in var_dict_string.split(","):
(var_name, var_value) = var_pair.split(":")
for buffer in list(self.buffer_dict.values()):
buffer.emacs_var_dict[var_name] = var_value
buffer.update_settings()
@ -399,7 +399,7 @@ class EAF(dbus.service.Object):
else:
print("No data present in session file, no need to restore session.")
else:
print("Not found %s, no need restore session." % (self.session_file_path))
print("Cannot find %s, no need restore session." % (self.session_file_path))
if __name__ == "__main__":
import sys

Loading…
Cancel
Save