示例#1
0
    def __init__(self, *args, **kwargs):
        """Default Constructor for wx.Frame"""
        super(MainWindow, self).__init__(*args, **kwargs)
        icon = PyEmbeddedImage(
            "iVBORw0KGgoAAAANSUhEUgAAAE4AAABECAYAAAAvMQN7AAAD+klEQVR42u1cP08yMRg//6CA"
            "KEhCSBwY3VwcNOED8AHcTEx4+QysjHwBJjYSRhIkzk6EWROjm4sTMXyKvj6XKynH9dq7a3tt"
            "735JAxJp6a/Pvz7PA46TI4dWGI/H6O8BHR4euo/k86OjI/yaMXh5eXE/P94Dfl4oFNDBwUHy"
            "/by+vroTEZPt/E0+J0jVFsvlcmcvpCCQ+yH/J/Ii7XYblcvlnYlpAxY6Pj72v64NVqsVKpVK"
            "rnZgsnzkBO4J3nN6eop+fn649+MSwZo8bBCqkCpqtZpLGGFSYo3RaIS49D/JIn4C05DAAJVL"
            "NDziw6VNJHF4A7Dw1dUVc/Fer4cqlcqOhID0wxgOh8z3Y5UU9fnJfVA16Pr6Wugp+QfMT9vw"
            "5+en+8HC1sd2h3XwsgZ8vu/v7/31wR2LlDZe4sDbRT39NIgjnIu6RRkSF5k48HaqiSOih/SJ"
            "u7y8RHENOcXmIdnqqgVxxWIx9umDE8kscQKckdI9BNpXlleTZOPEbiINicuJY68HkYcuXtUo"
            "Vb27u0PK4yAbiAu9soi+59lAHNed++TkRMp9z1TiwK7RbNseLi4uhEueicTFze7gq03WVTU6"
            "np+ft8wnlT4TiMOCwpN/4wJMmJQ83YmDvYGJ6nQ64hOv1Wo1NoG6Ewd7k5qWDijMGE0ceMyz"
            "szM16X2ogEUNWXQlzsvQqAPEe1HshwrieDPYcOhESks9vBoAVzwUlLWNQj5PpiJK6h8cQWp1"
            "y/V6PQL7wHIWtFYJATWOWPk9WgpcOVjkEbeQQFWNYi8x2e/v7zvzPT4+8pClD2l+taMRGHJ9"
            "ESJtYLNYB8B951QNLxYKHb+/v//ikkerNdzf3zOLydpJmh9w6mFqG1JU9rda7ama1wi0g263"
            "y1RtTxv0Rr/fZ54+raj89va2tXnYLhKemxpThhHHUf3XB6yyHxAiIvBkpb4gBJpMJkY1PnKH"
            "Gk9PT5E31mq1EJlwpZEn/f4pAx8fH1xNfNhwh7Q1bNFsNgO7KYPmFJYaSkvqeLofiY26Kkwm"
            "EnCzixdKcOfVGo2GucQJuh2IqrkaB9WEoZubG/OJ22w2TdUS59gCVepK2EZroEzaZrOZVcQ5"
            "CiXOLpyfn0vthrLOvmGEXeBFedSgJIDxeHh4UCFx1iIPeuPm6mQRV6/X7SVOZjxnRLIyLqCo"
            "E7cTIJOhiApVtdo5JP0ebGadQ05cAucgS11vb2/tjuNkEbdYLOwlbjAYSPlOrA7f/zfu9kB0"
            "POXERR3T6TQTxDle66iwGoOTJXjNM7EHNAYaWXBOiq+vLyRA8jIN7hCF/DEpJ4fjQPBKSl9Q"
            "JR97z/l8npPmB/wGCbRAkE3ZkHL3ekZy5Mgw/gMoRoA7F6WE6gAAAABJRU5ErkJggg=="
        )
        self.SetIcon(icon.GetIcon())

        self.sx = 0
        self.sy = 0 - 20
        self.mainpan = wx.Panel(self)
        self.configs = ConfigData()
        self.online_status = False
        self.goodcolor = self.configs.colors['online']
        self.warningcolor = self.configs.colors['offline']
        self.on_off_flag = threading.Event()
        self.running_flag = threading.Event()
        self.configs.VK_CODE

        self.__init_ui()
        self._start_watcher_thread()
