Skip to content

Commit

Permalink
fix windows build
Browse files Browse the repository at this point in the history
  • Loading branch information
piksel committed Feb 25, 2021
1 parent 2a29687 commit aa65194
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 61 deletions.
18 changes: 9 additions & 9 deletions barcode/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

from barcode import __release__

try:
import Image, ImageDraw, ImageFont
except ImportError:
try:
from PIL import Image, ImageDraw, ImageFont # lint:ok
except ImportError:
import sys
sys.stderr.write('PIL not found. Image output disabled.\n\n')
Image = ImageDraw = ImageFont = None # lint:ok
# try:
# import Image, ImageDraw, ImageFont
# except ImportError:
# try:
# from PIL import Image, ImageDraw, ImageFont # lint:ok
# except ImportError:
# import sys
# sys.stderr.write('PIL not found. Image output disabled.\n\n')
Image = ImageDraw = ImageFont = None # lint:ok


def mm2px(mm, dpi=300):
Expand Down
101 changes: 54 additions & 47 deletions gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from PyQt5.QtCore import Qt, pyqtSignal, QDir, QModelIndex, QSortFilterProxyModel
from PyQt5.QtGui import QPixmap, QImage, QStandardItemModel, QPainter, QColor, QDragEnterEvent, QDropEvent, \
QStandardItem, QFont, QKeySequence
QStandardItem, QFont, QKeySequence, QIcon
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton, QLabel, QFileDialog, QHBoxLayout, \
QTreeView, QGroupBox, QInputDialog, QMessageBox, QMainWindow, QMenuBar, QAction, QComboBox, QFileSystemModel, QMenu, \
QButtonGroup, QDialog, QTextEdit, QScrollArea, QBoxLayout, QSizePolicy
Expand All @@ -25,6 +25,17 @@
from printables.text import TextData, Text
from settings import Settings

if os.name == 'nt':
is_win = True
is_linux = False
is_mac = False
else:
import sys
is_win = False
plat = sys.platform.lower()
is_mac = plat[:6] == 'darwin'
is_linux = not is_mac


class ModelCol(Enum):
TYPE = 0
Expand All @@ -47,7 +58,6 @@ def name(self):


class ItemView(QTreeView):

rowMoved = pyqtSignal(int, int, name='rowMoved')

def itemFromIndex(self, index):
Expand Down Expand Up @@ -75,6 +85,7 @@ def dropEvent(self, e: QDropEvent) -> None:

self.rowMoved.emit(old_row, new_row)


def make_props_empty(parent):
print('####################### CREATING EMPTY ######################')
widget = QLabel('No item selected', parent)
Expand All @@ -83,7 +94,6 @@ def make_props_empty(parent):


class PyTouchCubeGUI(QMainWindow):

item_selected = None
props_current = None
printer_select = None
Expand All @@ -95,18 +105,17 @@ def __init__(self, app: QApplication):
Settings.load()

self.setWindowTitle(APP_NAME)
self.setWindowIcon(QIcon('pytouch3.png'))

self.app = app
app.setApplicationName(APP_NAME)
app.setApplicationDisplayName(APP_NAME)


self.preview_image = QLabel('No items to preview')
self.preview_image.setFixedHeight(USABLE_HEIGHT)

self.props_empty = False


self.save_image_button = QPushButton('Save image')
self.save_image_button.setDisabled(True)

Expand All @@ -123,8 +132,6 @@ def __init__(self, app: QApplication):
self.tree_view.setItemsExpandable(False)
self.tree_view.setDragDropOverwriteMode(False)



root = QVBoxLayout()

items_layout = QHBoxLayout()
Expand All @@ -147,8 +154,8 @@ def __init__(self, app: QApplication):
add_button.setMenu(add_menu)
buttons.addWidget(add_button)

#buttons.addWidget(add_text_button)
#buttons.addWidget(add_barcode_button)
# buttons.addWidget(add_text_button)
# buttons.addWidget(add_barcode_button)
buttons.addStretch()
buttons.setSpacing(1)

