我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用gi.repository.Gtk.main()。
def main(): format_ = '%(asctime)s - %(levelname)s - %(name)s - %(message)s' logging.basicConfig(level=logging.INFO, format=format_) logger = logging.getLogger(__name__) if geteuid() == 0: logger.error("Running eduVPN client as root is not supported (yet)") exit(1) GObject.threads_init() if have_dbus(): import dbus.mainloop.glib dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) # import this later so the logging is properly configured from eduvpn.ui import EduVpnApp edu_vpn_app = EduVpnApp() edu_vpn_app.run() Gtk.main()
def __init__(self): """ class constructor """ # initially set an empty configuration self.set_config(configparser.ConfigParser()) # set up the quit signals self.setup_signals( signals = [signal.SIGINT, signal.SIGTERM, signal.SIGHUP], handler = self.quit ) # can't use Gtk.main() because of a bug that prevents proper SIGINT # handling. use Glib.MainLoop() directly instead. self.mainloop = GLib.MainLoop() # main loop ################## ### Properties ### ##################
def start_app(datadir): global splash_win if not options.no_splash: solfege.splash_win = splash_win = SplashWin() time.sleep(0.1) Gdk.flush() while Gtk.events_pending(): Gtk.main_iteration() else: solfege.splash_win = splash_win = None style_provider = Gtk.CssProvider() with open("solfege.css", "r") as f: css = f.read() try: style_provider.load_from_data(css) except GObject.GError, e: print e pass Gtk.StyleContext.add_provider_for_screen( Gdk.Screen.get_default(), style_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION) GObject.timeout_add(1, start_gui, datadir) Gtk.main()
def __init__(self): # Applet icon global indicator indicator = appindicator.Indicator.new(APPINDICATOR_ID, self.exchange_app.dogecoin.icon, appindicator.IndicatorCategory.SYSTEM_SERVICES) indicator.set_status(appindicator.IndicatorStatus.ACTIVE) indicator.set_label('€ *.****', '100%') # Set the menu of the indicator (default: gtk.Menu()) indicator.set_menu(self.build_menu()) # Ctrl-C behaviour signal.signal(signal.SIGINT, signal.SIG_DFL) # Setup the refresh every 5 minutes gobject.timeout_add(1000*60*5, self.exchange_app.update_price, "timeout") # First price update within 1 second gobject.timeout_add(1000, self.exchange_app.first_update_price, "first_update") # Main loop gtk.main()
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 main(self): self.indicator = appindicator.Indicator.new(self.APPINDICATOR_ID, self.ICON_OFF, appindicator.IndicatorCategory.SYSTEM_SERVICES) self.indicator.set_status(appindicator.IndicatorStatus.ACTIVE) self.indicator.set_menu(self.build_menu()) # This sets the handler for “INT” signal processing #- the one issued by the OS when “Ctrl+C” is typed. #The handler we assign to it is the “default” handler, which, #in case of the interrupt signal, is to stop execution. signal.signal(signal.SIGINT, signal.SIG_DFL) #listen to quit signal notify.init(self.APPINDICATOR_ID) self.update() glib.timeout_add_seconds(self.UPDATE_FREQUENCY, self.update) gtk.main()
def __init__(self): self.builder = Gtk.Builder() self.builder.add_from_file("main.xml") self.win = self.builder.get_object("window_main") self.win.connect("delete-event", self.exit) self.win.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("white")) self.win.show_all() self.prefix = "SolStudio" self.ws = 0 # TODO: workspaces self.ctrl = False self.completion = True self.saved = [True] self.buff = [None] self.FILE = [None] self.ident = 0 self.connect() self.check_solc() self.reopen() # check for the last opened file Gtk.main()
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 main(): formatter = logging.Formatter( '%(levelname)-6s %(name)-30s %(message)s') handler = logging.StreamHandler() log = logging.getLogger() handler.setFormatter(formatter) log.addHandler(handler) log.setLevel({ "DEBUG": logging.DEBUG, "INFO": logging.INFO, "WARNING": logging.WARNING, "ERROR": logging.ERROR, }[os.getenv("PYTESTSHOT_VERBOSE", "INFO")]) comparator = Comparator() comparator.run()
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 main(): if len(sys.argv) < 2: watch_dir = zenipy.file_selection( multiple=False, directory=True, save=False, confirm_overwrite=False, filename=None, title='Choose a directory to watch', width=20, height=20, timeout=None ) else: watch_dir = os.path.abspath(sys.argv[1]) if not watch_dir: raise SystemExit('No watch directory selected - exiting') cfg.set_watch_dir(watch_dir) cfg.read() app = Application() app.run()
def install_and_import(package): """@brief Imports modules and installs them if they are not.""" import importlib try: importlib.import_module(package) except ImportError: try: import pip except ImportError: print "no pip" os.system('python get_pip.py') finally: import pip pip.main(['install', package]) finally: globals()[package] = importlib.import_module(package) # these other ones I a am not so sure of. Thus the install function.
def test_availablepane(self): from softwarecenter.ui.gtk3.panes.availablepane import get_test_window win = get_test_window() pane = win.get_data("pane") self._p() pane.on_search_terms_changed(None, "the") self._p() sortmode = pane.app_view.sort_methods_combobox.get_active_text() self.assertEqual(sortmode, "By Relevance") model = pane.app_view.tree_view.get_model() len1 = len(model) pane.on_search_terms_changed(None, "nosuchsearchtermforsure") self._p() len2 = len(model) self.assertTrue(len2 < len1) GObject.timeout_add(TIMEOUT, lambda: win.destroy()) Gtk.main()
def test_custom_lists(self): from softwarecenter.ui.gtk3.panes.availablepane import get_test_window win = get_test_window() pane = win.get_data("pane") self._p() pane.on_search_terms_changed(None, "ark,artha,software-center") self._p() model = pane.app_view.tree_view.get_model() # custom list should return three items self.assertTrue(len(model) == 3) # check package names, ordering is default "by relevance" self.assertPkgInListAtIndex(0, model, "ark") self.assertPkgInListAtIndex(1, model, "software-center") self.assertPkgInListAtIndex(2, model, "artha") # check that the status bar offers to install the packages install_button = pane.action_bar.get_button(ActionButtons.INSTALL) self.assertNotEqual(install_button, None) GObject.timeout_add(TIMEOUT, lambda: win.destroy()) Gtk.main()
def reload(self, sources_list=None, metadata=None): """ reload package list """ # check if the sourcespart is there, if not, do a full reload # this can happen when the "partner" repository is added, it # will be in the main sources.list already and this means that # aptsources will just enable it instead of adding a extra # sources.list.d file (LP: #666956) d = apt_pkg.config.find_dir("Dir::Etc::sourceparts") if (not sources_list or not os.path.exists(os.path.join(d, sources_list))): sources_list = "" try: trans = yield self.aptd_client.update_cache( sources_list=sources_list, defer=True) yield self._run_transaction(trans, None, None, None, metadata) except Exception as error: self._on_trans_error(error) # note that the cache re-open will happen via the connected # "transaction-finished" signal
def main(): global indicator, menu indicator = appindicator.Indicator.new(APPINDICATOR_ID, os.path.abspath('closed.svg'), appindicator.IndicatorCategory.SYSTEM_SERVICES) indicator.set_status(appindicator.IndicatorStatus.ACTIVE) pubnub = set_up_pubnub() menu = gtk.Menu() item = gtk.MenuItem('Quit') item.connect('activate', die, pubnub) menu.append(item) menu.show_all() indicator.set_menu(menu) indicator.set_icon(os.path.abspath("closed.svg")) notify.init(APPINDICATOR_ID) GObject.timeout_add_seconds(1, check_caps, pubnub) gtk.main()
def main(): builder = Gtk.Builder() builder.add_from_file('main_window.glade') builder.connect_signals(MainHandler(builder, FeedManager())) window = builder.get_object('main_window') window.show_all() # Fix keyboard interrupt not working signal.signal(signal.SIGINT, signal.SIG_DFL) Gtk.main()
def main(): import sys app = GUI(sys.argv[1]) Gtk.main()
def main(): import sys app = GUI(sys.argv[1], sys.argv[2]) Gtk.main()
def main(): import sys app = GUI(sys.argv[1], sys.argv[2], sys.argv[3]) Gtk.main()
def main(): import sys app = GUI() Gtk.main()
def main(): app = GUI() Gtk.main()
def populate_store(self, store): directory = '/home/anon/Documents' for filename in os.listdir(directory): size = os.path.getsize(os.path.join(directory, filename)) # the second element is displayed in the second TreeView column # but that column is sorted by the third element # so the file sizes are sorted as numbers, not as strings store.append([filename, '{0:,}'.format(size), size]) # The main part:
def get_current_rotation(): global rotations # Extract the rotation from xrandr for the first connected screen (probably the main screen). rotation = subprocess.check_output("xrandr | grep "+DISPLAY+" | cut -f 5 -d ' '", shell=True) rotation = rotation.strip(); if rotation not in rotations: rotation = rotations[0] print "current rotation: "+rotation return rotation
def show_window(self): self.window.show_all() Gtk.main()
def run(self): self.builder.get_object("stage").show_all() self.builder.get_object("name").set_text(self.ds.name) gtk.main()
def run_pi(self): # suppresses error: Couldn't connect to accessibility bus: # Failed to connect to socket: shell_this("export NO_AT_BRIDGE=1") # listener loop for icon switch signals ui_thread = Thread(target=self.update_icon) ui_thread.daemon = True ui_thread.start() # starting Gtk main: Gtk.main()
def __init__(self, scrlck_mode=False): self.scrlck_mode = scrlck_mode self.id_q = Queue() self.on_q = Queue() self.pi_q = Queue() # init processes gi_proc = Process(target=self.get_ids) gi_proc.daemon = True cs_proc = Process(target=self.change_state) # no daemon, or main program will terminate before Keys can be unlocked cs_proc.daemon = False zmq_lis = ZmqListener( self.on_q) # somehow works ony with threads not processes zmq_lis_thr = Thread(target=zmq_lis.start_listener) zmq_lis_thr.setDaemon(True) pi = PanelIndicator(self.pi_q, self.on_q) # starting processes and catching exceptions: try: gi_proc.start() cs_proc.start() zmq_lis_thr.start() pi.run_pi() # main loop of root process except (KeyboardInterrupt, SystemExit): print('Caught exit event.') finally: # send exit signal, will reactivate YubiKey slots print('Sending EXIT_SIGNAL') self.on_q.put(EXIT_SIGNAL)
def main(self): gtk.main() #Gets called when the (x) on the window is clicked to close the window. Note that stopping the program from Eclipse will NOT trigger this function
def run(self): # can't use Gtk.main() because of a bug that prevents proper SIGINT # handling. use Glib.MainLoop() directly instead. self.mainloop = GLib.MainLoop() # main loop # signal.signal(signal.SIGINT, signal.SIG_DFL) self.logger.debug(_("Starting GLib main loop...")) self.mainloop.run() self.logger.debug(_("GLib main loop ended.")) # quit the gui
def __init__(self): super(WelcomeWindow, self).__init__() self.hb = Gtk.HeaderBar() self.hb.set_show_close_button(True) self.hb.set_title("Py IDE") self.set_titlebar(self.hb) self.currentPage = None self.hbButtons = [] self.language = '' self.showHome() ################################################################## self.set_size_request(800, 400) self.set_resizable(False) self.loadSettings() self.connect('destroy', Gtk.main_quit) self.show_all() Gtk.main()
def main(): if dbus.SessionBus().request_name( 'es.atareao.PomodoroIndicator') !=\ dbus.bus.REQUEST_NAME_REPLY_PRIMARY_OWNER: print("application already running") exit(0) GObject.threads_init() Gst.init(None) Gst.init_check(None) Notify.init('pomodoro-indicator') Pomodoro_Indicator() Gtk.main()
def run(): Game() GObject.threads_init() Gtk.main() return 0
def start(self): from gi.repository import Gtk Gtk.main()
def mail_notify(self, inbox_count): """ If inbox_count is unchanged from last update - exit the function. If new inbox_count is smaller - user read the message somewhere else (browser, phone app, etc). """ notification_config = self.config.get('notifications') local_inbox_count = self.local_data.get('inbox_count', 0) if inbox_count == local_inbox_count: return elif inbox_count < local_inbox_count: self.INDICATOR.set_status(AppIndicator3.IndicatorStatus.ACTIVE) return self.INDICATOR.set_status(AppIndicator3.IndicatorStatus.ATTENTION) if not notification_config: return if not self.services['notification']: self.services['notification'] = Notify.init(self.APPINDICATOR_ID) if notification_config == 1: message_data = self.request.get_last_message() header = "reddit mail from <b>{author}</b>".format(author=message_data['author']) body = message_data['body'] else: header = "You have a new reddit mail" body = '' Notify.Notification.new( header, body, self.ICONS['main'] ).show()
def main_loop(): Gtk.main()
def __init__(self): from playlist_creator import preferences_file_location, systems_list self.settings_file_location = preferences_file_location with open(self.settings_file_location) as data_file: self.preferences_data = json.load(data_file) builder = Gtk.Builder() builder.add_from_file("glade/app.glade") builder.connect_signals(self) self.notebook = builder.get_object("notebook") self.renderer_text = Gtk.CellRendererText() self.playlists_directory_chooser = builder.get_object("playlists_directory_chooser") self.cores_directory_chooser = builder.get_object("cores_directory_chooser") self.infos_directory_chooser = builder.get_object("infos_directory_chooser") self.playlists_location = self.preferences_data[0]['playlists_location'] self.cores_location = self.preferences_data[0]['cores_location'] self.infos_location = self.preferences_data[0]['infos_location'] self.playlists_directory_chooser.set_current_folder(self.playlists_location) self.cores_directory_chooser.set_current_folder(self.cores_location) self.infos_directory_chooser.set_current_folder(self.infos_location) self.system_names = Gtk.ListStore(str) for system_name in systems_list: self.system_names.append([system_name]) # get all cores and populate list self.__populate_cores_list__() if len(self.preferences_data) > 1: for system_from_prefs in self.preferences_data[1]: self.create_new_tab(system_from_prefs['system_name'], system_from_prefs['roms_dir'], system_from_prefs['core_path'], system_from_prefs['core_name']) window = builder.get_object("window") window.show_all() Gtk.main()
def start(self, bridge): """Start the UI event loop.""" bridge.attach(80, 24, rgb=True) drawing_area = Gtk.DrawingArea() drawing_area.connect('draw', self._gtk_draw) window = Gtk.Window() window.add(drawing_area) window.set_events(window.get_events() | Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK | Gdk.EventMask.POINTER_MOTION_MASK | Gdk.EventMask.SCROLL_MASK) window.connect('configure-event', self._gtk_configure) window.connect('delete-event', self._gtk_quit) window.connect('key-press-event', self._gtk_key) window.connect('key-release-event', self._gtk_key_release) window.connect('button-press-event', self._gtk_button_press) window.connect('button-release-event', self._gtk_button_release) window.connect('motion-notify-event', self._gtk_motion_notify) window.connect('scroll-event', self._gtk_scroll) window.connect('focus-in-event', self._gtk_focus_in) window.connect('focus-out-event', self._gtk_focus_out) window.show_all() im_context = Gtk.IMMulticontext() im_context.set_client_window(drawing_area.get_window()) im_context.set_use_preedit(False) # TODO: preedit at cursor position im_context.connect('commit', self._gtk_input) self._pango_context = drawing_area.create_pango_context() self._drawing_area = drawing_area self._window = window self._im_context = im_context self._bridge = bridge Gtk.main()
def main(self): Gtk.main()
def main(): SIGS = [getattr(signal, s, None) for s in "SIGINT SIGTERM SIGHUP".split()] for sig in filter(None, SIGS): signal.signal(sig, idle_handler) GLib.idle_add(install_glib_handler, sig, priority=GLib.PRIORITY_HIGH) IEE = ImunesExperimentExporter() IEE.main()
def __init__(self, *args): super(main, self).__init__(*args) self.data = [] self.graph = None self.charts = None self.win = Gtk.Window() self.set_border_width(4) self.set_position(Gtk.WindowPosition.CENTER) self.set_title("PySpc : Statistical Process Control Charts for Humans") self.set_default_size(480, 600) self.connect("delete-event", Gtk.main_quit) self.buildui()
def get_new_values(self, widget): """ When ComboBox changed, main window will update all labels informations """ nb1, nb2 = self.combo.get_active(), self.combo2.get_active() self.img_name1, self.img_name2 = self.coin_list[nb1], self.coin_list[nb2] self.get_items(widget = "window")
def main(self): """ Main function """ window = self.builder.get_object("window1") window.connect("delete-event", self.safe_quit, "kill ui") window.show_all()