How to import a custom style for virtualkeyboard in pyqt? - pyqt

I'm building an Application using PyQt6.4.0 on Ubuntu 20.04 and I intend to customize the style of my virtual keyboard to make it smaller when the user enters some text in a QLineEdit. I've followed these instructions to copy the virtual keyboard binaries into my installation folder.
I tried to follow these instructions when adding a custom keyboard style. Specifically, I copy the built-in styles in src/styles/builtin from the qt virtualkeyboard repository into my PyQt installation folder: [PATH_TO_MY_VENV]/lib/python3.8/site-packages/PyQt6/Qt6/qml/QtQuick/VirtualKeyboard/Styles, and rename the file folder as 'test'. In my script, I set the environment variables:
os.environ["QML2_IMPORT_PATH"] = "[PATH_TO_MY_VENV]/lib/python3.8/site-packages/PyQt6/Qt6/qml"
os.environ["QT_VIRTUALKEYBOARD_STYLE"] = "test"
But I get the following warning, and my custom keyboard style does not appear:
WARNING: Cannot find style "test" - fallback: "default"
Investigating a bit further, I notice on the Qt documentation website that "The directory name can not contain spaces or special characters other than underscore." So I suspected that my pyqt installation path, containing '.' and '-' might've led to an invalid directory name. So I copied the QtQuick directory over to /home/[USERNAME]/ (with no special characters) , add that folder to my QML import path and run my application again:
os.environ["QML2_IMPORT_PATH"] = "/home/[USERNAME]/"
os.environ["QT_VIRTUALKEYBOARD_STYLE"] = "test"
But I get the same warning as above.
I've looked at forums where people struggle with the same issue, such as this, this and this. Tried following their instructions but with not much success. It might've been something I did not pick up while reading - since I'm relatively new to PyQt too.

Related

Tkinter cross-platform compatability

I have written a set of customized tkinter widgets, defined as classes, and loaded into the main app as modules. I am working in Windows 10, but have specific concerns in three areas in regard to compatibility with Linux and Mac. These are shown below.
Fonts
I am sticking with tkinter default fonts, and defining the desired font within each individual custom widget. I have found, surprisingly, that I can successfully specify fonts as follows, naming 'TkDefaultFont' just as I might name 'Arial' for example.
font=('TkDefaultFont',11)
font=('TkDefaultFont',10,'bold')
font=('TkDefaultFont',10,'italic')
Would this approach work across Linux and Mac as well as windows?
Importing modules
All of the resources for my main app are stored in a Folder named 'AppAssets' (which is in the same folder as the main app). The custom widgets are stored inside that folder, in another folder named 'TkMods'. In Windows, I am successfully importing these modules as follows, specifying a relative path:
from AppAssets.TkMods import ModButton
Again, would this work across Linux and Mac? If not, is there a line or lines of code that would work instead across all three platforms?
Importing image files
Many of the modules use custom image files (such as a rounded button image, for example). I am importing these as follows, again specifying a relative path.
btnimg = tk.PhotoImage(file="AppAssets/TkMods/Button.png")
Again, would this work cross-platform? If not, is there a single solution that would work across Windows, Mac and Linux?
Any advice appreciated.
I have found, surprisingly, that I can successfully specify fonts as follows, naming 'TkDefaultFont' just as I might name 'Arial' for example...
Would this approach work across Linux and Mac as well as windows?
It works, but probably not the way you think. You could use 'NotARealFont' instead of 'TkDefaultFont' and get the same results. The first parameter when defining a font as a tuple is a font family, and TkDefaultFont is not the name of a valid font family. It's the name of an internal font object, which is not the same thing. When you don't give a valid font family, tkinter will fall back to using the font defined by TkDefaultFont.
I am successfully importing these modules as follows... Again, would this work across Linux and Mac?
Yes, importing python modules works the same on platforms. This isn't anything unique to tkinter.
Many of the modules use custom image files ... I am importing these as follows, again specifying a relative path... Again, would this work cross-platform?
It should work the same on all platforms. Note that "work the same" also means it will fail in the same way on all platforms. The path is relative to the current working directory which may or may not be the same as the directory with the script.

