Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei47w committed Jun 11, 2024
1 parent efe2fbe commit 4aac6cc
Show file tree
Hide file tree
Showing 15 changed files with 306 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ message(STATUS "SCOPY_RESOURCE_FILES: " ${SCOPY_RESOURCE_FILES})
option(ENABLE_TRANSLATION "Enable translation" ON)
include(ScopyTranslation)


find_package(Python3 COMPONENTS Interpreter)
message("------------------------------${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/pyScripts/main.py ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}")
execute_process(COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/pyScripts/main.py ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
execute_process(COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/pyScripts/json.py ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})



if(ENABLE_TRANSLATION)
generate_translations()
qt_add_resources(SCOPY_RESOURCES ${CMAKE_BINARY_DIR}/translations.qrc)
Expand Down
5 changes: 4 additions & 1 deletion gui/src/plotwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "DisplayPlot.h"
#include "plotaxis.h"
#include "style_variables.h"

#include <QDebug>
#include <QLabel>
Expand All @@ -20,6 +21,7 @@
#include <customqwtscaledraw.hpp>
#include <osc_scale_engine.h>
#include <pluginbase/preferences.h>
#include <style.h>

using namespace scopy;

Expand Down Expand Up @@ -56,7 +58,8 @@ PlotWidget::PlotWidget(QWidget *parent)
setAxisScalesVisible(true);

// Plot needs a grid
QPen gridpen(QColor("#353537"));
qss::button::test;
QPen gridpen((QColor(theme::dark::highlight)));
EdgelessPlotGrid *d_grid = new EdgelessPlotGrid();
QColor majorPenColor(gridpen.color());
d_grid->setMajorPen(majorPenColor, 1.0, Qt::DashLine);
Expand Down
42 changes: 42 additions & 0 deletions plugins/testplugin/include/testplugin/scopy-testplugin_export.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

#ifndef SCOPY_TESTPLUGIN_EXPORT_H
#define SCOPY_TESTPLUGIN_EXPORT_H

#ifdef SCOPY_TESTPLUGIN_STATIC_DEFINE
# define SCOPY_TESTPLUGIN_EXPORT
# define SCOPY_TESTPLUGIN_NO_EXPORT
#else
# ifndef SCOPY_TESTPLUGIN_EXPORT
# ifdef scopy_testplugin_EXPORTS
/* We are building this library */
# define SCOPY_TESTPLUGIN_EXPORT __attribute__((visibility("default")))
# else
/* We are using this library */
# define SCOPY_TESTPLUGIN_EXPORT __attribute__((visibility("default")))
# endif
# endif

# ifndef SCOPY_TESTPLUGIN_NO_EXPORT
# define SCOPY_TESTPLUGIN_NO_EXPORT __attribute__((visibility("hidden")))
# endif
#endif

#ifndef SCOPY_TESTPLUGIN_DEPRECATED
# define SCOPY_TESTPLUGIN_DEPRECATED __attribute__ ((__deprecated__))
#endif

#ifndef SCOPY_TESTPLUGIN_DEPRECATED_EXPORT
# define SCOPY_TESTPLUGIN_DEPRECATED_EXPORT SCOPY_TESTPLUGIN_EXPORT SCOPY_TESTPLUGIN_DEPRECATED
#endif

#ifndef SCOPY_TESTPLUGIN_DEPRECATED_NO_EXPORT
# define SCOPY_TESTPLUGIN_DEPRECATED_NO_EXPORT SCOPY_TESTPLUGIN_NO_EXPORT SCOPY_TESTPLUGIN_DEPRECATED
#endif

#if 0 /* DEFINE_NO_DEPRECATED */
# ifndef SCOPY_TESTPLUGIN_NO_DEPRECATED
# define SCOPY_TESTPLUGIN_NO_DEPRECATED
# endif
#endif

#endif /* SCOPY_TESTPLUGIN_EXPORT_H */
56 changes: 56 additions & 0 deletions pyScripts/json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import os
import main


