예제 #1
0
def ToasterUtilisateur(parent,
                       titre=u"",
                       prenom=_(u"Philippe"),
                       nomImage="Femme",
                       taille=(200, 100),
                       couleurFond="#000000"):
    """ Affiche une boîte de dialogue temporaire """
    largeur, hauteur = (400, 148)  #taille
    tb = Toaster.ToasterBox(parent, Toaster.TB_COMPLEX,
                            Toaster.TB_DEFAULT_STYLE,
                            Toaster.TB_ONTIME)  # TB_CAPTION
    tb.SetTitle(titre)
    tb.SetPopupSize((largeur, hauteur))
    if 'phoenix' in wx.PlatformInfo:
        largeurEcran, hauteurEcran = wx.ScreenDC().GetSize()
    else:
        largeurEcran, hauteurEcran = wx.ScreenDC().GetSizeTuple()
    tb.SetPopupPosition(
        (largeurEcran - largeur - 10, hauteurEcran - hauteur - 50))
    tb.SetPopupPauseTime(3000)
    tb.SetPopupScrollSpeed(4)
    tb.SetPopupBackgroundColour(couleurFond)
    tb.SetPopupTextColour("#000000")

    tbpanel = tb.GetToasterBoxWindow()
    panel = wx.Panel(tbpanel, -1)
    sizer = wx.BoxSizer(wx.VERTICAL)
    sizerHoriz = wx.BoxSizer(wx.HORIZONTAL)
    sizerTexte = wx.BoxSizer(wx.VERTICAL)

    # Image
    bmp = wx.StaticBitmap(
        panel, -1,
        wx.Bitmap(
            Chemins.GetStaticPath("Images/Avatars/128x128/%s.png" % nomImage),
            wx.BITMAP_TYPE_PNG))
    sizerHoriz.Add(bmp, 0, wx.ALL, 10)

    # Texte1
    texte1 = _(u"Bonjour")
    label1 = wx.StaticText(panel, -1, texte1, style=wx.ALIGN_CENTER)
    label1.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
    label1.SetForegroundColour('Grey')
    sizerTexte.Add(label1, 1, wx.TOP | wx.EXPAND, 40)

    # Texte 2
    texte2 = prenom
    label2 = wx.StaticText(panel, -1, texte2, style=wx.ALIGN_CENTER)
    label2.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD))
    label2.SetForegroundColour('White')
    sizerTexte.Add(label2, 1, wx.TOP | wx.EXPAND, 0)

    sizerHoriz.Add(sizerTexte, 1, wx.EXPAND, 0)
    sizer.Add(sizerHoriz, 0, wx.EXPAND)
    panel.SetSizer(sizer)
    panel.Layout()

    tb.AddPanel(panel)

    tb.Play()
예제 #2
0
    def __init__(self, title, mins, maxs, values, *args, **kw):
        super().__init__(*args, **kw)
        panel = wx.Panel(self)
        panel.SetBackgroundColour(wx.Colour("White"))

        self.fig = Figure((5, 4), 75)
        # Adjust the subplots region to leave some space for the sliders and
        # buttons
        self.fig.subplots_adjust(left=0.25, bottom=0.25)
        self.ax = self.fig.add_axes([0.1, 0.2, 0.85, 0.75])
        self.canvas = FigureCanvasWxAgg(panel, -1, self.fig)
        self.toolbar = NavigationToolbar2Wx(self.canvas)  # matplotlib toolbar
        self.toolbar.Realize()

        self.sliders = []
        mins = np.atleast_1d(mins).flatten()
        maxs = np.atleast_1d(maxs).flatten()
        values = np.array(values).flatten()
        for idx, (min_, max_, val, tit) in enumerate(
                zip(mins, maxs, values, title)):
            slider = CustomSlider(
                panel,
                val,
                min_,
                max_,
                title=tit,
                height=wx.ScreenDC().GetPPI()[0] * 0.6,
                pads=wx.ScreenDC().GetPPI()[0] * 0.1,
            )
            slider.idx = idx
            self.sliders.append(slider)
        # self.highlighter2 = CustomSlider(panel, 1, 1, 8)
        self.clb = wx.CheckListBox(
            panel, -1, (wx.ScreenDC().GetPPI()[0] * 2, -1), wx.DefaultSize, []
        )
        self.retrain = wx.Button(panel, -1, "Retrain")

        hsizer = wx.BoxSizer(wx.HORIZONTAL)
        rsizer = wx.BoxSizer(wx.VERTICAL)
        # This way of adding to sizer allows resizing
        rsizer.Add(self.canvas, 1, wx.EXPAND)
        for slider in self.sliders:
            # | wx.LEFT | wx.RIGHT, 20)
            rsizer.Add(slider, 0, wx.EXPAND | wx.RIGHT)
        rsizer.Add(self.toolbar, 0, wx.GROW | wx.RIGHT)

        lsizer = wx.BoxSizer(wx.VERTICAL)
        lsizer.Add(self.clb, 1, wx.EXPAND)
        lsizer.Add(self.retrain, 0)

        hsizer.Add(lsizer, 0, wx.EXPAND)
        hsizer.Add(rsizer, 1, wx.EXPAND)

        self.Bind(wx.EVT_LISTBOX, self.OnListBox)
        self.Bind(wx.EVT_CHECKLISTBOX, self.OnCheckListBox)
        self.Bind(wx.EVT_BUTTON, self.OnRetrain)
        panel.SetSizer(hsizer)
        self.Layout()
        self.Centre()