Default folder missing in Sublime Text 3 directory

After installing Sublime Text 3, I try to use a custom keyboard shortcut (F5) defined in:
~/.config/sublime-text-3/Packages/User/Default (Linux).sublime-keymap
The shortcut doesn't work, and I see in the console the following message:
Unable to open /home/gabriel/.config/sublime-text-3/Packages/Default/Preferences.sublime-settings
Not only this file is missing in ST's install directory, the entire ~/.config/sublime-text-3/Packages/Default/ folder is missing. But If I open Preferences/Key Bindings, the default keymap file is opened correctly:
and the path shown for that file is within the ~/.config/sublime-text-3/Packages/Default/ folder, which I know is not there (!)
What is going on here? How can I fix this?
Why the Key Binding is not working is nothing to do with the default file paths, the directory not existing, or the console errors.
Restart Sublime Text and the Key Binding will work. Enable command logging to see that it's working: in the console sublime.log_commands(True).
Sublime text shouldn't be displaying the paths for those Default package files. The ~/.config/sublime-text-3/Packages/Default/ directory doesn't exist because those files are distributed with Sublime Text, you'll find the files in the the Default package where Sublime Text is installed e.g. /path/to/sublime_text_3/Packages/Default.sublime-package. .sublime-package files are essentially zip files. Ignore those paths, and the error messages in the console. Those are Sublime Text issues.
None of these answers are directly solving the problem you nerds.
For the silicon-challenged, what you need to do is this:
go to the path that it's telling you doesn't exist:
/home/gabriel/.config/sublime-text-3/Packages/Default/Preferences.sublime-settings
You are on the right track to deducing the source of the problem - I have the same problem but It wouldn't allow me to change the font for my text editing. Sublime must have an install problem. I'm on ubuntu 16.04 LTS .
Do this:
a. create the folder, name it "Default" - under "Packages"
b. go to your sublime text and go to preferences -> settings
c. copy everything on the LEFT side (it should be showing a full list of defaults, which you can't edit, and a user changeable file on the right)
d. go to the folder you just made (Default) -> inside it create a file with the exact name "Preferences.sublime-settings"
e. paste everything into it
f. restart sublime text
g. You are now a G
you're welcome
I arrived here via a very similar search for why a directory was not being displayed in sublime text. In case anyone else arrives here from the same search, here's why:
directories that are known to house source control information and various binary output files are automatically excluded from the sidebar
Source: https://forum.sublimetext.com/t/missing-files-in-folder-tree/31145/3

syntax highlight (.tmLanguage) in Sublime Text 3 for packages

I work on this plugin
Syntax highlight does not work with Sublime Text 3 when plugin is installed using package control.
Error loading syntax file "Sublime Text 3/Installed Packages/robot.tmLanguage": Unable to open Sublime Text 3/Installed Packages/robot.tmLanguage
The plugin is under Installed Packcages/Robot Framework Assistant.sublime-package, the file 'robot.tmLanguage' in inside Robot Framework Assistant.sublime-package archive.
Here is how I set paths
https://github.com/andriyko/sublime-robot-framework-assistant/blob/master/rfassistant/init.py
My question is similar to this thread, but in my case the plugin is installed as archive(.sublime-package) not folder with with files.
I am not sure that my path settings mentioned above are correct in python3.
How can I refer to tmLanguage file that is inside .sublime-package file?
Where should I put that file? It is totally confusing why does it work on Sublime Text 2 and Sublime Text 3(when installed into dir from github) but does not work when installed via Package Control.
So, how do I set path to tmLanguage file and where should I store it. Just want to clarify, that it works fine when plugin is installed from github zip file(because I put it's content into RobotFrameworkAssistant folder under Packages directory). It does not work when plugin is installed via Package Control.
Quick summary of my manual solution of adding custom .tmLanguage files based on others' suggestions:
Put the myLang.tmLanguage file into a folder with your desired syntax
name.
Zip the folder so that it's named myLang.zip
Rename the zip archive to myLang.sublime-package
Put the myLang.sublime-package into the Sublime 3 packages folder. It will now appear in the sublime syntax highlighting menu.
Based on ST3 docs, I can't seem to find an alternative to this manual method right now, but it will work.
Package control will likely do everything you need behind the scene
Do you need the content of the tmLanguage file? If so, you shouldn't be accessing it directly. Instead, you should be using sublime.load_resource(name), where name is something like Packages/Robot Framework Assistant/robot.tmLanguage. If you are just trying to set the file syntax, you should be using view.set_syntax_file(syntax_file), where syntax_file is like name for the resource. I did not look at your plugin in detail, so please clarify what you are trying to do if both of those answers are incorrect.
As a side note, based on that error, you would probably see issues in ST2 also. You are only looking at the root packages folder, not in your package.
In ST3, jps decided to make plugins runnable from .sublime-package files, rather than needing to be extracted. These files are simply renamed .zip files. Updates do need to be made if you are accessing resources within your plugin, but the API has been extended to support it.
This isn't a great list, but it covers some of the changes in ST3 from ST2.
http://www.sublimetext.com/docs/3/porting_guide.html
The issue seems to be solved. Please refer to this fix.
Why I had problems with syntax settings(.tmLanguage) in ST3?
Because it is totally confusing and not clear from ST3 docs where that file should be located.
(Even if it says that files lookup is continued in Packages directory if file was not found in Installed Packages).
There are two 'main' folders under Sublime Text 3 directory: Installed Packages and Packages.
When the plugin is installed using Package Control it goes into Installed Packages directory packed into archive file called like Robot Framework Assistant.sublime-package (which is actually ZIP file).
The robot.tmLanguage file (syntax file) is inside Robot Framework Assistant.sublime-package.
So, in few words, my question was: how to refer to that file (what path should be provided to view.set_syntax_file method)?
Unintuitive, but I should refer to non-existent path Packages/Robot Framework Assistant/robot.tmLanguage. Actually, in my case the Packages directory contains only Users folder. The only thing, that I can guess is that folder name should be the same as package name(Robot Framework Assistant in my case).

Where are the default packages in Sublime Text 3 on Ubuntu?

I'm migrating from Sublime Text 2 to 3. In Sublime Text 2, I changed a lot of the default settings of the editor -- such as the tab bar height, sidebar color, etc. -- by modifying the Default.sublime-theme file in sublime-text-2/Packages/Theme - Default. I was also able to modify the colors of the default color schemes in a similar fashion. I've been trying to figure out how to do this for Sublime Text 3, but can't seem to find these files. ~/.config/sublime-text-3 only seems to contain overrides for user settings, not the default settings.
This link on the Sublime Text forums seems to give the location for Windows and Mac, but not for Ubuntu. I've searched a bit to no avail. Does anyone have suggestions?
Thank you!
To amplify on #skuroda's answer - ST3 contains all of its data that, in ST2, was stored in Packages/PackageName, in PackageName.sublime-package files that are basically just zip files, or "Resources" as they're now known. Using PackageResourceViewer, you can easily edit the individual files contained within the resource, then save it back again. When saved, the proper directory structure under Packages/PackageName will be created, allowing you to edit the file directly next time. The way file precedence works in Sublime, any file that exists in ~/.config/sublime-text-3/Packages/PackageName/ will override any file of the same name stored in PackageName.sublime-package.
However, since you don't want these files to be accidentally overwritten, I would suggest creating ~/config/sublime-text-3/Packages/User/Themes/ and User/Color Schemes directories and storing your customized files there instead. The User/ directory is protected from overwrites during upgrades, etc., and unless you're planning on creating a customized theme or color scheme for redistribution through Package Control, it's best practice to keep your files in there.
EDIT
I just realized you hadn't gotten an answer to your original question - where are the files stored? If you installed the .deb file from sublimetext.com, all the .sublime-package files are in /opt/sublime_text/Packages.
If you want the easiest way to save your customized settings first copy all the default settings and paste into a new file named Preferences.sublime-settings.
Then make your changes and save the file to:
/home/**username**/.config/sublime-text-3/Packages/User
In order to see the .config folder you will have to enable show hidden files.
The instructions are written at the top of the default settings list in case you are wondering where got this from.
In the ST console, try entering sublime.executable_path(). This should get you close to where you need to be. Also, you should copy the content of the file out and move them (under a new name to the packages folder). You probably don't want your modifications to be reverted on subsequent update. An alternative method is to try overriding the files you need to. I haven't done that for theme files, so I'm unsure if everything will work as it should. If you take the override route, I'd recommend using PackageResourceViewer. I wrote it to help with browsing/overriding package files in ST3.
You can use
dpkg -L <package name>
For example
dpkg -L subli<tab>
Just open up sublime text, hit ctrl+` to open sublime text console, then run these command accordingly
sublime.packages_path() to see user installed packages directory
sublime.installed_packages_path() to see zipped packages (with .sublime-package file type) directory
Mostly likely, you'll find the Default package inside zipped packages directory.
You can use PackageResourceViewer to see zipped packages's contents as #MattDMo suggested, but more over, you can actually extract zipped packages into user installed package directory directly using PackageResourceViewer's extract command.

Adding CORE PLOT HEADER to the XCODE PROJECT

I can't seem to make Xcode find the Core Plot header. I've done the following:
Clone the hg repo;
Drag the CorePlot-CocoaTouch.xcodeproj file into my project;
Opened the CP project and compiled it successfully;
Dragged the lib file into the target's static link list;
Added CorePlot-CocoaTouch as a direct dependency for the target.
But I'm still getting the "CorePlot-CocoaTouch.h: No such file or directory" error on compile. I've been googling around trying to find an answer, but only seem to find a few people having the same problem but no clear solution. What have I missed?
Please help me getting out of it.....
Thanks
Make sure your header search paths contain a reference to the core-plot source directory.
In your targets Build Settings set Header Search Paths to the core-plot/framework directory. For example when your core-plot directory is placed next to your project directoy the search path would contain a value of ../core-plot/framework/** (I'm using a recursive reference here, thus the ** at the end).
Do not miss :-
1-Do not forget to add the library to Target dependance under the "Targets" source list that appears. Click on the "Build Phases" tab and expand the "Target Dependencies" group. Click on the plus button, select the CorePlot-CocoaTouch library, and click Add. This should ensure that the Core Plot library will be built with your application.
2- Core Plot is built as a static library for iPhone, so you'll need to drag the libCorePlot-CocoaTouch.a static library from under the CorePlot-CocoaTouch.xcodeproj group to the "Link Binaries With Libraries" group within the application target's "Build Phases" group you were just in.
3 Under your Build settings, set the Header Search Paths to the relative path from your application to the framework/ subdirectory within the Core Plot source tree. Make sure to make this header search path recursive. You need to add -ObjC to Other Linker Flags as well (as of Xcode 4.2, -all_load does not seem to be needed, but it may be required for older Xcode versions). -Header Search Paths : you must put the relative path for libCorePlot-CocoaTouch.a and it is too much important to check the recursive check-box.
Finally the following link may can help you...
http://code.google.com/p/core-plot/wiki/UsingCorePlotInApplications
maybe this blog might help more than the google source page of CorePlot.
For newbies it might be helpful to use the mac shell to get the relative path of the libCorePlot-CocoaTouch.a. Just open the Terminal and insert following line:
mdfind -name libCorePlot-CocoaTouch.a
you will get listed all paths that contain the file named "libCorePlot-CocoaTouch.a"

Resources