示例#2
0
class MyDialog(wx.Dialog):
    def __init__(self, *args, **kwds):
        self.index = 0
        self.prepDict = {}
        self.End = False
        kwds["style"] = wx.DEFAULT_DIALOG_STYLE
        wx.Dialog.__init__(self, *args, **kwds)
        self.labelPath = wx.StaticText(self, wx.ID_ANY, "Path : ")
        self.textCtrlPath = wx.TextCtrl(self, wx.ID_ANY, "")
        self.button_1 = wx.Button(self, wx.ID_ANY, "Open...")
        self.button_1.Disable()
        self.ffmpeg = wx.StaticText(self, wx.ID_ANY, "FFMPEG :")
        self.info = wx.StaticText(self, wx.ID_ANY, "")
        self.gauge = wx.Gauge(self,
                              range=20,
                              size=(445, 25),
                              style=wx.GA_HORIZONTAL)
        self.labelFile = wx.StaticText(self, wx.ID_ANY,
                                       "File List (must be *.mp4 or *.MP4):")
        self.icon = PyEmbeddedImage(icon)
        self.icon = self.icon.GetIcon()
        self.listCtrlFile = wx.ListCtrl(self,
                                        wx.ID_ANY,
                                        style=wx.LC_REPORT | wx.SUNKEN_BORDER)
        self.listCtrlFile.InsertColumn(0, "Name", width=320)
        self.listCtrlFile.InsertColumn(1, "Info", width=125)
        self.buttonAccept = wx.Button(self, wx.ID_ANY, "JOIN")
        self.buttonAccept.Disable()
        self.buttonExit = wx.Button(self, wx.ID_ANY, "EXIT")
        self.log = wx.TextCtrl(self,
                               wx.ID_ANY,
                               size=(300, 100),
                               style=wx.TE_MULTILINE | wx.TE_READONLY
                               | wx.HSCROLL)

        self.__set_properties()
        self.__do_layout()

        self.Bind(wx.EVT_BUTTON, self.OnButtonPath, self.button_1)
        self.Bind(wx.EVT_BUTTON, self.OnButtonAccept, self.buttonAccept)
        self.Bind(wx.EVT_BUTTON, self.OnButtonExit, self.buttonExit)

    def __set_properties(self):
        self.SetTitle("MP4joiner")
        self.textCtrlPath.SetBackgroundColour(wx.Colour(255, 255, 255))

    def check_ffmpeg(self):
        version = subprocess.Popen("ffmpeg -version",
                                   shell=True,
                                   stdin=subprocess.PIPE,
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE)
        output, error = version.communicate()
        while True:
            out = version.stderr.read()
            if not out:
                break
            print(out)
        if output:
            return output.decode("utf-8").split("\n")[0]
        else:
            return False

    def change_ffmpeg(self, label, color):
        self.ffmpeg.SetLabel("FFMPEG : %s" % label)
        self.ffmpeg.SetForegroundColour(color)

    def change_info(self, label):
        self.ffmpeg.SetLabel(label)

    def joiner(self, inFiles, outFile):
        str_files = '|'.join(inFiles)
        process = subprocess.Popen(
            'ffmpeg -i "concat:%s" -vcodec copy -bsf:a aac_adtstoasc "%s/%s"' %
            (str_files.encode('mbcs'),
             self.path.decode('utf-8').encode('mbcs'), outFile),
            shell=True,
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)
        inp, output, error = process.communicate()
        while True:
            output = process.stderr.read()
            if not output:
                print('[End join]')
                break
            print(output)
        if 'failed' in error:
            self.info.SetLabel("Fail on join(((")
            self.info.SetForegroundColour(wx.GREEN)
        self.End = True

    def prepare(self, file, indexWork):
        process = subprocess.Popen(
            'ffmpeg -i "%s" -vcodec copy -bsf:v h264_mp4toannexb -f mpegts "%s/tmp_%s.ts"'
            % (file.encode('mbcs'), self.path.decode('utf-8').encode('mbcs'),
               indexWork),
            shell=True,
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)
        #stdin,stdout, stderr, = process.communicate()
        while True:
            output = process.stderr.read()
            if not output:
                print('[End prepare]')
                break
            print(output)
        self.prepDict[indexWork] = False

    def remove_tmp(self):
        for tmp in glob.glob("%s/tmp_*.ts" % self.path.decode('utf-8')):
            os.remove(tmp)

    def workerPrepare(self):
        self.gauge.SetRange(len(self.files))
        indexWork = 0
        self.remove_tmp()
        for file in self.files:
            self.listCtrlFile.SetItem(indexWork, 1, "Preparing")
            self.prepDict[indexWork] = True
            self.info.SetLabel("Prepare: %s of %s" %
                               (indexWork + 1, len(self.files)))
            th = threading.Thread(target=self.prepare, args=[file, indexWork])
            th.daemon = True
            th.start()
            while self.prepDict[indexWork]:
                time.sleep(1)
            if os.path.isfile("%s/tmp_%s.ts" %
                              (self.path.decode('utf-8'), indexWork)):
                self.gauge.SetValue(indexWork + 1)
                self.listCtrlFile.SetItem(indexWork, 1, "Prepared")
            else:
                self.listCtrlFile.SetItem(indexWork, 1, "Error")
            indexWork += 1
            if len(glob.glob("%s/tmp_*.ts" %
                             self.path.decode('utf-8'))) == len(self.files):
                self.info.SetLabel("Joining, pleasewait")
                outfile = "outFile_%s.mp4" % time.strftime("%Y-%m-%d_%H-%M-%S")
                th = threading.Thread(target=self.joiner,
                                      args=[
                                          glob.glob("%s/tmp_*.ts" %
                                                    self.path.decode('utf-8')),
                                          outfile
                                      ])
                th.daemon = True
                th.start()
                while not self.End:
                    time.sleep(1)
                if os.path.isfile("%s/%s" %
                                  (self.path.decode('utf-8'), outfile)):
                    if not 'Fail' in self.info.GetLabel():
                        self.info.SetLabel("All DONE!!!")
                        self.info.SetForegroundColour(wx.GREEN)
                    self.gauge.SetValue(0)
                    self.buttonAccept.Enable()
                else:
                    self.info.SetLabel("Fail on join(((")
                    self.info.SetForegroundColour(wx.RED)
                self.remove_tmp()

    def change_line(self, index, state):
        self.listCtrlFile.SetItem(index, 1, state)

    def add_line(self, file):
        self.listCtrlFile.InsertItem(self.index, file)
        self.listCtrlFile.SetItem(self.index, 1, "Waiting")
        self.index += 1

    def __do_layout(self):
        mainSizer = wx.BoxSizer(wx.VERTICAL)
        footerSizer = wx.BoxSizer(wx.HORIZONTAL)
        pathSizer = wx.BoxSizer(wx.HORIZONTAL)
        self.SetIcon(self.icon)
        pathSizer.Add(self.labelPath, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 2)
        pathSizer.Add(self.textCtrlPath, 1, wx.LEFT | wx.RIGHT | wx.EXPAND, 3)
        pathSizer.Add(self.button_1, 0, 0, 0)
        mainSizer.Add(pathSizer, 0,
                      wx.ALL | wx.EXPAND | wx.ALIGN_CENTER_VERTICAL, 4)
        mainSizer.Add(self.ffmpeg, 0, wx.ALL, 6)
        mainSizer.Add(self.info, 0, wx.ALL, 7)
        mainSizer.Add(self.gauge, 0, wx.ALL, 8)
        mainSizer.Add(self.labelFile, 0, wx.ALL, 9)
        mainSizer.Add(self.listCtrlFile, 10, wx.ALL | wx.EXPAND, 4)
        mainSizer.Add(self.log, 5, wx.ALL | wx.EXPAND, 4)
        footerSizer.Add(self.buttonAccept, 1, wx.LEFT | wx.RIGHT | wx.EXPAND,
                        3)
        footerSizer.Add(self.buttonExit, 1, wx.LEFT | wx.RIGHT | wx.EXPAND, 3)
        mainSizer.Add(footerSizer, 1, wx.ALL | wx.EXPAND | wx.ALIGN_RIGHT, 2)
        self.SetSizer(mainSizer)
        mainSizer.Fit(self)
        self.Layout()
        redir = RedirectText(self.log)
        sys.stdout = redir
        sys.stderror = redir
        self.version = self.check_ffmpeg()
        if self.version:
            self.change_ffmpeg(self.version.split("Copyright")[0], wx.BLACK)
            self.button_1.Enable()
        else:
            self.change_ffmpeg(
                "Unknown,please install or put bin in main folder", wx.RED)

    def checkNeedSize(self):
        if os.name != 'nt':
            usage = disk_usage(self.path[0])
        else:
            usage = disk_usage('%s:\\' % self.path[0])
        need = sum(map(os.path.getsize, self.files)) * 2
        if need > usage.free:
            self.info.SetLabel("No need free disk space (need %s, free %s)" %
                               (bytes2human(need), bytes2human(usage.free)))
            self.info.SetForegroundColour(wx.RED)
            self.buttonAccept.Disable()

    def OnButtonPath(self, event):
        self.listCtrlFile.DeleteAllItems()
        self.index = 0
        self.info.SetLabel("")
        self.gauge.SetValue(0)
        dlg = wx.DirDialog(self, "Choose a directory:")
        if dlg.ShowModal() == wx.ID_OK:
            self.path = dlg.GetPath().encode('utf-8')
            self.files = glob.glob("%s/*.mp4" % self.path.decode('utf-8'))
            if os.name != 'nt':
                self.files = self.files + glob.glob(
                    "%s/*.MP4" % self.path.decode('utf-8'))
            self.textCtrlPath.Value = self.path.decode('utf-8')
            if len(self.files):
                self.buttonAccept.Enable()
                for file in self.files:
                    self.add_line(ntpath.basename(file))
            else:
                self.buttonAccept.Disable()
            self.checkNeedSize()
        dlg.Destroy()

    def OnButtonAccept(self, event):
        self.buttonAccept.Disable()
        threading.Thread(target=self.workerPrepare).start()
        event.Skip()

    def OnButtonExit(self, event):
        self.Destroy()
