Skip to content

Commit

Permalink
add a little executable
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv committed Feb 19, 2025
1 parent 100db72 commit 6bb50ab
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 14 deletions.
10 changes: 7 additions & 3 deletions pixi-editor/menu/menu.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"target_environment_is_base": "pixi-editor",
"target_environment_is_not_base": "pixi-editor ({{ ENV_NAME }})"
},
"description": "Scientific PYthon Development EnviRonment",
"description": "The pixi text-editor",
"icon": "{{ MENU_DIR }}/pixi-icon.{{ ICON_EXT }}",
"activate": false,
"terminal": false,
Expand All @@ -33,8 +33,12 @@
]
},
"osx": {
"command": ["open", "$@"],
"precommand": "pushd \"$(dirname \"$0\")\" &>/dev/null",
"command": ["./python", "{{ PREFIX }}/bin/pixi-editor-launcher.py", "$@"],
"CFBundleName": "Pixi Editor",
"link_in_bundle": {
"{{ PREFIX }}/bin/python": "{{ MENU_ITEM_LOCATION }}/Contents/MacOS/python"
},
"CFBundleIdentifier": "dev.prefix.pixi-editor",
"CFBundleVersion": "0.1.0",
"CFBundleDocumentTypes": [
Expand All @@ -44,7 +48,7 @@
"LSHandlerRank": "Default",
"CFBundleTypeIconFile": "pixi-icon.icns",
"LSItemContentTypes": [
"public.pixi"
"public.plain-text"
]
}
]
Expand Down
21 changes: 10 additions & 11 deletions pixi-editor/recipe.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package:
name: pixi-editor
version: "0.3.0"
version: "0.3.1"

build:
noarch: generic
script:
- if: unix
then:
- mkdir -p $PREFIX/Menu
- cp $RECIPE_DIR/menu/menu.json $PREFIX/Menu/pixi-editor.json
- cp $RECIPE_DIR/menu/pixi-icon.* $PREFIX/Menu/
- if: win
then:
- if not exist "%PREFIX%\Menu" mkdir "%PREFIX%\Menu"
- copy "%RECIPE_DIR%\menu\menu.json" "%PREFIX%\Menu\pixi-editor.json"
- copy "%RECIPE_DIR%\menu\pixi-icon.ico" "%PREFIX%\Menu\"
- mkdir -p $PREFIX/bin
- cp $RECIPE_DIR/src/main.py $PREFIX/bin/pixi-editor-launcher.py
- mkdir -p $PREFIX/Menu
- cp $RECIPE_DIR/menu/menu.json $PREFIX/Menu/pixi-editor.json
- cp $RECIPE_DIR/menu/pixi-icon.* $PREFIX/Menu/

requirements:
run:
- pyqt 5.*
81 changes: 81 additions & 0 deletions pixi-editor/src/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env python

import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QTextEdit, QEvent, QFileDialog, QAction

class TextEditor(QMainWindow):
def __init__(self, filename=None):
super().__init__()
self.initUI()
if filename:
self.openFile(filename)

def initUI(self):
self.setWindowTitle('Simple Text Editor')
self.setGeometry(100, 100, 800, 600)

# Create text edit widget
self.text_edit = QTextEdit()
self.setCentralWidget(self.text_edit)

# Create menu bar
menubar = self.menuBar()
file_menu = menubar.addMenu('File')

# File menu actions
open_action = QAction('Open', self)
open_action.setShortcut('Ctrl+O')
open_action.triggered.connect(self.openFileDialog)

save_action = QAction('Save', self)
save_action.setShortcut('Ctrl+S')
save_action.triggered.connect(self.saveFile)

file_menu.addAction(open_action)
file_menu.addAction(save_action)

def openFileDialog(self):
filename, _ = QFileDialog.getOpenFileName(self, 'Open File')
if filename:
self.openFile(filename)

def openFile(self, filename):
try:
with open(filename, 'r') as f:
text = f.read()
text += "\n" + "..".join(sys.argv)
self.text_edit.setText(text)


self.setWindowTitle(f'Simple Text Editor - {filename}')

except Exception as e:
print(f"Error opening file: {e}")

def saveFile(self):
filename, _ = QFileDialog.getSaveFileName(self, 'Save File')
if filename:
try:
with open(filename, 'w') as f:
f.write(self.text_edit.toPlainText())
except Exception as e:
print(f"Error saving file: {e}")

# Override event handler
def event(self, event):
print(event)
if event.type() == QEvent.Type.FileOpen:
self.handle_file(event.file())
return True
return super().event(event)


def main():
app = QApplication(sys.argv)
filename = sys.argv[1] if len(sys.argv) > 1 else None
editor = TextEditor(filename)
editor.show()
sys.exit(app.exec_())

if __name__ == '__main__':
main()

0 comments on commit 6bb50ab

Please sign in to comment.