예제 #3
0
    def OnMeasureItem(self, item):
        title = self.titles[item]
        subtitle = self.subtitles[item]

        dc = wx.ScreenDC()
        dc.SetFont(self.subtitle_font)
        wrapped = wordwrap(subtitle, self.GetSize().GetWidth(), dc)
        subtitle_height = dc.GetTextExtent(wrapped).GetHeight()

        dc = wx.ScreenDC()
        dc.SetFont(self.title_font)
        title_height = dc.GetTextExtent(title).GetHeight()

        return subtitle_height + title_height + 3 * self.MARGIN
    def testCalculateHeightWrapping(self):
        engine = ReportEngine()
        engine.workBounds = [0, 0, 200, 1000]
        engine.reportFormat.Text = fmt = BlockFormat()

        block = TextBlock(engine)
        fmt.Font = wx.FFont(12, wx.FONTFAMILY_DEFAULT, 0, "Arial")
        self.assertEqual(block.CalculateHeight(wx.ScreenDC()), 19)

        fmt.Padding = 10
        self.assertEqual(block.CalculateHeight(wx.ScreenDC()), 39)

        fmt.Padding = (5, 10, 15, 20)
        self.assertEqual(block.CalculateHeight(wx.ScreenDC()), 49)
예제 #5
0
    def GetPPM(self):
        """Get pixel per meter

        .. todo::
            now computed every time, is it necessary?

        .. todo::
            enable user to specify ppm (and store it in UserSettings)
        """
        # TODO: need to be fixed...
        # screen X region problem
        # user should specify ppm
        dc = wx.ScreenDC()
        dpSizePx = wx.DisplaySize()   # display size in pixels
        dpSizeMM = wx.DisplaySizeMM()  # display size in mm (system)
        dpSizeIn = (dpSizeMM[0] / 25.4, dpSizeMM[1] / 25.4)  # inches
        sysPpi = dc.GetPPI()
        comPpi = (dpSizePx[0] / dpSizeIn[0],
                  dpSizePx[1] / dpSizeIn[1])

        ppi = comPpi                  # pixel per inch
        ppm = ((ppi[0] / 2.54) * 100,  # pixel per meter
               (ppi[1] / 2.54) * 100)

        Debug.msg(4, "MapFrameBase.GetPPM(): size: px=%d,%d mm=%f,%f "
                  "in=%f,%f ppi: sys=%d,%d com=%d,%d; ppm=%f,%f" %
                  (dpSizePx[0], dpSizePx[1], dpSizeMM[0], dpSizeMM[1],
                   dpSizeIn[0], dpSizeIn[1],
                   sysPpi[0], sysPpi[1], comPpi[0], comPpi[1],
                   ppm[0], ppm[1]))

        return ppm