Expand All @@ -162,15 +169,13 @@ def __init__(self, app: QApplication):
b_clone = QPushButton('Copy')
b_clone.clicked.connect(self.on_clone)


buttons.addWidget(b_clone)
buttons.addSpacing(10)
buttons.addWidget(b_up)
buttons.addWidget(b_down)
buttons.addSpacing(10)
buttons.addWidget(b_delete)


layout.addLayout(buttons)
group.setLayout(layout)
items_layout.addWidget(group)
Expand All @@ -196,7 +201,7 @@ def __init__(self, app: QApplication):

preview_wrapper = QScrollArea(self)

#prev_layout = QHBoxLayout()
# prev_layout = QHBoxLayout()
preview_wrapper.setWidget(self.preview_image)
preview_wrapper.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
preview_wrapper.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
Expand All @@ -212,14 +217,14 @@ def __init__(self, app: QApplication):

self.printer_select = QComboBox(self)
fs_model = QFileSystemModel(self)
#model_proxy = QSortFilterProxyModel(self)
#model_proxy.setSourceModel(fs_model)
# model_proxy = QSortFilterProxyModel(self)
# model_proxy.setSourceModel(fs_model)
# fs_model.setNameFilters(['tty.PT-P3*'])

potential_printer = None
printers = QStandardItemModel()

