Skip to content

Instantly share code, notes, and snippets.

@EnumCode
Created August 17, 2018 13:24
Show Gist options
  • Save EnumCode/bbed2777ea0ceafd36ba8ad74cc2d9f7 to your computer and use it in GitHub Desktop.
Save EnumCode/bbed2777ea0ceafd36ba8ad74cc2d9f7 to your computer and use it in GitHub Desktop.
pyazo client side
import wx
import pyautogui
import requests
import webbrowser
class MyApp(wx.App):
def __init__(self, parent=None):
wx.App.__init__(self, False)
self.frame = MyFrame(parent, -1, passBack=self)
self.outputFromFrame = ""
def getOutput(self):
self.frame.Show()
self.MainLoop()
return self.outputFromFrame
class MyFrame(wx.Frame):
c1 = None
c2 = None
def __init__(self, parent, ID, passBack, title=""):
wx.Frame.__init__(self, parent, ID, title, size=(1920,1080),style=wx.BORDER_NONE)
self.passBack = passBack
self.panel = wx.Panel(self, size=self.GetSize())
self.Bind(wx.EVT_CHAR_HOOK, self.OnKeyUP)
self.panel.Bind(wx.EVT_MOTION, self.OnMouseMove)
self.panel.Bind(wx.EVT_LEFT_DOWN, self.OnMouseDown)
self.panel.Bind(wx.EVT_LEFT_UP, self.OnMouseUp)
self.panel.Bind(wx.EVT_PAINT, self.OnPaint)
self.SetCursor(wx.StockCursor(wx.CURSOR_CROSS))
self.SetTransparent(50)
self.drew = 0
def OnKeyUP(self, event):
keyCode = event.GetKeyCode()
if keyCode == wx.WXK_ESCAPE:
self.Close()
event.Skip()
def OnMouseMove(self, event):
if event.Dragging() and event.LeftIsDown():
self.c2 = event.GetPosition()
self.Refresh()
else:
if self.drew == 1:
self.Close()
self.passBack.outputFromFrame = (self.c1.x, self.c1.y, self.c2.x - self.c1.x, self.c2.y - self.c1.y)
def OnMouseDown(self, event):
self.c1 = event.GetPosition()
def OnMouseUp(self, event):
self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
def OnPaint(self, event):
if self.c1 is None or self.c2 is None: return
dc = wx.PaintDC(self.panel)
dc.SetPen(wx.Pen('black', 1))
dc.SetBrush(wx.Brush(wx.Colour(0, 0, 0), wx.TRANSPARENT))
dc.DrawRectangle(self.c1.x, self.c1.y, self.c2.x - self.c1.x, self.c2.y - self.c1.y)
self.drew = 1
def PrintPosition(self, pos):
return str(pos.x) + " " + str(pos.y)
def main():
app = MyApp()
val = app.getOutput()
if val is not "":
if val[2]<0 :
if val[3]<0:
myTuple = (val[0]+val[2],val[1]+val[3],abs(val[2]),abs(val[3]))
pyautogui.screenshot('test.png', region=myTuple)
else:
myTuple = (val[0] + val[2],val[1] ,abs(val[2]),val[3])
pyautogui.screenshot('test.png', region=myTuple)
elif val[3]<0:
myTuple = (val[0], val[1]+val[3], abs(val[2]), abs(val[3]))
pyautogui.screenshot('test.png', region=myTuple)
else:
pyautogui.screenshot('test.png', region=val)
url = '{flask_server_name}'
files = {'file': open('test.png', 'rb')}
r = requests.post(url, files=files)
print(r.text)
webbrowser.open('{nginx_server_name}'+r.text)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment