當前位置: 首頁>>代碼示例>>Python>>正文


Python GUI.center_window方法代碼示例

本文整理匯總了Python中GUI.center_window方法的典型用法代碼示例。如果您正苦於以下問題:Python GUI.center_window方法的具體用法?Python GUI.center_window怎麽用?Python GUI.center_window使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在GUI的用法示例。


在下文中一共展示了GUI.center_window方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import GUI [as 別名]
# 或者: from GUI import center_window [as 別名]
	def __init__(self, parent, describtion="Working..."):
		self.parent = parent

		# init popup dialog
		GUI.Toplevel.__init__(self, parent, takefocus=True)
		self.wm_title(describtion)
		self.transient(parent)
		self.resizable(0,0)

		# add some text
		label = GUI.Label(self, text="progress:")
		label.pack(fill='both', expand=1, padx=2, pady=2)

		# init progress bar
		self.progress_bar = GUI.Progressbar(self, orient='horizontal', length=300, mode='determinate')
		self.progress_bar.pack(fill='both', expand=1, padx=2, pady=2)

		# put window in front of others (popup-action)
		self.lift()
		self.grab_set()
		self.focus_set()
		self.set_maximum(100)
		self.set_progress(0)

		# center window into the center of the parent window
		GUI.center_window(self, parent)
開發者ID:COMSYS,項目名稱:PowerGraph,代碼行數:28,代碼來源:dialogs.py

示例2: connect

# 需要導入模塊: import GUI [as 別名]
# 或者: from GUI import center_window [as 別名]
def connect(tk_parent, host):
	try:
		c = PowerGraphConnection(host)
	
		# create window
		window = GUI.Toplevel(tk_parent)
		window.wm_title("Raspberry Control")
		window.iconbitmap("favicon.ico")
		window.transient(tk_parent)
		window.resizable(0,0)
		window.lift()
		window.grab_set()
		window.focus_set()

		# buttons
		frame = GUI.Frame(window)
		GUI.Button(frame, text="Configure Hardware", command=lambda: configure_hardware(window, c)).pack(side='left', padx=2, pady=2)
		GUI.Button(frame, text="Download Records", command=lambda: download(window, c)).pack(side='left', padx=2, pady=2)
		frame2 = GUI.Frame(frame, relief='sunken', borderwidth=0)
		GUI.Button(frame2, text="Start Measurement", command=lambda: c.start_measurement()).pack(padx=2, pady=2)
		GUI.Button(frame2, text="Stop Measurement", command=lambda: c.stop_measurement()).pack(padx=2, pady=2)
		frame2.pack(side='top', padx=2, pady=2)
		frame.grid(row=0, columnspan=2)

		# creating settings widgets line by line
		def add_labeled_widget(new_widget, label):
			GUI.Label(window, text=label).grid(row=add_labeled_widget.grid_row, column=0, sticky=GUI.align_option('right'))
			new_widget.grid(row=add_labeled_widget.grid_row, column=1, sticky=GUI.align_option('left', 'right'))
			add_labeled_widget.grid_row += 1
			return new_widget
		add_labeled_widget.grid_row = 1

		w_downsampling     = add_labeled_widget(GUI.EditBox(window), "combine n samples into 1 (downsampling):")
		w_resulting_rate   = add_labeled_widget(GUI.Label(window), "resulting sample rate:")
		w_filename_counter = add_labeled_widget(GUI.EditBox(window), "filename counter:")

		# load config from tool and display it in the dialog
		config = c.get_config()
		w_downsampling.value     = config.compound_count
		w_resulting_rate.value   = config.frequency//config.compound_count
		w_filename_counter.value = config.filename_counter

		# apply button
		def apply_settings():
			try:
				downsampling = int(w_downsampling.value)
				if downsampling < 1:
					raise ValueError("downsampling value must be 1 or higher")
				config.compound_count = downsampling
				config.filename_counter = int(w_filename_counter.value)
				c.set_config(config)
			except Exception as e:
				GUI.messagebox.showwarning("Error", str(e))
		GUI.Button(window, text="Apply Settings", command=apply_settings).grid(row=add_labeled_widget.grid_row, column=0, columnspan=2, padx=2, pady=2)

		# show window
		GUI.center_window(window, tk_parent)
		tk_parent.wait_window(window)

		c.close()

	except ConnectionRefusedError as e:
		GUI.messagebox.showwarning("Error", str(e))
		return
	except Exception as e:
		GUI.messagebox.showwarning("Error", str(e))
		return
開發者ID:COMSYS,項目名稱:PowerGraph,代碼行數:69,代碼來源:communication.py

示例3: configure_hardware

# 需要導入模塊: import GUI [as 別名]
# 或者: from GUI import center_window [as 別名]

#.........這裏部分代碼省略.........
	next_row.row = -1
	
	# creating settings widgets line by line
	def add_labeled_widget(new_widget, label):
		row = next_row()
		GUI.Label(window, text=label).grid(row=row, column=0, sticky=GUI.align_option('right'))
		new_widget                   .grid(row=row, column=1, sticky=GUI.align_option('left', 'right'))
		return new_widget

	w_device_name   = add_labeled_widget(GUI.EditBox(window), "device name:")
	w_unit_name     = add_labeled_widget(GUI.EditBox(window), "physical unit name (A):")
	w_unit_range    = add_labeled_widget(GUI.EditBox(window), "physical unit for ADC max (e.g. 120m):")
	w_sample_rate   = add_labeled_widget(GUI.ComboBoxEx(window), "samples per second:")
	w_ADC_min       = add_labeled_widget(GUI.EditBox(window), "ADC min value (hex):")
	w_ADC_max       = add_labeled_widget(GUI.EditBox(window), "ADC max value (hex):")
	w_SPI_output    = add_labeled_widget(GUI.EditBox(window), "SPI output pattern (hex):")
	w_SPI_clock_invert = add_labeled_widget(GUI.CheckBox(window), "SPI clock inverted")
	w_SPI_clock_delay  = add_labeled_widget(GUI.CheckBox(window), "SPI clock delayed")
	w_bit_shift     = add_labeled_widget(GUI.EditBox(window), "ADC data bit position:")
	w_digital_shift = add_labeled_widget(GUI.EditBox(window), "digital channel bit position:")

	# load config from tool and display it in the dialog
	config = c.get_config()
	w_device_name.value   = config.device_name
	w_unit_name.value     = config.unit_name
	w_unit_range.value    = format_significand_exponent(config.unit_significand, config.unit_exponent)
	w_sample_rate.values  = ['488281', '244140', '122070', '61035', '30517', '15258', '7629', '3814', '1907', '953']
	w_sample_rate.value   = config.frequency
	w_ADC_min.value       = "{:04X}".format(config.ADC_min)
	w_ADC_max.value       = "{:04X}".format(config.ADC_max)
	w_SPI_output.value    = "{:08X}".format(config.SPI_output_pattern)
	w_SPI_clock_invert.value = (config.SPI_clock_mode & 0x1) != 0
	w_SPI_clock_delay.value  = (config.SPI_clock_mode & 0x2) != 0
	w_bit_shift.value     = config.bit_shift
	w_digital_shift.value = config.digital_bit_shift

	# create diagram
	diagram = SignalDiagram(window, config)
	diagram.grid(row=0, column=3, rowspan=next_row(), sticky='wens')

	# update diagram with live data
	def tick():
		raw = c.get_raw_SPI_block()
		#print("{:08X}".format(raw))
		diagram.live_data = raw
		diagram.redraw()
		diagram.update()
		tick.timer = tk_parent.after(300, tick)
	tick()

	# completion
	def apply_action():
		c.stop_measurement()
		with dialogs.ProgressDialog(window, "Please wait..") as dialog:
			dialog.set_maximum(2)
			dialog.set_progress(0)
			# this simple statement will wait for Raspberry to stop the measurement, which can take a while depending on the configuration
			c.is_measurement_running()
		try:
			new_config                     = copy(config)
			current_entry = "device name"
			if len(w_device_name.value) > 31:
				raise ValueError("too long")
			new_config.device_name         = w_device_name.value
			current_entry = "unit name"
			if len(w_unit_name.value) > 15:
				raise ValueError("too long")
			new_config.unit_name           = w_unit_name.value
			current_entry = "unit range"
			new_config.unit_significand, config.unit_exponent = read_format_significand_exponent(w_unit_range.value)
			current_entry = "sample rate"
			new_config.frequency           = int(w_sample_rate.value)
			current_entry = "ADC min"
			new_config.ADC_min             = int(w_ADC_min.value, 16)
			current_entry = "ADC max"
			new_config.ADC_max             = int(w_ADC_max.value, 16)
			current_entry = "SPI clock mode"
			new_config.SPI_output_pattern  = int(w_SPI_output.value, 16)
			current_entry = "SPI clock mode"
			new_config.SPI_clock_mode      = (1 if w_SPI_clock_invert.value else 0) + (2 if w_SPI_clock_delay.value else 0)
			current_entry = "ADC bit position"
			new_config.bit_shift           = int(w_bit_shift.value)
			current_entry = "digital channel position"
			new_config.digital_bit_shift    = int(w_digital_shift.value)
			current_entry = "unknown"
			c.set_config(config)
			diagram.config = new_config
			c.start_dry_run()
		except (ValueError, struct.error) as e:
			GUI.messagebox.showwarning("Error", "Invalid entry in {}\n{}".format(current_entry, str(e)))
			return
	frame = GUI.Frame(window)
	GUI.Button(window, text="Apply Changes", command=apply_action).grid(column=0, row=next_row(), columnspan=2)

	# show window
	GUI.center_window(window, tk_parent)
	tk_parent.wait_window(window)
	tk_parent.after_cancel(tick.timer)

	c.stop_measurement()
