Tuesday, 1 December 2020

Can PyMacs be used to display graphics in an Emacs window?

Pymacs (Documentation) allows you to write plugins for Emacs in Python.

Is it possible to write an Emacs plugin in PyMacs which displays graphics in an Emacs window (using one of the graphics libraries available for Python)?

Update 1: Here is the result of the minimal example:

Minimal graphics example

In the upper right Emacs window, an ellipse, a rectangle and/or a line is displayed by code written, primarily, in Python.



from Can PyMacs be used to display graphics in an Emacs window?

Android Searchview : Open suggestions list dropdown by default

The following code allows to display a small suggestion window in my searchview :

enter image description here

I'm searching a way to display this view at the beginning by default when the user click on the search item on the menu.

Is there any way to force this behavior ?

val from = arrayOf(SearchManager.SUGGEST_COLUMN_TEXT_1)
        val to = intArrayOf(R.id.item_label)
        val cursorAdapter = SimpleCursorAdapter(context, R.layout.search_item, null, from, to, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER)
        val suggestions = listOf("Apple", "Blueberry", "Carrot", "Daikon")

        searchView.suggestionsAdapter = cursorAdapter

        searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
            override fun onQueryTextSubmit(query: String?): Boolean {
                hideKeyboard()
                return false
            }

            override fun onQueryTextChange(query: String?): Boolean {
                val cursor = MatrixCursor(arrayOf(BaseColumns._ID, SearchManager.SUGGEST_COLUMN_TEXT_1))

                query?.let {
                    suggestions.forEachIndexed { index, suggestion ->
                        if (suggestion.contains(query, true)) {
                            cursor.addRow(arrayOf(index, suggestion))
                        }
                    }
                }

                cursorAdapter.changeCursor(cursor)
                return true
            }
        })

        searchView.setOnSuggestionListener(object: SearchView.OnSuggestionListener {
            override fun onSuggestionSelect(position: Int): Boolean {
                return false
            }

            override fun onSuggestionClick(position: Int): Boolean {
                hideKeyboard()
                val cursor = searchView.suggestionsAdapter.getItem(position) as Cursor
                val selection = cursor.getString(cursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_1))
                searchView.setQuery(selection, false)

                // Do something with selection
                return true
            }
        })


from Android Searchview : Open suggestions list dropdown by default

Error installing pretrained models for pytorch

I'm working on a Windows 10 machine (yes, I know, don't laugh!), and with python 3.7, and I'm trying to install the pretrained models here:

https://github.com/meliketoy/fine-tuning.pytorch

The commands that the website suggests are:

$ git clone https://github.com/Cadene/pretrained-models.pytorch.git
$ pretrained-models.pytorch
$ python setup.py install

Although the website says this is for Python 3.5, and I have 3.7, I think the 3.7 version should be back-compatible, right?

I successfully ran the git clone, and the pretrained-models.pytorch was actually a cd command (which threw me for a loop for a second!). Then I ran into trouble with python setup.py install

The error I'm getting is:

[Errno 2] No such file or directory: 'build\\bdist.win-amd64\\egg\\pretrainedmodels\\models\\resnext_features\\__pycache__\\resnext101_32x4d_features.cpython-37.pyc.1702181039952'

How can I fix this error?

EDIT (in response to a comment): Someone asked for the full traceback. Here it is!

