Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dark theme (updated) #187

Merged
merged 22 commits into from
Nov 19, 2021
Merged

Fix dark theme (updated) #187

merged 22 commits into from
Nov 19, 2021

Conversation

lapp0
Copy link
Collaborator

@lapp0 lapp0 commented Nov 16, 2021

Built on top of #172

Fixes #141

Changes:

  • Remove all coloring except from "status circles". Coloring entire QListWidgetItems, QGroupBox's, and buttons doesn't work well with dark themes.
  • Change yellow and green shade
  • Use QStyledItemDelegate to create OptionListItemDelegate which handles rendering of both editable and uneditable navlist items. This delegate allows the placement of icons, status circles, text, and extra text.

image

image

@lapp0
Copy link
Collaborator Author

lapp0 commented Nov 17, 2021

@milahu could you please review? nix run github:nix-gui/nix-gui/fix-dark-theme should show nix-gui with these changes. Breeze-dark isn't working on my end.

@lapp0 lapp0 mentioned this pull request Nov 17, 2021
@milahu
Copy link
Contributor

milahu commented Nov 18, 2021

nix run github:nix-gui/nix-gui/fix-dark-theme should show nix-gui with these changes

throws

Traceback (most recent call last):
  File "/nix/store/y68c4556haqnc99kkqk22is6msfvh1sd-python3.9-nix-gui-0.1.2/lib/python3.9/site-packages/nixui/graphics/nav_interface.py", line 54, in set_lookup_key
    self.set_option_path(
  File "/nix/store/y68c4556haqnc99kkqk22is6msfvh1sd-python3.9-nix-gui-0.1.2/lib/python3.9/site-packages/nixui/graphics/nav_interface.py", line 88, in set_option_path
    num_children = len(api.get_option_tree().children(option_path, mode="leaves"))
  File "/nix/store/y68c4556haqnc99kkqk22is6msfvh1sd-python3.9-nix-gui-0.1.2/lib/python3.9/site-packages/nixui/utils/cache.py", line 85, in wrapper
    res = function(*args, **kwargs)
  File "/nix/store/y68c4556haqnc99kkqk22is6msfvh1sd-python3.9-nix-gui-0.1.2/lib/python3.9/site-packages/nixui/options/api.py", line 27, in get_option_tree
    convert_type_str_to_type_obj(
  File "/nix/store/y68c4556haqnc99kkqk22is6msfvh1sd-python3.9-nix-gui-0.1.2/lib/python3.9/site-packages/nixui/options/api.py", line 21, in convert_type_str_to_type_obj
    option_data_dict[key]['type'] = types.from_nix_type_str(option_data_dict[key]['type'])
  File "/nix/store/y68c4556haqnc99kkqk22is6msfvh1sd-python3.9-nix-gui-0.1.2/lib/python3.9/site-packages/nixui/options/types.py", line 26, in from_nix_type_str
    from_nix_type_str(nix_type_str.removeprefix('list of ').removesuffix('s'))
  File "/nix/store/y68c4556haqnc99kkqk22is6msfvh1sd-python3.9-nix-gui-0.1.2/lib/python3.9/site-packages/nixui/options/types.py", line 216, in from_nix_type_str
    raise ValueError(nix_type_str)
ValueError: string, with spaces inside double quotes

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/nix/store/y68c4556haqnc99kkqk22is6msfvh1sd-python3.9-nix-gui-0.1.2/bin/.nix-gui-wrapped", line 9, in <module>
    sys.exit(main())
  File "/nix/store/y68c4556haqnc99kkqk22is6msfvh1sd-python3.9-nix-gui-0.1.2/lib/python3.9/site-packages/nixui/main.py", line 69, in main
    run_program()
  File "/nix/store/y68c4556haqnc99kkqk22is6msfvh1sd-python3.9-nix-gui-0.1.2/lib/python3.9/site-packages/nixui/main.py", line 50, in run_program
    nix_gui = main_window.NixGuiMainWindow(statemodel)
  File "/nix/store/y68c4556haqnc99kkqk22is6msfvh1sd-python3.9-nix-gui-0.1.2/lib/python3.9/site-packages/nixui/graphics/main_window.py", line 17, in __init__
    nav_interface.OptionNavigationInterface(statemodel=statemodel)
  File "/nix/store/y68c4556haqnc99kkqk22is6msfvh1sd-python3.9-nix-gui-0.1.2/lib/python3.9/site-packages/nixui/graphics/nav_interface.py", line 39, in __init__
    self.set_lookup_key(starting_lookup_key)
  File "/nix/store/y68c4556haqnc99kkqk22is6msfvh1sd-python3.9-nix-gui-0.1.2/lib/python3.9/site-packages/nixui/graphics/nav_interface.py", line 63, in set_lookup_key
    self.revert_to_previous_lookup_key()
  File "/nix/store/y68c4556haqnc99kkqk22is6msfvh1sd-python3.9-nix-gui-0.1.2/lib/python3.9/site-packages/nixui/graphics/nav_interface.py", line 43, in revert_to_previous_lookup_key
    previous_uri = self.uri_stack.pop()
IndexError: pop from an empty deque

@lapp0
Copy link
Collaborator Author

lapp0 commented Nov 18, 2021

I assume you're on nixos-unstable? We don't have handling for that type string which was introduced 3 months ago as I've been developing based on <nixpkgs/nixos> 21.05 https://github.com/NixOS/nixpkgs/blame/0281ba6ace51fbf468aed8286f8c619ed25b5f01/nixos/modules/system/boot/kernel.nix#L88

The branch speed-up-startup loads types at runtime rather than at startup and incorporates the changes from this PR. So, you could smoke test this PRs changes with nix run github:nix-gui/nix-gui/speed-up-startup.

This further highlights the hackyness of resolving option types from their type string. Fortunately there is an issue to fix this. The new type system will not rely on parsing type strings, rather it will extract them in lib.nix. #180

@lapp0 lapp0 mentioned this pull request Nov 18, 2021
@milahu
Copy link
Contributor

milahu commented Nov 18, 2021

I assume you're on nixos-unstable?

yepp, i have pinned nixpkgs in /etc/nixos/flake.nix

you could smoke test this PRs changes with nix run github:nix-gui/nix-gui/speed-up-startup

throws

INFO:Retrieving option values for module "/etc/nixos/configuration.nix"
Traceback (most recent call last):
  File "nix-gui-0.1.2/bin/.nix-gui-wrapped", line 9, in <module>
    sys.exit(main())
  File "nix-gui-0.1.2/lib/python3.9/site-packages/nixui/main.py", line 69, in main
    run_program()
  File "nix-gui-0.1.2/lib/python3.9/site-packages/nixui/main.py", line 50, in run_program
    nix_gui = main_window.NixGuiMainWindow(statemodel)
  File "nix-gui-0.1.2/lib/python3.9/site-packages/nixui/graphics/main_window.py", line 17, in __init__
    nav_interface.OptionNavigationInterface(statemodel=statemodel)
  File "nix-gui-0.1.2/lib/python3.9/site-packages/nixui/graphics/nav_interface.py", line 39, in __init__
    self.set_lookup_key(starting_lookup_key)
  File "nix-gui-0.1.2/lib/python3.9/site-packages/nixui/graphics/nav_interface.py", line 54, in set_lookup_key
    self.set_option_path(
  File "nix-gui-0.1.2/lib/python3.9/site-packages/nixui/graphics/nav_interface.py", line 88, in set_option_path
    num_children = len(api.get_option_tree().children(option_path, mode="leaves"))
  File "nix-gui-0.1.2/lib/python3.9/site-packages/nixui/utils/cache.py", line 85, in wrapper
    res = function(*args, **kwargs)
  File "nix-gui-0.1.2/lib/python3.9/site-packages/nixui/options/api.py", line 24, in get_option_tree
    parser.get_all_option_values(configuration_path)
  File "nix-gui-0.1.2/lib/python3.9/site-packages/nixui/utils/cache.py", line 85, in wrapper
    res = function(*args, **kwargs)
  File "nix-gui-0.1.2/lib/python3.9/site-packages/nixui/options/parser.py", line 65, in get_all_option_values
    for attr_loc, value_node in get_key_value_nodes(module_path, tree).items():
  File "nix-gui-0.1.2/lib/python3.9/site-packages/nixui/options/parser.py", line 160, in get_key_value_nodes
    for attr, attr_data in nix_eval.get_modules_defined_attrs(module_path).items():
  File "nix-gui-0.1.2/lib/python3.9/site-packages/nixui/utils/cache.py", line 85, in wrapper
    res = function(*args, **kwargs)
  File "nix-gui-0.1.2/lib/python3.9/site-packages/nixui/options/nix_eval.py", line 108, in get_modules_defined_attrs
    leaves = nix_instantiate_eval(f'{fn} {module_path}', strict=True)
  File "nix-gui-0.1.2/lib/python3.9/site-packages/nixui/options/nix_eval.py", line 61, in nix_instantiate_eval
    return nix_instantiate_eval(expr, strict, show_trace=True)
  File "nix-gui-0.1.2/lib/python3.9/site-packages/nixui/options/nix_eval.py", line 68, in nix_instantiate_eval
    raise NixEvalError(err_str)
nixui.options.nix_eval.NixEvalError: NixEvalError("""
error: attribute 'services' missing

       at /etc/nixos/configuration.nix:393:48:

          392|       locations."/".extraConfig = ''
          393|         proxy_pass http://localhost:${toString config.services.nix-serve.port};
             |                                                ^
          394|         proxy_set_header Host $host;
(use '--show-trace' to show detailed location information)

""")

are you still using nix-instantiate to get the config schema?
why not use nix repl as i suggested in #176 (comment)
you just have to emulate a tty terminal (pseudo-terminal, pty)
and manage a request queue (that is missing in my code) to block parallel requests

@lapp0
Copy link
Collaborator Author

lapp0 commented Nov 18, 2021

Yes, we're still using nix-instantiate. nix repl would be better because it wouldn't need to load <nixpkgs/nixos> each time, but I don't think it would resolve this issue.

The error is probably due to config being an empty attribute set: https://github.com/nix-gui/nix-gui/blob/master/nixui/nix/lib.nix#L47

Could you please clarify whether you defined an option using config recently, or if this is a regression and the program was previously able to handle your configuration.nix?

@lapp0 lapp0 mentioned this pull request Nov 18, 2021
@lapp0
Copy link
Collaborator Author

lapp0 commented Nov 18, 2021

I managed to reproduce your error and then fix it in 426925b

Please try nix run github:nix-gui/nix-gui/call-module-fn-with-config

@milahu
Copy link
Contributor

milahu commented Nov 18, 2021

better : )

nix build github:nix-gui/nix-gui/call-module-fn-with-config
QT_STYLE_OVERRIDE=Adwaita-Dark ./result/bin/nix-gui

Adwaita-Dark is included in pyqt5 themes, compared to breeze-dark
pyqt5 has its own qt libs in /nix/store/*-python3.9-PyQt5-5.15.4/lib/python3.9/site-packages/PyQt5/

output
INFO:Retrieving option values for module "/etc/nixos/configuration.nix"
INFO:Retrieving option values for module "/etc/nixos/hardware-configuration.nix"
ERROR:Error evaluating (modulesPath + "/installer/scan/not-detected.nix"):
error=NixEvalError("""
error: undefined variable 'modulesPath'

       at «string»:1:2:

            1| (modulesPath + "/installer/scan/not-detected.nix")
             |  ^

""")
ERROR:failed to load element 0 of 
[ (modulesPath + "/installer/scan/not-detected.nix")
    ]
qt.glx: qglx_findConfig: Failed to finding matching FBConfig for QSurfaceFormat(version 2.0, options QFlags<QSurfaceFormat::FormatOption>(), depthBufferSize -1, redBufferSize 1, greenBufferSize 1, blueBufferSize 1, alphaBufferSize -1, stencilBufferSize -1, samples -1, swapBehavior QSurfaceFormat::SingleBuffer, swapInterval 1, colorSpace QSurfaceFormat::DefaultColorSpace, profile  QSurfaceFormat::NoProfile)
No XVisualInfo for format QSurfaceFormat(version 2.0, options QFlags<QSurfaceFormat::FormatOption>(), depthBufferSize -1, redBufferSize 1, greenBufferSize 1, blueBufferSize 1, alphaBufferSize -1, stencilBufferSize -1, samples -1, swapBehavior QSurfaceFormat::SingleBuffer, swapInterval 1, colorSpace QSurfaceFormat::DefaultColorSpace, profile  QSurfaceFormat::NoProfile)
Falling back to using screens root_visual.

undefined variable 'modulesPath' is from using flakes to pin nixpkgs

@lapp0
Copy link
Collaborator Author

lapp0 commented Nov 18, 2021

Thanks for reproducing and sharing a screenshot!

It's a bit concerning that the unselected text is dark. Perhaps fixing that should be a separate issue? I think it's in a much better state for merging, but I'm not sure why the text is black. Do you get the same result for Breeze-dark?

Regarding your error

I get the error too and I don't have a flakes based configuration.nix. In fact, if you run the command with nix run nix-gui -- -n -c nix-gui/nixui/tests/sample/configuration.nix you also get the error. modulesPath is passed to /etc/nixos/configuration.nix and all imports in lib.nix: https://github.com/nix-gui/nix-gui/blob/master/nixui/nix/lib.nix#L48

Could you elaborate on what is causing the issue and how it may be fixed?

Regarding reproducing dark mode,

I'm not sure pyqt5 has Adwaita, I can't find it anyways.

grep -R Adwaita /nix/store/mfjz98dkvzmslrb2p2vg0bcy6f3661pv-python3.9-PyQt5-5.15.2/lib/python3.9/site-packages/PyQt5 (no output)

And when I try to set the environment variable QT_STYLE_OVERRIDE, I get

QApplication: invalid style override 'Adwaita-dark' passed, ignoring it.
	Available styles: Windows, Fusion

Perhaps you already had Adwaita-dark in your environment?

#175

@milahu
Copy link
Contributor

milahu commented Nov 19, 2021

dark theme

Perhaps you already had Adwaita-dark in your environment?

yepp ...

on xfce desktop, Adwaita-dark is the default dark theme, which should be in gnome-themes-extra

QT_STYLE_OVERRIDE=Adwaita-dark nix-gui

Do you get the same result for Breeze-dark?

cant get it working on xfce desktop : /
maybe need to restart display-manager.service but meh

on plasma desktop, breeze-dark is the default dark theme, which should be in breeze-qt5

QT_STYLE_OVERRIDE=breeze-dark nix-gui

qt5 theme can be configured with qt5ct

QT_QPA_PLATFORMTHEME=qt5ct-style QT_STYLE_OVERRIDE= qt5ct
QT_STYLE_OVERRIDE=qt5ct-style nix-gui

i hope one of these works for you ; )

other pyqt5 apps

ideally, nix-gui should just use the system theme
this works for other pyqt5 apps
this did work until i updated my system ... probably i must restart display-manager.service

for example convertall (nixpkgs)

nix-shell -p convertall
convertall

@lapp0
Copy link
Collaborator Author

lapp0 commented Nov 19, 2021

modulesPath is derived from the NIX_PATH env var

Yes, we should change Nix-Gui to get modulesPath using get_nixpath_element

New issues:

modulesPath is currently set wrong in https://github.com/nix-gui/nix-gui/blob/master/nixui/nix/lib.nix#L48 however it is set. So we shouldn't have error: undefined variable, even if your NIX_PATH is worg. I'd expect another error since the wrong modulesPath is passed.

edit: the error seems gone now

That is probably because the result was cached so logs weren't reproduced. #148

You can run again with diskcache off (-n) to reproduce.

Themes

Trying your suggestions.

@milahu
Copy link
Contributor

milahu commented Nov 19, 2021

Do you get the same result for Breeze-dark?

same for QT_STYLE_OVERRIDE=kvantum-dark nix-gui

install qt kvantum theme with

#qtstyleplugin-kvantum-qt4
libsForQt5.qtstyleplugin-kvantum

@lapp0 lapp0 mentioned this pull request Nov 19, 2021
@lapp0
Copy link
Collaborator Author

lapp0 commented Nov 19, 2021

Nice, that one actually has the dark theme available! Thanks.

#205

I think we should resolve this in a separate issue. #206

Could you approve if it looks fine otherwise?

@milahu
Copy link
Contributor

milahu commented Nov 19, 2021

#205

same error. text color flips between black and white by random
the text-rendering looks complex, cant we use a table?

@lapp0
Copy link
Collaborator Author

lapp0 commented Nov 19, 2021

#205 just documents the smoke testing instructions.

#206 is fixed in #207

I tried with a table first for this PR but that doesn't work cleanly because we can't select and edit the entire row. QStyledItemDelegate allows us to paint (or use the default of) the EditRole and DisplayRole .

I think the delegate model is a better match and I'd rather try fixing the text rendering there.

The branch fix-dark-on-dark-text works on my end. Seems the changes from painting the status circle were bleeding over to the text rendering.

c595421

@milahu
Copy link
Contributor

milahu commented Nov 19, 2021

fixed : )

@lapp0 lapp0 merged commit f904529 into master Nov 19, 2021
@milahu
Copy link
Contributor

milahu commented Nov 19, 2021

#208

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve look and feel for dark themes
2 participants