예제 #6
0
파일: gridbase.py 프로젝트: lf1687/MyTools
    def _auto_size_columns(self):
        """Adjust column width based on content

        The width will be between values `col size` and `max col size`
        These can be changed in user preferences.
        """
        for col in range(self.NumberCols):
            # GetTextExtent seems to be quite slow, so filter out any cells
            # whose content most likely fits anway. This can of course fail
            # with large enough font sizes.
            values = [
                self.GetCellValue(r, col) for r in range(self.NumberRows)
                if len(self.GetCellValue(r, col)) > 20
            ]
            if not values:
                continue
            # Add five pixels, because GetTextExtent does not take
            # cell border into account
            content_sizes = [
                wx.ScreenDC().GetTextExtent(v)[0] + 5 for v in values
            ]
            content_width = min(max(content_sizes),
                                self.settings['max col size'])
            width = max(content_width, self.settings['col size'])
            if width != self.GetColSize(col):
                self.SetColSize(col, width)
예제 #7
0
def original_take_screenshot():
    screen = wx.ScreenDC()
    size = screen.GetSize()
    bmp = wx.Bitmap(size[0], size[1])
    mem = wx.MemoryDC(bmp)
    mem.Blit(0, 0, size[0], size[1], screen, 0, 0)
    return bmp.GetSubBitmap(wx.Rect([0,0],[SRC_W,SRC_H]))
예제 #8
0
    def DoHighlight(self, tlw, rect, colour, penWidth=2):
        if not tlw.IsFrozen():
            tlw.Freeze()

        if self.useOverlay:
            dc = wx.ClientDC(tlw)
            dco = wx.DCOverlay(self.overlay, dc)
            dco.Clear()
        else:
            dc = wx.ScreenDC()
            dco = None

        dc.SetPen(wx.Pen(colour, penWidth))
        dc.SetBrush(wx.TRANSPARENT_BRUSH)

        drawRect = wx.Rect(*rect)
        dc.DrawRectangle(drawRect)

        drawRect.Inflate(2, 2)
        if not self.useOverlay:
            pos = tlw.ScreenToClient(drawRect.GetPosition())
            drawRect.SetPosition(pos)
        wx.CallLater(self.highlightTime, self.DoUnhighlight, tlw, drawRect)

        return dc, dco
예제 #9
0
def WTFC(win, filename, obj):
    """WindowToFileClient"""
    if wx.Platform == '__WXMAC__':
        # Blit does not write color
        os.system('screencapture scr.png')
        screen = wx.Bitmap('scr.png')
        rect = win.GetClientRect()
        rect.Offset(win.ClientToScreen((0, 0)))
        bitmap = screen.GetSubBitmap(rect)
    else:
        context = wx.ScreenDC()
        memory = wx.MemoryDC()
        x, y = win.GetPosition()
        w, h = win.GetSize()
        x0, y0 = win.ClientToScreen((0, 0))
        h = obj.GetSize()[1]
        #        h += y0 - y + 5
        #        w += 10
        bitmap = wx.EmptyBitmap(128, h, -1)
        memory.SelectObject(bitmap)
        memory.Blit(0, 0, 128, h, context, x0, y + 24)
        memory.Destroy()
        context.Destroy()
    print 'Saving bitmap ', filename
    bitmap.SaveFile(filename, wx.BITMAP_TYPE_PNG)
    bitmap.Destroy()
예제 #10
0
 def grab(self, bbox=None):
     wx = self.wx
     if not self.app:
         self.app = wx.App()
     screen = wx.ScreenDC()
     size = screen.GetSize()
     if wx.__version__ >= '4':
         bmp = wx.Bitmap(size[0], size[1])
     else:
         bmp = wx.EmptyBitmap(size[0], size[1])
     mem = wx.MemoryDC(bmp)
     mem.Blit(0, 0, size[0], size[1], screen, 0, 0)
     del mem
     if hasattr(bmp, 'ConvertToImage'):
         myWxImage = bmp.ConvertToImage()
     else:
         myWxImage = wx.ImageFromBitmap(bmp)
     im = Image.new('RGB', (myWxImage.GetWidth(), myWxImage.GetHeight()))
     if hasattr(Image, 'frombytes'):
         # for Pillow
         im.frombytes(to_bytes(myWxImage.GetData()))
     else:
         # for PIL
         im.fromstring(myWxImage.GetData())
     if bbox:
         im = im.crop(bbox)
     return im