(base) G:\>python setup.py install
running install
running bdist_egg
running egg_info
creating pretrainedmodels.egg-info
writing pretrainedmodels.egg-info\PKG-INFO
writing dependency_links to pretrainedmodels.egg-info\dependency_links.txt
writing requirements to pretrainedmodels.egg-info\requires.txt
writing top-level names to pretrainedmodels.egg-info\top_level.txt
writing manifest file 'pretrainedmodels.egg-info\SOURCES.txt'
reading manifest file 'pretrainedmodels.egg-info\SOURCES.txt'
writing manifest file 'pretrainedmodels.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
running build_py
creating build
creating build\lib
creating build\lib\pretrainedmodels
copying pretrainedmodels\utils.py -> build\lib\pretrainedmodels
copying pretrainedmodels\version.py -> build\lib\pretrainedmodels
copying pretrainedmodels\__init__.py -> build\lib\pretrainedmodels
creating build\lib\pretrainedmodels\datasets
copying pretrainedmodels\datasets\utils.py -> build\lib\pretrainedmodels\datasets
copying pretrainedmodels\datasets\voc.py -> build\lib\pretrainedmodels\datasets
copying pretrainedmodels\datasets\__init__.py -> build\lib\pretrainedmodels\datasets
creating build\lib\pretrainedmodels\models
copying pretrainedmodels\models\bninception.py -> build\lib\pretrainedmodels\models
copying pretrainedmodels\models\cafferesnet.py -> build\lib\pretrainedmodels\models
copying pretrainedmodels\models\dpn.py -> build\lib\pretrainedmodels\models
copying pretrainedmodels\models\fbresnet.py -> build\lib\pretrainedmodels\models
copying pretrainedmodels\models\inceptionresnetv2.py -> build\lib\pretrainedmodels\models
copying pretrainedmodels\models\inceptionv4.py -> build\lib\pretrainedmodels\models
copying pretrainedmodels\models\nasnet.py -> build\lib\pretrainedmodels\models
copying pretrainedmodels\models\nasnet_mobile.py -> build\lib\pretrainedmodels\models
copying pretrainedmodels\models\pnasnet.py -> build\lib\pretrainedmodels\models
copying pretrainedmodels\models\polynet.py -> build\lib\pretrainedmodels\models
copying pretrainedmodels\models\resnext.py -> build\lib\pretrainedmodels\models
copying pretrainedmodels\models\senet.py -> build\lib\pretrainedmodels\models
copying pretrainedmodels\models\torchvision_models.py -> build\lib\pretrainedmodels\models
copying pretrainedmodels\models\utils.py -> build\lib\pretrainedmodels\models
copying pretrainedmodels\models\vggm.py -> build\lib\pretrainedmodels\models
copying pretrainedmodels\models\wideresnet.py -> build\lib\pretrainedmodels\models
copying pretrainedmodels\models\xception.py -> build\lib\pretrainedmodels\models
copying pretrainedmodels\models\__init__.py -> build\lib\pretrainedmodels\models
creating build\lib\pretrainedmodels\models\resnext_features
copying pretrainedmodels\models\resnext_features\resnext101_32x4d_features.py -> build\lib\pretrainedmodels\models\resnext_features
copying pretrainedmodels\models\resnext_features\resnext101_64x4d_features.py -> build\lib\pretrainedmodels\models\resnext_features
copying pretrainedmodels\models\resnext_features\__init__.py -> build\lib\pretrainedmodels\models\resnext_features
creating build\bdist.win-amd64
creating build\bdist.win-amd64\egg
creating build\bdist.win-amd64\egg\pretrainedmodels
creating build\bdist.win-amd64\egg\pretrainedmodels\datasets
copying build\lib\pretrainedmodels\datasets\utils.py -> build\bdist.win-amd64\egg\pretrainedmodels\datasets
copying build\lib\pretrainedmodels\datasets\voc.py -> build\bdist.win-amd64\egg\pretrainedmodels\datasets
copying build\lib\pretrainedmodels\datasets\__init__.py -> build\bdist.win-amd64\egg\pretrainedmodels\datasets
creating build\bdist.win-amd64\egg\pretrainedmodels\models
copying build\lib\pretrainedmodels\models\bninception.py -> build\bdist.win-amd64\egg\pretrainedmodels\models
copying build\lib\pretrainedmodels\models\cafferesnet.py -> build\bdist.win-amd64\egg\pretrainedmodels\models
copying build\lib\pretrainedmodels\models\dpn.py -> build\bdist.win-amd64\egg\pretrainedmodels\models
copying build\lib\pretrainedmodels\models\fbresnet.py -> build\bdist.win-amd64\egg\pretrainedmodels\models
copying build\lib\pretrainedmodels\models\inceptionresnetv2.py -> build\bdist.win-amd64\egg\pretrainedmodels\models
copying build\lib\pretrainedmodels\models\inceptionv4.py -> build\bdist.win-amd64\egg\pretrainedmodels\models
copying build\lib\pretrainedmodels\models\nasnet.py -> build\bdist.win-amd64\egg\pretrainedmodels\models
copying build\lib\pretrainedmodels\models\nasnet_mobile.py -> build\bdist.win-amd64\egg\pretrainedmodels\models
copying build\lib\pretrainedmodels\models\pnasnet.py -> build\bdist.win-amd64\egg\pretrainedmodels\models
copying build\lib\pretrainedmodels\models\polynet.py -> build\bdist.win-amd64\egg\pretrainedmodels\models
copying build\lib\pretrainedmodels\models\resnext.py -> build\bdist.win-amd64\egg\pretrainedmodels\models
creating build\bdist.win-amd64\egg\pretrainedmodels\models\resnext_features
copying build\lib\pretrainedmodels\models\resnext_features\resnext101_32x4d_features.py -> build\bdist.win-amd64\egg\pretrainedmodels\models\resnext_features
copying build\lib\pretrainedmodels\models\resnext_features\resnext101_64x4d_features.py -> build\bdist.win-amd64\egg\pretrainedmodels\models\resnext_features
copying build\lib\pretrainedmodels\models\resnext_features\__init__.py -> build\bdist.win-amd64\egg\pretrainedmodels\models\resnext_features
copying build\lib\pretrainedmodels\models\senet.py -> build\bdist.win-amd64\egg\pretrainedmodels\models
copying build\lib\pretrainedmodels\models\torchvision_models.py -> build\bdist.win-amd64\egg\pretrainedmodels\models
copying build\lib\pretrainedmodels\models\utils.py -> build\bdist.win-amd64\egg\pretrainedmodels\models
copying build\lib\pretrainedmodels\models\vggm.py -> build\bdist.win-amd64\egg\pretrainedmodels\models
copying build\lib\pretrainedmodels\models\wideresnet.py -> build\bdist.win-amd64\egg\pretrainedmodels\models
copying build\lib\pretrainedmodels\models\xception.py -> build\bdist.win-amd64\egg\pretrainedmodels\models
copying build\lib\pretrainedmodels\models\__init__.py -> build\bdist.win-amd64\egg\pretrainedmodels\models
copying build\lib\pretrainedmodels\utils.py -> build\bdist.win-amd64\egg\pretrainedmodels
copying build\lib\pretrainedmodels\version.py -> build\bdist.win-amd64\egg\pretrainedmodels
copying build\lib\pretrainedmodels\__init__.py -> build\bdist.win-amd64\egg\pretrainedmodels
byte-compiling build\bdist.win-amd64\egg\pretrainedmodels\datasets\utils.py to utils.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\pretrainedmodels\datasets\voc.py to voc.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\pretrainedmodels\datasets\__init__.py to __init__.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\pretrainedmodels\models\bninception.py to bninception.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\pretrainedmodels\models\cafferesnet.py to cafferesnet.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\pretrainedmodels\models\dpn.py to dpn.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\pretrainedmodels\models\fbresnet.py to fbresnet.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\pretrainedmodels\models\inceptionresnetv2.py to inceptionresnetv2.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\pretrainedmodels\models\inceptionv4.py to inceptionv4.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\pretrainedmodels\models\nasnet.py to nasnet.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\pretrainedmodels\models\nasnet_mobile.py to nasnet_mobile.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\pretrainedmodels\models\pnasnet.py to pnasnet.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\pretrainedmodels\models\polynet.py to polynet.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\pretrainedmodels\models\resnext.py to resnext.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\pretrainedmodels\models\resnext_features\resnext101_32x4d_features.py to resnext101_32x4d_features.cpython-37.pyc
error: [Errno 2] No such file or directory: 'build\\bdist.win-amd64\\egg\\pretrainedmodels\\models\\resnext_features\\__pycache__\\resnext101_32x4d_features.cpython-37.pyc.1702181039952'


from Error installing pretrained models for pytorch