def gtk_theme_colors(self):
window = Gtk.Window()
style_context = window.get_style_context()
gtk_theme_colors = {
'bg': style_context.lookup_color('theme_bg_color')[1],
'fg': style_context.lookup_color('theme_fg_color')[1],
'selected_bg': style_context.lookup_color('theme_selected_bg_color')[1],
'selected_fg': style_context.lookup_color('theme_selected_fg_color')[1],
'error_bg': style_context.lookup_color('error_bg_color')[1],
'error_fg': style_context.lookup_color('error_fg_color')[1],
'info_bg': style_context.lookup_color('info_bg_color')[1],
'unfocused_fg': style_context.lookup_color('theme_unfocused_fg_color')[1],
'unfocused_bg': style_context.lookup_color('theme_unfocused_bg_color')[1]
}
for name, color in gtk_theme_colors.items():
gtk_theme_colors[name] = self.rgba_to_hex(color)
return gtk_theme_colors
python类Window()的实例源码
def __init__(self):
Gtk.Window.__init__(self)
self.get_settings().set_property(
"gtk-application-prefer-dark-theme", True)
self.connect('destroy', lambda x: Gtk.main_quit())
# Layout
self.box = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0)
self.add(self.box)
self.abar = Gtk.ActionBar()
self.box.pack_end(self.abar, False, False, 0)
self.build_contents()
# Finalize the window itself
self.set_titlebar(self.headerbar())
self.set_title("Foreign Package Installer")
self.set_icon_name("system-software-install")
self.set_size_request(600, 450)
self.set_position(Gtk.WindowPosition.CENTER)
self.show_all()
def generate_window(self, *args):
"""
Generate application window (Gtk.Window)
"""
Gtk.ApplicationWindow.__init__(self, type=Gtk.WindowType.TOPLEVEL,
application=self.app)
self.move_latest_position()
self.set_wmclass("org.gnome.Authenticator", "Gnome Authenticator")
self.set_icon_name("org.gnome.Authenticator")
self.use_latest_size()
self.set_resizable(True)
self.connect("key_press_event", self.on_key_press)
self.connect("delete-event", lambda x, y: self.app.on_quit())
self.notification = InAppNotification()
self.observable.register(self.notification)
self.main_box.pack_start(self.notification, False, False, 0)
self.add(self.main_box)
def __init__(self, wmclass):
Gtk.Window.__init__(self)
OSDWindow._apply_css(Config())
self.argparser = argparse.ArgumentParser(description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog=self.EPILOG)
self._add_arguments()
self.exit_code = -1
self.position = (20, -20)
self.mainloop = None
self._controller = None
self.set_name(wmclass)
self.set_wmclass(wmclass, wmclass)
self.set_decorated(False)
self.stick()
self.set_skip_taskbar_hint(True)
self.set_skip_pager_hint(True)
self.set_keep_above(True)
self.set_type_hint(Gdk.WindowTypeHint.NOTIFICATION)
def __init__(self, n, front, back, step):
from gi.repository import Gtk
from gi.repository import GObject
Render.__init__(self, n, front, back)
window = Gtk.Window()
self.window = window
window.resize(self.n, self.n)
self.step = step
window.connect("destroy", self.__destroy)
darea = Gtk.DrawingArea()
# darea.connect("expose-event", self.expose)
self.darea = darea
window.add(darea)
window.show_all()
#self.cr = self.darea.window.cairo_create()
self.steps = 0
GObject.idle_add(self.step_wrap)
def __init__(self):
Gtk.Window.__init__(self, title="BTC Widget")
self._ticker_labels = {}
self._tickers_vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self._create_ticker_labels()
self._graph = btcwidget.graph.Graph(config['dark_theme'])
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
vbox.pack_start(self._tickers_vbox, False, False, 5)
vbox.pack_start(self._graph, True, True, 0)
self.set_icon_from_file(self._ICON_PATH)
self.connect('delete-event', Gtk.main_quit)
self.add(vbox)
self.show_all()
self._indicator = Indicator(self)
# self.open_options()
def __init__(self, parent):
Gtk.Window.__init__(self)
self.set_title(_("GNU Solfege lesson file editor") )
self.set_default_size(400, 400)
self.g_parent = parent
self.vbox = Gtk.VBox()
self.vbox.set_spacing(8)
self.add(self.vbox)
self.connect('delete_event', self.delete_cb)
self.g_htmlwidget = htmlwidget.HtmlWidget(None, None)
self.vbox.pack_start(self.g_htmlwidget, True, True, 0)
self.vbox.pack_start(Gtk.HSeparator(), False)
bbox = Gtk.HButtonBox()
bbox.set_border_width(8)
self.vbox.pack_start(bbox, False)
b = Gtk.Button(stock=Gtk.STOCK_CLOSE)
b.connect('clicked', self.close_cb)
bbox.pack_start(b, True, True, 0)
self.show_all()
self.set_focus(b)
def __init__(self, datadir):
Gtk.Window.__init__(self)
self.icons = stock.EditorIconFactory(self, datadir)
self.connect('destroy', lambda w: Gtk.main_quit())
self.g_help_window = None
# toplevel_vbox:
# -menubar
# -toolbar
# -notebook
# -statusbar
self.toplevel_vbox = Gtk.VBox()
self.add(self.toplevel_vbox)
self.create_menu_and_toolbar()
self.g_notebook = Gtk.Notebook()
self.toplevel_vbox.pack_start(self.g_notebook, True, True, 0)
self.vbox = Gtk.VBox()
self.toplevel_vbox.pack_start(self.vbox, True, True, 0)
self.create_mainwin_ui()
self.show_all()
def __init__(self):
Gtk.Window.__init__(self)
vbox = Gtk.VBox()
self.add(vbox)
self.set_default_size(600, 400)
self.w = RhythmWidget()
s = elems.Score()
s.add_staff(staff_class=elems.RhythmStaff)
s.add_bar(elems.TimeSignature(3, 4))
s.add_bar(elems.TimeSignature(3, 4))
s.voice11.fill_with_skips()
self.w.set_score(s)
vbox.pack_start(self.w, True, True, 0)
#
c = RhythmWidgetController(self.w)
vbox.pack_start(c, False, False, 0)
c.show()
c.set_editable(True)
self.connect('delete_event', self.quit)
def main():
win = Gtk.Window()
win.connect('destroy', Gtk.main_quit)
win.set_default_size(Width, Height)
global drawingarea
drawingarea = Gtk.DrawingArea()
drawingarea.connect('draw', draw)
drawing_event_box = Gtk.EventBox()
drawing_event_box.add(drawingarea)
drawing_event_box.connect('button-press-event', mouse_pressed)
drawing_event_box.connect('motion-notify-event', mouse_dragged)
check_useIk = Gtk.CheckButton("Lock Forearm & Hand")
check_useIk.set_active(True)
check_useIk.connect("toggled", check_toggled)
box = Gtk.VBox()
box.pack_start(check_useIk, False, True, 0)
box.pack_start(drawing_event_box, True, True, 0)
win.add(box)
win.show_all()
Gtk.main()
def __init__(self, title):
Gtk.Window.__init__(self, title=title)
self.set_border_width(10)
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
self.add(vbox)
self.progressbar = Gtk.ProgressBar()
self.progressbar.pulse()
self.progressbar.set_show_text(True)
vbox.pack_start(self.progressbar, True, True, 0)
self.timeout_id = GObject.timeout_add(50, self.on_timeout, None)
self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
self.set_deletable(False)
self.set_decorated(False)
self.set_resizable(False)
self.set_keep_above(True)
self.fraction = 0.0
self.pulse = True
def __init__(self, playlist, enable_web, transcoder, probe, preferred_transcoder, counter):
self.win = Gtk.Window(type=Gtk.WindowType.TOPLEVEL)
theme = Gtk.IconTheme.get_default()
self.playimage = theme.load_icon("media-playback-start", 16,0)
self.store = Gtk.ListStore(GdkPixbuf.Pixbuf, str, str, int, int, str, str, str, str)
self.selection_index = None
self.create_model(playlist)
if counter:
self.store[counter][0] = self.playimage
self.playlist_counter = None
self.play_now = False
self.playlist_changed = False
self.double_clicked = False
self.drag_index = None
self.transcoder = transcoder
self.number_clicked = 0
self.double_clicked_index = None
self.probe = probe
self.preferred_transcoder = preferred_transcoder
self.enable_web = enable_web
self.show_image = True
self.sorted_index = None
def _combo_changed_clients(self, widget):
ind = widget.get_active()
if ind == -1:
return
else:
dev = self.chromecasts[ind]
if not dev:
return
self.connect_to_chromecast(dev)
if self.cast:
self.cast.wait()
else:
self.clients_combo.set_active(-1)
message = ("Cannot connect to chromecast. You sure you are still connected to the same network?")
win = Gtk.Window(type=Gtk.WindowType.TOPLEVEL)
dialog = Gtk.MessageDialog(win, None, Gtk.MessageType.ERROR,
Gtk.ButtonsType.OK, message)
dialog.run()
dialog.destroy()
def __init__(self):
Gtk.Window.__init__(self, title='apart')
self.dying = False
self.status_listener = MessageListener(
on_message=lambda m: GLib.idle_add(self.on_status_msg, m),
message_predicate=lambda m: m['type'] == 'status')
self.core = ApartCore(listeners=[self.status_listener],
on_finish=lambda code: GLib.idle_add(self.on_delete))
self.sources = None
self.sources_interest = [] # array of callbacks on sources update
self.set_default_size(height=300, width=300 * 16/9)
self.loading_body = LoadingBody()
self.clone_body = None
self.add(self.loading_body)
self.connect('delete-event', self.on_delete)
self.set_icon_name('apart')
def main():
win = Window()
# allow keyboard interrupt / nodemon to end program cleanly
for sig in [signal.SIGINT, signal.SIGTERM, signal.SIGUSR2]:
signal.signal(sig, lambda _s, _f: win.on_delete())
style_provider = Gtk.CssProvider()
style_provider.load_from_path(os.path.dirname(os.path.realpath(__file__)) + "/apart.css")
Gtk.StyleContext.add_provider_for_screen(
Gdk.Screen.get_default(),
style_provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
)
win.show_all()
Gtk.main()
def __init__(self, root: Gtk.Window, text: str,
ok_button_text: str = Gtk.STOCK_OK,
cancel_button_text: str = Gtk.STOCK_CANCEL,
header: str = '',
message_type: Gtk.MessageType = Gtk.MessageType.WARNING):
Gtk.MessageDialog.__init__(self, root, 0, message_type=message_type)
self.set_title(header)
self.icon = Gtk.Image()
self.icon.set_from_icon_name(appropriate_icon(message_type), Gtk.IconSize.LARGE_TOOLBAR)
self.text = Gtk.Label(text)
heading = Gtk.Box()
heading.add(self.icon)
heading.add(self.text)
self.get_message_area().add(heading)
self.get_message_area().set_spacing(0)
self.add_button(cancel_button_text, Gtk.ResponseType.CANCEL)
self.add_button(ok_button_text, Gtk.ResponseType.OK)
self.show_all()
def __init__(self, root: Gtk.Window, text: str,
ok_button_text: str = Gtk.STOCK_OK,
header: str = '',
message_type: Gtk.MessageType = Gtk.MessageType.ERROR):
Gtk.MessageDialog.__init__(self, root, 0, message_type=message_type)
self.set_title(header)
self.icon = Gtk.Image()
self.icon.set_from_icon_name(appropriate_icon(message_type), Gtk.IconSize.LARGE_TOOLBAR)
self.text = Gtk.Label(text)
heading = Gtk.Box()
heading.add(self.icon)
heading.add(self.text)
self.get_message_area().add(heading)
self.get_message_area().set_spacing(0)
self.add_button(ok_button_text, Gtk.ResponseType.OK)
self.show_all()
def on_menuitem_custom_activate(self, widget):
self.custom_window = Gtk.Window()
self.custom_window.set_default_size(640, 480)
self.custom_window.set_position(Gtk.WindowPosition.CENTER)
self.custom_window.set_title("Custom CSS")
self.custom_vbox = Gtk.VBox()
self.custom_scroller = Gtk.ScrolledWindow()
self.custom_button = Gtk.Button("Apply")
self.custom_vbox.pack_end(self.custom_button, False, False, 0)
self.custom_text_view = Gtk.TextView()
self.custom_text_buffer = Gtk.TextBuffer()
self.custom_text_buffer.set_text(self.custom_css)
self.custom_text_view.set_buffer(self.custom_text_buffer)
self.custom_scroller.add(self.custom_text_view)
self.custom_vbox.pack_start(self.custom_scroller, True, True, 0)
self.custom_window.add(self.custom_vbox)
self.custom_window.show_all()
self.custom_button.connect("clicked", self.apply_custom_css, self.custom_window, self.custom_text_buffer)
def __init__(self):
window = Gtk.Window(Gtk.WindowType.TOPLEVEL)
window.set_title("Audio-Player")
window.set_default_size(300, -1)
window.connect("destroy", Gtk.main_quit, "WM destroy")
vbox = Gtk.VBox()
window.add(vbox)
self.entry = Gtk.Entry()
vbox.pack_start(self.entry, False, True, 0)
self.button = Gtk.Button("Start")
self.button.connect("clicked", self.start_stop)
vbox.add(self.button)
window.show_all()
self.player = Gst.ElementFactory.make("playbin", "player")
fakesink = Gst.ElementFactory.make("fakesink", "fakesink")
self.player.set_property("video-sink", fakesink)
bus = self.player.get_bus()
bus.add_signal_watch()
bus.connect("message", self.on_message)
def __init__(self):
Gtk.Window.__init__(self)
somegrid = toolgrid(2)
button1 = toolbutton("browser")
somegrid.add(button1)
button2 = toolbutton("alienarena")
somegrid.add(button2)
button3 = toolbutton("live")
somegrid.add(button3)
button4 = toolbutton("cs-network")
somegrid.add(button4)
self.add(somegrid)
def __init__(self):
Gtk.Window.__init__(self,title="Ghetto OMR")
self.set_resizable(True)
self.connect("configure-event",self.new_dim)
self.connect("delete-event",Gtk.main_quit)
self.win_width = 200
self.win_height = 200
something = Gtk.Label("SOMETHING")
self.maximize()
self.count =0
self.main = MainGrid(self)
self.add(self.main)
#
# self.main.destroy()
# self.main = Gtk.Label("SOMETHING")
# self.add(self.main)
def __init__(self, title):
Gtk.Window.__init__(self, title=title)
self.filename = None
self.config_dir = os.path.expanduser("~/.config/PyFlowChart")
self.config_file = os.path.expanduser("~/.config/PyFlowChart/config")
self.chart_dir = os.path.expanduser("~/.config/PyFlowChart/charts")
self.check_config()
self.course_manager = CourseManager()
self.modify_grid = ModifyGrid()
self.about_dialog = about_dialog(self)
# Preferences dialog should work like this, to be implemented
#self.preferences_dialog = preferences_dialog(self)
self.parse_config()
GUI.py 文件源码
项目:Simple-User-Input-Sculpture-Generation
作者: ClaireKincaid
项目源码
文件源码
阅读 30
收藏 0
点赞 0
评论 0
def __init__(self):
Gtk.Window.__init__(self, title = "Choose a method of Sculpture Generation")
self.set_border_width(10)
self.set_default_size(400, 50)
#initiates Gtk box window
self.box = Gtk.Box(spacing = 6)
self.add(self.box)
#Initializes Vector Animation Button, places in box
self.VectorButton = Gtk.Button(label = "Vector Animation")
self.VectorButton.connect("clicked", self.on_VectorButton_clicked)
self.VectorButton.connect("clicked", Gtk.main_quit)
self.box.pack_start(self.VectorButton, True, True, 0)
#Initializes Perlin Noise Button, places in box
self.PerlinButton = Gtk.Button(label = "Perlin Noise")
self.PerlinButton.connect("clicked", self.on_PerlinButton_clicked)
self.PerlinButton.connect("clicked", Gtk.main_quit)
self.box.pack_start(self.PerlinButton, True, True, 0)
#when VectorButton clicked, toggles to new GUI
def __init__(self, folders):
GObject.GObject.__init__(self)
Thread.__init__(self)
Gtk.Window.__init__(self)
# Here i assume that all folders got the same icon...
self._folders = folders
self.model = []
self._flowbox = Gtk.FlowBox()
# Threading stuff
self.setDaemon(True)
self.run()
# Window configurations
self.set_default_size(650, 500)
self.set_size_request(650, 500)
self.set_resizable(True)
self.set_position(Gtk.WindowPosition.CENTER_ON_PARENT)
# Widgets & Accelerators
self._build_header_bar()
self._build_content()
self._setup_accels()
def _get_seat_n_window():
"Return a Gdk seat (essentially input devices) and window"
display = Gdk.Display.get_default()
screen = display.get_default_screen()
visual = screen.get_rgba_visual()
# see gnome-screenshot source: create_select_window()
# screenshot-area-selection.c
win = Gtk.Window(type=Gtk.WindowType.POPUP)
if screen.is_composited():
win.set_visual(visual)
win.set_app_paintable(True)
win.move(-100, -100)
win.resize(10, 10)
win.show()
win.set_accept_focus(True)
win.set_can_focus(True)
seat = display.get_default_seat()
return seat, win.get_window()
def create_progressbar_window(self):
self.progressbar_window = Gtk.Window(
title = "Planescape: Torment",
type = Gtk.WindowType.TOPLEVEL,
window_position = Gtk.WindowPosition.CENTER_ALWAYS,
resizable = False,
default_width = 360
)
self.progressbar = Gtk.ProgressBar(
hexpand = True,
show_text = True,
text = _("Patching..."),
pulse_step = 0.1,
margin_top = 10,
margin_bottom = 10,
margin_left = 10,
margin_right = 10
)
self.progressbar_window.add(self.progressbar)
def create_main_window(self):
self.main_window = Gtk.Window(
title = _("Omikron: The Nomad Soul"),
type = Gtk.WindowType.TOPLEVEL,
window_position = Gtk.WindowPosition.CENTER_ALWAYS,
resizable = False,
)
self.main_window.connect('delete-event', self.quit_app)
button_patch = Gtk.Button(
label = _("Old Games Widescreen Patch"),
margin_top = 10,
margin_bottom = 10,
margin_left = 10,
margin_right = 10
)
button_patch.connect('clicked', self.cb_button_patch)
self.main_window.add(button_patch)
self.main_window.show_all()
def on_folder_clicked(self):
Gtk.Window.__init__(self, title=_("Change working directory"))
dialog = Gtk.FileChooserDialog(_("Choose directory"), self,
Gtk.FileChooserAction.SELECT_FOLDER,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
_("Apply"), Gtk.ResponseType.OK))
dialog.set_default_size(800, 400)
response = dialog.run()
if response == Gtk.ResponseType.OK:
print(_("Select clicked"))
print(_("Folder selected: ") + dialog.get_filename())
self.selectedfolder = dialog.get_filename()
elif response == Gtk.ResponseType.CANCEL:
print(_("Cancel clicked"))
self.selectedfolder = cli.stdir
dialog.destroy()
def __init__(self):
self.main_window = Gtk.Window()
self.main_window.set_border_width(5)
self.main_window.connect("destroy", self._destroy)
self.main_vbox = Gtk.VBox()
self.select_hbox = Gtk.HBox()
self.select_button = Gtk.Button("Select")
self.select_button.connect("clicked", self._select_clicked)
self.select_hbox.pack_start(self.select_button, False, True, 0)
self.file_combo = Gtk.ComboBoxText()
self.file_combo.connect("changed", self._file_combo_changed)
self.select_hbox.pack_start(self.file_combo, True, True, 0)
self.main_vbox.pack_start(self.select_hbox, False, True, 0)
self.metadata_table = Gtk.Table(1, 1)
self.metadata_table.attach(
Gtk.Label("Select a file to view metadata information..."), 0, 1, 0, 1)
self.main_vbox.pack_start(self.metadata_table, True, True, 0)
self.main_window.add(self.main_vbox)
self.main_window.show_all()
def __init__(self, n, front, back, step):
from gi.repository import Gtk
from gi.repository import GObject
Render.__init__(self, n, front, back)
window = Gtk.Window()
self.window = window
window.resize(self.n, self.n)
self.step = step
window.connect("destroy", self.__destroy)
darea = Gtk.DrawingArea()
# darea.connect("expose-event", self.expose)
self.darea = darea
window.add(darea)
window.show_all()
#self.cr = self.darea.window.cairo_create()
self.steps = 0
GObject.idle_add(self.step_wrap)