예제 #11
0
def get(rect):
    """ Takes a screenshot of the screen at give pos & size (rect). """

    # Create a DC for the whole screen area.
    dcScreen = wx.ScreenDC()

    # Create a Bitmap that will later on hold the screenshot image.
    # Note that the Bitmap must have a size big enough to hold the screenshot.
    # -1 means using the current default color depth.
    bmp = wx.EmptyBitmap(rect.width, rect.height)

    # Create a memory DC that will be used for actually taking the screenshot.
    memDC = wx.MemoryDC()

    # Tell the memory DC to use our Bitmap
    # all drawing action on the memory DC will go to the Bitmap now.
    memDC.SelectObject(bmp)

    # Blit (in this case copy) the actual screen on the memory DC
    # and thus the Bitmap
    memDC.Blit(0,  # Copy to this X coordinate.
        0,  # Copy to this Y coordinate.
        rect.width,  # Copy this width.
        rect.height,  # Copy this height.
        dcScreen,  # From where do we copy?
        rect.x,  # What's the X offset in the original DC?
        rect.y  # What's the Y offset in the original DC?
        )

    # Select the Bitmap out of the memory DC by selecting a new
    # uninitialized Bitmap.
    memDC.SelectObject(wx.NullBitmap)

    return bmp
예제 #12
0
    def grab(self, bbox=None):
        if platform_is_osx():
            raise WxBackendError("osx not supported")
        import wx

        global app
        if not app:
            app = wx.App()
        screen = wx.ScreenDC()
        size = screen.GetSize()
        if wx.__version__ >= "4":
            bmp = wx.Bitmap(size[0], size[1])
        else:
            bmp = wx.EmptyBitmap(size[0], size[1])
        mem = wx.MemoryDC(bmp)
        mem.Blit(0, 0, size[0], size[1], screen, 0, 0)
        del mem
        if hasattr(bmp, "ConvertToImage"):
            myWxImage = bmp.ConvertToImage()
        else:
            myWxImage = wx.ImageFromBitmap(bmp)
        im = Image.new("RGB", (myWxImage.GetWidth(), myWxImage.GetHeight()))
        if hasattr(Image, "frombytes"):
            # for Pillow
            im.frombytes(to_bytes(myWxImage.GetData()))
        else:
            # for PIL
            im.fromstring(myWxImage.GetData())
        if bbox:
            im = im.crop(bbox)
        return im
예제 #13
0
    def OnClipImage(self, evt):

        if wx.TheClipboard.Open():
            # get webView rectangle in the screen coordinate
            rect = self.webView.GetScreenRect()
            # apply screen scale
            rect.x = rect.x * self.scale
            rect.y = rect.y * self.scale
            rect.width = rect.width * self.scale
            rect.height = rect.height * self.scale

            # prepare screen DC
            dcScr = wx.ScreenDC()
            # prepare memory DC
            bmp = wx.Bitmap(rect.width, rect.height)
            memDC = wx.MemoryDC()
            memDC.SelectObject(bmp)
            # render screen area into the memory DC
            memDC.Blit(0, 0, rect.width, rect.height, dcScr, rect.x, rect.y)
            # clear memory DC
            memDC.SelectObject(wx.NullBitmap)

            # copy the bitmap into clipboard
            wx.TheClipboard.SetData(wx.BitmapDataObject(bmp))
            wx.TheClipboard.Close()