def parse_json_file(filepath):
with open(filepath, 'r') as file:
content = file.read()

content = content.strip()
if content[0] != '{' or content[-1] != '}':
raise ValueError(f"Invalid JSON format in file {filepath}")

json_content = {}
content = content[1:-1].strip() # Remove the outer braces
items = content.split(',')

for item in items:
key, value = item.split(':')
key = key.strip().strip('"')
value = value.strip().strip('"')
json_content[key] = os.path.relpath(filepath, style_folder).replace("/", "_").replace(file_extension, "") + "_" + key

return json_content


def generate_variable(filepath, indent):
with open(filepath, 'r') as file:
if len(file.read()) == 0:
return ''

json = parse_json_file(filepath)

variable = ""
for key in json:
variable += indent + 'const char* ' + key + ' = "' + json[key] + '";\n'

return variable[:-1]


if __name__ == "__main__":
import sys

if len(sys.argv) != 3:
print("Usage: python generate_json_header.py <input_folder> <output_file>")
sys.exit(1)
source_folder = sys.argv[1]
build_folder = sys.argv[2]

header_name = "style_variables.h"
header_path = source_folder + "/gui/include/gui/style_variables.h"
file_extension = '.json'
style_folder = source_folder + "/style"

namespace_structure = main.create_namespace_structure(style_folder, file_extension)
namespace_code = main.generate_namespace_code(namespace_structure, generate_variable)
main.write_header_file(header_path, namespace_code, header_name)
97 changes: 97 additions & 0 deletions pyScripts/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import os
import sys


def create_namespace_structure(folder, file_extension):
namespace_structure = {}

for dirpath, dirnames, filenames in os.walk(folder):
qss_files = [f for f in filenames if f.endswith(file_extension)]
if qss_files:
relative_path = os.path.relpath(dirpath, folder)
namespace_structure[relative_path] = {
os.path.splitext(f)[0]: os.path.join(dirpath, f).replace('\\', '/')
for f in qss_files
}

return namespace_structure


def replace_property(filepath, value):
search_text = "&&property&&"
with open(filepath, 'r') as file:
data = file.read()
data = data.replace(search_text, value)

with open(qss_path, 'a') as file:
file.write(data)


def generate_variable(filepath, indent):
value = os.path.relpath(filepath, qss_folder).replace("/", "_").replace(file_extension, "")
replace_property(filepath, value)

return f'{indent}const char* ' + os.path.basename(filepath).replace(file_extension, '') + f' = "{value}";'


def generate_namespace_code(namespace_structure, variable_func):
code_lines = []

def add_namespaces(path_parts, files, level):
indent = '\t' * level
code_lines.append(f'{indent}namespace {path_parts[level]} {{')
if level + 1 == len(path_parts):
for filename, filepath in files.items():
code_lines.append(variable_func(filepath, f'{indent}\t'))
else:
subnamespace = {k: v for k, v in namespace_structure.items() if
k.startswith('/'.join(path_parts[:level + 1]) + '/')}
if subnamespace:
for subpath, subfiles in subnamespace.items():
subpath_parts = subpath.split(os.sep)
add_namespaces(subpath_parts, subfiles, level + 1)
code_lines.append(f'{indent}}} // namespace {path_parts[level]}')

root_parts = sorted(namespace_structure.keys(), key=lambda x: x.count(os.sep))
added_namespaces = set()

for root_path in root_parts:
path_parts = root_path.split(os.sep)
if path_parts[0] not in added_namespaces:
add_namespaces(path_parts, namespace_structure[root_path], 0)
added_namespaces.add(path_parts[0])

return '\n'.join(code_lines)


def write_header_file(output_file, namespace_code, name):
def_name = name.upper().replace(".", "_")

with open(output_file, 'w') as f:
f.write("#ifndef " + def_name + "\n")
f.write("#define " + def_name + "\n")
f.write("#include <scopy-gui_export.h>\n\n")
f.write(namespace_code)
f.write("\n\n#endif // " + def_name + "\n")


# https://stackoverflow.com/questions/49018868/how-do-i-make-cmake-run-a-python-script-before-building-in-order-to-generate-fi


if __name__ == "__main__":
if len(sys.argv) != 3:
print("Error")
sys.exit(1)

source_folder = sys.argv[1]
build_folder = sys.argv[2]

header_name = "style.h"
header_path = source_folder + "/gui/include/gui/" + header_name
qss_path = build_folder + "/style.qss"
qss_folder = source_folder + "/style"
file_extension = '.qss'

open(qss_path, 'w')
namespace_code = generate_namespace_code(create_namespace_structure(qss_folder, file_extension), generate_variable)
write_header_file(header_path, namespace_code, header_name)
Empty file.
Empty file added style/json/globals/scripts.json
Empty file.
14 changes: 14 additions & 0 deletions style/qss/button/square.qss
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
QLabel[&&property&&="true"] {
background-color: &transparent&; // rgba(255, 255, 255, 0)

&add_font_small&
// color: white;
// font-weight: 500;
// font-family: Open Sans;
// font-size: 12px;
// font-style: normal;
}

QLabel[&&property&&="true"]:disabled {
color: &color_highlight_2&; // grey
}
3 changes: 3 additions & 0 deletions style/qss/button/test.qss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
QPushButton[&&property&&=true]{
size: 2px
}
Empty file.
26 changes: 26 additions & 0 deletions style/qss/label/big.qss
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
QPushButton[&&property&&="true"] {
width: &unit_pixel_1&; // 48px
height: &unit_pixel_1&; // 48px

&add_border_small&
// border-radius: 0px 2px 2px 0px;
// border-style: outset;

qproperty-iconSize: &1pixel_unit&; // 48px
background-color: &color_highlight_1&; // #272730

&add_font_small&
// color: white;
// font-weight: 700;
// font-size: 14px;

height: &unit_pixel_1&;
}

QPushButton[&&property&&="true"]:checked {
background-color: &color_highlight_2&; // #4A64FF
}

QPushButton[&&property&&="true"]:pressed {
background-color: &color_highlight_2&; // #4A64FF
}
26 changes: 26 additions & 0 deletions style/qss/label/medium.qss
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
QPushButton[&&property&&="true"] {
width: &unit_pixel_1&; // 48px
height: &unit_pixel_1&; // 48px

&add_border_small&
// border-radius: 0px 2px 2px 0px;
// border-style: outset;

qproperty-iconSize: &1pixel_unit&; // 48px
background-color: &color_highlight_1&; // #272730

&add_font_small&
// color: white;
// font-weight: 700;
// font-size: 14px;

height: &unit_pixel_1&;
}

QPushButton[&&property&&="true"]:checked {
background-color: &color_highlight_2&; // #4A64FF
}

QPushButton[&&property&&="true"]:pressed {
background-color: &color_highlight_2&; // #4A64FF
}
26 changes: 26 additions & 0 deletions style/qss/label/small.qss
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
QPushButton[&&property&&="true"] {
width: &unit_pixel_1&; // 48px
height: &unit_pixel_1&; // 48px

&add_border_small&
// border-radius: 0px 2px 2px 0px;
// border-style: outset;

qproperty-iconSize: &1pixel_unit&; // 48px
background-color: &color_highlight_1&; // #272730

&add_font_small&
// color: white;
// font-weight: 700;
// font-size: 14px;

height: &unit_pixel_1&;
}

QPushButton[&&property&&="true"]:checked {
background-color: &color_highlight_2&; // #4A64FF
}

QPushButton[&&property&&="true"]:pressed {
background-color: &color_highlight_2&; // #4A64FF
}
4 changes: 4 additions & 0 deletions style/theme/dark/colors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"background": "#121212",
"highlight" : "#890000"
}
Empty file added style/theme/light/colors.json
Empty file.

0 comments on commit 4aac6cc

Please sign in to comment.