UI线程与其他线程之间使用处理程序进行通信(Communication between UI thread and other threads using handler)
如何在UI线程和后台线程之间进行线程间通信? 我想在这里使用通用处理程序概念来更新我的UI。 我有如下概念
new Thread(new Runnable() { public void run() { while (mProgressStatus < 100) { mProgressStatus = doWork(); // Update the progress bar mHandler.post(new Runnable() { public void run() { mProgress.setProgress(mProgressStatus); } }); } } }).start();
我想使用两个类,一个类包含主线程,另一个类包含后台线程,它们使用相同的处理程序。 我该如何实现? 我知道这很常见,但我发现很难完全实现。
How to do inter thread communication between UI thread and background thread? I want use common handler concept here to update my UI. I have the concept as below
new Thread(new Runnable() { public void run() { while (mProgressStatus < 100) { mProgressStatus = doWork(); // Update the progress bar mHandler.post(new Runnable() { public void run() { mProgress.setProgress(mProgressStatus); } }); } } }).start();
I want to use two classes, one class contains main thread, another class contains background thread and they use the same handler. How do I implement this? I know it is very common but I am finding it difficult to exactly implement.
原文:https://stackoverflow.com/questions/42475812
更新时间:2023-12-11 10:12
最满意答案
相关问答
更多-
你可以使用matplotlib pgf后端来做到这一点。 然后你可以在序言中使用不同的包。 在这种情况下,我正在使用pdfcomment。 这是一个非常简单的例子,但我认为你可以从这里出发! import matplotlib as mpl mpl.use("pgf") pgf_with_pdflatex = { "pgf.texsystem": "pdflatex", "pgf.preamble": [ r"\usepackage[author={me}]{pdfcomme ...
-
我建议pyPdf 。 它的工作非常好 前几天我也写了一篇博文,你可以在这里找到。 I suggest pyPdf. It works really nice. I also wrote a blog post some while ago, you can find it here.
-
使用PHP合并PDF文件(Merge PDF files with PHP [closed])[2022-04-28]
我以前做过这个。 我有一个使用fpdf生成的pdf,我需要添加一个可变量的PDF。 所以我已经有一个fpdf对象和页面设置(http://www.fpdf.org/)我使用fpdi来导入文件(http://www.setasign.de/products/pdf-php-solutions/ fpdi /)通过扩展PDF类添加FDPI: class PDF extends FPDI { } $pdffile = "Filename.pdf"; $pagecount = $pdf-> ... -
Python PDF库[已关闭](Python PDF library [closed])[2022-10-08]
想到的两个是: pyPdf2 PDFMiner The two that come to mind are: pyPdf2 PDFMiner -
从python创建pdf(create pdf from python)[2022-05-07]
从ask.yahoo借来的 如果PDF文件是1.1版本的PDF文件,则该文件以“%PDF-1.1”开头。 如果没有存储二进制数据对象,您可以阅读PDF文件,如果您不需要在其中存储二进制对象,例如绘制位图,则甚至可以使用记事本制作一个。 但在看到“%PDF-1.1”后,忽略之后的内容(Adobe Reader也会这样做),直接到文件末尾,在那里有一行说“%% EOF”。 这总是文件中的最后一件事; 如果在那里,你知道在文件之前只有几个字符,那么后面跟着一个数字就是“startxref”。 该数字告诉读者程序在 ... -
有一个解决方案 。 如果我没记错的话,关键点是: 使用特殊的目录作为主文档(我使用index_TOC.rst而不是默认的index.rst ):在conf.py master_doc = 'index_TOC' latex_documents = [('index_TOC', 'uncertaintiesPythonpackage.tex',…] 新的目录文件index_TOC.rst包含ToC之类的 TOC === .. toctree:: :hidden: :maxdepth: 1 ...
-
在您的第一个块中,以二进制写入模式(wb)打开文件,因为您正在向其写入二进制文件。 另外,你不需要将它明确地转换为str。 它应该是这样的: file = open('code.txt', 'wb') for line in open('somefile.pdf', 'rb').readlines(): file.write(line) file.close() 对于第二个块,以读取二进制模式(rb)打开文件。 这里也不需要显式地转换为字节。 它应该是这样的: file = open('new.p ...
-
编辑:我刚刚遇到了兼容Python 3的Django Easy PDF,可能更有用: https://github.com/nigma/django-easy-pdf 但请注意,在编写此xhtml2pdf时 ,如果您安装最新的beta版本,那么Django Easy PDF的依赖项仅支持Python 3: pip install --pre xhtml2pdf WeasyPrint与Python 3兼容: http://weasyprint.org/ 它是一个很棒的库,很容易与Django集成。 这是一篇 ...
-
下面的代码应该正确地对完整的文件名进行排序,假设您更新的代码(基于salomonderossi和Byte Commander的答案中的代码)确实显示了正确的常用文件名部分。 请注意,此代码未经测试。 如果您在问题中提供了一小组典型的文件名,那么我们写答案会更容易。 这不仅有助于我们更好地理解任务,而且还可以更轻松地测试我们的代码。 import os import fnmatch files_result = [] for root, dirnames, files in os.walk(r'C:\PAT ...
-
使用PDFMiner(Python)和在线pdf文件。(Using PDFMiner (Python) with online pdf files. Encode the url?)[2022-03-17]
好吧,我终于找到了解决方案, 我使用了Request和StringIO并取消了open('my_file', 'rd')命令 from urllib2 import Request from StringIO import StringIO url = 'my_url' open = urllib2.urlopen(Request(url)).read() memoryFile = StringIO(open) parser = PDFParser(memoryFile) 这样Python就将url ...