예제 #14
0
def take_screenshot(fullscreen=True):
    """Returns a wx.Bitmap screenshot taken of fullscreen or program window."""
    wx.YieldIfNeeded()
    if fullscreen:
        rect = wx.Rect(0, 0, *wx.DisplaySize())
    else:
        window = wx.GetApp().TopWindow
        rect = window.GetRect()

        # adjust widths for Linux (figured out by John Torres
        # http://article.gmane.org/gmane.comp.python.wxpython/67327)
        if "linux2" == sys.platform:
            client_x, client_y = window.ClientToScreen((0, 0))
            border_width = client_x - rect.x
            title_bar_height = client_y - rect.y
            rect.width += (border_width * 2)
            rect.height += title_bar_height + border_width

    dc = wx.ScreenDC()
    bmp = wx.Bitmap(rect.width, rect.height)
    dc_bmp = wx.MemoryDC()
    dc_bmp.SelectObject(bmp)
    dc_bmp.Blit(0, 0, rect.width, rect.height, dc, rect.x, rect.y)
    dc_bmp.SelectObject(wx.NullBitmap)
    del dc, dc_bmp
    if bmp.Depth > 24:
        try:  # Drop alpha channel
            img = bmp.ConvertToImage()
            img.ClearAlpha()
            bmp = img.ConvertToBitmap()
        except Exception:
            pass
    return bmp
예제 #15
0
    def script_startRecognition(self, gesture):
        obj = api.getNavigatorObject()

        if obj.role != controlTypes.ROLE_GRAPHIC and conf["graphicOnly"]:
            ui.message(_("This object is not a graphical element"))
            return

        if controlTypes.STATE_OFFSCREEN in obj.states:
            ui.message(_("Captcha off screen"))
            return

        try:
            x, y, width, height = obj.location
        except Exception:
            ui.message(_("Captcha has no location"))
            return

        if conf["sizeReport"] and scriptHandler.getLastScriptRepeatCount(
        ) != 1:
            ui.message(_("Size: {0} X {1} pixels").format(width, height))
            return

        bmp = wx.Bitmap(width, height)
        mem = wx.MemoryDC(bmp)
        mem.Blit(0, 0, width, height, wx.ScreenDC(), x, y)
        image = bmp.ConvertToImage()
        body = io.BytesIO()
        image.SaveFile(body, wx.BITMAP_TYPE_PNG)

        wx.CallAfter(self._creator, body=body.getvalue())
예제 #16
0
    def DrawGridOnParent(self, xpos, ypos):
        """TO BE DEBUGGED. Actually draws a thin dotted gray line over the drawing parent window."""

        if not self._drawingparent:
            return

        parentrect = self._drawingparent.GetClientRect()

        dc = wx.ScreenDC()
        dc.SetLogicalFunction(wx.INVERT)
        dc.SetPen(wx.Pen(wx.Colour(110,120,110), 1, wx.LONG_DASH))
        dc.SetBrush(wx.TRANSPARENT_BRUSH)

        (w,h) = self.GetDrawingSize()
        imgx, imgy = xpos, h

        x1 = xpos + imgx/2
        y1 = parentrect.y + ypos + imgy
        x2 = x1
        y2 = y1 + parentrect.height - imgy
        x1, y1 = self.ClientToScreenXY(x1, y1)
        x2, y2 = self.ClientToScreenXY(x2, y2)

        dc.DrawLine(x1, y1, x2, y2)
        dc.SetLogicalFunction(wx.COPY)
예제 #17
0
    def DrawOnParent(self, indicator):
        """Actually draws the thin line over the drawing parent window."""

        if not self._drawingparent:
            return

        xpos, ypos = indicator.GetPosition()
        parentrect = self._drawingparent.GetClientRect()

        dc = wx.ScreenDC()
        dc.SetLogicalFunction(wx.INVERT)
        dc.SetPen( self._fgpen )
        dc.SetBrush(wx.TRANSPARENT_BRUSH)

        imgx, imgy = indicator.GetImageSize()

        x1 = xpos + imgx/2
        y1 = parentrect.y + ypos + imgy
        x2 = x1
        y2 = y1 + parentrect.height - imgy
        x1, y1 = self.ClientToScreenXY(x1, y1)
        x2, y2 = self.ClientToScreenXY(x2, y2)

        dc.DrawLine(x1, y1, x2, y2)
        dc.SetLogicalFunction(wx.COPY)