示例#3
0
        self.req = req
        self.timeout = timeout
        self.params = params
        Thread.__init__(self)
        self.start()  # start the thread

    def run(self):
        # This is the code executing in the new thread.
        try:
            if self.params != None:
                response = urllib2.urlopen(self.req, self.params, self.timeout)
            else:
                response = urllib2.urlopen(self.req, timeout=self.timeout)
            wx.CallAfter(Publisher.sendMessage,
                         topicName="update",
                         msg=response.read().decode('utf-8'))
        except Exception, e:
            print e
            wx.CallAfter(Publisher.sendMessage,
                         topicName="fail",
                         msg=e.message.decode('utf-8'))


app = wx.App(False)
frame = wx.Frame(None, -1, title=u'接口测试2.0--哥就像巴黎欧莱雅 你值得拥有', size=(800, 600))
# frame.SetIcon(wx.Icon("ayg.ico",wx.BITMAP_TYPE_ICO))
frame.SetIcon(ayg.GetIcon())
panel = ExamplePanel(frame)
frame.Center()
frame.Show()
app.MainLoop()
示例#4
0
wild = "supported files|*.pdf;*.xps;*.oxps;*.epub"

#==============================================================================
# define the file selection dialog
#==============================================================================
dlg = wx.FileDialog(None,
                    message="Choose a file to display",
                    defaultDir=os.path.expanduser("~"),
                    defaultFile="",
                    wildcard=wild,
                    style=wx.OPEN | wx.CHANGE_DIR)

