📜 ⬆️ ⬇️

FaceCode. Plugin for SublimeText2 (Linux OS)



Good day.



Background:


Somehow I had a fasting day at work, so that one idea did not get bored. Nothing serious, just a fan plugin for Sublime Text 2. Which will be removed by the webcam of the developer who saves the code and of course the code itself is saved.

')

Attention:


Immediately I want to draw your attention dear reader, I touched the python for the first time, as I also saw it for the first time. I also admit that my text may be grammatical, for that I ask you not to throw forgiveness at me , but to write to the post office (shcoder.alex@gmail.com) or in a personal. This plugin was written for personal use and fun.

Today without water.

Idea:


The plugin should at each N (cell) save to make a screen screen and photos from a webcam.
Throw it in different folders and name it with the exact date and time.

For correct work you need:


Any linux distribution - alas, but will only work on Linux (Macs in question)
Utility Streamer - for receiving photos from a webcam
ImageMagick - for taking screenshots from the subline

Code itself
import sublime, sublime_plugin, os,time, commands from datetime import datetime, timedelta class FaceCodeCommand(sublime_plugin.EventListener): def __init__(self): self.cnt = 0 self.settings = sublime.load_settings("FaceCode.sublime-settings") self.facecode = self.settings.get("facecode") self.time_format = self.settings.get("time_format") self.img_format = self.settings.get("img_format") self.path_photo = self.settings.get("path_save_photo") self.path_screen = self.settings.get("path_save_screen") self.device = self.settings.get("device") self.count_save = self.settings.get("count_save") self.filename = self.get_file_name() self.check_folder() def on_pre_save(self, view): if self.facecode: if self.cnt % self.count_save == 0: self.save_photo() self.save_screen() self.cnt += 1 def check_folder(self): if not os.path.exists(self.path_photo) and self.path_photo: os.mkdir(self.path_photo, 0777) if not os.path.exists(self.path_screen) and self.path_screen: os.mkdir(self.path_screen, 0777) return def get_file_name(self): dt = datetime.now() ds = str(dt.strftime(self.time_format)) return ds+"."+self.img_format def save_photo(self): os.system("streamer -c "+self.device+" -o "+self.path_photo+self.filename) return def save_screen(self): win_id = commands.getoutput( 'xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)" | awk \'{print $5}\'' ) os.system("import -window "+win_id+" "+self.path_screen+self.filename) return 



Settings
 { //  "facecode": true, //    //           false "path_save_photo": "/home/alex/webcam/photo/", "path_save_screen": "/home/alex/webcam/screenshot/", //  // %d -  // %m -  // %y -  // %H -  // %M -  // %S -  //01_02_13_12_23_18.jpeg "time_format": "%d_%m_%y_%H_%M_%S", //    (jpeg|jpg|png|gif) "img_format": "jpeg", //  "device": "/dev/video0", //        //1 -  , 100 -    "count_save": 14 } 



Total:


I got what I originally planned. I saw a "scary" python - experience after all.

Example



Screen screen


Photos from webcam

Plugin on githaba
Result gif (ATTENTION 12 mb - 800+ frames)

Thank you all, I went to work.

PS Adjustments and corrections for the plugin are welcome.

Source: https://habr.com/ru/post/170403/


All Articles