Skip to content
Browse files

fix bug about save file

  • Loading branch information...
1 parent cd9d094 commit 9325eb06183effff194eec254af0e6117a3f1d31 @linychuo committed
Showing with 70 additions and 54 deletions.
  1. +1 −1 capturescreen.py
  2. +43 −46 common.py
  3. +26 −7 make.py
View
2 capturescreen.py
@@ -1,4 +1,4 @@
-# -*- coding: gbk -*-
+# -*- coding: utf-8 -*-
from common import TaskBar
import wx
View
89 common.py
@@ -4,7 +4,7 @@
import os
import wx
-wildcard = "JPEG (*.jpeg)|*.jpeg|""JPEG (*.jpg)|*.jpg|""GIF (*.gif)|*.gif|""PNG (*.png)|*.png"
+wildcard = "JPEG (*.jpg)|*.jpg|""GIF (*.gif)|*.gif|""PNG (*.png)|*.png"
PAGE_WIDTH = 1000
PAGE_HEIGHT = 1000
@@ -40,29 +40,19 @@ def SetSize(self, size):
self._size = size
class SafeSaveFileDialog(wx.FileDialog):
- def __init__(self, parent, im):
- wx.FileDialog.__init__(self, parent, message="保存截图", defaultDir=os.getcwd(), defaultFile="default", wildcard=wildcard, style=wx.SAVE)
- self.im = im
+ def __init__(self, parent):
+ wx.FileDialog.__init__(self, parent, message=u"保存截图", defaultDir=os.getcwd(), defaultFile=u"default", wildcard=wildcard, style=wx.SAVE)
+ self.parent = parent
- def Save(self):
- done = False
- filePath = None
- while not done:
- if self.GetReturnCode() == wx.ID_OK:
- filePath = self.GetPath()
- if filePath == None:
- done = True
- else:
- if os.path.exists(filePath):
- done = wx.MessageBox("这个文件已经存在,确定要覆盖它吗?", "系统提示", wx.YES_NO | wx.ICON_EXCLAMATION) == wx.YES
- else:
- done = True
- else:
- done = True
-
- if filePath:
- self.im.save(filePath)
-
+ def Save(self,im):
+ filePath = self.GetPath()
+ if os.path.exists(filePath):
+ if wx.MessageBox(u"这个文件已经存在,确定要覆盖它吗?", u"系统提示", wx.YES_NO | wx.ICON_EXCLAMATION) == wx.YES:
+ im.save(filePath)
+ self.parent.Destroy()
+ else:
+ im.save(filePath)
+ self.parent.Destroy()
class TaskBar(wx.TaskBarIcon):
TBMENU_CLOSE = wx.NewId()
@@ -72,7 +62,7 @@ class TaskBar(wx.TaskBarIcon):
def __init__(self, app):
wx.TaskBarIcon.__init__(self)
self.app = app
- self.SetIcon(getFAVICONIcon(), "屏幕截屏工具")
+ self.SetIcon(getFAVICONIcon(), u"屏幕截屏工具")
self.menu = None
self.Bind(wx.EVT_TASKBAR_LEFT_DCLICK, self.OnTaskBarLeftDBClick)
@@ -84,10 +74,10 @@ def __init__(self, app):
def OnTaskBarLeftDBClick(self, evt):
if self.menu == None:
self.menu = wx.Menu()
- self.menu.Append(self.TBMENU_CAPTURE, "屏幕截图")
- self.menu.Append(self.TBMENU_CAPTUREALL, "截全屏")
+ self.menu.Append(self.TBMENU_CAPTURE, u"屏幕截图")
+ self.menu.Append(self.TBMENU_CAPTUREALL, u"截全屏")
self.menu.AppendSeparator()
- self.menu.Append(self.TBMENU_CLOSE, "退出程式")
+ self.menu.Append(self.TBMENU_CLOSE, u"退出程式")
self.PopupMenu(self.menu)
@@ -101,23 +91,22 @@ def OnCapture(self, evt):
def OnCaptureAll(self, evt):
- im = ImageGrab.grab()
- dlg = SafeSaveFileDialog(self.app, im)
- dlg.Save()
- dlg.Destroy()
- im = None
+ dlg = SafeSaveFileDialog(self.app)
+ if dlg.ShowModal() == wx.ID_OK :
+ dlg.Save(ImageGrab.grab())
+ else:
+ dlg.Destroy()
class TransparentFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, style=wx.FRAME_TOOL_WINDOW)
- self.parent = parent
- self.SetTransparent(180)
- self.SetBackgroundColour('#242424')
+ self.SetTransparent(150)
+ self.SetBackgroundColour('Black')
self.penColour = wx.BLUE
self.fillColour = wx.LIGHT_GREY
self.lineSize = 1
- self.region = Rect(penColour=self.penColour, fillColour=self.fillColour, lineSize=self.lineSize)
+ self.region = Rect(penColour=self.penColour,lineSize=self.lineSize)
self.SetCursor(wx.CROSS_CURSOR)
self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDBClick)
@@ -125,6 +114,7 @@ def __init__(self, parent):
self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
self.Bind(wx.EVT_MOTION, self.OnMove)
self.Bind(wx.EVT_PAINT, self.OnPaintEvent)
+ self.dlg = None
def OnLeftDBClick(self, evt):
self.Destroy()
@@ -136,6 +126,11 @@ def OnLeftDown(self, evt):
def OnLeftUp(self, evt):
self.endX = evt.X
self.endY = evt.Y
+
+ if self.dlg:
+ self.dlg.Destroy()
+ self.dlg = None
+
if self.beginX != self.endX and self.beginY != self.endY:
im = None
if self.endX < self.beginX:
@@ -148,15 +143,17 @@ def OnLeftUp(self, evt):
im = ImageGrab.grab((self.beginX, self.endY, self.endX, self.beginY))
else:
im = ImageGrab.grab((self.beginX, self.beginY, self.endX, self.endY))
-
-# dlg = SafeSaveFileDialog(self.parent, im)
-# dlg.ShowModal()
-# dlg.Save()
-# dlg.Destroy()
- drawingFrame = DrawingFrame(self.parent, im)
- drawingFrame.Center()
- drawingFrame.Show()
- self.Destroy()
+
+ self.dlg = SafeSaveFileDialog(self)
+ if self.dlg.ShowModal() == wx.ID_OK :
+ self.dlg.Save(im)
+ else:
+ self.dlg.Destroy()
+ self.dlg = None
+ #drawingFrame = DrawingFrame(self.parent, im)
+ #drawingFrame.Center()
+ #drawingFrame.Show()
+ #self.Destroy()
def OnMove(self, evt):
if evt.LeftIsDown():
@@ -184,7 +181,7 @@ def __init__(self, parent, images):
self.drawPanel.SetScrollbars(20, 20, PAGE_WIDTH / 20, PAGE_HEIGHT / 20)
tb = self.CreateToolBar(wx.TB_HORIZONTAL | wx.NO_BORDER | wx.TB_FLAT | wx.TB_TEXT)
self.CreateStatusBar()
- tb.AddSimpleTool(10, getSAVEBMPBitmap(), "保存", "保存一个截取的图片")
+ tb.AddSimpleTool(10, getSAVEBMPBitmap(), u"保存", u"保存一个截取的图片")
tb.Realize()
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Bind(wx.EVT_CLOSE, self.OnClose)
View
33 make.py
@@ -12,8 +12,6 @@ def __init__(self, **kw):
self.__dict__.update(kw)
# for the versioninfo resources
self.version = "0.1.0"
- self.company_name = "No Company"
- self.copyright = "No copyright"
self.name = "CaptureScree"
################################################################
@@ -29,14 +27,35 @@ def __init__(self, **kw):
manifest_template = '''
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
-<assemblyIdentity
+ <assemblyIdentity
version="5.0.0.0"
processorArchitecture="x86"
name="%(prog)s"
type="win32"
-/>
-<description>%(prog)s Program</description>
-<dependency>
+ />
+ <description>%(prog)s</description>
+ <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
+ <security>
+ <requestedPrivileges>
+ <requestedExecutionLevel
+ level="asInvoker"
+ uiAccess="false">
+ </requestedExecutionLevel>
+ </requestedPrivileges>
+ </security>
+ </trustInfo>
+ <dependency>
+ <dependentAssembly>
+ <assemblyIdentity
+ type="win32"
+ name="Microsoft.VC90.CRT"
+ version="9.0.21022.8"
+ processorArchitecture="x86"
+ publicKeyToken="1fc8b3b9a1e18e3b">
+ </assemblyIdentity>
+ </dependentAssembly>
+ </dependency>
+ <dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
@@ -47,7 +66,7 @@ def __init__(self, **kw):
language="*"
/>
</dependentAssembly>
-</dependency>
+ </dependency>
</assembly>
'''

0 comments on commit 9325eb0

Please sign in to comment.
Something went wrong with that request. Please try again.