Skip to content

Commit

Permalink
Export layout as svg
Browse files Browse the repository at this point in the history
  • Loading branch information
groig committed Sep 14, 2022
1 parent 9e607f8 commit b69f857
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/main/python/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import platform
from json import JSONDecodeError

from PyQt5.QtCore import Qt, QSettings, QStandardPaths, QTimer, QT_VERSION_STR
from PyQt5.QtCore import Qt, QSettings, QStandardPaths, QTimer, QT_VERSION_STR, QSize
from PyQt5.QtWidgets import QWidget, QComboBox, QToolButton, QHBoxLayout, QVBoxLayout, QMainWindow, QAction, qApp, \
QFileDialog, QDialog, QTabWidget, QActionGroup, QMessageBox, QLabel
from PyQt5.QtGui import QPainter
from PyQt5.QtSvg import QSvgGenerator

import os
import sys
Expand Down Expand Up @@ -147,6 +149,10 @@ def init_menu(self):
layout_save_act.setShortcut("Ctrl+S")
layout_save_act.triggered.connect(self.on_layout_save)

layout_export_svg = QAction(tr("MenuFile", "Export layout as svg..."), self)
layout_export_svg.setShortcut("Ctrl+I")
layout_export_svg.triggered.connect(self.on_layout_export_svg)

sideload_json_act = QAction(tr("MenuFile", "Sideload VIA JSON..."), self)
sideload_json_act.triggered.connect(self.on_sideload_json)

Expand All @@ -164,6 +170,7 @@ def init_menu(self):
file_menu = self.menuBar().addMenu(tr("Menu", "File"))
file_menu.addAction(layout_load_act)
file_menu.addAction(layout_save_act)
file_menu.addAction(layout_export_svg)
file_menu.addSeparator()
file_menu.addAction(sideload_json_act)
file_menu.addAction(download_via_stack_act)
Expand Down Expand Up @@ -248,6 +255,28 @@ def on_layout_save(self):
with open(dialog.selectedFiles()[0], "wb") as outf:
outf.write(self.keymap_editor.save_layout())

def on_layout_export_svg(self):
dialog = QFileDialog()
dialog.setDefaultSuffix("svg")
dialog.setAcceptMode(QFileDialog.AcceptSave)
dialog.setNameFilters(["Keymap image (*.svg)"])
if dialog.exec_() == QDialog.Accepted:
generator = QSvgGenerator()
generator.setSize(QSize(self.keymap_editor.container.width, self.keymap_editor.container.height * self.keymap_editor.keyboard.layers))
generator.setFileName(dialog.selectedFiles()[0])
generator.setTitle("My Keymap")
generator.setDescription("Keymap generated from Vial")
painter = QPainter()
painter.begin(generator)
current_layer = self.keymap_editor.current_layer
for x in range(self.keymap_editor.keyboard.layers):
self.keymap_editor.switch_layer(x)
self.keymap_editor.container.render(painter)
painter.translate(0, self.keymap_editor.container.height)
self.keymap_editor.switch_layer(current_layer)
painter.end()


def on_click_refresh(self):
self.autorefresh.update(quiet=False, hard=True)

Expand Down

0 comments on commit b69f857

Please sign in to comment.