예제 #18
0
파일: gui.py 프로젝트: Den4200/ScreenPaste
    def ss(self):
        app = wx.App()
        screen = wx.ScreenDC()
        size = pyautogui.size()
        bmp = wx.Bitmap(size[0], size[1])
        mem = wx.MemoryDC(bmp)

        mem.Blit(0, 0, size[0], size[1], screen, 0, 0)
        del mem
        bmp.SaveFile(os.path.join('screenshots', 'screenshot.png'),
                     wx.BITMAP_TYPE_PNG)

        log('INFO', 'Screenshot taken')

        client = Client()
        client.send_img()

        label = tk.Label(self.canvas,
                         text=client.returnLink(),
                         fg="blue",
                         cursor="hand2")
        label.pack()
        label.bind("<Button-1>", lambda e: self.callback(client.returnLink()))

        app.MainLoop()
예제 #19
0
    def AutoResizeByContentAndHeader(self):
        """
        Set the column header widths to be large enoguh to display both the
        header column label and all of the content under than header
        """
        dc = wx.ScreenDC()
        if not dc.Ok() or not self.GetFont().Ok():
            return

        # Get listview column header widths and heights
        for k in xrange(self.GetColumnCount()):
            # Measure the column text
            column = self.GetColumn(k)
            font = column.GetFont()
            if not font.Ok() and sys.platform != 'win32':
                font = self.GetFont()
                if not font.Ok():
                    break
            (colSizeW, colSizeH) = dc.GetTextExtent(column.GetText())

            # Find the largest listview entries for each column
            for j in xrange(self.GetItemCount()):
                item = self.GetItem(j, k)
                font = item.GetFont()
                if not font.Ok() and sys.platform != 'win32':
                    font = self.GetFont()
                    if not font.Ok():
                        break
                dc.SetFont(font)
                (itemSizeW, itemSizeH) = dc.GetTextExtent(item.GetText())
                if itemSizeW > colSizeW:
                    colSizeW = itemSizeW

            # Now set the column size
            self.SetColumnWidth(k, colSizeW + 8)
예제 #20
0
def get_text_width_px(window, text_str):
    """Using window settings, find width in pixels of a text str.

    Args:
        window (wx.Window): Window to contain string using default font
        text_str (str): string to find the width of

    Returns:
        (int) width of text_str in pixels in the given window
    """
    # get width in pixels of the given font
    screen_dc = wx.ScreenDC()
    screen_dc.SetFont(window.GetFont())
    (text_width_px, _) = screen_dc.GetTextExtent(text_str)
    del screen_dc

    # add horizontal margins if present
    try:
        margins = window.GetMargins()
    except AttributeError:
        margins = wx.Point(-1, -1)
    if margins.x > 0:
        text_width_px = text_width_px + margins.x * 2

    return text_width_px
예제 #21
0
def screenshot(region=None):
    global screen

    app = wx.App()
    screen = wx.ScreenDC()

    w, h = screen.Size.Get()

    # Construct a bitmap
    bmp = wx.Bitmap(w, h)

    # Fill bitmap delete memory (don't want memory leak)
    mem = wx.MemoryDC(bmp)
    mem.Blit(0, 0, w, h, screen, 0, 0)
    del mem

    # Convert bitmap to image
    wxB = bmp.ConvertToImage()
    
    
    # Get data buffer
    img_data = wxB.GetData()

    # Construct np array from data buffer and reshape it to img
    img_data_str = np.frombuffer(img_data, dtype='uint8')
    img = img_data_str.reshape((h, w, 3))

    #Converts np array image back to PIL image
    img = Image.fromarray(img)
    return img