#==============================================================================
# give an icon before we display it
#==============================================================================
dlg.SetIcon(img.GetIcon())

#==============================================================================
# now display and ask for return code in one go
#==============================================================================
# We got a file only when one was selected and OK pressed
if dlg.ShowModal() == wx.ID_OK:
    # This returns a Python list of selected files (we only have one though)
    filename = dlg.GetPaths()[0]
else:
    filename = None

# destroy this dialog
dlg.Destroy()

if filename:
示例#5
0
        self.psizer.Add(self.bitmap,1,wx.ALIGN_CENTER,0)
        self.panel.SetSizer(self.psizer)
        self.sizer=wx.FlexGridSizer(1,1,0,0)
        self.sizer.AddGrowableCol(0)
        self.sizer.AddGrowableRow(0)
        self.sizer.Add(self.panel,1,wx.ALIGN_CENTER,0)
        self.SetSizer(self.sizer)
        self.showimage(title)
        self.panel.Bind(wx.EVT_KEY_DOWN,self.keydown)
        self.panel.Bind(wx.EVT_CHAR,self.keychar)
        self.panel.Bind(wx.EVT_MOTION,self.drag)
        self.panel.Bind(wx.EVT_MOUSE_EVENTS,self.drag)
        self.bitmap.Bind(wx.EVT_MOTION,self.drag)
        self.bitmap.Bind(wx.EVT_MOUSE_EVENTS,self.drag)
        self.Bind(wx.EVT_SIZE,self.fresize)
        if osflag: self._icon=bpglogo.GetIcon()
        else:
            tmp_icon=bpglogo.GetImage()
            tmp_icon.Rescale(32,32,wx.IMAGE_QUALITY_HIGH)
            self._icon=wx.EmptyIcon()
            self._icon.CopyFromBitmap(wx.BitmapFromImage(tmp_icon))
        try: self.SetIcon(self._icon)
        except: pass
        self.Layout()
        self.Center()
        self.panel.SetFocus()

    def loadindex(self,old):
        if self.index!=old:
            self.stitle(_('Loading...'))
            self.showimage(self.filelist[self.index])