開發者ID:COMSYS,項目名稱:PowerGraph,代碼行數:104,代碼來源:communication.py

示例4: choose_host

# 需要導入模塊: import GUI [as 別名]
# 或者: from GUI import center_window [as 別名]
def choose_host(tk_parent):
	# create window
	window = GUI.Toplevel(tk_parent)
	window.wm_title("Connect...")
	window.iconbitmap("favicon.ico")
	window.transient(tk_parent)
	window.resizable(0,0)
	window.lift()
	window.grab_set()
	window.focus_set()

	# listbox for display of raspberry-pi devices found in local network
	listbox = GUI.Listbox(window)
	listbox.pack(fill='both', expand=1, padx=2, pady=2)

	# edit box for input of custom address
	editbox = GUI.EditBox(window)
	editbox.configure(state='active')
	editbox.set_cursor(0)
	editbox.pack(side='left', fill='x', expand=1)

	# load initial value from last time
	try:
		with open("saved_address.txt", 'r') as address_file:
			editbox.value = address_file.read()
	except:
		pass


	# button to connect to custom input
	custom_go = GUI.Button(window, text="Connect")
	custom_go.pack(side='left')

	GUI.center_window(window, tk_parent)


	# keep track of beacons (name, host)
	beacons = []

	listbox.delete(0, GUI.END)
	def add_beacon(device_name, host):
		if host not in beacons:
			beacons.append(host)
			listbox.insert(GUI.END, "{} - {}".format(device_name, host))

	# start listening for UDP broadcasts
	global broadcast_socket
	broadcast_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
	broadcast_socket.setblocking(0)
	broadcast_socket.bind(('', PORT)) # listen to every network interface

	def tick():
		try:
			while True:
				data, (host, port) = broadcast_socket.recvfrom(256)
				if data.startswith(b'PowerGraph beacon '):
					data = data[18:]
					device_name = data[:data.find(b'\x00')].decode()
					add_beacon(device_name, host)
				else:
					print("weird broadcast message received on correct port")
		except BlockingIOError:
			tick.timer_id = window.after(500, tick)
		except OSError:
			print("unexpected: received message that was too big\n")
	def tick_stop():
		window.after_cancel(tick.timer_id)
		broadcast_socket.close()
	tick()


	# handle listbox click events
	def on_select(e):
		select_index = listbox.curselection()
		if len(select_index) > 0:
			editbox.value = beacons[int(select_index[0])]
	listbox.bind('<<ListboxSelect>>', on_select)


	# on button click
	def on_click(*discard):
		if editbox.value != "":
			# save user's choice so we can load it next time
			with open("saved_address.txt", 'w') as address_file:
				address_file.write(editbox.value)

			on_click.result = editbox.value
			window.destroy()
	on_click.result = None
	custom_go.configure(command=on_click)
	listbox.bind('<Double-Button-1>', on_click)

	# redraw everything
	tk_parent.wait_window(window)
	tick_stop()
	print("user choice: {}".format(on_click.result))

	return on_click.result
開發者ID:COMSYS,項目名稱:PowerGraph,代碼行數:100,代碼來源:communication.py


注:本文中的GUI.center_window方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。