예제 #22
0
def take_screenshot():
    screen = wx.ScreenDC()
    size = screen.GetSize()
    bmp = wx.Bitmap(size[0], size[1])
    mem = wx.MemoryDC(bmp)
    mem.Blit(0, 0, size[0], size[1], screen, 0, 0)
    return bmp.GetSubBitmap(wx.Rect([0, 0], [615, 480]))
	def onbtn1(self,event): # print time.ctime() # 현재시간
		conn = pymysql.connect(host='flagish.kr', user='******', passwd='test', db='webshot', charset='utf8')
		curs = conn.cursor()
		dc = wx.ScreenDC() # dc= wx.ClientDC(self)
		mem = wx.MemoryDC()
		user32 = ctypes.windll.user32

		now = datetime.datetime.now()

		TIME = now.strftime('%Y-%m-%d %H:%M:%S')
		FILENAME = "display_"+now.strftime('%Y%m%d%H%M%S')+".png"
		
		x = user32.GetSystemMetrics(0)
		y = user32.GetSystemMetrics(1)

		if dc.IsOk(): 
			bmp2 = wx.Bitmap(x,y)
			mem.SelectObject(bmp2)
			mem.Blit(0,0,x,y,dc,0,0)

			mem.SelectObject(wx.NullBitmap)
			self.bmp = bmp2
			self.bmp.SaveFile(FILENAME,wx.BITMAP_TYPE_PNG)
		

		MD5 = hashlib.md5(FILENAME.encode('utf-8')).hexdigest()
		sql = "INSERT INTO screenshot_info (TIME, FILENAME, MD5) VALUES (%s, %s, %s)"
		curs.execute(sql,(TIME, FILENAME, MD5))
		conn.commit()
		conn.close()
예제 #24
0
def take_screenshot(fullscreen=True):
    """Returns a wx.Bitmap screenshot taken of fullscreen or program window."""
    wx.YieldIfNeeded()
    if fullscreen:
        rect = wx.Rect(0, 0, *wx.DisplaySize())
    else:
        window = wx.GetApp().TopWindow
        rect   = window.GetRect()

        # adjust widths for Linux (figured out by John Torres 
        # http://article.gmane.org/gmane.comp.python.wxpython/67327)
        if "linux2" == sys.platform:
            client_x, client_y = window.ClientToScreen((0, 0))
            border_width       = client_x - rect.x
            title_bar_height   = client_y - rect.y
            rect.width        += (border_width * 2)
            rect.height       += title_bar_height + border_width

    dc = wx.ScreenDC()
    bmp = wx.EmptyBitmap(rect.width, rect.height)
    dc_bmp = wx.MemoryDC()
    dc_bmp.SelectObject(bmp)
    dc_bmp.Blit(0, 0, rect.width, rect.height, dc, rect.x, rect.y)
    dc_bmp.SelectObject(wx.NullBitmap)
    # Hack to drop screen transparency, wx issue when blitting from screen
    bmp = wx.BitmapFromIcon(wx.IconFromBitmap(bmp))
    return bmp
예제 #25
0
    def AutosizeLabels(self, rows=True, cols=False):
        # Common setup.
        devContext = wx.ScreenDC()
        devContext.SetFont(self.GetLabelFont())

        # First do row labels.
        if rows:
            maxWidth = 0
            curRow = self.GetNumberRows() - 1
            while curRow >= 0:
                curWidth = devContext.GetTextExtent(
                    "M%s" % (self.GetRowLabelValue(curRow)))[0]
                if curWidth > maxWidth:
                    maxWidth = curWidth
                curRow = curRow - 1
            self.SetRowLabelSize(maxWidth)

        # Then column labels.
        if cols:
            maxHeight = 0
            curCol = self.GetNumberCols() - 1
            while curCol >= 0:
                (w, h, d, l) = devContext.GetFullTextExtent(
                    self.GetColLabelValue(curCol))
                curHeight = h + d + l + 4
                if curHeight > maxHeight:
                    maxHeight = curHeight
                curCol = curCol - 1
            self.SetColLabelSize(maxHeight)
        return
예제 #26
0
    def load_images(self):
        parent = self.parent

        self.show_b = True
        self.aligning = False

        #print "Widest : %s" % self.widest
        #print "Tallest: %s" % self.tallest

        screen = wx.ScreenDC()
        size = screen.GetSize()
        self.bmp_a = wx.EmptyBitmap(self.parent.zone_a[2],
                                    self.parent.zone_a[3])
        wx.MemoryDC(self.bmp_a).Blit(
            0,
            0,  # dest x, y
            self.parent.zone_a[2],
            self.parent.zone_a[3],  # dest w, h
            screen,  # src
            self.parent.game_zone[0] + self.parent.zone_a[0],  # src x
            self.parent.game_zone[1] + self.parent.zone_a[1],  # src y
        )

        self.bmp_b = wx.EmptyBitmap(self.parent.zone_b[2],
                                    self.parent.zone_b[3])
        wx.MemoryDC(self.bmp_b).Blit(
            0,
            0,  # dest x, y
            self.parent.zone_b[2],
            self.parent.zone_b[3],  # dest w, h
            screen,  # src
            self.parent.game_zone[0] + self.parent.zone_b[0],  # src x
            self.parent.game_zone[1] + self.parent.zone_b[1],  # src y
        )
예제 #27
0
    def publish_screenshot(self, event):
        import time
        settings = get_settings()
        #t = time.strftime("%I%M%S")
        t = 'temp'
        print t
        time.sleep(1)
        screen = wx.ScreenDC()
        size = screen.GetSize()
        bmp = wx.EmptyBitmap(size[0], size[1])
        mem = wx.MemoryDC(bmp)
        mem.Blit(0, 0, size[0], size[1], screen, 0, 0)
        del mem  # Release bitmap
        bmp.SaveFile(t + '.png', wx.BITMAP_TYPE_PNG)

        opener = streaminghttp.register_openers()
        params = {
            'image': open(t + '.png', 'rb'),
            'lesson': settings['id'],
            'publish': 'yes'
        }
        datagen, headers = multipart_encode(params)
        response = opener.open(
            urllib2.Request(settings['url2'], datagen, headers))

        print 'Hello, world!'
예제 #28
0
    def __init__(self, parent):
        wx.Frame.__init__(self,
                          parent,
                          wx.ID_ANY,
                          'Select Play Zones',
                          size=(parent.game_zone[2], parent.game_zone[3]))
        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)

        self.parent = parent

        self.zone_a = [0, 0, 100, 100]
        self.zone_b = [150, 0, 100, 100]

        screen = wx.ScreenDC()
        size = screen.GetSize()
        self.bmp = wx.EmptyBitmap(size[0], size[1])
        wx.MemoryDC(self.bmp).Blit(0, 0, parent.game_zone[2],
                                   parent.game_zone[3], screen,
                                   parent.game_zone[0], parent.game_zone[1])

        self.Bind(wx.EVT_PAINT, self.OnPaint)
        self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
        self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
        self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)
        self.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
        self.Bind(wx.EVT_MOTION, self.OnMotion)

        #self.Show()
        self.ShowFullScreen(True, wx.FULLSCREEN_ALL)
예제 #29
0
    def __init__(self, parent, Auto=True, MouseButton=wx.MOUSE_BTN_MIDDLE):
        self.parent = parent

        self.gestures = []
        self.actions = []
        self.actionarguments = []

        self.mousebutton = MouseButton
        self.modifiers = []

        self.recording = False

        self.lastposition = (-1, -1)

        self.pen = wx.Pen(wx.Colour(0, 144, 255), 5)

        self.dc = wx.ScreenDC()
        self.dc.SetPen(self.pen)

        self.showgesture = False

        self.wobbletolerance = 7

        self.rawgesture = ''

        self.SetAuto(Auto)
예제 #30
0
    def __init__(self, parent):
        wx.Frame.__init__(self,
                          parent,
                          wx.ID_ANY,
                          'STD Solver',
                          size=(200, 400),
                          style=wx.STAY_ON_TOP)
        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)

        screen = wx.ScreenDC()
        self.game_zone = [0, 0, screen.GetSize()[0], screen.GetSize()[1]]
        self.zone_a = [50, 75, 100, 50]
        self.zone_b = [75, 50, 50, 100]

        #screen.StartDrawingOnTop()
        #screen.DrawCircle(100, 100, 100)
        #screen.Clear()
        #screen.EndDrawingOnTop()

        self.SelectPlayZonesBtn = wx.Button(self, label="Select Play Zones")
        self.SelectPlayZonesBtn.Bind(wx.EVT_BUTTON, self.OnSelectPlayZones)

        self.AlignBtn = wx.Button(self, label="Align")
        self.AlignBtn.Bind(wx.EVT_BUTTON, self.OnAlign)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.SelectPlayZonesBtn, 0, wx.EXPAND)
        sizer.Add(self.AlignBtn, 0, wx.EXPAND)
        self.SetSizer(sizer)
        self.Layout()
        self.Fit()