FaceCode. Plugin for SublimeText2 (Linux OS)



Good afternoon.



Background:


Somehow, a fasting day fell at work, so in order not to be bored one idea fell into my head. Nothing serious, just a fan plugin for Sublime Text 2. Which will shoot the webcam of the developer saving the code and of course the stored code itself.


Attention:


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

Today without water.

Idea:


The plugin should, with every N (hundredth) save, take a screen shot and a photo from the webcam.
Throw it in different folders and name it with the exact date and time.


For correct operation you need:


Any linux distribution is, alas, it will only work on Linux (Macs are in question)
Streamer utility - for taking photos from
ImageMagick webcam - for taking screenshots from sub-lime


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 "terrible" python - experience after all.

Example



Screen screen


Photos from a webcam

Plug-in on github
Result GIF (ATTENTION 12 mb - 800+ frames)

Thank you all, I went to work.

PS Corrections and corrections for the plugin are welcome.

Also popular now: