Compare commits
3 Commits
00a181ad76
...
bb6aa43ce9
Author | SHA1 | Date |
---|---|---|
José Carlos Cuevas | bb6aa43ce9 | 4 years ago |
José Carlos Cuevas | 6718fb687a | 4 years ago |
José Carlos Cuevas | 1a9a2f56e7 | 4 years ago |
@ -0,0 +1,186 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Python imports
|
||||
import os.path
|
||||
import sys
|
||||
|
||||
# Gtk and Gobject
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk, Gio
|
||||
|
||||
# Internationalization support
|
||||
import gettext
|
||||
import locale
|
||||
|
||||
|
||||
if os.path.exists('locale/po') and os.path.exists('res'):
|
||||
# We're in the development tree
|
||||
DIR = "locale/po/"
|
||||
RESOURCES = "res/"
|
||||
|
||||
elif sys.platform != 'win32' and sys.platform != 'darwin':
|
||||
DIR = "/usr/share/locale/"
|
||||
RESOURCES = "/usr/local/share/jsoninspector"
|
||||
|
||||
else:
|
||||
DIR = "po"
|
||||
RESOURCES = "res/"
|
||||
|
||||
# Internationalization code, we'll cross that bridge when we get there
|
||||
# APP = "smallprint"
|
||||
#
|
||||
#
|
||||
# locale.setlocale(locale.LC_ALL, '')
|
||||
#
|
||||
# gettext.bindtextdomain(APP, DIR)
|
||||
# locale.bindtextdomain(APP, DIR)
|
||||
#
|
||||
#
|
||||
# gettext.textdomain(APP)
|
||||
# _ = gettext.gettext
|
||||
#
|
||||
|
||||
|
||||
class MainWindowMethods(Gtk.Application):
|
||||
"""
|
||||
Main Application object with the main window signals
|
||||
"""
|
||||
def __init__(self):
|
||||
Gtk.Application.__init__(self, application_id="apps.gnome.smallprint",
|
||||
flags=Gio.ApplicationFlags.FLAGS_NONE)
|
||||
|
||||
self.connect("activate", self.on_app_start)
|
||||
|
||||
def on_app_start(self, data=None):
|
||||
"""
|
||||
Loads the MainWindow widgets, shows it up and starts the main loop
|
||||
"""
|
||||
self.builder = Gtk.Builder()
|
||||
# self.builder.set_translation_domain(APP)
|
||||
self.builder.add_from_file(os.path.join(RESOURCES, 'smallprint.gtkbuilder'))
|
||||
self.builder.connect_signals(self)
|
||||
|
||||
# We get the window and show it
|
||||
self.window = self.builder.get_object("MainWindow")
|
||||
self.add_window(self.window)
|
||||
self.window.show_all()
|
||||
|
||||
def onOpenMenuClicked(self, event):
|
||||
"""
|
||||
User has pressed Open in the menu
|
||||
"""
|
||||
# Create the FileChooser Dialog
|
||||
chooser = Gtk.FileChooserDialog(_("Open JSON text file"), self.window,
|
||||
Gtk.FileChooserAction.OPEN,
|
||||
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
|
||||
Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
|
||||
|
||||
# Launch it
|
||||
response = chooser.run()
|
||||
|
||||
# If we choose a file, we load it
|
||||
if response == Gtk.ResponseType.OK:
|
||||
filename = chooser.get_filename()
|
||||
label = self.builder.get_object("StatusLabel")
|
||||
|
||||
# We update the statusbar accordingly to what has happened
|
||||
if self.logicObj.loadjson(filename):
|
||||
|
||||
label.set_text(filename)
|
||||
treeStore = self.builder.get_object("treestore1")
|
||||
treeStore.clear()
|
||||
self.logicObj.loadTree(treeStore)
|
||||
|
||||
else:
|
||||
|
||||
label.set_text(_("No JSON loaded."))
|
||||
|
||||
# We finish the dialog
|
||||
chooser.destroy()
|
||||
|
||||
def onCopyJSONClicked(self, widget):
|
||||
"""
|
||||
User asked to paste a JSON code
|
||||
"""
|
||||
# Show up the TextWindow
|
||||
textWindow = self.builder.get_object("TextWindow")
|
||||
textWindow.show_all()
|
||||
|
||||
def onCopyJSONDelete(self, widget, event):
|
||||
"""
|
||||
We've been told to close the CopyJSON Window
|
||||
"""
|
||||
textWindow = self.builder.get_object("TextWindow")
|
||||
textWindow.hide()
|
||||
|
||||
return True
|
||||
|
||||
def onCopyJSONDestroy(self, widget):
|
||||
"""
|
||||
We've been tasked with removing the CopyJSON window
|
||||
"""
|
||||
textWindow = self.builder.get_object("TextWindow")
|
||||
textWindow.hide()
|
||||
|
||||
return True
|
||||
|
||||
def onCopyJSONAcceptClicked(self, widget):
|
||||
"""
|
||||
The input is finished and accepted.
|
||||
"""
|
||||
textView = self.builder.get_object("textview1")
|
||||
jsonBuffer = textView.get_buffer()
|
||||
jsonText = jsonBuffer.get_text(jsonBuffer.get_start_iter(),
|
||||
jsonBuffer.get_end_iter(), True)
|
||||
|
||||
textWindow = self.builder.get_object("TextWindow")
|
||||
textWindow.hide()
|
||||
treestore = self.builder.get_object("treestore1")
|
||||
treestore.clear()
|
||||
|
||||
if self.logicObj.loadJSONText(jsonText):
|
||||
|
||||
status_label = self.builder.get_object("StatusLabel")
|
||||
status_label.set_text(_("Loaded from the clipboard."))
|
||||
self.logicObj.loadTree(treestore)
|
||||
|
||||
def onCopyJSONCancelClicked(self, widget):
|
||||
"""
|
||||
The user changed its mind and pressed cancel
|
||||
"""
|
||||
textWindow = self.builder.get_object("TextWindow")
|
||||
textWindow.hide()
|
||||
|
||||
def onExitMenuClicked(self, widget):
|
||||
"""
|
||||
Menu option Exit has been clicked
|
||||
"""
|
||||
self.quit()
|
||||
|
||||
def onAboutMenuActivate(self, widget):
|
||||
"""
|
||||
About option clicked
|
||||
"""
|
||||
about_dialog = self.builder.get_object("AboutDialog")
|
||||
about_dialog.run()
|
||||
about_dialog.hide()
|
||||
|
||||
def onMainWindowDelete(self, widget, event):
|
||||
"""
|
||||
Our MainWindow has been deleted or closed
|
||||
"""
|
||||
pass
|
||||
|
||||
def onAboutDialogClose(self, widget, event=None):
|
||||
pass
|
||||
|
||||
def onAboutDialogDeleteEvent(self, widget, event=None):
|
||||
pass
|
||||
|
||||
|
||||
# Main procedure
|
||||
if __name__ == "__main__":
|
||||
|
||||
mainWindow = MainWindowMethods()
|
||||
mainWindow.run(None)
|
@ -0,0 +1,313 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Generated with glade 3.22.1 -->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.20"/>
|
||||
<object class="GtkApplicationWindow" id="MainWindow">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="title" translatable="yes">Small Print Shop</property>
|
||||
<property name="window_position">center</property>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkMenuBar">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkMenuItem">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">_Archivo</property>
|
||||
<property name="use_underline">True</property>
|
||||
<child type="submenu">
|
||||
<object class="GtkMenu">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkImageMenuItem">
|
||||
<property name="label">gtk-new</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="use_stock">True</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkImageMenuItem">
|
||||
<property name="label">gtk-open</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="use_stock">True</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkImageMenuItem">
|
||||
<property name="label">gtk-save</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="use_stock">True</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkImageMenuItem">
|
||||
<property name="label">gtk-save-as</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="use_stock">True</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkSeparatorMenuItem">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkImageMenuItem">
|
||||
<property name="label">gtk-quit</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="use_stock">True</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkMenuItem">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">_Editar</property>
|
||||
<property name="use_underline">True</property>
|
||||
<child type="submenu">
|
||||
<object class="GtkMenu">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkImageMenuItem">
|
||||
<property name="label">gtk-cut</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="use_stock">True</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkImageMenuItem">
|
||||
<property name="label">gtk-copy</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="use_stock">True</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkImageMenuItem">
|
||||
<property name="label">gtk-paste</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="use_stock">True</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkImageMenuItem">
|
||||
<property name="label">gtk-delete</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="use_stock">True</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkMenuItem">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">_Ver</property>
|
||||
<property name="use_underline">True</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkMenuItem">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Ay_uda</property>
|
||||
<property name="use_underline">True</property>
|
||||
<child type="submenu">
|
||||
<object class="GtkMenu">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkImageMenuItem">
|
||||
<property name="label">gtk-about</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="use_stock">True</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkNotebook" id="ActionsTabs">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child type="tab">
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Print personal tickets</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="tab_fill">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child type="tab">
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Print files</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">1</property>
|
||||
<property name="tab_fill">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child type="tab">
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Create Documents</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">2</property>
|
||||
<property name="tab_fill">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="StatusImage">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="stock">gtk-connect</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="padding">5</property>
|
||||
<property name="pack_type">end</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="StatusLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Printer not configured</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="pack_type">end</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="padding">5</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
Loading…
Reference in new issue