#for p in QDir('/dev').entryList(['tty*'], QDir.System, QDir.Name):
# for p in QDir('/dev').entryList(['tty*'], QDir.System, QDir.Name):
# if p.startswith('tty.'):
for p in LabelMaker.list_serial_ports():
pprint(p.__dict__)
Expand All @@ -233,32 +238,26 @@ def __init__(self, app: QApplication):
potential_printer = item
'''

# print(printers.entryList())

# model_proxy.setRecursiveFilteringEnabled(True)
# model_proxy.setFilterKeyColumn(0)

#print(printers.entryList())


#model_proxy.setRecursiveFilteringEnabled(True)
#model_proxy.setFilterKeyColumn(0)

fs_model.setRootPath('/dev/')#/Users/nilsmasen')
fs_model.setFilter( QDir.System )
fs_model.setRootPath('/dev/') # /Users/nilsmasen')
fs_model.setFilter(QDir.System)

dev_index = fs_model.index('/dev')
#proxy_dev = model_proxy.mapFromSource(dev_index)


# proxy_dev = model_proxy.mapFromSource(dev_index)

self.printer_select.setModel(printers)

if potential_printer is not None:
index = printers.indexFromItem(potential_printer)
self.printer_select.setCurrentIndex(index.row())
#printer_select.setRootModelIndex(dev_index)
#printer_select.setRootIndex(dev_index)
#printer_select.setExpanded(dev_index, True)
#model_proxy.setFilterWildcard('tty*')

# printer_select.setRootModelIndex(dev_index)
# printer_select.setRootIndex(dev_index)
# printer_select.setExpanded(dev_index, True)
# model_proxy.setFilterWildcard('tty*')

bottom_box = QGroupBox('Print label: ')
bottom_bar = QHBoxLayout()
Expand All @@ -281,15 +280,17 @@ def __init__(self, app: QApplication):
menu = QMenuBar()
self.setMenuBar(menu)

menu.setWindowTitle(APP_NAME)
tools_menu = menu.addMenu('Python')
prefs = QAction('&Preferences', self)
prefs.triggered.connect(self.on_prefs)
tools_menu.addAction(prefs)
about = QAction('About ' + APP_NAME, self)
about.triggered.connect(self.on_prefs)
about.triggered.connect(self.on_about)
about.setMenuRole(QAction.AboutRole)
tools_menu.addAction(about)

if is_mac:
menu.setWindowTitle(APP_NAME)
tools_menu = menu.addMenu(APP_NAME)
prefs = QAction('&Preferences', self)
prefs.triggered.connect(self.on_prefs)
tools_menu.addAction(prefs)
tools_menu.addAction(about)

file_menu = menu.addMenu('Label')
act_new = QAction('&New', self)
Expand All @@ -312,6 +313,10 @@ def __init__(self, app: QApplication):
file_menu.addSeparator()
file_menu.addAction(QAction('&Export image', self))

if not is_mac:
help_menu = menu.addMenu('Help')
help_menu.addAction(about)

# menu.setNativeMenuBar(False)

def on_new(self):
Expand All @@ -320,19 +325,22 @@ def on_new(self):
self.update_items()
self.update_preview()

def on_prefs(self):
def on_about(self):
QMessageBox.information(self,
"Info",
"{0} v{1}\n\nhttps://github.com/piksel/pytouch-cube".format(APP_NAME, APP_VERSION))
f"{APP_NAME} v{APP_VERSION}\n\nhttps://github.com/piksel/pytouch-cube")

def on_prefs(self):
QMessageBox.information(self, "Info", "Not implemented")

def run(self):

self.show()
#self.add_item(Text(TextData('foo')))
#self.add_item(Text(TextData('Bar1')))
#self.add_item(Text(TextData('Bar2')))
#self.add_item(Spacing(SpacingData(10)))
#self.add_item(Text(TextData('baz')))
# self.add_item(Text(TextData('foo')))
# self.add_item(Text(TextData('Bar1')))
# self.add_item(Text(TextData('Bar2')))
# self.add_item(Spacing(SpacingData(10)))
# self.add_item(Text(TextData('baz')))
# self.add_item(Barcode(BarcodeData('123456789012')))
# self.add_item(Barcode(BarcodeData('ACE222', 'code128')))

Expand Down Expand Up @@ -378,7 +386,6 @@ def on_open(self):
self.current_file = file_path
self.open()


def save(self):
with open(self.current_file, 'wb') as file:
pickler = pickle.Pickler(file)
Expand Down Expand Up @@ -410,7 +417,7 @@ def print_clicked(self):

modal.setLayout(modal_layout)
modal.setFixedWidth(self.width() * .9)
modal.setFixedHeight(self.height()*.9)
modal.setFixedHeight(self.height() * .9)
modal.open()

def fmt_log(message):
Expand Down
Binary file added pytouch3.ico
Binary file not shown.
Binary file added pytouch3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ packbits
pypng
appdirs
pyyaml
pillow
qrcode
qrcode
py2exe
28 changes: 25 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,19 @@
from setuptools import setup

import app
import py2exe
import site

qt_plugin_root = site.getsitepackages()[1] + "\\PyQt5\\Qt\\plugins"

APP = ['gui.py']
DATA_FILES = []
DATA_FILES = [
('', ['pytouch3.png']),
("platforms", [ qt_plugin_root + "\\platforms\\qwindows.dll"]),
("iconengines", [qt_plugin_root + "\\iconengines\\qsvgicon.dll"]),
("platformthemes", [qt_plugin_root + "\\platformthemes\\qxdgdesktopportal.dll"]),
("styles", [qt_plugin_root + "\\styles\\qwindowsvistastyle.dll"])
]
OPTIONS = {'iconfile': 'pytouch3.icns'}

setup(
Expand All @@ -19,6 +29,18 @@
author=app.APP_AUTHOR,
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'], install_requires=['PyQt5', 'django-qrcode', 'pyserial', 'packbits', 'pypng', 'appdirs']
options={'py2app': OPTIONS, 'py2exe': {
'includes': [
'PyQt5.sip',
'PyQt5.QtCore',
'PyQt5.QtGui'
]
}},
windows=[{
"script": APP[0],
"icon_resources": [(0, "pytouch3.ico")],
"dest_base": "pytouch3"
}],
setup_requires=['py2app', 'py2exe'],
install_requires=['PyQt5', 'django-qrcode', 'pyserial', 'packbits', 'pypng', 'appdirs']
)

0 comments on commit aa65194

Please sign in to comment.