diff --git a/NoiceGRUB.py b/NoiceGRUB.py
index 21d1729..9b38921 100644
--- a/NoiceGRUB.py
+++ b/NoiceGRUB.py
@@ -18,11 +18,27 @@
console.print(table)
richprint("[cyan bold][ 0 ][/cyan bold] [green bold]Instructions for creating a preset[/green bold]")
-choice = IntPrompt.ask("[yellow]Choice[/yellow]",choices=[str(i) for i in range(len(os.listdir('presets'))+1)])
-if choice==0:
+choice = IntPrompt.ask("[yellow]Choice[/yellow]",choices=[str(i) for i in range(len(preset_dict)+1)])
+if choice == 0:
console.print(Markdown(open('noicegrub/createpreset.md').read()))
exit()
+
+print()
preset = get_preset(preset_dict[choice])
+table = preset_info_table(preset)
+console.print(table)
+font_file = preset[1]['font_family']
+if not os.path.exists(f'./fonts/{font_file}'):
+ richprint(f'[red bold][Error] {font_file} is not present in ./fonts/ [/red bold]')
+ exit()
+choice = Confirm.ask("[yellow bold]Would you like to customise the font ?[/yellow bold]")
+if choice:
+ table,fonts = font_table()
+ console.print(table)
+ font_choice = IntPrompt.ask("[yellow]Choice[/yellow]",choices=[str(i) for i in range(1,len(fonts)+1)])
+ preset[1]['font_family'] = fonts[font_choice]
+ font_size = IntPrompt.ask("[yellow]Font size in pixels (integer) [/yellow]")
+ preset[1]['selection_font'] = font_size
if preset[0]=='Kewl': NgCommonProps(preset).export_theme()
elif preset[0]=='Noice': NgNoiceTemplate(preset).export_theme()
@@ -30,7 +46,10 @@
elif preset[0]=='Mountains': NgMountainsTemplate(preset).export_theme()
elif preset[0]=='Nico': NgNicoTemplate(preset).export_theme()
-richprint('\n[green bold]Executing scripts/install.sh ... [/green bold]')
-os.system('chmod +x ./scripts/install.sh')
-os.system('sudo ./scripts/install.sh')
-richprint('[green bold]Thankyou for using NoiceGRUB[/green bold]')
\ No newline at end of file
+richprint('\n[cyan bold]Generated theme has been placed in ./export/ [/cyan bold]')
+choice = Confirm.ask("[yellow bold]Would you like to install the theme ?[/yellow bold]")
+if choice:
+ richprint('\n[green bold]Executing scripts/install.sh ... [/green bold]')
+ os.system('chmod +x ./scripts/install.sh')
+ os.system('sudo ./scripts/install.sh')
+richprint('[green bold]Done[/green bold]')
\ No newline at end of file
diff --git a/README.md b/README.md
index b372a9c..63565eb 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
# NoiceGRUB
-#### NoiceGRUB is a collection of linear gradient based GRUB2 themes that can be customised. By default NoiceGRUB comes with 4 templates and 8 presets.
+#### NoiceGRUB is a collection of linear gradient based GRUB2 themes that can be customised. By default NoiceGRUB comes with 5 templates and 10 presets.
# Contents
* [**Installation**][1]
* [**Presets**][2]
@@ -18,7 +18,8 @@ python3 NoiceGRUB.py
```
## [Presets][2]
### [Create Your Own Preset][3]
-NoiceGRUB preset files have the syntax of TOML and ends with `.toml` extension. Your own preset shall be placed in `presets` folder. It will be shown in the preset menu when you execute `NoiceGRUB.py`
+NoiceGRUB preset files have the syntax of TOML and ends with `.toml` extension. Your own preset shall be placed in `presets` folder. It will be shown in the preset menu when you execute `NoiceGRUB.py`
+Fonts are placed in `fonts` folder. User defined fonts should be place in this folder to be recognised by NoiceGRUB
#### File format
```toml
template='template name here'
@@ -30,6 +31,8 @@ secondary="secondary gradient colour"
header_font_colour = "header font colour or 'BOOTMENU' text colour"
footer_font_colour = "footer font colour or GRUB keymap text colour"
selection_bg_colour = "backgound colour of selection highlighter"
+selection_font = "font size in pixels (integer)"
+font_family = ".ttf or .otf font filename"
# This section defines theme.txt file and is mandatory too
[theme]
diff --git a/fonts/InterRegular.ttf b/fonts/InterRegular.ttf
new file mode 100644
index 0000000..5e4851f
Binary files /dev/null and b/fonts/InterRegular.ttf differ
diff --git a/fonts/NicoMojiRegular.ttf b/fonts/NicoMojiRegular.ttf
new file mode 100644
index 0000000..a303c7f
Binary files /dev/null and b/fonts/NicoMojiRegular.ttf differ
diff --git a/fonts/Unifont.otf b/fonts/Unifont.otf
new file mode 100644
index 0000000..8ea8530
Binary files /dev/null and b/fonts/Unifont.otf differ
diff --git a/img/screenshot.png b/img/screenshot.png
index 2b4864c..6bee0db 100644
Binary files a/img/screenshot.png and b/img/screenshot.png differ
diff --git a/noicegrub/__init__.py b/noicegrub/__init__.py
index 664c6d8..ce4b66b 100644
--- a/noicegrub/__init__.py
+++ b/noicegrub/__init__.py
@@ -5,12 +5,14 @@ def get_preset(name):
data=toml.load(open(f'./presets/{name}.toml'))
return [data[i] for i in data]
+
+#================= rich tables
def preset_table():
preset_dict={}
files=os.listdir('presets')
files.sort()
table = Table(title="Available Presets")
- table.add_column("No", justify="right", style="cyan", no_wrap=True)
+ table.add_column("No.", justify="right", style="cyan", no_wrap=True)
table.add_column("Preset", justify="left", style="green", no_wrap=True)
table.add_column("Template", justify="left", style="green", no_wrap=True)
presets=[{i.split('.')[0]:toml.load(open(f'presets/{i}'))['template']} for i in files]
@@ -20,6 +22,32 @@ def preset_table():
preset_dict[presets.index(i)+1]=preset
return table,preset_dict
+def preset_info_table(preset_conf):
+ table = Table(title="Selected Preset Info")
+ table.add_column("Template",justify="left", style="cyan", no_wrap=True)
+ table.add_column("Font Family",justify="left", style="green", no_wrap=True)
+ table.add_column("Size (pixels)",justify="left", style="green", no_wrap=True)
+ table.add_row(preset_conf[0],preset_conf[1]['font_family'],preset_conf[1]['selection_font'])
+ return table
+
+def font_table():
+ print()
+ fonts={}
+ files=os.listdir('fonts')
+ table = Table(title="Available Fonts")
+ table.add_column("No.",justify="right", style="cyan", no_wrap=True)
+ table.add_column("Font Family",justify="left", style="green", no_wrap=True)
+ for i in range(len(files)):
+ fonts[i+1]=files[i]
+ table.add_row(str(i+1),files[i])
+ return table,fonts
+
+#=================
+
+def gen_font_name(font_name,size):
+ font_name=font_name.split('.')
+ return f"export/{font_name[0]}.{size}.{font_name[1]}"
+
banner = '''
o o o .oPYo. .oPYo. o o .oPYo.
8b 8 8 8 8 `8 8 8 8 `8
@@ -28,4 +56,4 @@ def preset_table():
8 `b8 8 8 8 8 . 8. 8 8 8 8 8 8 8 8
8 `8 `YooP' 8 `YooP' `Yooo' `YooP8 8 8 `YooP' 8oooP'
..:::..:.....::..:.....::.....::....8 :..:::..:.....::......:
-:::::::: @1337kid ::::::::::::::::::8 ::::::: v1.8.3 ::::::::\n'''
\ No newline at end of file
+:::::::: @1337kid ::::::::::::::::::8 :::::::: v2.0 :::::::::\n'''
\ No newline at end of file
diff --git a/noicegrub/template/__init__.py b/noicegrub/template/__init__.py
index 365b105..f3ed00e 100644
--- a/noicegrub/template/__init__.py
+++ b/noicegrub/template/__init__.py
@@ -1,7 +1,8 @@
-import os
+import os,shutil
import xmltodict
import cairosvg
-from noicegrub.templateconf import header_footer_placement,item_placement
+from noicegrub.templateconf import header_footer_placement,item_placement,calc_selection_scale
+from noicegrub import gen_font_name
class NgCommonProps():
def __init__(self,preset):
@@ -27,8 +28,10 @@ def set_common_props(self):
self.svg_temp['svg']['defs']['linearGradient'][0]['stop'][1]['@stop-color']=self.common_props['secondary']
def export_theme(self):
- if not os.path.exists('export'): os.mkdir('export')
+ if os.path.exists('export'): shutil.rmtree('export')
+ os.mkdir('export')
#============ background.png
+
open('temp.svg','w').write(xmltodict.unparse(self.svg_temp,pretty=True))
'''
When unparsing, xmltodict changes the order of elements.
@@ -42,18 +45,25 @@ def export_theme(self):
png=cairosvg.svg2png(url='temp.svg')
open('./export/background.png','wb').write(png)
os.remove('temp.svg')
- #============ menu box selection background colour
- filenames=['select_c','select_e','select_w']
+
+ #============ menu box selection background colour & font
+
+ height,new_scale = calc_selection_scale(self.common_props['selection_font'])
+ filenames = ['select_c','select_e','select_w']
for i in filenames:
- svg_temp=xmltodict.parse(open(f'template/{i}.svg').read())
+ svg_temp = xmltodict.parse(open(f'template/{i}.svg').read())
svg_temp['svg']['path']['@fill']=self.common_props['selection_bg_colour']
open('temp.svg','w').write(xmltodict.unparse(svg_temp))
- cairosvg.svg2png(url='temp.svg', write_to=f'./export/{i}.png')
+ cairosvg.svg2png(url='temp.svg', write_to=f'./export/{i}.png',scale=new_scale)
os.remove('temp.svg')
+ shutil.copy(f"fonts/{self.common_props['font_family']}", gen_font_name(self.common_props['font_family'],self.common_props['selection_font']))
+
#============ theme.txt config file
+
font_colour,selection_font_colour,label_colour = self.theme_txt_conf['font_colour'],self.theme_txt_conf['selection_font_colour'],self.theme_txt_conf['label_colour']
- config=open('template/theme.txt').read()
- config=config.replace('{font_colour}',f'"{font_colour}"')
- config=config.replace('{selection_font_colour}',f'"{selection_font_colour}"')
- config=config.replace('{label_colour}',f'"{label_colour}"')
+ config = open('template/theme.txt').read()
+ config = config.replace('{font_colour}',f'"{font_colour}"')
+ config = config.replace('{selection_font_colour}',f'"{selection_font_colour}"')
+ config = config.replace('{label_colour}',f'"{label_colour}"')
+ config = config.replace('{selection_height}',f'{height}')
open('./export/theme.txt','w').write(config)
\ No newline at end of file
diff --git a/noicegrub/templateconf.py b/noicegrub/templateconf.py
index 67800eb..3267085 100644
--- a/noicegrub/templateconf.py
+++ b/noicegrub/templateconf.py
@@ -1,3 +1,5 @@
+from math import floor
+
item_placement={
'Kewl':[4,6],
'Noice':[3,9],
@@ -11,4 +13,11 @@
'TheMan':[6,5],
'Mountains':[1,4],
'Nico':[None,None],
-}
\ No newline at end of file
+}
+
+def calc_selection_scale(font_size):
+ height = 30.0
+ def_fontsize = 16.0
+ new_height = float(font_size)*(height/def_fontsize)
+ size = floor(new_height/height)
+ return (new_height, size)
\ No newline at end of file
diff --git a/presets/GradientGuy.toml b/presets/GradientGuy.toml
index 0c7c006..917cca4 100644
--- a/presets/GradientGuy.toml
+++ b/presets/GradientGuy.toml
@@ -6,6 +6,8 @@ secondary = "#031C20"
header_font_colour = "#fff"
footer_font_colour = "#fff"
selection_bg_colour = "#6C2082"
+selection_font = "32"
+font_family = "InterRegular.ttf"
[theme]
font_colour = "#fff"
diff --git a/presets/LightLime.toml b/presets/LightLime.toml
index aca0d7f..ff5675c 100644
--- a/presets/LightLime.toml
+++ b/presets/LightLime.toml
@@ -6,6 +6,8 @@ secondary = "#FFFB7D"
header_font_colour = "#fff"
footer_font_colour = "#fff"
selection_bg_colour = "#A7ED9A"
+selection_font = "32"
+font_family = "InterRegular.ttf"
[theme]
font_colour = "#fff"
diff --git a/presets/Mountains.toml b/presets/Mountains.toml
index 3646e29..92a68f3 100644
--- a/presets/Mountains.toml
+++ b/presets/Mountains.toml
@@ -6,6 +6,8 @@ secondary = "#6D0470"
header_font_colour = "#4662C8"
footer_font_colour = "#8027A9"
selection_bg_colour = "#4E31A0"
+selection_font = "32"
+font_family = "InterRegular.ttf"
[theme]
font_colour = "#000"
diff --git a/presets/Mountains2.toml b/presets/Mountains2.toml
index d1a2ffa..a4929d3 100644
--- a/presets/Mountains2.toml
+++ b/presets/Mountains2.toml
@@ -6,6 +6,8 @@ secondary = "#00BE9C"
header_font_colour = "#4AF2C0"
footer_font_colour = "#63D2C5"
selection_bg_colour = "#57F2CD"
+selection_font = "32"
+font_family = "InterRegular.ttf"
[theme]
font_colour = "#000"
diff --git a/presets/NicoBlue.toml b/presets/NicoBlue.toml
index db8b433..fde3ff7 100644
--- a/presets/NicoBlue.toml
+++ b/presets/NicoBlue.toml
@@ -6,6 +6,8 @@ secondary = "#470B6C"
header_font_colour = "#000"
footer_font_colour = "#000"
selection_bg_colour = "#4441EC"
+selection_font = "32"
+font_family = "NicoMojiRegular.ttf"
[theme]
font_colour = "#000"
diff --git a/presets/NicoPurple.toml b/presets/NicoPurple.toml
index daa03f3..2efd8a6 100644
--- a/presets/NicoPurple.toml
+++ b/presets/NicoPurple.toml
@@ -6,6 +6,8 @@ secondary = "#6211A1"
header_font_colour = "#000"
footer_font_colour = "#000"
selection_bg_colour = "#A349DA"
+selection_font = "32"
+font_family = "NicoMojiRegular.ttf"
[theme]
font_colour = "#000"
diff --git a/presets/Noice.toml b/presets/Noice.toml
index b230016..dc5e3df 100644
--- a/presets/Noice.toml
+++ b/presets/Noice.toml
@@ -6,6 +6,8 @@ secondary="#3A7385"
header_font_colour = "#D4B3FF"
footer_font_colour = "#1F1A1A"
selection_bg_colour = "#D4B5FB"
+selection_font = "32"
+font_family = "InterRegular.ttf"
[theme]
font_colour = "#000"
diff --git a/presets/TheSky.toml b/presets/TheSky.toml
index da0227a..14d3da5 100644
--- a/presets/TheSky.toml
+++ b/presets/TheSky.toml
@@ -6,6 +6,8 @@ secondary = "#80D0C7"
header_font_colour = "#fff"
footer_font_colour = "#fff"
selection_bg_colour = "#61BAEA"
+selection_font = "32"
+font_family = "InterRegular.ttf"
[theme]
font_colour = "#fff"
diff --git a/presets/VioBlue.toml b/presets/VioBlue.toml
index 0974279..5bc00fd 100644
--- a/presets/VioBlue.toml
+++ b/presets/VioBlue.toml
@@ -6,6 +6,8 @@ secondary = "#1C3D92"
header_font_colour = "#fff"
footer_font_colour = "#fff"
selection_bg_colour = "#D594F4"
+selection_font = "32"
+font_family = "InterRegular.ttf"
[theme]
font_colour = "#fff"
diff --git a/presets/WildFire.toml b/presets/WildFire.toml
index fc2a3bc..f65609e 100644
--- a/presets/WildFire.toml
+++ b/presets/WildFire.toml
@@ -6,6 +6,8 @@ secondary = "#A59508"
header_font_colour = "#fff"
footer_font_colour = "#fff"
selection_bg_colour = "#E64B19"
+selection_font = "32"
+font_family = "InterRegular.ttf"
[theme]
font_colour = "#fff"
diff --git a/scripts/install.sh b/scripts/install.sh
index 318558f..98dd034 100755
--- a/scripts/install.sh
+++ b/scripts/install.sh
@@ -13,15 +13,32 @@ get_path() {
fi
}
+makefont() {
+ font=$(ls ./export | grep -E '.ttf|.otf')
+ size=$(echo $font | awk -F '.' '{print $2}')
+ name="$(echo $font | awk -F '.' '{print $1}').pf2"
+ if [[ $(which grub2-mkfont) != "" ]];then
+ grub2-mkfont -s $size -o $THEME_PATH/$name ./export/$font 2>/dev/null
+ else
+ grub-mkfont -s $size -o $THEME_PATH/$name ./export/$font 2>/dev/null
+ fi
+ echo $name
+}
install() {
printf "\033[92m[+] \033[94mCreating $THEME_PATH\n"
+ rm -r $THEME_PATH 2> /dev/null
mkdir -p $THEME_PATH
printf "\033[92m[+] \033[94mCopying files\n"
cp ./export/* $THEME_PATH
+
+ #======== /etc/default/grub config file
sed -i 's/.*GRUB_THEME=.*//' /etc/default/grub
- echo "GRUB_THEME=$THEME_PATH/theme.txt" >> /etc/default/grub
- #
+ echo "GRUB_THEME=$THEME_PATH/theme.txt" >> /etc/default/grub #theme location
+ font_name=$(makefont)
+ sed -i 's/.*GRUB_FONT=.*//' /etc/default/grub
+ echo "GRUB_FONT=$THEME_PATH/$font_name" >> /etc/default/grub #font location
+
#========= GRUB update
#
printf "\033[92m[+] \033[94mUpdating GRUB config\n\033[92m"
@@ -58,8 +75,5 @@ fi
get_path
THEME_PATH=$GRUB_PATH"themes/noicegrub"
printf "\033[1m\033[93m"
-read -p "Do you want to place the generated theme in $GRUB_PATH [y/n] " inst
-case $inst in
- [Yy]* ) install;;
- * ) exit;;
-esac
\ No newline at end of file
+echo "Generated theme will be placed in $THEMES_PATH"
+install
\ No newline at end of file
diff --git a/template/theme.txt b/template/theme.txt
index 85bf70e..716d318 100644
--- a/template/theme.txt
+++ b/template/theme.txt
@@ -17,7 +17,7 @@ terminal-border: "0"
item_color = {font_colour}
selected_item_color = {selection_font_colour}
selected_item_pixmap_style = "select_*.png"
- item_height = 30
+ item_height = {selection_height}
item_padding = 2
item_spacing = 5
}