Add menu bar to application
This commit is contained in:
@@ -21,13 +21,36 @@ class MainWindow(Gtk.Window):
|
||||
|
||||
util.load_sets()
|
||||
|
||||
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
|
||||
self.add(vbox)
|
||||
self.notebook = Gtk.Notebook()
|
||||
|
||||
vbox.pack_start(self.notebook, True, True, 0)
|
||||
self.status_bar = Gtk.Statusbar()
|
||||
self.status_bar.set_no_show_all(True)
|
||||
|
||||
self.notebook = Gtk.Notebook()
|
||||
|
||||
# region Menu Bar
|
||||
|
||||
mb_main = Gtk.Menu()
|
||||
|
||||
self.menu_import = Gtk.MenuItem("Import Library")
|
||||
self.menu_export = Gtk.MenuItem("Export Library")
|
||||
self.menu_quit = Gtk.ImageMenuItem('Quit', Gtk.Image.new_from_icon_name(Gtk.STOCK_QUIT, 0))
|
||||
self.menu_quit.connect("activate", Gtk.main_quit)
|
||||
|
||||
mb_main.append(self.menu_import)
|
||||
mb_main.append(self.menu_export)
|
||||
mb_main.append(Gtk.SeparatorMenuItem())
|
||||
mb_main.append(self.menu_quit)
|
||||
|
||||
root_menu_main = Gtk.MenuItem("Main")
|
||||
root_menu_main.set_submenu(mb_main)
|
||||
|
||||
mb = Gtk.MenuBar()
|
||||
mb.append(root_menu_main)
|
||||
|
||||
# endregion
|
||||
|
||||
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
|
||||
vbox.pack_start(mb, False, False, 0)
|
||||
vbox.pack_start(self.notebook, True, True, 0)
|
||||
vbox.pack_start(self.status_bar, False, False, 0)
|
||||
|
||||
# Set reference to status bar in util
|
||||
@@ -43,12 +66,13 @@ class MainWindow(Gtk.Window):
|
||||
self.deckView = Gtk.Box()
|
||||
self.deckView.add(Gtk.Label("View and organize your Decklists!"))
|
||||
|
||||
|
||||
|
||||
self.notebook.append_page(self.searchView, Gtk.Label("Search"))
|
||||
self.notebook.append_page(self.collectionView, Gtk.Label("Collection"))
|
||||
self.notebook.append_page(self.deckView, Gtk.Label("Decks"))
|
||||
|
||||
self.add(vbox)
|
||||
|
||||
|
||||
win = MainWindow()
|
||||
win.connect('delete-event', Gtk.main_quit)
|
||||
GObject.threads_init()
|
||||
|
||||
@@ -5,17 +5,19 @@ import threading
|
||||
import gi
|
||||
from urllib.error import URLError, HTTPError
|
||||
from mtgsdk import Card
|
||||
from gi.repository import Gtk, GdkPixbuf, GObject, Pango
|
||||
from gi.repository import Gtk, Gdk, GdkPixbuf, GObject, Pango
|
||||
|
||||
gi.require_version('Gtk', '3.0')
|
||||
|
||||
|
||||
|
||||
class SearchView(Gtk.Grid):
|
||||
|
||||
# region Constructor
|
||||
def __init__(self):
|
||||
Gtk.Grid.__init__(self)
|
||||
self.set_column_spacing(5)
|
||||
|
||||
# Search Box
|
||||
# region Search Box
|
||||
self.searchbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=5,
|
||||
margin_end=5, margin_start=5, margin_top=5, margin_bottom=5)
|
||||
self.searchEntry = Gtk.Entry()
|
||||
@@ -33,8 +35,10 @@ class SearchView(Gtk.Grid):
|
||||
self.searchbox.add(self.searchbutton)
|
||||
self.searchbox.add(self.progressbar)
|
||||
self.searchbox.add(Gtk.HSeparator())
|
||||
# endregion
|
||||
|
||||
# region Filters
|
||||
|
||||
# Filters
|
||||
# Color of the cards
|
||||
color_cooser_label = Gtk.Label("Mana Color", xalign=0, yalign=0)
|
||||
|
||||
@@ -128,8 +132,11 @@ class SearchView(Gtk.Grid):
|
||||
margin_end=5, margin_start=5, margin_top=5, margin_bottom=5)
|
||||
self.filters.pack_start(self.filters_title, False, False, 5)
|
||||
self.filters.pack_start(self.filters_grid, False, False, 0)
|
||||
|
||||
# endregion
|
||||
|
||||
# Set all Buttons active
|
||||
self.do_init_filter_controls()
|
||||
self._do_init_filter_controls()
|
||||
|
||||
# Card List
|
||||
self.searchresults = Gtk.ScrolledWindow(hexpand=True, vexpand=True)
|
||||
@@ -190,16 +197,9 @@ class SearchView(Gtk.Grid):
|
||||
self.selection = self.list.get_selection()
|
||||
self.selection.connect("changed", self.on_card_selected)
|
||||
|
||||
def match_selected(self, completion, model, iter):
|
||||
self.set_combo.set_active_iter(iter)
|
||||
# endregion
|
||||
|
||||
def do_show_no_results(self, searchterm):
|
||||
# Should move to main UI, so parent can be used
|
||||
dialog = Gtk.MessageDialog(self.parent, 0, Gtk.MessageType.INFO,
|
||||
Gtk.ButtonsType.OK, "No Results")
|
||||
dialog.format_secondary_text("No cards with name \"" + searchterm + "\" were found")
|
||||
dialog.run()
|
||||
dialog.destroy()
|
||||
# region UI Events
|
||||
|
||||
def online_search_clicked(self, button):
|
||||
# Clear old data from liststore
|
||||
@@ -213,6 +213,33 @@ class SearchView(Gtk.Grid):
|
||||
# Start to load cards
|
||||
self.loadthread.start()
|
||||
|
||||
def mana_toggled(self, toggle_button):
|
||||
iconname = ""
|
||||
if toggle_button.get_active():
|
||||
iconname = "{" + toggle_button.get_name() + "}"
|
||||
else:
|
||||
iconname = "{" + toggle_button.get_name() + "_alt}"
|
||||
image = Gtk.Image()
|
||||
image.set_from_pixbuf(util.create_mana_icons(iconname))
|
||||
toggle_button.set_image(image)
|
||||
|
||||
def on_card_selected(self, selection):
|
||||
(model, pathlist) = selection.get_selected_rows()
|
||||
for path in pathlist:
|
||||
iter = model.get_iter(path)
|
||||
card_id = model.get_value(iter, 0)
|
||||
|
||||
selected_card = None
|
||||
for card in self.cards:
|
||||
if card.multiverse_id == card_id:
|
||||
selected_card = card
|
||||
if selected_card is not None:
|
||||
self.details.set_card_detail(selected_card)
|
||||
|
||||
# endregion
|
||||
|
||||
# region Public Functions
|
||||
|
||||
def load_cards(self):
|
||||
# Get search term
|
||||
term = self.searchEntry.get_text()
|
||||
@@ -301,39 +328,22 @@ class SearchView(Gtk.Grid):
|
||||
# Hide Progress bar
|
||||
GObject.idle_add(self.progressbar.set_visible, False, priorty=GObject.PRIORITY_DEFAULT)
|
||||
|
||||
def on_card_selected(self, selection):
|
||||
(model, pathlist) = selection.get_selected_rows()
|
||||
for path in pathlist:
|
||||
iter = model.get_iter(path)
|
||||
card_id = model.get_value(iter, 0)
|
||||
# endregion
|
||||
|
||||
selected_card = None
|
||||
for card in self.cards:
|
||||
if card.multiverse_id == card_id:
|
||||
selected_card = card
|
||||
if selected_card is not None:
|
||||
self.details.set_card_detail(selected_card)
|
||||
# region Private Functions
|
||||
|
||||
def get_color_filter(self):
|
||||
colorlist = []
|
||||
# Go through mana color buttons an get the active filters
|
||||
for widget in self.color_chooser:
|
||||
if isinstance(widget, Gtk.ToggleButton):
|
||||
if widget.get_active():
|
||||
colorlist.append(widget.get_name())
|
||||
return colorlist
|
||||
def _match_selected(self, completion, model, iter):
|
||||
self.set_combo.set_active_iter(iter)
|
||||
|
||||
def mana_toggled(self, toggle_button):
|
||||
iconname = ""
|
||||
if toggle_button.get_active():
|
||||
iconname = "{" + toggle_button.get_name() + "}"
|
||||
else:
|
||||
iconname = "{" + toggle_button.get_name() + "_alt}"
|
||||
image = Gtk.Image()
|
||||
image.set_from_pixbuf(util.create_mana_icons(iconname))
|
||||
toggle_button.set_image(image)
|
||||
def _do_show_no_results(self, searchterm):
|
||||
# Should move to main UI, so parent can be used
|
||||
dialog = Gtk.MessageDialog(self.parent, 0, Gtk.MessageType.INFO,
|
||||
Gtk.ButtonsType.OK, "No Results")
|
||||
dialog.format_secondary_text("No cards with name \"" + searchterm + "\" were found")
|
||||
dialog.run()
|
||||
dialog.destroy()
|
||||
|
||||
def do_init_filter_controls(self):
|
||||
def _do_init_filter_controls(self):
|
||||
# Toggle each Button to deactivate filter an load icon
|
||||
for widget in self.color_chooser:
|
||||
if isinstance(widget, Gtk.ToggleButton):
|
||||
@@ -344,7 +354,7 @@ class SearchView(Gtk.Grid):
|
||||
self.type_combo.set_active(0)
|
||||
self.set_combo.set_active(0)
|
||||
|
||||
def do_activate_controls(self, active):
|
||||
def _do_activate_controls(self, active):
|
||||
self.searchEntry.set_editable(active)
|
||||
self.searchEntry.set_sensitive(active)
|
||||
self.searchbutton.set_sensitive(active)
|
||||
@@ -357,3 +367,16 @@ class SearchView(Gtk.Grid):
|
||||
self.rarity_combo.set_sensitive(active)
|
||||
self.type_combo.set_sensitive(active)
|
||||
self.set_combo.set_sensitive(active)
|
||||
|
||||
def _get_color_filter(self):
|
||||
color_list = []
|
||||
# Go through mana color buttons an get the active filters
|
||||
for widget in self.color_chooser:
|
||||
if isinstance(widget, Gtk.ToggleButton):
|
||||
if widget.get_active():
|
||||
color_list.append(widget.get_name())
|
||||
return color_list
|
||||
|
||||
# endregion
|
||||
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user