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()
python类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()
cryptocoin_indicator.py 文件源码
项目:cryptocoin-indicator
作者: MichelMichels
项目源码
文件源码
阅读 26
收藏 0
点赞 0
评论 0
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 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(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()
Gtk.main()
def main():
import sys
app = GUI(sys.argv[1], sys.argv[2])
Gtk.main()
def main():
app = GUI()
Gtk.main()
def main():
import sys
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()