Created
October 8, 2015 20:00
Question to Gtk App Devel list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# | |
# opts.py | |
# | |
# Copyright (C) 2015 Germán A. Racca | |
# E-Mail: <gracca[AT]gmail[DOT]com> | |
# License: GPLv3+ | |
from gi.repository import Gtk | |
############# | |
## C L A S S | |
############################ | |
class Coor2MASS(Gtk.Dialog): | |
"""Options for selecting Coordinates""" | |
def __init__(self, parent): | |
"""Initialize the window""" | |
Gtk.Dialog.__init__(self, "Select columns to retrieve:", parent, 0, | |
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, | |
Gtk.STOCK_OK, Gtk.ResponseType.OK)) | |
self.set_modal(True) | |
# create a grid | |
self.grid = Gtk.Grid(column_homogeneous=True, | |
column_spacing=10, | |
row_spacing=10) | |
# create check buttons | |
self.btn_ra = Gtk.CheckButton(label="RAJ2000 [Right ascension (J2000)]") | |
self.btn_ra.set_active(True) | |
self.grid.add(self.btn_ra) | |
self.btn_de = Gtk.CheckButton(label="DEJ2000 [Declination (J2000)]") | |
self.btn_de.set_active(True) | |
self.grid.attach_next_to(self.btn_de, self.btn_ra, | |
Gtk.PositionType.BOTTOM, 1, 1) | |
self.btn_2m = Gtk.CheckButton(label="2MASS [Source designation]") | |
self.grid.attach_next_to(self.btn_2m, self.btn_de, | |
Gtk.PositionType.BOTTOM, 1, 1) | |
box = self.get_content_area() | |
box.add(self.grid) | |
self.show_all() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# | |
# q2MASS.py | |
# | |
# Copyright (C) 2015 Germán A. Racca | |
# E-Mail: <gracca[AT]gmail[DOT]com> | |
# License: GPLv3+ | |
__author__ = "Germán A. Racca" | |
__copyright__ = "Copyright (C) 2015, Germán A. Racca" | |
__email__ = "gracca@gmail.com" | |
__license__ = "GPLv3+" | |
__version__ = "0.1" | |
## REMOVE this when finished ### | |
import sys # | |
sys.dont_write_bytecode = True # | |
################################ | |
from gi.repository import Gtk | |
from opts import Coor2MASS | |
############# | |
## C L A S S | |
############################# | |
class Query2MASS(Gtk.Window): | |
"""Gtk+ interface for querying the 2MASS Point Source Catalog""" | |
def __init__(self): | |
"""Initialize the window""" | |
Gtk.Window.__init__(self) | |
self.set_default_size(800, 600) | |
self.set_position(Gtk.WindowPosition.CENTER) | |
self.set_border_width(10) | |
# add headerbar | |
tb = TitleBar() | |
titlebar = tb.headerbar() | |
self.set_titlebar(titlebar) | |
# create a grid | |
self.grid = Gtk.Grid(column_homogeneous=True, | |
column_spacing=10, | |
row_spacing=10) | |
self.add(self.grid) | |
# create a window with scroll bars | |
self.scrolledwindow = Gtk.ScrolledWindow() | |
self.scrolledwindow.set_policy(Gtk.PolicyType.NEVER, | |
Gtk.PolicyType.AUTOMATIC) | |
self.grid.add(self.scrolledwindow) | |
self.show_all() | |
############# | |
## C L A S S | |
############### | |
class TitleBar: | |
"""Create the header bar""" | |
def __init__(self): | |
"""Initialize the class""" | |
# create left and right headers | |
self.left_header = Gtk.Grid() | |
self.right_header = Gtk.Grid() | |
# left header | |
#------------ | |
self.entry_ra = Gtk.Entry() | |
self.entry_ra.set_placeholder_text("Right Ascension") | |
self.left_header.add(self.entry_ra) | |
self.entry_dec = Gtk.Entry() | |
self.entry_dec.set_placeholder_text("Declination") | |
self.left_header.attach_next_to(self.entry_dec, self.entry_ra, | |
Gtk.PositionType.RIGHT, 1, 1) | |
self.button_exec = Gtk.Button.new_from_icon_name('system-run-symbolic', 1) | |
self.button_exec.set_tooltip_text("Run the query...") | |
self.left_header.attach_next_to(self.button_exec, self.entry_dec, | |
Gtk.PositionType.RIGHT, 1, 1) | |
# right header | |
#------------- | |
# options | |
self.button_opts = Gtk.Button.new_from_icon_name('open-menu-symbolic', 1) | |
self.button_opts.set_tooltip_text("Select query options...") | |
self.button_opts.connect('clicked', self.on_button_opts_clicked) | |
self.right_header.add(self.button_opts) | |
self.popover_opts = Gtk.Popover() | |
self.popover_opts.set_relative_to(self.button_opts) | |
self.grid_opts = Gtk.Grid(row_homogeneous=True, row_spacing=5, margin=5) | |
self.button_coor = Gtk.Button("Coordinates") | |
self.button_coor.connect('clicked', self.on_button_coor_clicked) | |
self.button_mags = Gtk.Button("Magnitudes") | |
self.button_flag = Gtk.Button("Flags") | |
self.grid_opts.add(self.button_coor) | |
self.grid_opts.attach_next_to(self.button_mags, self.button_coor, | |
Gtk.PositionType.BOTTOM, 1, 1) | |
self.grid_opts.attach_next_to(self.button_flag, self.button_mags, | |
Gtk.PositionType.BOTTOM, 1, 1) | |
self.popover_opts.add(self.grid_opts) | |
# properties | |
self.button_prop = Gtk.Button.new_from_icon_name('preferences-other-symbolic', 1) | |
self.right_header.attach_next_to(self.button_prop, self.button_opts, | |
Gtk.PositionType.RIGHT, 1, 1) | |
# create the headerbar | |
def headerbar(self): | |
"""The header bar (left and right)""" | |
hb = Gtk.HeaderBar() | |
hb.set_title("q2MASS") | |
hb.set_subtitle("Query the 2MASS PSC") | |
hb.set_show_close_button(True) | |
hb.pack_start(self.left_header) | |
hb.pack_end(self.right_header) | |
return hb | |
# callback for button opts | |
def on_button_opts_clicked(self, widget): | |
"""Show popover contents for Options""" | |
self.popover_opts.show_all() | |
# callback for button coor | |
def on_button_coor_clicked(self, widget): | |
"""Close popover and show Coordinates options""" | |
self.popover_opts.hide() | |
coor = Coor2MASS(self) | |
resp = coor.run() | |
if resp == Gtk.ResponseType.OK: | |
print("Clicked OK!") | |
coor.destroy() | |
def main(): | |
"""Show the window""" | |
win = Query2MASS() | |
win.connect('delete-event', Gtk.main_quit) | |
win.show_all() | |
Gtk.main() | |
return 0 | |
if __name__ == '__main__': | |
main() |
Author
gracca
commented
Oct 8, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment